]> icculus.org git repositories - divverent/netradiant.git/blob - radiant/textureentry.h
another compile fix for win32 on arch linux
[divverent/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/gtkentry.h>
27 #include <gtk/gtkliststore.h>
28 #include "gtkutil/idledraw.h"
29
30 #include "generic/static.h"
31 #include "signal/isignal.h"
32 #include "shaderlib.h"
33
34 #include "texwindow.h"
35
36 template<typename StringList>
37 class EntryCompletion
38 {
39   GtkListStore* m_store;
40   IdleDraw m_idleUpdate;
41 public:
42   EntryCompletion() : m_store(0), m_idleUpdate(UpdateCaller(*this))
43   {
44   }
45
46   void connect(GtkEntry* entry)
47   {
48     if(m_store == 0)
49     {
50       m_store = gtk_list_store_new(1, G_TYPE_STRING);
51
52       fill();
53
54       StringList().connect(IdleDraw::QueueDrawCaller(m_idleUpdate));
55     }
56
57     GtkEntryCompletion* completion = gtk_entry_completion_new();
58     gtk_entry_set_completion(entry, completion);
59     gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(m_store));
60     gtk_entry_completion_set_text_column(completion, 0);
61   }
62
63   void append(const char* string)
64   {
65     GtkTreeIter iter;
66     gtk_list_store_append(m_store, &iter);
67     gtk_list_store_set(m_store, &iter, 0, string, -1);
68   }
69   typedef MemberCaller1<EntryCompletion, const char*, &EntryCompletion::append> AppendCaller;
70
71   void fill()
72   {
73     StringList().forEach(AppendCaller(*this));
74   }
75
76   void clear()
77   {
78     gtk_list_store_clear(m_store);
79   }
80
81   void update()
82   {
83     clear();
84     fill();
85   }
86   typedef MemberCaller<EntryCompletion, &EntryCompletion::update> UpdateCaller;
87 };
88
89 class TextureNameList
90 {
91 public:
92   void forEach(const ShaderNameCallback& callback) const
93   {
94     for(QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement())
95     {
96       IShader *shader = QERApp_ActiveShaders_IteratorCurrent();
97
98       if(shader_equal_prefix(shader->getName(), "textures/"))
99       {
100         callback(shader->getName() + 9);
101       }
102     }
103   }
104   void connect(const SignalHandler& update) const
105   {
106     TextureBrowser_addActiveShadersChangedCallback(update);
107   }
108 };
109
110 typedef Static< EntryCompletion<TextureNameList> > GlobalTextureEntryCompletion;
111
112
113 class ShaderList
114 {
115 public:
116   void forEach(const ShaderNameCallback& callback) const
117   {
118     GlobalShaderSystem().foreachShaderName(callback);
119   }
120   void connect(const SignalHandler& update) const
121   {
122     TextureBrowser_addShadersRealiseCallback(update);
123   }
124 };
125
126 typedef Static< EntryCompletion<ShaderList> > GlobalShaderEntryCompletion;
127
128
129 #endif