2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
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.
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.
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
25 // Leonardo Zide (leo@lokigames.com)
28 #include "texwindow.h"
30 #include "debugging/debugging.h"
33 #include "ifilesystem.h"
37 #include "moduleobserver.h"
44 #include <gtk/gtkrange.h>
45 #include <gtk/gtkframe.h>
46 #include <gtk/gtkhbox.h>
47 #include <gtk/gtkvbox.h>
48 #include <gtk/gtkvscrollbar.h>
50 #include "signal/signal.h"
51 #include "math/vector.h"
52 #include "texturelib.h"
53 #include "string/string.h"
54 #include "shaderlib.h"
57 #include "stream/memstream.h"
58 #include "stream/textfilestream.h"
59 #include "stream/stringstream.h"
65 #include "gtkutil/menu.h"
66 #include "gtkutil/nonmodal.h"
67 #include "gtkutil/cursor.h"
68 #include "gtkutil/widget.h"
69 #include "gtkutil/glwidget.h"
70 #include "gtkutil/messagebox.h"
76 #include "brush_primit.h"
77 #include "brushmanip.h"
78 #include "patchmanip.h"
83 #include "mainframe.h"
84 #include "findtexturedialog.h"
85 #include "surfacedialog.h"
86 #include "patchdialog.h"
87 #include "groupdialog.h"
88 #include "preferences.h"
92 bool TextureBrowser_showWads()
94 return !string_empty(g_pGameDescription->getKeyValue("show_wads"));
97 void TextureBrowser_queueDraw(TextureBrowser& textureBrowser);
99 bool string_equal_start(const char* string, StringRange start)
101 return string_equal_n(string, start.first, start.last - start.first);
104 typedef std::set<CopiedString> TextureGroups;
106 void TextureGroups_addWad(TextureGroups& groups, const char* archive)
108 if(extension_equal(path_get_extension(archive), "wad"))
111 groups.insert(archive);
113 CopiedString archiveBaseName(path_get_filename_start(archive), path_get_filename_base_end(archive));
114 groups.insert(archiveBaseName);
118 typedef ReferenceCaller1<TextureGroups, const char*, TextureGroups_addWad> TextureGroupsAddWadCaller;
120 void TextureGroups_addShader(TextureGroups& groups, const char* shaderName)
122 const char* texture = path_make_relative(shaderName, "textures/");
123 if(texture != shaderName)
125 const char* last = path_remove_directory(texture);
126 if(!string_empty(last))
128 groups.insert(CopiedString(StringRange(texture, --last)));
132 typedef ReferenceCaller1<TextureGroups, const char*, TextureGroups_addShader> TextureGroupsAddShaderCaller;
134 void TextureGroups_addDirectory(TextureGroups& groups, const char* directory)
136 groups.insert(directory);
138 typedef ReferenceCaller1<TextureGroups, const char*, TextureGroups_addDirectory> TextureGroupsAddDirectoryCaller;
142 bool g_TextureBrowser_shaderlistOnly = false;
143 bool g_TextureBrowser_fixedSize = false;
144 bool g_TextureBrowser_filterNotex = false;
147 class DeferredAdjustment
151 typedef void (*ValueChangedFunction)(void* data, gdouble value);
152 ValueChangedFunction m_function;
155 static gboolean deferred_value_changed(gpointer data)
157 reinterpret_cast<DeferredAdjustment*>(data)->m_function(
158 reinterpret_cast<DeferredAdjustment*>(data)->m_data,
159 reinterpret_cast<DeferredAdjustment*>(data)->m_value
161 reinterpret_cast<DeferredAdjustment*>(data)->m_handler = 0;
162 reinterpret_cast<DeferredAdjustment*>(data)->m_value = 0;
166 DeferredAdjustment(ValueChangedFunction function, void* data) : m_value(0), m_handler(0), m_function(function), m_data(data)
173 g_source_remove(m_handler);
174 deferred_value_changed(this);
177 void value_changed(gdouble value)
182 m_handler = g_idle_add(deferred_value_changed, this);
185 static void adjustment_value_changed(GtkAdjustment *adjustment, DeferredAdjustment* self)
187 self->value_changed(adjustment->value);
193 class TextureBrowser;
195 typedef ReferenceCaller<TextureBrowser, TextureBrowser_queueDraw> TextureBrowserQueueDrawCaller;
197 void TextureBrowser_scrollChanged(void* data, gdouble value);
202 STARTUPSHADERS_NONE = 0,
203 STARTUPSHADERS_COMMON,
206 void TextureBrowser_hideUnusedExport(const BoolImportCallback& importer);
207 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_hideUnusedExport> TextureBrowserHideUnusedExport;
209 void TextureBrowser_showShadersExport(const BoolImportCallback& importer);
210 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_showShadersExport> TextureBrowserShowShadersExport;
212 void TextureBrowser_showShaderlistOnly(const BoolImportCallback& importer);
213 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_showShaderlistOnly> TextureBrowserShowShaderlistOnlyExport;
215 void TextureBrowser_fixedSize(const BoolImportCallback& importer);
216 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_fixedSize> TextureBrowserFixedSizeExport;
218 void TextureBrowser_filterNotex(const BoolImportCallback& importer);
219 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_filterNotex> TextureBrowserFilterNotexExport;
231 GtkWidget* m_gl_widget;
232 GtkWidget* m_texture_scroll;
233 GtkWidget* m_treeViewTree;
234 GtkWidget* m_treeViewTags;
235 GtkWidget* m_tag_frame;
236 GtkListStore* m_assigned_store;
237 GtkListStore* m_available_store;
238 GtkWidget* m_assigned_tree;
239 GtkWidget* m_available_tree;
240 GtkWidget* m_scr_win_tree;
241 GtkWidget* m_scr_win_tags;
242 GtkWidget* m_tag_notebook;
243 GtkWidget* m_search_button;
244 GtkWidget* m_shader_info_item;
246 std::set<CopiedString> m_all_tags;
247 GtkListStore* m_all_tags_list;
248 std::vector<CopiedString> m_copied_tags;
249 std::set<CopiedString> m_found_shaders;
251 ToggleItem m_hideunused_item;
252 ToggleItem m_showshaders_item;
253 ToggleItem m_showshaderlistonly_item;
254 ToggleItem m_fixedsize_item;
255 ToggleItem m_filternotex_item;
258 guint m_exposeHandler;
260 bool m_heightChanged;
261 bool m_originInvalid;
263 DeferredAdjustment m_scrollAdjustment;
264 FreezePointer m_freezePointer;
266 Vector3 color_textureback;
267 // the increment step we use against the wheel mouse
268 std::size_t m_mouseWheelScrollIncrement;
269 std::size_t m_textureScale;
270 // make the texture increments match the grid changes
272 bool m_showTextureScrollbar;
273 StartupShaders m_startupShaders;
274 // if true, the texture window will only display in-use shaders
275 // if false, all the shaders in memory are displayed
280 // The uniform size (in pixels) that textures are resized to when m_resizeTextures is true.
281 int m_uniformTextureSize;
282 // Return the display width of a texture in the texture browser
283 int getTextureWidth(qtexture_t* tex)
286 if (!g_TextureBrowser_fixedSize)
288 // Don't use uniform size
289 width = (int)(tex->width * ((float)m_textureScale / 100));
291 (tex->width >= tex->height)
293 // Texture is square, or wider than it is tall
294 width = m_uniformTextureSize;
296 // Otherwise, preserve the texture's aspect ratio
297 width = (int)(m_uniformTextureSize * ((float)tex->width / tex->height));
301 // Return the display height of a texture in the texture browser
302 int getTextureHeight(qtexture_t* tex)
305 if (!g_TextureBrowser_fixedSize)
307 // Don't use uniform size
308 height = (int)(tex->height * ((float)m_textureScale / 100));
309 } else if (tex->height >= tex->width)
311 // Texture is square, or taller than it is wide
312 height = m_uniformTextureSize;
314 // Otherwise, preserve the texture's aspect ratio
315 height = (int)(m_uniformTextureSize * ((float)tex->height / tex->width));
322 m_hideunused_item(TextureBrowserHideUnusedExport()),
323 m_showshaders_item(TextureBrowserShowShadersExport()),
324 m_showshaderlistonly_item(TextureBrowserShowShaderlistOnlyExport()),
325 m_fixedsize_item(TextureBrowserFixedSizeExport()),
326 m_filternotex_item(TextureBrowserFilterNotexExport()),
327 m_heightChanged(true),
328 m_originInvalid(true),
329 m_scrollAdjustment(TextureBrowser_scrollChanged, this),
330 color_textureback(0.25f, 0.25f, 0.25f),
331 m_mouseWheelScrollIncrement(64),
334 m_showTextureScrollbar(true),
335 m_startupShaders(STARTUPSHADERS_NONE),
337 m_rmbSelected(false),
338 m_searchedTags(false),
340 m_uniformTextureSize(128)
345 void(*TextureBrowser_textureSelected)(const char* shader);
348 void TextureBrowser_updateScroll(TextureBrowser& textureBrowser);
351 const char* TextureBrowser_getComonShadersName()
353 const char* value = g_pGameDescription->getKeyValue("common_shaders_name");
354 if(!string_empty(value))
361 const char* TextureBrowser_getComonShadersDir()
363 const char* value = g_pGameDescription->getKeyValue("common_shaders_dir");
364 if(!string_empty(value))
371 inline int TextureBrowser_fontHeight(TextureBrowser& textureBrowser)
373 return GlobalOpenGL().m_fontHeight;
376 const char* TextureBrowser_GetSelectedShader(TextureBrowser& textureBrowser)
378 return textureBrowser.shader.c_str();
381 void TextureBrowser_SetStatus(TextureBrowser& textureBrowser, const char* name)
383 IShader* shader = QERApp_Shader_ForName( name);
384 qtexture_t* q = shader->getTexture();
385 StringOutputStream strTex(256);
386 strTex << name << " W: " << Unsigned(q->width) << " H: " << Unsigned(q->height);
388 g_pParentWnd->SetStatusText(g_pParentWnd->m_texture_status, strTex.c_str());
391 void TextureBrowser_Focus(TextureBrowser& textureBrowser, const char* name);
393 void TextureBrowser_SetSelectedShader(TextureBrowser& textureBrowser, const char* shader)
395 textureBrowser.shader = shader;
396 TextureBrowser_SetStatus(textureBrowser, shader);
397 TextureBrowser_Focus(textureBrowser, shader);
399 if(FindTextureDialog_isOpen())
401 FindTextureDialog_selectTexture(shader);
404 // disable the menu item "shader info" if no shader was selected
405 IShader* ishader = QERApp_Shader_ForName(shader);
406 CopiedString filename = ishader->getShaderFileName();
410 if(textureBrowser.m_shader_info_item != NULL)
412 gtk_widget_set_sensitive(textureBrowser.m_shader_info_item, FALSE);
415 gtk_widget_set_sensitive(textureBrowser.m_shader_info_item, TRUE);
422 CopiedString g_TextureBrowser_currentDirectory;
425 ============================================================================
429 TTimo: now based on a rundown through all the shaders
430 NOTE: we expect the Active shaders count doesn't change during a Texture_StartPos .. Texture_NextPos cycle
431 otherwise we may need to rely on a list instead of an array storage
432 ============================================================================
438 // texture layout functions
439 // TTimo: now based on shaders
440 int current_x, current_y, current_row;
443 void Texture_StartPos(TextureLayout& layout)
445 layout.current_x = 8;
446 layout.current_y = -8;
447 layout.current_row = 0;
450 void Texture_NextPos(TextureBrowser& textureBrowser, TextureLayout& layout, qtexture_t* current_texture, int *x, int *y)
452 qtexture_t* q = current_texture;
454 int nWidth = textureBrowser.getTextureWidth(q);
455 int nHeight = textureBrowser.getTextureHeight(q);
456 if (layout.current_x + nWidth > textureBrowser.width-8 && layout.current_row)
457 { // go to the next row unless the texture is the first on the row
458 layout.current_x = 8;
459 layout.current_y -= layout.current_row + TextureBrowser_fontHeight(textureBrowser) + 4;
460 layout.current_row = 0;
463 *x = layout.current_x;
464 *y = layout.current_y;
466 // Is our texture larger than the row? If so, grow the
467 // row height to match it
469 if (layout.current_row < nHeight)
470 layout.current_row = nHeight;
472 // never go less than 96, or the names get all crunched up
473 layout.current_x += nWidth < 96 ? 96 : nWidth;
474 layout.current_x += 8;
477 bool TextureSearch_IsShown(const char* name)
479 std::set<CopiedString>::iterator iter;
481 iter = GlobalTextureBrowser().m_found_shaders.find(name);
483 if(iter == GlobalTextureBrowser().m_found_shaders.end())
491 CopiedString g_notex;
492 CopiedString g_shadernotex;
494 // if texture_showinuse jump over non in-use textures
495 bool Texture_IsShown(IShader* shader, bool show_shaders, bool hideUnused)
497 // filter notex / shadernotex images
498 if(g_TextureBrowser_filterNotex && (string_equal(g_notex.c_str(), shader->getTexture()->name) || string_equal(g_shadernotex.c_str(), shader->getTexture()->name)))
503 if(g_TextureBrowser_currentDirectory == "Untagged")
505 std::set<CopiedString>::iterator iter;
507 iter = GlobalTextureBrowser().m_found_shaders.find(shader->getName());
509 if(iter == GlobalTextureBrowser().m_found_shaders.end())
517 if(!shader_equal_prefix(shader->getName(), "textures/"))
520 if (!show_shaders && !shader->IsDefault())
523 if(hideUnused && !shader->IsInUse())
526 if(GlobalTextureBrowser().m_searchedTags)
528 if(!TextureSearch_IsShown(shader->getName()))
535 if(!shader_equal_prefix(shader_get_textureName(shader->getName()), g_TextureBrowser_currentDirectory.c_str()))
544 void TextureBrowser_heightChanged(TextureBrowser& textureBrowser)
546 textureBrowser.m_heightChanged = true;
548 TextureBrowser_updateScroll(textureBrowser);
549 TextureBrowser_queueDraw(textureBrowser);
552 void TextureBrowser_evaluateHeight(TextureBrowser& textureBrowser)
554 if(textureBrowser.m_heightChanged)
556 textureBrowser.m_heightChanged = false;
558 textureBrowser.m_nTotalHeight = 0;
560 TextureLayout layout;
561 Texture_StartPos(layout);
562 for(QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement())
564 IShader* shader = QERApp_ActiveShaders_IteratorCurrent();
566 if(!Texture_IsShown(shader, textureBrowser.m_showShaders, textureBrowser.m_hideUnused))
570 Texture_NextPos(textureBrowser, layout, shader->getTexture(), &x, &y);
571 textureBrowser.m_nTotalHeight = std::max(textureBrowser.m_nTotalHeight, abs(layout.current_y) + TextureBrowser_fontHeight(textureBrowser) + textureBrowser.getTextureHeight(shader->getTexture()) + 4);
576 int TextureBrowser_TotalHeight(TextureBrowser& textureBrowser)
578 TextureBrowser_evaluateHeight(textureBrowser);
579 return textureBrowser.m_nTotalHeight;
582 inline const int& min_int(const int& left, const int& right)
584 return std::min(left, right);
587 void TextureBrowser_clampOriginY(TextureBrowser& textureBrowser)
589 if(textureBrowser.originy > 0)
591 textureBrowser.originy = 0;
593 int lower = min_int(textureBrowser.height - TextureBrowser_TotalHeight(textureBrowser), 0);
594 if(textureBrowser.originy < lower)
596 textureBrowser.originy = lower;
600 int TextureBrowser_getOriginY(TextureBrowser& textureBrowser)
602 if(textureBrowser.m_originInvalid)
604 textureBrowser.m_originInvalid = false;
605 TextureBrowser_clampOriginY(textureBrowser);
606 TextureBrowser_updateScroll(textureBrowser);
608 return textureBrowser.originy;
611 void TextureBrowser_setOriginY(TextureBrowser& textureBrowser, int originy)
613 textureBrowser.originy = originy;
614 TextureBrowser_clampOriginY(textureBrowser);
615 TextureBrowser_updateScroll(textureBrowser);
616 TextureBrowser_queueDraw(textureBrowser);
620 Signal0 g_activeShadersChangedCallbacks;
622 void TextureBrowser_addActiveShadersChangedCallback(const SignalHandler& handler)
624 g_activeShadersChangedCallbacks.connectLast(handler);
627 class ShadersObserver : public ModuleObserver
629 Signal0 m_realiseCallbacks;
633 m_realiseCallbacks();
638 void insert(const SignalHandler& handler)
640 m_realiseCallbacks.connectLast(handler);
646 ShadersObserver g_ShadersObserver;
649 void TextureBrowser_addShadersRealiseCallback(const SignalHandler& handler)
651 g_ShadersObserver.insert(handler);
654 void TextureBrowser_activeShadersChanged(TextureBrowser& textureBrowser)
656 TextureBrowser_heightChanged(textureBrowser);
657 textureBrowser.m_originInvalid = true;
659 g_activeShadersChangedCallbacks();
662 void TextureBrowser_importShowScrollbar(TextureBrowser& textureBrowser, bool value)
664 textureBrowser.m_showTextureScrollbar = value;
665 if(textureBrowser.m_texture_scroll != 0)
667 widget_set_visible(textureBrowser.m_texture_scroll, textureBrowser.m_showTextureScrollbar);
668 TextureBrowser_updateScroll(textureBrowser);
671 typedef ReferenceCaller1<TextureBrowser, bool, TextureBrowser_importShowScrollbar> TextureBrowserImportShowScrollbarCaller;
676 TextureBrowser_ShowDirectory
677 relies on texture_directory global for the directory to use
678 1) Load the shaders for the given directory
679 2) Scan the remaining texture, load them and assign them a default shader (the "noshader" shader)
680 NOTE: when writing a texture plugin, or some texture extensions, this function may need to be overriden, and made
681 available through the IShaders interface
682 NOTE: for texture window layout:
683 all shaders are stored with alphabetical order after load
684 previously loaded and displayed stuff is hidden, only in-use and newly loaded is shown
685 ( the GL textures are not flushed though)
689 bool endswith(const char *haystack, const char *needle)
691 size_t lh = strlen(haystack);
692 size_t ln = strlen(needle);
695 return !memcmp(haystack + (lh - ln), needle, ln);
698 bool texture_name_ignore(const char* name)
700 StringOutputStream strTemp(string_length(name));
701 strTemp << LowerCase(name);
704 endswith(strTemp.c_str(), ".specular") ||
705 endswith(strTemp.c_str(), ".glow") ||
706 endswith(strTemp.c_str(), ".bump") ||
707 endswith(strTemp.c_str(), ".diffuse") ||
708 endswith(strTemp.c_str(), ".blend") ||
709 endswith(strTemp.c_str(), ".alpha") ||
710 endswith(strTemp.c_str(), "_norm") ||
711 endswith(strTemp.c_str(), "_bump") ||
712 endswith(strTemp.c_str(), "_glow") ||
713 endswith(strTemp.c_str(), "_gloss") ||
714 endswith(strTemp.c_str(), "_pants") ||
715 endswith(strTemp.c_str(), "_shirt") ||
719 class LoadShaderVisitor : public Archive::Visitor
722 void visit(const char* name)
724 IShader* shader = QERApp_Shader_ForName(CopiedString(StringRange(name, path_get_filename_base_end(name))).c_str());
729 void TextureBrowser_SetHideUnused(TextureBrowser& textureBrowser, bool hideUnused);
731 GtkWidget* g_page_textures;
733 void TextureBrowser_toggleShow()
735 GroupDialog_showPage(g_page_textures);
739 void TextureBrowser_updateTitle()
741 GroupDialog_updatePageTitle(g_page_textures);
746 class TextureCategoryLoadShader
748 const char* m_directory;
749 std::size_t& m_count;
751 typedef const char* first_argument_type;
753 TextureCategoryLoadShader(const char* directory, std::size_t& count)
754 : m_directory(directory), m_count(count)
758 void operator()(const char* name) const
760 if(shader_equal_prefix(name, "textures/")
761 && shader_equal_prefix(name + string_length("textures/"), m_directory))
764 // request the shader, this will load the texture if needed
765 // this Shader_ForName call is a kind of hack
766 IShader *pFoo = QERApp_Shader_ForName(name);
772 void TextureDirectory_loadTexture(const char* directory, const char* texture)
774 StringOutputStream name(256);
775 name << directory << StringRange(texture, path_get_filename_base_end(texture));
777 if(texture_name_ignore(name.c_str()))
782 if (!shader_valid(name.c_str()))
784 globalOutputStream() << "Skipping invalid texture name: [" << name.c_str() << "]\n";
788 // if a texture is already in use to represent a shader, ignore it
789 IShader* shader = QERApp_Shader_ForName(name.c_str());
792 typedef ConstPointerCaller1<char, const char*, TextureDirectory_loadTexture> TextureDirectoryLoadTextureCaller;
794 class LoadTexturesByTypeVisitor : public ImageModules::Visitor
796 const char* m_dirstring;
798 LoadTexturesByTypeVisitor(const char* dirstring)
799 : m_dirstring(dirstring)
802 void visit(const char* minor, const _QERPlugImageTable& table) const
804 GlobalFileSystem().forEachFile(m_dirstring, minor, TextureDirectoryLoadTextureCaller(m_dirstring));
808 void TextureBrowser_ShowDirectory(TextureBrowser& textureBrowser, const char* directory)
810 if(TextureBrowser_showWads())
812 Archive* archive = GlobalFileSystem().getArchive(directory);
813 ASSERT_NOTNULL(archive);
814 LoadShaderVisitor visitor;
815 archive->forEachFile(Archive::VisitorFunc(visitor, Archive::eFiles, 0), "textures/");
819 g_TextureBrowser_currentDirectory = directory;
820 TextureBrowser_heightChanged(textureBrowser);
822 std::size_t shaders_count;
823 GlobalShaderSystem().foreachShaderName(makeCallback1(TextureCategoryLoadShader(directory, shaders_count)));
824 globalOutputStream() << "Showing " << Unsigned(shaders_count) << " shaders.\n";
826 if(g_pGameDescription->mGameType != "doom3")
828 // load remaining texture files
830 StringOutputStream dirstring(64);
831 dirstring << "textures/" << directory;
833 Radiant_getImageModules().foreachModule(LoadTexturesByTypeVisitor(dirstring.c_str()));
837 // we'll display the newly loaded textures + all the ones already in use
838 TextureBrowser_SetHideUnused(textureBrowser, false);
840 TextureBrowser_updateTitle();
843 void TextureBrowser_ShowTagSearchResult(TextureBrowser& textureBrowser, const char* directory)
845 g_TextureBrowser_currentDirectory = directory;
846 TextureBrowser_heightChanged(textureBrowser);
848 std::size_t shaders_count;
849 GlobalShaderSystem().foreachShaderName(makeCallback1(TextureCategoryLoadShader(directory, shaders_count)));
850 globalOutputStream() << "Showing " << Unsigned(shaders_count) << " shaders.\n";
852 if(g_pGameDescription->mGameType != "doom3")
854 // load remaining texture files
855 StringOutputStream dirstring(64);
856 dirstring << "textures/" << directory;
859 LoadTexturesByTypeVisitor visitor(dirstring.c_str());
860 Radiant_getImageModules().foreachModule(visitor);
864 // we'll display the newly loaded textures + all the ones already in use
865 TextureBrowser_SetHideUnused(textureBrowser, false);
869 bool TextureBrowser_hideUnused();
871 void TextureBrowser_hideUnusedExport(const BoolImportCallback& importer)
873 importer(TextureBrowser_hideUnused());
875 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_hideUnusedExport> TextureBrowserHideUnusedExport;
877 void TextureBrowser_showShadersExport(const BoolImportCallback& importer)
879 importer(GlobalTextureBrowser().m_showShaders);
881 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_showShadersExport> TextureBrowserShowShadersExport;
883 void TextureBrowser_showShaderlistOnly(const BoolImportCallback& importer)
885 importer(g_TextureBrowser_shaderlistOnly);
887 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_showShaderlistOnly> TextureBrowserShowShaderlistOnlyExport;
889 void TextureBrowser_fixedSize(const BoolImportCallback& importer)
891 importer(g_TextureBrowser_fixedSize);
893 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_fixedSize> TextureBrowser_FixedSizeExport;
895 void TextureBrowser_filterNotex(const BoolImportCallback& importer)
897 importer(g_TextureBrowser_filterNotex);
899 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_filterNotex> TextureBrowser_filterNotexExport;
901 void TextureBrowser_SetHideUnused(TextureBrowser& textureBrowser, bool hideUnused)
905 textureBrowser.m_hideUnused = true;
909 textureBrowser.m_hideUnused = false;
912 textureBrowser.m_hideunused_item.update();
914 TextureBrowser_heightChanged(textureBrowser);
915 textureBrowser.m_originInvalid = true;
918 void TextureBrowser_ShowStartupShaders(TextureBrowser& textureBrowser)
920 if(textureBrowser.m_startupShaders == STARTUPSHADERS_COMMON)
922 TextureBrowser_ShowDirectory(textureBrowser, TextureBrowser_getComonShadersDir());
927 //++timo NOTE: this is a mix of Shader module stuff and texture explorer
928 // it might need to be split in parts or moved out .. dunno
929 // scroll origin so the specified texture is completely on screen
930 // if current texture is not displayed, nothing is changed
931 void TextureBrowser_Focus(TextureBrowser& textureBrowser, const char* name)
933 TextureLayout layout;
934 // scroll origin so the texture is completely on screen
935 Texture_StartPos(layout);
937 for(QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement())
939 IShader* shader = QERApp_ActiveShaders_IteratorCurrent();
941 if(!Texture_IsShown(shader, textureBrowser.m_showShaders, textureBrowser.m_hideUnused))
945 Texture_NextPos(textureBrowser, layout, shader->getTexture(), &x, &y);
946 qtexture_t* q = shader->getTexture();
950 // we have found when texdef->name and the shader name match
951 // NOTE: as everywhere else for our comparisons, we are not case sensitive
952 if (shader_equal(name, shader->getName()))
954 int textureHeight = (int)(q->height * ((float)textureBrowser.m_textureScale / 100))
955 + 2 * TextureBrowser_fontHeight(textureBrowser);
957 int originy = TextureBrowser_getOriginY(textureBrowser);
963 if (y - textureHeight < originy - textureBrowser.height)
965 originy = (y - textureHeight) + textureBrowser.height;
968 TextureBrowser_setOriginY(textureBrowser, originy);
974 IShader* Texture_At(TextureBrowser& textureBrowser, int mx, int my)
976 my += TextureBrowser_getOriginY(textureBrowser) - textureBrowser.height;
978 TextureLayout layout;
979 Texture_StartPos(layout);
980 for(QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement())
982 IShader* shader = QERApp_ActiveShaders_IteratorCurrent();
984 if(!Texture_IsShown(shader, textureBrowser.m_showShaders, textureBrowser.m_hideUnused))
988 Texture_NextPos(textureBrowser, layout, shader->getTexture(), &x, &y);
989 qtexture_t *q = shader->getTexture();
993 int nWidth = textureBrowser.getTextureWidth(q);
994 int nHeight = textureBrowser.getTextureHeight(q);
995 if (mx > x && mx - x < nWidth
996 && my < y && y - my < nHeight + TextureBrowser_fontHeight(textureBrowser))
1012 void SelectTexture(TextureBrowser& textureBrowser, int mx, int my, bool bShift)
1014 IShader* shader = Texture_At(textureBrowser, mx, my);
1019 if (shader->IsDefault())
1020 globalOutputStream() << "ERROR: " << shader->getName() << " is not a shader, it's a texture.\n";
1022 ViewShader( shader->getShaderFileName(), shader->getName() );
1026 TextureBrowser_SetSelectedShader(textureBrowser, shader->getName());
1027 TextureBrowser_textureSelected(shader->getName());
1029 if (!FindTextureDialog_isOpen() && !textureBrowser.m_rmbSelected)
1031 UndoableCommand undo("textureNameSetSelected");
1032 Select_SetShader(shader->getName());
1039 ============================================================================
1043 ============================================================================
1046 void TextureBrowser_trackingDelta(int x, int y, unsigned int state, void* data)
1048 TextureBrowser& textureBrowser = *reinterpret_cast<TextureBrowser*>(data);
1053 if(state & GDK_SHIFT_MASK)
1056 int originy = TextureBrowser_getOriginY(textureBrowser);
1057 originy += y * scale;
1058 TextureBrowser_setOriginY(textureBrowser, originy);
1062 void TextureBrowser_Tracking_MouseDown(TextureBrowser& textureBrowser)
1064 textureBrowser.m_freezePointer.freeze_pointer(textureBrowser.m_parent, TextureBrowser_trackingDelta, &textureBrowser);
1067 void TextureBrowser_Tracking_MouseUp(TextureBrowser& textureBrowser)
1069 textureBrowser.m_freezePointer.unfreeze_pointer(textureBrowser.m_parent);
1072 void TextureBrowser_Selection_MouseDown(TextureBrowser& textureBrowser, guint32 flags, int pointx, int pointy)
1074 SelectTexture(textureBrowser, pointx, textureBrowser.height - 1 - pointy, (flags & GDK_SHIFT_MASK) != 0);
1078 ============================================================================
1082 ============================================================================
1088 TTimo: relying on the shaders list to display the textures
1089 we must query all qtexture_t* to manage and display through the IShaders interface
1090 this allows a plugin to completely override the texture system
1093 void Texture_Draw(TextureBrowser& textureBrowser)
1095 int originy = TextureBrowser_getOriginY(textureBrowser);
1097 glClearColor(textureBrowser.color_textureback[0],
1098 textureBrowser.color_textureback[1],
1099 textureBrowser.color_textureback[2],
1101 glViewport(0, 0, textureBrowser.width, textureBrowser.height);
1102 glMatrixMode(GL_PROJECTION);
1105 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1106 glDisable (GL_DEPTH_TEST);
1107 glDisable(GL_BLEND);
1108 glOrtho (0, textureBrowser.width, originy-textureBrowser.height, originy, -100, 100);
1109 glEnable (GL_TEXTURE_2D);
1111 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
1113 int last_y = 0, last_height = 0;
1115 TextureLayout layout;
1116 Texture_StartPos(layout);
1117 for(QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement())
1119 IShader* shader = QERApp_ActiveShaders_IteratorCurrent();
1121 if(!Texture_IsShown(shader, textureBrowser.m_showShaders, textureBrowser.m_hideUnused))
1125 Texture_NextPos(textureBrowser, layout, shader->getTexture(), &x, &y);
1126 qtexture_t *q = shader->getTexture();
1130 int nWidth = textureBrowser.getTextureWidth(q);
1131 int nHeight = textureBrowser.getTextureHeight(q);
1138 last_height = std::max (nHeight, last_height);
1140 // Is this texture visible?
1141 if ((y-nHeight-TextureBrowser_fontHeight(textureBrowser) < originy)
1142 && (y > originy - textureBrowser.height))
1145 // if it's the current texture, draw a thick red line, else:
1146 // shaders have a white border, simple textures don't
1147 // if !texture_showinuse: (some textures displayed may not be in use)
1148 // draw an additional square around with 0.5 1 0.5 color
1149 if (shader_equal(TextureBrowser_GetSelectedShader(textureBrowser), shader->getName()))
1152 if(textureBrowser.m_rmbSelected)
1158 glDisable (GL_TEXTURE_2D);
1160 glBegin (GL_LINE_LOOP);
1161 glVertex2i (x-4,y-TextureBrowser_fontHeight(textureBrowser)+4);
1162 glVertex2i (x-4,y-TextureBrowser_fontHeight(textureBrowser)-nHeight-4);
1163 glVertex2i (x+4+nWidth,y-TextureBrowser_fontHeight(textureBrowser)-nHeight-4);
1164 glVertex2i (x+4+nWidth,y-TextureBrowser_fontHeight(textureBrowser)+4);
1167 glEnable (GL_TEXTURE_2D);
1174 if (!shader->IsDefault())
1177 glDisable (GL_TEXTURE_2D);
1179 glBegin (GL_LINE_LOOP);
1180 glVertex2i (x-1,y+1-TextureBrowser_fontHeight(textureBrowser));
1181 glVertex2i (x-1,y-nHeight-1-TextureBrowser_fontHeight(textureBrowser));
1182 glVertex2i (x+1+nWidth,y-nHeight-1-TextureBrowser_fontHeight(textureBrowser));
1183 glVertex2i (x+1+nWidth,y+1-TextureBrowser_fontHeight(textureBrowser));
1185 glEnable (GL_TEXTURE_2D);
1188 // highlight in-use textures
1189 if (!textureBrowser.m_hideUnused && shader->IsInUse())
1191 glColor3f (0.5,1,0.5);
1192 glDisable (GL_TEXTURE_2D);
1193 glBegin (GL_LINE_LOOP);
1194 glVertex2i (x-3,y+3-TextureBrowser_fontHeight(textureBrowser));
1195 glVertex2i (x-3,y-nHeight-3-TextureBrowser_fontHeight(textureBrowser));
1196 glVertex2i (x+3+nWidth,y-nHeight-3-TextureBrowser_fontHeight(textureBrowser));
1197 glVertex2i (x+3+nWidth,y+3-TextureBrowser_fontHeight(textureBrowser));
1199 glEnable (GL_TEXTURE_2D);
1204 glBindTexture (GL_TEXTURE_2D, q->texture_number);
1205 GlobalOpenGL_debugAssertNoErrors();
1209 glVertex2i (x,y-TextureBrowser_fontHeight(textureBrowser));
1211 glVertex2i (x+nWidth,y-TextureBrowser_fontHeight(textureBrowser));
1213 glVertex2i (x+nWidth,y-TextureBrowser_fontHeight(textureBrowser)-nHeight);
1215 glVertex2i (x,y-TextureBrowser_fontHeight(textureBrowser)-nHeight);
1218 // draw the texture name
1219 glDisable (GL_TEXTURE_2D);
1222 glRasterPos2i (x, y-TextureBrowser_fontHeight(textureBrowser)+5);
1224 // don't draw the directory name
1225 const char* name = shader->getName();
1226 name += strlen(name);
1227 while(name != shader->getName() && *(name-1) != '/' && *(name-1) != '\\')
1230 GlobalOpenGL().drawString(name);
1231 glEnable (GL_TEXTURE_2D);
1234 //int totalHeight = abs(y) + last_height + TextureBrowser_fontHeight(textureBrowser) + 4;
1238 // reset the current texture
1239 glBindTexture(GL_TEXTURE_2D, 0);
1243 void TextureBrowser_queueDraw(TextureBrowser& textureBrowser)
1245 if(textureBrowser.m_gl_widget != 0)
1247 gtk_widget_queue_draw(textureBrowser.m_gl_widget);
1252 void TextureBrowser_setScale(TextureBrowser& textureBrowser, std::size_t scale)
1254 textureBrowser.m_textureScale = scale;
1256 TextureBrowser_queueDraw(textureBrowser);
1260 void TextureBrowser_MouseWheel(TextureBrowser& textureBrowser, bool bUp)
1262 int originy = TextureBrowser_getOriginY(textureBrowser);
1266 originy += int(textureBrowser.m_mouseWheelScrollIncrement);
1270 originy -= int(textureBrowser.m_mouseWheelScrollIncrement);
1273 TextureBrowser_setOriginY(textureBrowser, originy);
1276 XmlTagBuilder TagBuilder;
1284 void BuildStoreAssignedTags(GtkListStore* store, const char* shader, TextureBrowser* textureBrowser)
1288 gtk_list_store_clear(store);
1290 std::vector<CopiedString> assigned_tags;
1291 TagBuilder.GetShaderTags(shader, assigned_tags);
1293 for (size_t i = 0; i < assigned_tags.size(); i++)
1295 gtk_list_store_append (store, &iter);
1296 gtk_list_store_set (store, &iter, TAG_COLUMN, assigned_tags[i].c_str(), -1);
1300 void BuildStoreAvailableTags( GtkListStore* storeAvailable,
1301 GtkListStore* storeAssigned,
1302 const std::set<CopiedString>& allTags,
1303 TextureBrowser* textureBrowser)
1305 GtkTreeIter iterAssigned;
1306 GtkTreeIter iterAvailable;
1307 std::set<CopiedString>::const_iterator iterAll;
1308 gchar* tag_assigned;
1310 gtk_list_store_clear(storeAvailable);
1312 bool row = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(storeAssigned), &iterAssigned) != 0;
1314 if(!row) // does the shader have tags assigned?
1316 for (iterAll = allTags.begin(); iterAll != allTags.end(); ++iterAll)
1318 gtk_list_store_append (storeAvailable, &iterAvailable);
1319 gtk_list_store_set (storeAvailable, &iterAvailable, TAG_COLUMN, (*iterAll).c_str(), -1);
1324 while(row) // available tags = all tags - assigned tags
1326 gtk_tree_model_get(GTK_TREE_MODEL(storeAssigned), &iterAssigned, TAG_COLUMN, &tag_assigned, -1);
1328 for (iterAll = allTags.begin(); iterAll != allTags.end(); ++iterAll)
1330 if(strcmp((char*)tag_assigned, (*iterAll).c_str()) != 0)
1332 gtk_list_store_append (storeAvailable, &iterAvailable);
1333 gtk_list_store_set (storeAvailable, &iterAvailable, TAG_COLUMN, (*iterAll).c_str(), -1);
1337 row = gtk_tree_model_iter_next(GTK_TREE_MODEL(storeAssigned), &iterAssigned) != 0;
1341 gtk_tree_model_get(GTK_TREE_MODEL(storeAssigned), &iterAssigned, TAG_COLUMN, &tag_assigned, -1);
1349 gboolean TextureBrowser_button_press(GtkWidget* widget, GdkEventButton* event, TextureBrowser* textureBrowser)
1351 if(event->type == GDK_BUTTON_PRESS)
1353 if(event->button == 3)
1355 if(GlobalTextureBrowser().m_tags)
1357 textureBrowser->m_rmbSelected = true;
1358 TextureBrowser_Selection_MouseDown (*textureBrowser, event->state, static_cast<int>(event->x), static_cast<int>(event->y));
1360 BuildStoreAssignedTags(textureBrowser->m_assigned_store, textureBrowser->shader.c_str(), textureBrowser);
1361 BuildStoreAvailableTags(textureBrowser->m_available_store, textureBrowser->m_assigned_store, textureBrowser->m_all_tags, textureBrowser);
1362 textureBrowser->m_heightChanged = true;
1363 gtk_widget_show(textureBrowser->m_tag_frame);
1367 TextureBrowser_Focus(*textureBrowser, textureBrowser->shader.c_str());
1371 TextureBrowser_Tracking_MouseDown(*textureBrowser);
1374 else if(event->button == 1)
1376 TextureBrowser_Selection_MouseDown(*textureBrowser, event->state, static_cast<int>(event->x), static_cast<int>(event->y));
1378 if(GlobalTextureBrowser().m_tags)
1380 textureBrowser->m_rmbSelected = false;
1381 gtk_widget_hide(textureBrowser->m_tag_frame);
1388 gboolean TextureBrowser_button_release(GtkWidget* widget, GdkEventButton* event, TextureBrowser* textureBrowser)
1390 if(event->type == GDK_BUTTON_RELEASE)
1392 if(event->button == 3)
1394 if(!GlobalTextureBrowser().m_tags)
1396 TextureBrowser_Tracking_MouseUp(*textureBrowser);
1403 gboolean TextureBrowser_motion(GtkWidget *widget, GdkEventMotion *event, TextureBrowser* textureBrowser)
1408 gboolean TextureBrowser_scroll(GtkWidget* widget, GdkEventScroll* event, TextureBrowser* textureBrowser)
1410 if(event->direction == GDK_SCROLL_UP)
1412 TextureBrowser_MouseWheel(*textureBrowser, true);
1414 else if(event->direction == GDK_SCROLL_DOWN)
1416 TextureBrowser_MouseWheel(*textureBrowser, false);
1421 void TextureBrowser_scrollChanged(void* data, gdouble value)
1423 //globalOutputStream() << "vertical scroll\n";
1424 TextureBrowser_setOriginY(*reinterpret_cast<TextureBrowser*>(data), -(int)value);
1427 static void TextureBrowser_verticalScroll(GtkAdjustment *adjustment, TextureBrowser* textureBrowser)
1429 textureBrowser->m_scrollAdjustment.value_changed(adjustment->value);
1432 void TextureBrowser_updateScroll(TextureBrowser& textureBrowser)
1434 if(textureBrowser.m_showTextureScrollbar)
1436 int totalHeight = TextureBrowser_TotalHeight(textureBrowser);
1438 totalHeight = std::max(totalHeight, textureBrowser.height);
1440 GtkAdjustment *vadjustment = gtk_range_get_adjustment(GTK_RANGE(textureBrowser.m_texture_scroll));
1442 vadjustment->value = -TextureBrowser_getOriginY(textureBrowser);
1443 vadjustment->page_size = textureBrowser.height;
1444 vadjustment->page_increment = textureBrowser.height/2;
1445 vadjustment->step_increment = 20;
1446 vadjustment->lower = 0;
1447 vadjustment->upper = totalHeight;
1449 g_signal_emit_by_name(G_OBJECT (vadjustment), "changed");
1453 gboolean TextureBrowser_size_allocate(GtkWidget* widget, GtkAllocation* allocation, TextureBrowser* textureBrowser)
1455 textureBrowser->width = allocation->width;
1456 textureBrowser->height = allocation->height;
1457 TextureBrowser_heightChanged(*textureBrowser);
1458 textureBrowser->m_originInvalid = true;
1459 TextureBrowser_queueDraw(*textureBrowser);
1463 gboolean TextureBrowser_expose(GtkWidget* widget, GdkEventExpose* event, TextureBrowser* textureBrowser)
1465 if(glwidget_make_current(textureBrowser->m_gl_widget) != FALSE)
1467 GlobalOpenGL_debugAssertNoErrors();
1468 TextureBrowser_evaluateHeight(*textureBrowser);
1469 Texture_Draw(*textureBrowser);
1470 GlobalOpenGL_debugAssertNoErrors();
1471 glwidget_swap_buffers(textureBrowser->m_gl_widget);
1477 TextureBrowser g_TextureBrowser;
1479 TextureBrowser& GlobalTextureBrowser()
1481 return g_TextureBrowser;
1484 bool TextureBrowser_hideUnused()
1486 return g_TextureBrowser.m_hideUnused;
1489 void TextureBrowser_ToggleHideUnused()
1491 if(g_TextureBrowser.m_hideUnused)
1493 TextureBrowser_SetHideUnused(g_TextureBrowser, false);
1497 TextureBrowser_SetHideUnused(g_TextureBrowser, true);
1501 void TextureGroups_constructTreeModel(TextureGroups groups, GtkTreeStore* store)
1503 // put the information from the old textures menu into a treeview
1504 GtkTreeIter iter, child;
1506 TextureGroups::const_iterator i = groups.begin();
1507 while (i != groups.end())
1509 const char* dirName = (*i).c_str();
1510 const char* firstUnderscore = strchr(dirName, '_');
1511 StringRange dirRoot (dirName, (firstUnderscore == 0) ? dirName : firstUnderscore + 1);
1513 TextureGroups::const_iterator next = i;
1515 if(firstUnderscore != 0
1516 && next != groups.end()
1517 && string_equal_start((*next).c_str(), dirRoot))
1519 gtk_tree_store_append(store, &iter, NULL);
1520 gtk_tree_store_set (store, &iter, 0, CopiedString(StringRange(dirName, firstUnderscore)).c_str(), -1);
1523 while (i != groups.end() && string_equal_start((*i).c_str(), dirRoot))
1525 gtk_tree_store_append(store, &child, &iter);
1526 gtk_tree_store_set (store, &child, 0, (*i).c_str(), -1);
1532 gtk_tree_store_append(store, &iter, NULL);
1533 gtk_tree_store_set (store, &iter, 0, dirName, -1);
1539 TextureGroups TextureGroups_constructTreeView()
1541 TextureGroups groups;
1543 if (TextureBrowser_showWads())
1545 GlobalFileSystem().forEachArchive (TextureGroupsAddWadCaller (groups));
1549 // scan texture dirs and pak files only if not restricting to shaderlist
1550 if (g_pGameDescription->mGameType != "doom3" && !g_TextureBrowser_shaderlistOnly)
1552 GlobalFileSystem().forEachDirectory ("textures/", TextureGroupsAddDirectoryCaller(groups));
1555 GlobalShaderSystem().foreachShaderName(TextureGroupsAddShaderCaller(groups));
1561 void TextureBrowser_constructTreeStore()
1563 TextureGroups groups = TextureGroups_constructTreeView();
1564 GtkTreeStore* store = gtk_tree_store_new(1, G_TYPE_STRING);
1565 TextureGroups_constructTreeModel(groups, store);
1566 std::set<CopiedString>::iterator iter;
1568 GtkTreeModel* model = GTK_TREE_MODEL(store);
1570 gtk_tree_view_set_model(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTree), model);
1572 g_object_unref(G_OBJECT(store));
1575 void TextureBrowser_constructTreeStoreTags()
1577 TextureGroups groups;
1578 GtkTreeStore* store = gtk_tree_store_new(1, G_TYPE_STRING);
1579 GtkTreeModel* model = GTK_TREE_MODEL(g_TextureBrowser.m_all_tags_list);
1581 gtk_tree_view_set_model(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTags), model);
1583 g_object_unref(G_OBJECT(store));
1586 void TreeView_onRowActivated(GtkTreeView* treeview, GtkTreePath* path, GtkTreeViewColumn* col, gpointer userdata)
1590 GtkTreeModel* model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
1592 if (gtk_tree_model_get_iter (model, &iter, path))
1594 gchar dirName[1024];
1597 gtk_tree_model_get(model, &iter, 0, &buffer, -1);
1598 strcpy(dirName, buffer);
1601 g_TextureBrowser.m_searchedTags = false;
1603 if(!TextureBrowser_showWads())
1604 strcat(dirName, "/");
1606 ScopeDisableScreenUpdates disableScreenUpdates(dirName, "Loading Textures");
1607 TextureBrowser_ShowDirectory(GlobalTextureBrowser (), dirName);
1608 TextureBrowser_queueDraw(GlobalTextureBrowser ());
1612 void TextureBrowser_createTreeViewTree()
1614 GtkCellRenderer* renderer;
1615 g_TextureBrowser.m_treeViewTree = GTK_WIDGET(gtk_tree_view_new());
1616 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTree), FALSE);
1618 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTree), FALSE);
1619 g_signal_connect(g_TextureBrowser.m_treeViewTree, "row-activated", (GCallback) TreeView_onRowActivated, NULL);
1621 renderer = gtk_cell_renderer_text_new();
1622 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTree), -1, "", renderer, "text", 0, NULL);
1624 TextureBrowser_constructTreeStore();
1627 void TextureBrowser_addTag();
1628 void TextureBrowser_renameTag();
1629 void TextureBrowser_deleteTag();
1631 void TextureBrowser_createContextMenu(GtkWidget *treeview, GdkEventButton *event)
1633 GtkWidget* menu = gtk_menu_new();
1635 GtkWidget* menuitem = gtk_menu_item_new_with_label("Add tag");
1636 g_signal_connect(menuitem, "activate", (GCallback)TextureBrowser_addTag, treeview);
1637 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
1639 menuitem = gtk_menu_item_new_with_label("Rename tag");
1640 g_signal_connect(menuitem, "activate", (GCallback)TextureBrowser_renameTag, treeview);
1641 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
1643 menuitem = gtk_menu_item_new_with_label("Delete tag");
1644 g_signal_connect(menuitem, "activate", (GCallback)TextureBrowser_deleteTag, treeview);
1645 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
1647 gtk_widget_show_all(menu);
1649 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
1650 (event != NULL) ? event->button : 0,
1651 gdk_event_get_time((GdkEvent*)event));
1654 gboolean TreeViewTags_onButtonPressed(GtkWidget *treeview, GdkEventButton *event)
1656 if (event->type == GDK_BUTTON_PRESS && event->button == 3)
1659 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
1661 if(gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(treeview), event->x, event->y, &path, NULL, NULL, NULL))
1663 gtk_tree_selection_unselect_all(selection);
1664 gtk_tree_selection_select_path(selection, path);
1665 gtk_tree_path_free(path);
1668 TextureBrowser_createContextMenu(treeview, event);
1674 void TextureBrowser_createTreeViewTags()
1676 GtkCellRenderer* renderer;
1677 g_TextureBrowser.m_treeViewTags = GTK_WIDGET(gtk_tree_view_new());
1678 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTags), FALSE);
1680 g_signal_connect(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTags), "button-press-event", (GCallback)TreeViewTags_onButtonPressed, NULL);
1682 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTags), FALSE);
1684 renderer = gtk_cell_renderer_text_new();
1685 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTags), -1, "", renderer, "text", 0, NULL);
1687 TextureBrowser_constructTreeStoreTags();
1690 GtkMenuItem* TextureBrowser_constructViewMenu(GtkMenu* menu)
1692 GtkMenuItem* textures_menu_item = new_sub_menu_item_with_mnemonic("_View");
1694 if(g_Layout_enableDetachableMenus.m_value)
1695 menu_tearoff (menu);
1697 create_check_menu_item_with_mnemonic(menu, "Hide _Unused", "ShowInUse");
1698 if(string_empty(g_pGameDescription->getKeyValue("show_wads")))
1700 create_check_menu_item_with_mnemonic(menu, "Hide Image Missing", "FilterNotex");
1702 menu_separator(menu);
1704 create_menu_item_with_mnemonic(menu, "Show All", "ShowAllTextures");
1706 // we always want to show shaders but don't want a "Show Shaders" menu for doom3 and .wad file games
1707 if(g_pGameDescription->mGameType == "doom3" || !string_empty(g_pGameDescription->getKeyValue("show_wads")))
1709 g_TextureBrowser.m_showShaders = true;
1713 create_check_menu_item_with_mnemonic(menu, "Show shaders", "ToggleShowShaders");
1716 if(g_pGameDescription->mGameType != "doom3" && string_empty(g_pGameDescription->getKeyValue("show_wads")))
1718 create_check_menu_item_with_mnemonic (menu, "Shaders Only", "ToggleShowShaderlistOnly");
1720 if(g_TextureBrowser.m_tags)
1722 create_menu_item_with_mnemonic(menu, "Show Untagged", "ShowUntagged");
1725 create_check_menu_item_with_mnemonic(menu, "Fixed Size", "FixedSize");
1727 if(string_empty(g_pGameDescription->getKeyValue("show_wads")))
1729 menu_separator(menu);
1730 g_TextureBrowser.m_shader_info_item = GTK_WIDGET(create_menu_item_with_mnemonic(menu, "Shader Info", "ShaderInfo"));
1731 gtk_widget_set_sensitive(g_TextureBrowser.m_shader_info_item, FALSE);
1734 return textures_menu_item;
1737 GtkMenuItem* TextureBrowser_constructToolsMenu(GtkMenu* menu)
1739 GtkMenuItem* textures_menu_item = new_sub_menu_item_with_mnemonic("_Tools");
1741 if (g_Layout_enableDetachableMenus.m_value)
1742 menu_tearoff (menu);
1744 create_menu_item_with_mnemonic(menu, "Flush & Reload Shaders", "RefreshShaders");
1745 create_menu_item_with_mnemonic(menu, "Find / Replace...", "FindReplaceTextures");
1747 return textures_menu_item;
1750 GtkMenuItem* TextureBrowser_constructTagsMenu(GtkMenu* menu)
1752 GtkMenuItem* textures_menu_item = new_sub_menu_item_with_mnemonic("T_ags");
1754 if (g_Layout_enableDetachableMenus.m_value)
1755 menu_tearoff (menu);
1757 create_menu_item_with_mnemonic(menu, "Add tag", "AddTag");
1758 create_menu_item_with_mnemonic(menu, "Rename tag", "RenameTag");
1759 create_menu_item_with_mnemonic(menu, "Delete tag", "DeleteTag");
1760 menu_separator(menu);
1761 create_menu_item_with_mnemonic(menu, "Copy tags from selected", "CopyTag");
1762 create_menu_item_with_mnemonic(menu, "Paste tags to selected", "PasteTag");
1764 return textures_menu_item;
1767 gboolean TextureBrowser_tagMoveHelper(GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter, GSList** selected)
1769 g_assert(selected != NULL);
1771 GtkTreeRowReference* rowref = gtk_tree_row_reference_new (model, path);
1772 *selected = g_slist_append(*selected, rowref);
1777 void TextureBrowser_assignTags()
1779 GSList* selected = NULL;
1781 gchar* tag_assigned;
1783 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_TextureBrowser.m_available_tree));
1785 gtk_tree_selection_selected_foreach(selection, (GtkTreeSelectionForeachFunc)TextureBrowser_tagMoveHelper, &selected);
1787 if(selected != NULL)
1789 for (node = selected; node != NULL; node = node->next)
1791 GtkTreePath* path = gtk_tree_row_reference_get_path((GtkTreeRowReference*)node->data);
1797 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(g_TextureBrowser.m_available_store), &iter, path))
1799 gtk_tree_model_get(GTK_TREE_MODEL(g_TextureBrowser.m_available_store), &iter, TAG_COLUMN, &tag_assigned, -1);
1800 if(!TagBuilder.CheckShaderTag(g_TextureBrowser.shader.c_str()))
1802 // create a custom shader/texture entry
1803 IShader* ishader = QERApp_Shader_ForName(g_TextureBrowser.shader.c_str());
1804 CopiedString filename = ishader->getShaderFileName();
1806 if(filename.empty())
1809 TagBuilder.AddShaderNode(g_TextureBrowser.shader.c_str(), CUSTOM, TEXTURE);
1812 TagBuilder.AddShaderNode(g_TextureBrowser.shader.c_str(), CUSTOM, SHADER);
1816 TagBuilder.AddShaderTag(g_TextureBrowser.shader.c_str(), (char*)tag_assigned, TAG);
1818 gtk_list_store_remove(g_TextureBrowser.m_available_store, &iter);
1819 gtk_list_store_append (g_TextureBrowser.m_assigned_store, &iter);
1820 gtk_list_store_set (g_TextureBrowser.m_assigned_store, &iter, TAG_COLUMN, (char*)tag_assigned, -1);
1825 g_slist_foreach(selected, (GFunc)gtk_tree_row_reference_free, NULL);
1828 TagBuilder.SaveXmlDoc();
1830 g_slist_free(selected);
1833 void TextureBrowser_removeTags()
1835 GSList* selected = NULL;
1839 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_TextureBrowser.m_assigned_tree));
1841 gtk_tree_selection_selected_foreach(selection, (GtkTreeSelectionForeachFunc)TextureBrowser_tagMoveHelper, &selected);
1843 if(selected != NULL)
1845 for (node = selected; node != NULL; node = node->next)
1847 GtkTreePath* path = gtk_tree_row_reference_get_path((GtkTreeRowReference*)node->data);
1853 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(g_TextureBrowser.m_assigned_store), &iter, path))
1855 gtk_tree_model_get(GTK_TREE_MODEL(g_TextureBrowser.m_assigned_store), &iter, TAG_COLUMN, &tag, -1);
1856 TagBuilder.DeleteShaderTag(g_TextureBrowser.shader.c_str(), tag);
1857 gtk_list_store_remove(g_TextureBrowser.m_assigned_store, &iter);
1862 g_slist_foreach(selected, (GFunc)gtk_tree_row_reference_free, NULL);
1864 // Update the "available tags list"
1865 BuildStoreAvailableTags(g_TextureBrowser.m_available_store, g_TextureBrowser.m_assigned_store, g_TextureBrowser.m_all_tags, &g_TextureBrowser);
1868 TagBuilder.SaveXmlDoc();
1870 g_slist_free(selected);
1873 void TextureBrowser_buildTagList()
1875 GtkTreeIter treeIter;
1876 gtk_list_store_clear(g_TextureBrowser.m_all_tags_list);
1878 std::set<CopiedString>::iterator iter;
1880 for (iter = g_TextureBrowser.m_all_tags.begin(); iter != g_TextureBrowser.m_all_tags.end(); ++iter)
1882 gtk_list_store_append(g_TextureBrowser.m_all_tags_list, &treeIter);
1883 gtk_list_store_set(g_TextureBrowser.m_all_tags_list, &treeIter, TAG_COLUMN, (*iter).c_str(), -1);
1887 void TextureBrowser_searchTags()
1889 GSList* selected = NULL;
1893 char tags_searched[256];
1895 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTags));
1897 gtk_tree_selection_selected_foreach(selection, (GtkTreeSelectionForeachFunc)TextureBrowser_tagMoveHelper, &selected);
1899 if(selected != NULL)
1901 strcpy(buffer, "/root/*/*[tag='");
1902 strcpy(tags_searched, "[TAGS] ");
1904 for (node = selected; node != NULL; node = node->next)
1906 GtkTreePath* path = gtk_tree_row_reference_get_path((GtkTreeRowReference*)node->data);
1912 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(g_TextureBrowser.m_all_tags_list), &iter, path))
1914 gtk_tree_model_get(GTK_TREE_MODEL(g_TextureBrowser.m_all_tags_list), &iter, TAG_COLUMN, &tag, -1);
1916 strcat(buffer, tag);
1917 strcat(tags_searched, tag);
1918 if(node != g_slist_last(node))
1920 strcat(buffer, "' and tag='");
1921 strcat(tags_searched, ", ");
1927 strcat(buffer, "']");
1929 g_slist_foreach(selected, (GFunc)gtk_tree_row_reference_free, NULL);
1931 g_TextureBrowser.m_found_shaders.clear(); // delete old list
1932 TagBuilder.TagSearch(buffer, g_TextureBrowser.m_found_shaders);
1934 if(!g_TextureBrowser.m_found_shaders.empty()) // found something
1936 size_t shaders_found = g_TextureBrowser.m_found_shaders.size();
1938 globalOutputStream() << "Found " << (unsigned int)shaders_found << " textures and shaders with " << tags_searched << "\n";
1939 ScopeDisableScreenUpdates disableScreenUpdates("Searching...", "Loading Textures");
1941 std::set<CopiedString>::iterator iter;
1943 for(iter = g_TextureBrowser.m_found_shaders.begin(); iter != g_TextureBrowser.m_found_shaders.end(); iter++)
1945 std::string path = (*iter).c_str();
1946 size_t pos = path.find_last_of("/", path.size());
1947 std::string name = path.substr(pos + 1, path.size());
1948 path = path.substr(0, pos + 1);
1949 TextureDirectory_loadTexture(path.c_str(), name.c_str());
1952 g_TextureBrowser.m_searchedTags = true;
1953 g_TextureBrowser_currentDirectory = tags_searched;
1955 g_TextureBrowser.m_nTotalHeight = 0;
1956 TextureBrowser_setOriginY(g_TextureBrowser, 0);
1957 TextureBrowser_heightChanged(g_TextureBrowser);
1958 TextureBrowser_updateTitle();
1960 g_slist_free(selected);
1963 void TextureBrowser_toggleSearchButton()
1965 gint page = gtk_notebook_get_current_page(GTK_NOTEBOOK(g_TextureBrowser.m_tag_notebook));
1967 if(page == 0) // tag page
1969 gtk_widget_show_all(g_TextureBrowser.m_search_button);
1971 gtk_widget_hide_all(g_TextureBrowser.m_search_button);
1975 void TextureBrowser_constructTagNotebook()
1977 g_TextureBrowser.m_tag_notebook = gtk_notebook_new();
1978 GtkWidget* labelTags = gtk_label_new("Tags");
1979 GtkWidget* labelTextures = gtk_label_new("Textures");
1981 gtk_notebook_append_page(GTK_NOTEBOOK(g_TextureBrowser.m_tag_notebook), g_TextureBrowser.m_scr_win_tree, labelTextures);
1982 gtk_notebook_append_page(GTK_NOTEBOOK(g_TextureBrowser.m_tag_notebook), g_TextureBrowser.m_scr_win_tags, labelTags);
1984 g_signal_connect(G_OBJECT(g_TextureBrowser.m_tag_notebook), "switch-page", G_CALLBACK(TextureBrowser_toggleSearchButton), NULL);
1986 gtk_widget_show_all(g_TextureBrowser.m_tag_notebook);
1989 void TextureBrowser_constructSearchButton()
1991 GtkTooltips* tooltips = gtk_tooltips_new();
1993 GtkWidget* image = gtk_image_new_from_stock(GTK_STOCK_FIND, GTK_ICON_SIZE_SMALL_TOOLBAR);
1994 g_TextureBrowser.m_search_button = gtk_button_new();
1995 g_signal_connect(G_OBJECT(g_TextureBrowser.m_search_button), "clicked", G_CALLBACK(TextureBrowser_searchTags), NULL);
1996 gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltips), g_TextureBrowser.m_search_button, "Search with selected tags", "Search with selected tags");
1997 gtk_container_add(GTK_CONTAINER(g_TextureBrowser.m_search_button), image);
2000 void TextureBrowser_checkTagFile()
2002 const char SHADERTAG_FILE[] = "shadertags.xml";
2003 CopiedString default_filename, rc_filename;
2004 StringOutputStream stream(256);
2006 stream << LocalRcPath_get();
2007 stream << SHADERTAG_FILE;
2008 rc_filename = stream.c_str();
2010 if(file_exists(rc_filename.c_str()))
2012 g_TextureBrowser.m_tags = TagBuilder.OpenXmlDoc(rc_filename.c_str());
2014 if(g_TextureBrowser.m_tags)
2016 globalOutputStream() << "Loading tag file " << rc_filename.c_str() << ".\n";
2021 // load default tagfile
2023 stream << g_pGameDescription->mGameToolsPath.c_str();
2024 stream << SHADERTAG_FILE;
2025 default_filename = stream.c_str();
2027 if(file_exists(default_filename.c_str()))
2029 g_TextureBrowser.m_tags = TagBuilder.OpenXmlDoc(default_filename.c_str(), rc_filename.c_str());
2031 if(g_TextureBrowser.m_tags)
2033 globalOutputStream() << "Loading default tag file " << default_filename.c_str() << ".\n";
2038 globalErrorStream() << "Unable to find default tag file " << default_filename.c_str() << ". No tag support.\n";
2043 void TextureBrowser_SetNotex()
2045 StringOutputStream name(256);
2046 name << GlobalRadiant().getAppPath() << "bitmaps/notex.bmp";
2047 g_notex = name.c_str();
2050 name << GlobalRadiant().getAppPath() << "bitmaps/shadernotex.bmp";
2051 g_shadernotex = name.c_str();
2054 GtkWidget* TextureBrowser_constructWindow(GtkWindow* toplevel)
2056 // The gl_widget and the tag assignment frame should be packed into a GtkVPaned with the slider
2057 // position stored in local.pref. gtk_paned_get_position() and gtk_paned_set_position() don't
2058 // seem to work in gtk 2.4 and the arrow buttons don't handle GTK_FILL, so here's another thing
2059 // for the "once-the-gtk-libs-are-updated-TODO-list" :x
2061 TextureBrowser_checkTagFile();
2062 TextureBrowser_SetNotex();
2064 GlobalShaderSystem().setActiveShadersChangedNotify(ReferenceCaller<TextureBrowser, TextureBrowser_activeShadersChanged>(g_TextureBrowser));
2066 g_TextureBrowser.m_parent = toplevel;
2068 GtkWidget* table = gtk_table_new(3, 3, FALSE);
2069 GtkWidget* frame_table = NULL;
2070 GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
2071 gtk_table_attach(GTK_TABLE(table), vbox, 0, 1, 1, 3, GTK_FILL, GTK_FILL, 0, 0);
2072 gtk_widget_show(vbox);
2074 GtkWidget* menu_bar;
2077 menu_bar = gtk_menu_bar_new();
2078 GtkWidget* menu_view = gtk_menu_new();
2079 GtkWidget* view_item = (GtkWidget*)TextureBrowser_constructViewMenu(GTK_MENU(menu_view));
2080 gtk_menu_item_set_submenu(GTK_MENU_ITEM(view_item), menu_view);
2081 gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), view_item);
2083 GtkWidget* menu_tools = gtk_menu_new();
2084 GtkWidget* tools_item = (GtkWidget*)TextureBrowser_constructToolsMenu(GTK_MENU(menu_tools));
2085 gtk_menu_item_set_submenu(GTK_MENU_ITEM(tools_item), menu_tools);
2086 gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), tools_item);
2088 gtk_table_attach(GTK_TABLE (table), menu_bar, 0, 3, 0, 1, GTK_FILL, GTK_SHRINK, 0, 0);
2089 gtk_widget_show(menu_bar);
2091 { // Texture TreeView
2092 g_TextureBrowser.m_scr_win_tree = gtk_scrolled_window_new(NULL, NULL);
2093 gtk_container_set_border_width(GTK_CONTAINER(g_TextureBrowser.m_scr_win_tree), 0);
2095 // vertical only scrolling for treeview
2096 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(g_TextureBrowser.m_scr_win_tree), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
2098 gtk_widget_show(g_TextureBrowser.m_scr_win_tree);
2100 TextureBrowser_createTreeViewTree();
2102 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(g_TextureBrowser.m_scr_win_tree), GTK_WIDGET(g_TextureBrowser.m_treeViewTree));
2103 gtk_widget_show(GTK_WIDGET(g_TextureBrowser.m_treeViewTree));
2105 { // gl_widget scrollbar
2106 GtkWidget* w = gtk_vscrollbar_new(GTK_ADJUSTMENT(gtk_adjustment_new (0,0,0,1,1,0)));
2107 gtk_table_attach(GTK_TABLE (table), w, 2, 3, 1, 2, GTK_SHRINK, GTK_FILL, 0, 0);
2109 g_TextureBrowser.m_texture_scroll = w;
2111 GtkAdjustment *vadjustment = gtk_range_get_adjustment (GTK_RANGE (g_TextureBrowser.m_texture_scroll));
2112 g_signal_connect(G_OBJECT(vadjustment), "value_changed", G_CALLBACK(TextureBrowser_verticalScroll), &g_TextureBrowser);
2114 widget_set_visible(g_TextureBrowser.m_texture_scroll, g_TextureBrowser.m_showTextureScrollbar);
2117 g_TextureBrowser.m_gl_widget = glwidget_new(FALSE);
2118 gtk_widget_ref(g_TextureBrowser.m_gl_widget);
2120 gtk_widget_set_events(g_TextureBrowser.m_gl_widget, GDK_DESTROY | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_SCROLL_MASK);
2121 GTK_WIDGET_SET_FLAGS(g_TextureBrowser.m_gl_widget, GTK_CAN_FOCUS);
2123 gtk_table_attach_defaults(GTK_TABLE(table), g_TextureBrowser.m_gl_widget, 1, 2, 1, 2);
2124 gtk_widget_show(g_TextureBrowser.m_gl_widget);
2126 g_TextureBrowser.m_sizeHandler = g_signal_connect(G_OBJECT(g_TextureBrowser.m_gl_widget), "size_allocate", G_CALLBACK(TextureBrowser_size_allocate), &g_TextureBrowser);
2127 g_TextureBrowser.m_exposeHandler = g_signal_connect(G_OBJECT(g_TextureBrowser.m_gl_widget), "expose_event", G_CALLBACK(TextureBrowser_expose), &g_TextureBrowser);
2129 g_signal_connect(G_OBJECT(g_TextureBrowser.m_gl_widget), "button_press_event", G_CALLBACK(TextureBrowser_button_press), &g_TextureBrowser);
2130 g_signal_connect(G_OBJECT(g_TextureBrowser.m_gl_widget), "button_release_event", G_CALLBACK(TextureBrowser_button_release), &g_TextureBrowser);
2131 g_signal_connect(G_OBJECT(g_TextureBrowser.m_gl_widget), "motion_notify_event", G_CALLBACK(TextureBrowser_motion), &g_TextureBrowser);
2132 g_signal_connect(G_OBJECT(g_TextureBrowser.m_gl_widget), "scroll_event", G_CALLBACK(TextureBrowser_scroll), &g_TextureBrowser);
2136 if(g_TextureBrowser.m_tags)
2138 { // fill tag GtkListStore
2139 g_TextureBrowser.m_all_tags_list = gtk_list_store_new(N_COLUMNS, G_TYPE_STRING);
2140 GtkTreeSortable* sortable = GTK_TREE_SORTABLE(g_TextureBrowser.m_all_tags_list);
2141 gtk_tree_sortable_set_sort_column_id(sortable, TAG_COLUMN, GTK_SORT_ASCENDING);
2143 TagBuilder.GetAllTags(g_TextureBrowser.m_all_tags);
2144 TextureBrowser_buildTagList();
2147 GtkWidget* menu_tags = gtk_menu_new();
2148 GtkWidget* tags_item = (GtkWidget*)TextureBrowser_constructTagsMenu(GTK_MENU(menu_tags));
2149 gtk_menu_item_set_submenu(GTK_MENU_ITEM(tags_item), menu_tags);
2150 gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), tags_item);
2153 g_TextureBrowser.m_scr_win_tags = gtk_scrolled_window_new(NULL, NULL);
2154 gtk_container_set_border_width(GTK_CONTAINER(g_TextureBrowser.m_scr_win_tags), 0);
2156 // vertical only scrolling for treeview
2157 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(g_TextureBrowser.m_scr_win_tags), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
2159 TextureBrowser_createTreeViewTags();
2161 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTags));
2162 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
2164 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW (g_TextureBrowser.m_scr_win_tags), GTK_WIDGET (g_TextureBrowser.m_treeViewTags));
2165 gtk_widget_show(GTK_WIDGET(g_TextureBrowser.m_treeViewTags));
2167 { // Texture/Tag notebook
2168 TextureBrowser_constructTagNotebook();
2169 gtk_box_pack_start(GTK_BOX(vbox), g_TextureBrowser.m_tag_notebook, TRUE, TRUE, 0);
2171 { // Tag search button
2172 TextureBrowser_constructSearchButton();
2173 gtk_box_pack_end(GTK_BOX(vbox), g_TextureBrowser.m_search_button, FALSE, FALSE, 0);
2176 frame_table = gtk_table_new(3, 3, FALSE);
2178 g_TextureBrowser.m_tag_frame = gtk_frame_new("Tag assignment");
2179 gtk_frame_set_label_align(GTK_FRAME(g_TextureBrowser.m_tag_frame), 0.5, 0.5);
2180 gtk_frame_set_shadow_type(GTK_FRAME(g_TextureBrowser.m_tag_frame), GTK_SHADOW_NONE);
2182 gtk_table_attach(GTK_TABLE(table), g_TextureBrowser.m_tag_frame, 1, 3, 2, 3, GTK_FILL, GTK_SHRINK, 0, 0);
2184 gtk_widget_show(frame_table);
2186 gtk_container_add (GTK_CONTAINER(g_TextureBrowser.m_tag_frame), frame_table);
2188 { // assigned tag list
2189 GtkWidget* scrolled_win = gtk_scrolled_window_new(NULL, NULL);
2190 gtk_container_set_border_width(GTK_CONTAINER (scrolled_win), 0);
2191 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled_win), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
2193 g_TextureBrowser.m_assigned_store = gtk_list_store_new(N_COLUMNS, G_TYPE_STRING);
2195 GtkTreeSortable* sortable = GTK_TREE_SORTABLE(g_TextureBrowser.m_assigned_store);
2196 gtk_tree_sortable_set_sort_column_id(sortable, TAG_COLUMN, GTK_SORT_ASCENDING);
2198 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
2200 g_TextureBrowser.m_assigned_tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL (g_TextureBrowser.m_assigned_store));
2201 g_object_unref(G_OBJECT (g_TextureBrowser.m_assigned_store));
2202 g_signal_connect(g_TextureBrowser.m_assigned_tree, "row-activated", (GCallback) TextureBrowser_removeTags, NULL);
2203 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW (g_TextureBrowser.m_assigned_tree), FALSE);
2205 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_TextureBrowser.m_assigned_tree));
2206 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
2208 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes("", renderer, "text", TAG_COLUMN, NULL);
2209 gtk_tree_view_append_column(GTK_TREE_VIEW (g_TextureBrowser.m_assigned_tree), column);
2210 gtk_widget_show(g_TextureBrowser.m_assigned_tree);
2212 gtk_widget_show(scrolled_win);
2213 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW (scrolled_win), GTK_WIDGET (g_TextureBrowser.m_assigned_tree));
2215 gtk_table_attach(GTK_TABLE(frame_table), scrolled_win, 0, 1, 1, 3, GTK_FILL, GTK_FILL, 0, 0);
2217 { // available tag list
2218 GtkWidget* scrolled_win = gtk_scrolled_window_new (NULL, NULL);
2219 gtk_container_set_border_width (GTK_CONTAINER (scrolled_win), 0);
2220 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
2222 g_TextureBrowser.m_available_store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING);
2223 GtkTreeSortable* sortable = GTK_TREE_SORTABLE(g_TextureBrowser.m_available_store);
2224 gtk_tree_sortable_set_sort_column_id(sortable, TAG_COLUMN, GTK_SORT_ASCENDING);
2226 GtkCellRenderer* renderer = gtk_cell_renderer_text_new ();
2228 g_TextureBrowser.m_available_tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (g_TextureBrowser.m_available_store));
2229 g_object_unref (G_OBJECT (g_TextureBrowser.m_available_store));
2230 g_signal_connect(g_TextureBrowser.m_available_tree, "row-activated", (GCallback) TextureBrowser_assignTags, NULL);
2231 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (g_TextureBrowser.m_available_tree), FALSE);
2233 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_TextureBrowser.m_available_tree));
2234 gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
2236 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes ("", renderer, "text", TAG_COLUMN, NULL);
2237 gtk_tree_view_append_column (GTK_TREE_VIEW (g_TextureBrowser.m_available_tree), column);
2238 gtk_widget_show (g_TextureBrowser.m_available_tree);
2240 gtk_widget_show (scrolled_win);
2241 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win), GTK_WIDGET (g_TextureBrowser.m_available_tree));
2243 gtk_table_attach (GTK_TABLE (frame_table), scrolled_win, 2, 3, 1, 3, GTK_FILL, GTK_FILL, 0, 0);
2245 { // tag arrow buttons
2246 GtkWidget* m_btn_left = gtk_button_new();
2247 GtkWidget* m_btn_right = gtk_button_new();
2248 GtkWidget* m_arrow_left = gtk_arrow_new(GTK_ARROW_LEFT, GTK_SHADOW_OUT);
2249 GtkWidget* m_arrow_right = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_OUT);
2250 gtk_container_add(GTK_CONTAINER(m_btn_left), m_arrow_left);
2251 gtk_container_add(GTK_CONTAINER(m_btn_right), m_arrow_right);
2253 // workaround. the size of the tag frame depends of the requested size of the arrow buttons.
2254 gtk_widget_set_size_request(m_arrow_left, -1, 68);
2255 gtk_widget_set_size_request(m_arrow_right, -1, 68);
2257 gtk_table_attach(GTK_TABLE(frame_table), m_btn_left, 1, 2, 1, 2, GTK_SHRINK, GTK_EXPAND, 0, 0);
2258 gtk_table_attach(GTK_TABLE(frame_table), m_btn_right, 1, 2, 2, 3, GTK_SHRINK, GTK_EXPAND, 0, 0);
2260 g_signal_connect(G_OBJECT (m_btn_left), "clicked", G_CALLBACK(TextureBrowser_assignTags), NULL);
2261 g_signal_connect(G_OBJECT (m_btn_right), "clicked", G_CALLBACK(TextureBrowser_removeTags), NULL);
2263 gtk_widget_show(m_btn_left);
2264 gtk_widget_show(m_btn_right);
2265 gtk_widget_show(m_arrow_left);
2266 gtk_widget_show(m_arrow_right);
2268 { // tag fram labels
2269 GtkWidget* m_lbl_assigned = gtk_label_new ("Assigned");
2270 GtkWidget* m_lbl_unassigned = gtk_label_new ("Available");
2272 gtk_table_attach (GTK_TABLE (frame_table), m_lbl_assigned, 0, 1, 0, 1, GTK_EXPAND, GTK_SHRINK, 0, 0);
2273 gtk_table_attach (GTK_TABLE (frame_table), m_lbl_unassigned, 2, 3, 0, 1, GTK_EXPAND, GTK_SHRINK, 0, 0);
2275 gtk_widget_show (m_lbl_assigned);
2276 gtk_widget_show (m_lbl_unassigned);
2278 } else { // no tag support, show the texture tree only
2279 gtk_box_pack_start(GTK_BOX(vbox), g_TextureBrowser.m_scr_win_tree, TRUE, TRUE, 0);
2282 // TODO do we need this?
2283 //gtk_container_set_focus_chain(GTK_CONTAINER(hbox_table), NULL);
2288 void TextureBrowser_destroyWindow()
2290 GlobalShaderSystem().setActiveShadersChangedNotify(Callback());
2292 g_signal_handler_disconnect(G_OBJECT(g_TextureBrowser.m_gl_widget), g_TextureBrowser.m_sizeHandler);
2293 g_signal_handler_disconnect(G_OBJECT(g_TextureBrowser.m_gl_widget), g_TextureBrowser.m_exposeHandler);
2295 gtk_widget_unref(g_TextureBrowser.m_gl_widget);
2298 const Vector3& TextureBrowser_getBackgroundColour(TextureBrowser& textureBrowser)
2300 return textureBrowser.color_textureback;
2303 void TextureBrowser_setBackgroundColour(TextureBrowser& textureBrowser, const Vector3& colour)
2305 textureBrowser.color_textureback = colour;
2306 TextureBrowser_queueDraw(textureBrowser);
2309 void TextureBrowser_selectionHelper(GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter, GSList** selected)
2311 g_assert(selected != NULL);
2314 gtk_tree_model_get(model, iter, TAG_COLUMN, &name, -1);
2315 *selected = g_slist_append(*selected, name);
2318 void TextureBrowser_shaderInfo()
2320 const char* name = TextureBrowser_GetSelectedShader(g_TextureBrowser);
2321 IShader* shader = QERApp_Shader_ForName(name);
2323 DoShaderInfoDlg(name, shader->getShaderFileName(), "Shader Info");
2328 void TextureBrowser_addTag()
2332 EMessageBoxReturn result = DoShaderTagDlg(&tag, "Add shader tag");
2334 if (result == eIDOK && !tag.empty())
2336 GtkTreeIter iter, iter2;
2337 g_TextureBrowser.m_all_tags.insert(tag.c_str());
2338 gtk_list_store_append(g_TextureBrowser.m_available_store, &iter);
2339 gtk_list_store_set(g_TextureBrowser.m_available_store, &iter, TAG_COLUMN, tag.c_str(), -1);
2341 // Select the currently added tag in the available list
2342 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_TextureBrowser.m_available_tree));
2343 gtk_tree_selection_select_iter(selection, &iter);
2345 gtk_list_store_append(g_TextureBrowser.m_all_tags_list, &iter2);
2346 gtk_list_store_set(g_TextureBrowser.m_all_tags_list, &iter2, TAG_COLUMN, tag.c_str(), -1);
2350 void TextureBrowser_renameTag()
2352 /* WORKAROUND: The tag treeview is set to GTK_SELECTION_MULTIPLE. Because
2353 gtk_tree_selection_get_selected() doesn't work with GTK_SELECTION_MULTIPLE,
2354 we need to count the number of selected rows first and use
2355 gtk_tree_selection_selected_foreach() then to go through the list of selected
2356 rows (which always containins a single row).
2359 GSList* selected = NULL;
2361 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTags));
2362 gtk_tree_selection_selected_foreach(selection, GtkTreeSelectionForeachFunc(TextureBrowser_selectionHelper), &selected);
2364 if(g_slist_length(selected) == 1) // we only rename a single tag
2366 CopiedString newTag;
2367 EMessageBoxReturn result = DoShaderTagDlg(&newTag, "Rename shader tag");
2369 if (result == eIDOK && !newTag.empty())
2371 GtkTreeIter iterList;
2373 gchar* oldTag = (char*)selected->data;
2375 bool row = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(g_TextureBrowser.m_all_tags_list), &iterList) != 0;
2379 gtk_tree_model_get(GTK_TREE_MODEL(g_TextureBrowser.m_all_tags_list), &iterList, TAG_COLUMN, &rowTag, -1);
2381 if(strcmp(rowTag, oldTag) == 0)
2383 gtk_list_store_set(g_TextureBrowser.m_all_tags_list, &iterList, TAG_COLUMN, newTag.c_str(), -1);
2385 row = gtk_tree_model_iter_next(GTK_TREE_MODEL(g_TextureBrowser.m_all_tags_list), &iterList) != 0;
2388 TagBuilder.RenameShaderTag(oldTag, newTag.c_str());
2390 g_TextureBrowser.m_all_tags.erase((CopiedString)oldTag);
2391 g_TextureBrowser.m_all_tags.insert(newTag);
2393 BuildStoreAssignedTags(g_TextureBrowser.m_assigned_store, g_TextureBrowser.shader.c_str(), &g_TextureBrowser);
2394 BuildStoreAvailableTags(g_TextureBrowser.m_available_store, g_TextureBrowser.m_assigned_store, g_TextureBrowser.m_all_tags, &g_TextureBrowser);
2399 gtk_MessageBox(GTK_WIDGET(g_TextureBrowser.m_parent), "Select a single tag for renaming.");
2403 void TextureBrowser_deleteTag()
2405 GSList* selected = NULL;
2407 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTags));
2408 gtk_tree_selection_selected_foreach(selection, GtkTreeSelectionForeachFunc(TextureBrowser_selectionHelper), &selected);
2410 if(g_slist_length(selected) == 1) // we only delete a single tag
2412 EMessageBoxReturn result = gtk_MessageBox(GTK_WIDGET(g_TextureBrowser.m_parent), "Are you sure you want to delete the selected tag?", "Delete Tag", eMB_YESNO, eMB_ICONQUESTION);
2414 if(result == eIDYES)
2416 GtkTreeIter iterSelected;
2419 gchar* tagSelected = (char*)selected->data;
2421 bool row = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(g_TextureBrowser.m_all_tags_list), &iterSelected) != 0;
2425 gtk_tree_model_get(GTK_TREE_MODEL(g_TextureBrowser.m_all_tags_list), &iterSelected, TAG_COLUMN, &rowTag, -1);
2427 if(strcmp(rowTag, tagSelected) == 0)
2429 gtk_list_store_remove(g_TextureBrowser.m_all_tags_list, &iterSelected);
2432 row = gtk_tree_model_iter_next(GTK_TREE_MODEL(g_TextureBrowser.m_all_tags_list), &iterSelected) != 0;
2435 TagBuilder.DeleteTag(tagSelected);
2436 g_TextureBrowser.m_all_tags.erase((CopiedString)tagSelected);
2438 BuildStoreAssignedTags(g_TextureBrowser.m_assigned_store, g_TextureBrowser.shader.c_str(), &g_TextureBrowser);
2439 BuildStoreAvailableTags(g_TextureBrowser.m_available_store, g_TextureBrowser.m_assigned_store, g_TextureBrowser.m_all_tags, &g_TextureBrowser);
2442 gtk_MessageBox(GTK_WIDGET(g_TextureBrowser.m_parent), "Select a single tag for deletion.");
2446 void TextureBrowser_copyTag()
2448 g_TextureBrowser.m_copied_tags.clear();
2449 TagBuilder.GetShaderTags(g_TextureBrowser.shader.c_str(), g_TextureBrowser.m_copied_tags);
2452 void TextureBrowser_pasteTag()
2454 IShader* ishader = QERApp_Shader_ForName(g_TextureBrowser.shader.c_str());
2455 CopiedString shader = g_TextureBrowser.shader.c_str();
2457 if(!TagBuilder.CheckShaderTag(shader.c_str()))
2459 CopiedString shaderFile = ishader->getShaderFileName();
2460 if(shaderFile.empty())
2463 TagBuilder.AddShaderNode(shader.c_str(), CUSTOM, TEXTURE);
2468 TagBuilder.AddShaderNode(shader.c_str(), CUSTOM, SHADER);
2471 for(size_t i = 0; i < g_TextureBrowser.m_copied_tags.size(); ++i)
2473 TagBuilder.AddShaderTag(shader.c_str(), g_TextureBrowser.m_copied_tags[i].c_str(), TAG);
2478 for(size_t i = 0; i < g_TextureBrowser.m_copied_tags.size(); ++i)
2480 if(!TagBuilder.CheckShaderTag(shader.c_str(), g_TextureBrowser.m_copied_tags[i].c_str()))
2482 // the tag doesn't exist - let's add it
2483 TagBuilder.AddShaderTag(shader.c_str(), g_TextureBrowser.m_copied_tags[i].c_str(), TAG);
2490 TagBuilder.SaveXmlDoc();
2491 BuildStoreAssignedTags(g_TextureBrowser.m_assigned_store, shader.c_str(), &g_TextureBrowser);
2492 BuildStoreAvailableTags (g_TextureBrowser.m_available_store, g_TextureBrowser.m_assigned_store, g_TextureBrowser.m_all_tags, &g_TextureBrowser);
2495 void RefreshShaders()
2497 ScopeDisableScreenUpdates disableScreenUpdates("Processing...", "Loading Shaders");
2498 GlobalShaderSystem().refresh();
2502 void TextureBrowser_ToggleShowShaders()
2504 g_TextureBrowser.m_showShaders ^= 1;
2505 g_TextureBrowser.m_showshaders_item.update();
2506 TextureBrowser_queueDraw(g_TextureBrowser);
2509 void TextureBrowser_ToggleShowShaderListOnly()
2511 g_TextureBrowser_shaderlistOnly ^= 1;
2512 g_TextureBrowser.m_showshaderlistonly_item.update();
2514 TextureBrowser_constructTreeStore();
2517 void TextureBrowser_showAll()
2519 g_TextureBrowser_currentDirectory = "";
2520 g_TextureBrowser.m_searchedTags = false;
2521 TextureBrowser_heightChanged(g_TextureBrowser);
2522 TextureBrowser_updateTitle();
2525 void TextureBrowser_showUntagged()
2527 EMessageBoxReturn result = gtk_MessageBox(GTK_WIDGET(g_TextureBrowser.m_parent), "WARNING! This function might need a lot of memory and time. Are you sure you want to use it?", "Show Untagged", eMB_YESNO, eMB_ICONWARNING);
2529 if(result == eIDYES)
2531 g_TextureBrowser.m_found_shaders.clear();
2532 TagBuilder.GetUntagged(g_TextureBrowser.m_found_shaders);
2533 std::set<CopiedString>::iterator iter;
2535 ScopeDisableScreenUpdates disableScreenUpdates("Searching untagged textures...", "Loading Textures");
2537 for(iter = g_TextureBrowser.m_found_shaders.begin(); iter != g_TextureBrowser.m_found_shaders.end(); iter++)
2539 std::string path = (*iter).c_str();
2540 size_t pos = path.find_last_of("/", path.size());
2541 std::string name = path.substr(pos + 1, path.size());
2542 path = path.substr(0, pos + 1);
2543 TextureDirectory_loadTexture(path.c_str(), name.c_str());
2544 globalErrorStream() << path.c_str() << name.c_str() << "\n";
2547 g_TextureBrowser_currentDirectory = "Untagged";
2548 TextureBrowser_queueDraw(GlobalTextureBrowser());
2549 TextureBrowser_heightChanged(g_TextureBrowser);
2550 TextureBrowser_updateTitle();
2554 void TextureBrowser_FixedSize()
2556 g_TextureBrowser_fixedSize ^= 1;
2557 GlobalTextureBrowser().m_fixedsize_item.update();
2558 TextureBrowser_activeShadersChanged(GlobalTextureBrowser());
2561 void TextureBrowser_FilterNotex()
2563 g_TextureBrowser_filterNotex ^= 1;
2564 GlobalTextureBrowser().m_filternotex_item.update();
2565 TextureBrowser_activeShadersChanged(GlobalTextureBrowser());
2568 void TextureBrowser_exportTitle(const StringImportCallback& importer)
2570 StringOutputStream buffer(64);
2571 buffer << "Textures: ";
2572 if(!string_empty(g_TextureBrowser_currentDirectory.c_str()))
2574 buffer << g_TextureBrowser_currentDirectory.c_str();
2580 importer(buffer.c_str());
2584 void TextureScaleImport(TextureBrowser& textureBrowser, int value)
2589 TextureBrowser_setScale(textureBrowser, 10);
2592 TextureBrowser_setScale(textureBrowser, 25);
2595 TextureBrowser_setScale(textureBrowser, 50);
2598 TextureBrowser_setScale(textureBrowser, 100);
2601 TextureBrowser_setScale(textureBrowser, 200);
2605 typedef ReferenceCaller1<TextureBrowser, int, TextureScaleImport> TextureScaleImportCaller;
2607 void TextureScaleExport(TextureBrowser& textureBrowser, const IntImportCallback& importer)
2609 switch(textureBrowser.m_textureScale)
2628 typedef ReferenceCaller1<TextureBrowser, const IntImportCallback&, TextureScaleExport> TextureScaleExportCaller;
2630 void TextureBrowser_constructPreferences(PreferencesPage& page)
2632 page.appendCheckBox(
2633 "", "Texture scrollbar",
2634 TextureBrowserImportShowScrollbarCaller(GlobalTextureBrowser()),
2635 BoolExportCaller(GlobalTextureBrowser().m_showTextureScrollbar)
2638 const char* texture_scale[] = { "10%", "25%", "50%", "100%", "200%" };
2640 "Texture Thumbnail Scale",
2641 STRING_ARRAY_RANGE(texture_scale),
2642 IntImportCallback(TextureScaleImportCaller(GlobalTextureBrowser())),
2643 IntExportCallback(TextureScaleExportCaller(GlobalTextureBrowser()))
2646 page.appendEntry("Mousewheel Increment", GlobalTextureBrowser().m_mouseWheelScrollIncrement);
2648 const char* startup_shaders[] = { "None", TextureBrowser_getComonShadersName() };
2649 page.appendCombo("Load Shaders at Startup", reinterpret_cast<int&>(GlobalTextureBrowser().m_startupShaders), STRING_ARRAY_RANGE(startup_shaders));
2652 void TextureBrowser_constructPage(PreferenceGroup& group)
2654 PreferencesPage page(group.createPage("Texture Browser", "Texture Browser Preferences"));
2655 TextureBrowser_constructPreferences(page);
2657 void TextureBrowser_registerPreferencesPage()
2659 PreferencesDialog_addSettingsPage(FreeCaller1<PreferenceGroup&, TextureBrowser_constructPage>());
2663 #include "preferencesystem.h"
2664 #include "stringio.h"
2666 typedef ReferenceCaller1<TextureBrowser, std::size_t, TextureBrowser_setScale> TextureBrowserSetScaleCaller;
2670 void TextureClipboard_textureSelected(const char* shader);
2672 void TextureBrowser_Construct()
2674 GlobalCommands_insert("ShaderInfo", FreeCaller<TextureBrowser_shaderInfo>());
2675 GlobalCommands_insert("ShowUntagged", FreeCaller<TextureBrowser_showUntagged>());
2676 GlobalCommands_insert("AddTag", FreeCaller<TextureBrowser_addTag>());
2677 GlobalCommands_insert("RenameTag", FreeCaller<TextureBrowser_renameTag>());
2678 GlobalCommands_insert("DeleteTag", FreeCaller<TextureBrowser_deleteTag>());
2679 GlobalCommands_insert("CopyTag", FreeCaller<TextureBrowser_copyTag>());
2680 GlobalCommands_insert("PasteTag", FreeCaller<TextureBrowser_pasteTag>());
2681 GlobalCommands_insert("RefreshShaders", FreeCaller<RefreshShaders>());
2682 GlobalToggles_insert("ShowInUse", FreeCaller<TextureBrowser_ToggleHideUnused>(), ToggleItem::AddCallbackCaller(g_TextureBrowser.m_hideunused_item), Accelerator('U'));
2683 GlobalCommands_insert("ShowAllTextures", FreeCaller<TextureBrowser_showAll>(), Accelerator('A', (GdkModifierType)GDK_CONTROL_MASK));
2684 GlobalCommands_insert("ToggleTextures", FreeCaller<TextureBrowser_toggleShow>(), Accelerator('T'));
2685 GlobalToggles_insert("ToggleShowShaders", FreeCaller<TextureBrowser_ToggleShowShaders>(), ToggleItem::AddCallbackCaller(g_TextureBrowser.m_showshaders_item));
2686 GlobalToggles_insert("ToggleShowShaderlistOnly", FreeCaller<TextureBrowser_ToggleShowShaderListOnly>(), ToggleItem::AddCallbackCaller(g_TextureBrowser.m_showshaderlistonly_item));
2687 GlobalToggles_insert("FixedSize", FreeCaller<TextureBrowser_FixedSize>(), ToggleItem::AddCallbackCaller(g_TextureBrowser.m_fixedsize_item));
2688 GlobalToggles_insert("FilterNotex", FreeCaller<TextureBrowser_FilterNotex>(), ToggleItem::AddCallbackCaller(g_TextureBrowser.m_filternotex_item));
2690 GlobalPreferenceSystem().registerPreference("TextureScale",
2691 makeSizeStringImportCallback(TextureBrowserSetScaleCaller(g_TextureBrowser)),
2692 SizeExportStringCaller(g_TextureBrowser.m_textureScale)
2694 GlobalPreferenceSystem().registerPreference("TextureScrollbar",
2695 makeBoolStringImportCallback(TextureBrowserImportShowScrollbarCaller(g_TextureBrowser)),
2696 BoolExportStringCaller(GlobalTextureBrowser().m_showTextureScrollbar)
2698 GlobalPreferenceSystem().registerPreference("ShowShaders", BoolImportStringCaller(GlobalTextureBrowser().m_showShaders), BoolExportStringCaller(GlobalTextureBrowser().m_showShaders));
2699 GlobalPreferenceSystem().registerPreference("ShowShaderlistOnly", BoolImportStringCaller(g_TextureBrowser_shaderlistOnly), BoolExportStringCaller(g_TextureBrowser_shaderlistOnly));
2700 GlobalPreferenceSystem().registerPreference("FixedSize", BoolImportStringCaller(g_TextureBrowser_fixedSize), BoolExportStringCaller(g_TextureBrowser_fixedSize));
2701 GlobalPreferenceSystem().registerPreference("FilterNotex", BoolImportStringCaller(g_TextureBrowser_filterNotex), BoolExportStringCaller(g_TextureBrowser_filterNotex));
2702 GlobalPreferenceSystem().registerPreference("LoadShaders", IntImportStringCaller(reinterpret_cast<int&>(GlobalTextureBrowser().m_startupShaders)), IntExportStringCaller(reinterpret_cast<int&>(GlobalTextureBrowser().m_startupShaders)));
2703 GlobalPreferenceSystem().registerPreference("WheelMouseInc", SizeImportStringCaller(GlobalTextureBrowser().m_mouseWheelScrollIncrement), SizeExportStringCaller(GlobalTextureBrowser().m_mouseWheelScrollIncrement));
2704 GlobalPreferenceSystem().registerPreference("SI_Colors0", Vector3ImportStringCaller(GlobalTextureBrowser().color_textureback), Vector3ExportStringCaller(GlobalTextureBrowser().color_textureback));
2706 g_TextureBrowser.shader = texdef_name_default();
2708 Textures_setModeChangedNotify(ReferenceCaller<TextureBrowser, TextureBrowser_queueDraw>(g_TextureBrowser));
2710 TextureBrowser_registerPreferencesPage();
2712 GlobalShaderSystem().attach(g_ShadersObserver);
2714 TextureBrowser_textureSelected = TextureClipboard_textureSelected;
2716 void TextureBrowser_Destroy()
2718 GlobalShaderSystem().detach(g_ShadersObserver);
2720 Textures_setModeChangedNotify(Callback());