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" ) ) {
104 groups.insert( archive );
108 typedef ReferenceCaller<TextureGroups, void(const char*), TextureGroups_addWad> TextureGroupsAddWadCaller;
112 bool g_TextureBrowser_shaderlistOnly = false;
113 bool g_TextureBrowser_fixedSize = true;
114 bool g_TextureBrowser_filterMissing = false;
115 bool g_TextureBrowser_filterFallback = true;
116 bool g_TextureBrowser_enableAlpha = false;
119 CopiedString g_notex;
120 CopiedString g_shadernotex;
122 bool isMissing(const char* name);
124 bool isNotex(const char* name);
126 bool isMissing(const char* name){
127 if ( string_equal( g_notex.c_str(), name ) ) {
130 if ( string_equal( g_shadernotex.c_str(), name ) ) {
136 bool isNotex(const char* name){
137 if ( string_equal_suffix( name, "/" DEFAULT_NOTEX_BASENAME ) ) {
140 if ( string_equal_suffix( name, "/" DEFAULT_SHADERNOTEX_BASENAME ) ) {
146 void TextureGroups_addShader( TextureGroups& groups, const char* shaderName ){
147 const char* texture = path_make_relative( shaderName, "textures/" );
149 // hide notex / shadernotex images
150 if ( g_TextureBrowser_filterFallback ) {
151 if ( isNotex( shaderName ) ) {
156 if ( texture != shaderName ) {
157 const char* last = path_remove_directory( texture );
158 if ( !string_empty( last ) ) {
159 groups.insert( CopiedString( StringRange( texture, --last ) ) );
164 typedef ReferenceCaller<TextureGroups, void(const char*), TextureGroups_addShader> TextureGroupsAddShaderCaller;
166 void TextureGroups_addDirectory( TextureGroups& groups, const char* directory ){
167 groups.insert( directory );
170 typedef ReferenceCaller<TextureGroups, void(const char*), TextureGroups_addDirectory> TextureGroupsAddDirectoryCaller;
172 class DeferredAdjustment
177 typedef void ( *ValueChangedFunction )( void* data, gdouble value );
179 ValueChangedFunction m_function;
182 static gboolean deferred_value_changed( gpointer data ){
183 reinterpret_cast<DeferredAdjustment*>( data )->m_function(
184 reinterpret_cast<DeferredAdjustment*>( data )->m_data,
185 reinterpret_cast<DeferredAdjustment*>( data )->m_value
187 reinterpret_cast<DeferredAdjustment*>( data )->m_handler = 0;
188 reinterpret_cast<DeferredAdjustment*>( data )->m_value = 0;
193 DeferredAdjustment( ValueChangedFunction function, void* data ) : m_value( 0 ), m_handler( 0 ), m_function( function ), m_data( data ){
197 if ( m_handler != 0 ) {
198 g_source_remove( m_handler );
199 deferred_value_changed( this );
203 void value_changed( gdouble value ){
205 if ( m_handler == 0 ) {
206 m_handler = g_idle_add( deferred_value_changed, this );
210 static void adjustment_value_changed(ui::Adjustment adjustment, DeferredAdjustment* self ){
211 self->value_changed( gtk_adjustment_get_value(adjustment) );
216 class TextureBrowser;
218 typedef ReferenceCaller<TextureBrowser, void(), TextureBrowser_queueDraw> TextureBrowserQueueDrawCaller;
220 void TextureBrowser_scrollChanged( void* data, gdouble value );
225 STARTUPSHADERS_NONE = 0,
226 STARTUPSHADERS_COMMON,
229 void TextureBrowser_hideUnusedExport( const Callback<void(bool)> & importer );
231 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_hideUnusedExport> TextureBrowserHideUnusedExport;
233 void TextureBrowser_showShadersExport( const Callback<void(bool)> & importer );
235 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_showShadersExport> TextureBrowserShowShadersExport;
237 void TextureBrowser_showTexturesExport( const Callback<void(bool)> & importer );
239 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_showTexturesExport> TextureBrowserShowTexturesExport;
241 void TextureBrowser_showShaderlistOnly( const Callback<void(bool)> & importer );
243 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_showShaderlistOnly> TextureBrowserShowShaderlistOnlyExport;
245 void TextureBrowser_fixedSize( const Callback<void(bool)> & importer );
247 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_fixedSize> TextureBrowserFixedSizeExport;
249 void TextureBrowser_filterMissing( const Callback<void(bool)> & importer );
251 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_filterMissing> TextureBrowserFilterMissingExport;
253 void TextureBrowser_filterFallback( const Callback<void(bool)> & importer );
255 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_filterFallback> TextureBrowserFilterFallbackExport;
257 void TextureBrowser_enableAlpha( const Callback<void(bool)> & importer );
259 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_enableAlpha> TextureBrowserEnableAlphaExport;
270 ui::Window m_parent{ui::null};
271 #ifdef WORKAROUND_MACOS_GTK2_GLWIDGET
272 ui::VBox m_vframe{ui::null};
273 ui::VBox m_vfiller{ui::null};
274 ui::HBox m_hframe{ui::null};
275 ui::HBox m_hfiller{ui::null};
276 #else // !WORKAROUND_MACOS_GTK2_GLWIDGET
277 ui::VBox m_frame{ui::null};
278 #endif // !WORKAROUND_MACOS_GTK2_GLWIDGET
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_move_started( false ),
397 m_uniformTextureSize( 160 ),
398 m_uniformTextureMinSize( 48 ),
399 m_hideNonShadersInCommon( true ){
403 void ( *TextureBrowser_textureSelected )( const char* shader );
406 void TextureBrowser_updateScroll( TextureBrowser& textureBrowser );
409 const char* TextureBrowser_getCommonShadersName(){
410 const char* value = g_pGameDescription->getKeyValue( "common_shaders_name" );
411 if ( !string_empty( value ) ) {
417 const char* TextureBrowser_getCommonShadersDir(){
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() ) ) {
552 if ( g_TextureBrowser_currentDirectory == "Untagged" ) {
553 std::set<CopiedString>::iterator iter;
555 iter = GlobalTextureBrowser().m_found_shaders.find( shader->getName() );
557 if ( iter == GlobalTextureBrowser().m_found_shaders.end() ) {
565 if ( !shader_equal_prefix( shader->getName(), "textures/" ) ) {
569 if ( !show_shaders && !shader->IsDefault() ) {
573 if ( !show_textures && shader->IsDefault() ) {
577 if ( hideUnused && !shader->IsInUse() ) {
581 if( hideNonShadersInCommon && shader->IsDefault() && !shader->IsInUse() //&& g_TextureBrowser_currentDirectory != ""
582 && shader_equal_prefix( shader_get_textureName( shader->getName() ), TextureBrowser_getCommonShadersDir() ) ){
586 if ( GlobalTextureBrowser().m_searchedTags ) {
587 if ( !TextureSearch_IsShown( shader->getName() ) ) {
595 if ( TextureBrowser_showWads() )
597 if ( g_TextureBrowser_currentDirectory != ""
598 && !string_equal( shader->getWadName(), g_TextureBrowser_currentDirectory.c_str() ) )
603 else if ( !shader_equal_prefix( shader_get_textureName( shader->getName() ), g_TextureBrowser_currentDirectory.c_str() ) ) {
611 void TextureBrowser_heightChanged( TextureBrowser& textureBrowser ){
612 textureBrowser.m_heightChanged = true;
614 TextureBrowser_updateScroll( textureBrowser );
615 TextureBrowser_queueDraw( textureBrowser );
618 void TextureBrowser_evaluateHeight( TextureBrowser& textureBrowser ){
619 if ( textureBrowser.m_heightChanged ) {
620 textureBrowser.m_heightChanged = false;
622 textureBrowser.m_nTotalHeight = 0;
624 TextureLayout layout;
625 Texture_StartPos( layout );
626 for ( QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement() )
628 IShader* shader = QERApp_ActiveShaders_IteratorCurrent();
630 if ( !Texture_IsShown( shader, textureBrowser.m_showShaders, textureBrowser.m_showTextures, textureBrowser.m_hideUnused, textureBrowser.m_hideNonShadersInCommon ) ) {
635 Texture_NextPos( textureBrowser, layout, shader->getTexture(), &x, &y );
637 textureBrowser.getTextureWH( shader->getTexture(), nWidth, nHeight );
638 textureBrowser.m_nTotalHeight = std::max( textureBrowser.m_nTotalHeight, abs( layout.current_y ) + TextureBrowser_fontHeight( textureBrowser ) + nHeight + 4 );
643 int TextureBrowser_TotalHeight( TextureBrowser& textureBrowser ){
644 TextureBrowser_evaluateHeight( textureBrowser );
645 return textureBrowser.m_nTotalHeight;
648 inline const int& min_int( const int& left, const int& right ){
649 return std::min( left, right );
652 void TextureBrowser_clampOriginY( TextureBrowser& textureBrowser ){
653 if ( textureBrowser.originy > 0 ) {
654 textureBrowser.originy = 0;
656 int lower = min_int( textureBrowser.height - TextureBrowser_TotalHeight( textureBrowser ), 0 );
657 if ( textureBrowser.originy < lower ) {
658 textureBrowser.originy = lower;
662 int TextureBrowser_getOriginY( TextureBrowser& textureBrowser ){
663 if ( textureBrowser.m_originInvalid ) {
664 textureBrowser.m_originInvalid = false;
665 TextureBrowser_clampOriginY( textureBrowser );
666 TextureBrowser_updateScroll( textureBrowser );
668 return textureBrowser.originy;
671 void TextureBrowser_setOriginY( TextureBrowser& textureBrowser, int originy ){
672 textureBrowser.originy = originy;
673 TextureBrowser_clampOriginY( textureBrowser );
674 TextureBrowser_updateScroll( textureBrowser );
675 TextureBrowser_queueDraw( textureBrowser );
679 Signal0 g_activeShadersChangedCallbacks;
681 void TextureBrowser_addActiveShadersChangedCallback( const SignalHandler& handler ){
682 g_activeShadersChangedCallbacks.connectLast( handler );
685 void TextureBrowser_constructTreeStore();
687 class ShadersObserver : public ModuleObserver
689 Signal0 m_realiseCallbacks;
692 m_realiseCallbacks();
693 /* texturebrowser tree update on vfs restart */
694 // TextureBrowser_constructTreeStore();
700 void insert( const SignalHandler& handler ){
701 m_realiseCallbacks.connectLast( handler );
707 ShadersObserver g_ShadersObserver;
710 void TextureBrowser_addShadersRealiseCallback( const SignalHandler& handler ){
711 g_ShadersObserver.insert( handler );
714 void TextureBrowser_activeShadersChanged( TextureBrowser& textureBrowser ){
715 TextureBrowser_heightChanged( textureBrowser );
716 textureBrowser.m_originInvalid = true;
718 g_activeShadersChangedCallbacks();
721 struct TextureBrowser_ShowScrollbar {
722 static void Export(const TextureBrowser &self, const Callback<void(bool)> &returnz) {
723 returnz(self.m_showTextureScrollbar);
726 static void Import(TextureBrowser &self, bool value) {
727 self.m_showTextureScrollbar = value;
728 if (self.m_texture_scroll) {
729 self.m_texture_scroll.visible(self.m_showTextureScrollbar);
730 TextureBrowser_updateScroll(self);
738 TextureBrowser_ShowDirectory
739 relies on texture_directory global for the directory to use
740 1) Load the shaders for the given directory
741 2) Scan the remaining texture, load them and assign them a default shader (the "noshader" shader)
742 NOTE: when writing a texture plugin, or some texture extensions, this function may need to be overriden, and made
743 available through the IShaders interface
744 NOTE: for texture window layout:
745 all shaders are stored with alphabetical order after load
746 previously loaded and displayed stuff is hidden, only in-use and newly loaded is shown
747 ( the GL textures are not flushed though)
751 bool endswith( const char *haystack, const char *needle ){
752 size_t lh = strlen( haystack );
753 size_t ln = strlen( needle );
757 return !memcmp( haystack + ( lh - ln ), needle, ln );
760 bool texture_name_ignore( const char* name ){
761 StringOutputStream strTemp( string_length( name ) );
762 strTemp << LowerCase( name );
765 endswith( strTemp.c_str(), ".specular" ) ||
766 endswith( strTemp.c_str(), ".glow" ) ||
767 endswith( strTemp.c_str(), ".bump" ) ||
768 endswith( strTemp.c_str(), ".diffuse" ) ||
769 endswith( strTemp.c_str(), ".blend" ) ||
770 endswith( strTemp.c_str(), ".alpha" ) ||
771 endswith( strTemp.c_str(), "_alpha" ) ||
773 endswith( strTemp.c_str(), "_h" ) ||
774 endswith( strTemp.c_str(), "_local" ) ||
775 endswith( strTemp.c_str(), "_nm" ) ||
776 endswith( strTemp.c_str(), "_s" ) ||
778 endswith( strTemp.c_str(), "_bump" ) ||
779 endswith( strTemp.c_str(), "_glow" ) ||
780 endswith( strTemp.c_str(), "_gloss" ) ||
781 endswith( strTemp.c_str(), "_luma" ) ||
782 endswith( strTemp.c_str(), "_norm" ) ||
783 endswith( strTemp.c_str(), "_pants" ) ||
784 endswith( strTemp.c_str(), "_shirt" ) ||
785 endswith( strTemp.c_str(), "_reflect" ) ||
787 endswith( strTemp.c_str(), "_d" ) ||
788 endswith( strTemp.c_str(), "_n" ) ||
789 endswith( strTemp.c_str(), "_p" ) ||
790 endswith( strTemp.c_str(), "_g" ) ||
791 endswith( strTemp.c_str(), "_a" ) ||
795 class LoadShaderVisitor : public Archive::Visitor
798 void visit( const char* name ){
799 IShader* shader = QERApp_Shader_ForName( CopiedString( StringRange( name, path_get_filename_base_end( name ) ) ).c_str() );
801 shader->setWadName( g_TextureBrowser_currentDirectory.c_str() );
805 void TextureBrowser_SetHideUnused( TextureBrowser& textureBrowser, bool hideUnused );
807 ui::Widget g_page_textures{ui::null};
809 void TextureBrowser_toggleShow(){
810 GroupDialog_showPage( g_page_textures );
814 void TextureBrowser_updateTitle(){
815 GroupDialog_updatePageTitle( g_page_textures );
819 class TextureCategoryLoadShader
821 const char* m_directory;
822 std::size_t& m_count;
824 using func = void(const char *);
826 TextureCategoryLoadShader( const char* directory, std::size_t& count )
827 : m_directory( directory ), m_count( count ){
831 void operator()( const char* name ) const {
832 if ( shader_equal_prefix( name, "textures/" )
833 && shader_equal_prefix( name + string_length( "textures/" ), m_directory ) ) {
835 // request the shader, this will load the texture if needed
836 // this Shader_ForName call is a kind of hack
837 IShader *pFoo = QERApp_Shader_ForName( name );
843 void TextureDirectory_loadTexture( const char* directory, const char* texture ){
844 // Doom3-like dds/ prefix (used by DarkPlaces).
845 // When we list dds/textures/ folder,
846 // store the texture names without dds/ prefix.
847 if ( !strncmp( "dds/", directory, 4 ) )
849 directory = &directory[ 4 ];
852 StringOutputStream name( 256 );
853 name << directory << StringRange( texture, path_get_filename_base_end( texture ) );
855 if ( texture_name_ignore( name.c_str() ) ) {
859 if ( !shader_valid( name.c_str() ) ) {
860 globalOutputStream() << "Skipping invalid texture name: [" << name.c_str() << "]\n";
864 // if a texture is already in use to represent a shader, ignore it
865 IShader* shader = QERApp_Shader_ForName( name.c_str() );
869 typedef ConstPointerCaller<char, void(const char*), TextureDirectory_loadTexture> TextureDirectoryLoadTextureCaller;
871 class LoadTexturesByTypeVisitor : public ImageModules::Visitor
873 const char* m_dirstring;
875 LoadTexturesByTypeVisitor( const char* dirstring )
876 : m_dirstring( dirstring ){
879 void visit( const char* minor, const _QERPlugImageTable& table ) const {
880 GlobalFileSystem().forEachFile( m_dirstring, minor, TextureDirectoryLoadTextureCaller( m_dirstring ) );
884 void TextureBrowser_ShowDirectory( TextureBrowser& textureBrowser, const char* directory ){
885 textureBrowser.m_searchedTags = false;
886 if ( TextureBrowser_showWads() ) {
887 g_TextureBrowser_currentDirectory = directory;
888 TextureBrowser_heightChanged( textureBrowser );
890 Archive* archive = GlobalFileSystem().getArchive( directory );
891 if ( archive != nullptr )
893 LoadShaderVisitor visitor;
894 archive->forEachFile( Archive::VisitorFunc( visitor, Archive::eFiles, 0 ), "textures/" );
896 // Doom3-like dds/ prefix (used by DarkPlaces).
897 archive->forEachFile( Archive::VisitorFunc( visitor, Archive::eFiles, 0 ), "dds/textures/" );
899 else if ( extension_equal_i( path_get_extension( directory ), "wad" ) )
901 globalErrorStream() << "Failed to load " << directory << "\n";
906 g_TextureBrowser_currentDirectory = directory;
907 TextureBrowser_heightChanged( textureBrowser );
909 std::size_t shaders_count;
910 GlobalShaderSystem().foreachShaderName(makeCallback( TextureCategoryLoadShader( directory, shaders_count ) ) );
911 globalOutputStream() << "Showing " << Unsigned( shaders_count ) << " shaders.\n";
913 if ( g_pGameDescription->mGameType != "doom3" ) {
914 // load remaining texture files
916 StringOutputStream dirstring( 64 );
917 dirstring << "textures/" << directory;
920 LoadTexturesByTypeVisitor visitor( dirstring.c_str() );
921 Radiant_getImageModules().foreachModule( visitor );
924 // Doom3-like dds/ prefix (used by DarkPlaces).
926 dirstring << "dds/textures/" << directory;
929 LoadTexturesByTypeVisitor visitor( dirstring.c_str() );
930 Radiant_getImageModules().foreachModule( visitor );
935 // we'll display the newly loaded textures + all the ones already in use
936 TextureBrowser_SetHideUnused( textureBrowser, false );
938 TextureBrowser_updateTitle();
941 void TextureBrowser_ShowTagSearchResult( TextureBrowser& textureBrowser, const char* directory ){
942 g_TextureBrowser_currentDirectory = directory;
943 TextureBrowser_heightChanged( textureBrowser );
945 std::size_t shaders_count;
946 GlobalShaderSystem().foreachShaderName(makeCallback( TextureCategoryLoadShader( directory, shaders_count ) ) );
947 globalOutputStream() << "Showing " << Unsigned( shaders_count ) << " shaders.\n";
949 if ( g_pGameDescription->mGameType != "doom3" ) {
950 // load remaining texture files
951 StringOutputStream dirstring( 64 );
952 dirstring << "textures/" << directory;
955 LoadTexturesByTypeVisitor visitor( dirstring.c_str() );
956 Radiant_getImageModules().foreachModule( visitor );
959 // Doom3-like dds/ prefix (used by DarkPlaces).
961 dirstring << "dds/textures/" << directory;
964 LoadTexturesByTypeVisitor visitor( dirstring.c_str() );
965 Radiant_getImageModules().foreachModule( visitor );
969 // we'll display the newly loaded textures + all the ones already in use
970 TextureBrowser_SetHideUnused( textureBrowser, false );
974 bool TextureBrowser_hideUnused();
976 void TextureBrowser_hideUnusedExport( const Callback<void(bool)> & importer ){
977 importer( TextureBrowser_hideUnused() );
980 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_hideUnusedExport> TextureBrowserHideUnusedExport;
982 void TextureBrowser_showShadersExport( const Callback<void(bool)> & importer ){
983 importer( GlobalTextureBrowser().m_showShaders );
986 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_showShadersExport> TextureBrowserShowShadersExport;
988 void TextureBrowser_showTexturesExport( const Callback<void(bool)> & importer ){
989 importer( GlobalTextureBrowser().m_showTextures );
992 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_showTexturesExport> TextureBrowserShowTexturesExport;
994 void TextureBrowser_showShaderlistOnly( const Callback<void(bool)> & importer ){
995 importer( g_TextureBrowser_shaderlistOnly );
998 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_showShaderlistOnly> TextureBrowserShowShaderlistOnlyExport;
1000 void TextureBrowser_fixedSize( const Callback<void(bool)> & importer ){
1001 importer( g_TextureBrowser_fixedSize );
1004 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_fixedSize> TextureBrowser_FixedSizeExport;
1006 void TextureBrowser_filterMissing( const Callback<void(bool)> & importer ){
1007 importer( g_TextureBrowser_filterMissing );
1010 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_filterMissing> TextureBrowser_filterMissingExport;
1012 void TextureBrowser_filterFallback( const Callback<void(bool)> & importer ){
1013 importer( g_TextureBrowser_filterFallback );
1016 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_filterFallback> TextureBrowser_filterFallbackExport;
1018 void TextureBrowser_enableAlpha( const Callback<void(bool)> & importer ){
1019 importer( g_TextureBrowser_enableAlpha );
1022 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_enableAlpha> TextureBrowser_enableAlphaExport;
1024 void TextureBrowser_SetHideUnused( TextureBrowser& textureBrowser, bool hideUnused ){
1025 textureBrowser.m_hideUnused = hideUnused;
1027 textureBrowser.m_hideunused_item.update();
1029 TextureBrowser_heightChanged( textureBrowser );
1030 textureBrowser.m_originInvalid = true;
1033 void TextureBrowser_ShowStartupShaders( TextureBrowser& textureBrowser ){
1034 if ( textureBrowser.m_startupShaders == STARTUPSHADERS_COMMON ) {
1035 TextureBrowser_ShowDirectory( textureBrowser, TextureBrowser_getCommonShadersDir() );
1040 //++timo NOTE: this is a mix of Shader module stuff and texture explorer
1041 // it might need to be split in parts or moved out .. dunno
1042 // scroll origin so the specified texture is completely on screen
1043 // if current texture is not displayed, nothing is changed
1044 void TextureBrowser_Focus( TextureBrowser& textureBrowser, const char* name ){
1045 TextureLayout layout;
1046 // scroll origin so the texture is completely on screen
1047 Texture_StartPos( layout );
1049 for ( QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement() )
1051 IShader* shader = QERApp_ActiveShaders_IteratorCurrent();
1053 if ( !Texture_IsShown( shader, textureBrowser.m_showShaders, textureBrowser.m_showTextures, textureBrowser.m_hideUnused, textureBrowser.m_hideNonShadersInCommon ) ) {
1058 Texture_NextPos( textureBrowser, layout, shader->getTexture(), &x, &y );
1059 qtexture_t* q = shader->getTexture();
1064 // we have found when texdef->name and the shader name match
1065 // NOTE: as everywhere else for our comparisons, we are not case sensitive
1066 if ( shader_equal( name, shader->getName() ) ) {
1067 //int textureHeight = (int)( q->height * ( (float)textureBrowser.m_textureScale / 100 ) ) + 2 * TextureBrowser_fontHeight( textureBrowser );
1068 int textureWidth, textureHeight;
1069 textureBrowser.getTextureWH( q, textureWidth, textureHeight );
1070 textureHeight += 2 * TextureBrowser_fontHeight( textureBrowser );
1073 int originy = TextureBrowser_getOriginY( textureBrowser );
1074 if ( y > originy ) {
1078 if ( y - textureHeight < originy - textureBrowser.height ) {
1079 originy = ( y - textureHeight ) + textureBrowser.height;
1082 TextureBrowser_setOriginY( textureBrowser, originy );
1088 IShader* Texture_At( TextureBrowser& textureBrowser, int mx, int my ){
1089 my += TextureBrowser_getOriginY( textureBrowser ) - textureBrowser.height;
1091 TextureLayout layout;
1092 Texture_StartPos( layout );
1093 for ( QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement() )
1095 IShader* shader = QERApp_ActiveShaders_IteratorCurrent();
1097 if ( !Texture_IsShown( shader, textureBrowser.m_showShaders, textureBrowser.m_showTextures, textureBrowser.m_hideUnused, textureBrowser.m_hideNonShadersInCommon ) ) {
1102 Texture_NextPos( textureBrowser, layout, shader->getTexture(), &x, &y );
1103 qtexture_t *q = shader->getTexture();
1108 int nWidth, nHeight;
1109 textureBrowser.getTextureWH( q, nWidth, nHeight );
1110 if ( mx > x && mx - x < nWidth
1111 && my < y && y - my < nHeight + TextureBrowser_fontHeight( textureBrowser ) ) {
1126 void SelectTexture( TextureBrowser& textureBrowser, int mx, int my, guint32 flags, bool texturizeSelection ){
1127 if ( ( flags & GDK_SHIFT_MASK ) == 0 ) {
1128 IShader* shader = Texture_At( textureBrowser, mx, my );
1129 if ( shader != 0 ) {
1130 TextureBrowser_SetSelectedShader( textureBrowser, shader->getName() );
1131 TextureBrowser_textureSelected( shader->getName() );
1133 if ( !FindTextureDialog_isOpen() && !textureBrowser.m_rmbSelected && !texturizeSelection ) {
1134 Select_SetShader_Undo( shader->getName() );
1141 ============================================================================
1145 ============================================================================
1148 void TextureBrowser_trackingDelta( int x, int y, unsigned int state, void* data ){
1149 TextureBrowser& textureBrowser = *reinterpret_cast<TextureBrowser*>( data );
1153 if ( state & GDK_SHIFT_MASK ) {
1157 int originy = TextureBrowser_getOriginY( textureBrowser );
1158 originy += y * scale;
1159 TextureBrowser_setOriginY( textureBrowser, originy );
1163 void TextureBrowser_Tracking_MouseUp( TextureBrowser& textureBrowser ){
1164 textureBrowser.m_move_started = false;
1165 /* NetRadiantCustom did this instead:
1166 textureBrowser.m_freezePointer.unfreeze_pointer( textureBrowser.m_parent, false ); */
1167 textureBrowser.m_freezePointer.unfreeze_pointer( textureBrowser.m_gl_widget, false );
1170 void TextureBrowser_Tracking_MouseDown( TextureBrowser& textureBrowser ){
1171 if( textureBrowser.m_move_started ){
1172 TextureBrowser_Tracking_MouseUp( textureBrowser );
1174 textureBrowser.m_move_started = true;
1175 /* NetRadiantCustom did this instead:
1176 textureBrowser.m_freezePointer.freeze_pointer( textureBrowser.m_parent, textureBrowser.m_gl_widget, TextureBrowser_trackingDelta, &textureBrowser ); */
1177 textureBrowser.m_freezePointer.freeze_pointer( textureBrowser.m_gl_widget, TextureBrowser_trackingDelta, &textureBrowser );
1180 void TextureBrowser_Selection_MouseDown( TextureBrowser& textureBrowser, guint32 flags, int pointx, int pointy, bool texturizeSelection ){
1181 SelectTexture( textureBrowser, pointx, textureBrowser.height - 1 - pointy, flags, texturizeSelection );
1184 void TextureBrowser_Selection_MouseUp( TextureBrowser& textureBrowser, guint32 flags, int pointx, int pointy ){
1185 if ( ( flags & GDK_SHIFT_MASK ) != 0 ) {
1186 IShader* shader = Texture_At( textureBrowser, pointx, textureBrowser.height - 1 - pointy );
1187 if ( shader != 0 ) {
1188 if ( shader->IsDefault() ) {
1189 globalOutputStream() << "ERROR: " << shader->getName() << " is not a shader, it's a texture.\n";
1192 ViewShader( shader->getShaderFileName(), shader->getName(), ( flags & GDK_CONTROL_MASK ) != 0 );
1199 ============================================================================
1203 ============================================================================
1209 TTimo: relying on the shaders list to display the textures
1210 we must query all qtexture_t* to manage and display through the IShaders interface
1211 this allows a plugin to completely override the texture system
1214 void Texture_Draw( TextureBrowser& textureBrowser ){
1215 int originy = TextureBrowser_getOriginY( textureBrowser );
1217 glClearColor( textureBrowser.color_textureback[0],
1218 textureBrowser.color_textureback[1],
1219 textureBrowser.color_textureback[2],
1222 glViewport( 0, 0, textureBrowser.width, textureBrowser.height );
1223 glMatrixMode( GL_PROJECTION );
1226 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
1227 glDisable( GL_DEPTH_TEST );
1229 //glDisable( GL_BLEND );
1230 if ( g_TextureBrowser_enableAlpha ) {
1231 glEnable( GL_BLEND );
1232 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1235 glDisable( GL_BLEND );
1238 glOrtho( 0, textureBrowser.width, originy - textureBrowser.height, originy, -100, 100 );
1239 glEnable( GL_TEXTURE_2D );
1241 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
1243 int last_y = 0, last_height = 0;
1245 TextureLayout layout;
1246 Texture_StartPos( layout );
1247 for ( QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement() )
1249 IShader* shader = QERApp_ActiveShaders_IteratorCurrent();
1251 if ( !Texture_IsShown( shader, textureBrowser.m_showShaders, textureBrowser.m_showTextures, textureBrowser.m_hideUnused, textureBrowser.m_hideNonShadersInCommon ) ) {
1256 Texture_NextPos( textureBrowser, layout, shader->getTexture(), &x, &y );
1257 qtexture_t *q = shader->getTexture();
1262 int nWidth, nHeight;
1263 textureBrowser.getTextureWH( q, nWidth, nHeight );
1265 if ( y != last_y ) {
1269 last_height = std::max( nHeight, last_height );
1271 // Is this texture visible?
1272 if ( ( y - nHeight - TextureBrowser_fontHeight( textureBrowser ) < originy )
1273 && ( y > originy - textureBrowser.height ) ) {
1275 // if it's the current texture, draw a thick red line, else:
1276 // shaders have a white border, simple textures don't
1277 // if !texture_showinuse: (some textures displayed may not be in use)
1278 // draw an additional square around with 0.5 1 0.5 color
1280 const float xf = (float)x;
1281 const float yf = (float)( y - TextureBrowser_fontHeight( textureBrowser ) );
1282 float xfMax = xf + 1.5 + nWidth;
1283 float xfMin = xf - 1.5;
1284 float yfMax = yf + 1.5;
1285 float yfMin = yf - nHeight - 1.5;
1288 if ( shader_equal( TextureBrowser_GetSelectedShader( textureBrowser ), shader->getName() ) ) {
1290 if ( textureBrowser.m_rmbSelected ) {
1300 glDisable( GL_TEXTURE_2D );
1301 glBegin( GL_LINE_LOOP );
1302 glVertex2f( xfMin ,yfMax );
1303 glVertex2f( xfMin ,yfMin );
1304 glVertex2f( xfMax ,yfMin );
1305 glVertex2f( xfMax ,yfMax );
1307 glEnable( GL_TEXTURE_2D );
1309 // highlight in-use textures
1310 else if ( !textureBrowser.m_hideUnused && shader->IsInUse() ) {
1311 glColor3f( 0.5,1,0.5 );
1312 glDisable( GL_TEXTURE_2D );
1313 glBegin( GL_LINE_LOOP );
1314 glVertex2f( xfMin ,yfMax );
1315 glVertex2f( xfMin ,yfMin );
1316 glVertex2f( xfMax ,yfMin );
1317 glVertex2f( xfMax ,yfMax );
1319 glEnable( GL_TEXTURE_2D );
1321 // shader white border:
1322 else if ( !shader->IsDefault() ) {
1323 glColor3f( 1, 1, 1 );
1324 glDisable( GL_TEXTURE_2D );
1325 glBegin( GL_LINE_LOOP );
1326 glVertex2f( xfMin ,yfMax );
1327 glVertex2f( xfMin ,yfMin );
1328 glVertex2f( xfMax ,yfMin );
1329 glVertex2f( xfMax ,yfMax );
1331 glEnable( GL_TEXTURE_2D );
1335 if ( !shader->IsDefault() ) {
1336 glEnable( GL_LINE_STIPPLE );
1337 glLineStipple( 1, 0xF000 );
1338 glDisable( GL_TEXTURE_2D );
1339 glBegin( GL_LINE_LOOP );
1340 glColor3f( 0, 0, 0 );
1341 glVertex2f( xfMin ,yfMax );
1342 glVertex2f( xfMin ,yfMin );
1343 glVertex2f( xfMax ,yfMin );
1344 glVertex2f( xfMax ,yfMax );
1346 glDisable( GL_LINE_STIPPLE );
1347 glEnable( GL_TEXTURE_2D );
1350 // draw checkerboard for transparent textures
1351 if ( g_TextureBrowser_enableAlpha )
1353 glDisable( GL_TEXTURE_2D );
1354 glBegin( GL_QUADS );
1355 int font_height = TextureBrowser_fontHeight( textureBrowser );
1356 for ( int i = 0; i < nHeight; i += 8 )
1357 for ( int j = 0; j < nWidth; j += 8 )
1359 unsigned char color = (i + j) / 8 % 2 ? 0x66 : 0x99;
1360 glColor3ub( color, color, color );
1362 int right = std::min(j+8, nWidth);
1364 int bottom = std::min(i+8, nHeight);
1365 glVertex2i(x + right, y - nHeight - font_height + top);
1366 glVertex2i(x + left, y - nHeight - font_height + top);
1367 glVertex2i(x + left, y - nHeight - font_height + bottom);
1368 glVertex2i(x + right, y - nHeight - font_height + bottom);
1371 glEnable( GL_TEXTURE_2D );
1375 glBindTexture( GL_TEXTURE_2D, q->texture_number );
1376 GlobalOpenGL_debugAssertNoErrors();
1378 glBegin( GL_QUADS );
1379 glTexCoord2i( 0,0 );
1380 glVertex2i( x,y - TextureBrowser_fontHeight( textureBrowser ) );
1381 glTexCoord2i( 1,0 );
1382 glVertex2i( x + nWidth,y - TextureBrowser_fontHeight( textureBrowser ) );
1383 glTexCoord2i( 1,1 );
1384 glVertex2i( x + nWidth,y - TextureBrowser_fontHeight( textureBrowser ) - nHeight );
1385 glTexCoord2i( 0,1 );
1386 glVertex2i( x,y - TextureBrowser_fontHeight( textureBrowser ) - nHeight );
1389 // draw the texture name
1390 glDisable( GL_TEXTURE_2D );
1393 glRasterPos2i( x, y - TextureBrowser_fontHeight( textureBrowser ) + 2 );//+5
1395 // don't draw the directory name
1396 const char* name = shader->getName();
1397 name += strlen( name );
1398 while ( name != shader->getName() && *( name - 1 ) != '/' && *( name - 1 ) != '\\' )
1401 GlobalOpenGL().drawString( name );
1402 glEnable( GL_TEXTURE_2D );
1405 //int totalHeight = abs(y) + last_height + TextureBrowser_fontHeight(textureBrowser) + 4;
1409 // reset the current texture
1410 glBindTexture( GL_TEXTURE_2D, 0 );
1414 void TextureBrowser_queueDraw( TextureBrowser& textureBrowser ){
1415 if ( textureBrowser.m_gl_widget ) {
1416 gtk_widget_queue_draw( textureBrowser.m_gl_widget );
1421 void TextureBrowser_setScale( TextureBrowser& textureBrowser, std::size_t scale ){
1422 textureBrowser.m_textureScale = scale;
1424 textureBrowser.m_heightChanged = true;
1425 textureBrowser.m_originInvalid = true;
1426 g_activeShadersChangedCallbacks();
1428 TextureBrowser_queueDraw( textureBrowser );
1431 void TextureBrowser_setUniformSize( TextureBrowser& textureBrowser, std::size_t scale ){
1432 textureBrowser.m_uniformTextureSize = scale;
1434 textureBrowser.m_heightChanged = true;
1435 textureBrowser.m_originInvalid = true;
1436 g_activeShadersChangedCallbacks();
1438 TextureBrowser_queueDraw( textureBrowser );
1441 void TextureBrowser_setUniformMinSize( TextureBrowser& textureBrowser, std::size_t scale ){
1442 textureBrowser.m_uniformTextureMinSize = scale;
1444 textureBrowser.m_heightChanged = true;
1445 textureBrowser.m_originInvalid = true;
1446 g_activeShadersChangedCallbacks();
1448 TextureBrowser_queueDraw( textureBrowser );
1451 void TextureBrowser_MouseWheel( TextureBrowser& textureBrowser, bool bUp ){
1452 int originy = TextureBrowser_getOriginY( textureBrowser );
1455 originy += int(textureBrowser.m_mouseWheelScrollIncrement);
1459 originy -= int(textureBrowser.m_mouseWheelScrollIncrement);
1462 TextureBrowser_setOriginY( textureBrowser, originy );
1465 XmlTagBuilder TagBuilder;
1473 void BuildStoreAssignedTags( ui::ListStore store, const char* shader, TextureBrowser* textureBrowser ){
1478 std::vector<CopiedString> assigned_tags;
1479 TagBuilder.GetShaderTags( shader, assigned_tags );
1481 for ( size_t i = 0; i < assigned_tags.size(); i++ )
1483 store.append(TAG_COLUMN, assigned_tags[i].c_str());
1487 void BuildStoreAvailableTags( ui::ListStore storeAvailable,
1488 ui::ListStore storeAssigned,
1489 const std::set<CopiedString>& allTags,
1490 TextureBrowser* textureBrowser ){
1491 GtkTreeIter iterAssigned;
1492 GtkTreeIter iterAvailable;
1493 std::set<CopiedString>::const_iterator iterAll;
1494 gchar* tag_assigned;
1496 storeAvailable.clear();
1498 bool row = gtk_tree_model_get_iter_first(storeAssigned, &iterAssigned ) != 0;
1500 if ( !row ) { // does the shader have tags assigned?
1501 for ( iterAll = allTags.begin(); iterAll != allTags.end(); ++iterAll )
1503 storeAvailable.append(TAG_COLUMN, (*iterAll).c_str());
1508 while ( row ) // available tags = all tags - assigned tags
1510 gtk_tree_model_get(storeAssigned, &iterAssigned, TAG_COLUMN, &tag_assigned, -1 );
1512 for ( iterAll = allTags.begin(); iterAll != allTags.end(); ++iterAll )
1514 if ( strcmp( (char*)tag_assigned, ( *iterAll ).c_str() ) != 0 ) {
1515 storeAvailable.append(TAG_COLUMN, (*iterAll).c_str());
1519 row = gtk_tree_model_iter_next(storeAssigned, &iterAssigned ) != 0;
1522 gtk_tree_model_get(storeAssigned, &iterAssigned, TAG_COLUMN, &tag_assigned, -1 );
1530 gboolean TextureBrowser_button_press( ui::Widget widget, GdkEventButton* event, TextureBrowser* textureBrowser ){
1531 if ( event->type == GDK_BUTTON_PRESS ) {
1532 gtk_widget_grab_focus( widget );
1533 if ( event->button == 3 ) {
1534 if ( textureBrowser->m_tags ) {
1535 textureBrowser->m_rmbSelected = true;
1536 TextureBrowser_Selection_MouseDown( *textureBrowser, event->state, static_cast<int>( event->x ), static_cast<int>( event->y ), false );
1538 BuildStoreAssignedTags( textureBrowser->m_assigned_store, textureBrowser->shader.c_str(), textureBrowser );
1539 BuildStoreAvailableTags( textureBrowser->m_available_store, textureBrowser->m_assigned_store, textureBrowser->m_all_tags, textureBrowser );
1540 textureBrowser->m_heightChanged = true;
1541 textureBrowser->m_tag_frame.show();
1545 TextureBrowser_Focus( *textureBrowser, textureBrowser->shader.c_str() );
1549 TextureBrowser_Tracking_MouseDown( *textureBrowser );
1552 else if ( event->button == 1 || event->button == 2 ) {
1553 TextureBrowser_Selection_MouseDown( *textureBrowser, event->state, static_cast<int>( event->x ), static_cast<int>( event->y ), event->button == 2 );
1555 if ( textureBrowser->m_tags ) {
1556 textureBrowser->m_rmbSelected = false;
1557 textureBrowser->m_tag_frame.hide();
1561 else if ( event->type == GDK_2BUTTON_PRESS && event->button == 1 ) {
1562 #define GARUX_DISABLE_2BUTTON
1563 #ifndef GARUX_DISABLE_2BUTTON
1564 CopiedString texName = textureBrowser->shader;
1565 char* sh = const_cast<char*>( texName.c_str() );
1566 char* dir = strrchr( sh, '/' );
1569 dir = strchr( sh, '/' );
1573 ScopeDisableScreenUpdates disableScreenUpdates( dir, "Loading Textures" );
1574 TextureBrowser_ShowDirectory( *textureBrowser, dir );
1575 TextureBrowser_Focus( *textureBrowser, textureBrowser->shader.c_str() );
1576 TextureBrowser_queueDraw( *textureBrowser );
1582 else if ( event->type == GDK_2BUTTON_PRESS && event->button == 3 ) {
1583 ScopeDisableScreenUpdates disableScreenUpdates( TextureBrowser_getCommonShadersDir(), "Loading Textures" );
1584 TextureBrowser_ShowDirectory( *textureBrowser, TextureBrowser_getCommonShadersDir() );
1585 TextureBrowser_queueDraw( *textureBrowser );
1590 gboolean TextureBrowser_button_release( ui::Widget widget, GdkEventButton* event, TextureBrowser* textureBrowser ){
1591 if ( event->type == GDK_BUTTON_RELEASE ) {
1592 if ( event->button == 3 ) {
1593 if ( !textureBrowser->m_tags ) {
1594 TextureBrowser_Tracking_MouseUp( *textureBrowser );
1597 if ( event->button == 1 ) {
1598 TextureBrowser_Selection_MouseUp( *textureBrowser, event->state, static_cast<int>( event->x ), static_cast<int>( event->y ) );
1604 gboolean TextureBrowser_motion( ui::Widget widget, GdkEventMotion *event, TextureBrowser* textureBrowser ){
1608 gboolean TextureBrowser_scroll( ui::Widget widget, GdkEventScroll* event, TextureBrowser* textureBrowser ){
1609 gtk_widget_grab_focus( widget );
1610 if( !gtk_window_is_active( textureBrowser->m_parent ) )
1611 gtk_window_present( textureBrowser->m_parent );
1613 if ( event->direction == GDK_SCROLL_UP ) {
1614 TextureBrowser_MouseWheel( *textureBrowser, true );
1616 else if ( event->direction == GDK_SCROLL_DOWN ) {
1617 TextureBrowser_MouseWheel( *textureBrowser, false );
1622 void TextureBrowser_scrollChanged( void* data, gdouble value ){
1623 //globalOutputStream() << "vertical scroll\n";
1624 TextureBrowser_setOriginY( *reinterpret_cast<TextureBrowser*>( data ), -(int)value );
1627 static void TextureBrowser_verticalScroll(ui::Adjustment adjustment, TextureBrowser* textureBrowser ){
1628 textureBrowser->m_scrollAdjustment.value_changed( gtk_adjustment_get_value(adjustment) );
1631 void TextureBrowser_updateScroll( TextureBrowser& textureBrowser ){
1632 if ( textureBrowser.m_showTextureScrollbar ) {
1633 int totalHeight = TextureBrowser_TotalHeight( textureBrowser );
1635 totalHeight = std::max( totalHeight, textureBrowser.height );
1637 auto vadjustment = gtk_range_get_adjustment( GTK_RANGE( textureBrowser.m_texture_scroll ) );
1639 gtk_adjustment_set_value(vadjustment, -TextureBrowser_getOriginY( textureBrowser ));
1640 gtk_adjustment_set_page_size(vadjustment, textureBrowser.height);
1641 gtk_adjustment_set_page_increment(vadjustment, textureBrowser.height / 2);
1642 gtk_adjustment_set_step_increment(vadjustment, 20);
1643 gtk_adjustment_set_lower(vadjustment, 0);
1644 gtk_adjustment_set_upper(vadjustment, totalHeight);
1646 g_signal_emit_by_name( G_OBJECT( vadjustment ), "changed" );
1650 gboolean TextureBrowser_size_allocate( ui::Widget widget, GtkAllocation* allocation, TextureBrowser* textureBrowser ){
1651 textureBrowser->width = allocation->width;
1652 textureBrowser->height = allocation->height;
1653 TextureBrowser_heightChanged( *textureBrowser );
1654 textureBrowser->m_originInvalid = true;
1655 TextureBrowser_queueDraw( *textureBrowser );
1659 void TextureBrowser_redraw( TextureBrowser* textureBrowser ){
1660 if ( glwidget_make_current( textureBrowser->m_gl_widget ) != FALSE ) {
1661 GlobalOpenGL_debugAssertNoErrors();
1662 TextureBrowser_evaluateHeight( *textureBrowser );
1663 Texture_Draw( *textureBrowser );
1664 GlobalOpenGL_debugAssertNoErrors();
1665 glwidget_swap_buffers( textureBrowser->m_gl_widget );
1669 gboolean TextureBrowser_expose( ui::Widget widget, GdkEventExpose* event, TextureBrowser* textureBrowser ){
1670 TextureBrowser_redraw( textureBrowser );
1674 TextureBrowser& GlobalTextureBrowser(){
1675 static TextureBrowser textureBrowser;
1676 return textureBrowser;
1679 bool TextureBrowser_hideUnused(){
1680 return GlobalTextureBrowser().m_hideUnused;
1683 void TextureBrowser_ToggleHideUnused(){
1684 TextureBrowser &textureBrowser = GlobalTextureBrowser();
1685 if ( textureBrowser.m_hideUnused ) {
1686 TextureBrowser_SetHideUnused( textureBrowser, false );
1690 TextureBrowser_SetHideUnused( textureBrowser, true );
1694 const char* TextureGroups_transformDirName( const char* dirName, StringOutputStream *archiveName )
1696 if ( TextureBrowser_showWads() ) {
1697 archiveName->clear();
1698 *archiveName << StringRange( path_get_filename_start( dirName ), path_get_filename_base_end( dirName ) ) \
1699 << "." << path_get_extension( dirName );
1700 return archiveName->c_str();
1705 void TextureGroups_constructTreeModel( TextureGroups groups, ui::TreeStore store ){
1706 // put the information from the old textures menu into a treeview
1707 GtkTreeIter iter, child;
1709 TextureGroups::const_iterator i = groups.begin();
1710 while ( i != groups.end() )
1712 StringOutputStream archiveName;
1713 StringOutputStream nextArchiveName;
1714 const char* dirName = TextureGroups_transformDirName( ( *i ).c_str(), &archiveName );
1716 const char* firstUnderscore = strchr( dirName, '_' );
1717 StringRange dirRoot( dirName, ( firstUnderscore == 0 ) ? dirName : firstUnderscore + 1 );
1719 TextureGroups::const_iterator next = i;
1722 if ( firstUnderscore != 0
1723 && next != groups.end()
1724 && string_equal_start( TextureGroups_transformDirName( ( *next ).c_str(), &nextArchiveName ), dirRoot ) ) {
1725 gtk_tree_store_append( store, &iter, NULL );
1726 gtk_tree_store_set( store, &iter, 0, CopiedString( StringRange( dirName, firstUnderscore ) ).c_str(), -1 );
1729 while ( i != groups.end() && string_equal_start( TextureGroups_transformDirName( ( *i ).c_str(), &nextArchiveName ), dirRoot ) )
1731 gtk_tree_store_append( store, &child, &iter );
1732 gtk_tree_store_set( store, &child, 0, TextureGroups_transformDirName( ( *i ).c_str(), &nextArchiveName ), -1 );
1738 gtk_tree_store_append( store, &iter, NULL );
1739 gtk_tree_store_set( store, &iter, 0, dirName, -1 );
1745 TextureGroups TextureGroups_constructTreeView(){
1746 TextureGroups groups;
1748 if ( TextureBrowser_showWads() ) {
1749 GlobalFileSystem().forEachArchive( TextureGroupsAddWadCaller( groups ) );
1753 // scan texture dirs and pak files only if not restricting to shaderlist
1754 if ( g_pGameDescription->mGameType != "doom3" && !g_TextureBrowser_shaderlistOnly ) {
1755 GlobalFileSystem().forEachDirectory( "textures/", TextureGroupsAddDirectoryCaller( groups ) );
1758 GlobalShaderSystem().foreachShaderName( TextureGroupsAddShaderCaller( groups ) );
1764 void TextureBrowser_constructTreeStore(){
1765 TextureGroups groups = TextureGroups_constructTreeView();
1766 auto store = ui::TreeStore::from(gtk_tree_store_new( 1, G_TYPE_STRING ));
1767 TextureGroups_constructTreeModel( groups, store );
1768 std::set<CopiedString>::iterator iter;
1770 gtk_tree_view_set_model(GlobalTextureBrowser().m_treeViewTree, store);
1772 g_object_unref( G_OBJECT( store ) );
1775 void TextureBrowser_constructTreeStoreTags(){
1776 //TextureGroups groups;
1777 TextureBrowser &textureBrowser = GlobalTextureBrowser();
1778 auto store = ui::TreeStore::from(gtk_tree_store_new( 1, G_TYPE_STRING ));
1779 auto model = GlobalTextureBrowser().m_all_tags_list;
1781 gtk_tree_view_set_model(GlobalTextureBrowser().m_treeViewTags, model );
1783 g_object_unref( G_OBJECT( store ) );
1786 void TreeView_onRowActivated( ui::TreeView treeview, ui::TreePath path, ui::TreeViewColumn col, gpointer userdata ){
1789 auto model = gtk_tree_view_get_model(treeview );
1791 if ( gtk_tree_model_get_iter( model, &iter, path ) ) {
1792 gchar dirName[1024];
1795 gtk_tree_model_get( model, &iter, 0, &buffer, -1 );
1796 strcpy( dirName, buffer );
1799 GlobalTextureBrowser().m_searchedTags = false;
1801 if ( !TextureBrowser_showWads() ) {
1802 strcat( dirName, "/" );
1805 ScopeDisableScreenUpdates disableScreenUpdates( dirName, "Loading Textures" );
1806 TextureBrowser_ShowDirectory( GlobalTextureBrowser(), dirName );
1807 TextureBrowser_queueDraw( GlobalTextureBrowser() );
1808 //deactivate, so SPACE and RETURN wont be broken for 2d
1809 gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( treeview ) ) ), NULL );
1813 void TextureBrowser_createTreeViewTree(){
1814 TextureBrowser &textureBrowser = GlobalTextureBrowser();
1815 gtk_tree_view_set_enable_search(textureBrowser.m_treeViewTree, FALSE );
1817 gtk_tree_view_set_headers_visible(textureBrowser.m_treeViewTree, FALSE );
1818 textureBrowser.m_treeViewTree.connect( "row-activated", (GCallback) TreeView_onRowActivated, NULL );
1820 auto renderer = ui::CellRendererText(ui::New);
1821 gtk_tree_view_insert_column_with_attributes(textureBrowser.m_treeViewTree, -1, "", renderer, "text", 0, NULL );
1823 TextureBrowser_constructTreeStore();
1826 void TextureBrowser_addTag();
1828 void TextureBrowser_renameTag();
1830 void TextureBrowser_deleteTag();
1832 void TextureBrowser_createContextMenu( ui::Widget treeview, GdkEventButton *event ){
1833 ui::Widget menu = ui::Menu(ui::New);
1835 ui::Widget menuitem = ui::MenuItem( "Add tag" );
1836 menuitem.connect( "activate", (GCallback)TextureBrowser_addTag, treeview );
1837 gtk_menu_shell_append( GTK_MENU_SHELL( menu ), menuitem );
1839 menuitem = ui::MenuItem( "Rename tag" );
1840 menuitem.connect( "activate", (GCallback)TextureBrowser_renameTag, treeview );
1841 gtk_menu_shell_append( GTK_MENU_SHELL( menu ), menuitem );
1843 menuitem = ui::MenuItem( "Delete tag" );
1844 menuitem.connect( "activate", (GCallback)TextureBrowser_deleteTag, treeview );
1845 gtk_menu_shell_append( GTK_MENU_SHELL( menu ), menuitem );
1847 gtk_widget_show_all( menu );
1849 gtk_menu_popup( GTK_MENU( menu ), NULL, NULL, NULL, NULL,
1850 ( event != NULL ) ? event->button : 0,
1851 gdk_event_get_time( (GdkEvent*)event ) );
1854 void TextureBrowser_searchTags();
1856 gboolean TreeViewTags_onButtonPressed( ui::TreeView treeview, GdkEventButton *event ){
1857 if ( event->type == GDK_BUTTON_PRESS && event->button == 3 ) {
1859 auto selection = gtk_tree_view_get_selection(treeview );
1861 if ( gtk_tree_view_get_path_at_pos(treeview, event->x, event->y, &path, NULL, NULL, NULL ) ) {
1862 gtk_tree_selection_unselect_all( selection );
1863 gtk_tree_selection_select_path( selection, path );
1864 gtk_tree_path_free( path );
1867 TextureBrowser_createContextMenu( treeview, event );
1870 if( event->type == GDK_2BUTTON_PRESS && event->button == 1 ){
1871 TextureBrowser_searchTags();
1877 void TextureBrowser_createTreeViewTags(){
1878 TextureBrowser &textureBrowser = GlobalTextureBrowser();
1879 textureBrowser.m_treeViewTags = ui::TreeView(ui::New);
1880 gtk_tree_view_set_enable_search(textureBrowser.m_treeViewTags, FALSE );
1882 textureBrowser.m_treeViewTags.connect( "button-press-event", (GCallback)TreeViewTags_onButtonPressed, NULL );
1884 gtk_tree_view_set_headers_visible(textureBrowser.m_treeViewTags, FALSE );
1886 auto renderer = ui::CellRendererText(ui::New);
1887 gtk_tree_view_insert_column_with_attributes(textureBrowser.m_treeViewTags, -1, "", renderer, "text", 0, NULL );
1889 TextureBrowser_constructTreeStoreTags();
1892 ui::MenuItem TextureBrowser_constructViewMenu( ui::Menu menu ){
1893 TextureBrowser &textureBrowser = GlobalTextureBrowser();
1894 ui::MenuItem textures_menu_item = ui::MenuItem(new_sub_menu_item_with_mnemonic( "_View" ));
1896 if ( g_Layout_enableDetachableMenus.m_value ) {
1897 menu_tearoff( menu );
1900 create_check_menu_item_with_mnemonic( menu, "Hide _Unused", "ShowInUse" );
1901 create_menu_item_with_mnemonic( menu, "Show All", "ShowAllTextures" );
1903 if ( string_empty( g_pGameDescription->getKeyValue( "show_wads" ) ) ) {
1904 create_check_menu_item_with_mnemonic( menu, "Hide Image Missing", "FilterMissing" );
1907 // hide notex and shadernotex on texture browser: no one wants to apply them
1908 create_check_menu_item_with_mnemonic( menu, "Hide Fallback", "FilterFallback" );
1910 menu_separator( menu );
1913 // we always want to show shaders but don't want a "Show Shaders" menu for doom3 and .wad file games
1914 if ( g_pGameDescription->mGameType == "doom3" || TextureBrowser_showWads() ) {
1915 textureBrowser.m_showShaders = true;
1919 create_check_menu_item_with_mnemonic( menu, "Show shaders", "ToggleShowShaders" );
1920 create_check_menu_item_with_mnemonic( menu, "Show textures", "ToggleShowTextures" );
1921 menu_separator( menu );
1924 if ( textureBrowser.m_tags ) {
1925 create_menu_item_with_mnemonic( menu, "Show Untagged", "ShowUntagged" );
1927 if ( g_pGameDescription->mGameType != "doom3" && string_empty( g_pGameDescription->getKeyValue( "show_wads" ) ) ) {
1928 create_check_menu_item_with_mnemonic( menu, "ShaderList Only", "ToggleShowShaderlistOnly" );
1931 menu_separator( menu );
1932 create_check_menu_item_with_mnemonic( menu, "Fixed Size", "FixedSize" );
1933 create_check_menu_item_with_mnemonic( menu, "Transparency", "EnableAlpha" );
1935 if ( string_empty( g_pGameDescription->getKeyValue( "show_wads" ) ) ) {
1936 menu_separator( menu );
1937 textureBrowser.m_shader_info_item = ui::Widget(create_menu_item_with_mnemonic( menu, "Shader Info", "ShaderInfo" ));
1938 gtk_widget_set_sensitive( textureBrowser.m_shader_info_item, FALSE );
1942 return textures_menu_item;
1945 void Popup_View_Menu( GtkWidget *widget, GtkMenu *menu ){
1946 gtk_menu_popup( menu, NULL, NULL, NULL, NULL, 1, gtk_get_current_event_time() );
1949 ui::MenuItem TextureBrowser_constructToolsMenu( ui::Menu menu ){
1950 ui::MenuItem textures_menu_item = ui::MenuItem(new_sub_menu_item_with_mnemonic( "_Tools" ));
1952 if ( g_Layout_enableDetachableMenus.m_value ) {
1953 menu_tearoff( menu );
1956 create_menu_item_with_mnemonic( menu, "Flush & Reload Shaders", "RefreshShaders" );
1957 create_menu_item_with_mnemonic( menu, "Find / Replace...", "FindReplaceTextures" );
1959 return textures_menu_item;
1962 ui::MenuItem TextureBrowser_constructTagsMenu( ui::Menu menu ){
1963 ui::MenuItem textures_menu_item = ui::MenuItem(new_sub_menu_item_with_mnemonic( "T_ags" ));
1965 if ( g_Layout_enableDetachableMenus.m_value ) {
1966 menu_tearoff( menu );
1969 create_menu_item_with_mnemonic( menu, "Add tag", "AddTag" );
1970 create_menu_item_with_mnemonic( menu, "Rename tag", "RenameTag" );
1971 create_menu_item_with_mnemonic( menu, "Delete tag", "DeleteTag" );
1972 menu_separator( menu );
1973 create_menu_item_with_mnemonic( menu, "Copy tags from selected", "CopyTag" );
1974 create_menu_item_with_mnemonic( menu, "Paste tags to selected", "PasteTag" );
1976 return textures_menu_item;
1979 gboolean TextureBrowser_tagMoveHelper( ui::TreeModel model, ui::TreePath path, GtkTreeIter* iter, GSList** selected ){
1980 g_assert( selected != NULL );
1982 auto rowref = gtk_tree_row_reference_new( model, path );
1983 *selected = g_slist_append( *selected, rowref );
1988 void TextureBrowser_assignTags(){
1989 GSList* selected = NULL;
1991 gchar* tag_assigned;
1992 TextureBrowser &textureBrowser = GlobalTextureBrowser();
1994 auto selection = gtk_tree_view_get_selection(textureBrowser.m_available_tree );
1996 gtk_tree_selection_selected_foreach( selection, (GtkTreeSelectionForeachFunc)TextureBrowser_tagMoveHelper, &selected );
1998 if ( selected != NULL ) {
1999 for ( node = selected; node != NULL; node = node->next )
2001 auto path = gtk_tree_row_reference_get_path( (GtkTreeRowReference*)node->data );
2006 if ( gtk_tree_model_get_iter(textureBrowser.m_available_store, &iter, path ) ) {
2007 gtk_tree_model_get(textureBrowser.m_available_store, &iter, TAG_COLUMN, &tag_assigned, -1 );
2008 if ( !TagBuilder.CheckShaderTag( textureBrowser.shader.c_str() ) ) {
2009 // create a custom shader/texture entry
2010 IShader* ishader = QERApp_Shader_ForName( textureBrowser.shader.c_str() );
2011 CopiedString filename = ishader->getShaderFileName();
2013 if ( filename.empty() ) {
2015 TagBuilder.AddShaderNode( textureBrowser.shader.c_str(), CUSTOM, TEXTURE );
2019 TagBuilder.AddShaderNode( textureBrowser.shader.c_str(), CUSTOM, SHADER );
2023 TagBuilder.AddShaderTag( textureBrowser.shader.c_str(), (char*)tag_assigned, TAG );
2025 gtk_list_store_remove( textureBrowser.m_available_store, &iter );
2026 textureBrowser.m_assigned_store.append(TAG_COLUMN, tag_assigned);
2031 g_slist_foreach( selected, (GFunc)gtk_tree_row_reference_free, NULL );
2034 TagBuilder.SaveXmlDoc();
2036 g_slist_free( selected );
2039 void TextureBrowser_removeTags(){
2040 GSList* selected = NULL;
2043 TextureBrowser &textureBrowser = GlobalTextureBrowser();
2045 auto selection = gtk_tree_view_get_selection(textureBrowser.m_assigned_tree );
2047 gtk_tree_selection_selected_foreach( selection, (GtkTreeSelectionForeachFunc)TextureBrowser_tagMoveHelper, &selected );
2049 if ( selected != NULL ) {
2050 for ( node = selected; node != NULL; node = node->next )
2052 auto path = gtk_tree_row_reference_get_path( (GtkTreeRowReference*)node->data );
2057 if ( gtk_tree_model_get_iter(textureBrowser.m_assigned_store, &iter, path ) ) {
2058 gtk_tree_model_get(textureBrowser.m_assigned_store, &iter, TAG_COLUMN, &tag, -1 );
2059 TagBuilder.DeleteShaderTag( textureBrowser.shader.c_str(), tag );
2060 gtk_list_store_remove( textureBrowser.m_assigned_store, &iter );
2065 g_slist_foreach( selected, (GFunc)gtk_tree_row_reference_free, NULL );
2067 // Update the "available tags list"
2068 BuildStoreAvailableTags( textureBrowser.m_available_store, textureBrowser.m_assigned_store, textureBrowser.m_all_tags, &textureBrowser );
2071 TagBuilder.SaveXmlDoc();
2073 g_slist_free( selected );
2076 void TextureBrowser_buildTagList(){
2077 TextureBrowser &textureBrowser = GlobalTextureBrowser();
2078 textureBrowser.m_all_tags_list.clear();
2080 std::set<CopiedString>::iterator iter;
2082 for ( iter = textureBrowser.m_all_tags.begin(); iter != textureBrowser.m_all_tags.end(); ++iter )
2084 textureBrowser.m_all_tags_list.append(TAG_COLUMN, (*iter).c_str());
2088 void TextureBrowser_searchTags(){
2089 GSList* selected = NULL;
2093 char tags_searched[256];
2094 TextureBrowser &textureBrowser = GlobalTextureBrowser();
2096 auto selection = gtk_tree_view_get_selection(textureBrowser.m_treeViewTags );
2098 gtk_tree_selection_selected_foreach( selection, (GtkTreeSelectionForeachFunc)TextureBrowser_tagMoveHelper, &selected );
2100 if ( selected != NULL ) {
2101 strcpy( buffer, "/root/*/*[tag='" );
2102 strcpy( tags_searched, "[TAGS] " );
2104 for ( node = selected; node != NULL; node = node->next )
2106 auto path = gtk_tree_row_reference_get_path( (GtkTreeRowReference*)node->data );
2111 if ( gtk_tree_model_get_iter(textureBrowser.m_all_tags_list, &iter, path ) ) {
2112 gtk_tree_model_get(textureBrowser.m_all_tags_list, &iter, TAG_COLUMN, &tag, -1 );
2114 strcat( buffer, tag );
2115 strcat( tags_searched, tag );
2116 if ( node != g_slist_last( node ) ) {
2117 strcat( buffer, "' and tag='" );
2118 strcat( tags_searched, ", " );
2124 strcat( buffer, "']" );
2126 g_slist_foreach( selected, (GFunc)gtk_tree_row_reference_free, NULL );
2128 textureBrowser.m_found_shaders.clear(); // delete old list
2129 TagBuilder.TagSearch( buffer, textureBrowser.m_found_shaders );
2131 if ( !textureBrowser.m_found_shaders.empty() ) { // found something
2132 size_t shaders_found = textureBrowser.m_found_shaders.size();
2134 globalOutputStream() << "Found " << (unsigned int)shaders_found << " textures and shaders with " << tags_searched << "\n";
2135 ScopeDisableScreenUpdates disableScreenUpdates( "Searching...", "Loading Textures" );
2137 std::set<CopiedString>::iterator iter;
2139 for ( iter = textureBrowser.m_found_shaders.begin(); iter != textureBrowser.m_found_shaders.end(); iter++ )
2141 std::string path = ( *iter ).c_str();
2142 size_t pos = path.find_last_of( "/", path.size() );
2143 std::string name = path.substr( pos + 1, path.size() );
2144 path = path.substr( 0, pos + 1 );
2145 TextureDirectory_loadTexture( path.c_str(), name.c_str() );
2148 TextureBrowser_SetHideUnused( textureBrowser, false );
2149 textureBrowser.m_searchedTags = true;
2150 g_TextureBrowser_currentDirectory = tags_searched;
2152 textureBrowser.m_nTotalHeight = 0;
2153 TextureBrowser_setOriginY( textureBrowser, 0 );
2154 TextureBrowser_heightChanged( textureBrowser );
2155 TextureBrowser_updateTitle();
2157 g_slist_free( selected );
2160 void TextureBrowser_toggleSearchButton(){
2161 TextureBrowser &textureBrowser = GlobalTextureBrowser();
2162 gint page = gtk_notebook_get_current_page( GTK_NOTEBOOK( textureBrowser.m_tag_notebook ) );
2164 if ( page == 0 ) { // tag page
2165 gtk_widget_show_all( textureBrowser.m_search_button );
2168 textureBrowser.m_search_button.hide();
2172 void TextureBrowser_constructTagNotebook(){
2173 TextureBrowser &textureBrowser = GlobalTextureBrowser();
2174 textureBrowser.m_tag_notebook = ui::Widget::from(gtk_notebook_new());
2175 ui::Widget labelTags = ui::Label( "Tags" );
2176 ui::Widget labelTextures = ui::Label( "Textures" );
2178 gtk_notebook_append_page( GTK_NOTEBOOK( textureBrowser.m_tag_notebook ), textureBrowser.m_scr_win_tree, labelTextures );
2179 gtk_notebook_append_page( GTK_NOTEBOOK( textureBrowser.m_tag_notebook ), textureBrowser.m_scr_win_tags, labelTags );
2181 textureBrowser.m_tag_notebook.connect( "switch-page", G_CALLBACK( TextureBrowser_toggleSearchButton ), NULL );
2183 gtk_widget_show_all( textureBrowser.m_tag_notebook );
2186 void TextureBrowser_constructSearchButton(){
2187 auto image = ui::Widget::from(gtk_image_new_from_stock( GTK_STOCK_FIND, GTK_ICON_SIZE_SMALL_TOOLBAR ));
2188 TextureBrowser &textureBrowser = GlobalTextureBrowser();
2189 textureBrowser.m_search_button = ui::Button(ui::New);
2190 textureBrowser.m_search_button.connect( "clicked", G_CALLBACK( TextureBrowser_searchTags ), NULL );
2191 gtk_widget_set_tooltip_text(textureBrowser.m_search_button, "Search with selected tags");
2192 textureBrowser.m_search_button.add(image);
2195 void TextureBrowser_checkTagFile(){
2196 const char SHADERTAG_FILE[] = "shadertags.xml";
2197 CopiedString default_filename, rc_filename;
2198 StringOutputStream stream( 256 );
2199 TextureBrowser &textureBrowser = GlobalTextureBrowser();
2201 stream << LocalRcPath_get();
2202 stream << SHADERTAG_FILE;
2203 rc_filename = stream.c_str();
2205 if ( file_exists( rc_filename.c_str() ) ) {
2206 textureBrowser.m_tags = TagBuilder.OpenXmlDoc( rc_filename.c_str() );
2208 if ( textureBrowser.m_tags ) {
2209 globalOutputStream() << "Loading tag file " << rc_filename.c_str() << ".\n";
2214 // load default tagfile
2216 stream << g_pGameDescription->mGameToolsPath.c_str();
2217 stream << SHADERTAG_FILE;
2218 default_filename = stream.c_str();
2220 if ( file_exists( default_filename.c_str() ) ) {
2221 textureBrowser.m_tags = TagBuilder.OpenXmlDoc( default_filename.c_str(), rc_filename.c_str() );
2223 if ( textureBrowser.m_tags ) {
2224 globalOutputStream() << "Loading default tag file " << default_filename.c_str() << ".\n";
2229 globalOutputStream() << "Unable to find default tag file " << default_filename.c_str() << ". No tag support. Plugins -> ShaderPlug -> Create tag file: to start using tags\n";
2234 void TextureBrowser_SetNotex(){
2235 IShader* notex = QERApp_Shader_ForName( DEFAULT_NOTEX_NAME );
2236 IShader* shadernotex = QERApp_Shader_ForName( DEFAULT_SHADERNOTEX_NAME );
2238 g_notex = notex->getTexture()->name;
2240 g_shadernotex = shadernotex->getTexture()->name;
2243 shadernotex->DecRef();
2246 static bool isGLWidgetConstructed = false;
2247 static bool isWindowConstructed = false;
2249 void TextureBrowser_constructGLWidget(){
2250 TextureBrowser &textureBrowser = GlobalTextureBrowser();
2251 textureBrowser.m_gl_widget = glwidget_new( FALSE );
2252 g_object_ref( textureBrowser.m_gl_widget._handle );
2254 gtk_widget_set_events( textureBrowser.m_gl_widget, GDK_DESTROY | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_SCROLL_MASK );
2255 gtk_widget_set_can_focus( textureBrowser.m_gl_widget, true );
2257 textureBrowser.m_sizeHandler = textureBrowser.m_gl_widget.connect( "size_allocate", G_CALLBACK( TextureBrowser_size_allocate ), &textureBrowser );
2258 textureBrowser.m_exposeHandler = textureBrowser.m_gl_widget.on_render( G_CALLBACK( TextureBrowser_expose ), &textureBrowser );
2260 textureBrowser.m_gl_widget.connect( "button_press_event", G_CALLBACK( TextureBrowser_button_press ), &textureBrowser );
2261 textureBrowser.m_gl_widget.connect( "button_release_event", G_CALLBACK( TextureBrowser_button_release ), &textureBrowser );
2262 textureBrowser.m_gl_widget.connect( "motion_notify_event", G_CALLBACK( TextureBrowser_motion ), &textureBrowser );
2263 textureBrowser.m_gl_widget.connect( "scroll_event", G_CALLBACK( TextureBrowser_scroll ), &textureBrowser );
2265 #ifdef WORKAROUND_MACOS_GTK2_GLWIDGET
2266 textureBrowser.m_hframe.pack_start( textureBrowser.m_gl_widget, TRUE, TRUE, 0 );
2267 #else // !WORKAROUND_MACOS_GTK2_GLWIDGET
2268 textureBrowser.m_frame.pack_start( textureBrowser.m_gl_widget, TRUE, TRUE, 0 );
2269 #endif // !WORKAROUND_MACOS_GTK2_GLWIDGET
2271 textureBrowser.m_gl_widget.show();
2273 isGLWidgetConstructed = true;
2276 ui::Widget TextureBrowser_constructWindow( ui::Window toplevel ){
2277 // The gl_widget and the tag assignment frame should be packed into a GtkVPaned with the slider
2278 // position stored in local.pref. gtk_paned_get_position() and gtk_paned_set_position() don't
2279 // seem to work in gtk 2.4 and the arrow buttons don't handle GTK_FILL, so here's another thing
2280 // for the "once-the-gtk-libs-are-updated-TODO-list" :x
2281 TextureBrowser &textureBrowser = GlobalTextureBrowser();
2283 TextureBrowser_checkTagFile();
2284 TextureBrowser_SetNotex();
2286 GlobalShaderSystem().setActiveShadersChangedNotify( ReferenceCaller<TextureBrowser, void(), TextureBrowser_activeShadersChanged>( textureBrowser ) );
2288 textureBrowser.m_parent = toplevel;
2290 auto table = ui::Table(3, 3, FALSE);
2291 auto vbox = ui::VBox(FALSE, 0);
2292 table.attach(vbox, {0, 1, 1, 3}, {GTK_FILL, GTK_FILL});
2295 // ui::Widget menu_bar{ui::null};
2296 auto toolbar = ui::Toolbar::from( gtk_toolbar_new() );
2299 // menu_bar = ui::Widget::from(gtk_menu_bar_new());
2300 auto menu_view = ui::Menu(ui::New);
2301 // auto view_item = TextureBrowser_constructViewMenu( menu_view );
2302 TextureBrowser_constructViewMenu( menu_view );
2303 gtk_menu_set_title( menu_view, "View" );
2304 // gtk_menu_item_set_submenu( GTK_MENU_ITEM( view_item ), menu_view );
2305 // gtk_menu_shell_append( GTK_MENU_SHELL( menu_bar ), view_item );
2307 //gtk_table_attach( GTK_TABLE( table ), GTK_WIDGET( toolbar ), 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0 );
2308 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( toolbar ), FALSE, FALSE, 0 );
2312 auto button = toolbar_append_button( toolbar, "View", "texbro_view.png" );
2313 button.dimensions( 22, 22 );
2314 button.connect( "clicked", G_CALLBACK( Popup_View_Menu ), menu_view );
2316 //to show detached menu over floating tex bro
2317 gtk_menu_attach_to_widget( GTK_MENU( menu_view ), GTK_WIDGET( button ), NULL );
2320 auto button = toolbar_append_button( toolbar, "Find / Replace...", "texbro_gtk-find-and-replace.png", "FindReplaceTextures" );
2321 button.dimensions( 22, 22 );
2324 auto button = toolbar_append_button( toolbar, "Flush & Reload Shaders", "texbro_refresh.png", "RefreshShaders" );
2325 button.dimensions( 22, 22 );
2330 auto menu_tools = ui::Menu(ui::New);
2331 auto tools_item = TextureBrowser_constructToolsMenu( menu_tools );
2332 gtk_menu_item_set_submenu( GTK_MENU_ITEM( tools_item ), menu_tools );
2333 gtk_menu_shell_append( GTK_MENU_SHELL( menu_bar ), tools_item );
2335 // table.attach(menu_bar, {0, 3, 0, 1}, {GTK_FILL, GTK_SHRINK});
2338 { // Texture TreeView
2339 textureBrowser.m_scr_win_tree = ui::ScrolledWindow(ui::New);
2340 gtk_container_set_border_width( GTK_CONTAINER( textureBrowser.m_scr_win_tree ), 0 );
2342 // vertical only scrolling for treeview
2343 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( textureBrowser.m_scr_win_tree ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
2345 textureBrowser.m_scr_win_tree.show();
2347 TextureBrowser_createTreeViewTree();
2349 //gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW( textureBrowser.m_scr_win_tree ), textureBrowser.m_treeViewTree );
2350 gtk_container_add( GTK_CONTAINER( textureBrowser.m_scr_win_tree ), GTK_WIDGET( textureBrowser.m_treeViewTree ) );
2352 textureBrowser.m_treeViewTree.show();
2354 { // gl_widget scrollbar
2355 auto w = ui::Widget::from(gtk_vscrollbar_new( ui::Adjustment( 0,0,0,1,1,0 ) ));
2356 table.attach(w, {2, 3, 1, 2}, {GTK_SHRINK, GTK_FILL});
2358 textureBrowser.m_texture_scroll = w;
2360 auto vadjustment = ui::Adjustment::from(gtk_range_get_adjustment( GTK_RANGE( textureBrowser.m_texture_scroll ) ));
2361 vadjustment.connect( "value_changed", G_CALLBACK( TextureBrowser_verticalScroll ), &textureBrowser );
2363 textureBrowser.m_texture_scroll.visible(textureBrowser.m_showTextureScrollbar);
2366 #ifdef WORKAROUND_MACOS_GTK2_GLWIDGET
2367 textureBrowser.m_vframe = ui::VBox( FALSE, 0 );
2368 table.attach(textureBrowser.m_vframe, {1, 2, 1, 2});
2370 textureBrowser.m_vfiller = ui::VBox( FALSE, 0 );
2371 textureBrowser.m_vframe.pack_start( textureBrowser.m_vfiller, FALSE, FALSE, 0 );
2373 textureBrowser.m_hframe = ui::HBox( FALSE, 0 );
2374 textureBrowser.m_vframe.pack_start( textureBrowser.m_hframe, TRUE, TRUE, 0 );
2376 textureBrowser.m_hfiller = ui::HBox( FALSE, 0 );
2377 textureBrowser.m_hframe.pack_start( textureBrowser.m_hfiller, FALSE, FALSE, 0 );
2379 textureBrowser.m_vframe.show();
2380 textureBrowser.m_vfiller.show();
2381 textureBrowser.m_hframe.show(),
2382 textureBrowser.m_hfiller.show();
2383 #else // !WORKAROUND_MACOS_GTK2_GLWIDGET
2384 textureBrowser.m_frame = ui::VBox( FALSE, 0 );
2385 table.attach(textureBrowser.m_frame, {1, 2, 1, 2});
2386 textureBrowser.m_frame.show();
2387 #endif // !WORKAROUND_MACOS_GTK2_GLWIDGET
2389 TextureBrowser_constructGLWidget();
2393 if ( textureBrowser.m_tags ) {
2394 { // fill tag GtkListStore
2395 textureBrowser.m_all_tags_list = ui::ListStore::from(gtk_list_store_new( N_COLUMNS, G_TYPE_STRING ));
2396 auto sortable = GTK_TREE_SORTABLE( textureBrowser.m_all_tags_list );
2397 gtk_tree_sortable_set_sort_column_id( sortable, TAG_COLUMN, GTK_SORT_ASCENDING );
2399 TagBuilder.GetAllTags( textureBrowser.m_all_tags );
2400 TextureBrowser_buildTagList();
2403 auto menu_tags = ui::Menu(ui::New);
2404 gtk_menu_set_title( GTK_MENU( menu_tags ), "Tags" );
2405 // auto tags_item = TextureBrowser_constructTagsMenu( menu_tags );
2406 TextureBrowser_constructTagsMenu( menu_tags );
2407 // gtk_menu_item_set_submenu( GTK_MENU_ITEM( tags_item ), menu_tags );
2408 // gtk_menu_shell_append( GTK_MENU_SHELL( menu_bar ), tags_item );
2410 auto button = toolbar_append_button( toolbar, "Tags", "texbro_tags.png" );
2411 button.dimensions( 22, 22 );
2412 button.connect( "clicked", G_CALLBACK( Popup_View_Menu ), menu_tags );
2414 //to show detached menu over floating tex bro and main wnd...
2415 gtk_menu_attach_to_widget( GTK_MENU( menu_tags ), GTK_WIDGET( button ), NULL );
2418 textureBrowser.m_scr_win_tags = ui::ScrolledWindow(ui::New);
2419 gtk_container_set_border_width( GTK_CONTAINER( textureBrowser.m_scr_win_tags ), 0 );
2421 // vertical only scrolling for treeview
2422 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( textureBrowser.m_scr_win_tags ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
2424 TextureBrowser_createTreeViewTags();
2426 auto selection = gtk_tree_view_get_selection(textureBrowser.m_treeViewTags );
2427 gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE );
2429 //gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW( textureBrowser.m_scr_win_tags ), textureBrowser.m_treeViewTags );
2430 gtk_container_add( GTK_CONTAINER( textureBrowser.m_scr_win_tags ), GTK_WIDGET( textureBrowser.m_treeViewTags ) );
2432 textureBrowser.m_treeViewTags.show();
2434 { // Texture/Tag notebook
2435 TextureBrowser_constructTagNotebook();
2436 vbox.pack_start( textureBrowser.m_tag_notebook, TRUE, TRUE, 0 );
2438 { // Tag search button
2439 TextureBrowser_constructSearchButton();
2440 vbox.pack_end(textureBrowser.m_search_button, FALSE, FALSE, 0);
2442 auto frame_table = ui::Table(3, 3, FALSE);
2445 textureBrowser.m_tag_frame = ui::Frame( "Tag assignment" );
2446 gtk_frame_set_label_align( GTK_FRAME( textureBrowser.m_tag_frame ), 0.5, 0.5 );
2447 gtk_frame_set_shadow_type( GTK_FRAME( textureBrowser.m_tag_frame ), GTK_SHADOW_NONE );
2449 table.attach(textureBrowser.m_tag_frame, {1, 3, 2, 3}, {GTK_FILL, GTK_SHRINK});
2453 textureBrowser.m_tag_frame.add(frame_table);
2455 { // assigned tag list
2456 ui::Widget scrolled_win = ui::ScrolledWindow(ui::New);
2457 gtk_container_set_border_width( GTK_CONTAINER( scrolled_win ), 0 );
2458 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scrolled_win ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
2460 textureBrowser.m_assigned_store = ui::ListStore::from(gtk_list_store_new( N_COLUMNS, G_TYPE_STRING ));
2462 auto sortable = GTK_TREE_SORTABLE( textureBrowser.m_assigned_store );
2463 gtk_tree_sortable_set_sort_column_id( sortable, TAG_COLUMN, GTK_SORT_ASCENDING );
2465 auto renderer = ui::CellRendererText(ui::New);
2467 textureBrowser.m_assigned_tree = ui::TreeView(ui::TreeModel::from(textureBrowser.m_assigned_store._handle));
2468 textureBrowser.m_assigned_store.unref();
2469 textureBrowser.m_assigned_tree.connect( "row-activated", (GCallback) TextureBrowser_removeTags, NULL );
2470 gtk_tree_view_set_headers_visible(textureBrowser.m_assigned_tree, FALSE );
2472 auto selection = gtk_tree_view_get_selection(textureBrowser.m_assigned_tree );
2473 gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE );
2475 auto column = ui::TreeViewColumn( "", renderer, {{"text", TAG_COLUMN}} );
2476 gtk_tree_view_append_column(textureBrowser.m_assigned_tree, column );
2477 textureBrowser.m_assigned_tree.show();
2479 scrolled_win.show();
2481 //gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW( scrolled_win ), textureBrowser.m_assigned_tree );
2482 gtk_container_add( GTK_CONTAINER( scrolled_win ), GTK_WIDGET( textureBrowser.m_available_tree ) );
2484 frame_table.attach(scrolled_win, {0, 1, 1, 3}, {GTK_FILL, GTK_FILL});
2486 { // available tag list
2487 ui::Widget scrolled_win = ui::ScrolledWindow(ui::New);
2488 gtk_container_set_border_width( GTK_CONTAINER( scrolled_win ), 0 );
2489 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scrolled_win ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
2491 textureBrowser.m_available_store = ui::ListStore::from(gtk_list_store_new( N_COLUMNS, G_TYPE_STRING ));
2492 auto sortable = GTK_TREE_SORTABLE( textureBrowser.m_available_store );
2493 gtk_tree_sortable_set_sort_column_id( sortable, TAG_COLUMN, GTK_SORT_ASCENDING );
2495 auto renderer = ui::CellRendererText(ui::New);
2497 textureBrowser.m_available_tree = ui::TreeView(ui::TreeModel::from(textureBrowser.m_available_store._handle));
2498 textureBrowser.m_available_store.unref();
2499 textureBrowser.m_available_tree.connect( "row-activated", (GCallback) TextureBrowser_assignTags, NULL );
2500 gtk_tree_view_set_headers_visible(textureBrowser.m_available_tree, FALSE );
2502 auto selection = gtk_tree_view_get_selection(textureBrowser.m_available_tree );
2503 gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE );
2505 auto column = ui::TreeViewColumn( "", renderer, {{"text", TAG_COLUMN}} );
2506 gtk_tree_view_append_column(textureBrowser.m_available_tree, column );
2507 textureBrowser.m_available_tree.show();
2509 scrolled_win.show();
2511 //gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW( scrolled_win ), textureBrowser.m_available_tree );
2512 gtk_container_add( GTK_CONTAINER( scrolled_win ), GTK_WIDGET( textureBrowser.m_available_tree ) );
2514 frame_table.attach(scrolled_win, {2, 3, 1, 3}, {GTK_FILL, GTK_FILL});
2516 { // tag arrow buttons
2517 auto m_btn_left = ui::Button(ui::New);
2518 auto m_btn_right = ui::Button(ui::New);
2519 auto m_arrow_left = ui::Widget::from(gtk_arrow_new( GTK_ARROW_LEFT, GTK_SHADOW_OUT ));
2520 auto m_arrow_right = ui::Widget::from(gtk_arrow_new( GTK_ARROW_RIGHT, GTK_SHADOW_OUT ));
2521 m_btn_left.add(m_arrow_left);
2522 m_btn_right.add(m_arrow_right);
2524 // workaround. the size of the tag frame depends of the requested size of the arrow buttons.
2525 m_arrow_left.dimensions(-1, 68);
2526 m_arrow_right.dimensions(-1, 68);
2528 frame_table.attach(m_btn_left, {1, 2, 1, 2}, {GTK_SHRINK, GTK_EXPAND});
2529 frame_table.attach(m_btn_right, {1, 2, 2, 3}, {GTK_SHRINK, GTK_EXPAND});
2531 m_btn_left.connect( "clicked", G_CALLBACK( TextureBrowser_assignTags ), NULL );
2532 m_btn_right.connect( "clicked", G_CALLBACK( TextureBrowser_removeTags ), NULL );
2536 m_arrow_left.show();
2537 m_arrow_right.show();
2539 { // tag fram labels
2540 ui::Widget m_lbl_assigned = ui::Label( "Assigned" );
2541 ui::Widget m_lbl_unassigned = ui::Label( "Available" );
2543 frame_table.attach(m_lbl_assigned, {0, 1, 0, 1}, {GTK_EXPAND, GTK_SHRINK});
2544 frame_table.attach(m_lbl_unassigned, {2, 3, 0, 1}, {GTK_EXPAND, GTK_SHRINK});
2546 m_lbl_assigned.show();
2547 m_lbl_unassigned.show();
2550 else { // no tag support, show the texture tree only
2551 vbox.pack_start( textureBrowser.m_scr_win_tree, TRUE, TRUE, 0 );
2554 // TODO do we need this?
2555 //gtk_container_set_focus_chain(GTK_CONTAINER(hbox_table), NULL);
2557 isWindowConstructed = true;
2562 void TextureBrowser_destroyGLWidget(){
2563 TextureBrowser &textureBrowser = GlobalTextureBrowser();
2564 if ( isGLWidgetConstructed )
2566 g_signal_handler_disconnect( G_OBJECT( textureBrowser.m_gl_widget ), textureBrowser.m_sizeHandler );
2567 g_signal_handler_disconnect( G_OBJECT( textureBrowser.m_gl_widget ), textureBrowser.m_exposeHandler );
2569 #ifdef WORKAROUND_MACOS_GTK2_GLWIDGET
2570 textureBrowser.m_hframe.remove( textureBrowser.m_gl_widget );
2571 #else // !WORKAROUND_MACOS_GTK2_GLWIDGET
2572 textureBrowser.m_frame.remove( textureBrowser.m_gl_widget );
2573 #endif // !WORKAROUND_MACOS_GTK2_GLWIDGET
2575 textureBrowser.m_gl_widget.unref();
2577 isGLWidgetConstructed = false;
2581 void TextureBrowser_destroyWindow(){
2582 GlobalShaderSystem().setActiveShadersChangedNotify( Callback<void()>() );
2584 TextureBrowser_destroyGLWidget();
2587 #ifdef WORKAROUND_MACOS_GTK2_GLWIDGET
2588 /* workaround for gtkglext on gtk 2 issue: OpenGL texture viewport being drawn over the other pages */
2589 /* this is very ugly: force the resizing of the viewport to a single bottom line by forcing the
2590 * resizing of the gl widget by expanding some empty boxes, so the widget area size is reduced
2591 * while covered by another page, so the texture viewport is still rendered over the other page
2592 * but does not annoy the user that much because it's just a line on the bottom that may even
2593 * be printed over existing bottom frame or very close to it. */
2594 void TextureBrowser_showGLWidget(){
2595 TextureBrowser &textureBrowser = GlobalTextureBrowser();
2596 if ( isWindowConstructed && isGLWidgetConstructed )
2598 textureBrowser.m_vframe.set_child_packing( textureBrowser.m_vfiller, FALSE, FALSE, 0, ui::Packing::START );
2599 textureBrowser.m_vframe.set_child_packing( textureBrowser.m_hframe, TRUE, TRUE, 0, ui::Packing::START );
2600 textureBrowser.m_vframe.set_child_packing( textureBrowser.m_hfiller, FALSE, FALSE, 0, ui::Packing::START );
2601 textureBrowser.m_vframe.set_child_packing( textureBrowser.m_gl_widget, TRUE, TRUE, 0, ui::Packing::START );
2603 textureBrowser.m_gl_widget.show();
2607 void TextureBrowser_hideGLWidget(){
2608 TextureBrowser &textureBrowser = GlobalTextureBrowser();
2609 if ( isWindowConstructed && isGLWidgetConstructed )
2611 textureBrowser.m_vframe.set_child_packing( textureBrowser.m_vfiller, TRUE, TRUE, 0, ui::Packing::START);
2612 textureBrowser.m_vframe.set_child_packing( textureBrowser.m_hframe, FALSE, FALSE, 0, ui::Packing::END );
2613 textureBrowser.m_vframe.set_child_packing( textureBrowser.m_hfiller, TRUE, TRUE, 0, ui::Packing::START);
2614 textureBrowser.m_vframe.set_child_packing( textureBrowser.m_gl_widget, FALSE, FALSE, 0, ui::Packing::END );
2616 // The hack needs the GL widget to not be hidden to work,
2617 // so resizing it triggers the redraw of it with the new size.
2618 // GlobalTextureBrowser().m_gl_widget.hide();
2620 // Trigger the redraw.
2621 TextureBrowser_redraw( &GlobalTextureBrowser() );
2625 #endif // WORKAROUND_MACOS_GTK2_GLWIDGET
2627 const Vector3& TextureBrowser_getBackgroundColour( TextureBrowser& textureBrowser ){
2628 return textureBrowser.color_textureback;
2631 void TextureBrowser_setBackgroundColour( TextureBrowser& textureBrowser, const Vector3& colour ){
2632 textureBrowser.color_textureback = colour;
2633 TextureBrowser_queueDraw( textureBrowser );
2636 void TextureBrowser_selectionHelper( ui::TreeModel model, ui::TreePath path, GtkTreeIter* iter, GSList** selected ){
2637 g_assert( selected != NULL );
2640 gtk_tree_model_get( model, iter, TAG_COLUMN, &name, -1 );
2641 *selected = g_slist_append( *selected, name );
2644 void TextureBrowser_shaderInfo(){
2645 const char* name = TextureBrowser_GetSelectedShader( GlobalTextureBrowser() );
2646 IShader* shader = QERApp_Shader_ForName( name );
2648 DoShaderInfoDlg( name, shader->getShaderFileName(), "Shader Info" );
2653 void TextureBrowser_addTag(){
2655 TextureBrowser &textureBrowser = GlobalTextureBrowser();
2657 EMessageBoxReturn result = DoShaderTagDlg( &tag, "Add shader tag" );
2659 if ( result == eIDOK && !tag.empty() ) {
2661 textureBrowser.m_all_tags.insert( tag.c_str() );
2662 gtk_list_store_append( textureBrowser.m_available_store, &iter );
2663 gtk_list_store_set( textureBrowser.m_available_store, &iter, TAG_COLUMN, tag.c_str(), -1 );
2665 // Select the currently added tag in the available list
2666 auto selection = gtk_tree_view_get_selection(textureBrowser.m_available_tree );
2667 gtk_tree_selection_select_iter( selection, &iter );
2669 textureBrowser.m_all_tags_list.append(TAG_COLUMN, tag.c_str());
2673 void TextureBrowser_renameTag(){
2674 /* WORKAROUND: The tag treeview is set to GTK_SELECTION_MULTIPLE. Because
2675 gtk_tree_selection_get_selected() doesn't work with GTK_SELECTION_MULTIPLE,
2676 we need to count the number of selected rows first and use
2677 gtk_tree_selection_selected_foreach() then to go through the list of selected
2678 rows (which always containins a single row).
2681 GSList* selected = NULL;
2682 TextureBrowser &textureBrowser = GlobalTextureBrowser();
2684 auto selection = gtk_tree_view_get_selection(textureBrowser.m_treeViewTags );
2685 gtk_tree_selection_selected_foreach( selection, GtkTreeSelectionForeachFunc( TextureBrowser_selectionHelper ), &selected );
2687 if ( g_slist_length( selected ) == 1 ) { // we only rename a single tag
2688 CopiedString newTag;
2689 EMessageBoxReturn result = DoShaderTagDlg( &newTag, "Rename shader tag" );
2691 if ( result == eIDOK && !newTag.empty() ) {
2692 GtkTreeIter iterList;
2694 gchar* oldTag = (char*)selected->data;
2696 bool row = gtk_tree_model_get_iter_first(textureBrowser.m_all_tags_list, &iterList ) != 0;
2700 gtk_tree_model_get(textureBrowser.m_all_tags_list, &iterList, TAG_COLUMN, &rowTag, -1 );
2702 if ( strcmp( rowTag, oldTag ) == 0 ) {
2703 gtk_list_store_set( textureBrowser.m_all_tags_list, &iterList, TAG_COLUMN, newTag.c_str(), -1 );
2705 row = gtk_tree_model_iter_next(textureBrowser.m_all_tags_list, &iterList ) != 0;
2708 TagBuilder.RenameShaderTag( oldTag, newTag.c_str() );
2710 textureBrowser.m_all_tags.erase( (CopiedString)oldTag );
2711 textureBrowser.m_all_tags.insert( newTag );
2713 BuildStoreAssignedTags( textureBrowser.m_assigned_store, textureBrowser.shader.c_str(), &textureBrowser );
2714 BuildStoreAvailableTags( textureBrowser.m_available_store, textureBrowser.m_assigned_store, textureBrowser.m_all_tags, &textureBrowser );
2719 ui::alert( textureBrowser.m_parent, "Select a single tag for renaming." );
2723 void TextureBrowser_deleteTag(){
2724 GSList* selected = NULL;
2725 TextureBrowser &textureBrowser = GlobalTextureBrowser();
2727 auto selection = gtk_tree_view_get_selection(textureBrowser.m_treeViewTags );
2728 gtk_tree_selection_selected_foreach( selection, GtkTreeSelectionForeachFunc( TextureBrowser_selectionHelper ), &selected );
2730 if ( g_slist_length( selected ) == 1 ) { // we only delete a single tag
2731 auto result = ui::alert( textureBrowser.m_parent, "Are you sure you want to delete the selected tag?", "Delete Tag", ui::alert_type::YESNO, ui::alert_icon::Question );
2733 if ( result == ui::alert_response::YES ) {
2734 GtkTreeIter iterSelected;
2737 gchar* tagSelected = (char*)selected->data;
2739 bool row = gtk_tree_model_get_iter_first(textureBrowser.m_all_tags_list, &iterSelected ) != 0;
2743 gtk_tree_model_get(textureBrowser.m_all_tags_list, &iterSelected, TAG_COLUMN, &rowTag, -1 );
2745 if ( strcmp( rowTag, tagSelected ) == 0 ) {
2746 gtk_list_store_remove( textureBrowser.m_all_tags_list, &iterSelected );
2749 row = gtk_tree_model_iter_next(textureBrowser.m_all_tags_list, &iterSelected ) != 0;
2752 TagBuilder.DeleteTag( tagSelected );
2753 textureBrowser.m_all_tags.erase( (CopiedString)tagSelected );
2755 BuildStoreAssignedTags( textureBrowser.m_assigned_store, textureBrowser.shader.c_str(), &textureBrowser );
2756 BuildStoreAvailableTags( textureBrowser.m_available_store, textureBrowser.m_assigned_store, textureBrowser.m_all_tags, &textureBrowser );
2760 ui::alert( textureBrowser.m_parent, "Select a single tag for deletion." );
2764 void TextureBrowser_copyTag(){
2765 TextureBrowser &textureBrowser = GlobalTextureBrowser();
2766 textureBrowser.m_copied_tags.clear();
2767 TagBuilder.GetShaderTags( textureBrowser.shader.c_str(), textureBrowser.m_copied_tags );
2770 void TextureBrowser_pasteTag(){
2771 TextureBrowser &textureBrowser = GlobalTextureBrowser();
2772 IShader* ishader = QERApp_Shader_ForName( textureBrowser.shader.c_str() );
2773 CopiedString shader = textureBrowser.shader.c_str();
2775 if ( !TagBuilder.CheckShaderTag( shader.c_str() ) ) {
2776 CopiedString shaderFile = ishader->getShaderFileName();
2777 if ( shaderFile.empty() ) {
2779 TagBuilder.AddShaderNode( shader.c_str(), CUSTOM, TEXTURE );
2784 TagBuilder.AddShaderNode( shader.c_str(), CUSTOM, SHADER );
2787 for ( size_t i = 0; i < textureBrowser.m_copied_tags.size(); ++i )
2789 TagBuilder.AddShaderTag( shader.c_str(), textureBrowser.m_copied_tags[i].c_str(), TAG );
2794 for ( size_t i = 0; i < textureBrowser.m_copied_tags.size(); ++i )
2796 if ( !TagBuilder.CheckShaderTag( shader.c_str(), textureBrowser.m_copied_tags[i].c_str() ) ) {
2797 // the tag doesn't exist - let's add it
2798 TagBuilder.AddShaderTag( shader.c_str(), textureBrowser.m_copied_tags[i].c_str(), TAG );
2805 TagBuilder.SaveXmlDoc();
2806 BuildStoreAssignedTags( textureBrowser.m_assigned_store, shader.c_str(), &textureBrowser );
2807 BuildStoreAvailableTags( textureBrowser.m_available_store, textureBrowser.m_assigned_store, textureBrowser.m_all_tags, &textureBrowser );
2810 void TextureBrowser_RefreshShaders(){
2811 TextureBrowser &textureBrowser = GlobalTextureBrowser();
2813 /* When shaders are refreshed, forces reloading the textures as well.
2814 Previously it would at best only display shaders, at worst mess up some textured objects. */
2816 auto selection = gtk_tree_view_get_selection(GlobalTextureBrowser().m_treeViewTree);
2817 GtkTreeModel* model = NULL;
2819 if ( gtk_tree_selection_get_selected (selection, &model, &iter) )
2821 gchar dirName[1024];
2824 gtk_tree_model_get( model, &iter, 0, &buffer, -1 );
2825 strcpy( dirName, buffer );
2827 if ( !TextureBrowser_showWads() ) {
2828 strcat( dirName, "/" );
2831 ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", "Loading Shaders" );
2832 GlobalShaderSystem().refresh();
2833 /* texturebrowser tree update on vfs restart */
2834 TextureBrowser_constructTreeStore();
2837 TextureBrowser_ShowDirectory( GlobalTextureBrowser(), dirName );
2838 TextureBrowser_queueDraw( GlobalTextureBrowser() );
2842 ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", "Loading Shaders" );
2843 GlobalShaderSystem().refresh();
2844 /* texturebrowser tree update on vfs restart */
2845 TextureBrowser_constructTreeStore();
2850 void TextureBrowser_ToggleShowShaders(){
2851 GlobalTextureBrowser().m_showShaders ^= 1;
2852 GlobalTextureBrowser().m_showshaders_item.update();
2854 GlobalTextureBrowser().m_heightChanged = true;
2855 GlobalTextureBrowser().m_originInvalid = true;
2856 g_activeShadersChangedCallbacks();
2858 TextureBrowser_queueDraw( GlobalTextureBrowser() );
2861 void TextureBrowser_ToggleShowTextures(){
2862 GlobalTextureBrowser().m_showTextures ^= 1;
2863 GlobalTextureBrowser().m_showtextures_item.update();
2865 GlobalTextureBrowser().m_heightChanged = true;
2866 GlobalTextureBrowser().m_originInvalid = true;
2867 g_activeShadersChangedCallbacks();
2869 TextureBrowser_queueDraw( GlobalTextureBrowser() );
2872 void TextureBrowser_ToggleShowShaderListOnly(){
2873 g_TextureBrowser_shaderlistOnly ^= 1;
2874 GlobalTextureBrowser().m_showshaderlistonly_item.update();
2876 TextureBrowser_constructTreeStore();
2879 void TextureBrowser_showAll(){
2880 g_TextureBrowser_currentDirectory = "";
2881 GlobalTextureBrowser().m_searchedTags = false;
2882 // TextureBrowser_SetHideUnused( GlobalTextureBrowser(), false );
2883 TextureBrowser_ToggleHideUnused();
2884 //TextureBrowser_heightChanged( GlobalTextureBrowser() );
2885 TextureBrowser_updateTitle();
2888 void TextureBrowser_showUntagged(){
2889 TextureBrowser &textureBrowser = GlobalTextureBrowser();
2890 auto result = ui::alert( 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 );
2892 if ( result == ui::alert_response::YES ) {
2893 textureBrowser.m_found_shaders.clear();
2894 TagBuilder.GetUntagged( textureBrowser.m_found_shaders );
2895 std::set<CopiedString>::iterator iter;
2897 ScopeDisableScreenUpdates disableScreenUpdates( "Searching untagged textures...", "Loading Textures" );
2899 for ( iter = textureBrowser.m_found_shaders.begin(); iter != textureBrowser.m_found_shaders.end(); iter++ )
2901 std::string path = ( *iter ).c_str();
2902 size_t pos = path.find_last_of( "/", path.size() );
2903 std::string name = path.substr( pos + 1, path.size() );
2904 path = path.substr( 0, pos + 1 );
2905 TextureDirectory_loadTexture( path.c_str(), name.c_str() );
2906 globalErrorStream() << path.c_str() << name.c_str() << "\n";
2909 g_TextureBrowser_currentDirectory = "Untagged";
2910 TextureBrowser_queueDraw( GlobalTextureBrowser() );
2911 TextureBrowser_heightChanged( textureBrowser );
2912 TextureBrowser_updateTitle();
2916 void TextureBrowser_FixedSize(){
2917 g_TextureBrowser_fixedSize ^= 1;
2918 GlobalTextureBrowser().m_fixedsize_item.update();
2919 TextureBrowser_activeShadersChanged( GlobalTextureBrowser() );
2922 void TextureBrowser_FilterMissing(){
2923 g_TextureBrowser_filterMissing ^= 1;
2924 GlobalTextureBrowser().m_filternotex_item.update();
2925 TextureBrowser_activeShadersChanged( GlobalTextureBrowser() );
2926 TextureBrowser_RefreshShaders();
2929 void TextureBrowser_FilterFallback(){
2930 g_TextureBrowser_filterFallback ^= 1;
2931 GlobalTextureBrowser().m_hidenotex_item.update();
2932 TextureBrowser_activeShadersChanged( GlobalTextureBrowser() );
2933 TextureBrowser_RefreshShaders();
2936 void TextureBrowser_EnableAlpha(){
2937 g_TextureBrowser_enableAlpha ^= 1;
2938 GlobalTextureBrowser().m_enablealpha_item.update();
2939 TextureBrowser_activeShadersChanged( GlobalTextureBrowser() );
2942 void TextureBrowser_exportTitle( const Callback<void(const char *)> & importer ){
2943 StringOutputStream buffer( 64 );
2944 buffer << "Textures: ";
2945 if ( !string_empty( g_TextureBrowser_currentDirectory.c_str() ) ) {
2946 buffer << g_TextureBrowser_currentDirectory.c_str();
2952 importer( buffer.c_str() );
2955 struct TextureScale {
2956 static void Export(const TextureBrowser &self, const Callback<void(int)> &returnz) {
2957 switch (self.m_textureScale) {
2976 static void Import(TextureBrowser &self, int value) {
2979 TextureBrowser_setScale(self, 10);
2982 TextureBrowser_setScale(self, 25);
2985 TextureBrowser_setScale(self, 50);
2988 TextureBrowser_setScale(self, 100);
2991 TextureBrowser_setScale(self, 200);
2997 struct UniformTextureSize {
2998 static void Export(const TextureBrowser &self, const Callback<void(int)> &returnz) {
2999 returnz(GlobalTextureBrowser().m_uniformTextureSize);
3002 static void Import(TextureBrowser &self, int value) {
3004 TextureBrowser_setUniformSize(self, value);
3008 struct UniformTextureMinSize {
3009 static void Export(const TextureBrowser &self, const Callback<void(int)> &returnz) {
3010 returnz(GlobalTextureBrowser().m_uniformTextureMinSize);
3013 static void Import(TextureBrowser &self, int value) {
3015 TextureBrowser_setUniformSize(self, value);
3019 void TextureBrowser_constructPreferences( PreferencesPage& page ){
3020 page.appendCheckBox(
3021 "", "Texture scrollbar",
3022 make_property<TextureBrowser_ShowScrollbar>(GlobalTextureBrowser())
3025 const char* texture_scale[] = { "10%", "25%", "50%", "100%", "200%" };
3027 "Texture Thumbnail Scale",
3028 STRING_ARRAY_RANGE( texture_scale ),
3029 make_property<TextureScale>(GlobalTextureBrowser())
3032 page.appendSpinner( "Thumbnails Max Size", GlobalTextureBrowser().m_uniformTextureSize, GlobalTextureBrowser().m_uniformTextureSize, 16, 8192 );
3033 page.appendSpinner( "Thumbnails Min Size", GlobalTextureBrowser().m_uniformTextureMinSize, GlobalTextureBrowser().m_uniformTextureMinSize, 16, 8192 );
3034 page.appendEntry( "Mousewheel Increment", GlobalTextureBrowser().m_mouseWheelScrollIncrement );
3036 const char* startup_shaders[] = { "None", TextureBrowser_getCommonShadersName() };
3037 page.appendCombo( "Load Shaders at Startup", reinterpret_cast<int&>( GlobalTextureBrowser().m_startupShaders ), STRING_ARRAY_RANGE( startup_shaders ) );
3040 StringOutputStream sstream( 256 );
3041 sstream << "Hide nonShaders in " << TextureBrowser_getCommonShadersDir() << " folder";
3042 page.appendCheckBox(
3043 "", sstream.c_str(),
3044 GlobalTextureBrowser().m_hideNonShadersInCommon
3049 void TextureBrowser_constructPage( PreferenceGroup& group ){
3050 PreferencesPage page( group.createPage( "Texture Browser", "Texture Browser Preferences" ) );
3051 TextureBrowser_constructPreferences( page );
3054 void TextureBrowser_registerPreferencesPage(){
3055 PreferencesDialog_addSettingsPage( makeCallbackF(TextureBrowser_constructPage) );
3059 #include "preferencesystem.h"
3060 #include "stringio.h"
3063 void TextureClipboard_textureSelected( const char* shader );
3065 void TextureBrowser_Construct(){
3066 TextureBrowser &textureBrowser = GlobalTextureBrowser();
3068 GlobalCommands_insert( "ShaderInfo", makeCallbackF(TextureBrowser_shaderInfo) );
3069 GlobalCommands_insert( "ShowUntagged", makeCallbackF(TextureBrowser_showUntagged) );
3070 GlobalCommands_insert( "AddTag", makeCallbackF(TextureBrowser_addTag) );
3071 GlobalCommands_insert( "RenameTag", makeCallbackF(TextureBrowser_renameTag) );
3072 GlobalCommands_insert( "DeleteTag", makeCallbackF(TextureBrowser_deleteTag) );
3073 GlobalCommands_insert( "CopyTag", makeCallbackF(TextureBrowser_copyTag) );
3074 GlobalCommands_insert( "PasteTag", makeCallbackF(TextureBrowser_pasteTag) );
3075 GlobalCommands_insert( "RefreshShaders", makeCallbackF(VFS_Refresh) );
3076 GlobalToggles_insert( "ShowInUse", makeCallbackF(TextureBrowser_ToggleHideUnused), ToggleItem::AddCallbackCaller( textureBrowser.m_hideunused_item ), Accelerator( 'U' ) );
3077 GlobalCommands_insert( "ShowAllTextures", makeCallbackF(TextureBrowser_showAll), Accelerator( 'A', (GdkModifierType)GDK_CONTROL_MASK ) );
3078 GlobalCommands_insert( "ToggleTextures", makeCallbackF(TextureBrowser_toggleShow), Accelerator( 'T' ) );
3079 GlobalToggles_insert( "ToggleShowShaders", makeCallbackF(TextureBrowser_ToggleShowShaders), ToggleItem::AddCallbackCaller( GlobalTextureBrowser().m_showshaders_item ) );
3080 GlobalToggles_insert( "ToggleShowTextures", makeCallbackF(TextureBrowser_ToggleShowTextures), ToggleItem::AddCallbackCaller( GlobalTextureBrowser().m_showtextures_item ) );
3081 GlobalToggles_insert( "ToggleShowShaderlistOnly", makeCallbackF(TextureBrowser_ToggleShowShaderListOnly),
3082 ToggleItem::AddCallbackCaller( GlobalTextureBrowser().m_showshaderlistonly_item ) );
3083 GlobalToggles_insert( "FixedSize", makeCallbackF(TextureBrowser_FixedSize), ToggleItem::AddCallbackCaller( GlobalTextureBrowser().m_fixedsize_item ) );
3084 GlobalToggles_insert( "FilterMissing", makeCallbackF(TextureBrowser_FilterMissing), ToggleItem::AddCallbackCaller( GlobalTextureBrowser().m_filternotex_item ) );
3085 GlobalToggles_insert( "FilterFallback", makeCallbackF(TextureBrowser_FilterFallback), ToggleItem::AddCallbackCaller( GlobalTextureBrowser().m_hidenotex_item ) );
3086 GlobalToggles_insert( "EnableAlpha", makeCallbackF(TextureBrowser_EnableAlpha), ToggleItem::AddCallbackCaller( GlobalTextureBrowser().m_enablealpha_item ) );
3088 GlobalPreferenceSystem().registerPreference( "TextureScale", make_property_string<TextureScale>(textureBrowser) );
3089 GlobalPreferenceSystem().registerPreference( "UniformTextureSize", make_property_string<UniformTextureSize>(textureBrowser) );
3090 GlobalPreferenceSystem().registerPreference( "UniformTextureMinSize", make_property_string<UniformTextureMinSize>(textureBrowser) );
3091 GlobalPreferenceSystem().registerPreference( "TextureScrollbar", make_property_string<TextureBrowser_ShowScrollbar>(textureBrowser));
3092 GlobalPreferenceSystem().registerPreference( "ShowShaders", make_property_string( textureBrowser.m_showShaders ) );
3093 GlobalPreferenceSystem().registerPreference( "ShowTextures", make_property_string( GlobalTextureBrowser().m_showTextures ) );
3094 GlobalPreferenceSystem().registerPreference( "ShowShaderlistOnly", make_property_string( g_TextureBrowser_shaderlistOnly ) );
3095 GlobalPreferenceSystem().registerPreference( "FixedSize", make_property_string( g_TextureBrowser_fixedSize ) );
3096 GlobalPreferenceSystem().registerPreference( "FilterMissing", make_property_string( g_TextureBrowser_filterMissing ) );
3097 GlobalPreferenceSystem().registerPreference( "EnableAlpha", make_property_string( g_TextureBrowser_enableAlpha ) );
3098 GlobalPreferenceSystem().registerPreference( "LoadShaders", make_property_string( reinterpret_cast<int&>( textureBrowser.m_startupShaders ) ) );
3099 GlobalPreferenceSystem().registerPreference( "WheelMouseInc", make_property_string( textureBrowser.m_mouseWheelScrollIncrement ) );
3100 GlobalPreferenceSystem().registerPreference( "SI_Colors0", make_property_string( textureBrowser.color_textureback ) );
3101 GlobalPreferenceSystem().registerPreference( "HideNonShadersInCommon", make_property_string( GlobalTextureBrowser().m_hideNonShadersInCommon ) );
3103 textureBrowser.shader = texdef_name_default();
3105 Textures_setModeChangedNotify( ReferenceCaller<TextureBrowser, void(), TextureBrowser_queueDraw>( textureBrowser ) );
3107 TextureBrowser_registerPreferencesPage();
3109 GlobalShaderSystem().attach( g_ShadersObserver );
3111 TextureBrowser_textureSelected = TextureClipboard_textureSelected;
3114 void TextureBrowser_Destroy(){
3115 GlobalShaderSystem().detach( g_ShadersObserver );
3117 Textures_setModeChangedNotify( Callback<void()>() );
3120 #if WORKAROUND_WINDOWS_GTK2_GLWIDGET
3121 ui::GLArea TextureBrowser_getGLWidget(){
3122 return GlobalTextureBrowser().m_gl_widget;
3124 #endif // WORKAROUND_WINDOWS_GTK2_GLWIDGET