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)
688 bool texture_name_ignore(const char* name)
690 StringOutputStream strTemp(string_length(name));
691 strTemp << LowerCase(name);
693 return strstr(strTemp.c_str(), ".specular") != 0 ||
694 strstr(strTemp.c_str(), ".glow") != 0 ||
695 strstr(strTemp.c_str(), ".bump") != 0 ||
696 strstr(strTemp.c_str(), ".diffuse") != 0 ||
697 strstr(strTemp.c_str(), ".blend") != 0 ||
698 strstr(strTemp.c_str(), ".alpha") != 0;
701 class LoadShaderVisitor : public Archive::Visitor
704 void visit(const char* name)
706 IShader* shader = QERApp_Shader_ForName(CopiedString(StringRange(name, path_get_filename_base_end(name))).c_str());
711 void TextureBrowser_SetHideUnused(TextureBrowser& textureBrowser, bool hideUnused);
713 GtkWidget* g_page_textures;
715 void TextureBrowser_toggleShow()
717 GroupDialog_showPage(g_page_textures);
721 void TextureBrowser_updateTitle()
723 GroupDialog_updatePageTitle(g_page_textures);
728 class TextureCategoryLoadShader
730 const char* m_directory;
731 std::size_t& m_count;
733 typedef const char* first_argument_type;
735 TextureCategoryLoadShader(const char* directory, std::size_t& count)
736 : m_directory(directory), m_count(count)
740 void operator()(const char* name) const
742 if(shader_equal_prefix(name, "textures/")
743 && shader_equal_prefix(name + string_length("textures/"), m_directory))
746 // request the shader, this will load the texture if needed
747 // this Shader_ForName call is a kind of hack
748 IShader *pFoo = QERApp_Shader_ForName(name);
754 void TextureDirectory_loadTexture(const char* directory, const char* texture)
756 StringOutputStream name(256);
757 name << directory << StringRange(texture, path_get_filename_base_end(texture));
759 if(texture_name_ignore(name.c_str()))
764 if (!shader_valid(name.c_str()))
766 globalOutputStream() << "Skipping invalid texture name: [" << name.c_str() << "]\n";
770 // if a texture is already in use to represent a shader, ignore it
771 IShader* shader = QERApp_Shader_ForName(name.c_str());
774 typedef ConstPointerCaller1<char, const char*, TextureDirectory_loadTexture> TextureDirectoryLoadTextureCaller;
776 class LoadTexturesByTypeVisitor : public ImageModules::Visitor
778 const char* m_dirstring;
780 LoadTexturesByTypeVisitor(const char* dirstring)
781 : m_dirstring(dirstring)
784 void visit(const char* minor, const _QERPlugImageTable& table) const
786 GlobalFileSystem().forEachFile(m_dirstring, minor, TextureDirectoryLoadTextureCaller(m_dirstring));
790 void TextureBrowser_ShowDirectory(TextureBrowser& textureBrowser, const char* directory)
792 if(TextureBrowser_showWads())
794 Archive* archive = GlobalFileSystem().getArchive(directory);
795 ASSERT_NOTNULL(archive);
796 LoadShaderVisitor visitor;
797 archive->forEachFile(Archive::VisitorFunc(visitor, Archive::eFiles, 0), "textures/");
801 g_TextureBrowser_currentDirectory = directory;
802 TextureBrowser_heightChanged(textureBrowser);
804 std::size_t shaders_count;
805 GlobalShaderSystem().foreachShaderName(makeCallback1(TextureCategoryLoadShader(directory, shaders_count)));
806 globalOutputStream() << "Showing " << Unsigned(shaders_count) << " shaders.\n";
808 if(g_pGameDescription->mGameType != "doom3")
810 // load remaining texture files
812 StringOutputStream dirstring(64);
813 dirstring << "textures/" << directory;
815 Radiant_getImageModules().foreachModule(LoadTexturesByTypeVisitor(dirstring.c_str()));
819 // we'll display the newly loaded textures + all the ones already in use
820 TextureBrowser_SetHideUnused(textureBrowser, false);
822 TextureBrowser_updateTitle();
825 void TextureBrowser_ShowTagSearchResult(TextureBrowser& textureBrowser, const char* directory)
827 g_TextureBrowser_currentDirectory = directory;
828 TextureBrowser_heightChanged(textureBrowser);
830 std::size_t shaders_count;
831 GlobalShaderSystem().foreachShaderName(makeCallback1(TextureCategoryLoadShader(directory, shaders_count)));
832 globalOutputStream() << "Showing " << Unsigned(shaders_count) << " shaders.\n";
834 if(g_pGameDescription->mGameType != "doom3")
836 // load remaining texture files
837 StringOutputStream dirstring(64);
838 dirstring << "textures/" << directory;
841 LoadTexturesByTypeVisitor visitor(dirstring.c_str());
842 Radiant_getImageModules().foreachModule(visitor);
846 // we'll display the newly loaded textures + all the ones already in use
847 TextureBrowser_SetHideUnused(textureBrowser, false);
851 bool TextureBrowser_hideUnused();
853 void TextureBrowser_hideUnusedExport(const BoolImportCallback& importer)
855 importer(TextureBrowser_hideUnused());
857 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_hideUnusedExport> TextureBrowserHideUnusedExport;
859 void TextureBrowser_showShadersExport(const BoolImportCallback& importer)
861 importer(GlobalTextureBrowser().m_showShaders);
863 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_showShadersExport> TextureBrowserShowShadersExport;
865 void TextureBrowser_showShaderlistOnly(const BoolImportCallback& importer)
867 importer(g_TextureBrowser_shaderlistOnly);
869 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_showShaderlistOnly> TextureBrowserShowShaderlistOnlyExport;
871 void TextureBrowser_fixedSize(const BoolImportCallback& importer)
873 importer(g_TextureBrowser_fixedSize);
875 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_fixedSize> TextureBrowser_FixedSizeExport;
877 void TextureBrowser_filterNotex(const BoolImportCallback& importer)
879 importer(g_TextureBrowser_filterNotex);
881 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_filterNotex> TextureBrowser_filterNotexExport;
883 void TextureBrowser_SetHideUnused(TextureBrowser& textureBrowser, bool hideUnused)
887 textureBrowser.m_hideUnused = true;
891 textureBrowser.m_hideUnused = false;
894 textureBrowser.m_hideunused_item.update();
896 TextureBrowser_heightChanged(textureBrowser);
897 textureBrowser.m_originInvalid = true;
900 void TextureBrowser_ShowStartupShaders(TextureBrowser& textureBrowser)
902 if(textureBrowser.m_startupShaders == STARTUPSHADERS_COMMON)
904 TextureBrowser_ShowDirectory(textureBrowser, TextureBrowser_getComonShadersDir());
909 //++timo NOTE: this is a mix of Shader module stuff and texture explorer
910 // it might need to be split in parts or moved out .. dunno
911 // scroll origin so the specified texture is completely on screen
912 // if current texture is not displayed, nothing is changed
913 void TextureBrowser_Focus(TextureBrowser& textureBrowser, const char* name)
915 TextureLayout layout;
916 // scroll origin so the texture is completely on screen
917 Texture_StartPos(layout);
919 for(QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement())
921 IShader* shader = QERApp_ActiveShaders_IteratorCurrent();
923 if(!Texture_IsShown(shader, textureBrowser.m_showShaders, textureBrowser.m_hideUnused))
927 Texture_NextPos(textureBrowser, layout, shader->getTexture(), &x, &y);
928 qtexture_t* q = shader->getTexture();
932 // we have found when texdef->name and the shader name match
933 // NOTE: as everywhere else for our comparisons, we are not case sensitive
934 if (shader_equal(name, shader->getName()))
936 int textureHeight = (int)(q->height * ((float)textureBrowser.m_textureScale / 100))
937 + 2 * TextureBrowser_fontHeight(textureBrowser);
939 int originy = TextureBrowser_getOriginY(textureBrowser);
945 if (y - textureHeight < originy - textureBrowser.height)
947 originy = (y - textureHeight) + textureBrowser.height;
950 TextureBrowser_setOriginY(textureBrowser, originy);
956 IShader* Texture_At(TextureBrowser& textureBrowser, int mx, int my)
958 my += TextureBrowser_getOriginY(textureBrowser) - textureBrowser.height;
960 TextureLayout layout;
961 Texture_StartPos(layout);
962 for(QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement())
964 IShader* shader = QERApp_ActiveShaders_IteratorCurrent();
966 if(!Texture_IsShown(shader, textureBrowser.m_showShaders, textureBrowser.m_hideUnused))
970 Texture_NextPos(textureBrowser, layout, shader->getTexture(), &x, &y);
971 qtexture_t *q = shader->getTexture();
975 int nWidth = textureBrowser.getTextureWidth(q);
976 int nHeight = textureBrowser.getTextureHeight(q);
977 if (mx > x && mx - x < nWidth
978 && my < y && y - my < nHeight + TextureBrowser_fontHeight(textureBrowser))
994 void SelectTexture(TextureBrowser& textureBrowser, int mx, int my, bool bShift)
996 IShader* shader = Texture_At(textureBrowser, mx, my);
1001 if (shader->IsDefault())
1002 globalOutputStream() << "ERROR: " << shader->getName() << " is not a shader, it's a texture.\n";
1004 ViewShader( shader->getShaderFileName(), shader->getName() );
1008 TextureBrowser_SetSelectedShader(textureBrowser, shader->getName());
1009 TextureBrowser_textureSelected(shader->getName());
1011 if (!FindTextureDialog_isOpen() && !textureBrowser.m_rmbSelected)
1013 UndoableCommand undo("textureNameSetSelected");
1014 Select_SetShader(shader->getName());
1021 ============================================================================
1025 ============================================================================
1028 void TextureBrowser_trackingDelta(int x, int y, unsigned int state, void* data)
1030 TextureBrowser& textureBrowser = *reinterpret_cast<TextureBrowser*>(data);
1035 if(state & GDK_SHIFT_MASK)
1038 int originy = TextureBrowser_getOriginY(textureBrowser);
1039 originy += y * scale;
1040 TextureBrowser_setOriginY(textureBrowser, originy);
1044 void TextureBrowser_Tracking_MouseDown(TextureBrowser& textureBrowser)
1046 textureBrowser.m_freezePointer.freeze_pointer(textureBrowser.m_parent, TextureBrowser_trackingDelta, &textureBrowser);
1049 void TextureBrowser_Tracking_MouseUp(TextureBrowser& textureBrowser)
1051 textureBrowser.m_freezePointer.unfreeze_pointer(textureBrowser.m_parent);
1054 void TextureBrowser_Selection_MouseDown(TextureBrowser& textureBrowser, guint32 flags, int pointx, int pointy)
1056 SelectTexture(textureBrowser, pointx, textureBrowser.height - 1 - pointy, (flags & GDK_SHIFT_MASK) != 0);
1060 ============================================================================
1064 ============================================================================
1070 TTimo: relying on the shaders list to display the textures
1071 we must query all qtexture_t* to manage and display through the IShaders interface
1072 this allows a plugin to completely override the texture system
1075 void Texture_Draw(TextureBrowser& textureBrowser)
1077 int originy = TextureBrowser_getOriginY(textureBrowser);
1079 glClearColor(textureBrowser.color_textureback[0],
1080 textureBrowser.color_textureback[1],
1081 textureBrowser.color_textureback[2],
1083 glViewport(0, 0, textureBrowser.width, textureBrowser.height);
1084 glMatrixMode(GL_PROJECTION);
1087 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1088 glDisable (GL_DEPTH_TEST);
1089 glDisable(GL_BLEND);
1090 glOrtho (0, textureBrowser.width, originy-textureBrowser.height, originy, -100, 100);
1091 glEnable (GL_TEXTURE_2D);
1093 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
1095 int last_y = 0, last_height = 0;
1097 TextureLayout layout;
1098 Texture_StartPos(layout);
1099 for(QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement())
1101 IShader* shader = QERApp_ActiveShaders_IteratorCurrent();
1103 if(!Texture_IsShown(shader, textureBrowser.m_showShaders, textureBrowser.m_hideUnused))
1107 Texture_NextPos(textureBrowser, layout, shader->getTexture(), &x, &y);
1108 qtexture_t *q = shader->getTexture();
1112 int nWidth = textureBrowser.getTextureWidth(q);
1113 int nHeight = textureBrowser.getTextureHeight(q);
1120 last_height = std::max (nHeight, last_height);
1122 // Is this texture visible?
1123 if ((y-nHeight-TextureBrowser_fontHeight(textureBrowser) < originy)
1124 && (y > originy - textureBrowser.height))
1127 // if it's the current texture, draw a thick red line, else:
1128 // shaders have a white border, simple textures don't
1129 // if !texture_showinuse: (some textures displayed may not be in use)
1130 // draw an additional square around with 0.5 1 0.5 color
1131 if (shader_equal(TextureBrowser_GetSelectedShader(textureBrowser), shader->getName()))
1134 if(textureBrowser.m_rmbSelected)
1140 glDisable (GL_TEXTURE_2D);
1142 glBegin (GL_LINE_LOOP);
1143 glVertex2i (x-4,y-TextureBrowser_fontHeight(textureBrowser)+4);
1144 glVertex2i (x-4,y-TextureBrowser_fontHeight(textureBrowser)-nHeight-4);
1145 glVertex2i (x+4+nWidth,y-TextureBrowser_fontHeight(textureBrowser)-nHeight-4);
1146 glVertex2i (x+4+nWidth,y-TextureBrowser_fontHeight(textureBrowser)+4);
1149 glEnable (GL_TEXTURE_2D);
1156 if (!shader->IsDefault())
1159 glDisable (GL_TEXTURE_2D);
1161 glBegin (GL_LINE_LOOP);
1162 glVertex2i (x-1,y+1-TextureBrowser_fontHeight(textureBrowser));
1163 glVertex2i (x-1,y-nHeight-1-TextureBrowser_fontHeight(textureBrowser));
1164 glVertex2i (x+1+nWidth,y-nHeight-1-TextureBrowser_fontHeight(textureBrowser));
1165 glVertex2i (x+1+nWidth,y+1-TextureBrowser_fontHeight(textureBrowser));
1167 glEnable (GL_TEXTURE_2D);
1170 // highlight in-use textures
1171 if (!textureBrowser.m_hideUnused && shader->IsInUse())
1173 glColor3f (0.5,1,0.5);
1174 glDisable (GL_TEXTURE_2D);
1175 glBegin (GL_LINE_LOOP);
1176 glVertex2i (x-3,y+3-TextureBrowser_fontHeight(textureBrowser));
1177 glVertex2i (x-3,y-nHeight-3-TextureBrowser_fontHeight(textureBrowser));
1178 glVertex2i (x+3+nWidth,y-nHeight-3-TextureBrowser_fontHeight(textureBrowser));
1179 glVertex2i (x+3+nWidth,y+3-TextureBrowser_fontHeight(textureBrowser));
1181 glEnable (GL_TEXTURE_2D);
1186 glBindTexture (GL_TEXTURE_2D, q->texture_number);
1187 GlobalOpenGL_debugAssertNoErrors();
1191 glVertex2i (x,y-TextureBrowser_fontHeight(textureBrowser));
1193 glVertex2i (x+nWidth,y-TextureBrowser_fontHeight(textureBrowser));
1195 glVertex2i (x+nWidth,y-TextureBrowser_fontHeight(textureBrowser)-nHeight);
1197 glVertex2i (x,y-TextureBrowser_fontHeight(textureBrowser)-nHeight);
1200 // draw the texture name
1201 glDisable (GL_TEXTURE_2D);
1204 glRasterPos2i (x, y-TextureBrowser_fontHeight(textureBrowser)+5);
1206 // don't draw the directory name
1207 const char* name = shader->getName();
1208 name += strlen(name);
1209 while(name != shader->getName() && *(name-1) != '/' && *(name-1) != '\\')
1212 GlobalOpenGL().drawString(name);
1213 glEnable (GL_TEXTURE_2D);
1216 //int totalHeight = abs(y) + last_height + TextureBrowser_fontHeight(textureBrowser) + 4;
1220 // reset the current texture
1221 glBindTexture(GL_TEXTURE_2D, 0);
1225 void TextureBrowser_queueDraw(TextureBrowser& textureBrowser)
1227 if(textureBrowser.m_gl_widget != 0)
1229 gtk_widget_queue_draw(textureBrowser.m_gl_widget);
1234 void TextureBrowser_setScale(TextureBrowser& textureBrowser, std::size_t scale)
1236 textureBrowser.m_textureScale = scale;
1238 TextureBrowser_queueDraw(textureBrowser);
1242 void TextureBrowser_MouseWheel(TextureBrowser& textureBrowser, bool bUp)
1244 int originy = TextureBrowser_getOriginY(textureBrowser);
1248 originy += int(textureBrowser.m_mouseWheelScrollIncrement);
1252 originy -= int(textureBrowser.m_mouseWheelScrollIncrement);
1255 TextureBrowser_setOriginY(textureBrowser, originy);
1258 XmlTagBuilder TagBuilder;
1266 void BuildStoreAssignedTags(GtkListStore* store, const char* shader, TextureBrowser* textureBrowser)
1270 gtk_list_store_clear(store);
1272 std::vector<CopiedString> assigned_tags;
1273 TagBuilder.GetShaderTags(shader, assigned_tags);
1275 for (size_t i = 0; i < assigned_tags.size(); i++)
1277 gtk_list_store_append (store, &iter);
1278 gtk_list_store_set (store, &iter, TAG_COLUMN, assigned_tags[i].c_str(), -1);
1282 void BuildStoreAvailableTags( GtkListStore* storeAvailable,
1283 GtkListStore* storeAssigned,
1284 const std::set<CopiedString>& allTags,
1285 TextureBrowser* textureBrowser)
1287 GtkTreeIter iterAssigned;
1288 GtkTreeIter iterAvailable;
1289 std::set<CopiedString>::const_iterator iterAll;
1290 gchar* tag_assigned;
1292 gtk_list_store_clear(storeAvailable);
1294 bool row = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(storeAssigned), &iterAssigned) != 0;
1296 if(!row) // does the shader have tags assigned?
1298 for (iterAll = allTags.begin(); iterAll != allTags.end(); ++iterAll)
1300 gtk_list_store_append (storeAvailable, &iterAvailable);
1301 gtk_list_store_set (storeAvailable, &iterAvailable, TAG_COLUMN, (*iterAll).c_str(), -1);
1306 while(row) // available tags = all tags - assigned tags
1308 gtk_tree_model_get(GTK_TREE_MODEL(storeAssigned), &iterAssigned, TAG_COLUMN, &tag_assigned, -1);
1310 for (iterAll = allTags.begin(); iterAll != allTags.end(); ++iterAll)
1312 if(strcmp((char*)tag_assigned, (*iterAll).c_str()) != 0)
1314 gtk_list_store_append (storeAvailable, &iterAvailable);
1315 gtk_list_store_set (storeAvailable, &iterAvailable, TAG_COLUMN, (*iterAll).c_str(), -1);
1319 row = gtk_tree_model_iter_next(GTK_TREE_MODEL(storeAssigned), &iterAssigned) != 0;
1323 gtk_tree_model_get(GTK_TREE_MODEL(storeAssigned), &iterAssigned, TAG_COLUMN, &tag_assigned, -1);
1331 gboolean TextureBrowser_button_press(GtkWidget* widget, GdkEventButton* event, TextureBrowser* textureBrowser)
1333 if(event->type == GDK_BUTTON_PRESS)
1335 if(event->button == 3)
1337 if(GlobalTextureBrowser().m_tags)
1339 textureBrowser->m_rmbSelected = true;
1340 TextureBrowser_Selection_MouseDown (*textureBrowser, event->state, static_cast<int>(event->x), static_cast<int>(event->y));
1342 BuildStoreAssignedTags(textureBrowser->m_assigned_store, textureBrowser->shader.c_str(), textureBrowser);
1343 BuildStoreAvailableTags(textureBrowser->m_available_store, textureBrowser->m_assigned_store, textureBrowser->m_all_tags, textureBrowser);
1344 textureBrowser->m_heightChanged = true;
1345 gtk_widget_show(textureBrowser->m_tag_frame);
1349 TextureBrowser_Focus(*textureBrowser, textureBrowser->shader.c_str());
1353 TextureBrowser_Tracking_MouseDown(*textureBrowser);
1356 else if(event->button == 1)
1358 TextureBrowser_Selection_MouseDown(*textureBrowser, event->state, static_cast<int>(event->x), static_cast<int>(event->y));
1360 if(GlobalTextureBrowser().m_tags)
1362 textureBrowser->m_rmbSelected = false;
1363 gtk_widget_hide(textureBrowser->m_tag_frame);
1370 gboolean TextureBrowser_button_release(GtkWidget* widget, GdkEventButton* event, TextureBrowser* textureBrowser)
1372 if(event->type == GDK_BUTTON_RELEASE)
1374 if(event->button == 3)
1376 if(!GlobalTextureBrowser().m_tags)
1378 TextureBrowser_Tracking_MouseUp(*textureBrowser);
1385 gboolean TextureBrowser_motion(GtkWidget *widget, GdkEventMotion *event, TextureBrowser* textureBrowser)
1390 gboolean TextureBrowser_scroll(GtkWidget* widget, GdkEventScroll* event, TextureBrowser* textureBrowser)
1392 if(event->direction == GDK_SCROLL_UP)
1394 TextureBrowser_MouseWheel(*textureBrowser, true);
1396 else if(event->direction == GDK_SCROLL_DOWN)
1398 TextureBrowser_MouseWheel(*textureBrowser, false);
1403 void TextureBrowser_scrollChanged(void* data, gdouble value)
1405 //globalOutputStream() << "vertical scroll\n";
1406 TextureBrowser_setOriginY(*reinterpret_cast<TextureBrowser*>(data), -(int)value);
1409 static void TextureBrowser_verticalScroll(GtkAdjustment *adjustment, TextureBrowser* textureBrowser)
1411 textureBrowser->m_scrollAdjustment.value_changed(adjustment->value);
1414 void TextureBrowser_updateScroll(TextureBrowser& textureBrowser)
1416 if(textureBrowser.m_showTextureScrollbar)
1418 int totalHeight = TextureBrowser_TotalHeight(textureBrowser);
1420 totalHeight = std::max(totalHeight, textureBrowser.height);
1422 GtkAdjustment *vadjustment = gtk_range_get_adjustment(GTK_RANGE(textureBrowser.m_texture_scroll));
1424 vadjustment->value = -TextureBrowser_getOriginY(textureBrowser);
1425 vadjustment->page_size = textureBrowser.height;
1426 vadjustment->page_increment = textureBrowser.height/2;
1427 vadjustment->step_increment = 20;
1428 vadjustment->lower = 0;
1429 vadjustment->upper = totalHeight;
1431 g_signal_emit_by_name(G_OBJECT (vadjustment), "changed");
1435 gboolean TextureBrowser_size_allocate(GtkWidget* widget, GtkAllocation* allocation, TextureBrowser* textureBrowser)
1437 textureBrowser->width = allocation->width;
1438 textureBrowser->height = allocation->height;
1439 TextureBrowser_heightChanged(*textureBrowser);
1440 textureBrowser->m_originInvalid = true;
1441 TextureBrowser_queueDraw(*textureBrowser);
1445 gboolean TextureBrowser_expose(GtkWidget* widget, GdkEventExpose* event, TextureBrowser* textureBrowser)
1447 if(glwidget_make_current(textureBrowser->m_gl_widget) != FALSE)
1449 GlobalOpenGL_debugAssertNoErrors();
1450 TextureBrowser_evaluateHeight(*textureBrowser);
1451 Texture_Draw(*textureBrowser);
1452 GlobalOpenGL_debugAssertNoErrors();
1453 glwidget_swap_buffers(textureBrowser->m_gl_widget);
1459 TextureBrowser g_TextureBrowser;
1461 TextureBrowser& GlobalTextureBrowser()
1463 return g_TextureBrowser;
1466 bool TextureBrowser_hideUnused()
1468 return g_TextureBrowser.m_hideUnused;
1471 void TextureBrowser_ToggleHideUnused()
1473 if(g_TextureBrowser.m_hideUnused)
1475 TextureBrowser_SetHideUnused(g_TextureBrowser, false);
1479 TextureBrowser_SetHideUnused(g_TextureBrowser, true);
1483 void TextureGroups_constructTreeModel(TextureGroups groups, GtkTreeStore* store)
1485 // put the information from the old textures menu into a treeview
1486 GtkTreeIter iter, child;
1488 TextureGroups::const_iterator i = groups.begin();
1489 while (i != groups.end())
1491 const char* dirName = (*i).c_str();
1492 const char* firstUnderscore = strchr(dirName, '_');
1493 StringRange dirRoot (dirName, (firstUnderscore == 0) ? dirName : firstUnderscore + 1);
1495 TextureGroups::const_iterator next = i;
1497 if(firstUnderscore != 0
1498 && next != groups.end()
1499 && string_equal_start((*next).c_str(), dirRoot))
1501 gtk_tree_store_append(store, &iter, NULL);
1502 gtk_tree_store_set (store, &iter, 0, CopiedString(StringRange(dirName, firstUnderscore)).c_str(), -1);
1505 while (i != groups.end() && string_equal_start((*i).c_str(), dirRoot))
1507 gtk_tree_store_append(store, &child, &iter);
1508 gtk_tree_store_set (store, &child, 0, (*i).c_str(), -1);
1514 gtk_tree_store_append(store, &iter, NULL);
1515 gtk_tree_store_set (store, &iter, 0, dirName, -1);
1521 TextureGroups TextureGroups_constructTreeView()
1523 TextureGroups groups;
1525 if (TextureBrowser_showWads())
1527 GlobalFileSystem().forEachArchive (TextureGroupsAddWadCaller (groups));
1531 // scan texture dirs and pak files only if not restricting to shaderlist
1532 if (g_pGameDescription->mGameType != "doom3" && !g_TextureBrowser_shaderlistOnly)
1534 GlobalFileSystem().forEachDirectory ("textures/", TextureGroupsAddDirectoryCaller(groups));
1537 GlobalShaderSystem().foreachShaderName(TextureGroupsAddShaderCaller(groups));
1543 void TextureBrowser_constructTreeStore()
1545 TextureGroups groups = TextureGroups_constructTreeView();
1546 GtkTreeStore* store = gtk_tree_store_new(1, G_TYPE_STRING);
1547 TextureGroups_constructTreeModel(groups, store);
1548 std::set<CopiedString>::iterator iter;
1550 GtkTreeModel* model = GTK_TREE_MODEL(store);
1552 gtk_tree_view_set_model(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTree), model);
1554 g_object_unref(G_OBJECT(store));
1557 void TextureBrowser_constructTreeStoreTags()
1559 TextureGroups groups;
1560 GtkTreeStore* store = gtk_tree_store_new(1, G_TYPE_STRING);
1561 GtkTreeModel* model = GTK_TREE_MODEL(g_TextureBrowser.m_all_tags_list);
1563 gtk_tree_view_set_model(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTags), model);
1565 g_object_unref(G_OBJECT(store));
1568 void TreeView_onRowActivated(GtkTreeView* treeview, GtkTreePath* path, GtkTreeViewColumn* col, gpointer userdata)
1572 GtkTreeModel* model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
1574 if (gtk_tree_model_get_iter (model, &iter, path))
1576 gchar dirName[1024];
1579 gtk_tree_model_get(model, &iter, 0, &buffer, -1);
1580 strcpy(dirName, buffer);
1583 g_TextureBrowser.m_searchedTags = false;
1585 if(!TextureBrowser_showWads())
1586 strcat(dirName, "/");
1588 ScopeDisableScreenUpdates disableScreenUpdates(dirName, "Loading Textures");
1589 TextureBrowser_ShowDirectory(GlobalTextureBrowser (), dirName);
1590 TextureBrowser_queueDraw(GlobalTextureBrowser ());
1594 void TextureBrowser_createTreeViewTree()
1596 GtkCellRenderer* renderer;
1597 g_TextureBrowser.m_treeViewTree = GTK_WIDGET(gtk_tree_view_new());
1598 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTree), FALSE);
1600 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTree), FALSE);
1601 g_signal_connect(g_TextureBrowser.m_treeViewTree, "row-activated", (GCallback) TreeView_onRowActivated, NULL);
1603 renderer = gtk_cell_renderer_text_new();
1604 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTree), -1, "", renderer, "text", 0, NULL);
1606 TextureBrowser_constructTreeStore();
1609 void TextureBrowser_addTag();
1610 void TextureBrowser_renameTag();
1611 void TextureBrowser_deleteTag();
1613 void TextureBrowser_createContextMenu(GtkWidget *treeview, GdkEventButton *event)
1615 GtkWidget* menu = gtk_menu_new();
1617 GtkWidget* menuitem = gtk_menu_item_new_with_label("Add tag");
1618 g_signal_connect(menuitem, "activate", (GCallback)TextureBrowser_addTag, treeview);
1619 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
1621 menuitem = gtk_menu_item_new_with_label("Rename tag");
1622 g_signal_connect(menuitem, "activate", (GCallback)TextureBrowser_renameTag, treeview);
1623 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
1625 menuitem = gtk_menu_item_new_with_label("Delete tag");
1626 g_signal_connect(menuitem, "activate", (GCallback)TextureBrowser_deleteTag, treeview);
1627 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
1629 gtk_widget_show_all(menu);
1631 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL,
1632 (event != NULL) ? event->button : 0,
1633 gdk_event_get_time((GdkEvent*)event));
1636 gboolean TreeViewTags_onButtonPressed(GtkWidget *treeview, GdkEventButton *event)
1638 if (event->type == GDK_BUTTON_PRESS && event->button == 3)
1641 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
1643 if(gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(treeview), event->x, event->y, &path, NULL, NULL, NULL))
1645 gtk_tree_selection_unselect_all(selection);
1646 gtk_tree_selection_select_path(selection, path);
1647 gtk_tree_path_free(path);
1650 TextureBrowser_createContextMenu(treeview, event);
1656 void TextureBrowser_createTreeViewTags()
1658 GtkCellRenderer* renderer;
1659 g_TextureBrowser.m_treeViewTags = GTK_WIDGET(gtk_tree_view_new());
1660 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTags), FALSE);
1662 g_signal_connect(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTags), "button-press-event", (GCallback)TreeViewTags_onButtonPressed, NULL);
1664 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTags), FALSE);
1666 renderer = gtk_cell_renderer_text_new();
1667 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTags), -1, "", renderer, "text", 0, NULL);
1669 TextureBrowser_constructTreeStoreTags();
1672 GtkMenuItem* TextureBrowser_constructViewMenu(GtkMenu* menu)
1674 GtkMenuItem* textures_menu_item = new_sub_menu_item_with_mnemonic("_View");
1676 if(g_Layout_enableDetachableMenus.m_value)
1677 menu_tearoff (menu);
1679 create_check_menu_item_with_mnemonic(menu, "Hide _Unused", "ShowInUse");
1680 if(string_empty(g_pGameDescription->getKeyValue("show_wads")))
1682 create_check_menu_item_with_mnemonic(menu, "Hide Image Missing", "FilterNotex");
1684 menu_separator(menu);
1686 create_menu_item_with_mnemonic(menu, "Show All", "ShowAllTextures");
1688 // we always want to show shaders but don't want a "Show Shaders" menu for doom3 and .wad file games
1689 if(g_pGameDescription->mGameType == "doom3" || !string_empty(g_pGameDescription->getKeyValue("show_wads")))
1691 g_TextureBrowser.m_showShaders = true;
1695 create_check_menu_item_with_mnemonic(menu, "Show shaders", "ToggleShowShaders");
1698 if(g_pGameDescription->mGameType != "doom3" && string_empty(g_pGameDescription->getKeyValue("show_wads")))
1700 create_check_menu_item_with_mnemonic (menu, "Shaders Only", "ToggleShowShaderlistOnly");
1702 if(g_TextureBrowser.m_tags)
1704 create_menu_item_with_mnemonic(menu, "Show Untagged", "ShowUntagged");
1707 create_check_menu_item_with_mnemonic(menu, "Fixed Size", "FixedSize");
1709 if(string_empty(g_pGameDescription->getKeyValue("show_wads")))
1711 menu_separator(menu);
1712 g_TextureBrowser.m_shader_info_item = GTK_WIDGET(create_menu_item_with_mnemonic(menu, "Shader Info", "ShaderInfo"));
1713 gtk_widget_set_sensitive(g_TextureBrowser.m_shader_info_item, FALSE);
1716 return textures_menu_item;
1719 GtkMenuItem* TextureBrowser_constructToolsMenu(GtkMenu* menu)
1721 GtkMenuItem* textures_menu_item = new_sub_menu_item_with_mnemonic("_Tools");
1723 if (g_Layout_enableDetachableMenus.m_value)
1724 menu_tearoff (menu);
1726 create_menu_item_with_mnemonic(menu, "Flush & Reload Shaders", "RefreshShaders");
1727 create_menu_item_with_mnemonic(menu, "Find / Replace...", "FindReplaceTextures");
1729 return textures_menu_item;
1732 GtkMenuItem* TextureBrowser_constructTagsMenu(GtkMenu* menu)
1734 GtkMenuItem* textures_menu_item = new_sub_menu_item_with_mnemonic("T_ags");
1736 if (g_Layout_enableDetachableMenus.m_value)
1737 menu_tearoff (menu);
1739 create_menu_item_with_mnemonic(menu, "Add tag", "AddTag");
1740 create_menu_item_with_mnemonic(menu, "Rename tag", "RenameTag");
1741 create_menu_item_with_mnemonic(menu, "Delete tag", "DeleteTag");
1742 menu_separator(menu);
1743 create_menu_item_with_mnemonic(menu, "Copy tags from selected", "CopyTag");
1744 create_menu_item_with_mnemonic(menu, "Paste tags to selected", "PasteTag");
1746 return textures_menu_item;
1749 gboolean TextureBrowser_tagMoveHelper(GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter, GSList** selected)
1751 g_assert(selected != NULL);
1753 GtkTreeRowReference* rowref = gtk_tree_row_reference_new (model, path);
1754 *selected = g_slist_append(*selected, rowref);
1759 void TextureBrowser_assignTags()
1761 GSList* selected = NULL;
1763 gchar* tag_assigned;
1765 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_TextureBrowser.m_available_tree));
1767 gtk_tree_selection_selected_foreach(selection, (GtkTreeSelectionForeachFunc)TextureBrowser_tagMoveHelper, &selected);
1769 if(selected != NULL)
1771 for (node = selected; node != NULL; node = node->next)
1773 GtkTreePath* path = gtk_tree_row_reference_get_path((GtkTreeRowReference*)node->data);
1779 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(g_TextureBrowser.m_available_store), &iter, path))
1781 gtk_tree_model_get(GTK_TREE_MODEL(g_TextureBrowser.m_available_store), &iter, TAG_COLUMN, &tag_assigned, -1);
1782 if(!TagBuilder.CheckShaderTag(g_TextureBrowser.shader.c_str()))
1784 // create a custom shader/texture entry
1785 IShader* ishader = QERApp_Shader_ForName(g_TextureBrowser.shader.c_str());
1786 CopiedString filename = ishader->getShaderFileName();
1788 if(filename.empty())
1791 TagBuilder.AddShaderNode(g_TextureBrowser.shader.c_str(), CUSTOM, TEXTURE);
1794 TagBuilder.AddShaderNode(g_TextureBrowser.shader.c_str(), CUSTOM, SHADER);
1798 TagBuilder.AddShaderTag(g_TextureBrowser.shader.c_str(), (char*)tag_assigned, TAG);
1800 gtk_list_store_remove(g_TextureBrowser.m_available_store, &iter);
1801 gtk_list_store_append (g_TextureBrowser.m_assigned_store, &iter);
1802 gtk_list_store_set (g_TextureBrowser.m_assigned_store, &iter, TAG_COLUMN, (char*)tag_assigned, -1);
1807 g_slist_foreach(selected, (GFunc)gtk_tree_row_reference_free, NULL);
1810 TagBuilder.SaveXmlDoc();
1812 g_slist_free(selected);
1815 void TextureBrowser_removeTags()
1817 GSList* selected = NULL;
1821 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_TextureBrowser.m_assigned_tree));
1823 gtk_tree_selection_selected_foreach(selection, (GtkTreeSelectionForeachFunc)TextureBrowser_tagMoveHelper, &selected);
1825 if(selected != NULL)
1827 for (node = selected; node != NULL; node = node->next)
1829 GtkTreePath* path = gtk_tree_row_reference_get_path((GtkTreeRowReference*)node->data);
1835 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(g_TextureBrowser.m_assigned_store), &iter, path))
1837 gtk_tree_model_get(GTK_TREE_MODEL(g_TextureBrowser.m_assigned_store), &iter, TAG_COLUMN, &tag, -1);
1838 TagBuilder.DeleteShaderTag(g_TextureBrowser.shader.c_str(), tag);
1839 gtk_list_store_remove(g_TextureBrowser.m_assigned_store, &iter);
1844 g_slist_foreach(selected, (GFunc)gtk_tree_row_reference_free, NULL);
1846 // Update the "available tags list"
1847 BuildStoreAvailableTags(g_TextureBrowser.m_available_store, g_TextureBrowser.m_assigned_store, g_TextureBrowser.m_all_tags, &g_TextureBrowser);
1850 TagBuilder.SaveXmlDoc();
1852 g_slist_free(selected);
1855 void TextureBrowser_buildTagList()
1857 GtkTreeIter treeIter;
1858 gtk_list_store_clear(g_TextureBrowser.m_all_tags_list);
1860 std::set<CopiedString>::iterator iter;
1862 for (iter = g_TextureBrowser.m_all_tags.begin(); iter != g_TextureBrowser.m_all_tags.end(); ++iter)
1864 gtk_list_store_append(g_TextureBrowser.m_all_tags_list, &treeIter);
1865 gtk_list_store_set(g_TextureBrowser.m_all_tags_list, &treeIter, TAG_COLUMN, (*iter).c_str(), -1);
1869 void TextureBrowser_searchTags()
1871 GSList* selected = NULL;
1875 char tags_searched[256];
1877 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTags));
1879 gtk_tree_selection_selected_foreach(selection, (GtkTreeSelectionForeachFunc)TextureBrowser_tagMoveHelper, &selected);
1881 if(selected != NULL)
1883 strcpy(buffer, "/root/*/*[tag='");
1884 strcpy(tags_searched, "[TAGS] ");
1886 for (node = selected; node != NULL; node = node->next)
1888 GtkTreePath* path = gtk_tree_row_reference_get_path((GtkTreeRowReference*)node->data);
1894 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(g_TextureBrowser.m_all_tags_list), &iter, path))
1896 gtk_tree_model_get(GTK_TREE_MODEL(g_TextureBrowser.m_all_tags_list), &iter, TAG_COLUMN, &tag, -1);
1898 strcat(buffer, tag);
1899 strcat(tags_searched, tag);
1900 if(node != g_slist_last(node))
1902 strcat(buffer, "' and tag='");
1903 strcat(tags_searched, ", ");
1909 strcat(buffer, "']");
1911 g_slist_foreach(selected, (GFunc)gtk_tree_row_reference_free, NULL);
1913 g_TextureBrowser.m_found_shaders.clear(); // delete old list
1914 TagBuilder.TagSearch(buffer, g_TextureBrowser.m_found_shaders);
1916 if(!g_TextureBrowser.m_found_shaders.empty()) // found something
1918 size_t shaders_found = g_TextureBrowser.m_found_shaders.size();
1920 globalOutputStream() << "Found " << (unsigned int)shaders_found << " textures and shaders with " << tags_searched << "\n";
1921 ScopeDisableScreenUpdates disableScreenUpdates("Searching...", "Loading Textures");
1923 std::set<CopiedString>::iterator iter;
1925 for(iter = g_TextureBrowser.m_found_shaders.begin(); iter != g_TextureBrowser.m_found_shaders.end(); iter++)
1927 std::string path = (*iter).c_str();
1928 size_t pos = path.find_last_of("/", path.size());
1929 std::string name = path.substr(pos + 1, path.size());
1930 path = path.substr(0, pos + 1);
1931 TextureDirectory_loadTexture(path.c_str(), name.c_str());
1934 g_TextureBrowser.m_searchedTags = true;
1935 g_TextureBrowser_currentDirectory = tags_searched;
1937 g_TextureBrowser.m_nTotalHeight = 0;
1938 TextureBrowser_setOriginY(g_TextureBrowser, 0);
1939 TextureBrowser_heightChanged(g_TextureBrowser);
1940 TextureBrowser_updateTitle();
1942 g_slist_free(selected);
1945 void TextureBrowser_toggleSearchButton()
1947 gint page = gtk_notebook_get_current_page(GTK_NOTEBOOK(g_TextureBrowser.m_tag_notebook));
1949 if(page == 0) // tag page
1951 gtk_widget_show_all(g_TextureBrowser.m_search_button);
1953 gtk_widget_hide_all(g_TextureBrowser.m_search_button);
1957 void TextureBrowser_constructTagNotebook()
1959 g_TextureBrowser.m_tag_notebook = gtk_notebook_new();
1960 GtkWidget* labelTags = gtk_label_new("Tags");
1961 GtkWidget* labelTextures = gtk_label_new("Textures");
1963 gtk_notebook_append_page(GTK_NOTEBOOK(g_TextureBrowser.m_tag_notebook), g_TextureBrowser.m_scr_win_tree, labelTextures);
1964 gtk_notebook_append_page(GTK_NOTEBOOK(g_TextureBrowser.m_tag_notebook), g_TextureBrowser.m_scr_win_tags, labelTags);
1966 g_signal_connect(G_OBJECT(g_TextureBrowser.m_tag_notebook), "switch-page", G_CALLBACK(TextureBrowser_toggleSearchButton), NULL);
1968 gtk_widget_show_all(g_TextureBrowser.m_tag_notebook);
1971 void TextureBrowser_constructSearchButton()
1973 GtkTooltips* tooltips = gtk_tooltips_new();
1975 GtkWidget* image = gtk_image_new_from_stock(GTK_STOCK_FIND, GTK_ICON_SIZE_SMALL_TOOLBAR);
1976 g_TextureBrowser.m_search_button = gtk_button_new();
1977 g_signal_connect(G_OBJECT(g_TextureBrowser.m_search_button), "clicked", G_CALLBACK(TextureBrowser_searchTags), NULL);
1978 gtk_tooltips_set_tip(GTK_TOOLTIPS(tooltips), g_TextureBrowser.m_search_button, "Search with selected tags", "Search with selected tags");
1979 gtk_container_add(GTK_CONTAINER(g_TextureBrowser.m_search_button), image);
1982 void TextureBrowser_checkTagFile()
1984 const char SHADERTAG_FILE[] = "shadertags.xml";
1985 CopiedString default_filename, rc_filename;
1986 StringOutputStream stream(256);
1988 stream << LocalRcPath_get();
1989 stream << SHADERTAG_FILE;
1990 rc_filename = stream.c_str();
1992 if(file_exists(rc_filename.c_str()))
1994 g_TextureBrowser.m_tags = TagBuilder.OpenXmlDoc(rc_filename.c_str());
1996 if(g_TextureBrowser.m_tags)
1998 globalOutputStream() << "Loading tag file " << rc_filename.c_str() << ".\n";
2003 // load default tagfile
2005 stream << g_pGameDescription->mGameToolsPath.c_str();
2006 stream << SHADERTAG_FILE;
2007 default_filename = stream.c_str();
2009 if(file_exists(default_filename.c_str()))
2011 g_TextureBrowser.m_tags = TagBuilder.OpenXmlDoc(default_filename.c_str(), rc_filename.c_str());
2013 if(g_TextureBrowser.m_tags)
2015 globalOutputStream() << "Loading default tag file " << default_filename.c_str() << ".\n";
2020 globalErrorStream() << "Unable to find default tag file " << default_filename.c_str() << ". No tag support.\n";
2025 void TextureBrowser_SetNotex()
2027 StringOutputStream name(256);
2028 name << GlobalRadiant().getAppPath() << "bitmaps/notex.bmp";
2029 g_notex = name.c_str();
2032 name << GlobalRadiant().getAppPath() << "bitmaps/shadernotex.bmp";
2033 g_shadernotex = name.c_str();
2036 GtkWidget* TextureBrowser_constructWindow(GtkWindow* toplevel)
2038 // The gl_widget and the tag assignment frame should be packed into a GtkVPaned with the slider
2039 // position stored in local.pref. gtk_paned_get_position() and gtk_paned_set_position() don't
2040 // seem to work in gtk 2.4 and the arrow buttons don't handle GTK_FILL, so here's another thing
2041 // for the "once-the-gtk-libs-are-updated-TODO-list" :x
2043 TextureBrowser_checkTagFile();
2044 TextureBrowser_SetNotex();
2046 GlobalShaderSystem().setActiveShadersChangedNotify(ReferenceCaller<TextureBrowser, TextureBrowser_activeShadersChanged>(g_TextureBrowser));
2048 g_TextureBrowser.m_parent = toplevel;
2050 GtkWidget* table = gtk_table_new(3, 3, FALSE);
2051 GtkWidget* frame_table = NULL;
2052 GtkWidget* vbox = gtk_vbox_new(FALSE, 0);
2053 gtk_table_attach(GTK_TABLE(table), vbox, 0, 1, 1, 3, GTK_FILL, GTK_FILL, 0, 0);
2054 gtk_widget_show(vbox);
2056 GtkWidget* menu_bar;
2059 menu_bar = gtk_menu_bar_new();
2060 GtkWidget* menu_view = gtk_menu_new();
2061 GtkWidget* view_item = (GtkWidget*)TextureBrowser_constructViewMenu(GTK_MENU(menu_view));
2062 gtk_menu_item_set_submenu(GTK_MENU_ITEM(view_item), menu_view);
2063 gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), view_item);
2065 GtkWidget* menu_tools = gtk_menu_new();
2066 GtkWidget* tools_item = (GtkWidget*)TextureBrowser_constructToolsMenu(GTK_MENU(menu_tools));
2067 gtk_menu_item_set_submenu(GTK_MENU_ITEM(tools_item), menu_tools);
2068 gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), tools_item);
2070 gtk_table_attach(GTK_TABLE (table), menu_bar, 0, 3, 0, 1, GTK_FILL, GTK_SHRINK, 0, 0);
2071 gtk_widget_show(menu_bar);
2073 { // Texture TreeView
2074 g_TextureBrowser.m_scr_win_tree = gtk_scrolled_window_new(NULL, NULL);
2075 gtk_container_set_border_width(GTK_CONTAINER(g_TextureBrowser.m_scr_win_tree), 0);
2077 // vertical only scrolling for treeview
2078 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(g_TextureBrowser.m_scr_win_tree), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
2080 gtk_widget_show(g_TextureBrowser.m_scr_win_tree);
2082 TextureBrowser_createTreeViewTree();
2084 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(g_TextureBrowser.m_scr_win_tree), GTK_WIDGET(g_TextureBrowser.m_treeViewTree));
2085 gtk_widget_show(GTK_WIDGET(g_TextureBrowser.m_treeViewTree));
2087 { // gl_widget scrollbar
2088 GtkWidget* w = gtk_vscrollbar_new(GTK_ADJUSTMENT(gtk_adjustment_new (0,0,0,1,1,1)));
2089 gtk_table_attach(GTK_TABLE (table), w, 2, 3, 1, 2, GTK_SHRINK, GTK_FILL, 0, 0);
2091 g_TextureBrowser.m_texture_scroll = w;
2093 GtkAdjustment *vadjustment = gtk_range_get_adjustment (GTK_RANGE (g_TextureBrowser.m_texture_scroll));
2094 g_signal_connect(G_OBJECT(vadjustment), "value_changed", G_CALLBACK(TextureBrowser_verticalScroll), &g_TextureBrowser);
2096 widget_set_visible(g_TextureBrowser.m_texture_scroll, g_TextureBrowser.m_showTextureScrollbar);
2099 g_TextureBrowser.m_gl_widget = glwidget_new(FALSE);
2100 gtk_widget_ref(g_TextureBrowser.m_gl_widget);
2102 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);
2103 GTK_WIDGET_SET_FLAGS(g_TextureBrowser.m_gl_widget, GTK_CAN_FOCUS);
2105 gtk_table_attach_defaults(GTK_TABLE(table), g_TextureBrowser.m_gl_widget, 1, 2, 1, 2);
2106 gtk_widget_show(g_TextureBrowser.m_gl_widget);
2108 g_TextureBrowser.m_sizeHandler = g_signal_connect(G_OBJECT(g_TextureBrowser.m_gl_widget), "size_allocate", G_CALLBACK(TextureBrowser_size_allocate), &g_TextureBrowser);
2109 g_TextureBrowser.m_exposeHandler = g_signal_connect(G_OBJECT(g_TextureBrowser.m_gl_widget), "expose_event", G_CALLBACK(TextureBrowser_expose), &g_TextureBrowser);
2111 g_signal_connect(G_OBJECT(g_TextureBrowser.m_gl_widget), "button_press_event", G_CALLBACK(TextureBrowser_button_press), &g_TextureBrowser);
2112 g_signal_connect(G_OBJECT(g_TextureBrowser.m_gl_widget), "button_release_event", G_CALLBACK(TextureBrowser_button_release), &g_TextureBrowser);
2113 g_signal_connect(G_OBJECT(g_TextureBrowser.m_gl_widget), "motion_notify_event", G_CALLBACK(TextureBrowser_motion), &g_TextureBrowser);
2114 g_signal_connect(G_OBJECT(g_TextureBrowser.m_gl_widget), "scroll_event", G_CALLBACK(TextureBrowser_scroll), &g_TextureBrowser);
2118 if(g_TextureBrowser.m_tags)
2120 { // fill tag GtkListStore
2121 g_TextureBrowser.m_all_tags_list = gtk_list_store_new(N_COLUMNS, G_TYPE_STRING);
2122 GtkTreeSortable* sortable = GTK_TREE_SORTABLE(g_TextureBrowser.m_all_tags_list);
2123 gtk_tree_sortable_set_sort_column_id(sortable, TAG_COLUMN, GTK_SORT_ASCENDING);
2125 TagBuilder.GetAllTags(g_TextureBrowser.m_all_tags);
2126 TextureBrowser_buildTagList();
2129 GtkWidget* menu_tags = gtk_menu_new();
2130 GtkWidget* tags_item = (GtkWidget*)TextureBrowser_constructTagsMenu(GTK_MENU(menu_tags));
2131 gtk_menu_item_set_submenu(GTK_MENU_ITEM(tags_item), menu_tags);
2132 gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), tags_item);
2135 g_TextureBrowser.m_scr_win_tags = gtk_scrolled_window_new(NULL, NULL);
2136 gtk_container_set_border_width(GTK_CONTAINER(g_TextureBrowser.m_scr_win_tags), 0);
2138 // vertical only scrolling for treeview
2139 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(g_TextureBrowser.m_scr_win_tags), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
2141 TextureBrowser_createTreeViewTags();
2143 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTags));
2144 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
2146 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW (g_TextureBrowser.m_scr_win_tags), GTK_WIDGET (g_TextureBrowser.m_treeViewTags));
2147 gtk_widget_show(GTK_WIDGET(g_TextureBrowser.m_treeViewTags));
2149 { // Texture/Tag notebook
2150 TextureBrowser_constructTagNotebook();
2151 gtk_box_pack_start(GTK_BOX(vbox), g_TextureBrowser.m_tag_notebook, TRUE, TRUE, 0);
2153 { // Tag search button
2154 TextureBrowser_constructSearchButton();
2155 gtk_box_pack_end(GTK_BOX(vbox), g_TextureBrowser.m_search_button, FALSE, FALSE, 0);
2158 frame_table = gtk_table_new(3, 3, FALSE);
2160 g_TextureBrowser.m_tag_frame = gtk_frame_new("Tag assignment");
2161 gtk_frame_set_label_align(GTK_FRAME(g_TextureBrowser.m_tag_frame), 0.5, 0.5);
2162 gtk_frame_set_shadow_type(GTK_FRAME(g_TextureBrowser.m_tag_frame), GTK_SHADOW_NONE);
2164 gtk_table_attach(GTK_TABLE(table), g_TextureBrowser.m_tag_frame, 1, 3, 2, 3, GTK_FILL, GTK_SHRINK, 0, 0);
2166 gtk_widget_show(frame_table);
2168 gtk_container_add (GTK_CONTAINER(g_TextureBrowser.m_tag_frame), frame_table);
2170 { // assigned tag list
2171 GtkWidget* scrolled_win = gtk_scrolled_window_new(NULL, NULL);
2172 gtk_container_set_border_width(GTK_CONTAINER (scrolled_win), 0);
2173 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled_win), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
2175 g_TextureBrowser.m_assigned_store = gtk_list_store_new(N_COLUMNS, G_TYPE_STRING);
2177 GtkTreeSortable* sortable = GTK_TREE_SORTABLE(g_TextureBrowser.m_assigned_store);
2178 gtk_tree_sortable_set_sort_column_id(sortable, TAG_COLUMN, GTK_SORT_ASCENDING);
2180 GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
2182 g_TextureBrowser.m_assigned_tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL (g_TextureBrowser.m_assigned_store));
2183 g_object_unref(G_OBJECT (g_TextureBrowser.m_assigned_store));
2184 g_signal_connect(g_TextureBrowser.m_assigned_tree, "row-activated", (GCallback) TextureBrowser_removeTags, NULL);
2185 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW (g_TextureBrowser.m_assigned_tree), FALSE);
2187 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_TextureBrowser.m_assigned_tree));
2188 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
2190 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes("", renderer, "text", TAG_COLUMN, NULL);
2191 gtk_tree_view_append_column(GTK_TREE_VIEW (g_TextureBrowser.m_assigned_tree), column);
2192 gtk_widget_show(g_TextureBrowser.m_assigned_tree);
2194 gtk_widget_show(scrolled_win);
2195 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW (scrolled_win), GTK_WIDGET (g_TextureBrowser.m_assigned_tree));
2197 gtk_table_attach(GTK_TABLE(frame_table), scrolled_win, 0, 1, 1, 3, GTK_FILL, GTK_FILL, 0, 0);
2199 { // available tag list
2200 GtkWidget* scrolled_win = gtk_scrolled_window_new (NULL, NULL);
2201 gtk_container_set_border_width (GTK_CONTAINER (scrolled_win), 0);
2202 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
2204 g_TextureBrowser.m_available_store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING);
2205 GtkTreeSortable* sortable = GTK_TREE_SORTABLE(g_TextureBrowser.m_available_store);
2206 gtk_tree_sortable_set_sort_column_id(sortable, TAG_COLUMN, GTK_SORT_ASCENDING);
2208 GtkCellRenderer* renderer = gtk_cell_renderer_text_new ();
2210 g_TextureBrowser.m_available_tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (g_TextureBrowser.m_available_store));
2211 g_object_unref (G_OBJECT (g_TextureBrowser.m_available_store));
2212 g_signal_connect(g_TextureBrowser.m_available_tree, "row-activated", (GCallback) TextureBrowser_assignTags, NULL);
2213 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (g_TextureBrowser.m_available_tree), FALSE);
2215 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_TextureBrowser.m_available_tree));
2216 gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
2218 GtkTreeViewColumn* column = gtk_tree_view_column_new_with_attributes ("", renderer, "text", TAG_COLUMN, NULL);
2219 gtk_tree_view_append_column (GTK_TREE_VIEW (g_TextureBrowser.m_available_tree), column);
2220 gtk_widget_show (g_TextureBrowser.m_available_tree);
2222 gtk_widget_show (scrolled_win);
2223 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win), GTK_WIDGET (g_TextureBrowser.m_available_tree));
2225 gtk_table_attach (GTK_TABLE (frame_table), scrolled_win, 2, 3, 1, 3, GTK_FILL, GTK_FILL, 0, 0);
2227 { // tag arrow buttons
2228 GtkWidget* m_btn_left = gtk_button_new();
2229 GtkWidget* m_btn_right = gtk_button_new();
2230 GtkWidget* m_arrow_left = gtk_arrow_new(GTK_ARROW_LEFT, GTK_SHADOW_OUT);
2231 GtkWidget* m_arrow_right = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_OUT);
2232 gtk_container_add(GTK_CONTAINER(m_btn_left), m_arrow_left);
2233 gtk_container_add(GTK_CONTAINER(m_btn_right), m_arrow_right);
2235 // workaround. the size of the tag frame depends of the requested size of the arrow buttons.
2236 gtk_widget_set_size_request(m_arrow_left, -1, 68);
2237 gtk_widget_set_size_request(m_arrow_right, -1, 68);
2239 gtk_table_attach(GTK_TABLE(frame_table), m_btn_left, 1, 2, 1, 2, GTK_SHRINK, GTK_EXPAND, 0, 0);
2240 gtk_table_attach(GTK_TABLE(frame_table), m_btn_right, 1, 2, 2, 3, GTK_SHRINK, GTK_EXPAND, 0, 0);
2242 g_signal_connect(G_OBJECT (m_btn_left), "clicked", G_CALLBACK(TextureBrowser_assignTags), NULL);
2243 g_signal_connect(G_OBJECT (m_btn_right), "clicked", G_CALLBACK(TextureBrowser_removeTags), NULL);
2245 gtk_widget_show(m_btn_left);
2246 gtk_widget_show(m_btn_right);
2247 gtk_widget_show(m_arrow_left);
2248 gtk_widget_show(m_arrow_right);
2250 { // tag fram labels
2251 GtkWidget* m_lbl_assigned = gtk_label_new ("Assigned");
2252 GtkWidget* m_lbl_unassigned = gtk_label_new ("Available");
2254 gtk_table_attach (GTK_TABLE (frame_table), m_lbl_assigned, 0, 1, 0, 1, GTK_EXPAND, GTK_SHRINK, 0, 0);
2255 gtk_table_attach (GTK_TABLE (frame_table), m_lbl_unassigned, 2, 3, 0, 1, GTK_EXPAND, GTK_SHRINK, 0, 0);
2257 gtk_widget_show (m_lbl_assigned);
2258 gtk_widget_show (m_lbl_unassigned);
2260 } else { // no tag support, show the texture tree only
2261 gtk_box_pack_start(GTK_BOX(vbox), g_TextureBrowser.m_scr_win_tree, TRUE, TRUE, 0);
2264 // TODO do we need this?
2265 //gtk_container_set_focus_chain(GTK_CONTAINER(hbox_table), NULL);
2270 void TextureBrowser_destroyWindow()
2272 GlobalShaderSystem().setActiveShadersChangedNotify(Callback());
2274 g_signal_handler_disconnect(G_OBJECT(g_TextureBrowser.m_gl_widget), g_TextureBrowser.m_sizeHandler);
2275 g_signal_handler_disconnect(G_OBJECT(g_TextureBrowser.m_gl_widget), g_TextureBrowser.m_exposeHandler);
2277 gtk_widget_unref(g_TextureBrowser.m_gl_widget);
2280 const Vector3& TextureBrowser_getBackgroundColour(TextureBrowser& textureBrowser)
2282 return textureBrowser.color_textureback;
2285 void TextureBrowser_setBackgroundColour(TextureBrowser& textureBrowser, const Vector3& colour)
2287 textureBrowser.color_textureback = colour;
2288 TextureBrowser_queueDraw(textureBrowser);
2291 void TextureBrowser_selectionHelper(GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter, GSList** selected)
2293 g_assert(selected != NULL);
2296 gtk_tree_model_get(model, iter, TAG_COLUMN, &name, -1);
2297 *selected = g_slist_append(*selected, name);
2300 void TextureBrowser_shaderInfo()
2302 const char* name = TextureBrowser_GetSelectedShader(g_TextureBrowser);
2303 IShader* shader = QERApp_Shader_ForName(name);
2305 DoShaderInfoDlg(name, shader->getShaderFileName(), "Shader Info");
2310 void TextureBrowser_addTag()
2314 EMessageBoxReturn result = DoShaderTagDlg(&tag, "Add shader tag");
2316 if (result == eIDOK && !tag.empty())
2318 GtkTreeIter iter, iter2;
2319 g_TextureBrowser.m_all_tags.insert(tag.c_str());
2320 gtk_list_store_append(g_TextureBrowser.m_available_store, &iter);
2321 gtk_list_store_set(g_TextureBrowser.m_available_store, &iter, TAG_COLUMN, tag.c_str(), -1);
2323 // Select the currently added tag in the available list
2324 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_TextureBrowser.m_available_tree));
2325 gtk_tree_selection_select_iter(selection, &iter);
2327 gtk_list_store_append(g_TextureBrowser.m_all_tags_list, &iter2);
2328 gtk_list_store_set(g_TextureBrowser.m_all_tags_list, &iter2, TAG_COLUMN, tag.c_str(), -1);
2332 void TextureBrowser_renameTag()
2334 /* WORKAROUND: The tag treeview is set to GTK_SELECTION_MULTIPLE. Because
2335 gtk_tree_selection_get_selected() doesn't work with GTK_SELECTION_MULTIPLE,
2336 we need to count the number of selected rows first and use
2337 gtk_tree_selection_selected_foreach() then to go through the list of selected
2338 rows (which always containins a single row).
2341 GSList* selected = NULL;
2343 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTags));
2344 gtk_tree_selection_selected_foreach(selection, GtkTreeSelectionForeachFunc(TextureBrowser_selectionHelper), &selected);
2346 if(g_slist_length(selected) == 1) // we only rename a single tag
2348 CopiedString newTag;
2349 EMessageBoxReturn result = DoShaderTagDlg(&newTag, "Rename shader tag");
2351 if (result == eIDOK && !newTag.empty())
2353 GtkTreeIter iterList;
2355 gchar* oldTag = (char*)selected->data;
2357 bool row = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(g_TextureBrowser.m_all_tags_list), &iterList) != 0;
2361 gtk_tree_model_get(GTK_TREE_MODEL(g_TextureBrowser.m_all_tags_list), &iterList, TAG_COLUMN, &rowTag, -1);
2363 if(strcmp(rowTag, oldTag) == 0)
2365 gtk_list_store_set(g_TextureBrowser.m_all_tags_list, &iterList, TAG_COLUMN, newTag.c_str(), -1);
2367 row = gtk_tree_model_iter_next(GTK_TREE_MODEL(g_TextureBrowser.m_all_tags_list), &iterList) != 0;
2370 TagBuilder.RenameShaderTag(oldTag, newTag.c_str());
2372 g_TextureBrowser.m_all_tags.erase((CopiedString)oldTag);
2373 g_TextureBrowser.m_all_tags.insert(newTag);
2375 BuildStoreAssignedTags(g_TextureBrowser.m_assigned_store, g_TextureBrowser.shader.c_str(), &g_TextureBrowser);
2376 BuildStoreAvailableTags(g_TextureBrowser.m_available_store, g_TextureBrowser.m_assigned_store, g_TextureBrowser.m_all_tags, &g_TextureBrowser);
2381 gtk_MessageBox(GTK_WIDGET(g_TextureBrowser.m_parent), "Select a single tag for renaming.");
2385 void TextureBrowser_deleteTag()
2387 GSList* selected = NULL;
2389 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(g_TextureBrowser.m_treeViewTags));
2390 gtk_tree_selection_selected_foreach(selection, GtkTreeSelectionForeachFunc(TextureBrowser_selectionHelper), &selected);
2392 if(g_slist_length(selected) == 1) // we only delete a single tag
2394 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);
2396 if(result == eIDYES)
2398 GtkTreeIter iterSelected;
2401 gchar* tagSelected = (char*)selected->data;
2403 bool row = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(g_TextureBrowser.m_all_tags_list), &iterSelected) != 0;
2407 gtk_tree_model_get(GTK_TREE_MODEL(g_TextureBrowser.m_all_tags_list), &iterSelected, TAG_COLUMN, &rowTag, -1);
2409 if(strcmp(rowTag, tagSelected) == 0)
2411 gtk_list_store_remove(g_TextureBrowser.m_all_tags_list, &iterSelected);
2414 row = gtk_tree_model_iter_next(GTK_TREE_MODEL(g_TextureBrowser.m_all_tags_list), &iterSelected) != 0;
2417 TagBuilder.DeleteTag(tagSelected);
2418 g_TextureBrowser.m_all_tags.erase((CopiedString)tagSelected);
2420 BuildStoreAssignedTags(g_TextureBrowser.m_assigned_store, g_TextureBrowser.shader.c_str(), &g_TextureBrowser);
2421 BuildStoreAvailableTags(g_TextureBrowser.m_available_store, g_TextureBrowser.m_assigned_store, g_TextureBrowser.m_all_tags, &g_TextureBrowser);
2424 gtk_MessageBox(GTK_WIDGET(g_TextureBrowser.m_parent), "Select a single tag for deletion.");
2428 void TextureBrowser_copyTag()
2430 g_TextureBrowser.m_copied_tags.clear();
2431 TagBuilder.GetShaderTags(g_TextureBrowser.shader.c_str(), g_TextureBrowser.m_copied_tags);
2434 void TextureBrowser_pasteTag()
2436 IShader* ishader = QERApp_Shader_ForName(g_TextureBrowser.shader.c_str());
2437 CopiedString shader = g_TextureBrowser.shader.c_str();
2439 if(!TagBuilder.CheckShaderTag(shader.c_str()))
2441 CopiedString shaderFile = ishader->getShaderFileName();
2442 if(shaderFile.empty())
2445 TagBuilder.AddShaderNode(shader.c_str(), CUSTOM, TEXTURE);
2450 TagBuilder.AddShaderNode(shader.c_str(), CUSTOM, SHADER);
2453 for(size_t i = 0; i < g_TextureBrowser.m_copied_tags.size(); ++i)
2455 TagBuilder.AddShaderTag(shader.c_str(), g_TextureBrowser.m_copied_tags[i].c_str(), TAG);
2460 for(size_t i = 0; i < g_TextureBrowser.m_copied_tags.size(); ++i)
2462 if(!TagBuilder.CheckShaderTag(shader.c_str(), g_TextureBrowser.m_copied_tags[i].c_str()))
2464 // the tag doesn't exist - let's add it
2465 TagBuilder.AddShaderTag(shader.c_str(), g_TextureBrowser.m_copied_tags[i].c_str(), TAG);
2472 TagBuilder.SaveXmlDoc();
2473 BuildStoreAssignedTags(g_TextureBrowser.m_assigned_store, shader.c_str(), &g_TextureBrowser);
2474 BuildStoreAvailableTags (g_TextureBrowser.m_available_store, g_TextureBrowser.m_assigned_store, g_TextureBrowser.m_all_tags, &g_TextureBrowser);
2477 void RefreshShaders()
2479 ScopeDisableScreenUpdates disableScreenUpdates("Processing...", "Loading Shaders");
2480 GlobalShaderSystem().refresh();
2484 void TextureBrowser_ToggleShowShaders()
2486 g_TextureBrowser.m_showShaders ^= 1;
2487 g_TextureBrowser.m_showshaders_item.update();
2488 TextureBrowser_queueDraw(g_TextureBrowser);
2491 void TextureBrowser_ToggleShowShaderListOnly()
2493 g_TextureBrowser_shaderlistOnly ^= 1;
2494 g_TextureBrowser.m_showshaderlistonly_item.update();
2496 TextureBrowser_constructTreeStore();
2499 void TextureBrowser_showAll()
2501 g_TextureBrowser_currentDirectory = "";
2502 g_TextureBrowser.m_searchedTags = false;
2503 TextureBrowser_heightChanged(g_TextureBrowser);
2504 TextureBrowser_updateTitle();
2507 void TextureBrowser_showUntagged()
2509 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);
2511 if(result == eIDYES)
2513 g_TextureBrowser.m_found_shaders.clear();
2514 TagBuilder.GetUntagged(g_TextureBrowser.m_found_shaders);
2515 std::set<CopiedString>::iterator iter;
2517 ScopeDisableScreenUpdates disableScreenUpdates("Searching untagged textures...", "Loading Textures");
2519 for(iter = g_TextureBrowser.m_found_shaders.begin(); iter != g_TextureBrowser.m_found_shaders.end(); iter++)
2521 std::string path = (*iter).c_str();
2522 size_t pos = path.find_last_of("/", path.size());
2523 std::string name = path.substr(pos + 1, path.size());
2524 path = path.substr(0, pos + 1);
2525 TextureDirectory_loadTexture(path.c_str(), name.c_str());
2526 globalErrorStream() << path.c_str() << name.c_str() << "\n";
2529 g_TextureBrowser_currentDirectory = "Untagged";
2530 TextureBrowser_queueDraw(GlobalTextureBrowser());
2531 TextureBrowser_heightChanged(g_TextureBrowser);
2532 TextureBrowser_updateTitle();
2536 void TextureBrowser_FixedSize()
2538 g_TextureBrowser_fixedSize ^= 1;
2539 GlobalTextureBrowser().m_fixedsize_item.update();
2540 TextureBrowser_activeShadersChanged(GlobalTextureBrowser());
2543 void TextureBrowser_FilterNotex()
2545 g_TextureBrowser_filterNotex ^= 1;
2546 GlobalTextureBrowser().m_filternotex_item.update();
2547 TextureBrowser_activeShadersChanged(GlobalTextureBrowser());
2550 void TextureBrowser_exportTitle(const StringImportCallback& importer)
2552 StringOutputStream buffer(64);
2553 buffer << "Textures: ";
2554 if(!string_empty(g_TextureBrowser_currentDirectory.c_str()))
2556 buffer << g_TextureBrowser_currentDirectory.c_str();
2562 importer(buffer.c_str());
2566 void TextureScaleImport(TextureBrowser& textureBrowser, int value)
2571 TextureBrowser_setScale(textureBrowser, 10);
2574 TextureBrowser_setScale(textureBrowser, 25);
2577 TextureBrowser_setScale(textureBrowser, 50);
2580 TextureBrowser_setScale(textureBrowser, 100);
2583 TextureBrowser_setScale(textureBrowser, 200);
2587 typedef ReferenceCaller1<TextureBrowser, int, TextureScaleImport> TextureScaleImportCaller;
2589 void TextureScaleExport(TextureBrowser& textureBrowser, const IntImportCallback& importer)
2591 switch(textureBrowser.m_textureScale)
2610 typedef ReferenceCaller1<TextureBrowser, const IntImportCallback&, TextureScaleExport> TextureScaleExportCaller;
2612 void TextureBrowser_constructPreferences(PreferencesPage& page)
2614 page.appendCheckBox(
2615 "", "Texture scrollbar",
2616 TextureBrowserImportShowScrollbarCaller(GlobalTextureBrowser()),
2617 BoolExportCaller(GlobalTextureBrowser().m_showTextureScrollbar)
2620 const char* texture_scale[] = { "10%", "25%", "50%", "100%", "200%" };
2622 "Texture Thumbnail Scale",
2623 STRING_ARRAY_RANGE(texture_scale),
2624 IntImportCallback(TextureScaleImportCaller(GlobalTextureBrowser())),
2625 IntExportCallback(TextureScaleExportCaller(GlobalTextureBrowser()))
2628 page.appendEntry("Mousewheel Increment", GlobalTextureBrowser().m_mouseWheelScrollIncrement);
2630 const char* startup_shaders[] = { "None", TextureBrowser_getComonShadersName() };
2631 page.appendCombo("Load Shaders at Startup", reinterpret_cast<int&>(GlobalTextureBrowser().m_startupShaders), STRING_ARRAY_RANGE(startup_shaders));
2634 void TextureBrowser_constructPage(PreferenceGroup& group)
2636 PreferencesPage page(group.createPage("Texture Browser", "Texture Browser Preferences"));
2637 TextureBrowser_constructPreferences(page);
2639 void TextureBrowser_registerPreferencesPage()
2641 PreferencesDialog_addSettingsPage(FreeCaller1<PreferenceGroup&, TextureBrowser_constructPage>());
2645 #include "preferencesystem.h"
2646 #include "stringio.h"
2648 typedef ReferenceCaller1<TextureBrowser, std::size_t, TextureBrowser_setScale> TextureBrowserSetScaleCaller;
2652 void TextureClipboard_textureSelected(const char* shader);
2654 void TextureBrowser_Construct()
2656 GlobalCommands_insert("ShaderInfo", FreeCaller<TextureBrowser_shaderInfo>());
2657 GlobalCommands_insert("ShowUntagged", FreeCaller<TextureBrowser_showUntagged>());
2658 GlobalCommands_insert("AddTag", FreeCaller<TextureBrowser_addTag>());
2659 GlobalCommands_insert("RenameTag", FreeCaller<TextureBrowser_renameTag>());
2660 GlobalCommands_insert("DeleteTag", FreeCaller<TextureBrowser_deleteTag>());
2661 GlobalCommands_insert("CopyTag", FreeCaller<TextureBrowser_copyTag>());
2662 GlobalCommands_insert("PasteTag", FreeCaller<TextureBrowser_pasteTag>());
2663 GlobalCommands_insert("RefreshShaders", FreeCaller<RefreshShaders>());
2664 GlobalToggles_insert("ShowInUse", FreeCaller<TextureBrowser_ToggleHideUnused>(), ToggleItem::AddCallbackCaller(g_TextureBrowser.m_hideunused_item), Accelerator('U'));
2665 GlobalCommands_insert("ShowAllTextures", FreeCaller<TextureBrowser_showAll>(), Accelerator('A', (GdkModifierType)GDK_CONTROL_MASK));
2666 GlobalCommands_insert("ToggleTextures", FreeCaller<TextureBrowser_toggleShow>(), Accelerator('T'));
2667 GlobalToggles_insert("ToggleShowShaders", FreeCaller<TextureBrowser_ToggleShowShaders>(), ToggleItem::AddCallbackCaller(g_TextureBrowser.m_showshaders_item));
2668 GlobalToggles_insert("ToggleShowShaderlistOnly", FreeCaller<TextureBrowser_ToggleShowShaderListOnly>(), ToggleItem::AddCallbackCaller(g_TextureBrowser.m_showshaderlistonly_item));
2669 GlobalToggles_insert("FixedSize", FreeCaller<TextureBrowser_FixedSize>(), ToggleItem::AddCallbackCaller(g_TextureBrowser.m_fixedsize_item));
2670 GlobalToggles_insert("FilterNotex", FreeCaller<TextureBrowser_FilterNotex>(), ToggleItem::AddCallbackCaller(g_TextureBrowser.m_filternotex_item));
2672 GlobalPreferenceSystem().registerPreference("TextureScale",
2673 makeSizeStringImportCallback(TextureBrowserSetScaleCaller(g_TextureBrowser)),
2674 SizeExportStringCaller(g_TextureBrowser.m_textureScale)
2676 GlobalPreferenceSystem().registerPreference("TextureScrollbar",
2677 makeBoolStringImportCallback(TextureBrowserImportShowScrollbarCaller(g_TextureBrowser)),
2678 BoolExportStringCaller(GlobalTextureBrowser().m_showTextureScrollbar)
2680 GlobalPreferenceSystem().registerPreference("ShowShaders", BoolImportStringCaller(GlobalTextureBrowser().m_showShaders), BoolExportStringCaller(GlobalTextureBrowser().m_showShaders));
2681 GlobalPreferenceSystem().registerPreference("ShowShaderlistOnly", BoolImportStringCaller(g_TextureBrowser_shaderlistOnly), BoolExportStringCaller(g_TextureBrowser_shaderlistOnly));
2682 GlobalPreferenceSystem().registerPreference("FixedSize", BoolImportStringCaller(g_TextureBrowser_fixedSize), BoolExportStringCaller(g_TextureBrowser_fixedSize));
2683 GlobalPreferenceSystem().registerPreference("FilterNotex", BoolImportStringCaller(g_TextureBrowser_filterNotex), BoolExportStringCaller(g_TextureBrowser_filterNotex));
2684 GlobalPreferenceSystem().registerPreference("LoadShaders", IntImportStringCaller(reinterpret_cast<int&>(GlobalTextureBrowser().m_startupShaders)), IntExportStringCaller(reinterpret_cast<int&>(GlobalTextureBrowser().m_startupShaders)));
2685 GlobalPreferenceSystem().registerPreference("WheelMouseInc", SizeImportStringCaller(GlobalTextureBrowser().m_mouseWheelScrollIncrement), SizeExportStringCaller(GlobalTextureBrowser().m_mouseWheelScrollIncrement));
2686 GlobalPreferenceSystem().registerPreference("SI_Colors0", Vector3ImportStringCaller(GlobalTextureBrowser().color_textureback), Vector3ExportStringCaller(GlobalTextureBrowser().color_textureback));
2688 g_TextureBrowser.shader = texdef_name_default();
2690 Textures_setModeChangedNotify(ReferenceCaller<TextureBrowser, TextureBrowser_queueDraw>(g_TextureBrowser));
2692 TextureBrowser_registerPreferencesPage();
2694 GlobalShaderSystem().attach(g_ShadersObserver);
2696 TextureBrowser_textureSelected = TextureClipboard_textureSelected;
2698 void TextureBrowser_Destroy()
2700 GlobalShaderSystem().detach(g_ShadersObserver);
2702 Textures_setModeChangedNotify(Callback());