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