]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/textureentry.h
Wrap gtkutil/entry
[xonotic/netradiant.git] / radiant / textureentry.h
1 /*
2    Copyright (C) 2001-2006, William Joseph.
3    All Rights Reserved.
4
5    This file is part of GtkRadiant.
6
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    GtkRadiant is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 #if !defined( INCLUDED_TEXTUREENTRY_H )
23 #define INCLUDED_TEXTUREENTRY_H
24
25
26 #include <gtk/gtk.h>
27 #include "gtkutil/idledraw.h"
28
29 #include "generic/static.h"
30 #include "signal/isignal.h"
31 #include "shaderlib.h"
32
33 #include "texwindow.h"
34
35 template<typename StringList>
36 class EntryCompletion
37 {
38 ui::ListStore m_store;
39 IdleDraw m_idleUpdate;
40 public:
41 EntryCompletion() : m_store( 0 ), m_idleUpdate( UpdateCaller( *this ) ){
42 }
43
44 void connect( GtkEntry* entry ){
45         if ( !m_store ) {
46                 m_store = ui::ListStore(gtk_list_store_new( 1, G_TYPE_STRING ));
47
48                 fill();
49
50                 StringList().connect( IdleDraw::QueueDrawCaller( m_idleUpdate ) );
51         }
52
53         GtkEntryCompletion* completion = gtk_entry_completion_new();
54         gtk_entry_set_completion( entry, completion );
55         gtk_entry_completion_set_model( completion, GTK_TREE_MODEL( m_store ) );
56         gtk_entry_completion_set_text_column( completion, 0 );
57 }
58
59 void append( const char* string ){
60         GtkTreeIter iter;
61         gtk_list_store_append( m_store, &iter );
62         gtk_list_store_set( m_store, &iter, 0, string, -1 );
63 }
64 typedef MemberCaller1<EntryCompletion, const char*, &EntryCompletion::append> AppendCaller;
65
66 void fill(){
67         StringList().forEach( AppendCaller( *this ) );
68 }
69
70 void clear(){
71         gtk_list_store_clear( m_store );
72 }
73
74 void update(){
75         clear();
76         fill();
77 }
78 typedef MemberCaller<EntryCompletion, &EntryCompletion::update> UpdateCaller;
79 };
80
81 class TextureNameList
82 {
83 public:
84 void forEach( const ShaderNameCallback& callback ) const {
85         for ( QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement() )
86         {
87                 IShader *shader = QERApp_ActiveShaders_IteratorCurrent();
88
89                 if ( shader_equal_prefix( shader->getName(), "textures/" ) ) {
90                         callback( shader->getName() + 9 );
91                 }
92         }
93 }
94 void connect( const SignalHandler& update ) const {
95         TextureBrowser_addActiveShadersChangedCallback( update );
96 }
97 };
98
99 typedef Static< EntryCompletion<TextureNameList> > GlobalTextureEntryCompletion;
100
101
102 class ShaderList
103 {
104 public:
105 void forEach( const ShaderNameCallback& callback ) const {
106         GlobalShaderSystem().foreachShaderName( callback );
107 }
108 void connect( const SignalHandler& update ) const {
109         TextureBrowser_addShadersRealiseCallback( update );
110 }
111 };
112
113 typedef Static< EntryCompletion<ShaderList> > GlobalShaderEntryCompletion;
114
115
116 #endif