2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 // Leonardo Zide (leo@lokigames.com)
28 #include "texwindow.h"
32 #include "debugging/debugging.h"
36 #include "ifilesystem.h"
40 #include "moduleobserver.h"
46 #include <uilib/uilib.h>
48 #include "signal/signal.h"
49 #include "math/vector.h"
50 #include "texturelib.h"
51 #include "string/string.h"
52 #include "shaderlib.h"
55 #include "stream/memstream.h"
56 #include "stream/textfilestream.h"
57 #include "stream/stringstream.h"
63 #include "gtkutil/menu.h"
64 #include "gtkutil/nonmodal.h"
65 #include "gtkutil/cursor.h"
66 #include "gtkutil/widget.h"
67 #include "gtkutil/glwidget.h"
68 #include "gtkutil/messagebox.h"
74 #include "brush_primit.h"
75 #include "brushmanip.h"
76 #include "patchmanip.h"
81 #include "mainframe.h"
82 #include "findtexturedialog.h"
83 #include "surfacedialog.h"
84 #include "patchdialog.h"
85 #include "groupdialog.h"
86 #include "preferences.h"
90 bool TextureBrowser_showWads(){
91 return !string_empty( g_pGameDescription->getKeyValue( "show_wads" ) );
94 void TextureBrowser_queueDraw( TextureBrowser& textureBrowser );
96 bool string_equal_start( const char* string, StringRange start ){
97 return string_equal_n( string, start.first, start.last - start.first );
100 typedef std::set<CopiedString> TextureGroups;
102 void TextureGroups_addWad( TextureGroups& groups, const char* archive ){
103 if ( extension_equal( path_get_extension( archive ), "wad" ) ) {
105 groups.insert( archive );
107 CopiedString archiveBaseName( path_get_filename_start( archive ), path_get_filename_base_end( archive ) );
108 groups.insert( archiveBaseName );
113 typedef ReferenceCaller<TextureGroups, void(const char*), TextureGroups_addWad> TextureGroupsAddWadCaller;
117 bool g_TextureBrowser_shaderlistOnly = false;
118 bool g_TextureBrowser_fixedSize = true;
119 bool g_TextureBrowser_filterMissing = false;
120 bool g_TextureBrowser_filterFallback = true;
121 bool g_TextureBrowser_enableAlpha = true;
124 CopiedString g_notex;
125 CopiedString g_shadernotex;
127 bool isMissing(const char* name);
129 bool isNotex(const char* name);
131 bool isMissing(const char* name){
132 if ( string_equal( g_notex.c_str(), name ) ) {
135 if ( string_equal( g_shadernotex.c_str(), name ) ) {
141 bool isNotex(const char* name){
142 if ( string_equal_suffix( name, "/" DEFAULT_NOTEX_BASENAME ) ) {
145 if ( string_equal_suffix( name, "/" DEFAULT_SHADERNOTEX_BASENAME ) ) {
151 void TextureGroups_addShader( TextureGroups& groups, const char* shaderName ){
152 const char* texture = path_make_relative( shaderName, "textures/" );
154 // hide notex / shadernotex images
155 if ( g_TextureBrowser_filterFallback ) {
156 if ( isNotex( shaderName ) ) {
159 if ( isNotex( texture ) ) {
164 if ( texture != shaderName ) {
165 const char* last = path_remove_directory( texture );
166 if ( !string_empty( last ) ) {
167 groups.insert( CopiedString( StringRange( texture, --last ) ) );
172 typedef ReferenceCaller<TextureGroups, void(const char*), TextureGroups_addShader> TextureGroupsAddShaderCaller;
174 void TextureGroups_addDirectory( TextureGroups& groups, const char* directory ){
175 groups.insert( directory );
178 typedef ReferenceCaller<TextureGroups, void(const char*), TextureGroups_addDirectory> TextureGroupsAddDirectoryCaller;
180 class DeferredAdjustment
185 typedef void ( *ValueChangedFunction )( void* data, gdouble value );
187 ValueChangedFunction m_function;
190 static gboolean deferred_value_changed( gpointer data ){
191 reinterpret_cast<DeferredAdjustment*>( data )->m_function(
192 reinterpret_cast<DeferredAdjustment*>( data )->m_data,
193 reinterpret_cast<DeferredAdjustment*>( data )->m_value
195 reinterpret_cast<DeferredAdjustment*>( data )->m_handler = 0;
196 reinterpret_cast<DeferredAdjustment*>( data )->m_value = 0;
201 DeferredAdjustment( ValueChangedFunction function, void* data ) : m_value( 0 ), m_handler( 0 ), m_function( function ), m_data( data ){
205 if ( m_handler != 0 ) {
206 g_source_remove( m_handler );
207 deferred_value_changed( this );
211 void value_changed( gdouble value ){
213 if ( m_handler == 0 ) {
214 m_handler = g_idle_add( deferred_value_changed, this );
218 static void adjustment_value_changed(ui::Adjustment adjustment, DeferredAdjustment* self ){
219 self->value_changed( gtk_adjustment_get_value(adjustment) );
224 class TextureBrowser;
226 typedef ReferenceCaller<TextureBrowser, void(), TextureBrowser_queueDraw> TextureBrowserQueueDrawCaller;
228 void TextureBrowser_scrollChanged( void* data, gdouble value );
233 STARTUPSHADERS_NONE = 0,
234 STARTUPSHADERS_COMMON,
237 void TextureBrowser_hideUnusedExport( const Callback<void(bool)> & importer );
239 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_hideUnusedExport> TextureBrowserHideUnusedExport;
241 void TextureBrowser_showShadersExport( const Callback<void(bool)> & importer );
243 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_showShadersExport> TextureBrowserShowShadersExport;
245 void TextureBrowser_showShaderlistOnly( const Callback<void(bool)> & importer );
247 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_showShaderlistOnly> TextureBrowserShowShaderlistOnlyExport;
249 void TextureBrowser_fixedSize( const Callback<void(bool)> & importer );
251 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_fixedSize> TextureBrowserFixedSizeExport;
253 void TextureBrowser_filterMissing( const Callback<void(bool)> & importer );
255 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_filterMissing> TextureBrowserFilterMissingExport;
257 void TextureBrowser_filterFallback( const Callback<void(bool)> & importer );
259 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_filterFallback> TextureBrowserFilterFallbackExport;
261 void TextureBrowser_enableAlpha( const Callback<void(bool)> & importer );
263 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_enableAlpha> TextureBrowserEnableAlphaExport;
274 ui::Window m_parent{ui::null};
275 ui::GLArea m_gl_widget{ui::null};
276 ui::Widget m_texture_scroll{ui::null};
277 ui::TreeView m_treeViewTree{ui::New};
278 ui::TreeView m_treeViewTags{ui::null};
279 ui::Frame m_tag_frame{ui::null};
280 ui::ListStore m_assigned_store{ui::null};
281 ui::ListStore m_available_store{ui::null};
282 ui::TreeView m_assigned_tree{ui::null};
283 ui::TreeView m_available_tree{ui::null};
284 ui::Widget m_scr_win_tree{ui::null};
285 ui::Widget m_scr_win_tags{ui::null};
286 ui::Widget m_tag_notebook{ui::null};
287 ui::Button m_search_button{ui::null};
288 ui::Widget m_shader_info_item{ui::null};
290 std::set<CopiedString> m_all_tags;
291 ui::ListStore m_all_tags_list{ui::null};
292 std::vector<CopiedString> m_copied_tags;
293 std::set<CopiedString> m_found_shaders;
295 ToggleItem m_hideunused_item;
296 ToggleItem m_hidenotex_item;
297 ToggleItem m_showshaders_item;
298 ToggleItem m_showshaderlistonly_item;
299 ToggleItem m_fixedsize_item;
300 ToggleItem m_filternotex_item;
301 ToggleItem m_enablealpha_item;
304 guint m_exposeHandler;
306 bool m_heightChanged;
307 bool m_originInvalid;
309 DeferredAdjustment m_scrollAdjustment;
310 FreezePointer m_freezePointer;
312 Vector3 color_textureback;
313 // the increment step we use against the wheel mouse
314 std::size_t m_mouseWheelScrollIncrement;
315 std::size_t m_textureScale;
316 // make the texture increments match the grid changes
318 bool m_showTextureScrollbar;
319 StartupShaders m_startupShaders;
320 // if true, the texture window will only display in-use shaders
321 // if false, all the shaders in memory are displayed
326 // The uniform size (in pixels) that textures are resized to when m_resizeTextures is true.
327 int m_uniformTextureSize;
328 int m_uniformTextureMinSize;
330 // Return the display width of a texture in the texture browser
331 /*void getTextureWH( qtexture_t* tex, int *width, int *height ){
332 if ( !g_TextureBrowser_fixedSize ) {
333 // Don't use uniform size
334 *width = (int)( tex->width * ( (float)m_textureScale / 100 ) );
335 *height = (int)( tex->height * ( (float)m_textureScale / 100 ) );
338 else if ( tex->width >= tex->height ) {
339 // Texture is square, or wider than it is tall
340 if ( tex->width >= m_uniformTextureSize ){
341 *width = m_uniformTextureSize;
342 *height = (int)( m_uniformTextureSize * ( (float)tex->height / tex->width ) );
344 else if ( tex->width <= m_uniformTextureMinSize ){
345 *width = m_uniformTextureMinSize;
346 *height = (int)( m_uniformTextureMinSize * ( (float)tex->height / tex->width ) );
350 *height = tex->height;
354 // Texture taller than it is wide
355 if ( tex->height >= m_uniformTextureSize ){
356 *height = m_uniformTextureSize;
357 *width = (int)( m_uniformTextureSize * ( (float)tex->width / tex->height ) );
359 else if ( tex->height <= m_uniformTextureMinSize ){
360 *height = m_uniformTextureMinSize;
361 *width = (int)( m_uniformTextureMinSize * ( (float)tex->width / tex->height ) );
365 *height = tex->height;
371 void getTextureWH( qtexture_t* tex, int &W, int &H ){
372 // Don't use uniform size
373 W = (int)( tex->width * ( (float)m_textureScale / 100 ) );
374 H = (int)( tex->height * ( (float)m_textureScale / 100 ) );
376 if ( g_TextureBrowser_fixedSize ){
378 // Texture is square, or wider than it is tall
379 if ( W >= m_uniformTextureSize ){
380 H = m_uniformTextureSize * H / W;
381 W = m_uniformTextureSize;
383 else if ( W <= m_uniformTextureMinSize ){
384 H = m_uniformTextureMinSize * H / W;
385 W = m_uniformTextureMinSize;
389 // Texture taller than it is wide
390 if ( H >= m_uniformTextureSize ){
391 W = m_uniformTextureSize * W / H;
392 H = m_uniformTextureSize;
394 else if ( H <= m_uniformTextureMinSize ){
395 W = m_uniformTextureMinSize * W / H;
396 H = m_uniformTextureMinSize;
403 m_texture_scroll( ui::null ),
404 m_hideunused_item( TextureBrowserHideUnusedExport() ),
405 m_hidenotex_item( TextureBrowserFilterFallbackExport() ),
406 m_showshaders_item( TextureBrowserShowShadersExport() ),
407 m_showshaderlistonly_item( TextureBrowserShowShaderlistOnlyExport() ),
408 m_fixedsize_item( TextureBrowserFixedSizeExport() ),
409 m_filternotex_item( TextureBrowserFilterMissingExport() ),
410 m_enablealpha_item( TextureBrowserEnableAlphaExport() ),
411 m_heightChanged( true ),
412 m_originInvalid( true ),
413 m_scrollAdjustment( TextureBrowser_scrollChanged, this ),
414 color_textureback( 0.25f, 0.25f, 0.25f ),
415 m_mouseWheelScrollIncrement( 64 ),
416 m_textureScale( 50 ),
417 m_showShaders( true ),
418 m_showTextureScrollbar( true ),
419 m_startupShaders( STARTUPSHADERS_NONE ),
420 m_hideUnused( false ),
421 m_rmbSelected( false ),
422 m_searchedTags( false ),
424 m_uniformTextureSize( 160 ),
425 m_uniformTextureMinSize( 48 ){
429 void ( *TextureBrowser_textureSelected )( const char* shader );
432 void TextureBrowser_updateScroll( TextureBrowser& textureBrowser );
435 const char* TextureBrowser_getComonShadersName(){
436 const char* value = g_pGameDescription->getKeyValue( "common_shaders_name" );
437 if ( !string_empty( value ) ) {
443 const char* TextureBrowser_getComonShadersDir(){
444 const char* value = g_pGameDescription->getKeyValue( "common_shaders_dir" );
445 if ( !string_empty( value ) ) {
451 inline int TextureBrowser_fontHeight( TextureBrowser& textureBrowser ){
452 return GlobalOpenGL().m_font->getPixelHeight();
455 const char* TextureBrowser_GetSelectedShader( TextureBrowser& textureBrowser ){
456 return textureBrowser.shader.c_str();
459 void TextureBrowser_SetStatus( TextureBrowser& textureBrowser, const char* name ){
460 IShader* shader = QERApp_Shader_ForName( name );
461 qtexture_t* q = shader->getTexture();
462 StringOutputStream strTex( 256 );
463 strTex << name << " W: " << Unsigned( q->width ) << " H: " << Unsigned( q->height );
465 g_pParentWnd->SetStatusText( g_pParentWnd->m_texture_status, strTex.c_str() );
468 void TextureBrowser_Focus( TextureBrowser& textureBrowser, const char* name );
470 void TextureBrowser_SetSelectedShader( TextureBrowser& textureBrowser, const char* shader ){
471 textureBrowser.shader = shader;
472 TextureBrowser_SetStatus( textureBrowser, shader );
473 TextureBrowser_Focus( textureBrowser, shader );
475 if ( FindTextureDialog_isOpen() ) {
476 FindTextureDialog_selectTexture( shader );
479 // disable the menu item "shader info" if no shader was selected
480 IShader* ishader = QERApp_Shader_ForName( shader );
481 CopiedString filename = ishader->getShaderFileName();
483 if ( filename.empty() ) {
484 if ( textureBrowser.m_shader_info_item != NULL ) {
485 gtk_widget_set_sensitive( textureBrowser.m_shader_info_item, FALSE );
489 gtk_widget_set_sensitive( textureBrowser.m_shader_info_item, TRUE );
496 CopiedString g_TextureBrowser_currentDirectory;
499 ============================================================================
503 TTimo: now based on a rundown through all the shaders
504 NOTE: we expect the Active shaders count doesn't change during a Texture_StartPos .. Texture_NextPos cycle
505 otherwise we may need to rely on a list instead of an array storage
506 ============================================================================
512 // texture layout functions
513 // TTimo: now based on shaders
514 int current_x, current_y, current_row;
517 void Texture_StartPos( TextureLayout& layout ){
518 layout.current_x = 8;
519 layout.current_y = -8;
520 layout.current_row = 0;
523 void Texture_NextPos( TextureBrowser& textureBrowser, TextureLayout& layout, qtexture_t* current_texture, int *x, int *y ){
524 qtexture_t* q = current_texture;
527 textureBrowser.getTextureWH( q, nWidth, nHeight );
528 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
529 layout.current_x = 8;
530 layout.current_y -= layout.current_row + TextureBrowser_fontHeight( textureBrowser ) + 4;
531 layout.current_row = 0;
534 *x = layout.current_x;
535 *y = layout.current_y;
537 // Is our texture larger than the row? If so, grow the
538 // row height to match it
540 if ( layout.current_row < nHeight ) {
541 layout.current_row = nHeight;
544 // never go less than 96, or the names get all crunched up
545 layout.current_x += nWidth < 96 ? 96 : nWidth;
546 layout.current_x += 8;
549 bool TextureSearch_IsShown( const char* name ){
550 std::set<CopiedString>::iterator iter;
552 iter = GlobalTextureBrowser().m_found_shaders.find( name );
554 if ( iter == GlobalTextureBrowser().m_found_shaders.end() ) {
562 // if texture_showinuse jump over non in-use textures
563 bool Texture_IsShown( IShader* shader, bool show_shaders, bool hideUnused ){
564 // filter missing shaders
565 // ugly: filter on built-in fallback name after substitution
566 if ( g_TextureBrowser_filterMissing ) {
567 if ( isMissing( shader->getTexture()->name ) ) {
571 // filter the fallback (notex/shadernotex) for missing shaders or editor image
572 if ( g_TextureBrowser_filterFallback ) {
573 if ( isNotex( shader->getName() ) ) {
576 if ( isNotex( shader->getTexture()->name ) ) {
581 if ( g_TextureBrowser_currentDirectory == "Untagged" ) {
582 std::set<CopiedString>::iterator iter;
584 iter = GlobalTextureBrowser().m_found_shaders.find( shader->getName() );
586 if ( iter == GlobalTextureBrowser().m_found_shaders.end() ) {
594 if ( !shader_equal_prefix( shader->getName(), "textures/" ) ) {
598 if ( !show_shaders && !shader->IsDefault() ) {
602 if ( hideUnused && !shader->IsInUse() ) {
606 if ( GlobalTextureBrowser().m_searchedTags ) {
607 if ( !TextureSearch_IsShown( shader->getName() ) ) {
615 if ( !shader_equal_prefix( shader_get_textureName( shader->getName() ), g_TextureBrowser_currentDirectory.c_str() ) ) {
623 void TextureBrowser_heightChanged( TextureBrowser& textureBrowser ){
624 textureBrowser.m_heightChanged = true;
626 TextureBrowser_updateScroll( textureBrowser );
627 TextureBrowser_queueDraw( textureBrowser );
630 void TextureBrowser_evaluateHeight( TextureBrowser& textureBrowser ){
631 if ( textureBrowser.m_heightChanged ) {
632 textureBrowser.m_heightChanged = false;
634 textureBrowser.m_nTotalHeight = 0;
636 TextureLayout layout;
637 Texture_StartPos( layout );
638 for ( QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement() )
640 IShader* shader = QERApp_ActiveShaders_IteratorCurrent();
642 if ( !Texture_IsShown( shader, textureBrowser.m_showShaders, textureBrowser.m_hideUnused ) ) {
647 Texture_NextPos( textureBrowser, layout, shader->getTexture(), &x, &y );
649 textureBrowser.getTextureWH( shader->getTexture(), nWidth, nHeight );
650 textureBrowser.m_nTotalHeight = std::max( textureBrowser.m_nTotalHeight, abs( layout.current_y ) + TextureBrowser_fontHeight( textureBrowser ) + nHeight + 4 );
655 int TextureBrowser_TotalHeight( TextureBrowser& textureBrowser ){
656 TextureBrowser_evaluateHeight( textureBrowser );
657 return textureBrowser.m_nTotalHeight;
660 inline const int& min_int( const int& left, const int& right ){
661 return std::min( left, right );
664 void TextureBrowser_clampOriginY( TextureBrowser& textureBrowser ){
665 if ( textureBrowser.originy > 0 ) {
666 textureBrowser.originy = 0;
668 int lower = min_int( textureBrowser.height - TextureBrowser_TotalHeight( textureBrowser ), 0 );
669 if ( textureBrowser.originy < lower ) {
670 textureBrowser.originy = lower;
674 int TextureBrowser_getOriginY( TextureBrowser& textureBrowser ){
675 if ( textureBrowser.m_originInvalid ) {
676 textureBrowser.m_originInvalid = false;
677 TextureBrowser_clampOriginY( textureBrowser );
678 TextureBrowser_updateScroll( textureBrowser );
680 return textureBrowser.originy;
683 void TextureBrowser_setOriginY( TextureBrowser& textureBrowser, int originy ){
684 textureBrowser.originy = originy;
685 TextureBrowser_clampOriginY( textureBrowser );
686 TextureBrowser_updateScroll( textureBrowser );
687 TextureBrowser_queueDraw( textureBrowser );
691 Signal0 g_activeShadersChangedCallbacks;
693 void TextureBrowser_addActiveShadersChangedCallback( const SignalHandler& handler ){
694 g_activeShadersChangedCallbacks.connectLast( handler );
697 void TextureBrowser_constructTreeStore();
699 class ShadersObserver : public ModuleObserver
701 Signal0 m_realiseCallbacks;
704 m_realiseCallbacks();
705 TextureBrowser_constructTreeStore();
711 void insert( const SignalHandler& handler ){
712 m_realiseCallbacks.connectLast( handler );
718 ShadersObserver g_ShadersObserver;
721 void TextureBrowser_addShadersRealiseCallback( const SignalHandler& handler ){
722 g_ShadersObserver.insert( handler );
725 void TextureBrowser_activeShadersChanged( TextureBrowser& textureBrowser ){
726 TextureBrowser_heightChanged( textureBrowser );
727 textureBrowser.m_originInvalid = true;
729 g_activeShadersChangedCallbacks();
732 struct TextureBrowser_ShowScrollbar {
733 static void Export(const TextureBrowser &self, const Callback<void(bool)> &returnz) {
734 returnz(self.m_showTextureScrollbar);
737 static void Import(TextureBrowser &self, bool value) {
738 self.m_showTextureScrollbar = value;
739 if (self.m_texture_scroll) {
740 self.m_texture_scroll.visible(self.m_showTextureScrollbar);
741 TextureBrowser_updateScroll(self);
749 TextureBrowser_ShowDirectory
750 relies on texture_directory global for the directory to use
751 1) Load the shaders for the given directory
752 2) Scan the remaining texture, load them and assign them a default shader (the "noshader" shader)
753 NOTE: when writing a texture plugin, or some texture extensions, this function may need to be overriden, and made
754 available through the IShaders interface
755 NOTE: for texture window layout:
756 all shaders are stored with alphabetical order after load
757 previously loaded and displayed stuff is hidden, only in-use and newly loaded is shown
758 ( the GL textures are not flushed though)
762 bool endswith( const char *haystack, const char *needle ){
763 size_t lh = strlen( haystack );
764 size_t ln = strlen( needle );
768 return !memcmp( haystack + ( lh - ln ), needle, ln );
771 bool texture_name_ignore( const char* name ){
772 StringOutputStream strTemp( string_length( name ) );
773 strTemp << LowerCase( name );
776 endswith( strTemp.c_str(), ".specular" ) ||
777 endswith( strTemp.c_str(), ".glow" ) ||
778 endswith( strTemp.c_str(), ".bump" ) ||
779 endswith( strTemp.c_str(), ".diffuse" ) ||
780 endswith( strTemp.c_str(), ".blend" ) ||
781 endswith( strTemp.c_str(), ".alpha" ) ||
782 endswith( strTemp.c_str(), "_alpha" ) ||
784 endswith( strTemp.c_str(), "_h" ) ||
785 endswith( strTemp.c_str(), "_local" ) ||
786 endswith( strTemp.c_str(), "_nm" ) ||
787 endswith( strTemp.c_str(), "_s" ) ||
789 endswith( strTemp.c_str(), "_bump" ) ||
790 endswith( strTemp.c_str(), "_glow" ) ||
791 endswith( strTemp.c_str(), "_gloss" ) ||
792 endswith( strTemp.c_str(), "_luma" ) ||
793 endswith( strTemp.c_str(), "_norm" ) ||
794 endswith( strTemp.c_str(), "_pants" ) ||
795 endswith( strTemp.c_str(), "_shirt" ) ||
796 endswith( strTemp.c_str(), "_reflect" ) ||
798 endswith( strTemp.c_str(), "_d" ) ||
799 endswith( strTemp.c_str(), "_n" ) ||
800 endswith( strTemp.c_str(), "_p" ) ||
801 endswith( strTemp.c_str(), "_g" ) ||
802 endswith( strTemp.c_str(), "_a" ) ||
806 class LoadShaderVisitor : public Archive::Visitor
809 void visit( const char* name ){
810 IShader* shader = QERApp_Shader_ForName( CopiedString( StringRange( name, path_get_filename_base_end( name ) ) ).c_str() );
815 void TextureBrowser_SetHideUnused( TextureBrowser& textureBrowser, bool hideUnused );
817 ui::Widget g_page_textures{ui::null};
819 void TextureBrowser_toggleShow(){
820 GroupDialog_showPage( g_page_textures );
824 void TextureBrowser_updateTitle(){
825 GroupDialog_updatePageTitle( g_page_textures );
829 class TextureCategoryLoadShader
831 const char* m_directory;
832 std::size_t& m_count;
834 using func = void(const char *);
836 TextureCategoryLoadShader( const char* directory, std::size_t& count )
837 : m_directory( directory ), m_count( count ){
841 void operator()( const char* name ) const {
842 if ( shader_equal_prefix( name, "textures/" )
843 && shader_equal_prefix( name + string_length( "textures/" ), m_directory ) ) {
845 // request the shader, this will load the texture if needed
846 // this Shader_ForName call is a kind of hack
847 IShader *pFoo = QERApp_Shader_ForName( name );
853 void TextureDirectory_loadTexture( const char* directory, const char* texture ){
854 StringOutputStream name( 256 );
855 name << directory << StringRange( texture, path_get_filename_base_end( texture ) );
857 if ( texture_name_ignore( name.c_str() ) ) {
861 if ( !shader_valid( name.c_str() ) ) {
862 globalOutputStream() << "Skipping invalid texture name: [" << name.c_str() << "]\n";
866 // if a texture is already in use to represent a shader, ignore it
867 IShader* shader = QERApp_Shader_ForName( name.c_str() );
871 typedef ConstPointerCaller<char, void(const char*), TextureDirectory_loadTexture> TextureDirectoryLoadTextureCaller;
873 class LoadTexturesByTypeVisitor : public ImageModules::Visitor
875 const char* m_dirstring;
877 LoadTexturesByTypeVisitor( const char* dirstring )
878 : m_dirstring( dirstring ){
881 void visit( const char* minor, const _QERPlugImageTable& table ) const {
882 GlobalFileSystem().forEachFile( m_dirstring, minor, TextureDirectoryLoadTextureCaller( m_dirstring ) );
886 void TextureBrowser_ShowDirectory( TextureBrowser& textureBrowser, const char* directory ){
887 if ( TextureBrowser_showWads() ) {
888 Archive* archive = GlobalFileSystem().getArchive( directory );
889 ASSERT_NOTNULL( archive );
890 LoadShaderVisitor visitor;
891 archive->forEachFile( Archive::VisitorFunc( visitor, Archive::eFiles, 0 ), "textures/" );
895 g_TextureBrowser_currentDirectory = directory;
896 TextureBrowser_heightChanged( textureBrowser );
898 std::size_t shaders_count;
899 GlobalShaderSystem().foreachShaderName(makeCallback( TextureCategoryLoadShader( directory, shaders_count ) ) );
900 globalOutputStream() << "Showing " << Unsigned( shaders_count ) << " shaders.\n";
902 if ( g_pGameDescription->mGameType != "doom3" ) {
903 // load remaining texture files
905 StringOutputStream dirstring( 64 );
906 dirstring << "textures/" << directory;
908 Radiant_getImageModules().foreachModule( LoadTexturesByTypeVisitor( dirstring.c_str() ) );
912 // we'll display the newly loaded textures + all the ones already in use
913 TextureBrowser_SetHideUnused( textureBrowser, false );
915 TextureBrowser_updateTitle();
918 void TextureBrowser_ShowTagSearchResult( TextureBrowser& textureBrowser, const char* directory ){
919 g_TextureBrowser_currentDirectory = directory;
920 TextureBrowser_heightChanged( textureBrowser );
922 std::size_t shaders_count;
923 GlobalShaderSystem().foreachShaderName(makeCallback( TextureCategoryLoadShader( directory, shaders_count ) ) );
924 globalOutputStream() << "Showing " << Unsigned( shaders_count ) << " shaders.\n";
926 if ( g_pGameDescription->mGameType != "doom3" ) {
927 // load remaining texture files
928 StringOutputStream dirstring( 64 );
929 dirstring << "textures/" << directory;
932 LoadTexturesByTypeVisitor visitor( dirstring.c_str() );
933 Radiant_getImageModules().foreachModule( visitor );
937 // we'll display the newly loaded textures + all the ones already in use
938 TextureBrowser_SetHideUnused( textureBrowser, false );
942 bool TextureBrowser_hideUnused();
944 void TextureBrowser_hideUnusedExport( const Callback<void(bool)> & importer ){
945 importer( TextureBrowser_hideUnused() );
948 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_hideUnusedExport> TextureBrowserHideUnusedExport;
950 void TextureBrowser_showShadersExport( const Callback<void(bool)> & importer ){
951 importer( GlobalTextureBrowser().m_showShaders );
954 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_showShadersExport> TextureBrowserShowShadersExport;
956 void TextureBrowser_showShaderlistOnly( const Callback<void(bool)> & importer ){
957 importer( g_TextureBrowser_shaderlistOnly );
960 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_showShaderlistOnly> TextureBrowserShowShaderlistOnlyExport;
962 void TextureBrowser_fixedSize( const Callback<void(bool)> & importer ){
963 importer( g_TextureBrowser_fixedSize );
966 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_fixedSize> TextureBrowser_FixedSizeExport;
968 void TextureBrowser_filterMissing( const Callback<void(bool)> & importer ){
969 importer( g_TextureBrowser_filterMissing );
972 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_filterMissing> TextureBrowser_filterMissingExport;
974 void TextureBrowser_filterFallback( const Callback<void(bool)> & importer ){
975 importer( g_TextureBrowser_filterFallback );
978 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_filterFallback> TextureBrowser_filterFallbackExport;
980 void TextureBrowser_enableAlpha( const Callback<void(bool)> & importer ){
981 importer( g_TextureBrowser_enableAlpha );
984 typedef FreeCaller<void(const Callback<void(bool)> &), TextureBrowser_enableAlpha> TextureBrowser_enableAlphaExport;
986 void TextureBrowser_SetHideUnused( TextureBrowser& textureBrowser, bool hideUnused ){
988 textureBrowser.m_hideUnused = true;
992 textureBrowser.m_hideUnused = false;
995 textureBrowser.m_hideunused_item.update();
997 TextureBrowser_heightChanged( textureBrowser );
998 textureBrowser.m_originInvalid = true;
1001 void TextureBrowser_ShowStartupShaders( TextureBrowser& textureBrowser ){
1002 if ( textureBrowser.m_startupShaders == STARTUPSHADERS_COMMON ) {
1003 TextureBrowser_ShowDirectory( textureBrowser, TextureBrowser_getComonShadersDir() );
1008 //++timo NOTE: this is a mix of Shader module stuff and texture explorer
1009 // it might need to be split in parts or moved out .. dunno
1010 // scroll origin so the specified texture is completely on screen
1011 // if current texture is not displayed, nothing is changed
1012 void TextureBrowser_Focus( TextureBrowser& textureBrowser, const char* name ){
1013 TextureLayout layout;
1014 // scroll origin so the texture is completely on screen
1015 Texture_StartPos( layout );
1017 for ( QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement() )
1019 IShader* shader = QERApp_ActiveShaders_IteratorCurrent();
1021 if ( !Texture_IsShown( shader, textureBrowser.m_showShaders, textureBrowser.m_hideUnused ) ) {
1026 Texture_NextPos( textureBrowser, layout, shader->getTexture(), &x, &y );
1027 qtexture_t* q = shader->getTexture();
1032 // we have found when texdef->name and the shader name match
1033 // NOTE: as everywhere else for our comparisons, we are not case sensitive
1034 if ( shader_equal( name, shader->getName() ) ) {
1035 int textureHeight = (int)( q->height * ( (float)textureBrowser.m_textureScale / 100 ) )
1036 + 2 * TextureBrowser_fontHeight( textureBrowser );
1038 int originy = TextureBrowser_getOriginY( textureBrowser );
1039 if ( y > originy ) {
1043 if ( y - textureHeight < originy - textureBrowser.height ) {
1044 originy = ( y - textureHeight ) + textureBrowser.height;
1047 TextureBrowser_setOriginY( textureBrowser, originy );
1053 IShader* Texture_At( TextureBrowser& textureBrowser, int mx, int my ){
1054 my += TextureBrowser_getOriginY( textureBrowser ) - textureBrowser.height;
1056 TextureLayout layout;
1057 Texture_StartPos( layout );
1058 for ( QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement() )
1060 IShader* shader = QERApp_ActiveShaders_IteratorCurrent();
1062 if ( !Texture_IsShown( shader, textureBrowser.m_showShaders, textureBrowser.m_hideUnused ) ) {
1067 Texture_NextPos( textureBrowser, layout, shader->getTexture(), &x, &y );
1068 qtexture_t *q = shader->getTexture();
1073 int nWidth, nHeight;
1074 textureBrowser.getTextureWH( q, nWidth, nHeight );
1075 if ( mx > x && mx - x < nWidth
1076 && my < y && y - my < nHeight + TextureBrowser_fontHeight( textureBrowser ) ) {
1091 void SelectTexture( TextureBrowser& textureBrowser, int mx, int my, bool bShift ){
1092 IShader* shader = Texture_At( textureBrowser, mx, my );
1093 if ( shader != 0 ) {
1095 if ( shader->IsDefault() ) {
1096 globalOutputStream() << "ERROR: " << shader->getName() << " is not a shader, it's a texture.\n";
1099 ViewShader( shader->getShaderFileName(), shader->getName() );
1104 TextureBrowser_SetSelectedShader( textureBrowser, shader->getName() );
1105 TextureBrowser_textureSelected( shader->getName() );
1107 if ( !FindTextureDialog_isOpen() && !textureBrowser.m_rmbSelected ) {
1108 UndoableCommand undo( "textureNameSetSelected" );
1109 Select_SetShader( shader->getName() );
1116 ============================================================================
1120 ============================================================================
1123 void TextureBrowser_trackingDelta( int x, int y, unsigned int state, void* data ){
1124 TextureBrowser& textureBrowser = *reinterpret_cast<TextureBrowser*>( data );
1128 if ( state & GDK_SHIFT_MASK ) {
1132 int originy = TextureBrowser_getOriginY( textureBrowser );
1133 originy += y * scale;
1134 TextureBrowser_setOriginY( textureBrowser, originy );
1138 void TextureBrowser_Tracking_MouseDown( TextureBrowser& textureBrowser ){
1139 textureBrowser.m_freezePointer.freeze_pointer( textureBrowser.m_parent, TextureBrowser_trackingDelta, &textureBrowser );
1142 void TextureBrowser_Tracking_MouseUp( TextureBrowser& textureBrowser ){
1143 textureBrowser.m_freezePointer.unfreeze_pointer( textureBrowser.m_parent );
1146 void TextureBrowser_Selection_MouseDown( TextureBrowser& textureBrowser, guint32 flags, int pointx, int pointy ){
1147 SelectTexture( textureBrowser, pointx, textureBrowser.height - 1 - pointy, ( flags & GDK_SHIFT_MASK ) != 0 );
1151 ============================================================================
1155 ============================================================================
1161 TTimo: relying on the shaders list to display the textures
1162 we must query all qtexture_t* to manage and display through the IShaders interface
1163 this allows a plugin to completely override the texture system
1166 void Texture_Draw( TextureBrowser& textureBrowser ){
1167 int originy = TextureBrowser_getOriginY( textureBrowser );
1169 glClearColor( textureBrowser.color_textureback[0],
1170 textureBrowser.color_textureback[1],
1171 textureBrowser.color_textureback[2],
1173 glViewport( 0, 0, textureBrowser.width, textureBrowser.height );
1174 glMatrixMode( GL_PROJECTION );
1177 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
1178 glDisable( GL_DEPTH_TEST );
1179 if ( g_TextureBrowser_enableAlpha ) {
1180 glEnable( GL_BLEND );
1181 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1184 glDisable( GL_BLEND );
1186 glOrtho( 0, textureBrowser.width, originy - textureBrowser.height, originy, -100, 100 );
1187 glEnable( GL_TEXTURE_2D );
1189 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
1191 int last_y = 0, last_height = 0;
1193 TextureLayout layout;
1194 Texture_StartPos( layout );
1195 for ( QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement() )
1197 IShader* shader = QERApp_ActiveShaders_IteratorCurrent();
1199 if ( !Texture_IsShown( shader, textureBrowser.m_showShaders, textureBrowser.m_hideUnused ) ) {
1204 Texture_NextPos( textureBrowser, layout, shader->getTexture(), &x, &y );
1205 qtexture_t *q = shader->getTexture();
1210 int nWidth, nHeight;
1211 textureBrowser.getTextureWH( q, nWidth, nHeight );
1213 if ( y != last_y ) {
1217 last_height = std::max( nHeight, last_height );
1219 // Is this texture visible?
1220 if ( ( y - nHeight - TextureBrowser_fontHeight( textureBrowser ) < originy )
1221 && ( y > originy - textureBrowser.height ) ) {
1223 // if it's the current texture, draw a thick red line, else:
1224 // shaders have a white border, simple textures don't
1225 // if !texture_showinuse: (some textures displayed may not be in use)
1226 // draw an additional square around with 0.5 1 0.5 color
1227 if ( shader_equal( TextureBrowser_GetSelectedShader( textureBrowser ), shader->getName() ) ) {
1229 if ( textureBrowser.m_rmbSelected ) {
1235 glDisable( GL_TEXTURE_2D );
1237 glBegin( GL_LINE_LOOP );
1238 glVertex2i( x - 4,y - TextureBrowser_fontHeight( textureBrowser ) + 4 );
1239 glVertex2i( x - 4,y - TextureBrowser_fontHeight( textureBrowser ) - nHeight - 4 );
1240 glVertex2i( x + 4 + nWidth,y - TextureBrowser_fontHeight( textureBrowser ) - nHeight - 4 );
1241 glVertex2i( x + 4 + nWidth,y - TextureBrowser_fontHeight( textureBrowser ) + 4 );
1244 glEnable( GL_TEXTURE_2D );
1251 if ( !shader->IsDefault() ) {
1253 glDisable( GL_TEXTURE_2D );
1255 glBegin( GL_LINE_LOOP );
1256 glVertex2i( x - 1,y + 1 - TextureBrowser_fontHeight( textureBrowser ) );
1257 glVertex2i( x - 1,y - nHeight - 1 - TextureBrowser_fontHeight( textureBrowser ) );
1258 glVertex2i( x + 1 + nWidth,y - nHeight - 1 - TextureBrowser_fontHeight( textureBrowser ) );
1259 glVertex2i( x + 1 + nWidth,y + 1 - TextureBrowser_fontHeight( textureBrowser ) );
1261 glEnable( GL_TEXTURE_2D );
1264 // highlight in-use textures
1265 if ( !textureBrowser.m_hideUnused && shader->IsInUse() ) {
1266 glColor3f( 0.5,1,0.5 );
1267 glDisable( GL_TEXTURE_2D );
1268 glBegin( GL_LINE_LOOP );
1269 glVertex2i( x - 3,y + 3 - TextureBrowser_fontHeight( textureBrowser ) );
1270 glVertex2i( x - 3,y - nHeight - 3 - TextureBrowser_fontHeight( textureBrowser ) );
1271 glVertex2i( x + 3 + nWidth,y - nHeight - 3 - TextureBrowser_fontHeight( textureBrowser ) );
1272 glVertex2i( x + 3 + nWidth,y + 3 - TextureBrowser_fontHeight( textureBrowser ) );
1274 glEnable( GL_TEXTURE_2D );
1278 // draw checkerboard for transparent textures
1279 if ( g_TextureBrowser_enableAlpha )
1281 glDisable( GL_TEXTURE_2D );
1282 glBegin( GL_QUADS );
1283 int font_height = TextureBrowser_fontHeight( textureBrowser );
1284 for ( int i = 0; i < nHeight; i += 8 )
1286 for ( int j = 0; j < nWidth; j += 8 )
1288 unsigned char color = (i + j) / 8 % 2 ? 0x66 : 0x99;
1289 glColor3ub( color, color, color );
1291 int right = std::min(j+8, nWidth);
1293 int bottom = std::min(i+8, nHeight);
1294 glVertex2i(x + right, y - nHeight - font_height + top);
1295 glVertex2i(x + left, y - nHeight - font_height + top);
1296 glVertex2i(x + left, y - nHeight - font_height + bottom);
1297 glVertex2i(x + right, y - nHeight - font_height + bottom);
1301 glEnable( GL_TEXTURE_2D );
1305 glBindTexture( GL_TEXTURE_2D, q->texture_number );
1306 GlobalOpenGL_debugAssertNoErrors();
1308 glBegin( GL_QUADS );
1309 glTexCoord2i( 0,0 );
1310 glVertex2i( x,y - TextureBrowser_fontHeight( textureBrowser ) );
1311 glTexCoord2i( 1,0 );
1312 glVertex2i( x + nWidth,y - TextureBrowser_fontHeight( textureBrowser ) );
1313 glTexCoord2i( 1,1 );
1314 glVertex2i( x + nWidth,y - TextureBrowser_fontHeight( textureBrowser ) - nHeight );
1315 glTexCoord2i( 0,1 );
1316 glVertex2i( x,y - TextureBrowser_fontHeight( textureBrowser ) - nHeight );
1319 // draw the texture name
1320 glDisable( GL_TEXTURE_2D );
1323 glRasterPos2i( x, y - TextureBrowser_fontHeight( textureBrowser ) + 5 );
1325 // don't draw the directory name
1326 const char* name = shader->getName();
1327 name += strlen( name );
1328 while ( name != shader->getName() && *( name - 1 ) != '/' && *( name - 1 ) != '\\' )
1331 GlobalOpenGL().drawString( name );
1332 glEnable( GL_TEXTURE_2D );
1335 //int totalHeight = abs(y) + last_height + TextureBrowser_fontHeight(textureBrowser) + 4;
1339 // reset the current texture
1340 glBindTexture( GL_TEXTURE_2D, 0 );
1344 void TextureBrowser_queueDraw( TextureBrowser& textureBrowser ){
1345 if ( textureBrowser.m_gl_widget ) {
1346 gtk_widget_queue_draw( textureBrowser.m_gl_widget );
1351 void TextureBrowser_setScale( TextureBrowser& textureBrowser, std::size_t scale ){
1352 textureBrowser.m_textureScale = scale;
1354 TextureBrowser_queueDraw( textureBrowser );
1357 void TextureBrowser_setUniformSize( TextureBrowser& textureBrowser, std::size_t scale ){
1358 textureBrowser.m_uniformTextureSize = scale;
1360 TextureBrowser_queueDraw( textureBrowser );
1363 void TextureBrowser_setUniformMinSize( TextureBrowser& textureBrowser, std::size_t scale ){
1364 textureBrowser.m_uniformTextureMinSize = scale;
1366 TextureBrowser_queueDraw( textureBrowser );
1369 void TextureBrowser_MouseWheel( TextureBrowser& textureBrowser, bool bUp ){
1370 int originy = TextureBrowser_getOriginY( textureBrowser );
1373 originy += int(textureBrowser.m_mouseWheelScrollIncrement);
1377 originy -= int(textureBrowser.m_mouseWheelScrollIncrement);
1380 TextureBrowser_setOriginY( textureBrowser, originy );
1383 XmlTagBuilder TagBuilder;
1391 void BuildStoreAssignedTags( ui::ListStore store, const char* shader, TextureBrowser* textureBrowser ){
1396 std::vector<CopiedString> assigned_tags;
1397 TagBuilder.GetShaderTags( shader, assigned_tags );
1399 for ( size_t i = 0; i < assigned_tags.size(); i++ )
1401 store.append(TAG_COLUMN, assigned_tags[i].c_str());
1405 void BuildStoreAvailableTags( ui::ListStore storeAvailable,
1406 ui::ListStore storeAssigned,
1407 const std::set<CopiedString>& allTags,
1408 TextureBrowser* textureBrowser ){
1409 GtkTreeIter iterAssigned;
1410 GtkTreeIter iterAvailable;
1411 std::set<CopiedString>::const_iterator iterAll;
1412 gchar* tag_assigned;
1414 storeAvailable.clear();
1416 bool row = gtk_tree_model_get_iter_first(storeAssigned, &iterAssigned ) != 0;
1418 if ( !row ) { // does the shader have tags assigned?
1419 for ( iterAll = allTags.begin(); iterAll != allTags.end(); ++iterAll )
1421 storeAvailable.append(TAG_COLUMN, (*iterAll).c_str());
1426 while ( row ) // available tags = all tags - assigned tags
1428 gtk_tree_model_get(storeAssigned, &iterAssigned, TAG_COLUMN, &tag_assigned, -1 );
1430 for ( iterAll = allTags.begin(); iterAll != allTags.end(); ++iterAll )
1432 if ( strcmp( (char*)tag_assigned, ( *iterAll ).c_str() ) != 0 ) {
1433 storeAvailable.append(TAG_COLUMN, (*iterAll).c_str());
1437 row = gtk_tree_model_iter_next(storeAssigned, &iterAssigned ) != 0;
1440 gtk_tree_model_get(storeAssigned, &iterAssigned, TAG_COLUMN, &tag_assigned, -1 );
1448 gboolean TextureBrowser_button_press( ui::Widget widget, GdkEventButton* event, TextureBrowser* textureBrowser ){
1449 if ( event->type == GDK_BUTTON_PRESS ) {
1450 if ( event->button == 3 ) {
1451 if ( GlobalTextureBrowser().m_tags ) {
1452 textureBrowser->m_rmbSelected = true;
1453 TextureBrowser_Selection_MouseDown( *textureBrowser, event->state, static_cast<int>( event->x ), static_cast<int>( event->y ) );
1455 BuildStoreAssignedTags( textureBrowser->m_assigned_store, textureBrowser->shader.c_str(), textureBrowser );
1456 BuildStoreAvailableTags( textureBrowser->m_available_store, textureBrowser->m_assigned_store, textureBrowser->m_all_tags, textureBrowser );
1457 textureBrowser->m_heightChanged = true;
1458 textureBrowser->m_tag_frame.show();
1462 TextureBrowser_Focus( *textureBrowser, textureBrowser->shader.c_str() );
1466 TextureBrowser_Tracking_MouseDown( *textureBrowser );
1469 else if ( event->button == 1 ) {
1470 TextureBrowser_Selection_MouseDown( *textureBrowser, event->state, static_cast<int>( event->x ), static_cast<int>( event->y ) );
1472 if ( GlobalTextureBrowser().m_tags ) {
1473 textureBrowser->m_rmbSelected = false;
1474 textureBrowser->m_tag_frame.hide();
1481 gboolean TextureBrowser_button_release( ui::Widget widget, GdkEventButton* event, TextureBrowser* textureBrowser ){
1482 if ( event->type == GDK_BUTTON_RELEASE ) {
1483 if ( event->button == 3 ) {
1484 if ( !GlobalTextureBrowser().m_tags ) {
1485 TextureBrowser_Tracking_MouseUp( *textureBrowser );
1492 gboolean TextureBrowser_motion( ui::Widget widget, GdkEventMotion *event, TextureBrowser* textureBrowser ){
1496 gboolean TextureBrowser_scroll( ui::Widget widget, GdkEventScroll* event, TextureBrowser* textureBrowser ){
1497 if ( event->direction == GDK_SCROLL_UP ) {
1498 TextureBrowser_MouseWheel( *textureBrowser, true );
1500 else if ( event->direction == GDK_SCROLL_DOWN ) {
1501 TextureBrowser_MouseWheel( *textureBrowser, false );
1506 void TextureBrowser_scrollChanged( void* data, gdouble value ){
1507 //globalOutputStream() << "vertical scroll\n";
1508 TextureBrowser_setOriginY( *reinterpret_cast<TextureBrowser*>( data ), -(int)value );
1511 static void TextureBrowser_verticalScroll(ui::Adjustment adjustment, TextureBrowser* textureBrowser ){
1512 textureBrowser->m_scrollAdjustment.value_changed( gtk_adjustment_get_value(adjustment) );
1515 void TextureBrowser_updateScroll( TextureBrowser& textureBrowser ){
1516 if ( textureBrowser.m_showTextureScrollbar ) {
1517 int totalHeight = TextureBrowser_TotalHeight( textureBrowser );
1519 totalHeight = std::max( totalHeight, textureBrowser.height );
1521 auto vadjustment = gtk_range_get_adjustment( GTK_RANGE( textureBrowser.m_texture_scroll ) );
1523 gtk_adjustment_set_value(vadjustment, -TextureBrowser_getOriginY( textureBrowser ));
1524 gtk_adjustment_set_page_size(vadjustment, textureBrowser.height);
1525 gtk_adjustment_set_page_increment(vadjustment, textureBrowser.height / 2);
1526 gtk_adjustment_set_step_increment(vadjustment, 20);
1527 gtk_adjustment_set_lower(vadjustment, 0);
1528 gtk_adjustment_set_upper(vadjustment, totalHeight);
1530 g_signal_emit_by_name( G_OBJECT( vadjustment ), "changed" );
1534 gboolean TextureBrowser_size_allocate( ui::Widget widget, GtkAllocation* allocation, TextureBrowser* textureBrowser ){
1535 textureBrowser->width = allocation->width;
1536 textureBrowser->height = allocation->height;
1537 TextureBrowser_heightChanged( *textureBrowser );
1538 textureBrowser->m_originInvalid = true;
1539 TextureBrowser_queueDraw( *textureBrowser );
1543 gboolean TextureBrowser_expose( ui::Widget widget, GdkEventExpose* event, TextureBrowser* textureBrowser ){
1544 if ( glwidget_make_current( textureBrowser->m_gl_widget ) != FALSE ) {
1545 GlobalOpenGL_debugAssertNoErrors();
1546 TextureBrowser_evaluateHeight( *textureBrowser );
1547 Texture_Draw( *textureBrowser );
1548 GlobalOpenGL_debugAssertNoErrors();
1549 glwidget_swap_buffers( textureBrowser->m_gl_widget );
1555 TextureBrowser g_TextureBrowser;
1557 TextureBrowser& GlobalTextureBrowser(){
1558 return g_TextureBrowser;
1561 bool TextureBrowser_hideUnused(){
1562 return g_TextureBrowser.m_hideUnused;
1565 void TextureBrowser_ToggleHideUnused(){
1566 if ( g_TextureBrowser.m_hideUnused ) {
1567 TextureBrowser_SetHideUnused( g_TextureBrowser, false );
1571 TextureBrowser_SetHideUnused( g_TextureBrowser, true );
1575 void TextureGroups_constructTreeModel( TextureGroups groups, ui::TreeStore store ){
1576 // put the information from the old textures menu into a treeview
1577 GtkTreeIter iter, child;
1579 TextureGroups::const_iterator i = groups.begin();
1580 while ( i != groups.end() )
1582 const char* dirName = ( *i ).c_str();
1583 const char* firstUnderscore = strchr( dirName, '_' );
1584 StringRange dirRoot( dirName, ( firstUnderscore == 0 ) ? dirName : firstUnderscore + 1 );
1586 TextureGroups::const_iterator next = i;
1588 if ( firstUnderscore != 0
1589 && next != groups.end()
1590 && string_equal_start( ( *next ).c_str(), dirRoot ) ) {
1591 gtk_tree_store_append( store, &iter, NULL );
1592 gtk_tree_store_set( store, &iter, 0, CopiedString( StringRange( dirName, firstUnderscore ) ).c_str(), -1 );
1595 while ( i != groups.end() && string_equal_start( ( *i ).c_str(), dirRoot ) )
1597 gtk_tree_store_append( store, &child, &iter );
1598 gtk_tree_store_set( store, &child, 0, ( *i ).c_str(), -1 );
1604 gtk_tree_store_append( store, &iter, NULL );
1605 gtk_tree_store_set( store, &iter, 0, dirName, -1 );
1611 TextureGroups TextureGroups_constructTreeView(){
1612 TextureGroups groups;
1614 if ( TextureBrowser_showWads() ) {
1615 GlobalFileSystem().forEachArchive( TextureGroupsAddWadCaller( groups ) );
1619 // scan texture dirs and pak files only if not restricting to shaderlist
1620 if ( g_pGameDescription->mGameType != "doom3" && !g_TextureBrowser_shaderlistOnly ) {
1621 GlobalFileSystem().forEachDirectory( "textures/", TextureGroupsAddDirectoryCaller( groups ) );
1624 GlobalShaderSystem().foreachShaderName( TextureGroupsAddShaderCaller( groups ) );
1630 void TextureBrowser_constructTreeStore(){
1631 TextureGroups groups = TextureGroups_constructTreeView();
1632 auto store = ui::TreeStore::from(gtk_tree_store_new( 1, G_TYPE_STRING ));
1633 TextureGroups_constructTreeModel( groups, store );
1635 gtk_tree_view_set_model(g_TextureBrowser.m_treeViewTree, store);
1637 g_object_unref( G_OBJECT( store ) );
1640 void TextureBrowser_constructTreeStoreTags(){
1641 TextureGroups groups;
1642 auto store = ui::TreeStore::from(gtk_tree_store_new( 1, G_TYPE_STRING ));
1643 auto model = g_TextureBrowser.m_all_tags_list;
1645 gtk_tree_view_set_model(g_TextureBrowser.m_treeViewTags, model );
1647 g_object_unref( G_OBJECT( store ) );
1650 void TreeView_onRowActivated( ui::TreeView treeview, ui::TreePath path, ui::TreeViewColumn col, gpointer userdata ){
1653 auto model = gtk_tree_view_get_model(treeview );
1655 if ( gtk_tree_model_get_iter( model, &iter, path ) ) {
1656 gchar dirName[1024];
1659 gtk_tree_model_get( model, &iter, 0, &buffer, -1 );
1660 strcpy( dirName, buffer );
1663 g_TextureBrowser.m_searchedTags = false;
1665 if ( !TextureBrowser_showWads() ) {
1666 strcat( dirName, "/" );
1669 ScopeDisableScreenUpdates disableScreenUpdates( dirName, "Loading Textures" );
1670 TextureBrowser_ShowDirectory( GlobalTextureBrowser(), dirName );
1671 TextureBrowser_queueDraw( GlobalTextureBrowser() );
1672 //deactivate, so SPACE and RETURN wont be broken for 2d
1673 gtk_window_set_focus( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( treeview ) ) ), NULL );
1677 void TextureBrowser_createTreeViewTree(){
1678 gtk_tree_view_set_enable_search(g_TextureBrowser.m_treeViewTree, FALSE );
1680 gtk_tree_view_set_headers_visible(g_TextureBrowser.m_treeViewTree, FALSE );
1681 g_TextureBrowser.m_treeViewTree.connect( "row-activated", (GCallback) TreeView_onRowActivated, NULL );
1683 auto renderer = ui::CellRendererText(ui::New);
1684 gtk_tree_view_insert_column_with_attributes(g_TextureBrowser.m_treeViewTree, -1, "", renderer, "text", 0, NULL );
1686 TextureBrowser_constructTreeStore();
1689 void TextureBrowser_addTag();
1691 void TextureBrowser_renameTag();
1693 void TextureBrowser_deleteTag();
1695 void TextureBrowser_createContextMenu( ui::Widget treeview, GdkEventButton *event ){
1696 ui::Widget menu = ui::Menu(ui::New);
1698 ui::Widget menuitem = ui::MenuItem( "Add tag" );
1699 menuitem.connect( "activate", (GCallback)TextureBrowser_addTag, treeview );
1700 gtk_menu_shell_append( GTK_MENU_SHELL( menu ), menuitem );
1702 menuitem = ui::MenuItem( "Rename tag" );
1703 menuitem.connect( "activate", (GCallback)TextureBrowser_renameTag, treeview );
1704 gtk_menu_shell_append( GTK_MENU_SHELL( menu ), menuitem );
1706 menuitem = ui::MenuItem( "Delete tag" );
1707 menuitem.connect( "activate", (GCallback)TextureBrowser_deleteTag, treeview );
1708 gtk_menu_shell_append( GTK_MENU_SHELL( menu ), menuitem );
1710 gtk_widget_show_all( menu );
1712 gtk_menu_popup( GTK_MENU( menu ), NULL, NULL, NULL, NULL,
1713 ( event != NULL ) ? event->button : 0,
1714 gdk_event_get_time( (GdkEvent*)event ) );
1717 gboolean TreeViewTags_onButtonPressed( ui::TreeView treeview, GdkEventButton *event ){
1718 if ( event->type == GDK_BUTTON_PRESS && event->button == 3 ) {
1720 auto selection = gtk_tree_view_get_selection(treeview );
1722 if ( gtk_tree_view_get_path_at_pos(treeview, event->x, event->y, &path, NULL, NULL, NULL ) ) {
1723 gtk_tree_selection_unselect_all( selection );
1724 gtk_tree_selection_select_path( selection, path );
1725 gtk_tree_path_free( path );
1728 TextureBrowser_createContextMenu( treeview, event );
1734 void TextureBrowser_createTreeViewTags(){
1735 g_TextureBrowser.m_treeViewTags = ui::TreeView(ui::New);
1736 gtk_tree_view_set_enable_search(g_TextureBrowser.m_treeViewTags, FALSE );
1738 g_TextureBrowser.m_treeViewTags.connect( "button-press-event", (GCallback)TreeViewTags_onButtonPressed, NULL );
1740 gtk_tree_view_set_headers_visible(g_TextureBrowser.m_treeViewTags, FALSE );
1742 auto renderer = ui::CellRendererText(ui::New);
1743 gtk_tree_view_insert_column_with_attributes(g_TextureBrowser.m_treeViewTags, -1, "", renderer, "text", 0, NULL );
1745 TextureBrowser_constructTreeStoreTags();
1748 ui::MenuItem TextureBrowser_constructViewMenu( ui::Menu menu ){
1749 ui::MenuItem textures_menu_item = ui::MenuItem(new_sub_menu_item_with_mnemonic( "_View" ));
1751 if ( g_Layout_enableDetachableMenus.m_value ) {
1752 menu_tearoff( menu );
1755 create_check_menu_item_with_mnemonic( menu, "Hide _Unused", "ShowInUse" );
1756 if ( string_empty( g_pGameDescription->getKeyValue( "show_wads" ) ) ) {
1757 create_check_menu_item_with_mnemonic( menu, "Hide Image Missing", "FilterMissing" );
1760 // hide notex and shadernotex on texture browser: no one wants to apply them
1761 create_check_menu_item_with_mnemonic( menu, "Hide Fallback", "FilterFallback" );
1763 menu_separator( menu );
1765 create_menu_item_with_mnemonic( menu, "Show All", "ShowAllTextures" );
1767 // we always want to show shaders but don't want a "Show Shaders" menu for doom3 and .wad file games
1768 if ( g_pGameDescription->mGameType == "doom3" || !string_empty( g_pGameDescription->getKeyValue( "show_wads" ) ) ) {
1769 g_TextureBrowser.m_showShaders = true;
1773 create_check_menu_item_with_mnemonic( menu, "Show shaders", "ToggleShowShaders" );
1776 if ( g_pGameDescription->mGameType != "doom3" && string_empty( g_pGameDescription->getKeyValue( "show_wads" ) ) ) {
1777 create_check_menu_item_with_mnemonic( menu, "Shaders Only", "ToggleShowShaderlistOnly" );
1779 if ( g_TextureBrowser.m_tags ) {
1780 create_menu_item_with_mnemonic( menu, "Show Untagged", "ShowUntagged" );
1783 menu_separator( menu );
1784 create_check_menu_item_with_mnemonic( menu, "Fixed Size", "FixedSize" );
1785 create_check_menu_item_with_mnemonic( menu, "Transparency", "EnableAlpha" );
1787 if ( string_empty( g_pGameDescription->getKeyValue( "show_wads" ) ) ) {
1788 menu_separator( menu );
1789 g_TextureBrowser.m_shader_info_item = ui::Widget(create_menu_item_with_mnemonic( menu, "Shader Info", "ShaderInfo" ));
1790 gtk_widget_set_sensitive( g_TextureBrowser.m_shader_info_item, FALSE );
1794 return textures_menu_item;
1797 ui::MenuItem TextureBrowser_constructToolsMenu( ui::Menu menu ){
1798 ui::MenuItem textures_menu_item = ui::MenuItem(new_sub_menu_item_with_mnemonic( "_Tools" ));
1800 if ( g_Layout_enableDetachableMenus.m_value ) {
1801 menu_tearoff( menu );
1804 create_menu_item_with_mnemonic( menu, "Flush & Reload Shaders", "RefreshShaders" );
1805 create_menu_item_with_mnemonic( menu, "Find / Replace...", "FindReplaceTextures" );
1807 return textures_menu_item;
1810 ui::MenuItem TextureBrowser_constructTagsMenu( ui::Menu menu ){
1811 ui::MenuItem textures_menu_item = ui::MenuItem(new_sub_menu_item_with_mnemonic( "T_ags" ));
1813 if ( g_Layout_enableDetachableMenus.m_value ) {
1814 menu_tearoff( menu );
1817 create_menu_item_with_mnemonic( menu, "Add tag", "AddTag" );
1818 create_menu_item_with_mnemonic( menu, "Rename tag", "RenameTag" );
1819 create_menu_item_with_mnemonic( menu, "Delete tag", "DeleteTag" );
1820 menu_separator( menu );
1821 create_menu_item_with_mnemonic( menu, "Copy tags from selected", "CopyTag" );
1822 create_menu_item_with_mnemonic( menu, "Paste tags to selected", "PasteTag" );
1824 return textures_menu_item;
1827 gboolean TextureBrowser_tagMoveHelper( ui::TreeModel model, ui::TreePath path, GtkTreeIter iter, GSList** selected ){
1828 g_assert( selected != NULL );
1830 auto rowref = gtk_tree_row_reference_new( model, path );
1831 *selected = g_slist_append( *selected, rowref );
1836 void TextureBrowser_assignTags(){
1837 GSList* selected = NULL;
1839 gchar* tag_assigned;
1841 auto selection = gtk_tree_view_get_selection(g_TextureBrowser.m_available_tree );
1843 gtk_tree_selection_selected_foreach( selection, (GtkTreeSelectionForeachFunc)TextureBrowser_tagMoveHelper, &selected );
1845 if ( selected != NULL ) {
1846 for ( node = selected; node != NULL; node = node->next )
1848 auto path = gtk_tree_row_reference_get_path( (GtkTreeRowReference*)node->data );
1853 if ( gtk_tree_model_get_iter(g_TextureBrowser.m_available_store, &iter, path ) ) {
1854 gtk_tree_model_get(g_TextureBrowser.m_available_store, &iter, TAG_COLUMN, &tag_assigned, -1 );
1855 if ( !TagBuilder.CheckShaderTag( g_TextureBrowser.shader.c_str() ) ) {
1856 // create a custom shader/texture entry
1857 IShader* ishader = QERApp_Shader_ForName( g_TextureBrowser.shader.c_str() );
1858 CopiedString filename = ishader->getShaderFileName();
1860 if ( filename.empty() ) {
1862 TagBuilder.AddShaderNode( g_TextureBrowser.shader.c_str(), CUSTOM, TEXTURE );
1866 TagBuilder.AddShaderNode( g_TextureBrowser.shader.c_str(), CUSTOM, SHADER );
1870 TagBuilder.AddShaderTag( g_TextureBrowser.shader.c_str(), (char*)tag_assigned, TAG );
1872 gtk_list_store_remove( g_TextureBrowser.m_available_store, &iter );
1873 g_TextureBrowser.m_assigned_store.append(TAG_COLUMN, tag_assigned);
1878 g_slist_foreach( selected, (GFunc)gtk_tree_row_reference_free, NULL );
1881 TagBuilder.SaveXmlDoc();
1883 g_slist_free( selected );
1886 void TextureBrowser_removeTags(){
1887 GSList* selected = NULL;
1891 auto selection = gtk_tree_view_get_selection(g_TextureBrowser.m_assigned_tree );
1893 gtk_tree_selection_selected_foreach( selection, (GtkTreeSelectionForeachFunc)TextureBrowser_tagMoveHelper, &selected );
1895 if ( selected != NULL ) {
1896 for ( node = selected; node != NULL; node = node->next )
1898 auto path = gtk_tree_row_reference_get_path( (GtkTreeRowReference*)node->data );
1903 if ( gtk_tree_model_get_iter(g_TextureBrowser.m_assigned_store, &iter, path ) ) {
1904 gtk_tree_model_get(g_TextureBrowser.m_assigned_store, &iter, TAG_COLUMN, &tag, -1 );
1905 TagBuilder.DeleteShaderTag( g_TextureBrowser.shader.c_str(), tag );
1906 gtk_list_store_remove( g_TextureBrowser.m_assigned_store, &iter );
1911 g_slist_foreach( selected, (GFunc)gtk_tree_row_reference_free, NULL );
1913 // Update the "available tags list"
1914 BuildStoreAvailableTags( g_TextureBrowser.m_available_store, g_TextureBrowser.m_assigned_store, g_TextureBrowser.m_all_tags, &g_TextureBrowser );
1917 TagBuilder.SaveXmlDoc();
1919 g_slist_free( selected );
1922 void TextureBrowser_buildTagList(){
1923 g_TextureBrowser.m_all_tags_list.clear();
1925 std::set<CopiedString>::iterator iter;
1927 for ( iter = g_TextureBrowser.m_all_tags.begin(); iter != g_TextureBrowser.m_all_tags.end(); ++iter )
1929 g_TextureBrowser.m_all_tags_list.append(TAG_COLUMN, (*iter).c_str());
1933 void TextureBrowser_searchTags(){
1934 GSList* selected = NULL;
1938 char tags_searched[256];
1940 auto selection = gtk_tree_view_get_selection(g_TextureBrowser.m_treeViewTags );
1942 gtk_tree_selection_selected_foreach( selection, (GtkTreeSelectionForeachFunc)TextureBrowser_tagMoveHelper, &selected );
1944 if ( selected != NULL ) {
1945 strcpy( buffer, "/root/*/*[tag='" );
1946 strcpy( tags_searched, "[TAGS] " );
1948 for ( node = selected; node != NULL; node = node->next )
1950 auto path = gtk_tree_row_reference_get_path( (GtkTreeRowReference*)node->data );
1955 if ( gtk_tree_model_get_iter(g_TextureBrowser.m_all_tags_list, &iter, path ) ) {
1956 gtk_tree_model_get(g_TextureBrowser.m_all_tags_list, &iter, TAG_COLUMN, &tag, -1 );
1958 strcat( buffer, tag );
1959 strcat( tags_searched, tag );
1960 if ( node != g_slist_last( node ) ) {
1961 strcat( buffer, "' and tag='" );
1962 strcat( tags_searched, ", " );
1968 strcat( buffer, "']" );
1970 g_slist_foreach( selected, (GFunc)gtk_tree_row_reference_free, NULL );
1972 g_TextureBrowser.m_found_shaders.clear(); // delete old list
1973 TagBuilder.TagSearch( buffer, g_TextureBrowser.m_found_shaders );
1975 if ( !g_TextureBrowser.m_found_shaders.empty() ) { // found something
1976 size_t shaders_found = g_TextureBrowser.m_found_shaders.size();
1978 globalOutputStream() << "Found " << (unsigned int)shaders_found << " textures and shaders with " << tags_searched << "\n";
1979 ScopeDisableScreenUpdates disableScreenUpdates( "Searching...", "Loading Textures" );
1981 std::set<CopiedString>::iterator iter;
1983 for ( iter = g_TextureBrowser.m_found_shaders.begin(); iter != g_TextureBrowser.m_found_shaders.end(); iter++ )
1985 std::string path = ( *iter ).c_str();
1986 size_t pos = path.find_last_of( "/", path.size() );
1987 std::string name = path.substr( pos + 1, path.size() );
1988 path = path.substr( 0, pos + 1 );
1989 TextureDirectory_loadTexture( path.c_str(), name.c_str() );
1992 g_TextureBrowser.m_searchedTags = true;
1993 g_TextureBrowser_currentDirectory = tags_searched;
1995 g_TextureBrowser.m_nTotalHeight = 0;
1996 TextureBrowser_setOriginY( g_TextureBrowser, 0 );
1997 TextureBrowser_heightChanged( g_TextureBrowser );
1998 TextureBrowser_updateTitle();
2000 g_slist_free( selected );
2003 void TextureBrowser_toggleSearchButton(){
2004 gint page = gtk_notebook_get_current_page( GTK_NOTEBOOK( g_TextureBrowser.m_tag_notebook ) );
2006 if ( page == 0 ) { // tag page
2007 gtk_widget_show_all( g_TextureBrowser.m_search_button );
2010 g_TextureBrowser.m_search_button.hide();
2014 void TextureBrowser_constructTagNotebook(){
2015 g_TextureBrowser.m_tag_notebook = ui::Widget::from(gtk_notebook_new());
2016 ui::Widget labelTags = ui::Label( "Tags" );
2017 ui::Widget labelTextures = ui::Label( "Textures" );
2019 gtk_notebook_append_page( GTK_NOTEBOOK( g_TextureBrowser.m_tag_notebook ), g_TextureBrowser.m_scr_win_tree, labelTextures );
2020 gtk_notebook_append_page( GTK_NOTEBOOK( g_TextureBrowser.m_tag_notebook ), g_TextureBrowser.m_scr_win_tags, labelTags );
2022 g_TextureBrowser.m_tag_notebook.connect( "switch-page", G_CALLBACK( TextureBrowser_toggleSearchButton ), NULL );
2024 gtk_widget_show_all( g_TextureBrowser.m_tag_notebook );
2027 void TextureBrowser_constructSearchButton(){
2028 auto image = ui::Widget::from(gtk_image_new_from_stock( GTK_STOCK_FIND, GTK_ICON_SIZE_SMALL_TOOLBAR ));
2029 g_TextureBrowser.m_search_button = ui::Button(ui::New);
2030 g_TextureBrowser.m_search_button.connect( "clicked", G_CALLBACK( TextureBrowser_searchTags ), NULL );
2031 gtk_widget_set_tooltip_text(g_TextureBrowser.m_search_button, "Search with selected tags");
2032 g_TextureBrowser.m_search_button.add(image);
2035 void TextureBrowser_checkTagFile(){
2036 const char SHADERTAG_FILE[] = "shadertags.xml";
2037 CopiedString default_filename, rc_filename;
2038 StringOutputStream stream( 256 );
2040 stream << LocalRcPath_get();
2041 stream << SHADERTAG_FILE;
2042 rc_filename = stream.c_str();
2044 if ( file_exists( rc_filename.c_str() ) ) {
2045 g_TextureBrowser.m_tags = TagBuilder.OpenXmlDoc( rc_filename.c_str() );
2047 if ( g_TextureBrowser.m_tags ) {
2048 globalOutputStream() << "Loading tag file " << rc_filename.c_str() << ".\n";
2053 // load default tagfile
2055 stream << g_pGameDescription->mGameToolsPath.c_str();
2056 stream << SHADERTAG_FILE;
2057 default_filename = stream.c_str();
2059 if ( file_exists( default_filename.c_str() ) ) {
2060 g_TextureBrowser.m_tags = TagBuilder.OpenXmlDoc( default_filename.c_str(), rc_filename.c_str() );
2062 if ( g_TextureBrowser.m_tags ) {
2063 globalOutputStream() << "Loading default tag file " << default_filename.c_str() << ".\n";
2068 globalErrorStream() << "Unable to find default tag file " << default_filename.c_str() << ". No tag support.\n";
2073 void TextureBrowser_SetNotex(){
2074 IShader* notex = QERApp_Shader_ForName( DEFAULT_NOTEX_NAME );
2075 IShader* shadernotex = QERApp_Shader_ForName( DEFAULT_SHADERNOTEX_NAME );
2077 g_notex = notex->getTexture()->name;
2078 g_shadernotex = shadernotex->getTexture()->name;
2081 shadernotex->DecRef();
2084 ui::Widget TextureBrowser_constructWindow( ui::Window toplevel ){
2085 // The gl_widget and the tag assignment frame should be packed into a GtkVPaned with the slider
2086 // position stored in local.pref. gtk_paned_get_position() and gtk_paned_set_position() don't
2087 // seem to work in gtk 2.4 and the arrow buttons don't handle GTK_FILL, so here's another thing
2088 // for the "once-the-gtk-libs-are-updated-TODO-list" :x
2090 TextureBrowser_checkTagFile();
2091 TextureBrowser_SetNotex();
2093 GlobalShaderSystem().setActiveShadersChangedNotify( ReferenceCaller<TextureBrowser, void(), TextureBrowser_activeShadersChanged>( g_TextureBrowser ) );
2095 g_TextureBrowser.m_parent = toplevel;
2097 auto table = ui::Table(3, 3, FALSE);
2098 auto vbox = ui::VBox(FALSE, 0);
2099 table.attach(vbox, {0, 1, 1, 3}, {GTK_FILL, GTK_FILL});
2102 ui::Widget menu_bar{ui::null};
2105 menu_bar = ui::Widget::from(gtk_menu_bar_new());
2106 auto menu_view = ui::Menu(ui::New);
2107 auto view_item = TextureBrowser_constructViewMenu( menu_view );
2108 gtk_menu_item_set_submenu( GTK_MENU_ITEM( view_item ), menu_view );
2109 gtk_menu_shell_append( GTK_MENU_SHELL( menu_bar ), view_item );
2111 auto menu_tools = ui::Menu(ui::New);
2112 auto tools_item = TextureBrowser_constructToolsMenu( menu_tools );
2113 gtk_menu_item_set_submenu( GTK_MENU_ITEM( tools_item ), menu_tools );
2114 gtk_menu_shell_append( GTK_MENU_SHELL( menu_bar ), tools_item );
2116 table.attach(menu_bar, {0, 3, 0, 1}, {GTK_FILL, GTK_SHRINK});
2119 { // Texture TreeView
2120 g_TextureBrowser.m_scr_win_tree = ui::ScrolledWindow(ui::New);
2121 gtk_container_set_border_width( GTK_CONTAINER( g_TextureBrowser.m_scr_win_tree ), 0 );
2123 // vertical only scrolling for treeview
2124 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( g_TextureBrowser.m_scr_win_tree ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
2126 g_TextureBrowser.m_scr_win_tree.show();
2128 TextureBrowser_createTreeViewTree();
2130 gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW( g_TextureBrowser.m_scr_win_tree ), g_TextureBrowser.m_treeViewTree );
2131 g_TextureBrowser.m_treeViewTree.show();
2133 { // gl_widget scrollbar
2134 auto w = ui::Widget::from(gtk_vscrollbar_new( ui::Adjustment( 0,0,0,1,1,0 ) ));
2135 table.attach(w, {2, 3, 1, 2}, {GTK_SHRINK, GTK_FILL});
2137 g_TextureBrowser.m_texture_scroll = w;
2139 auto vadjustment = ui::Adjustment::from(gtk_range_get_adjustment( GTK_RANGE( g_TextureBrowser.m_texture_scroll ) ));
2140 vadjustment.connect( "value_changed", G_CALLBACK( TextureBrowser_verticalScroll ), &g_TextureBrowser );
2142 g_TextureBrowser.m_texture_scroll.visible(g_TextureBrowser.m_showTextureScrollbar);
2145 g_TextureBrowser.m_gl_widget = glwidget_new( FALSE );
2146 g_object_ref( g_TextureBrowser.m_gl_widget._handle );
2148 gtk_widget_set_events( g_TextureBrowser.m_gl_widget, GDK_DESTROY | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_SCROLL_MASK );
2149 gtk_widget_set_can_focus( g_TextureBrowser.m_gl_widget, true );
2151 table.attach(g_TextureBrowser.m_gl_widget, {1, 2, 1, 2});
2152 g_TextureBrowser.m_gl_widget.show();
2154 g_TextureBrowser.m_sizeHandler = g_TextureBrowser.m_gl_widget.connect( "size_allocate", G_CALLBACK( TextureBrowser_size_allocate ), &g_TextureBrowser );
2155 g_TextureBrowser.m_exposeHandler = g_TextureBrowser.m_gl_widget.on_render( G_CALLBACK( TextureBrowser_expose ), &g_TextureBrowser );
2157 g_TextureBrowser.m_gl_widget.connect( "button_press_event", G_CALLBACK( TextureBrowser_button_press ), &g_TextureBrowser );
2158 g_TextureBrowser.m_gl_widget.connect( "button_release_event", G_CALLBACK( TextureBrowser_button_release ), &g_TextureBrowser );
2159 g_TextureBrowser.m_gl_widget.connect( "motion_notify_event", G_CALLBACK( TextureBrowser_motion ), &g_TextureBrowser );
2160 g_TextureBrowser.m_gl_widget.connect( "scroll_event", G_CALLBACK( TextureBrowser_scroll ), &g_TextureBrowser );
2164 if ( g_TextureBrowser.m_tags ) {
2165 { // fill tag GtkListStore
2166 g_TextureBrowser.m_all_tags_list = ui::ListStore::from(gtk_list_store_new( N_COLUMNS, G_TYPE_STRING ));
2167 auto sortable = GTK_TREE_SORTABLE( g_TextureBrowser.m_all_tags_list );
2168 gtk_tree_sortable_set_sort_column_id( sortable, TAG_COLUMN, GTK_SORT_ASCENDING );
2170 TagBuilder.GetAllTags( g_TextureBrowser.m_all_tags );
2171 TextureBrowser_buildTagList();
2174 auto menu_tags = ui::Menu(ui::New);
2175 auto tags_item = TextureBrowser_constructTagsMenu( menu_tags );
2176 gtk_menu_item_set_submenu( GTK_MENU_ITEM( tags_item ), menu_tags );
2177 gtk_menu_shell_append( GTK_MENU_SHELL( menu_bar ), tags_item );
2180 g_TextureBrowser.m_scr_win_tags = ui::ScrolledWindow(ui::New);
2181 gtk_container_set_border_width( GTK_CONTAINER( g_TextureBrowser.m_scr_win_tags ), 0 );
2183 // vertical only scrolling for treeview
2184 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( g_TextureBrowser.m_scr_win_tags ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
2186 TextureBrowser_createTreeViewTags();
2188 auto selection = gtk_tree_view_get_selection(g_TextureBrowser.m_treeViewTags );
2189 gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE );
2191 gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW( g_TextureBrowser.m_scr_win_tags ), g_TextureBrowser.m_treeViewTags );
2192 g_TextureBrowser.m_treeViewTags.show();
2194 { // Texture/Tag notebook
2195 TextureBrowser_constructTagNotebook();
2196 vbox.pack_start( g_TextureBrowser.m_tag_notebook, TRUE, TRUE, 0 );
2198 { // Tag search button
2199 TextureBrowser_constructSearchButton();
2200 vbox.pack_end(g_TextureBrowser.m_search_button, FALSE, FALSE, 0);
2202 auto frame_table = ui::Table(3, 3, FALSE);
2205 g_TextureBrowser.m_tag_frame = ui::Frame( "Tag assignment" );
2206 gtk_frame_set_label_align( GTK_FRAME( g_TextureBrowser.m_tag_frame ), 0.5, 0.5 );
2207 gtk_frame_set_shadow_type( GTK_FRAME( g_TextureBrowser.m_tag_frame ), GTK_SHADOW_NONE );
2209 table.attach(g_TextureBrowser.m_tag_frame, {1, 3, 2, 3}, {GTK_FILL, GTK_SHRINK});
2213 g_TextureBrowser.m_tag_frame.add(frame_table);
2215 { // assigned tag list
2216 ui::Widget scrolled_win = ui::ScrolledWindow(ui::New);
2217 gtk_container_set_border_width( GTK_CONTAINER( scrolled_win ), 0 );
2218 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scrolled_win ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
2220 g_TextureBrowser.m_assigned_store = ui::ListStore::from(gtk_list_store_new( N_COLUMNS, G_TYPE_STRING ));
2222 auto sortable = GTK_TREE_SORTABLE( g_TextureBrowser.m_assigned_store );
2223 gtk_tree_sortable_set_sort_column_id( sortable, TAG_COLUMN, GTK_SORT_ASCENDING );
2225 auto renderer = ui::CellRendererText(ui::New);
2227 g_TextureBrowser.m_assigned_tree = ui::TreeView(ui::TreeModel::from(g_TextureBrowser.m_assigned_store._handle));
2228 g_TextureBrowser.m_assigned_store.unref();
2229 g_TextureBrowser.m_assigned_tree.connect( "row-activated", (GCallback) TextureBrowser_removeTags, NULL );
2230 gtk_tree_view_set_headers_visible(g_TextureBrowser.m_assigned_tree, FALSE );
2232 auto selection = gtk_tree_view_get_selection(g_TextureBrowser.m_assigned_tree );
2233 gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE );
2235 auto column = ui::TreeViewColumn( "", renderer, {{"text", TAG_COLUMN}} );
2236 gtk_tree_view_append_column(g_TextureBrowser.m_assigned_tree, column );
2237 g_TextureBrowser.m_assigned_tree.show();
2239 scrolled_win.show();
2240 gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW( scrolled_win ), g_TextureBrowser.m_assigned_tree );
2242 frame_table.attach(scrolled_win, {0, 1, 1, 3}, {GTK_FILL, GTK_FILL});
2244 { // available tag list
2245 ui::Widget scrolled_win = ui::ScrolledWindow(ui::New);
2246 gtk_container_set_border_width( GTK_CONTAINER( scrolled_win ), 0 );
2247 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scrolled_win ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
2249 g_TextureBrowser.m_available_store = ui::ListStore::from(gtk_list_store_new( N_COLUMNS, G_TYPE_STRING ));
2250 auto sortable = GTK_TREE_SORTABLE( g_TextureBrowser.m_available_store );
2251 gtk_tree_sortable_set_sort_column_id( sortable, TAG_COLUMN, GTK_SORT_ASCENDING );
2253 auto renderer = ui::CellRendererText(ui::New);
2255 g_TextureBrowser.m_available_tree = ui::TreeView(ui::TreeModel::from(g_TextureBrowser.m_available_store._handle));
2256 g_TextureBrowser.m_available_store.unref();
2257 g_TextureBrowser.m_available_tree.connect( "row-activated", (GCallback) TextureBrowser_assignTags, NULL );
2258 gtk_tree_view_set_headers_visible(g_TextureBrowser.m_available_tree, FALSE );
2260 auto selection = gtk_tree_view_get_selection(g_TextureBrowser.m_available_tree );
2261 gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE );
2263 auto column = ui::TreeViewColumn( "", renderer, {{"text", TAG_COLUMN}} );
2264 gtk_tree_view_append_column(g_TextureBrowser.m_available_tree, column );
2265 g_TextureBrowser.m_available_tree.show();
2267 scrolled_win.show();
2268 gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW( scrolled_win ), g_TextureBrowser.m_available_tree );
2270 frame_table.attach(scrolled_win, {2, 3, 1, 3}, {GTK_FILL, GTK_FILL});
2272 { // tag arrow buttons
2273 auto m_btn_left = ui::Button(ui::New);
2274 auto m_btn_right = ui::Button(ui::New);
2275 auto m_arrow_left = ui::Widget::from(gtk_arrow_new( GTK_ARROW_LEFT, GTK_SHADOW_OUT ));
2276 auto m_arrow_right = ui::Widget::from(gtk_arrow_new( GTK_ARROW_RIGHT, GTK_SHADOW_OUT ));
2277 m_btn_left.add(m_arrow_left);
2278 m_btn_right.add(m_arrow_right);
2280 // workaround. the size of the tag frame depends of the requested size of the arrow buttons.
2281 m_arrow_left.dimensions(-1, 68);
2282 m_arrow_right.dimensions(-1, 68);
2284 frame_table.attach(m_btn_left, {1, 2, 1, 2}, {GTK_SHRINK, GTK_EXPAND});
2285 frame_table.attach(m_btn_right, {1, 2, 2, 3}, {GTK_SHRINK, GTK_EXPAND});
2287 m_btn_left.connect( "clicked", G_CALLBACK( TextureBrowser_assignTags ), NULL );
2288 m_btn_right.connect( "clicked", G_CALLBACK( TextureBrowser_removeTags ), NULL );
2292 m_arrow_left.show();
2293 m_arrow_right.show();
2295 { // tag fram labels
2296 ui::Widget m_lbl_assigned = ui::Label( "Assigned" );
2297 ui::Widget m_lbl_unassigned = ui::Label( "Available" );
2299 frame_table.attach(m_lbl_assigned, {0, 1, 0, 1}, {GTK_EXPAND, GTK_SHRINK});
2300 frame_table.attach(m_lbl_unassigned, {2, 3, 0, 1}, {GTK_EXPAND, GTK_SHRINK});
2302 m_lbl_assigned.show();
2303 m_lbl_unassigned.show();
2306 else { // no tag support, show the texture tree only
2307 vbox.pack_start( g_TextureBrowser.m_scr_win_tree, TRUE, TRUE, 0 );
2310 // TODO do we need this?
2311 //gtk_container_set_focus_chain(GTK_CONTAINER(hbox_table), NULL);
2316 void TextureBrowser_destroyWindow(){
2317 GlobalShaderSystem().setActiveShadersChangedNotify( Callback<void()>() );
2319 g_signal_handler_disconnect( G_OBJECT( g_TextureBrowser.m_gl_widget ), g_TextureBrowser.m_sizeHandler );
2320 g_signal_handler_disconnect( G_OBJECT( g_TextureBrowser.m_gl_widget ), g_TextureBrowser.m_exposeHandler );
2322 g_TextureBrowser.m_gl_widget.unref();
2325 const Vector3& TextureBrowser_getBackgroundColour( TextureBrowser& textureBrowser ){
2326 return textureBrowser.color_textureback;
2329 void TextureBrowser_setBackgroundColour( TextureBrowser& textureBrowser, const Vector3& colour ){
2330 textureBrowser.color_textureback = colour;
2331 TextureBrowser_queueDraw( textureBrowser );
2334 void TextureBrowser_selectionHelper( ui::TreeModel model, ui::TreePath path, GtkTreeIter* iter, GSList** selected ){
2335 g_assert( selected != NULL );
2338 gtk_tree_model_get( model, iter, TAG_COLUMN, &name, -1 );
2339 *selected = g_slist_append( *selected, name );
2342 void TextureBrowser_shaderInfo(){
2343 const char* name = TextureBrowser_GetSelectedShader( g_TextureBrowser );
2344 IShader* shader = QERApp_Shader_ForName( name );
2346 DoShaderInfoDlg( name, shader->getShaderFileName(), "Shader Info" );
2351 void TextureBrowser_addTag(){
2354 EMessageBoxReturn result = DoShaderTagDlg( &tag, "Add shader tag" );
2356 if ( result == eIDOK && !tag.empty() ) {
2358 g_TextureBrowser.m_all_tags.insert( tag.c_str() );
2359 gtk_list_store_append( g_TextureBrowser.m_available_store, &iter );
2360 gtk_list_store_set( g_TextureBrowser.m_available_store, &iter, TAG_COLUMN, tag.c_str(), -1 );
2362 // Select the currently added tag in the available list
2363 auto selection = gtk_tree_view_get_selection(g_TextureBrowser.m_available_tree );
2364 gtk_tree_selection_select_iter( selection, &iter );
2366 g_TextureBrowser.m_all_tags_list.append(TAG_COLUMN, tag.c_str());
2370 void TextureBrowser_renameTag(){
2371 /* WORKAROUND: The tag treeview is set to GTK_SELECTION_MULTIPLE. Because
2372 gtk_tree_selection_get_selected() doesn't work with GTK_SELECTION_MULTIPLE,
2373 we need to count the number of selected rows first and use
2374 gtk_tree_selection_selected_foreach() then to go through the list of selected
2375 rows (which always containins a single row).
2378 GSList* selected = NULL;
2380 auto selection = gtk_tree_view_get_selection(g_TextureBrowser.m_treeViewTags );
2381 gtk_tree_selection_selected_foreach( selection, GtkTreeSelectionForeachFunc( TextureBrowser_selectionHelper ), &selected );
2383 if ( g_slist_length( selected ) == 1 ) { // we only rename a single tag
2384 CopiedString newTag;
2385 EMessageBoxReturn result = DoShaderTagDlg( &newTag, "Rename shader tag" );
2387 if ( result == eIDOK && !newTag.empty() ) {
2388 GtkTreeIter iterList;
2390 gchar* oldTag = (char*)selected->data;
2392 bool row = gtk_tree_model_get_iter_first(g_TextureBrowser.m_all_tags_list, &iterList ) != 0;
2396 gtk_tree_model_get(g_TextureBrowser.m_all_tags_list, &iterList, TAG_COLUMN, &rowTag, -1 );
2398 if ( strcmp( rowTag, oldTag ) == 0 ) {
2399 gtk_list_store_set( g_TextureBrowser.m_all_tags_list, &iterList, TAG_COLUMN, newTag.c_str(), -1 );
2401 row = gtk_tree_model_iter_next(g_TextureBrowser.m_all_tags_list, &iterList ) != 0;
2404 TagBuilder.RenameShaderTag( oldTag, newTag.c_str() );
2406 g_TextureBrowser.m_all_tags.erase( (CopiedString)oldTag );
2407 g_TextureBrowser.m_all_tags.insert( newTag );
2409 BuildStoreAssignedTags( g_TextureBrowser.m_assigned_store, g_TextureBrowser.shader.c_str(), &g_TextureBrowser );
2410 BuildStoreAvailableTags( g_TextureBrowser.m_available_store, g_TextureBrowser.m_assigned_store, g_TextureBrowser.m_all_tags, &g_TextureBrowser );
2415 ui::alert( g_TextureBrowser.m_parent, "Select a single tag for renaming." );
2419 void TextureBrowser_deleteTag(){
2420 GSList* selected = NULL;
2422 auto selection = gtk_tree_view_get_selection(g_TextureBrowser.m_treeViewTags );
2423 gtk_tree_selection_selected_foreach( selection, GtkTreeSelectionForeachFunc( TextureBrowser_selectionHelper ), &selected );
2425 if ( g_slist_length( selected ) == 1 ) { // we only delete a single tag
2426 auto result = ui::alert( g_TextureBrowser.m_parent, "Are you sure you want to delete the selected tag?", "Delete Tag", ui::alert_type::YESNO, ui::alert_icon::Question );
2428 if ( result == ui::alert_response::YES ) {
2429 GtkTreeIter iterSelected;
2432 gchar* tagSelected = (char*)selected->data;
2434 bool row = gtk_tree_model_get_iter_first(g_TextureBrowser.m_all_tags_list, &iterSelected ) != 0;
2438 gtk_tree_model_get(g_TextureBrowser.m_all_tags_list, &iterSelected, TAG_COLUMN, &rowTag, -1 );
2440 if ( strcmp( rowTag, tagSelected ) == 0 ) {
2441 gtk_list_store_remove( g_TextureBrowser.m_all_tags_list, &iterSelected );
2444 row = gtk_tree_model_iter_next(g_TextureBrowser.m_all_tags_list, &iterSelected ) != 0;
2447 TagBuilder.DeleteTag( tagSelected );
2448 g_TextureBrowser.m_all_tags.erase( (CopiedString)tagSelected );
2450 BuildStoreAssignedTags( g_TextureBrowser.m_assigned_store, g_TextureBrowser.shader.c_str(), &g_TextureBrowser );
2451 BuildStoreAvailableTags( g_TextureBrowser.m_available_store, g_TextureBrowser.m_assigned_store, g_TextureBrowser.m_all_tags, &g_TextureBrowser );
2455 ui::alert( g_TextureBrowser.m_parent, "Select a single tag for deletion." );
2459 void TextureBrowser_copyTag(){
2460 g_TextureBrowser.m_copied_tags.clear();
2461 TagBuilder.GetShaderTags( g_TextureBrowser.shader.c_str(), g_TextureBrowser.m_copied_tags );
2464 void TextureBrowser_pasteTag(){
2465 IShader* ishader = QERApp_Shader_ForName( g_TextureBrowser.shader.c_str() );
2466 CopiedString shader = g_TextureBrowser.shader.c_str();
2468 if ( !TagBuilder.CheckShaderTag( shader.c_str() ) ) {
2469 CopiedString shaderFile = ishader->getShaderFileName();
2470 if ( shaderFile.empty() ) {
2472 TagBuilder.AddShaderNode( shader.c_str(), CUSTOM, TEXTURE );
2477 TagBuilder.AddShaderNode( shader.c_str(), CUSTOM, SHADER );
2480 for ( size_t i = 0; i < g_TextureBrowser.m_copied_tags.size(); ++i )
2482 TagBuilder.AddShaderTag( shader.c_str(), g_TextureBrowser.m_copied_tags[i].c_str(), TAG );
2487 for ( size_t i = 0; i < g_TextureBrowser.m_copied_tags.size(); ++i )
2489 if ( !TagBuilder.CheckShaderTag( shader.c_str(), g_TextureBrowser.m_copied_tags[i].c_str() ) ) {
2490 // the tag doesn't exist - let's add it
2491 TagBuilder.AddShaderTag( shader.c_str(), g_TextureBrowser.m_copied_tags[i].c_str(), TAG );
2498 TagBuilder.SaveXmlDoc();
2499 BuildStoreAssignedTags( g_TextureBrowser.m_assigned_store, shader.c_str(), &g_TextureBrowser );
2500 BuildStoreAvailableTags( g_TextureBrowser.m_available_store, g_TextureBrowser.m_assigned_store, g_TextureBrowser.m_all_tags, &g_TextureBrowser );
2503 void TextureBrowser_RefreshShaders(){
2504 ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", "Loading Shaders" );
2505 GlobalShaderSystem().refresh();
2507 auto selection = gtk_tree_view_get_selection(GlobalTextureBrowser().m_treeViewTree);
2508 GtkTreeModel* model = NULL;
2510 if ( gtk_tree_selection_get_selected (selection, &model, &iter) )
2512 gchar dirName[1024];
2515 gtk_tree_model_get( model, &iter, 0, &buffer, -1 );
2516 strcpy( dirName, buffer );
2518 if ( !TextureBrowser_showWads() ) {
2519 strcat( dirName, "/" );
2521 TextureBrowser_ShowDirectory( GlobalTextureBrowser(), dirName );
2522 TextureBrowser_queueDraw( GlobalTextureBrowser() );
2526 void TextureBrowser_ToggleShowShaders(){
2527 g_TextureBrowser.m_showShaders ^= 1;
2528 g_TextureBrowser.m_showshaders_item.update();
2529 TextureBrowser_queueDraw( g_TextureBrowser );
2532 void TextureBrowser_ToggleShowShaderListOnly(){
2533 g_TextureBrowser_shaderlistOnly ^= 1;
2534 g_TextureBrowser.m_showshaderlistonly_item.update();
2536 TextureBrowser_constructTreeStore();
2539 void TextureBrowser_showAll(){
2540 g_TextureBrowser_currentDirectory = "";
2541 g_TextureBrowser.m_searchedTags = false;
2542 TextureBrowser_heightChanged( g_TextureBrowser );
2543 TextureBrowser_updateTitle();
2546 void TextureBrowser_showUntagged(){
2547 auto result = ui::alert( g_TextureBrowser.m_parent, "WARNING! This function might need a lot of memory and time. Are you sure you want to use it?", "Show Untagged", ui::alert_type::YESNO, ui::alert_icon::Warning );
2549 if ( result == ui::alert_response::YES ) {
2550 g_TextureBrowser.m_found_shaders.clear();
2551 TagBuilder.GetUntagged( g_TextureBrowser.m_found_shaders );
2552 std::set<CopiedString>::iterator iter;
2554 ScopeDisableScreenUpdates disableScreenUpdates( "Searching untagged textures...", "Loading Textures" );
2556 for ( iter = g_TextureBrowser.m_found_shaders.begin(); iter != g_TextureBrowser.m_found_shaders.end(); iter++ )
2558 std::string path = ( *iter ).c_str();
2559 size_t pos = path.find_last_of( "/", path.size() );
2560 std::string name = path.substr( pos + 1, path.size() );
2561 path = path.substr( 0, pos + 1 );
2562 TextureDirectory_loadTexture( path.c_str(), name.c_str() );
2563 globalErrorStream() << path.c_str() << name.c_str() << "\n";
2566 g_TextureBrowser_currentDirectory = "Untagged";
2567 TextureBrowser_queueDraw( GlobalTextureBrowser() );
2568 TextureBrowser_heightChanged( g_TextureBrowser );
2569 TextureBrowser_updateTitle();
2573 void TextureBrowser_FixedSize(){
2574 g_TextureBrowser_fixedSize ^= 1;
2575 GlobalTextureBrowser().m_fixedsize_item.update();
2576 TextureBrowser_activeShadersChanged( GlobalTextureBrowser() );
2579 void TextureBrowser_FilterMissing(){
2580 g_TextureBrowser_filterMissing ^= 1;
2581 GlobalTextureBrowser().m_filternotex_item.update();
2582 TextureBrowser_activeShadersChanged( GlobalTextureBrowser() );
2583 TextureBrowser_RefreshShaders();
2586 void TextureBrowser_FilterFallback(){
2587 g_TextureBrowser_filterFallback ^= 1;
2588 GlobalTextureBrowser().m_hidenotex_item.update();
2589 TextureBrowser_activeShadersChanged( GlobalTextureBrowser() );
2590 TextureBrowser_RefreshShaders();
2593 void TextureBrowser_EnableAlpha(){
2594 g_TextureBrowser_enableAlpha ^= 1;
2595 GlobalTextureBrowser().m_enablealpha_item.update();
2596 TextureBrowser_activeShadersChanged( GlobalTextureBrowser() );
2599 void TextureBrowser_exportTitle( const Callback<void(const char *)> & importer ){
2600 StringOutputStream buffer( 64 );
2601 buffer << "Textures: ";
2602 if ( !string_empty( g_TextureBrowser_currentDirectory.c_str() ) ) {
2603 buffer << g_TextureBrowser_currentDirectory.c_str();
2609 importer( buffer.c_str() );
2612 struct TextureScale {
2613 static void Export(const TextureBrowser &self, const Callback<void(int)> &returnz) {
2614 switch (self.m_textureScale) {
2633 static void Import(TextureBrowser &self, int value) {
2636 TextureBrowser_setScale(self, 10);
2639 TextureBrowser_setScale(self, 25);
2642 TextureBrowser_setScale(self, 50);
2645 TextureBrowser_setScale(self, 100);
2648 TextureBrowser_setScale(self, 200);
2654 struct UniformTextureSize {
2655 static void Export(const TextureBrowser &self, const Callback<void(int)> &returnz) {
2656 returnz(g_TextureBrowser.m_uniformTextureSize);
2659 static void Import(TextureBrowser &self, int value) {
2661 TextureBrowser_setUniformSize(self, value);
2665 struct UniformTextureMinSize {
2666 static void Export(const TextureBrowser &self, const Callback<void(int)> &returnz) {
2667 returnz(g_TextureBrowser.m_uniformTextureMinSize);
2670 static void Import(TextureBrowser &self, int value) {
2672 TextureBrowser_setUniformSize(self, value);
2676 void TextureBrowser_constructPreferences( PreferencesPage& page ){
2677 page.appendCheckBox(
2678 "", "Texture scrollbar",
2679 make_property<TextureBrowser_ShowScrollbar>(GlobalTextureBrowser())
2682 const char* texture_scale[] = { "10%", "25%", "50%", "100%", "200%" };
2684 "Texture Thumbnail Scale",
2685 STRING_ARRAY_RANGE( texture_scale ),
2686 make_property<TextureScale>(GlobalTextureBrowser())
2689 page.appendSpinner( "Thumbnails Max Size", GlobalTextureBrowser().m_uniformTextureSize, GlobalTextureBrowser().m_uniformTextureSize, 16, 8192 );
2690 page.appendSpinner( "Thumbnails Min Size", GlobalTextureBrowser().m_uniformTextureMinSize, GlobalTextureBrowser().m_uniformTextureMinSize, 16, 8192 );
2691 page.appendEntry( "Mousewheel Increment", GlobalTextureBrowser().m_mouseWheelScrollIncrement );
2693 const char* startup_shaders[] = { "None", TextureBrowser_getComonShadersName() };
2694 page.appendCombo( "Load Shaders at Startup", reinterpret_cast<int&>( GlobalTextureBrowser().m_startupShaders ), STRING_ARRAY_RANGE( startup_shaders ) );
2698 void TextureBrowser_constructPage( PreferenceGroup& group ){
2699 PreferencesPage page( group.createPage( "Texture Browser", "Texture Browser Preferences" ) );
2700 TextureBrowser_constructPreferences( page );
2703 void TextureBrowser_registerPreferencesPage(){
2704 PreferencesDialog_addSettingsPage( makeCallbackF(TextureBrowser_constructPage) );
2708 #include "preferencesystem.h"
2709 #include "stringio.h"
2712 void TextureClipboard_textureSelected( const char* shader );
2714 void TextureBrowser_Construct(){
2715 GlobalCommands_insert( "ShaderInfo", makeCallbackF(TextureBrowser_shaderInfo) );
2716 GlobalCommands_insert( "ShowUntagged", makeCallbackF(TextureBrowser_showUntagged) );
2717 GlobalCommands_insert( "AddTag", makeCallbackF(TextureBrowser_addTag) );
2718 GlobalCommands_insert( "RenameTag", makeCallbackF(TextureBrowser_renameTag) );
2719 GlobalCommands_insert( "DeleteTag", makeCallbackF(TextureBrowser_deleteTag) );
2720 GlobalCommands_insert( "CopyTag", makeCallbackF(TextureBrowser_copyTag) );
2721 GlobalCommands_insert( "PasteTag", makeCallbackF(TextureBrowser_pasteTag) );
2722 GlobalCommands_insert( "RefreshShaders", makeCallbackF(VFS_Refresh) );
2723 GlobalToggles_insert( "ShowInUse", makeCallbackF(TextureBrowser_ToggleHideUnused), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_hideunused_item ), Accelerator( 'U' ) );
2724 GlobalCommands_insert( "ShowAllTextures", makeCallbackF(TextureBrowser_showAll), Accelerator( 'A', (GdkModifierType)GDK_CONTROL_MASK ) );
2725 GlobalCommands_insert( "ToggleTextures", makeCallbackF(TextureBrowser_toggleShow), Accelerator( 'T' ) );
2726 GlobalToggles_insert( "ToggleShowShaders", makeCallbackF(TextureBrowser_ToggleShowShaders), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_showshaders_item ) );
2727 GlobalToggles_insert( "ToggleShowShaderlistOnly", makeCallbackF(TextureBrowser_ToggleShowShaderListOnly), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_showshaderlistonly_item ) );
2728 GlobalToggles_insert( "FixedSize", makeCallbackF(TextureBrowser_FixedSize), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_fixedsize_item ) );
2729 GlobalToggles_insert( "FilterMissing", makeCallbackF(TextureBrowser_FilterMissing), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_filternotex_item ) );
2730 GlobalToggles_insert( "FilterFallback", makeCallbackF(TextureBrowser_FilterFallback), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_hidenotex_item ) );
2731 GlobalToggles_insert( "EnableAlpha", makeCallbackF(TextureBrowser_EnableAlpha), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_enablealpha_item ) );
2733 GlobalPreferenceSystem().registerPreference( "TextureScale", make_property_string<TextureScale>(g_TextureBrowser) );
2734 GlobalPreferenceSystem().registerPreference( "UniformTextureSize", make_property_string<UniformTextureSize>(g_TextureBrowser) );
2735 GlobalPreferenceSystem().registerPreference( "UniformTextureMinSize", make_property_string<UniformTextureMinSize>(g_TextureBrowser) );
2736 GlobalPreferenceSystem().registerPreference( "TextureScrollbar", make_property_string<TextureBrowser_ShowScrollbar>(GlobalTextureBrowser()));
2737 GlobalPreferenceSystem().registerPreference( "ShowShaders", make_property_string( GlobalTextureBrowser().m_showShaders ) );
2738 GlobalPreferenceSystem().registerPreference( "ShowShaderlistOnly", make_property_string( g_TextureBrowser_shaderlistOnly ) );
2739 GlobalPreferenceSystem().registerPreference( "FixedSize", make_property_string( g_TextureBrowser_fixedSize ) );
2740 GlobalPreferenceSystem().registerPreference( "FilterMissing", make_property_string( g_TextureBrowser_filterMissing ) );
2741 GlobalPreferenceSystem().registerPreference( "EnableAlpha", make_property_string( g_TextureBrowser_enableAlpha ) );
2742 GlobalPreferenceSystem().registerPreference( "LoadShaders", make_property_string( reinterpret_cast<int&>( GlobalTextureBrowser().m_startupShaders ) ) );
2743 GlobalPreferenceSystem().registerPreference( "WheelMouseInc", make_property_string( GlobalTextureBrowser().m_mouseWheelScrollIncrement ) );
2744 GlobalPreferenceSystem().registerPreference( "SI_Colors0", make_property_string( GlobalTextureBrowser().color_textureback ) );
2746 g_TextureBrowser.shader = texdef_name_default();
2748 Textures_setModeChangedNotify( ReferenceCaller<TextureBrowser, void(), TextureBrowser_queueDraw>( g_TextureBrowser ) );
2750 TextureBrowser_registerPreferencesPage();
2752 GlobalShaderSystem().attach( g_ShadersObserver );
2754 TextureBrowser_textureSelected = TextureClipboard_textureSelected;
2757 void TextureBrowser_Destroy(){
2758 GlobalShaderSystem().detach( g_ShadersObserver );
2760 Textures_setModeChangedNotify( Callback<void()>() );