textureentry.h

Go to the documentation of this file.
00001 /*
00002  Copyright (C) 2001-2006, William Joseph.
00003  All Rights Reserved.
00004 
00005  This file is part of GtkRadiant.
00006 
00007  GtkRadiant is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU General Public License as published by
00009  the Free Software Foundation; either version 2 of the License, or
00010  (at your option) any later version.
00011 
00012  GtkRadiant is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU General Public License for more details.
00016 
00017  You should have received a copy of the GNU General Public License
00018  along with GtkRadiant; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020  */
00021 
00022 #if !defined(INCLUDED_TEXTUREENTRY_H)
00023 #define INCLUDED_TEXTUREENTRY_H
00024 
00025 #include <gtk/gtkentry.h>
00026 #include <gtk/gtkliststore.h>
00027 #include "gtkutil/idledraw.h"
00028 
00029 #include "generic/static.h"
00030 #include "signal/isignal.h"
00031 #include "shaderlib.h"
00032 
00033 #include "sidebar/sidebar.h"
00034 
00035 template<typename StringList>
00036 class EntryCompletion
00037 {
00038         GtkListStore* m_store;
00039         IdleDraw m_idleUpdate;
00040     public:
00041         EntryCompletion () :
00042             m_store(0), m_idleUpdate(UpdateCaller(*this))
00043         {
00044         }
00045 
00046         void connect (GtkEntry* entry)
00047         {
00048             if (m_store == 0) {
00049                 m_store = gtk_list_store_new(1, G_TYPE_STRING);
00050 
00051                 fill();
00052 
00053                 StringList().connect(IdleDraw::QueueDrawCaller(m_idleUpdate));
00054             }
00055 
00056             GtkEntryCompletion* completion = gtk_entry_completion_new();
00057             gtk_entry_set_completion(entry, completion);
00058             gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(m_store));
00059             gtk_entry_completion_set_text_column(completion, 0);
00060         }
00061 
00062         void append (const char* string)
00063         {
00064             GtkTreeIter iter;
00065             gtk_list_store_append(m_store, &iter);
00066             gtk_list_store_set(m_store, &iter, 0, string, -1);
00067         }
00068         typedef MemberCaller1<EntryCompletion, const char*, &EntryCompletion::append> AppendCaller;
00069 
00070         void fill ()
00071         {
00072             StringList().forEach(AppendCaller(*this));
00073         }
00074 
00075         void clear ()
00076         {
00077             if (m_store != 0)
00078                 gtk_list_store_clear(m_store);
00079         }
00080 
00081         void update ()
00082         {
00083             clear();
00084             fill();
00085         }
00086         typedef MemberCaller<EntryCompletion, &EntryCompletion::update> UpdateCaller;
00087 };
00088 
00089 class TextureNameList
00090 {
00091     public:
00092         void forEach (const ShaderNameCallback& callback) const
00093         {
00094             for (GlobalShaderSystem().beginActiveShadersIterator(); !GlobalShaderSystem().endActiveShadersIterator(); GlobalShaderSystem().incrementActiveShadersIterator()) {
00095                 IShader *shader = GlobalShaderSystem().dereferenceActiveShadersIterator();
00096 
00097                 if (shader_equal_prefix(shader->getName(), "textures/")) {
00098                     callback(shader->getName() + 9);
00099                 }
00100             }
00101         }
00102         void connect (const SignalHandler& update) const
00103         {
00104             TextureBrowser_addActiveShadersChangedCallback(update);
00105         }
00106 };
00107 
00108 typedef Static<EntryCompletion<TextureNameList> > GlobalTextureEntryCompletion;
00109 
00110 #endif

Generated by  doxygen 1.6.2