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"
32 #include "debugging/debugging.h"
36 #include "ifilesystem.h"
40 #include "moduleobserver.h"
46 #include <uilib/uilib.h>
48 #include "signal/signal.h"
49 #include "math/vector.h"
50 #include "texturelib.h"
51 #include "string/string.h"
52 #include "shaderlib.h"
55 #include "stream/memstream.h"
56 #include "stream/textfilestream.h"
57 #include "stream/stringstream.h"
63 #include "gtkutil/menu.h"
64 #include "gtkutil/nonmodal.h"
65 #include "gtkutil/cursor.h"
66 #include "gtkutil/widget.h"
67 #include "gtkutil/glwidget.h"
68 #include "gtkutil/messagebox.h"
74 #include "brush_primit.h"
75 #include "brushmanip.h"
76 #include "patchmanip.h"
81 #include "mainframe.h"
82 #include "findtexturedialog.h"
83 #include "surfacedialog.h"
84 #include "patchdialog.h"
85 #include "groupdialog.h"
86 #include "preferences.h"
90 bool TextureBrowser_showWads(){
91 return !string_empty( g_pGameDescription->getKeyValue( "show_wads" ) );
94 void TextureBrowser_queueDraw( TextureBrowser& textureBrowser );
96 bool string_equal_start( const char* string, StringRange start ){
97 return string_equal_n( string, start.first, start.last - start.first );
100 typedef std::set<CopiedString> TextureGroups;
102 void TextureGroups_addWad( TextureGroups& groups, const char* archive ){
103 if ( extension_equal( path_get_extension( archive ), "wad" ) ) {
105 groups.insert( archive );
107 CopiedString archiveBaseName( path_get_filename_start( archive ), path_get_filename_base_end( archive ) );
108 groups.insert( archiveBaseName );
113 typedef ReferenceCaller<TextureGroups, void(const char*), TextureGroups_addWad> TextureGroupsAddWadCaller;
117 bool g_TextureBrowser_shaderlistOnly = false;
118 bool g_TextureBrowser_fixedSize = true;
119 bool g_TextureBrowser_filterMissing = false;
120 bool g_TextureBrowser_filterFallback = true;
121 bool g_TextureBrowser_enableAlpha = false;
124 CopiedString g_notex;
125 CopiedString g_shadernotex;
127 bool isMissing(const char* name);
129 bool isNotex(const char* name);
131 bool isMissing(const char* name){
132 if ( string_equal( g_notex.c_str(), name ) ) {
135 if ( string_equal( g_shadernotex.c_str(), name ) ) {
141 bool isNotex(const char* name){
142 if ( string_equal_suffix( name, "/" DEFAULT_NOTEX_BASENAME ) ) {
145 if ( string_equal_suffix( name, "/" DEFAULT_SHADERNOTEX_BASENAME ) ) {
151 void TextureGroups_addShader( TextureGroups& groups, const char* shaderName ){
152 const char* texture = path_make_relative( shaderName, "textures/" );
154 // hide notex / shadernotex images
155 if ( g_TextureBrowser_filterFallback ) {
156 if ( isNotex( shaderName ) ) {
159 if ( isNotex( texture ) ) {
164 if ( texture != shaderName ) {
165 const char* last = path_remove_directory( texture );
166 if ( !string_empty( last ) ) {
167 groups.insert( CopiedString( StringRange( texture, --last ) ) );
172 typedef ReferenceCaller<TextureGroups, void(const char*), TextureGroups_addShader> TextureGroupsAddShaderCaller;
174 void TextureGroups_addDirectory( TextureGroups& groups, const char* directory ){
175 groups.insert( directory );
178 typedef ReferenceCaller<TextureGroups, void(const char*), TextureGroups_addDirectory> TextureGroupsAddDirectoryCaller;
180 class DeferredAdjustment
185 typedef void ( *ValueChangedFunction )( void* data, gdouble value );
187 ValueChangedFunction m_function;
190 static gboolean deferred_value_changed( gpointer data ){
191 reinterpret_cast<DeferredAdjustment*>( data )->m_function(
192 reinterpret_cast<DeferredAdjustment*>( data )->m_data,
193 reinterpret_cast<DeferredAdjustment*>( data )->m_value
195 reinterpret_cast<DeferredAdjustment*>( data )->m_handler = 0;
196 reinterpret_cast<DeferredAdjustment*>( data )->m_value = 0;
201 DeferredAdjustment( ValueChangedFunction function, void* data ) : m_value( 0 ), m_handler( 0 ), m_function( function ), m_data( data ){
205 if ( m_handler != 0 ) {
206 g_source_remove( m_handler );
207 deferred_value_changed( this );
211 void value_changed( gdouble value ){
213 if ( m_handler == 0 ) {
214 m_handler = g_idle_add( deferred_value_changed, this );
218 static void adjustment_value_changed(ui::Adjustment adjustment, DeferredAdjustment* self ){
219 self->value_changed( gtk_adjustment_get_value(adjustment) );
224 class TextureBrowser;
226 typedef ReferenceCaller<TextureBrowser, void(), TextureBrowser_queueDraw> TextureBrowserQueueDrawCaller;
228 void TextureBrowser_scrollChanged( void* data, gdouble value );
233 STARTUPSHADERS_NONE = 0,
234 STARTUPSHADERS_COMMON,
237 void TextureBrowser_hideUnusedExport( const Callback<void(bool)> & importer );
239 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_hideUnusedExport> TextureBrowserHideUnusedExport;
241 void TextureBrowser_showShadersExport( const Callback<void(bool)> & importer );
243 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_showShadersExport> TextureBrowserShowShadersExport;
245 void TextureBrowser_showTexturesExport( const Callback<void(bool)> & importer );
247 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_showTexturesExport> TextureBrowserShowTexturesExport;
249 void TextureBrowser_showShaderlistOnly( const Callback<void(bool)> & importer );
251 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_showShaderlistOnly> TextureBrowserShowShaderlistOnlyExport;
253 void TextureBrowser_fixedSize( const Callback<void(bool)> & importer );
255 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_fixedSize> TextureBrowserFixedSizeExport;
257 void TextureBrowser_filterMissing( const Callback<void(bool)> & importer );
259 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_filterMissing> TextureBrowserFilterMissingExport;
261 void TextureBrowser_filterFallback( const Callback<void(bool)> & importer );
263 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_filterFallback> TextureBrowserFilterFallbackExport;
265 void TextureBrowser_enableAlpha( const Callback<void(bool)> & importer );
267 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_enableAlpha> TextureBrowserEnableAlphaExport;
278 ui::Window m_parent{ui::null};
279 ui::GLArea m_gl_widget{ui::null};
280 ui::Widget m_texture_scroll{ui::null};
281 ui::TreeView m_treeViewTree{ui::New};
282 ui::TreeView m_treeViewTags{ui::null};
283 ui::Frame m_tag_frame{ui::null};
284 ui::ListStore m_assigned_store{ui::null};
285 ui::ListStore m_available_store{ui::null};
286 ui::TreeView m_assigned_tree{ui::null};
287 ui::TreeView m_available_tree{ui::null};
288 ui::Widget m_scr_win_tree{ui::null};
289 ui::Widget m_scr_win_tags{ui::null};
290 ui::Widget m_tag_notebook{ui::null};
291 ui::Button m_search_button{ui::null};
292 ui::Widget m_shader_info_item{ui::null};
294 std::set<CopiedString> m_all_tags;
295 ui::ListStore m_all_tags_list{ui::null};
296 std::vector<CopiedString> m_copied_tags;
297 std::set<CopiedString> m_found_shaders;
299 ToggleItem m_hideunused_item;
300 ToggleItem m_hidenotex_item;
301 ToggleItem m_showshaders_item;
302 ToggleItem m_showtextures_item;
303 ToggleItem m_showshaderlistonly_item;
304 ToggleItem m_fixedsize_item;
305 ToggleItem m_filternotex_item;
306 ToggleItem m_enablealpha_item;
309 guint m_exposeHandler;
311 bool m_heightChanged;
312 bool m_originInvalid;
314 DeferredAdjustment m_scrollAdjustment;
315 FreezePointer m_freezePointer;
317 Vector3 color_textureback;
318 // the increment step we use against the wheel mouse
319 std::size_t m_mouseWheelScrollIncrement;
320 std::size_t m_textureScale;
321 // make the texture increments match the grid changes
324 bool m_showTextureScrollbar;
325 StartupShaders m_startupShaders;
326 // if true, the texture window will only display in-use shaders
327 // if false, all the shaders in memory are displayed
333 // The uniform size (in pixels) that textures are resized to when m_resizeTextures is true.
334 int m_uniformTextureSize;
335 int m_uniformTextureMinSize;
337 bool m_hideNonShadersInCommon;
338 // Return the display width of a texture in the texture browser
339 void getTextureWH( qtexture_t* tex, int &W, int &H ){
340 // Don't use uniform size
341 W = (int)( tex->width * ( (float)m_textureScale / 100 ) );
342 H = (int)( tex->height * ( (float)m_textureScale / 100 ) );
346 if ( g_TextureBrowser_fixedSize ){
348 // Texture is square, or wider than it is tall
349 if ( W >= m_uniformTextureSize ){
350 H = m_uniformTextureSize * H / W;
351 W = m_uniformTextureSize;
353 else if ( W <= m_uniformTextureMinSize ){
354 H = m_uniformTextureMinSize * H / W;
355 W = m_uniformTextureMinSize;
359 // Texture taller than it is wide
360 if ( H >= m_uniformTextureSize ){
361 W = m_uniformTextureSize * W / H;
362 H = m_uniformTextureSize;
364 else if ( H <= m_uniformTextureMinSize ){
365 W = m_uniformTextureMinSize * W / H;
366 H = m_uniformTextureMinSize;
373 m_texture_scroll( ui::null ),
374 m_hideunused_item( TextureBrowserHideUnusedExport() ),
375 m_hidenotex_item( TextureBrowserFilterFallbackExport() ),
376 m_showshaders_item( TextureBrowserShowShadersExport() ),
377 m_showtextures_item( TextureBrowserShowTexturesExport() ),
378 m_showshaderlistonly_item( TextureBrowserShowShaderlistOnlyExport() ),
379 m_fixedsize_item( TextureBrowserFixedSizeExport() ),
380 m_filternotex_item( TextureBrowserFilterMissingExport() ),
381 m_enablealpha_item( TextureBrowserEnableAlphaExport() ),
382 m_heightChanged( true ),
383 m_originInvalid( true ),
384 m_scrollAdjustment( TextureBrowser_scrollChanged, this ),
385 color_textureback( 0.25f, 0.25f, 0.25f ),
386 m_mouseWheelScrollIncrement( 64 ),
387 m_textureScale( 50 ),
388 m_showShaders( true ),
389 m_showTextures( true ),
390 m_showTextureScrollbar( true ),
391 m_startupShaders( STARTUPSHADERS_NONE ),
392 m_hideUnused( false ),
393 m_rmbSelected( false ),
394 m_searchedTags( false ),
396 m_uniformTextureSize( 160 ),
397 m_uniformTextureMinSize( 48 ),
398 m_hideNonShadersInCommon( true ),
399 m_move_started( false ){
403 void ( *TextureBrowser_textureSelected )( const char* shader );
406 void TextureBrowser_updateScroll( TextureBrowser& textureBrowser );
409 const char* TextureBrowser_getComonShadersName(){
410 const char* value = g_pGameDescription->getKeyValue( "common_shaders_name" );
411 if ( !string_empty( value ) ) {
417 const char* TextureBrowser_getComonShadersDir(){
418 const char* value = g_pGameDescription->getKeyValue( "common_shaders_dir" );
419 if ( !string_empty( value ) ) {
425 inline int TextureBrowser_fontHeight( TextureBrowser& textureBrowser ){
426 return GlobalOpenGL().m_font->getPixelHeight();
429 const char* TextureBrowser_GetSelectedShader( TextureBrowser& textureBrowser ){
430 return textureBrowser.shader.c_str();
433 void TextureBrowser_SetStatus( TextureBrowser& textureBrowser, const char* name ){
434 IShader* shader = QERApp_Shader_ForName( name );
435 qtexture_t* q = shader->getTexture();
436 StringOutputStream strTex( 256 );
437 strTex << name << " W: " << Unsigned( q->width ) << " H: " << Unsigned( q->height );
439 g_pParentWnd->SetStatusText( g_pParentWnd->m_texture_status, strTex.c_str() );
442 void TextureBrowser_Focus( TextureBrowser& textureBrowser, const char* name );
444 void TextureBrowser_SetSelectedShader( TextureBrowser& textureBrowser, const char* shader ){
445 textureBrowser.shader = shader;
446 TextureBrowser_SetStatus( textureBrowser, shader );
447 TextureBrowser_Focus( textureBrowser, shader );
449 if ( FindTextureDialog_isOpen() ) {
450 FindTextureDialog_selectTexture( shader );
453 // disable the menu item "shader info" if no shader was selected
454 IShader* ishader = QERApp_Shader_ForName( shader );
455 CopiedString filename = ishader->getShaderFileName();
457 if ( filename.empty() ) {
458 if ( textureBrowser.m_shader_info_item != NULL ) {
459 gtk_widget_set_sensitive( textureBrowser.m_shader_info_item, FALSE );
463 gtk_widget_set_sensitive( textureBrowser.m_shader_info_item, TRUE );
470 CopiedString g_TextureBrowser_currentDirectory;
473 ============================================================================
477 TTimo: now based on a rundown through all the shaders
478 NOTE: we expect the Active shaders count doesn't change during a Texture_StartPos .. Texture_NextPos cycle
479 otherwise we may need to rely on a list instead of an array storage
480 ============================================================================
486 // texture layout functions
487 // TTimo: now based on shaders
488 int current_x, current_y, current_row;
491 void Texture_StartPos( TextureLayout& layout ){
492 layout.current_x = 8;
493 layout.current_y = -8;
494 layout.current_row = 0;
497 void Texture_NextPos( TextureBrowser& textureBrowser, TextureLayout& layout, qtexture_t* current_texture, int *x, int *y ){
498 qtexture_t* q = current_texture;
501 textureBrowser.getTextureWH( q, nWidth, nHeight );
502 if ( layout.current_x + nWidth > textureBrowser.width - 8 && layout.current_row ) { // go to the next row unless the texture is the first on the row
503 layout.current_x = 8;
504 layout.current_y -= layout.current_row + TextureBrowser_fontHeight( textureBrowser ) + 4;//+4
505 layout.current_row = 0;
508 *x = layout.current_x;
509 *y = layout.current_y;
511 // Is our texture larger than the row? If so, grow the
512 // row height to match it
514 if ( layout.current_row < nHeight ) {
515 layout.current_row = nHeight;
518 // never go less than 96, or the names get all crunched up
519 layout.current_x += nWidth < 96 ? 96 : nWidth;
520 layout.current_x += 8;
523 bool TextureSearch_IsShown( const char* name ){
524 std::set<CopiedString>::iterator iter;
526 iter = GlobalTextureBrowser().m_found_shaders.find( name );
528 if ( iter == GlobalTextureBrowser().m_found_shaders.end() ) {
536 // if texture_showinuse jump over non in-use textures
537 bool Texture_IsShown( IShader* shader, bool show_shaders, bool show_textures, bool hideUnused, bool hideNonShadersInCommon ){
538 // filter missing shaders
539 // ugly: filter on built-in fallback name after substitution
540 if ( g_TextureBrowser_filterMissing ) {
541 if ( isMissing( shader->getTexture()->name ) ) {
545 // filter the fallback (notex/shadernotex) for missing shaders or editor image
546 if ( g_TextureBrowser_filterFallback ) {
547 if ( isNotex( shader->getName() ) ) {
550 if ( isNotex( shader->getTexture()->name ) ) {
555 if ( g_TextureBrowser_currentDirectory == "Untagged" ) {
556 std::set<CopiedString>::iterator iter;
558 iter = GlobalTextureBrowser().m_found_shaders.find( shader->getName() );
560 if ( iter == GlobalTextureBrowser().m_found_shaders.end() ) {
568 if ( !shader_equal_prefix( shader->getName(), "textures/" ) ) {
572 if ( !show_shaders && !shader->IsDefault() ) {
576 if ( !show_textures && shader->IsDefault() ) {
580 if ( hideUnused && !shader->IsInUse() ) {
584 if( hideNonShadersInCommon && shader->IsDefault() && !shader->IsInUse() //&& g_TextureBrowser_currentDirectory != ""
585 && shader_equal_prefix( shader_get_textureName( shader->getName() ), TextureBrowser_getComonShadersDir() ) ){
589 if ( GlobalTextureBrowser().m_searchedTags ) {
590 if ( !TextureSearch_IsShown( shader->getName() ) ) {
598 if ( !shader_equal_prefix( shader_get_textureName( shader->getName() ), g_TextureBrowser_currentDirectory.c_str() ) ) {
606 void TextureBrowser_heightChanged( TextureBrowser& textureBrowser ){
607 textureBrowser.m_heightChanged = true;
609 TextureBrowser_updateScroll( textureBrowser );
610 TextureBrowser_queueDraw( textureBrowser );
613 void TextureBrowser_evaluateHeight( TextureBrowser& textureBrowser ){
614 if ( textureBrowser.m_heightChanged ) {
615 textureBrowser.m_heightChanged = false;
617 textureBrowser.m_nTotalHeight = 0;
619 TextureLayout layout;
620 Texture_StartPos( layout );
621 for ( QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement() )
623 IShader* shader = QERApp_ActiveShaders_IteratorCurrent();
625 if ( !Texture_IsShown( shader, textureBrowser.m_showShaders, textureBrowser.m_showTextures, textureBrowser.m_hideUnused, textureBrowser.m_hideNonShadersInCommon ) ) {
630 Texture_NextPos( textureBrowser, layout, shader->getTexture(), &x, &y );
632 textureBrowser.getTextureWH( shader->getTexture(), nWidth, nHeight );
633 textureBrowser.m_nTotalHeight = std::max( textureBrowser.m_nTotalHeight, abs( layout.current_y ) + TextureBrowser_fontHeight( textureBrowser ) + nHeight + 4 );
638 int TextureBrowser_TotalHeight( TextureBrowser& textureBrowser ){
639 TextureBrowser_evaluateHeight( textureBrowser );
640 return textureBrowser.m_nTotalHeight;
643 inline const int& min_int( const int& left, const int& right ){
644 return std::min( left, right );
647 void TextureBrowser_clampOriginY( TextureBrowser& textureBrowser ){
648 if ( textureBrowser.originy > 0 ) {
649 textureBrowser.originy = 0;
651 int lower = min_int( textureBrowser.height - TextureBrowser_TotalHeight( textureBrowser ), 0 );
652 if ( textureBrowser.originy < lower ) {
653 textureBrowser.originy = lower;
657 int TextureBrowser_getOriginY( TextureBrowser& textureBrowser ){
658 if ( textureBrowser.m_originInvalid ) {
659 textureBrowser.m_originInvalid = false;
660 TextureBrowser_clampOriginY( textureBrowser );
661 TextureBrowser_updateScroll( textureBrowser );
663 return textureBrowser.originy;
666 void TextureBrowser_setOriginY( TextureBrowser& textureBrowser, int originy ){
667 textureBrowser.originy = originy;
668 TextureBrowser_clampOriginY( textureBrowser );
669 TextureBrowser_updateScroll( textureBrowser );
670 TextureBrowser_queueDraw( textureBrowser );
674 Signal0 g_activeShadersChangedCallbacks;
676 void TextureBrowser_addActiveShadersChangedCallback( const SignalHandler& handler ){
677 g_activeShadersChangedCallbacks.connectLast( handler );
680 void TextureBrowser_constructTreeStore();
682 class ShadersObserver : public ModuleObserver
684 Signal0 m_realiseCallbacks;
687 m_realiseCallbacks();
688 /* texturebrowser tree update on vfs restart */
689 // TextureBrowser_constructTreeStore();
695 void insert( const SignalHandler& handler ){
696 m_realiseCallbacks.connectLast( handler );
702 ShadersObserver g_ShadersObserver;
705 void TextureBrowser_addShadersRealiseCallback( const SignalHandler& handler ){
706 g_ShadersObserver.insert( handler );
709 void TextureBrowser_activeShadersChanged( TextureBrowser& textureBrowser ){
710 TextureBrowser_heightChanged( textureBrowser );
711 textureBrowser.m_originInvalid = true;
713 g_activeShadersChangedCallbacks();
716 struct TextureBrowser_ShowScrollbar {
717 static void Export(const TextureBrowser &self, const Callback<void(bool)> &returnz) {
718 returnz(self.m_showTextureScrollbar);
721 static void Import(TextureBrowser &self, bool value) {
722 self.m_showTextureScrollbar = value;
723 if (self.m_texture_scroll) {
724 self.m_texture_scroll.visible(self.m_showTextureScrollbar);
725 TextureBrowser_updateScroll(self);
733 TextureBrowser_ShowDirectory
734 relies on texture_directory global for the directory to use
735 1) Load the shaders for the given directory
736 2) Scan the remaining texture, load them and assign them a default shader (the "noshader" shader)
737 NOTE: when writing a texture plugin, or some texture extensions, this function may need to be overriden, and made
738 available through the IShaders interface
739 NOTE: for texture window layout:
740 all shaders are stored with alphabetical order after load
741 previously loaded and displayed stuff is hidden, only in-use and newly loaded is shown
742 ( the GL textures are not flushed though)
746 bool endswith( const char *haystack, const char *needle ){
747 size_t lh = strlen( haystack );
748 size_t ln = strlen( needle );
752 return !memcmp( haystack + ( lh - ln ), needle, ln );
755 bool texture_name_ignore( const char* name ){
756 StringOutputStream strTemp( string_length( name ) );
757 strTemp << LowerCase( name );
760 endswith( strTemp.c_str(), ".specular" ) ||
761 endswith( strTemp.c_str(), ".glow" ) ||
762 endswith( strTemp.c_str(), ".bump" ) ||
763 endswith( strTemp.c_str(), ".diffuse" ) ||
764 endswith( strTemp.c_str(), ".blend" ) ||
765 endswith( strTemp.c_str(), ".alpha" ) ||
766 endswith( strTemp.c_str(), "_alpha" ) ||
768 endswith( strTemp.c_str(), "_h" ) ||
769 endswith( strTemp.c_str(), "_local" ) ||
770 endswith( strTemp.c_str(), "_nm" ) ||
771 endswith( strTemp.c_str(), "_s" ) ||
773 endswith( strTemp.c_str(), "_bump" ) ||
774 endswith( strTemp.c_str(), "_glow" ) ||
775 endswith( strTemp.c_str(), "_gloss" ) ||
776 endswith( strTemp.c_str(), "_luma" ) ||
777 endswith( strTemp.c_str(), "_norm" ) ||
778 endswith( strTemp.c_str(), "_pants" ) ||
779 endswith( strTemp.c_str(), "_shirt" ) ||
780 endswith( strTemp.c_str(), "_reflect" ) ||
782 endswith( strTemp.c_str(), "_d" ) ||
783 endswith( strTemp.c_str(), "_n" ) ||
784 endswith( strTemp.c_str(), "_p" ) ||
785 endswith( strTemp.c_str(), "_g" ) ||
786 endswith( strTemp.c_str(), "_a" ) ||
790 class LoadShaderVisitor : public Archive::Visitor
793 void visit( const char* name ){
794 IShader* shader = QERApp_Shader_ForName( CopiedString( StringRange( name, path_get_filename_base_end( name ) ) ).c_str() );
799 void TextureBrowser_SetHideUnused( TextureBrowser& textureBrowser, bool hideUnused );
801 ui::Widget g_page_textures{ui::null};
803 void TextureBrowser_toggleShow(){
804 GroupDialog_showPage( g_page_textures );
808 void TextureBrowser_updateTitle(){
809 GroupDialog_updatePageTitle( g_page_textures );
813 class TextureCategoryLoadShader
815 const char* m_directory;
816 std::size_t& m_count;
818 using func = void(const char *);
820 TextureCategoryLoadShader( const char* directory, std::size_t& count )
821 : m_directory( directory ), m_count( count ){
825 void operator()( const char* name ) const {
826 if ( shader_equal_prefix( name, "textures/" )
827 && shader_equal_prefix( name + string_length( "textures/" ), m_directory ) ) {
829 // request the shader, this will load the texture if needed
830 // this Shader_ForName call is a kind of hack
831 IShader *pFoo = QERApp_Shader_ForName( name );
837 void TextureDirectory_loadTexture( const char* directory, const char* texture ){
838 StringOutputStream name( 256 );
839 name << directory << StringRange( texture, path_get_filename_base_end( texture ) );
841 if ( texture_name_ignore( name.c_str() ) ) {
845 if ( !shader_valid( name.c_str() ) ) {
846 globalOutputStream() << "Skipping invalid texture name: [" << name.c_str() << "]\n";
850 // if a texture is already in use to represent a shader, ignore it
851 IShader* shader = QERApp_Shader_ForName( name.c_str() );
855 typedef ConstPointerCaller<char, void(const char*), TextureDirectory_loadTexture> TextureDirectoryLoadTextureCaller;
857 class LoadTexturesByTypeVisitor : public ImageModules::Visitor
859 const char* m_dirstring;
861 LoadTexturesByTypeVisitor( const char* dirstring )
862 : m_dirstring( dirstring ){
865 void visit( const char* minor, const _QERPlugImageTable& table ) const {
866 GlobalFileSystem().forEachFile( m_dirstring, minor, TextureDirectoryLoadTextureCaller( m_dirstring ) );
870 void TextureBrowser_ShowDirectory( TextureBrowser& textureBrowser, const char* directory ){
871 if ( TextureBrowser_showWads() ) {
872 Archive* archive = GlobalFileSystem().getArchive( directory );
873 ASSERT_NOTNULL( archive );
874 LoadShaderVisitor visitor;
875 archive->forEachFile( Archive::VisitorFunc( visitor, Archive::eFiles, 0 ), "textures/" );
879 g_TextureBrowser_currentDirectory = directory;
880 TextureBrowser_heightChanged( textureBrowser );
882 std::size_t shaders_count;
883 GlobalShaderSystem().foreachShaderName(makeCallback( TextureCategoryLoadShader( directory, shaders_count ) ) );
884 globalOutputStream() << "Showing " << Unsigned( shaders_count ) << " shaders.\n";
886 if ( g_pGameDescription->mGameType != "doom3" ) {
887 // load remaining texture files
889 StringOutputStream dirstring( 64 );
890 dirstring << "textures/" << directory;
892 Radiant_getImageModules().foreachModule( LoadTexturesByTypeVisitor( dirstring.c_str() ) );
896 // we'll display the newly loaded textures + all the ones already in use
897 TextureBrowser_SetHideUnused( textureBrowser, false );
899 TextureBrowser_updateTitle();
902 void TextureBrowser_ShowTagSearchResult( TextureBrowser& textureBrowser, const char* directory ){
903 g_TextureBrowser_currentDirectory = directory;
904 TextureBrowser_heightChanged( textureBrowser );
906 std::size_t shaders_count;
907 GlobalShaderSystem().foreachShaderName(makeCallback( TextureCategoryLoadShader( directory, shaders_count ) ) );
908 globalOutputStream() << "Showing " << Unsigned( shaders_count ) << " shaders.\n";
910 if ( g_pGameDescription->mGameType != "doom3" ) {
911 // load remaining texture files
912 StringOutputStream dirstring( 64 );
913 dirstring << "textures/" << directory;
916 LoadTexturesByTypeVisitor visitor( dirstring.c_str() );
917 Radiant_getImageModules().foreachModule( visitor );
921 // we'll display the newly loaded textures + all the ones already in use
922 TextureBrowser_SetHideUnused( textureBrowser, false );
926 bool TextureBrowser_hideUnused();
928 void TextureBrowser_hideUnusedExport( const Callback<void(bool)> & importer ){
929 importer( TextureBrowser_hideUnused() );
932 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_hideUnusedExport> TextureBrowserHideUnusedExport;
934 void TextureBrowser_showShadersExport( const Callback<void(bool)> & importer ){
935 importer( GlobalTextureBrowser().m_showShaders );
938 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_showShadersExport> TextureBrowserShowShadersExport;
940 void TextureBrowser_showTexturesExport( const Callback<void(bool)> & importer ){
941 importer( GlobalTextureBrowser().m_showTextures );
944 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_showTexturesExport> TextureBrowserShowTexturesExport;
946 void TextureBrowser_showShaderlistOnly( const Callback<void(bool)> & importer ){
947 importer( g_TextureBrowser_shaderlistOnly );
950 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_showShaderlistOnly> TextureBrowserShowShaderlistOnlyExport;
952 void TextureBrowser_fixedSize( const Callback<void(bool)> & importer ){
953 importer( g_TextureBrowser_fixedSize );
956 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_fixedSize> TextureBrowser_FixedSizeExport;
958 void TextureBrowser_filterMissing( const Callback<void(bool)> & importer ){
959 importer( g_TextureBrowser_filterMissing );
962 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_filterMissing> TextureBrowser_filterMissingExport;
964 void TextureBrowser_filterFallback( const Callback<void(bool)> & importer ){
965 importer( g_TextureBrowser_filterFallback );
968 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_filterFallback> TextureBrowser_filterFallbackExport;
970 void TextureBrowser_enableAlpha( const Callback<void(bool)> & importer ){
971 importer( g_TextureBrowser_enableAlpha );
974 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_enableAlpha> TextureBrowser_enableAlphaExport;
976 void TextureBrowser_SetHideUnused( TextureBrowser& textureBrowser, bool hideUnused ){
977 textureBrowser.m_hideUnused = hideUnused;
979 textureBrowser.m_hideunused_item.update();
981 TextureBrowser_heightChanged( textureBrowser );
982 textureBrowser.m_originInvalid = true;
985 void TextureBrowser_ShowStartupShaders( TextureBrowser& textureBrowser ){
986 if ( textureBrowser.m_startupShaders == STARTUPSHADERS_COMMON ) {
987 TextureBrowser_ShowDirectory( textureBrowser, TextureBrowser_getComonShadersDir() );
992 //++timo NOTE: this is a mix of Shader module stuff and texture explorer
993 // it might need to be split in parts or moved out .. dunno
994 // scroll origin so the specified texture is completely on screen
995 // if current texture is not displayed, nothing is changed
996 void TextureBrowser_Focus( TextureBrowser& textureBrowser, const char* name ){
997 TextureLayout layout;
998 // scroll origin so the texture is completely on screen
999 Texture_StartPos( layout );
1001 for ( QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement() )
1003 IShader* shader = QERApp_ActiveShaders_IteratorCurrent();
1005 if ( !Texture_IsShown( shader, textureBrowser.m_showShaders, textureBrowser.m_showTextures, textureBrowser.m_hideUnused, textureBrowser.m_hideNonShadersInCommon ) ) {
1010 Texture_NextPos( textureBrowser, layout, shader->getTexture(), &x, &y );
1011 qtexture_t* q = shader->getTexture();
1016 // we have found when texdef->name and the shader name match
1017 // NOTE: as everywhere else for our comparisons, we are not case sensitive
1018 if ( shader_equal( name, shader->getName() ) ) {
1019 //int textureHeight = (int)( q->height * ( (float)textureBrowser.m_textureScale / 100 ) ) + 2 * TextureBrowser_fontHeight( textureBrowser );
1020 int textureWidth, textureHeight;
1021 textureBrowser.getTextureWH( q, textureWidth, textureHeight );
1022 textureHeight += 2 * TextureBrowser_fontHeight( textureBrowser );
1025 int originy = TextureBrowser_getOriginY( textureBrowser );
1026 if ( y > originy ) {
1030 if ( y - textureHeight < originy - textureBrowser.height ) {
1031 originy = ( y - textureHeight ) + textureBrowser.height;
1034 TextureBrowser_setOriginY( textureBrowser, originy );
1040 IShader* Texture_At( TextureBrowser& textureBrowser, int mx, int my ){
1041 my += TextureBrowser_getOriginY( textureBrowser ) - textureBrowser.height;
1043 TextureLayout layout;
1044 Texture_StartPos( layout );
1045 for ( QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement() )
1047 IShader* shader = QERApp_ActiveShaders_IteratorCurrent();
1049 if ( !Texture_IsShown( shader, textureBrowser.m_showShaders, textureBrowser.m_showTextures, textureBrowser.m_hideUnused, textureBrowser.m_hideNonShadersInCommon ) ) {
1054 Texture_NextPos( textureBrowser, layout, shader->getTexture(), &x, &y );
1055 qtexture_t *q = shader->getTexture();
1060 int nWidth, nHeight;
1061 textureBrowser.getTextureWH( q, nWidth, nHeight );
1062 if ( mx > x && mx - x < nWidth
1063 && my < y && y - my < nHeight + TextureBrowser_fontHeight( textureBrowser ) ) {
1078 void SelectTexture( TextureBrowser& textureBrowser, int mx, int my, bool bShift ){
1079 IShader* shader = Texture_At( textureBrowser, mx, my );
1080 if ( shader != 0 ) {
1082 if ( shader->IsDefault() ) {
1083 globalOutputStream() << "ERROR: " << shader->getName() << " is not a shader, it's a texture.\n";
1086 ViewShader( shader->getShaderFileName(), shader->getName() );
1091 TextureBrowser_SetSelectedShader( textureBrowser, shader->getName() );
1092 TextureBrowser_textureSelected( shader->getName() );
1094 if ( !FindTextureDialog_isOpen() && !textureBrowser.m_rmbSelected ) {
1095 UndoableCommand undo( "textureNameSetSelected" );
1096 Select_SetShader( shader->getName() );
1103 ============================================================================
1107 ============================================================================
1110 void TextureBrowser_trackingDelta( int x, int y, unsigned int state, void* data ){
1111 TextureBrowser& textureBrowser = *reinterpret_cast<TextureBrowser*>( data );
1115 if ( state & GDK_SHIFT_MASK ) {
1119 int originy = TextureBrowser_getOriginY( textureBrowser );
1120 originy += y * scale;
1121 TextureBrowser_setOriginY( textureBrowser, originy );
1125 void TextureBrowser_Tracking_MouseUp( TextureBrowser& textureBrowser ){
1126 textureBrowser.m_move_started = false;
1127 textureBrowser.m_freezePointer.unfreeze_pointer( textureBrowser.m_parent, false );
1130 void TextureBrowser_Tracking_MouseDown( TextureBrowser& textureBrowser ){
1131 if( textureBrowser.m_move_started ){
1132 TextureBrowser_Tracking_MouseUp( textureBrowser );
1134 textureBrowser.m_move_started = true;
1135 textureBrowser.m_freezePointer.freeze_pointer( textureBrowser.m_parent, textureBrowser.m_gl_widget, TextureBrowser_trackingDelta, &textureBrowser );
1138 void TextureBrowser_Selection_MouseDown( TextureBrowser& textureBrowser, guint32 flags, int pointx, int pointy ){
1139 SelectTexture( textureBrowser, pointx, textureBrowser.height - 1 - pointy, ( flags & GDK_SHIFT_MASK ) != 0 );
1143 ============================================================================
1147 ============================================================================
1153 TTimo: relying on the shaders list to display the textures
1154 we must query all qtexture_t* to manage and display through the IShaders interface
1155 this allows a plugin to completely override the texture system
1158 void Texture_Draw( TextureBrowser& textureBrowser ){
1159 int originy = TextureBrowser_getOriginY( textureBrowser );
1161 glClearColor( textureBrowser.color_textureback[0],
1162 textureBrowser.color_textureback[1],
1163 textureBrowser.color_textureback[2],
1165 glViewport( 0, 0, textureBrowser.width, textureBrowser.height );
1166 glMatrixMode( GL_PROJECTION );
1169 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
1170 glDisable( GL_DEPTH_TEST );
1172 //glDisable( GL_BLEND );
1173 if ( g_TextureBrowser_enableAlpha ) {
1174 glEnable( GL_BLEND );
1175 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1178 glDisable( GL_BLEND );
1181 glOrtho( 0, textureBrowser.width, originy - textureBrowser.height, originy, -100, 100 );
1182 glEnable( GL_TEXTURE_2D );
1184 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
1186 int last_y = 0, last_height = 0;
1188 TextureLayout layout;
1189 Texture_StartPos( layout );
1190 for ( QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement() )
1192 IShader* shader = QERApp_ActiveShaders_IteratorCurrent();
1194 if ( !Texture_IsShown( shader, textureBrowser.m_showShaders, textureBrowser.m_showTextures, textureBrowser.m_hideUnused, textureBrowser.m_hideNonShadersInCommon ) ) {
1199 Texture_NextPos( textureBrowser, layout, shader->getTexture(), &x, &y );
1200 qtexture_t *q = shader->getTexture();
1205 int nWidth, nHeight;
1206 textureBrowser.getTextureWH( q, nWidth, nHeight );
1208 if ( y != last_y ) {
1212 last_height = std::max( nHeight, last_height );
1214 // Is this texture visible?
1215 if ( ( y - nHeight - TextureBrowser_fontHeight( textureBrowser ) < originy )
1216 && ( y > originy - textureBrowser.height ) ) {
1218 // if it's the current texture, draw a thick red line, else:
1219 // shaders have a white border, simple textures don't
1220 // if !texture_showinuse: (some textures displayed may not be in use)
1221 // draw an additional square around with 0.5 1 0.5 color
1223 const float xf = (float)x;
1224 const float yf = (float)( y - TextureBrowser_fontHeight( textureBrowser ) );
1225 float xfMax = xf + 1.5 + nWidth;
1226 float xfMin = xf - 1.5;
1227 float yfMax = yf + 1.5;
1228 float yfMin = yf - nHeight - 1.5;
1231 if ( shader_equal( TextureBrowser_GetSelectedShader( textureBrowser ), shader->getName() ) ) {
1233 if ( textureBrowser.m_rmbSelected ) {
1243 glDisable( GL_TEXTURE_2D );
1244 glBegin( GL_LINE_LOOP );
1245 glVertex2f( xfMin ,yfMax );
1246 glVertex2f( xfMin ,yfMin );
1247 glVertex2f( xfMax ,yfMin );
1248 glVertex2f( xfMax ,yfMax );
1250 glEnable( GL_TEXTURE_2D );
1252 // highlight in-use textures
1253 else if ( !textureBrowser.m_hideUnused && shader->IsInUse() ) {
1254 glColor3f( 0.5,1,0.5 );
1255 glDisable( GL_TEXTURE_2D );
1256 glBegin( GL_LINE_LOOP );
1257 glVertex2f( xfMin ,yfMax );
1258 glVertex2f( xfMin ,yfMin );
1259 glVertex2f( xfMax ,yfMin );
1260 glVertex2f( xfMax ,yfMax );
1262 glEnable( GL_TEXTURE_2D );
1264 // shader white border:
1265 else if ( !shader->IsDefault() ) {
1266 glColor3f( 1, 1, 1 );
1267 glDisable( GL_TEXTURE_2D );
1268 glBegin( GL_LINE_LOOP );
1269 glVertex2f( xfMin ,yfMax );
1270 glVertex2f( xfMin ,yfMin );
1271 glVertex2f( xfMax ,yfMin );
1272 glVertex2f( xfMax ,yfMax );
1274 glEnable( GL_TEXTURE_2D );
1278 if ( !shader->IsDefault() ) {
1279 glEnable( GL_LINE_STIPPLE );
1280 glLineStipple( 1, 0xF000 );
1281 glDisable( GL_TEXTURE_2D );
1282 glBegin( GL_LINE_LOOP );
1283 glColor3f( 0, 0, 0 );
1284 glVertex2f( xfMin ,yfMax );
1285 glVertex2f( xfMin ,yfMin );
1286 glVertex2f( xfMax ,yfMin );
1287 glVertex2f( xfMax ,yfMax );
1289 glDisable( GL_LINE_STIPPLE );
1290 glEnable( GL_TEXTURE_2D );
1293 // draw checkerboard for transparent textures
1294 if ( g_TextureBrowser_enableAlpha )
1296 glDisable( GL_TEXTURE_2D );
1297 glBegin( GL_QUADS );
1298 int font_height = TextureBrowser_fontHeight( textureBrowser );
1299 for ( int i = 0; i < nHeight; i += 8 )
1300 for ( int j = 0; j < nWidth; j += 8 )
1302 unsigned char color = (i + j) / 8 % 2 ? 0x66 : 0x99;
1303 glColor3ub( color, color, color );
1305 int right = std::min(j+8, nWidth);
1307 int bottom = std::min(i+8, nHeight);
1308 glVertex2i(x + right, y - nHeight - font_height + top);
1309 glVertex2i(x + left, y - nHeight - font_height + top);
1310 glVertex2i(x + left, y - nHeight - font_height + bottom);
1311 glVertex2i(x + right, y - nHeight - font_height + bottom);
1314 glEnable( GL_TEXTURE_2D );
1318 glBindTexture( GL_TEXTURE_2D, q->texture_number );
1319 GlobalOpenGL_debugAssertNoErrors();
1321 glBegin( GL_QUADS );
1322 glTexCoord2i( 0,0 );
1323 glVertex2i( x,y - TextureBrowser_fontHeight( textureBrowser ) );
1324 glTexCoord2i( 1,0 );
1325 glVertex2i( x + nWidth,y - TextureBrowser_fontHeight( textureBrowser ) );
1326 glTexCoord2i( 1,1 );
1327 glVertex2i( x + nWidth,y - TextureBrowser_fontHeight( textureBrowser ) - nHeight );
1328 glTexCoord2i( 0,1 );
1329 glVertex2i( x,y - TextureBrowser_fontHeight( textureBrowser ) - nHeight );
1332 // draw the texture name
1333 glDisable( GL_TEXTURE_2D );
1336 glRasterPos2i( x, y - TextureBrowser_fontHeight( textureBrowser ) + 2 );//+5
1338 // don't draw the directory name
1339 const char* name = shader->getName();
1340 name += strlen( name );
1341 while ( name != shader->getName() && *( name - 1 ) != '/' && *( name - 1 ) != '\\' )
1344 GlobalOpenGL().drawString( name );
1345 glEnable( GL_TEXTURE_2D );
1348 //int totalHeight = abs(y) + last_height + TextureBrowser_fontHeight(textureBrowser) + 4;
1352 // reset the current texture
1353 glBindTexture( GL_TEXTURE_2D, 0 );
1357 void TextureBrowser_queueDraw( TextureBrowser& textureBrowser ){
1358 if ( textureBrowser.m_gl_widget ) {
1359 gtk_widget_queue_draw( textureBrowser.m_gl_widget );
1364 void TextureBrowser_setScale( TextureBrowser& textureBrowser, std::size_t scale ){
1365 textureBrowser.m_textureScale = scale;
1367 textureBrowser.m_heightChanged = true;
1368 textureBrowser.m_originInvalid = true;
1369 g_activeShadersChangedCallbacks();
1371 TextureBrowser_queueDraw( textureBrowser );
1374 void TextureBrowser_setUniformSize( TextureBrowser& textureBrowser, std::size_t scale ){
1375 textureBrowser.m_uniformTextureSize = scale;
1377 textureBrowser.m_heightChanged = true;
1378 textureBrowser.m_originInvalid = true;
1379 g_activeShadersChangedCallbacks();
1381 TextureBrowser_queueDraw( textureBrowser );
1384 void TextureBrowser_setUniformMinSize( TextureBrowser& textureBrowser, std::size_t scale ){
1385 textureBrowser.m_uniformTextureMinSize = scale;
1387 textureBrowser.m_heightChanged = true;
1388 textureBrowser.m_originInvalid = true;
1389 g_activeShadersChangedCallbacks();
1391 TextureBrowser_queueDraw( textureBrowser );
1394 void TextureBrowser_MouseWheel( TextureBrowser& textureBrowser, bool bUp ){
1395 int originy = TextureBrowser_getOriginY( textureBrowser );
1398 originy += int(textureBrowser.m_mouseWheelScrollIncrement);
1402 originy -= int(textureBrowser.m_mouseWheelScrollIncrement);
1405 TextureBrowser_setOriginY( textureBrowser, originy );
1408 XmlTagBuilder TagBuilder;
1416 void BuildStoreAssignedTags( ui::ListStore store, const char* shader, TextureBrowser* textureBrowser ){
1421 std::vector<CopiedString> assigned_tags;
1422 TagBuilder.GetShaderTags( shader, assigned_tags );
1424 for ( size_t i = 0; i < assigned_tags.size(); i++ )
1426 store.append(TAG_COLUMN, assigned_tags[i].c_str());
1430 void BuildStoreAvailableTags( ui::ListStore storeAvailable,
1431 ui::ListStore storeAssigned,
1432 const std::set<CopiedString>& allTags,
1433 TextureBrowser* textureBrowser ){
1434 GtkTreeIter iterAssigned;
1435 GtkTreeIter iterAvailable;
1436 std::set<CopiedString>::const_iterator iterAll;
1437 gchar* tag_assigned;
1439 storeAvailable.clear();
1441 bool row = gtk_tree_model_get_iter_first(storeAssigned, &iterAssigned ) != 0;
1443 if ( !row ) { // does the shader have tags assigned?
1444 for ( iterAll = allTags.begin(); iterAll != allTags.end(); ++iterAll )
1446 storeAvailable.append(TAG_COLUMN, (*iterAll).c_str());
1451 while ( row ) // available tags = all tags - assigned tags
1453 gtk_tree_model_get(storeAssigned, &iterAssigned, TAG_COLUMN, &tag_assigned, -1 );
1455 for ( iterAll = allTags.begin(); iterAll != allTags.end(); ++iterAll )
1457 if ( strcmp( (char*)tag_assigned, ( *iterAll ).c_str() ) != 0 ) {
1458 storeAvailable.append(TAG_COLUMN, (*iterAll).c_str());
1462 row = gtk_tree_model_iter_next(storeAssigned, &iterAssigned ) != 0;
1465 gtk_tree_model_get(storeAssigned, &iterAssigned, TAG_COLUMN, &tag_assigned, -1 );
1473 gboolean TextureBrowser_button_press( ui::Widget widget, GdkEventButton* event, TextureBrowser* textureBrowser ){
1474 if ( event->type == GDK_BUTTON_PRESS ) {
1475 if ( event->button == 3 ) {
1476 if ( GlobalTextureBrowser().m_tags ) {
1477 textureBrowser->m_rmbSelected = true;
1478 TextureBrowser_Selection_MouseDown( *textureBrowser, event->state, static_cast<int>( event->x ), static_cast<int>( event->y ) );
1480 BuildStoreAssignedTags( textureBrowser->m_assigned_store, textureBrowser->shader.c_str(), textureBrowser );
1481 BuildStoreAvailableTags( textureBrowser->m_available_store, textureBrowser->m_assigned_store, textureBrowser->m_all_tags, textureBrowser );
1482 textureBrowser->m_heightChanged = true;
1483 textureBrowser->m_tag_frame.show();
1487 TextureBrowser_Focus( *textureBrowser, textureBrowser->shader.c_str() );
1491 TextureBrowser_Tracking_MouseDown( *textureBrowser );
1494 else if ( event->button == 1 ) {
1495 TextureBrowser_Selection_MouseDown( *textureBrowser, event->state, static_cast<int>( event->x ), static_cast<int>( event->y ) );
1497 if ( GlobalTextureBrowser().m_tags ) {
1498 textureBrowser->m_rmbSelected = false;
1499 textureBrowser->m_tag_frame.hide();
1503 else if ( event->type == GDK_2BUTTON_PRESS && event->button == 1 ) {
1504 #define GARUX_DISABLE_2BUTTON
1505 #ifndef GARUX_DISABLE_2BUTTON
1506 CopiedString texName = textureBrowser->shader;
1507 //const char* sh = texName.c_str();
1508 char* sh = const_cast<char*>( texName.c_str() );
1509 char* dir = strrchr( sh, '/' );
1512 dir = strchr( sh, '/' );
1516 ScopeDisableScreenUpdates disableScreenUpdates( dir, "Loading Textures" );
1517 TextureBrowser_ShowDirectory( *textureBrowser, dir );
1518 TextureBrowser_Focus( *textureBrowser, textureBrowser->shader.c_str() );
1519 TextureBrowser_queueDraw( *textureBrowser );
1525 else if ( event->type == GDK_2BUTTON_PRESS && event->button == 3 ) {
1526 ScopeDisableScreenUpdates disableScreenUpdates( TextureBrowser_getComonShadersDir(), "Loading Textures" );
1527 TextureBrowser_ShowDirectory( *textureBrowser, TextureBrowser_getComonShadersDir() );
1528 TextureBrowser_queueDraw( *textureBrowser );
1533 gboolean TextureBrowser_button_release( ui::Widget widget, GdkEventButton* event, TextureBrowser* textureBrowser ){
1534 if ( event->type == GDK_BUTTON_RELEASE ) {
1535 if ( event->button == 3 ) {
1536 if ( !GlobalTextureBrowser().m_tags ) {
1537 TextureBrowser_Tracking_MouseUp( *textureBrowser );
1544 gboolean TextureBrowser_motion( ui::Widget widget, GdkEventMotion *event, TextureBrowser* textureBrowser ){
1548 gboolean TextureBrowser_scroll( ui::Widget widget, GdkEventScroll* event, TextureBrowser* textureBrowser ){
1549 if ( event->direction == GDK_SCROLL_UP ) {
1550 TextureBrowser_MouseWheel( *textureBrowser, true );
1552 else if ( event->direction == GDK_SCROLL_DOWN ) {
1553 TextureBrowser_MouseWheel( *textureBrowser, false );
1558 void TextureBrowser_scrollChanged( void* data, gdouble value ){
1559 //globalOutputStream() << "vertical scroll\n";
1560 TextureBrowser_setOriginY( *reinterpret_cast<TextureBrowser*>( data ), -(int)value );
1563 static void TextureBrowser_verticalScroll(ui::Adjustment adjustment, TextureBrowser* textureBrowser ){
1564 textureBrowser->m_scrollAdjustment.value_changed( gtk_adjustment_get_value(adjustment) );
1567 void TextureBrowser_updateScroll( TextureBrowser& textureBrowser ){
1568 if ( textureBrowser.m_showTextureScrollbar ) {
1569 int totalHeight = TextureBrowser_TotalHeight( textureBrowser );
1571 totalHeight = std::max( totalHeight, textureBrowser.height );
1573 auto vadjustment = gtk_range_get_adjustment( GTK_RANGE( textureBrowser.m_texture_scroll ) );
1575 gtk_adjustment_set_value(vadjustment, -TextureBrowser_getOriginY( textureBrowser ));
1576 gtk_adjustment_set_page_size(vadjustment, textureBrowser.height);
1577 gtk_adjustment_set_page_increment(vadjustment, textureBrowser.height / 2);
1578 gtk_adjustment_set_step_increment(vadjustment, 20);
1579 gtk_adjustment_set_lower(vadjustment, 0);
1580 gtk_adjustment_set_upper(vadjustment, totalHeight);
1582 g_signal_emit_by_name( G_OBJECT( vadjustment ), "changed" );
1586 gboolean TextureBrowser_size_allocate( ui::Widget widget, GtkAllocation* allocation, TextureBrowser* textureBrowser ){
1587 textureBrowser->width = allocation->width;
1588 textureBrowser->height = allocation->height;
1589 TextureBrowser_heightChanged( *textureBrowser );
1590 textureBrowser->m_originInvalid = true;
1591 TextureBrowser_queueDraw( *textureBrowser );
1595 gboolean TextureBrowser_expose( ui::Widget widget, GdkEventExpose* event, TextureBrowser* textureBrowser ){
1596 if ( glwidget_make_current( textureBrowser->m_gl_widget ) != FALSE ) {
1597 GlobalOpenGL_debugAssertNoErrors();
1598 TextureBrowser_evaluateHeight( *textureBrowser );
1599 Texture_Draw( *textureBrowser );
1600 GlobalOpenGL_debugAssertNoErrors();
1601 glwidget_swap_buffers( textureBrowser->m_gl_widget );
1607 TextureBrowser g_TextureBrowser;
1609 TextureBrowser& GlobalTextureBrowser(){
1610 return g_TextureBrowser;
1613 bool TextureBrowser_hideUnused(){
1614 return g_TextureBrowser.m_hideUnused;
1617 void TextureBrowser_ToggleHideUnused(){
1618 if ( g_TextureBrowser.m_hideUnused ) {
1619 TextureBrowser_SetHideUnused( g_TextureBrowser, false );
1623 TextureBrowser_SetHideUnused( g_TextureBrowser, true );
1627 void TextureGroups_constructTreeModel( TextureGroups groups, ui::TreeStore store ){
1628 // put the information from the old textures menu into a treeview
1629 GtkTreeIter iter, child;
1631 TextureGroups::const_iterator i = groups.begin();
1632 while ( i != groups.end() )
1634 const char* dirName = ( *i ).c_str();
1635 const char* firstUnderscore = strchr( dirName, '_' );
1636 StringRange dirRoot( dirName, ( firstUnderscore == 0 ) ? dirName : firstUnderscore + 1 );
1638 TextureGroups::const_iterator next = i;
1640 if ( firstUnderscore != 0
1641 && next != groups.end()
1642 && string_equal_start( ( *next ).c_str(), dirRoot ) ) {
1643 gtk_tree_store_append( store, &iter, NULL );
1644 gtk_tree_store_set( store, &iter, 0, CopiedString( StringRange( dirName, firstUnderscore ) ).c_str(), -1 );
1647 while ( i != groups.end() && string_equal_start( ( *i ).c_str(), dirRoot ) )
1649 gtk_tree_store_append( store, &child, &iter );
1650 gtk_tree_store_set( store, &child, 0, ( *i ).c_str(), -1 );
1656 gtk_tree_store_append( store, &iter, NULL );
1657 gtk_tree_store_set( store, &iter, 0, dirName, -1 );
1663 TextureGroups TextureGroups_constructTreeView(){
1664 TextureGroups groups;
1666 if ( TextureBrowser_showWads() ) {
1667 GlobalFileSystem().forEachArchive( TextureGroupsAddWadCaller( groups ) );
1671 // scan texture dirs and pak files only if not restricting to shaderlist
1672 if ( g_pGameDescription->mGameType != "doom3" && !g_TextureBrowser_shaderlistOnly ) {
1673 GlobalFileSystem().forEachDirectory( "textures/", TextureGroupsAddDirectoryCaller( groups ) );
1676 GlobalShaderSystem().foreachShaderName( TextureGroupsAddShaderCaller( groups ) );
1682 void TextureBrowser_constructTreeStore(){
1683 TextureGroups groups = TextureGroups_constructTreeView();
1684 auto store = ui::TreeStore::from(gtk_tree_store_new( 1, G_TYPE_STRING ));
1685 TextureGroups_constructTreeModel( groups, store );
1686 std::set<CopiedString>::iterator iter;
1688 gtk_tree_view_set_model(g_TextureBrowser.m_treeViewTree, store);
1690 g_object_unref( G_OBJECT( store ) );
1693 void TextureBrowser_constructTreeStoreTags(){
1694 //TextureGroups groups;
1695 auto store = ui::TreeStore::from(gtk_tree_store_new( 1, G_TYPE_STRING ));
1696 auto model = g_TextureBrowser.m_all_tags_list;
1698 gtk_tree_view_set_model(g_TextureBrowser.m_treeViewTags, model );
1700 g_object_unref( G_OBJECT( store ) );
1703 void TreeView_onRowActivated( ui::TreeView treeview, ui::TreePath path, ui::TreeViewColumn col, gpointer userdata ){
1706 auto model = gtk_tree_view_get_model(treeview );
1708 if ( gtk_tree_model_get_iter( model, &iter, path ) ) {
1709 gchar dirName[1024];
1712 gtk_tree_model_get( model, &iter, 0, &buffer, -1 );
1713 strcpy( dirName, buffer );
1716 g_TextureBrowser.m_searchedTags = false;
1718 if ( !TextureBrowser_showWads() ) {
1719 strcat( dirName, "/" );
1722 ScopeDisableScreenUpdates disableScreenUpdates( dirName, "Loading Textures" );
1723 TextureBrowser_ShowDirectory( GlobalTextureBrowser(), dirName );
1724 TextureBrowser_queueDraw( GlobalTextureBrowser() );
1725 //deactivate, so SPACE and RETURN wont be broken for 2d
1726 gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( treeview ) ) ), NULL );
1730 void TextureBrowser_createTreeViewTree(){
1731 gtk_tree_view_set_enable_search(g_TextureBrowser.m_treeViewTree, FALSE );
1733 gtk_tree_view_set_headers_visible(g_TextureBrowser.m_treeViewTree, FALSE );
1734 g_TextureBrowser.m_treeViewTree.connect( "row-activated", (GCallback) TreeView_onRowActivated, NULL );
1736 auto renderer = ui::CellRendererText(ui::New);
1737 gtk_tree_view_insert_column_with_attributes(g_TextureBrowser.m_treeViewTree, -1, "", renderer, "text", 0, NULL );
1739 TextureBrowser_constructTreeStore();
1742 void TextureBrowser_addTag();
1744 void TextureBrowser_renameTag();
1746 void TextureBrowser_deleteTag();
1748 void TextureBrowser_createContextMenu( ui::Widget treeview, GdkEventButton *event ){
1749 ui::Widget menu = ui::Menu(ui::New);
1751 ui::Widget menuitem = ui::MenuItem( "Add tag" );
1752 menuitem.connect( "activate", (GCallback)TextureBrowser_addTag, treeview );
1753 gtk_menu_shell_append( GTK_MENU_SHELL( menu ), menuitem );
1755 menuitem = ui::MenuItem( "Rename tag" );
1756 menuitem.connect( "activate", (GCallback)TextureBrowser_renameTag, treeview );
1757 gtk_menu_shell_append( GTK_MENU_SHELL( menu ), menuitem );
1759 menuitem = ui::MenuItem( "Delete tag" );
1760 menuitem.connect( "activate", (GCallback)TextureBrowser_deleteTag, treeview );
1761 gtk_menu_shell_append( GTK_MENU_SHELL( menu ), menuitem );
1763 gtk_widget_show_all( menu );
1765 gtk_menu_popup( GTK_MENU( menu ), NULL, NULL, NULL, NULL,
1766 ( event != NULL ) ? event->button : 0,
1767 gdk_event_get_time( (GdkEvent*)event ) );
1770 void TextureBrowser_searchTags();
1772 gboolean TreeViewTags_onButtonPressed( ui::TreeView treeview, GdkEventButton *event ){
1773 if ( event->type == GDK_BUTTON_PRESS && event->button == 3 ) {
1775 auto selection = gtk_tree_view_get_selection(treeview );
1777 if ( gtk_tree_view_get_path_at_pos(treeview, event->x, event->y, &path, NULL, NULL, NULL ) ) {
1778 gtk_tree_selection_unselect_all( selection );
1779 gtk_tree_selection_select_path( selection, path );
1780 gtk_tree_path_free( path );
1783 TextureBrowser_createContextMenu( treeview, event );
1786 if( event->type == GDK_2BUTTON_PRESS && event->button == 1 ){
1787 TextureBrowser_searchTags();
1793 void TextureBrowser_createTreeViewTags(){
1794 g_TextureBrowser.m_treeViewTags = ui::TreeView(ui::New);
1795 gtk_tree_view_set_enable_search(g_TextureBrowser.m_treeViewTags, FALSE );
1797 g_TextureBrowser.m_treeViewTags.connect( "button-press-event", (GCallback)TreeViewTags_onButtonPressed, NULL );
1799 gtk_tree_view_set_headers_visible(g_TextureBrowser.m_treeViewTags, FALSE );
1801 auto renderer = ui::CellRendererText(ui::New);
1802 gtk_tree_view_insert_column_with_attributes(g_TextureBrowser.m_treeViewTags, -1, "", renderer, "text", 0, NULL );
1804 TextureBrowser_constructTreeStoreTags();
1807 ui::MenuItem TextureBrowser_constructViewMenu( ui::Menu menu ){
1808 ui::MenuItem textures_menu_item = ui::MenuItem(new_sub_menu_item_with_mnemonic( "_View" ));
1810 if ( g_Layout_enableDetachableMenus.m_value ) {
1811 menu_tearoff( menu );
1814 create_check_menu_item_with_mnemonic( menu, "Hide _Unused", "ShowInUse" );
1815 if ( string_empty( g_pGameDescription->getKeyValue( "show_wads" ) ) ) {
1816 create_check_menu_item_with_mnemonic( menu, "Hide Image Missing", "FilterMissing" );
1819 // hide notex and shadernotex on texture browser: no one wants to apply them
1820 create_check_menu_item_with_mnemonic( menu, "Hide Fallback", "FilterFallback" );
1822 menu_separator( menu );
1825 // we always want to show shaders but don't want a "Show Shaders" menu for doom3 and .wad file games
1826 if ( g_pGameDescription->mGameType == "doom3" || !string_empty( g_pGameDescription->getKeyValue( "show_wads" ) ) ) {
1827 g_TextureBrowser.m_showShaders = true;
1831 create_check_menu_item_with_mnemonic( menu, "Show shaders", "ToggleShowShaders" );
1832 create_check_menu_item_with_mnemonic( menu, "Show textures", "ToggleShowTextures" );
1833 menu_separator( menu );
1836 if ( g_TextureBrowser.m_tags ) {
1837 create_menu_item_with_mnemonic( menu, "Show Untagged", "ShowUntagged" );
1839 if ( g_pGameDescription->mGameType != "doom3" && string_empty( g_pGameDescription->getKeyValue( "show_wads" ) ) ) {
1840 create_check_menu_item_with_mnemonic( menu, "ShaderList Only", "ToggleShowShaderlistOnly" );
1843 menu_separator( menu );
1844 create_check_menu_item_with_mnemonic( menu, "Fixed Size", "FixedSize" );
1845 create_check_menu_item_with_mnemonic( menu, "Transparency", "EnableAlpha" );
1847 if ( string_empty( g_pGameDescription->getKeyValue( "show_wads" ) ) ) {
1848 menu_separator( menu );
1849 g_TextureBrowser.m_shader_info_item = ui::Widget(create_menu_item_with_mnemonic( menu, "Shader Info", "ShaderInfo" ));
1850 gtk_widget_set_sensitive( g_TextureBrowser.m_shader_info_item, FALSE );
1854 return textures_menu_item;
1857 void Popup_View_Menu( GtkWidget *widget, GtkMenu *menu ){
1858 gtk_menu_popup( menu, NULL, NULL, NULL, NULL, 1, gtk_get_current_event_time() );
1861 ui::MenuItem TextureBrowser_constructToolsMenu( ui::Menu menu ){
1862 ui::MenuItem textures_menu_item = ui::MenuItem(new_sub_menu_item_with_mnemonic( "_Tools" ));
1864 if ( g_Layout_enableDetachableMenus.m_value ) {
1865 menu_tearoff( menu );
1868 create_menu_item_with_mnemonic( menu, "Flush & Reload Shaders", "RefreshShaders" );
1869 create_menu_item_with_mnemonic( menu, "Find / Replace...", "FindReplaceTextures" );
1871 return textures_menu_item;
1874 ui::MenuItem TextureBrowser_constructTagsMenu( ui::Menu menu ){
1875 ui::MenuItem textures_menu_item = ui::MenuItem(new_sub_menu_item_with_mnemonic( "T_ags" ));
1877 if ( g_Layout_enableDetachableMenus.m_value ) {
1878 menu_tearoff( menu );
1881 create_menu_item_with_mnemonic( menu, "Add tag", "AddTag" );
1882 create_menu_item_with_mnemonic( menu, "Rename tag", "RenameTag" );
1883 create_menu_item_with_mnemonic( menu, "Delete tag", "DeleteTag" );
1884 menu_separator( menu );
1885 create_menu_item_with_mnemonic( menu, "Copy tags from selected", "CopyTag" );
1886 create_menu_item_with_mnemonic( menu, "Paste tags to selected", "PasteTag" );
1888 return textures_menu_item;
1891 gboolean TextureBrowser_tagMoveHelper( ui::TreeModel model, ui::TreePath path, GtkTreeIter iter, GSList** selected ){
1892 g_assert( selected != NULL );
1894 auto rowref = gtk_tree_row_reference_new( model, path );
1895 *selected = g_slist_append( *selected, rowref );
1900 void TextureBrowser_assignTags(){
1901 GSList* selected = NULL;
1903 gchar* tag_assigned;
1905 auto selection = gtk_tree_view_get_selection(g_TextureBrowser.m_available_tree );
1907 gtk_tree_selection_selected_foreach( selection, (GtkTreeSelectionForeachFunc)TextureBrowser_tagMoveHelper, &selected );
1909 if ( selected != NULL ) {
1910 for ( node = selected; node != NULL; node = node->next )
1912 auto path = gtk_tree_row_reference_get_path( (GtkTreeRowReference*)node->data );
1917 if ( gtk_tree_model_get_iter(g_TextureBrowser.m_available_store, &iter, path ) ) {
1918 gtk_tree_model_get(g_TextureBrowser.m_available_store, &iter, TAG_COLUMN, &tag_assigned, -1 );
1919 if ( !TagBuilder.CheckShaderTag( g_TextureBrowser.shader.c_str() ) ) {
1920 // create a custom shader/texture entry
1921 IShader* ishader = QERApp_Shader_ForName( g_TextureBrowser.shader.c_str() );
1922 CopiedString filename = ishader->getShaderFileName();
1924 if ( filename.empty() ) {
1926 TagBuilder.AddShaderNode( g_TextureBrowser.shader.c_str(), CUSTOM, TEXTURE );
1930 TagBuilder.AddShaderNode( g_TextureBrowser.shader.c_str(), CUSTOM, SHADER );
1934 TagBuilder.AddShaderTag( g_TextureBrowser.shader.c_str(), (char*)tag_assigned, TAG );
1936 gtk_list_store_remove( g_TextureBrowser.m_available_store, &iter );
1937 g_TextureBrowser.m_assigned_store.append(TAG_COLUMN, tag_assigned);
1942 g_slist_foreach( selected, (GFunc)gtk_tree_row_reference_free, NULL );
1945 TagBuilder.SaveXmlDoc();
1947 g_slist_free( selected );
1950 void TextureBrowser_removeTags(){
1951 GSList* selected = NULL;
1955 auto selection = gtk_tree_view_get_selection(g_TextureBrowser.m_assigned_tree );
1957 gtk_tree_selection_selected_foreach( selection, (GtkTreeSelectionForeachFunc)TextureBrowser_tagMoveHelper, &selected );
1959 if ( selected != NULL ) {
1960 for ( node = selected; node != NULL; node = node->next )
1962 auto path = gtk_tree_row_reference_get_path( (GtkTreeRowReference*)node->data );
1967 if ( gtk_tree_model_get_iter(g_TextureBrowser.m_assigned_store, &iter, path ) ) {
1968 gtk_tree_model_get(g_TextureBrowser.m_assigned_store, &iter, TAG_COLUMN, &tag, -1 );
1969 TagBuilder.DeleteShaderTag( g_TextureBrowser.shader.c_str(), tag );
1970 gtk_list_store_remove( g_TextureBrowser.m_assigned_store, &iter );
1975 g_slist_foreach( selected, (GFunc)gtk_tree_row_reference_free, NULL );
1977 // Update the "available tags list"
1978 BuildStoreAvailableTags( g_TextureBrowser.m_available_store, g_TextureBrowser.m_assigned_store, g_TextureBrowser.m_all_tags, &g_TextureBrowser );
1981 TagBuilder.SaveXmlDoc();
1983 g_slist_free( selected );
1986 void TextureBrowser_buildTagList(){
1987 g_TextureBrowser.m_all_tags_list.clear();
1989 std::set<CopiedString>::iterator iter;
1991 for ( iter = g_TextureBrowser.m_all_tags.begin(); iter != g_TextureBrowser.m_all_tags.end(); ++iter )
1993 g_TextureBrowser.m_all_tags_list.append(TAG_COLUMN, (*iter).c_str());
1997 void TextureBrowser_searchTags(){
1998 GSList* selected = NULL;
2002 char tags_searched[256];
2004 auto selection = gtk_tree_view_get_selection(g_TextureBrowser.m_treeViewTags );
2006 gtk_tree_selection_selected_foreach( selection, (GtkTreeSelectionForeachFunc)TextureBrowser_tagMoveHelper, &selected );
2008 if ( selected != NULL ) {
2009 strcpy( buffer, "/root/*/*[tag='" );
2010 strcpy( tags_searched, "[TAGS] " );
2012 for ( node = selected; node != NULL; node = node->next )
2014 auto path = gtk_tree_row_reference_get_path( (GtkTreeRowReference*)node->data );
2019 if ( gtk_tree_model_get_iter(g_TextureBrowser.m_all_tags_list, &iter, path ) ) {
2020 gtk_tree_model_get(g_TextureBrowser.m_all_tags_list, &iter, TAG_COLUMN, &tag, -1 );
2022 strcat( buffer, tag );
2023 strcat( tags_searched, tag );
2024 if ( node != g_slist_last( node ) ) {
2025 strcat( buffer, "' and tag='" );
2026 strcat( tags_searched, ", " );
2032 strcat( buffer, "']" );
2034 g_slist_foreach( selected, (GFunc)gtk_tree_row_reference_free, NULL );
2036 g_TextureBrowser.m_found_shaders.clear(); // delete old list
2037 TagBuilder.TagSearch( buffer, g_TextureBrowser.m_found_shaders );
2039 if ( !g_TextureBrowser.m_found_shaders.empty() ) { // found something
2040 size_t shaders_found = g_TextureBrowser.m_found_shaders.size();
2042 globalOutputStream() << "Found " << (unsigned int)shaders_found << " textures and shaders with " << tags_searched << "\n";
2043 ScopeDisableScreenUpdates disableScreenUpdates( "Searching...", "Loading Textures" );
2045 std::set<CopiedString>::iterator iter;
2047 for ( iter = g_TextureBrowser.m_found_shaders.begin(); iter != g_TextureBrowser.m_found_shaders.end(); iter++ )
2049 std::string path = ( *iter ).c_str();
2050 size_t pos = path.find_last_of( "/", path.size() );
2051 std::string name = path.substr( pos + 1, path.size() );
2052 path = path.substr( 0, pos + 1 );
2053 TextureDirectory_loadTexture( path.c_str(), name.c_str() );
2056 g_TextureBrowser.m_searchedTags = true;
2057 g_TextureBrowser_currentDirectory = tags_searched;
2059 g_TextureBrowser.m_nTotalHeight = 0;
2060 TextureBrowser_setOriginY( g_TextureBrowser, 0 );
2061 TextureBrowser_heightChanged( g_TextureBrowser );
2062 TextureBrowser_updateTitle();
2064 g_slist_free( selected );
2067 void TextureBrowser_toggleSearchButton(){
2068 gint page = gtk_notebook_get_current_page( GTK_NOTEBOOK( g_TextureBrowser.m_tag_notebook ) );
2070 if ( page == 0 ) { // tag page
2071 gtk_widget_show_all( g_TextureBrowser.m_search_button );
2074 g_TextureBrowser.m_search_button.hide();
2078 void TextureBrowser_constructTagNotebook(){
2079 g_TextureBrowser.m_tag_notebook = ui::Widget::from(gtk_notebook_new());
2080 ui::Widget labelTags = ui::Label( "Tags" );
2081 ui::Widget labelTextures = ui::Label( "Textures" );
2083 gtk_notebook_append_page( GTK_NOTEBOOK( g_TextureBrowser.m_tag_notebook ), g_TextureBrowser.m_scr_win_tree, labelTextures );
2084 gtk_notebook_append_page( GTK_NOTEBOOK( g_TextureBrowser.m_tag_notebook ), g_TextureBrowser.m_scr_win_tags, labelTags );
2086 g_TextureBrowser.m_tag_notebook.connect( "switch-page", G_CALLBACK( TextureBrowser_toggleSearchButton ), NULL );
2088 gtk_widget_show_all( g_TextureBrowser.m_tag_notebook );
2091 void TextureBrowser_constructSearchButton(){
2092 auto image = ui::Widget::from(gtk_image_new_from_stock( GTK_STOCK_FIND, GTK_ICON_SIZE_SMALL_TOOLBAR ));
2093 g_TextureBrowser.m_search_button = ui::Button(ui::New);
2094 g_TextureBrowser.m_search_button.connect( "clicked", G_CALLBACK( TextureBrowser_searchTags ), NULL );
2095 gtk_widget_set_tooltip_text(g_TextureBrowser.m_search_button, "Search with selected tags");
2096 g_TextureBrowser.m_search_button.add(image);
2099 void TextureBrowser_checkTagFile(){
2100 const char SHADERTAG_FILE[] = "shadertags.xml";
2101 CopiedString default_filename, rc_filename;
2102 StringOutputStream stream( 256 );
2104 stream << LocalRcPath_get();
2105 stream << SHADERTAG_FILE;
2106 rc_filename = stream.c_str();
2108 if ( file_exists( rc_filename.c_str() ) ) {
2109 g_TextureBrowser.m_tags = TagBuilder.OpenXmlDoc( rc_filename.c_str() );
2111 if ( g_TextureBrowser.m_tags ) {
2112 globalOutputStream() << "Loading tag file " << rc_filename.c_str() << ".\n";
2117 // load default tagfile
2119 stream << g_pGameDescription->mGameToolsPath.c_str();
2120 stream << SHADERTAG_FILE;
2121 default_filename = stream.c_str();
2123 if ( file_exists( default_filename.c_str() ) ) {
2124 g_TextureBrowser.m_tags = TagBuilder.OpenXmlDoc( default_filename.c_str(), rc_filename.c_str() );
2126 if ( g_TextureBrowser.m_tags ) {
2127 globalOutputStream() << "Loading default tag file " << default_filename.c_str() << ".\n";
2132 globalOutputStream() << "Unable to find default tag file " << default_filename.c_str() << ". No tag support. Plugins -> ShaderPlug -> Create tag file: to start using tags\n";
2137 void TextureBrowser_SetNotex(){
2138 IShader* notex = QERApp_Shader_ForName( DEFAULT_NOTEX_NAME );
2139 IShader* shadernotex = QERApp_Shader_ForName( DEFAULT_SHADERNOTEX_NAME );
2141 g_notex = notex->getTexture()->name;
2142 g_shadernotex = shadernotex->getTexture()->name;
2145 shadernotex->DecRef();
2148 ui::Widget TextureBrowser_constructWindow( ui::Window toplevel ){
2149 // The gl_widget and the tag assignment frame should be packed into a GtkVPaned with the slider
2150 // position stored in local.pref. gtk_paned_get_position() and gtk_paned_set_position() don't
2151 // seem to work in gtk 2.4 and the arrow buttons don't handle GTK_FILL, so here's another thing
2152 // for the "once-the-gtk-libs-are-updated-TODO-list" :x
2154 TextureBrowser_checkTagFile();
2155 TextureBrowser_SetNotex();
2157 GlobalShaderSystem().setActiveShadersChangedNotify( ReferenceCaller<TextureBrowser, void(), TextureBrowser_activeShadersChanged>( g_TextureBrowser ) );
2159 g_TextureBrowser.m_parent = toplevel;
2161 auto table = ui::Table(3, 3, FALSE);
2162 auto vbox = ui::VBox(FALSE, 0);
2163 table.attach(vbox, {0, 1, 1, 3}, {GTK_FILL, GTK_FILL});
2166 // ui::Widget menu_bar{ui::null};
2167 auto toolbar = ui::Toolbar::from( gtk_toolbar_new() );
2170 // menu_bar = ui::Widget::from(gtk_menu_bar_new());
2171 auto menu_view = ui::Menu(ui::New);
2172 // auto view_item = TextureBrowser_constructViewMenu( menu_view );
2173 TextureBrowser_constructViewMenu( menu_view );
2174 gtk_menu_set_title( menu_view, "View" );
2175 // gtk_menu_item_set_submenu( GTK_MENU_ITEM( view_item ), menu_view );
2176 // gtk_menu_shell_append( GTK_MENU_SHELL( menu_bar ), view_item );
2178 //gtk_table_attach( GTK_TABLE( table ), GTK_WIDGET( toolbar ), 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0 );
2179 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( toolbar ), FALSE, FALSE, 0 );
2183 auto button = toolbar_append_button( toolbar, "View", "texbro_view.png" );
2184 button.dimensions( 22, 22 );
2185 button.connect( "clicked", G_CALLBACK( Popup_View_Menu ), menu_view );
2187 //to show detached menu over floating tex bro
2188 gtk_menu_attach_to_widget( GTK_MENU( menu_view ), GTK_WIDGET( button ), NULL );
2191 auto button = toolbar_append_button( toolbar, "Find / Replace...", "texbro_gtk-find-and-replace.png", "FindReplaceTextures" );
2192 button.dimensions( 22, 22 );
2195 auto button = toolbar_append_button( toolbar, "Flush & Reload Shaders", "texbro_refresh.png", "RefreshShaders" );
2196 button.dimensions( 22, 22 );
2201 auto menu_tools = ui::Menu(ui::New);
2202 auto tools_item = TextureBrowser_constructToolsMenu( menu_tools );
2203 gtk_menu_item_set_submenu( GTK_MENU_ITEM( tools_item ), menu_tools );
2204 gtk_menu_shell_append( GTK_MENU_SHELL( menu_bar ), tools_item );
2206 // table.attach(menu_bar, {0, 3, 0, 1}, {GTK_FILL, GTK_SHRINK});
2209 { // Texture TreeView
2210 g_TextureBrowser.m_scr_win_tree = ui::ScrolledWindow(ui::New);
2211 gtk_container_set_border_width( GTK_CONTAINER( g_TextureBrowser.m_scr_win_tree ), 0 );
2213 // vertical only scrolling for treeview
2214 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( g_TextureBrowser.m_scr_win_tree ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
2216 g_TextureBrowser.m_scr_win_tree.show();
2218 TextureBrowser_createTreeViewTree();
2220 //gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW( g_TextureBrowser.m_scr_win_tree ), g_TextureBrowser.m_treeViewTree );
2221 gtk_container_add( GTK_CONTAINER( g_TextureBrowser.m_scr_win_tree ), GTK_WIDGET( g_TextureBrowser.m_treeViewTree ) );
2222 g_TextureBrowser.m_treeViewTree.show();
2224 { // gl_widget scrollbar
2225 auto w = ui::Widget::from(gtk_vscrollbar_new( ui::Adjustment( 0,0,0,1,1,0 ) ));
2226 table.attach(w, {2, 3, 1, 2}, {GTK_SHRINK, GTK_FILL});
2228 g_TextureBrowser.m_texture_scroll = w;
2230 auto vadjustment = ui::Adjustment::from(gtk_range_get_adjustment( GTK_RANGE( g_TextureBrowser.m_texture_scroll ) ));
2231 vadjustment.connect( "value_changed", G_CALLBACK( TextureBrowser_verticalScroll ), &g_TextureBrowser );
2233 g_TextureBrowser.m_texture_scroll.visible(g_TextureBrowser.m_showTextureScrollbar);
2236 g_TextureBrowser.m_gl_widget = glwidget_new( FALSE );
2237 g_object_ref( g_TextureBrowser.m_gl_widget._handle );
2239 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 );
2240 gtk_widget_set_can_focus( g_TextureBrowser.m_gl_widget, true );
2242 table.attach(g_TextureBrowser.m_gl_widget, {1, 2, 1, 2});
2243 g_TextureBrowser.m_gl_widget.show();
2245 g_TextureBrowser.m_sizeHandler = g_TextureBrowser.m_gl_widget.connect( "size_allocate", G_CALLBACK( TextureBrowser_size_allocate ), &g_TextureBrowser );
2246 g_TextureBrowser.m_exposeHandler = g_TextureBrowser.m_gl_widget.on_render( G_CALLBACK( TextureBrowser_expose ), &g_TextureBrowser );
2248 g_TextureBrowser.m_gl_widget.connect( "button_press_event", G_CALLBACK( TextureBrowser_button_press ), &g_TextureBrowser );
2249 g_TextureBrowser.m_gl_widget.connect( "button_release_event", G_CALLBACK( TextureBrowser_button_release ), &g_TextureBrowser );
2250 g_TextureBrowser.m_gl_widget.connect( "motion_notify_event", G_CALLBACK( TextureBrowser_motion ), &g_TextureBrowser );
2251 g_TextureBrowser.m_gl_widget.connect( "scroll_event", G_CALLBACK( TextureBrowser_scroll ), &g_TextureBrowser );
2255 if ( g_TextureBrowser.m_tags ) {
2256 { // fill tag GtkListStore
2257 g_TextureBrowser.m_all_tags_list = ui::ListStore::from(gtk_list_store_new( N_COLUMNS, G_TYPE_STRING ));
2258 auto sortable = GTK_TREE_SORTABLE( g_TextureBrowser.m_all_tags_list );
2259 gtk_tree_sortable_set_sort_column_id( sortable, TAG_COLUMN, GTK_SORT_ASCENDING );
2261 TagBuilder.GetAllTags( g_TextureBrowser.m_all_tags );
2262 TextureBrowser_buildTagList();
2265 auto menu_tags = ui::Menu(ui::New);
2266 gtk_menu_set_title( GTK_MENU( menu_tags ), "Tags" );
2267 // auto tags_item = TextureBrowser_constructTagsMenu( menu_tags );
2268 TextureBrowser_constructTagsMenu( menu_tags );
2269 // gtk_menu_item_set_submenu( GTK_MENU_ITEM( tags_item ), menu_tags );
2270 // gtk_menu_shell_append( GTK_MENU_SHELL( menu_bar ), tags_item );
2272 auto button = toolbar_append_button( toolbar, "Tags", "texbro_tags.png" );
2273 button.dimensions( 22, 22 );
2274 button.connect( "clicked", G_CALLBACK( Popup_View_Menu ), menu_tags );
2276 //to show detached menu over floating tex bro and main wnd...
2277 gtk_menu_attach_to_widget( GTK_MENU( menu_tags ), GTK_WIDGET( button ), NULL );
2280 g_TextureBrowser.m_scr_win_tags = ui::ScrolledWindow(ui::New);
2281 gtk_container_set_border_width( GTK_CONTAINER( g_TextureBrowser.m_scr_win_tags ), 0 );
2283 // vertical only scrolling for treeview
2284 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( g_TextureBrowser.m_scr_win_tags ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
2286 TextureBrowser_createTreeViewTags();
2288 auto selection = gtk_tree_view_get_selection(g_TextureBrowser.m_treeViewTags );
2289 gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE );
2291 //gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW( g_TextureBrowser.m_scr_win_tags ), g_TextureBrowser.m_treeViewTags );
2292 gtk_container_add( GTK_CONTAINER( g_TextureBrowser.m_scr_win_tags ), GTK_WIDGET( g_TextureBrowser.m_treeViewTags ) );
2293 g_TextureBrowser.m_treeViewTags.show();
2295 { // Texture/Tag notebook
2296 TextureBrowser_constructTagNotebook();
2297 vbox.pack_start( g_TextureBrowser.m_tag_notebook, TRUE, TRUE, 0 );
2299 { // Tag search button
2300 TextureBrowser_constructSearchButton();
2301 vbox.pack_end(g_TextureBrowser.m_search_button, FALSE, FALSE, 0);
2303 auto frame_table = ui::Table(3, 3, FALSE);
2306 g_TextureBrowser.m_tag_frame = ui::Frame( "Tag assignment" );
2307 gtk_frame_set_label_align( GTK_FRAME( g_TextureBrowser.m_tag_frame ), 0.5, 0.5 );
2308 gtk_frame_set_shadow_type( GTK_FRAME( g_TextureBrowser.m_tag_frame ), GTK_SHADOW_NONE );
2310 table.attach(g_TextureBrowser.m_tag_frame, {1, 3, 2, 3}, {GTK_FILL, GTK_SHRINK});
2314 g_TextureBrowser.m_tag_frame.add(frame_table);
2316 { // assigned tag list
2317 ui::Widget scrolled_win = ui::ScrolledWindow(ui::New);
2318 gtk_container_set_border_width( GTK_CONTAINER( scrolled_win ), 0 );
2319 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scrolled_win ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
2321 g_TextureBrowser.m_assigned_store = ui::ListStore::from(gtk_list_store_new( N_COLUMNS, G_TYPE_STRING ));
2323 auto sortable = GTK_TREE_SORTABLE( g_TextureBrowser.m_assigned_store );
2324 gtk_tree_sortable_set_sort_column_id( sortable, TAG_COLUMN, GTK_SORT_ASCENDING );
2326 auto renderer = ui::CellRendererText(ui::New);
2328 g_TextureBrowser.m_assigned_tree = ui::TreeView(ui::TreeModel::from(g_TextureBrowser.m_assigned_store._handle));
2329 g_TextureBrowser.m_assigned_store.unref();
2330 g_TextureBrowser.m_assigned_tree.connect( "row-activated", (GCallback) TextureBrowser_removeTags, NULL );
2331 gtk_tree_view_set_headers_visible(g_TextureBrowser.m_assigned_tree, FALSE );
2333 auto selection = gtk_tree_view_get_selection(g_TextureBrowser.m_assigned_tree );
2334 gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE );
2336 auto column = ui::TreeViewColumn( "", renderer, {{"text", TAG_COLUMN}} );
2337 gtk_tree_view_append_column(g_TextureBrowser.m_assigned_tree, column );
2338 g_TextureBrowser.m_assigned_tree.show();
2340 scrolled_win.show();
2341 //gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW( scrolled_win ), g_TextureBrowser.m_assigned_tree );
2342 gtk_container_add( GTK_CONTAINER( scrolled_win ), GTK_WIDGET( g_TextureBrowser.m_available_tree ) );
2344 frame_table.attach(scrolled_win, {0, 1, 1, 3}, {GTK_FILL, GTK_FILL});
2346 { // available tag list
2347 ui::Widget scrolled_win = ui::ScrolledWindow(ui::New);
2348 gtk_container_set_border_width( GTK_CONTAINER( scrolled_win ), 0 );
2349 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scrolled_win ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
2351 g_TextureBrowser.m_available_store = ui::ListStore::from(gtk_list_store_new( N_COLUMNS, G_TYPE_STRING ));
2352 auto sortable = GTK_TREE_SORTABLE( g_TextureBrowser.m_available_store );
2353 gtk_tree_sortable_set_sort_column_id( sortable, TAG_COLUMN, GTK_SORT_ASCENDING );
2355 auto renderer = ui::CellRendererText(ui::New);
2357 g_TextureBrowser.m_available_tree = ui::TreeView(ui::TreeModel::from(g_TextureBrowser.m_available_store._handle));
2358 g_TextureBrowser.m_available_store.unref();
2359 g_TextureBrowser.m_available_tree.connect( "row-activated", (GCallback) TextureBrowser_assignTags, NULL );
2360 gtk_tree_view_set_headers_visible(g_TextureBrowser.m_available_tree, FALSE );
2362 auto selection = gtk_tree_view_get_selection(g_TextureBrowser.m_available_tree );
2363 gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE );
2365 auto column = ui::TreeViewColumn( "", renderer, {{"text", TAG_COLUMN}} );
2366 gtk_tree_view_append_column(g_TextureBrowser.m_available_tree, column );
2367 g_TextureBrowser.m_available_tree.show();
2369 scrolled_win.show();
2370 //gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW( scrolled_win ), g_TextureBrowser.m_available_tree );
2371 gtk_container_add( GTK_CONTAINER( scrolled_win ), GTK_WIDGET( g_TextureBrowser.m_available_tree ) );
2373 frame_table.attach(scrolled_win, {2, 3, 1, 3}, {GTK_FILL, GTK_FILL});
2375 { // tag arrow buttons
2376 auto m_btn_left = ui::Button(ui::New);
2377 auto m_btn_right = ui::Button(ui::New);
2378 auto m_arrow_left = ui::Widget::from(gtk_arrow_new( GTK_ARROW_LEFT, GTK_SHADOW_OUT ));
2379 auto m_arrow_right = ui::Widget::from(gtk_arrow_new( GTK_ARROW_RIGHT, GTK_SHADOW_OUT ));
2380 m_btn_left.add(m_arrow_left);
2381 m_btn_right.add(m_arrow_right);
2383 // workaround. the size of the tag frame depends of the requested size of the arrow buttons.
2384 m_arrow_left.dimensions(-1, 68);
2385 m_arrow_right.dimensions(-1, 68);
2387 frame_table.attach(m_btn_left, {1, 2, 1, 2}, {GTK_SHRINK, GTK_EXPAND});
2388 frame_table.attach(m_btn_right, {1, 2, 2, 3}, {GTK_SHRINK, GTK_EXPAND});
2390 m_btn_left.connect( "clicked", G_CALLBACK( TextureBrowser_assignTags ), NULL );
2391 m_btn_right.connect( "clicked", G_CALLBACK( TextureBrowser_removeTags ), NULL );
2395 m_arrow_left.show();
2396 m_arrow_right.show();
2398 { // tag fram labels
2399 ui::Widget m_lbl_assigned = ui::Label( "Assigned" );
2400 ui::Widget m_lbl_unassigned = ui::Label( "Available" );
2402 frame_table.attach(m_lbl_assigned, {0, 1, 0, 1}, {GTK_EXPAND, GTK_SHRINK});
2403 frame_table.attach(m_lbl_unassigned, {2, 3, 0, 1}, {GTK_EXPAND, GTK_SHRINK});
2405 m_lbl_assigned.show();
2406 m_lbl_unassigned.show();
2409 else { // no tag support, show the texture tree only
2410 vbox.pack_start( g_TextureBrowser.m_scr_win_tree, TRUE, TRUE, 0 );
2413 // TODO do we need this?
2414 //gtk_container_set_focus_chain(GTK_CONTAINER(hbox_table), NULL);
2419 void TextureBrowser_destroyWindow(){
2420 GlobalShaderSystem().setActiveShadersChangedNotify( Callback<void()>() );
2422 g_signal_handler_disconnect( G_OBJECT( g_TextureBrowser.m_gl_widget ), g_TextureBrowser.m_sizeHandler );
2423 g_signal_handler_disconnect( G_OBJECT( g_TextureBrowser.m_gl_widget ), g_TextureBrowser.m_exposeHandler );
2425 g_TextureBrowser.m_gl_widget.unref();
2428 const Vector3& TextureBrowser_getBackgroundColour( TextureBrowser& textureBrowser ){
2429 return textureBrowser.color_textureback;
2432 void TextureBrowser_setBackgroundColour( TextureBrowser& textureBrowser, const Vector3& colour ){
2433 textureBrowser.color_textureback = colour;
2434 TextureBrowser_queueDraw( textureBrowser );
2437 void TextureBrowser_selectionHelper( ui::TreeModel model, ui::TreePath path, GtkTreeIter* iter, GSList** selected ){
2438 g_assert( selected != NULL );
2441 gtk_tree_model_get( model, iter, TAG_COLUMN, &name, -1 );
2442 *selected = g_slist_append( *selected, name );
2445 void TextureBrowser_shaderInfo(){
2446 const char* name = TextureBrowser_GetSelectedShader( g_TextureBrowser );
2447 IShader* shader = QERApp_Shader_ForName( name );
2449 DoShaderInfoDlg( name, shader->getShaderFileName(), "Shader Info" );
2454 void TextureBrowser_addTag(){
2457 EMessageBoxReturn result = DoShaderTagDlg( &tag, "Add shader tag" );
2459 if ( result == eIDOK && !tag.empty() ) {
2461 g_TextureBrowser.m_all_tags.insert( tag.c_str() );
2462 gtk_list_store_append( g_TextureBrowser.m_available_store, &iter );
2463 gtk_list_store_set( g_TextureBrowser.m_available_store, &iter, TAG_COLUMN, tag.c_str(), -1 );
2465 // Select the currently added tag in the available list
2466 auto selection = gtk_tree_view_get_selection(g_TextureBrowser.m_available_tree );
2467 gtk_tree_selection_select_iter( selection, &iter );
2469 g_TextureBrowser.m_all_tags_list.append(TAG_COLUMN, tag.c_str());
2473 void TextureBrowser_renameTag(){
2474 /* WORKAROUND: The tag treeview is set to GTK_SELECTION_MULTIPLE. Because
2475 gtk_tree_selection_get_selected() doesn't work with GTK_SELECTION_MULTIPLE,
2476 we need to count the number of selected rows first and use
2477 gtk_tree_selection_selected_foreach() then to go through the list of selected
2478 rows (which always containins a single row).
2481 GSList* selected = NULL;
2483 auto selection = gtk_tree_view_get_selection(g_TextureBrowser.m_treeViewTags );
2484 gtk_tree_selection_selected_foreach( selection, GtkTreeSelectionForeachFunc( TextureBrowser_selectionHelper ), &selected );
2486 if ( g_slist_length( selected ) == 1 ) { // we only rename a single tag
2487 CopiedString newTag;
2488 EMessageBoxReturn result = DoShaderTagDlg( &newTag, "Rename shader tag" );
2490 if ( result == eIDOK && !newTag.empty() ) {
2491 GtkTreeIter iterList;
2493 gchar* oldTag = (char*)selected->data;
2495 bool row = gtk_tree_model_get_iter_first(g_TextureBrowser.m_all_tags_list, &iterList ) != 0;
2499 gtk_tree_model_get(g_TextureBrowser.m_all_tags_list, &iterList, TAG_COLUMN, &rowTag, -1 );
2501 if ( strcmp( rowTag, oldTag ) == 0 ) {
2502 gtk_list_store_set( g_TextureBrowser.m_all_tags_list, &iterList, TAG_COLUMN, newTag.c_str(), -1 );
2504 row = gtk_tree_model_iter_next(g_TextureBrowser.m_all_tags_list, &iterList ) != 0;
2507 TagBuilder.RenameShaderTag( oldTag, newTag.c_str() );
2509 g_TextureBrowser.m_all_tags.erase( (CopiedString)oldTag );
2510 g_TextureBrowser.m_all_tags.insert( newTag );
2512 BuildStoreAssignedTags( g_TextureBrowser.m_assigned_store, g_TextureBrowser.shader.c_str(), &g_TextureBrowser );
2513 BuildStoreAvailableTags( g_TextureBrowser.m_available_store, g_TextureBrowser.m_assigned_store, g_TextureBrowser.m_all_tags, &g_TextureBrowser );
2518 ui::alert( g_TextureBrowser.m_parent, "Select a single tag for renaming." );
2522 void TextureBrowser_deleteTag(){
2523 GSList* selected = NULL;
2525 auto selection = gtk_tree_view_get_selection(g_TextureBrowser.m_treeViewTags );
2526 gtk_tree_selection_selected_foreach( selection, GtkTreeSelectionForeachFunc( TextureBrowser_selectionHelper ), &selected );
2528 if ( g_slist_length( selected ) == 1 ) { // we only delete a single tag
2529 auto result = ui::alert( g_TextureBrowser.m_parent, "Are you sure you want to delete the selected tag?", "Delete Tag", ui::alert_type::YESNO, ui::alert_icon::Question );
2531 if ( result == ui::alert_response::YES ) {
2532 GtkTreeIter iterSelected;
2535 gchar* tagSelected = (char*)selected->data;
2537 bool row = gtk_tree_model_get_iter_first(g_TextureBrowser.m_all_tags_list, &iterSelected ) != 0;
2541 gtk_tree_model_get(g_TextureBrowser.m_all_tags_list, &iterSelected, TAG_COLUMN, &rowTag, -1 );
2543 if ( strcmp( rowTag, tagSelected ) == 0 ) {
2544 gtk_list_store_remove( g_TextureBrowser.m_all_tags_list, &iterSelected );
2547 row = gtk_tree_model_iter_next(g_TextureBrowser.m_all_tags_list, &iterSelected ) != 0;
2550 TagBuilder.DeleteTag( tagSelected );
2551 g_TextureBrowser.m_all_tags.erase( (CopiedString)tagSelected );
2553 BuildStoreAssignedTags( g_TextureBrowser.m_assigned_store, g_TextureBrowser.shader.c_str(), &g_TextureBrowser );
2554 BuildStoreAvailableTags( g_TextureBrowser.m_available_store, g_TextureBrowser.m_assigned_store, g_TextureBrowser.m_all_tags, &g_TextureBrowser );
2558 ui::alert( g_TextureBrowser.m_parent, "Select a single tag for deletion." );
2562 void TextureBrowser_copyTag(){
2563 g_TextureBrowser.m_copied_tags.clear();
2564 TagBuilder.GetShaderTags( g_TextureBrowser.shader.c_str(), g_TextureBrowser.m_copied_tags );
2567 void TextureBrowser_pasteTag(){
2568 IShader* ishader = QERApp_Shader_ForName( g_TextureBrowser.shader.c_str() );
2569 CopiedString shader = g_TextureBrowser.shader.c_str();
2571 if ( !TagBuilder.CheckShaderTag( shader.c_str() ) ) {
2572 CopiedString shaderFile = ishader->getShaderFileName();
2573 if ( shaderFile.empty() ) {
2575 TagBuilder.AddShaderNode( shader.c_str(), CUSTOM, TEXTURE );
2580 TagBuilder.AddShaderNode( shader.c_str(), CUSTOM, SHADER );
2583 for ( size_t i = 0; i < g_TextureBrowser.m_copied_tags.size(); ++i )
2585 TagBuilder.AddShaderTag( shader.c_str(), g_TextureBrowser.m_copied_tags[i].c_str(), TAG );
2590 for ( size_t i = 0; i < g_TextureBrowser.m_copied_tags.size(); ++i )
2592 if ( !TagBuilder.CheckShaderTag( shader.c_str(), g_TextureBrowser.m_copied_tags[i].c_str() ) ) {
2593 // the tag doesn't exist - let's add it
2594 TagBuilder.AddShaderTag( shader.c_str(), g_TextureBrowser.m_copied_tags[i].c_str(), TAG );
2601 TagBuilder.SaveXmlDoc();
2602 BuildStoreAssignedTags( g_TextureBrowser.m_assigned_store, shader.c_str(), &g_TextureBrowser );
2603 BuildStoreAvailableTags( g_TextureBrowser.m_available_store, g_TextureBrowser.m_assigned_store, g_TextureBrowser.m_all_tags, &g_TextureBrowser );
2606 void TextureBrowser_RefreshShaders(){
2608 /* When shaders are refreshed, forces reloading the textures as well.
2609 Previously it would at best only display shaders, at worst mess up some textured objects. */
2611 auto selection = gtk_tree_view_get_selection(GlobalTextureBrowser().m_treeViewTree);
2612 GtkTreeModel* model = NULL;
2614 if ( gtk_tree_selection_get_selected (selection, &model, &iter) )
2616 gchar dirName[1024];
2619 gtk_tree_model_get( model, &iter, 0, &buffer, -1 );
2620 strcpy( dirName, buffer );
2622 if ( !TextureBrowser_showWads() ) {
2623 strcat( dirName, "/" );
2626 ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", "Loading Shaders" );
2627 GlobalShaderSystem().refresh();
2628 /* texturebrowser tree update on vfs restart */
2629 TextureBrowser_constructTreeStore();
2632 TextureBrowser_ShowDirectory( GlobalTextureBrowser(), dirName );
2633 TextureBrowser_queueDraw( GlobalTextureBrowser() );
2637 ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", "Loading Shaders" );
2638 GlobalShaderSystem().refresh();
2639 /* texturebrowser tree update on vfs restart */
2640 TextureBrowser_constructTreeStore();
2645 void TextureBrowser_ToggleShowShaders(){
2646 g_TextureBrowser.m_showShaders ^= 1;
2647 g_TextureBrowser.m_showshaders_item.update();
2649 g_TextureBrowser.m_heightChanged = true;
2650 g_TextureBrowser.m_originInvalid = true;
2651 g_activeShadersChangedCallbacks();
2653 TextureBrowser_queueDraw( g_TextureBrowser );
2656 void TextureBrowser_ToggleShowTextures(){
2657 g_TextureBrowser.m_showTextures ^= 1;
2658 g_TextureBrowser.m_showtextures_item.update();
2660 g_TextureBrowser.m_heightChanged = true;
2661 g_TextureBrowser.m_originInvalid = true;
2662 g_activeShadersChangedCallbacks();
2664 TextureBrowser_queueDraw( g_TextureBrowser );
2667 void TextureBrowser_ToggleShowShaderListOnly(){
2668 g_TextureBrowser_shaderlistOnly ^= 1;
2669 g_TextureBrowser.m_showshaderlistonly_item.update();
2671 TextureBrowser_constructTreeStore();
2674 void TextureBrowser_showAll(){
2675 g_TextureBrowser_currentDirectory = "";
2676 g_TextureBrowser.m_searchedTags = false;
2677 // TextureBrowser_SetHideUnused( g_TextureBrowser, false );
2678 TextureBrowser_ToggleHideUnused();
2679 //TextureBrowser_heightChanged( g_TextureBrowser );
2680 TextureBrowser_updateTitle();
2683 void TextureBrowser_showUntagged(){
2684 auto result = ui::alert( 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", ui::alert_type::YESNO, ui::alert_icon::Warning );
2686 if ( result == ui::alert_response::YES ) {
2687 g_TextureBrowser.m_found_shaders.clear();
2688 TagBuilder.GetUntagged( g_TextureBrowser.m_found_shaders );
2689 std::set<CopiedString>::iterator iter;
2691 ScopeDisableScreenUpdates disableScreenUpdates( "Searching untagged textures...", "Loading Textures" );
2693 for ( iter = g_TextureBrowser.m_found_shaders.begin(); iter != g_TextureBrowser.m_found_shaders.end(); iter++ )
2695 std::string path = ( *iter ).c_str();
2696 size_t pos = path.find_last_of( "/", path.size() );
2697 std::string name = path.substr( pos + 1, path.size() );
2698 path = path.substr( 0, pos + 1 );
2699 TextureDirectory_loadTexture( path.c_str(), name.c_str() );
2700 globalErrorStream() << path.c_str() << name.c_str() << "\n";
2703 g_TextureBrowser_currentDirectory = "Untagged";
2704 TextureBrowser_queueDraw( GlobalTextureBrowser() );
2705 TextureBrowser_heightChanged( g_TextureBrowser );
2706 TextureBrowser_updateTitle();
2710 void TextureBrowser_FixedSize(){
2711 g_TextureBrowser_fixedSize ^= 1;
2712 GlobalTextureBrowser().m_fixedsize_item.update();
2713 TextureBrowser_activeShadersChanged( GlobalTextureBrowser() );
2716 void TextureBrowser_FilterMissing(){
2717 g_TextureBrowser_filterMissing ^= 1;
2718 GlobalTextureBrowser().m_filternotex_item.update();
2719 TextureBrowser_activeShadersChanged( GlobalTextureBrowser() );
2720 TextureBrowser_RefreshShaders();
2723 void TextureBrowser_FilterFallback(){
2724 g_TextureBrowser_filterFallback ^= 1;
2725 GlobalTextureBrowser().m_hidenotex_item.update();
2726 TextureBrowser_activeShadersChanged( GlobalTextureBrowser() );
2727 TextureBrowser_RefreshShaders();
2730 void TextureBrowser_EnableAlpha(){
2731 g_TextureBrowser_enableAlpha ^= 1;
2732 GlobalTextureBrowser().m_enablealpha_item.update();
2733 TextureBrowser_activeShadersChanged( GlobalTextureBrowser() );
2736 void TextureBrowser_exportTitle( const Callback<void(const char *)> & importer ){
2737 StringOutputStream buffer( 64 );
2738 buffer << "Textures: ";
2739 if ( !string_empty( g_TextureBrowser_currentDirectory.c_str() ) ) {
2740 buffer << g_TextureBrowser_currentDirectory.c_str();
2746 importer( buffer.c_str() );
2749 struct TextureScale {
2750 static void Export(const TextureBrowser &self, const Callback<void(int)> &returnz) {
2751 switch (self.m_textureScale) {
2770 static void Import(TextureBrowser &self, int value) {
2773 TextureBrowser_setScale(self, 10);
2776 TextureBrowser_setScale(self, 25);
2779 TextureBrowser_setScale(self, 50);
2782 TextureBrowser_setScale(self, 100);
2785 TextureBrowser_setScale(self, 200);
2791 struct UniformTextureSize {
2792 static void Export(const TextureBrowser &self, const Callback<void(int)> &returnz) {
2793 returnz(g_TextureBrowser.m_uniformTextureSize);
2796 static void Import(TextureBrowser &self, int value) {
2798 TextureBrowser_setUniformSize(self, value);
2802 struct UniformTextureMinSize {
2803 static void Export(const TextureBrowser &self, const Callback<void(int)> &returnz) {
2804 returnz(g_TextureBrowser.m_uniformTextureMinSize);
2807 static void Import(TextureBrowser &self, int value) {
2809 TextureBrowser_setUniformSize(self, value);
2813 void TextureBrowser_constructPreferences( PreferencesPage& page ){
2814 page.appendCheckBox(
2815 "", "Texture scrollbar",
2816 make_property<TextureBrowser_ShowScrollbar>(GlobalTextureBrowser())
2819 const char* texture_scale[] = { "10%", "25%", "50%", "100%", "200%" };
2821 "Texture Thumbnail Scale",
2822 STRING_ARRAY_RANGE( texture_scale ),
2823 make_property<TextureScale>(GlobalTextureBrowser())
2826 page.appendSpinner( "Thumbnails Max Size", GlobalTextureBrowser().m_uniformTextureSize, GlobalTextureBrowser().m_uniformTextureSize, 16, 8192 );
2827 page.appendSpinner( "Thumbnails Min Size", GlobalTextureBrowser().m_uniformTextureMinSize, GlobalTextureBrowser().m_uniformTextureMinSize, 16, 8192 );
2828 page.appendEntry( "Mousewheel Increment", GlobalTextureBrowser().m_mouseWheelScrollIncrement );
2830 const char* startup_shaders[] = { "None", TextureBrowser_getComonShadersName() };
2831 page.appendCombo( "Load Shaders at Startup", reinterpret_cast<int&>( GlobalTextureBrowser().m_startupShaders ), STRING_ARRAY_RANGE( startup_shaders ) );
2834 StringOutputStream sstream( 256 );
2835 sstream << "Hide nonShaders in " << TextureBrowser_getComonShadersDir() << " folder";
2836 page.appendCheckBox(
2837 "", sstream.c_str(),
2838 GlobalTextureBrowser().m_hideNonShadersInCommon
2843 void TextureBrowser_constructPage( PreferenceGroup& group ){
2844 PreferencesPage page( group.createPage( "Texture Browser", "Texture Browser Preferences" ) );
2845 TextureBrowser_constructPreferences( page );
2848 void TextureBrowser_registerPreferencesPage(){
2849 PreferencesDialog_addSettingsPage( makeCallbackF(TextureBrowser_constructPage) );
2853 #include "preferencesystem.h"
2854 #include "stringio.h"
2857 void TextureClipboard_textureSelected( const char* shader );
2859 void TextureBrowser_Construct(){
2860 GlobalCommands_insert( "ShaderInfo", makeCallbackF(TextureBrowser_shaderInfo) );
2861 GlobalCommands_insert( "ShowUntagged", makeCallbackF(TextureBrowser_showUntagged) );
2862 GlobalCommands_insert( "AddTag", makeCallbackF(TextureBrowser_addTag) );
2863 GlobalCommands_insert( "RenameTag", makeCallbackF(TextureBrowser_renameTag) );
2864 GlobalCommands_insert( "DeleteTag", makeCallbackF(TextureBrowser_deleteTag) );
2865 GlobalCommands_insert( "CopyTag", makeCallbackF(TextureBrowser_copyTag) );
2866 GlobalCommands_insert( "PasteTag", makeCallbackF(TextureBrowser_pasteTag) );
2867 GlobalCommands_insert( "RefreshShaders", makeCallbackF(VFS_Refresh) );
2868 GlobalToggles_insert( "ShowInUse", makeCallbackF(TextureBrowser_ToggleHideUnused), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_hideunused_item ), Accelerator( 'U' ) );
2869 GlobalCommands_insert( "ShowAllTextures", makeCallbackF(TextureBrowser_showAll), Accelerator( 'A', (GdkModifierType)GDK_CONTROL_MASK ) );
2870 GlobalCommands_insert( "ToggleTextures", makeCallbackF(TextureBrowser_toggleShow), Accelerator( 'T' ) );
2871 GlobalToggles_insert( "ToggleShowShaders", makeCallbackF(TextureBrowser_ToggleShowShaders), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_showshaders_item ) );
2872 GlobalToggles_insert( "ToggleShowTextures", makeCallbackF(TextureBrowser_ToggleShowTextures), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_showtextures_item ) );
2873 GlobalToggles_insert( "ToggleShowShaderlistOnly", makeCallbackF(TextureBrowser_ToggleShowShaderListOnly),
2874 ToggleItem::AddCallbackCaller( g_TextureBrowser.m_showshaderlistonly_item ) );
2875 GlobalToggles_insert( "FixedSize", makeCallbackF(TextureBrowser_FixedSize), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_fixedsize_item ) );
2876 GlobalToggles_insert( "FilterMissing", makeCallbackF(TextureBrowser_FilterMissing), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_filternotex_item ) );
2877 GlobalToggles_insert( "FilterFallback", makeCallbackF(TextureBrowser_FilterFallback), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_hidenotex_item ) );
2878 GlobalToggles_insert( "EnableAlpha", makeCallbackF(TextureBrowser_EnableAlpha), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_enablealpha_item ) );
2880 GlobalPreferenceSystem().registerPreference( "TextureScale", make_property_string<TextureScale>(g_TextureBrowser) );
2881 GlobalPreferenceSystem().registerPreference( "UniformTextureSize", make_property_string<UniformTextureSize>(g_TextureBrowser) );
2882 GlobalPreferenceSystem().registerPreference( "UniformTextureMinSize", make_property_string<UniformTextureMinSize>(g_TextureBrowser) );
2883 GlobalPreferenceSystem().registerPreference( "TextureScrollbar", make_property_string<TextureBrowser_ShowScrollbar>(GlobalTextureBrowser()));
2884 GlobalPreferenceSystem().registerPreference( "ShowShaders", make_property_string( GlobalTextureBrowser().m_showShaders ) );
2885 GlobalPreferenceSystem().registerPreference( "ShowTextures", make_property_string( GlobalTextureBrowser().m_showTextures ) );
2886 GlobalPreferenceSystem().registerPreference( "ShowShaderlistOnly", make_property_string( g_TextureBrowser_shaderlistOnly ) );
2887 GlobalPreferenceSystem().registerPreference( "FixedSize", make_property_string( g_TextureBrowser_fixedSize ) );
2888 GlobalPreferenceSystem().registerPreference( "FilterMissing", make_property_string( g_TextureBrowser_filterMissing ) );
2889 GlobalPreferenceSystem().registerPreference( "EnableAlpha", make_property_string( g_TextureBrowser_enableAlpha ) );
2890 GlobalPreferenceSystem().registerPreference( "LoadShaders", make_property_string( reinterpret_cast<int&>( GlobalTextureBrowser().m_startupShaders ) ) );
2891 GlobalPreferenceSystem().registerPreference( "WheelMouseInc", make_property_string( GlobalTextureBrowser().m_mouseWheelScrollIncrement ) );
2892 GlobalPreferenceSystem().registerPreference( "SI_Colors0", make_property_string( GlobalTextureBrowser().color_textureback ) );
2893 GlobalPreferenceSystem().registerPreference( "HideNonShadersInCommon", make_property_string( GlobalTextureBrowser().m_hideNonShadersInCommon ) );
2895 g_TextureBrowser.shader = texdef_name_default();
2897 Textures_setModeChangedNotify( ReferenceCaller<TextureBrowser, void(), TextureBrowser_queueDraw>( g_TextureBrowser ) );
2899 TextureBrowser_registerPreferencesPage();
2901 GlobalShaderSystem().attach( g_ShadersObserver );
2903 TextureBrowser_textureSelected = TextureClipboard_textureSelected;
2906 void TextureBrowser_Destroy(){
2907 GlobalShaderSystem().detach( g_ShadersObserver );
2909 Textures_setModeChangedNotify( Callback<void()>() );
2912 ui::Widget TextureBrowser_getGLWidget(){
2913 return GlobalTextureBrowser().m_gl_widget;