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"
35 #include "ifilesystem.h"
39 #include "moduleobserver.h"
45 #include <uilib/uilib.h>
47 #include "signal/signal.h"
48 #include "math/vector.h"
49 #include "texturelib.h"
50 #include "string/string.h"
51 #include "shaderlib.h"
54 #include "stream/memstream.h"
55 #include "stream/textfilestream.h"
56 #include "stream/stringstream.h"
62 #include "gtkutil/menu.h"
63 #include "gtkutil/nonmodal.h"
64 #include "gtkutil/cursor.h"
65 #include "gtkutil/widget.h"
66 #include "gtkutil/glwidget.h"
67 #include "gtkutil/messagebox.h"
73 #include "brush_primit.h"
74 #include "brushmanip.h"
75 #include "patchmanip.h"
80 #include "mainframe.h"
81 #include "findtexturedialog.h"
82 #include "surfacedialog.h"
83 #include "patchdialog.h"
84 #include "groupdialog.h"
85 #include "preferences.h"
89 #define NOTEX_BASENAME "notex"
90 #define SHADERNOTEX_BASENAME "shadernotex"
92 bool TextureBrowser_showWads(){
93 return !string_empty( g_pGameDescription->getKeyValue( "show_wads" ) );
96 void TextureBrowser_queueDraw( TextureBrowser& textureBrowser );
98 bool string_equal_start( const char* string, StringRange start ){
99 return string_equal_n( string, start.first, start.last - start.first );
102 typedef std::set<CopiedString> TextureGroups;
104 void TextureGroups_addWad( TextureGroups& groups, const char* archive ){
105 if ( extension_equal( path_get_extension( archive ), "wad" ) ) {
107 groups.insert( archive );
109 CopiedString archiveBaseName( path_get_filename_start( archive ), path_get_filename_base_end( archive ) );
110 groups.insert( archiveBaseName );
114 typedef ReferenceCaller1<TextureGroups, const char*, TextureGroups_addWad> TextureGroupsAddWadCaller;
118 bool g_TextureBrowser_shaderlistOnly = false;
119 bool g_TextureBrowser_fixedSize = true;
120 bool g_TextureBrowser_filterMissing = false;
121 bool g_TextureBrowser_filterFallback = true;
122 bool g_TextureBrowser_enableAlpha = true;
125 CopiedString g_notex;
126 CopiedString g_shadernotex;
127 bool isMissing(const char* name);
128 bool isNotex(const char* name);
130 bool isMissing(const char* name){
131 if ( string_equal( g_notex.c_str(), name ) ) {
134 if ( string_equal( g_shadernotex.c_str(), name ) ) {
140 bool isNotex(const char* name){
141 if ( string_equal_suffix( name, "/" NOTEX_BASENAME ) ) {
144 if ( string_equal_suffix( name, "/" SHADERNOTEX_BASENAME ) ) {
150 void TextureGroups_addShader( TextureGroups& groups, const char* shaderName ){
151 const char* texture = path_make_relative( shaderName, "textures/" );
153 // hide notex / shadernotex images
154 if ( g_TextureBrowser_filterFallback ) {
155 if ( isNotex( shaderName ) ) {
158 if ( isNotex( texture ) ) {
163 if ( texture != shaderName ) {
164 const char* last = path_remove_directory( texture );
165 if ( !string_empty( last ) ) {
166 groups.insert( CopiedString( StringRange( texture, --last ) ) );
170 typedef ReferenceCaller1<TextureGroups, const char*, TextureGroups_addShader> TextureGroupsAddShaderCaller;
172 void TextureGroups_addDirectory( TextureGroups& groups, const char* directory ){
173 groups.insert( directory );
175 typedef ReferenceCaller1<TextureGroups, const char*, TextureGroups_addDirectory> TextureGroupsAddDirectoryCaller;
177 class DeferredAdjustment
181 typedef void ( *ValueChangedFunction )( void* data, gdouble value );
182 ValueChangedFunction m_function;
185 static gboolean deferred_value_changed( gpointer data ){
186 reinterpret_cast<DeferredAdjustment*>( data )->m_function(
187 reinterpret_cast<DeferredAdjustment*>( data )->m_data,
188 reinterpret_cast<DeferredAdjustment*>( data )->m_value
190 reinterpret_cast<DeferredAdjustment*>( data )->m_handler = 0;
191 reinterpret_cast<DeferredAdjustment*>( data )->m_value = 0;
195 DeferredAdjustment( ValueChangedFunction function, void* data ) : m_value( 0 ), m_handler( 0 ), m_function( function ), m_data( data ){
198 if ( m_handler != 0 ) {
199 g_source_remove( m_handler );
200 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 );
209 static void adjustment_value_changed( GtkAdjustment *adjustment, DeferredAdjustment* self ){
210 self->value_changed( gtk_adjustment_get_value(adjustment) );
216 class TextureBrowser;
218 typedef ReferenceCaller<TextureBrowser, TextureBrowser_queueDraw> TextureBrowserQueueDrawCaller;
220 void TextureBrowser_scrollChanged( void* data, gdouble value );
225 STARTUPSHADERS_NONE = 0,
226 STARTUPSHADERS_COMMON,
229 void TextureBrowser_hideUnusedExport( const BoolImportCallback& importer );
230 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_hideUnusedExport> TextureBrowserHideUnusedExport;
232 void TextureBrowser_showShadersExport( const BoolImportCallback& importer );
233 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_showShadersExport> TextureBrowserShowShadersExport;
235 void TextureBrowser_showShaderlistOnly( const BoolImportCallback& importer );
236 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_showShaderlistOnly> TextureBrowserShowShaderlistOnlyExport;
238 void TextureBrowser_fixedSize( const BoolImportCallback& importer );
239 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_fixedSize> TextureBrowserFixedSizeExport;
241 void TextureBrowser_filterMissing( const BoolImportCallback& importer );
242 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_filterMissing> TextureBrowserFilterMissingExport;
244 void TextureBrowser_filterFallback( const BoolImportCallback& importer );
245 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_filterFallback> TextureBrowserFilterFallbackExport;
247 void TextureBrowser_enableAlpha( const BoolImportCallback& importer );
248 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_enableAlpha> TextureBrowserEnableAlphaExport;
259 ui::Window m_parent{ui::null};
260 ui::GLArea m_gl_widget{ui::null};
261 ui::Widget m_texture_scroll;
262 ui::Widget m_treeViewTree;
263 ui::Widget m_treeViewTags;
264 ui::Frame m_tag_frame{ui::null};
265 ui::ListStore m_assigned_store{ui::null};
266 ui::ListStore m_available_store{ui::null};
267 ui::Widget m_assigned_tree;
268 ui::Widget m_available_tree;
269 ui::Widget m_scr_win_tree;
270 ui::Widget m_scr_win_tags;
271 ui::Widget m_tag_notebook;
272 ui::Button m_search_button{ui::null};
273 ui::Widget m_shader_info_item;
275 std::set<CopiedString> m_all_tags;
276 ui::ListStore m_all_tags_list{ui::null};
277 std::vector<CopiedString> m_copied_tags;
278 std::set<CopiedString> m_found_shaders;
280 ToggleItem m_hideunused_item;
281 ToggleItem m_hidenotex_item;
282 ToggleItem m_showshaders_item;
283 ToggleItem m_showshaderlistonly_item;
284 ToggleItem m_fixedsize_item;
285 ToggleItem m_filternotex_item;
286 ToggleItem m_enablealpha_item;
289 guint m_exposeHandler;
291 bool m_heightChanged;
292 bool m_originInvalid;
294 DeferredAdjustment m_scrollAdjustment;
295 FreezePointer m_freezePointer;
297 Vector3 color_textureback;
298 // the increment step we use against the wheel mouse
299 std::size_t m_mouseWheelScrollIncrement;
300 std::size_t m_textureScale;
301 // make the texture increments match the grid changes
303 bool m_showTextureScrollbar;
304 StartupShaders m_startupShaders;
305 // if true, the texture window will only display in-use shaders
306 // if false, all the shaders in memory are displayed
311 // The uniform size (in pixels) that textures are resized to when m_resizeTextures is true.
312 int m_uniformTextureSize;
313 // Return the display width of a texture in the texture browser
314 int getTextureWidth( qtexture_t* tex ){
316 if ( !g_TextureBrowser_fixedSize ) {
317 // Don't use uniform size
318 width = (int)( tex->width * ( (float)m_textureScale / 100 ) );
321 ( tex->width >= tex->height ) {
322 // Texture is square, or wider than it is tall
323 width = m_uniformTextureSize;
326 // Otherwise, preserve the texture's aspect ratio
327 width = (int)( m_uniformTextureSize * ( (float)tex->width / tex->height ) );
331 // Return the display height of a texture in the texture browser
332 int getTextureHeight( qtexture_t* tex ){
334 if ( !g_TextureBrowser_fixedSize ) {
335 // Don't use uniform size
336 height = (int)( tex->height * ( (float)m_textureScale / 100 ) );
338 else if ( tex->height >= tex->width ) {
339 // Texture is square, or taller than it is wide
340 height = m_uniformTextureSize;
343 // Otherwise, preserve the texture's aspect ratio
344 height = (int)( m_uniformTextureSize * ( (float)tex->height / tex->width ) );
350 m_texture_scroll( 0 ),
351 m_hideunused_item( TextureBrowserHideUnusedExport() ),
352 m_showshaders_item( TextureBrowserShowShadersExport() ),
353 m_showshaderlistonly_item( TextureBrowserShowShaderlistOnlyExport() ),
354 m_fixedsize_item( TextureBrowserFixedSizeExport() ),
355 m_filternotex_item( TextureBrowserFilterMissingExport() ),
356 m_hidenotex_item( TextureBrowserFilterFallbackExport() ),
357 m_enablealpha_item( TextureBrowserEnableAlphaExport() ),
358 m_heightChanged( true ),
359 m_originInvalid( true ),
360 m_scrollAdjustment( TextureBrowser_scrollChanged, this ),
361 color_textureback( 0.25f, 0.25f, 0.25f ),
362 m_mouseWheelScrollIncrement( 64 ),
363 m_textureScale( 50 ),
364 m_showShaders( true ),
365 m_showTextureScrollbar( true ),
366 m_startupShaders( STARTUPSHADERS_NONE ),
367 m_hideUnused( false ),
368 m_rmbSelected( false ),
369 m_searchedTags( false ),
371 m_uniformTextureSize( 96 ){
375 void ( *TextureBrowser_textureSelected )( const char* shader );
378 void TextureBrowser_updateScroll( TextureBrowser& textureBrowser );
381 const char* TextureBrowser_getComonShadersName(){
382 const char* value = g_pGameDescription->getKeyValue( "common_shaders_name" );
383 if ( !string_empty( value ) ) {
389 const char* TextureBrowser_getComonShadersDir(){
390 const char* value = g_pGameDescription->getKeyValue( "common_shaders_dir" );
391 if ( !string_empty( value ) ) {
397 inline int TextureBrowser_fontHeight( TextureBrowser& textureBrowser ){
398 return GlobalOpenGL().m_font->getPixelHeight();
401 const char* TextureBrowser_GetSelectedShader( TextureBrowser& textureBrowser ){
402 return textureBrowser.shader.c_str();
405 void TextureBrowser_SetStatus( TextureBrowser& textureBrowser, const char* name ){
406 IShader* shader = QERApp_Shader_ForName( name );
407 qtexture_t* q = shader->getTexture();
408 StringOutputStream strTex( 256 );
409 strTex << name << " W: " << Unsigned( q->width ) << " H: " << Unsigned( q->height );
411 g_pParentWnd->SetStatusText( g_pParentWnd->m_texture_status, strTex.c_str() );
414 void TextureBrowser_Focus( TextureBrowser& textureBrowser, const char* name );
416 void TextureBrowser_SetSelectedShader( TextureBrowser& textureBrowser, const char* shader ){
417 textureBrowser.shader = shader;
418 TextureBrowser_SetStatus( textureBrowser, shader );
419 TextureBrowser_Focus( textureBrowser, shader );
421 if ( FindTextureDialog_isOpen() ) {
422 FindTextureDialog_selectTexture( shader );
425 // disable the menu item "shader info" if no shader was selected
426 IShader* ishader = QERApp_Shader_ForName( shader );
427 CopiedString filename = ishader->getShaderFileName();
429 if ( filename.empty() ) {
430 if ( textureBrowser.m_shader_info_item != NULL ) {
431 gtk_widget_set_sensitive( textureBrowser.m_shader_info_item, FALSE );
435 gtk_widget_set_sensitive( textureBrowser.m_shader_info_item, TRUE );
442 CopiedString g_TextureBrowser_currentDirectory;
445 ============================================================================
449 TTimo: now based on a rundown through all the shaders
450 NOTE: we expect the Active shaders count doesn't change during a Texture_StartPos .. Texture_NextPos cycle
451 otherwise we may need to rely on a list instead of an array storage
452 ============================================================================
458 // texture layout functions
459 // TTimo: now based on shaders
460 int current_x, current_y, current_row;
463 void Texture_StartPos( TextureLayout& layout ){
464 layout.current_x = 8;
465 layout.current_y = -8;
466 layout.current_row = 0;
469 void Texture_NextPos( TextureBrowser& textureBrowser, TextureLayout& layout, qtexture_t* current_texture, int *x, int *y ){
470 qtexture_t* q = current_texture;
472 int nWidth = textureBrowser.getTextureWidth( q );
473 int nHeight = textureBrowser.getTextureHeight( q );
474 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
475 layout.current_x = 8;
476 layout.current_y -= layout.current_row + TextureBrowser_fontHeight( textureBrowser ) + 4;
477 layout.current_row = 0;
480 *x = layout.current_x;
481 *y = layout.current_y;
483 // Is our texture larger than the row? If so, grow the
484 // row height to match it
486 if ( layout.current_row < nHeight ) {
487 layout.current_row = nHeight;
490 // never go less than 96, or the names get all crunched up
491 layout.current_x += nWidth < 96 ? 96 : nWidth;
492 layout.current_x += 8;
495 bool TextureSearch_IsShown( const char* name ){
496 std::set<CopiedString>::iterator iter;
498 iter = GlobalTextureBrowser().m_found_shaders.find( name );
500 if ( iter == GlobalTextureBrowser().m_found_shaders.end() ) {
508 // if texture_showinuse jump over non in-use textures
509 bool Texture_IsShown( IShader* shader, bool show_shaders, bool hideUnused ){
510 // filter missing shaders
511 // ugly: filter on built-in fallback name after substitution
512 if ( g_TextureBrowser_filterMissing ) {
513 if ( isMissing( shader->getTexture()->name ) ) {
517 // filter the fallback (notex/shadernotex) for missing shaders or editor image
518 if ( g_TextureBrowser_filterFallback ) {
519 if ( isNotex( shader->getName() ) ) {
522 if ( isNotex( shader->getTexture()->name ) ) {
527 if ( g_TextureBrowser_currentDirectory == "Untagged" ) {
528 std::set<CopiedString>::iterator iter;
530 iter = GlobalTextureBrowser().m_found_shaders.find( shader->getName() );
532 if ( iter == GlobalTextureBrowser().m_found_shaders.end() ) {
540 if ( !shader_equal_prefix( shader->getName(), "textures/" ) ) {
544 if ( !show_shaders && !shader->IsDefault() ) {
548 if ( hideUnused && !shader->IsInUse() ) {
552 if ( GlobalTextureBrowser().m_searchedTags ) {
553 if ( !TextureSearch_IsShown( shader->getName() ) ) {
561 if ( !shader_equal_prefix( shader_get_textureName( shader->getName() ), g_TextureBrowser_currentDirectory.c_str() ) ) {
569 void TextureBrowser_heightChanged( TextureBrowser& textureBrowser ){
570 textureBrowser.m_heightChanged = true;
572 TextureBrowser_updateScroll( textureBrowser );
573 TextureBrowser_queueDraw( textureBrowser );
576 void TextureBrowser_evaluateHeight( TextureBrowser& textureBrowser ){
577 if ( textureBrowser.m_heightChanged ) {
578 textureBrowser.m_heightChanged = false;
580 textureBrowser.m_nTotalHeight = 0;
582 TextureLayout layout;
583 Texture_StartPos( layout );
584 for ( QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement() )
586 IShader* shader = QERApp_ActiveShaders_IteratorCurrent();
588 if ( !Texture_IsShown( shader, textureBrowser.m_showShaders, textureBrowser.m_hideUnused ) ) {
593 Texture_NextPos( textureBrowser, layout, shader->getTexture(), &x, &y );
594 textureBrowser.m_nTotalHeight = std::max( textureBrowser.m_nTotalHeight, abs( layout.current_y ) + TextureBrowser_fontHeight( textureBrowser ) + textureBrowser.getTextureHeight( shader->getTexture() ) + 4 );
599 int TextureBrowser_TotalHeight( TextureBrowser& textureBrowser ){
600 TextureBrowser_evaluateHeight( textureBrowser );
601 return textureBrowser.m_nTotalHeight;
604 inline const int& min_int( const int& left, const int& right ){
605 return std::min( left, right );
608 void TextureBrowser_clampOriginY( TextureBrowser& textureBrowser ){
609 if ( textureBrowser.originy > 0 ) {
610 textureBrowser.originy = 0;
612 int lower = min_int( textureBrowser.height - TextureBrowser_TotalHeight( textureBrowser ), 0 );
613 if ( textureBrowser.originy < lower ) {
614 textureBrowser.originy = lower;
618 int TextureBrowser_getOriginY( TextureBrowser& textureBrowser ){
619 if ( textureBrowser.m_originInvalid ) {
620 textureBrowser.m_originInvalid = false;
621 TextureBrowser_clampOriginY( textureBrowser );
622 TextureBrowser_updateScroll( textureBrowser );
624 return textureBrowser.originy;
627 void TextureBrowser_setOriginY( TextureBrowser& textureBrowser, int originy ){
628 textureBrowser.originy = originy;
629 TextureBrowser_clampOriginY( textureBrowser );
630 TextureBrowser_updateScroll( textureBrowser );
631 TextureBrowser_queueDraw( textureBrowser );
635 Signal0 g_activeShadersChangedCallbacks;
637 void TextureBrowser_addActiveShadersChangedCallback( const SignalHandler& handler ){
638 g_activeShadersChangedCallbacks.connectLast( handler );
641 void TextureBrowser_constructTreeStore();
643 class ShadersObserver : public ModuleObserver
645 Signal0 m_realiseCallbacks;
648 m_realiseCallbacks();
649 TextureBrowser_constructTreeStore();
653 void insert( const SignalHandler& handler ){
654 m_realiseCallbacks.connectLast( handler );
660 ShadersObserver g_ShadersObserver;
663 void TextureBrowser_addShadersRealiseCallback( const SignalHandler& handler ){
664 g_ShadersObserver.insert( handler );
667 void TextureBrowser_activeShadersChanged( TextureBrowser& textureBrowser ){
668 TextureBrowser_heightChanged( textureBrowser );
669 textureBrowser.m_originInvalid = true;
671 g_activeShadersChangedCallbacks();
674 void TextureBrowser_importShowScrollbar( TextureBrowser& textureBrowser, bool value ){
675 textureBrowser.m_showTextureScrollbar = value;
676 if ( textureBrowser.m_texture_scroll != 0 ) {
677 widget_set_visible( textureBrowser.m_texture_scroll, textureBrowser.m_showTextureScrollbar );
678 TextureBrowser_updateScroll( textureBrowser );
681 typedef ReferenceCaller1<TextureBrowser, bool, TextureBrowser_importShowScrollbar> TextureBrowserImportShowScrollbarCaller;
686 TextureBrowser_ShowDirectory
687 relies on texture_directory global for the directory to use
688 1) Load the shaders for the given directory
689 2) Scan the remaining texture, load them and assign them a default shader (the "noshader" shader)
690 NOTE: when writing a texture plugin, or some texture extensions, this function may need to be overriden, and made
691 available through the IShaders interface
692 NOTE: for texture window layout:
693 all shaders are stored with alphabetical order after load
694 previously loaded and displayed stuff is hidden, only in-use and newly loaded is shown
695 ( the GL textures are not flushed though)
699 bool endswith( const char *haystack, const char *needle ){
700 size_t lh = strlen( haystack );
701 size_t ln = strlen( needle );
705 return !memcmp( haystack + ( lh - ln ), needle, ln );
708 bool texture_name_ignore( const char* name ){
709 StringOutputStream strTemp( string_length( name ) );
710 strTemp << LowerCase( name );
713 endswith( strTemp.c_str(), ".specular" ) ||
714 endswith( strTemp.c_str(), ".glow" ) ||
715 endswith( strTemp.c_str(), ".bump" ) ||
716 endswith( strTemp.c_str(), ".diffuse" ) ||
717 endswith( strTemp.c_str(), ".blend" ) ||
718 endswith( strTemp.c_str(), ".alpha" ) ||
719 endswith( strTemp.c_str(), "_norm" ) ||
720 endswith( strTemp.c_str(), "_bump" ) ||
721 endswith( strTemp.c_str(), "_glow" ) ||
722 endswith( strTemp.c_str(), "_gloss" ) ||
723 endswith( strTemp.c_str(), "_pants" ) ||
724 endswith( strTemp.c_str(), "_shirt" ) ||
725 endswith( strTemp.c_str(), "_reflect" ) ||
726 endswith( strTemp.c_str(), "_alpha" ) ||
730 class LoadShaderVisitor : public Archive::Visitor
733 void visit( const char* name ){
734 IShader* shader = QERApp_Shader_ForName( CopiedString( StringRange( name, path_get_filename_base_end( name ) ) ).c_str() );
739 void TextureBrowser_SetHideUnused( TextureBrowser& textureBrowser, bool hideUnused );
741 ui::Widget g_page_textures;
743 void TextureBrowser_toggleShow(){
744 GroupDialog_showPage( g_page_textures );
748 void TextureBrowser_updateTitle(){
749 GroupDialog_updatePageTitle( g_page_textures );
754 class TextureCategoryLoadShader
756 const char* m_directory;
757 std::size_t& m_count;
759 typedef const char* first_argument_type;
761 TextureCategoryLoadShader( const char* directory, std::size_t& count )
762 : m_directory( directory ), m_count( count ){
765 void operator()( const char* name ) const {
766 if ( shader_equal_prefix( name, "textures/" )
767 && shader_equal_prefix( name + string_length( "textures/" ), m_directory ) ) {
769 // request the shader, this will load the texture if needed
770 // this Shader_ForName call is a kind of hack
771 IShader *pFoo = QERApp_Shader_ForName( name );
777 void TextureDirectory_loadTexture( const char* directory, const char* texture ){
778 StringOutputStream name( 256 );
779 name << directory << StringRange( texture, path_get_filename_base_end( texture ) );
781 if ( texture_name_ignore( name.c_str() ) ) {
785 if ( !shader_valid( name.c_str() ) ) {
786 globalOutputStream() << "Skipping invalid texture name: [" << name.c_str() << "]\n";
790 // if a texture is already in use to represent a shader, ignore it
791 IShader* shader = QERApp_Shader_ForName( name.c_str() );
794 typedef ConstPointerCaller1<char, const char*, TextureDirectory_loadTexture> TextureDirectoryLoadTextureCaller;
796 class LoadTexturesByTypeVisitor : public ImageModules::Visitor
798 const char* m_dirstring;
800 LoadTexturesByTypeVisitor( const char* dirstring )
801 : m_dirstring( dirstring ){
803 void visit( const char* minor, const _QERPlugImageTable& table ) const {
804 GlobalFileSystem().forEachFile( m_dirstring, minor, TextureDirectoryLoadTextureCaller( m_dirstring ) );
808 void TextureBrowser_ShowDirectory( TextureBrowser& textureBrowser, const char* directory ){
809 if ( TextureBrowser_showWads() ) {
810 Archive* archive = GlobalFileSystem().getArchive( directory );
811 ASSERT_NOTNULL( archive );
812 LoadShaderVisitor visitor;
813 archive->forEachFile( Archive::VisitorFunc( visitor, Archive::eFiles, 0 ), "textures/" );
817 g_TextureBrowser_currentDirectory = directory;
818 TextureBrowser_heightChanged( textureBrowser );
820 std::size_t shaders_count;
821 GlobalShaderSystem().foreachShaderName( makeCallback1( TextureCategoryLoadShader( directory, shaders_count ) ) );
822 globalOutputStream() << "Showing " << Unsigned( shaders_count ) << " shaders.\n";
824 if ( g_pGameDescription->mGameType != "doom3" ) {
825 // load remaining texture files
827 StringOutputStream dirstring( 64 );
828 dirstring << "textures/" << directory;
830 Radiant_getImageModules().foreachModule( LoadTexturesByTypeVisitor( dirstring.c_str() ) );
834 // we'll display the newly loaded textures + all the ones already in use
835 TextureBrowser_SetHideUnused( textureBrowser, false );
837 TextureBrowser_updateTitle();
840 void TextureBrowser_ShowTagSearchResult( TextureBrowser& textureBrowser, const char* directory ){
841 g_TextureBrowser_currentDirectory = directory;
842 TextureBrowser_heightChanged( textureBrowser );
844 std::size_t shaders_count;
845 GlobalShaderSystem().foreachShaderName( makeCallback1( TextureCategoryLoadShader( directory, shaders_count ) ) );
846 globalOutputStream() << "Showing " << Unsigned( shaders_count ) << " shaders.\n";
848 if ( g_pGameDescription->mGameType != "doom3" ) {
849 // load remaining texture files
850 StringOutputStream dirstring( 64 );
851 dirstring << "textures/" << directory;
854 LoadTexturesByTypeVisitor visitor( dirstring.c_str() );
855 Radiant_getImageModules().foreachModule( visitor );
859 // we'll display the newly loaded textures + all the ones already in use
860 TextureBrowser_SetHideUnused( textureBrowser, false );
864 bool TextureBrowser_hideUnused();
866 void TextureBrowser_hideUnusedExport( const BoolImportCallback& importer ){
867 importer( TextureBrowser_hideUnused() );
869 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_hideUnusedExport> TextureBrowserHideUnusedExport;
871 void TextureBrowser_showShadersExport( const BoolImportCallback& importer ){
872 importer( GlobalTextureBrowser().m_showShaders );
874 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_showShadersExport> TextureBrowserShowShadersExport;
876 void TextureBrowser_showShaderlistOnly( const BoolImportCallback& importer ){
877 importer( g_TextureBrowser_shaderlistOnly );
879 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_showShaderlistOnly> TextureBrowserShowShaderlistOnlyExport;
881 void TextureBrowser_fixedSize( const BoolImportCallback& importer ){
882 importer( g_TextureBrowser_fixedSize );
884 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_fixedSize> TextureBrowser_FixedSizeExport;
886 void TextureBrowser_filterMissing( const BoolImportCallback& importer ){
887 importer( g_TextureBrowser_filterMissing );
889 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_filterMissing> TextureBrowser_filterMissingExport;
891 void TextureBrowser_filterFallback( const BoolImportCallback& importer ){
892 importer( g_TextureBrowser_filterFallback );
894 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_filterFallback> TextureBrowser_filterFallbackExport;
896 void TextureBrowser_enableAlpha( const BoolImportCallback& importer ){
897 importer( g_TextureBrowser_enableAlpha );
899 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_enableAlpha> TextureBrowser_enableAlphaExport;
901 void TextureBrowser_SetHideUnused( TextureBrowser& textureBrowser, bool hideUnused ){
903 textureBrowser.m_hideUnused = true;
907 textureBrowser.m_hideUnused = false;
910 textureBrowser.m_hideunused_item.update();
912 TextureBrowser_heightChanged( textureBrowser );
913 textureBrowser.m_originInvalid = true;
916 void TextureBrowser_ShowStartupShaders( TextureBrowser& textureBrowser ){
917 if ( textureBrowser.m_startupShaders == STARTUPSHADERS_COMMON ) {
918 TextureBrowser_ShowDirectory( textureBrowser, TextureBrowser_getComonShadersDir() );
923 //++timo NOTE: this is a mix of Shader module stuff and texture explorer
924 // it might need to be split in parts or moved out .. dunno
925 // scroll origin so the specified texture is completely on screen
926 // if current texture is not displayed, nothing is changed
927 void TextureBrowser_Focus( TextureBrowser& textureBrowser, const char* name ){
928 TextureLayout layout;
929 // scroll origin so the texture is completely on screen
930 Texture_StartPos( layout );
932 for ( QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement() )
934 IShader* shader = QERApp_ActiveShaders_IteratorCurrent();
936 if ( !Texture_IsShown( shader, textureBrowser.m_showShaders, textureBrowser.m_hideUnused ) ) {
941 Texture_NextPos( textureBrowser, layout, shader->getTexture(), &x, &y );
942 qtexture_t* q = shader->getTexture();
947 // we have found when texdef->name and the shader name match
948 // NOTE: as everywhere else for our comparisons, we are not case sensitive
949 if ( shader_equal( name, shader->getName() ) ) {
950 int textureHeight = (int)( q->height * ( (float)textureBrowser.m_textureScale / 100 ) )
951 + 2 * TextureBrowser_fontHeight( textureBrowser );
953 int originy = TextureBrowser_getOriginY( textureBrowser );
958 if ( y - textureHeight < originy - textureBrowser.height ) {
959 originy = ( y - textureHeight ) + textureBrowser.height;
962 TextureBrowser_setOriginY( textureBrowser, originy );
968 IShader* Texture_At( TextureBrowser& textureBrowser, int mx, int my ){
969 my += TextureBrowser_getOriginY( textureBrowser ) - textureBrowser.height;
971 TextureLayout layout;
972 Texture_StartPos( layout );
973 for ( QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement() )
975 IShader* shader = QERApp_ActiveShaders_IteratorCurrent();
977 if ( !Texture_IsShown( shader, textureBrowser.m_showShaders, textureBrowser.m_hideUnused ) ) {
982 Texture_NextPos( textureBrowser, layout, shader->getTexture(), &x, &y );
983 qtexture_t *q = shader->getTexture();
988 int nWidth = textureBrowser.getTextureWidth( q );
989 int nHeight = textureBrowser.getTextureHeight( q );
990 if ( mx > x && mx - x < nWidth
991 && my < y && y - my < nHeight + TextureBrowser_fontHeight( textureBrowser ) ) {
1006 void SelectTexture( TextureBrowser& textureBrowser, int mx, int my, bool bShift ){
1007 IShader* shader = Texture_At( textureBrowser, mx, my );
1008 if ( shader != 0 ) {
1010 if ( shader->IsDefault() ) {
1011 globalOutputStream() << "ERROR: " << shader->getName() << " is not a shader, it's a texture.\n";
1014 ViewShader( shader->getShaderFileName(), shader->getName() );
1019 TextureBrowser_SetSelectedShader( textureBrowser, shader->getName() );
1020 TextureBrowser_textureSelected( shader->getName() );
1022 if ( !FindTextureDialog_isOpen() && !textureBrowser.m_rmbSelected ) {
1023 UndoableCommand undo( "textureNameSetSelected" );
1024 Select_SetShader( shader->getName() );
1031 ============================================================================
1035 ============================================================================
1038 void TextureBrowser_trackingDelta( int x, int y, unsigned int state, void* data ){
1039 TextureBrowser& textureBrowser = *reinterpret_cast<TextureBrowser*>( data );
1043 if ( state & GDK_SHIFT_MASK ) {
1047 int originy = TextureBrowser_getOriginY( textureBrowser );
1048 originy += y * scale;
1049 TextureBrowser_setOriginY( textureBrowser, originy );
1053 void TextureBrowser_Tracking_MouseDown( TextureBrowser& textureBrowser ){
1054 textureBrowser.m_freezePointer.freeze_pointer( textureBrowser.m_parent, TextureBrowser_trackingDelta, &textureBrowser );
1057 void TextureBrowser_Tracking_MouseUp( TextureBrowser& textureBrowser ){
1058 textureBrowser.m_freezePointer.unfreeze_pointer( textureBrowser.m_parent );
1061 void TextureBrowser_Selection_MouseDown( TextureBrowser& textureBrowser, guint32 flags, int pointx, int pointy ){
1062 SelectTexture( textureBrowser, pointx, textureBrowser.height - 1 - pointy, ( flags & GDK_SHIFT_MASK ) != 0 );
1066 ============================================================================
1070 ============================================================================
1076 TTimo: relying on the shaders list to display the textures
1077 we must query all qtexture_t* to manage and display through the IShaders interface
1078 this allows a plugin to completely override the texture system
1081 void Texture_Draw( TextureBrowser& textureBrowser ){
1082 int originy = TextureBrowser_getOriginY( textureBrowser );
1084 glClearColor( textureBrowser.color_textureback[0],
1085 textureBrowser.color_textureback[1],
1086 textureBrowser.color_textureback[2],
1088 glViewport( 0, 0, textureBrowser.width, textureBrowser.height );
1089 glMatrixMode( GL_PROJECTION );
1092 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
1093 glDisable( GL_DEPTH_TEST );
1094 if ( g_TextureBrowser_enableAlpha ) {
1095 glEnable( GL_BLEND );
1096 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1099 glDisable( GL_BLEND );
1101 glOrtho( 0, textureBrowser.width, originy - textureBrowser.height, originy, -100, 100 );
1102 glEnable( GL_TEXTURE_2D );
1104 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
1106 int last_y = 0, last_height = 0;
1108 TextureLayout layout;
1109 Texture_StartPos( layout );
1110 for ( QERApp_ActiveShaders_IteratorBegin(); !QERApp_ActiveShaders_IteratorAtEnd(); QERApp_ActiveShaders_IteratorIncrement() )
1112 IShader* shader = QERApp_ActiveShaders_IteratorCurrent();
1114 if ( !Texture_IsShown( shader, textureBrowser.m_showShaders, textureBrowser.m_hideUnused ) ) {
1119 Texture_NextPos( textureBrowser, layout, shader->getTexture(), &x, &y );
1120 qtexture_t *q = shader->getTexture();
1125 int nWidth = textureBrowser.getTextureWidth( q );
1126 int nHeight = textureBrowser.getTextureHeight( q );
1128 if ( y != last_y ) {
1132 last_height = std::max( nHeight, last_height );
1134 // Is this texture visible?
1135 if ( ( y - nHeight - TextureBrowser_fontHeight( textureBrowser ) < originy )
1136 && ( y > originy - textureBrowser.height ) ) {
1138 // if it's the current texture, draw a thick red line, else:
1139 // shaders have a white border, simple textures don't
1140 // if !texture_showinuse: (some textures displayed may not be in use)
1141 // draw an additional square around with 0.5 1 0.5 color
1142 if ( shader_equal( TextureBrowser_GetSelectedShader( textureBrowser ), shader->getName() ) ) {
1144 if ( textureBrowser.m_rmbSelected ) {
1150 glDisable( GL_TEXTURE_2D );
1152 glBegin( GL_LINE_LOOP );
1153 glVertex2i( x - 4,y - TextureBrowser_fontHeight( textureBrowser ) + 4 );
1154 glVertex2i( x - 4,y - TextureBrowser_fontHeight( textureBrowser ) - nHeight - 4 );
1155 glVertex2i( x + 4 + nWidth,y - TextureBrowser_fontHeight( textureBrowser ) - nHeight - 4 );
1156 glVertex2i( x + 4 + nWidth,y - TextureBrowser_fontHeight( textureBrowser ) + 4 );
1159 glEnable( GL_TEXTURE_2D );
1166 if ( !shader->IsDefault() ) {
1168 glDisable( GL_TEXTURE_2D );
1170 glBegin( GL_LINE_LOOP );
1171 glVertex2i( x - 1,y + 1 - TextureBrowser_fontHeight( textureBrowser ) );
1172 glVertex2i( x - 1,y - nHeight - 1 - TextureBrowser_fontHeight( textureBrowser ) );
1173 glVertex2i( x + 1 + nWidth,y - nHeight - 1 - TextureBrowser_fontHeight( textureBrowser ) );
1174 glVertex2i( x + 1 + nWidth,y + 1 - TextureBrowser_fontHeight( textureBrowser ) );
1176 glEnable( GL_TEXTURE_2D );
1179 // highlight in-use textures
1180 if ( !textureBrowser.m_hideUnused && shader->IsInUse() ) {
1181 glColor3f( 0.5,1,0.5 );
1182 glDisable( GL_TEXTURE_2D );
1183 glBegin( GL_LINE_LOOP );
1184 glVertex2i( x - 3,y + 3 - TextureBrowser_fontHeight( textureBrowser ) );
1185 glVertex2i( x - 3,y - nHeight - 3 - TextureBrowser_fontHeight( textureBrowser ) );
1186 glVertex2i( x + 3 + nWidth,y - nHeight - 3 - TextureBrowser_fontHeight( textureBrowser ) );
1187 glVertex2i( x + 3 + nWidth,y + 3 - TextureBrowser_fontHeight( textureBrowser ) );
1189 glEnable( GL_TEXTURE_2D );
1193 // draw checkerboard for transparent textures
1194 if ( g_TextureBrowser_enableAlpha )
1196 glDisable( GL_TEXTURE_2D );
1197 glBegin( GL_QUADS );
1198 int font_height = TextureBrowser_fontHeight( textureBrowser );
1199 for ( int i = 0; i < nHeight; i += 8 )
1200 for ( int j = 0; j < nWidth; j += 8 )
1202 unsigned char color = (i + j) / 8 % 2 ? 0x66 : 0x99;
1203 glColor3ub( color, color, color );
1205 int right = std::min(j+8, nWidth);
1207 int bottom = std::min(i+8, nHeight);
1208 glVertex2i(x + right, y - nHeight - font_height + top);
1209 glVertex2i(x + left, y - nHeight - font_height + top);
1210 glVertex2i(x + left, y - nHeight - font_height + bottom);
1211 glVertex2i(x + right, y - nHeight - font_height + bottom);
1214 glEnable( GL_TEXTURE_2D );
1218 glBindTexture( GL_TEXTURE_2D, q->texture_number );
1219 GlobalOpenGL_debugAssertNoErrors();
1221 glBegin( GL_QUADS );
1222 glTexCoord2i( 0,0 );
1223 glVertex2i( x,y - TextureBrowser_fontHeight( textureBrowser ) );
1224 glTexCoord2i( 1,0 );
1225 glVertex2i( x + nWidth,y - TextureBrowser_fontHeight( textureBrowser ) );
1226 glTexCoord2i( 1,1 );
1227 glVertex2i( x + nWidth,y - TextureBrowser_fontHeight( textureBrowser ) - nHeight );
1228 glTexCoord2i( 0,1 );
1229 glVertex2i( x,y - TextureBrowser_fontHeight( textureBrowser ) - nHeight );
1232 // draw the texture name
1233 glDisable( GL_TEXTURE_2D );
1236 glRasterPos2i( x, y - TextureBrowser_fontHeight( textureBrowser ) + 5 );
1238 // don't draw the directory name
1239 const char* name = shader->getName();
1240 name += strlen( name );
1241 while ( name != shader->getName() && *( name - 1 ) != '/' && *( name - 1 ) != '\\' )
1244 GlobalOpenGL().drawString( name );
1245 glEnable( GL_TEXTURE_2D );
1248 //int totalHeight = abs(y) + last_height + TextureBrowser_fontHeight(textureBrowser) + 4;
1252 // reset the current texture
1253 glBindTexture( GL_TEXTURE_2D, 0 );
1257 void TextureBrowser_queueDraw( TextureBrowser& textureBrowser ){
1258 if ( textureBrowser.m_gl_widget ) {
1259 gtk_widget_queue_draw( textureBrowser.m_gl_widget );
1264 void TextureBrowser_setScale( TextureBrowser& textureBrowser, std::size_t scale ){
1265 textureBrowser.m_textureScale = scale;
1267 TextureBrowser_queueDraw( textureBrowser );
1270 void TextureBrowser_setUniformSize( TextureBrowser& textureBrowser, std::size_t scale ){
1271 textureBrowser.m_uniformTextureSize = scale;
1273 TextureBrowser_queueDraw( textureBrowser );
1277 void TextureBrowser_MouseWheel( TextureBrowser& textureBrowser, bool bUp ){
1278 int originy = TextureBrowser_getOriginY( textureBrowser );
1281 originy += int(textureBrowser.m_mouseWheelScrollIncrement);
1285 originy -= int(textureBrowser.m_mouseWheelScrollIncrement);
1288 TextureBrowser_setOriginY( textureBrowser, originy );
1291 XmlTagBuilder TagBuilder;
1299 void BuildStoreAssignedTags( ui::ListStore store, const char* shader, TextureBrowser* textureBrowser ){
1302 gtk_list_store_clear( store );
1304 std::vector<CopiedString> assigned_tags;
1305 TagBuilder.GetShaderTags( shader, assigned_tags );
1307 for ( size_t i = 0; i < assigned_tags.size(); i++ )
1309 gtk_list_store_append( store, &iter );
1310 gtk_list_store_set( store, &iter, TAG_COLUMN, assigned_tags[i].c_str(), -1 );
1314 void BuildStoreAvailableTags( ui::ListStore storeAvailable,
1315 ui::ListStore storeAssigned,
1316 const std::set<CopiedString>& allTags,
1317 TextureBrowser* textureBrowser ){
1318 GtkTreeIter iterAssigned;
1319 GtkTreeIter iterAvailable;
1320 std::set<CopiedString>::const_iterator iterAll;
1321 gchar* tag_assigned;
1323 gtk_list_store_clear( storeAvailable );
1325 bool row = gtk_tree_model_get_iter_first( GTK_TREE_MODEL( storeAssigned ), &iterAssigned ) != 0;
1327 if ( !row ) { // does the shader have tags assigned?
1328 for ( iterAll = allTags.begin(); iterAll != allTags.end(); ++iterAll )
1330 gtk_list_store_append( storeAvailable, &iterAvailable );
1331 gtk_list_store_set( storeAvailable, &iterAvailable, TAG_COLUMN, ( *iterAll ).c_str(), -1 );
1336 while ( row ) // available tags = all tags - assigned tags
1338 gtk_tree_model_get( GTK_TREE_MODEL( storeAssigned ), &iterAssigned, TAG_COLUMN, &tag_assigned, -1 );
1340 for ( iterAll = allTags.begin(); iterAll != allTags.end(); ++iterAll )
1342 if ( strcmp( (char*)tag_assigned, ( *iterAll ).c_str() ) != 0 ) {
1343 gtk_list_store_append( storeAvailable, &iterAvailable );
1344 gtk_list_store_set( storeAvailable, &iterAvailable, TAG_COLUMN, ( *iterAll ).c_str(), -1 );
1348 row = gtk_tree_model_iter_next( GTK_TREE_MODEL( storeAssigned ), &iterAssigned ) != 0;
1351 gtk_tree_model_get( GTK_TREE_MODEL( storeAssigned ), &iterAssigned, TAG_COLUMN, &tag_assigned, -1 );
1359 gboolean TextureBrowser_button_press( ui::Widget widget, GdkEventButton* event, TextureBrowser* textureBrowser ){
1360 if ( event->type == GDK_BUTTON_PRESS ) {
1361 if ( event->button == 3 ) {
1362 if ( GlobalTextureBrowser().m_tags ) {
1363 textureBrowser->m_rmbSelected = true;
1364 TextureBrowser_Selection_MouseDown( *textureBrowser, event->state, static_cast<int>( event->x ), static_cast<int>( event->y ) );
1366 BuildStoreAssignedTags( textureBrowser->m_assigned_store, textureBrowser->shader.c_str(), textureBrowser );
1367 BuildStoreAvailableTags( textureBrowser->m_available_store, textureBrowser->m_assigned_store, textureBrowser->m_all_tags, textureBrowser );
1368 textureBrowser->m_heightChanged = true;
1369 textureBrowser->m_tag_frame.show();
1373 TextureBrowser_Focus( *textureBrowser, textureBrowser->shader.c_str() );
1377 TextureBrowser_Tracking_MouseDown( *textureBrowser );
1380 else if ( event->button == 1 ) {
1381 TextureBrowser_Selection_MouseDown( *textureBrowser, event->state, static_cast<int>( event->x ), static_cast<int>( event->y ) );
1383 if ( GlobalTextureBrowser().m_tags ) {
1384 textureBrowser->m_rmbSelected = false;
1385 gtk_widget_hide( textureBrowser->m_tag_frame );
1392 gboolean TextureBrowser_button_release( ui::Widget widget, GdkEventButton* event, TextureBrowser* textureBrowser ){
1393 if ( event->type == GDK_BUTTON_RELEASE ) {
1394 if ( event->button == 3 ) {
1395 if ( !GlobalTextureBrowser().m_tags ) {
1396 TextureBrowser_Tracking_MouseUp( *textureBrowser );
1403 gboolean TextureBrowser_motion( ui::Widget widget, GdkEventMotion *event, TextureBrowser* textureBrowser ){
1407 gboolean TextureBrowser_scroll( ui::Widget widget, GdkEventScroll* event, TextureBrowser* textureBrowser ){
1408 if ( event->direction == GDK_SCROLL_UP ) {
1409 TextureBrowser_MouseWheel( *textureBrowser, true );
1411 else if ( event->direction == GDK_SCROLL_DOWN ) {
1412 TextureBrowser_MouseWheel( *textureBrowser, false );
1417 void TextureBrowser_scrollChanged( void* data, gdouble value ){
1418 //globalOutputStream() << "vertical scroll\n";
1419 TextureBrowser_setOriginY( *reinterpret_cast<TextureBrowser*>( data ), -(int)value );
1422 static void TextureBrowser_verticalScroll( GtkAdjustment *adjustment, TextureBrowser* textureBrowser ){
1423 textureBrowser->m_scrollAdjustment.value_changed( gtk_adjustment_get_value(adjustment) );
1426 void TextureBrowser_updateScroll( TextureBrowser& textureBrowser ){
1427 if ( textureBrowser.m_showTextureScrollbar ) {
1428 int totalHeight = TextureBrowser_TotalHeight( textureBrowser );
1430 totalHeight = std::max( totalHeight, textureBrowser.height );
1432 GtkAdjustment *vadjustment = gtk_range_get_adjustment( GTK_RANGE( textureBrowser.m_texture_scroll ) );
1434 gtk_adjustment_set_value(vadjustment, -TextureBrowser_getOriginY( textureBrowser ));
1435 gtk_adjustment_set_page_size(vadjustment, textureBrowser.height);
1436 gtk_adjustment_set_page_increment(vadjustment, textureBrowser.height / 2);
1437 gtk_adjustment_set_step_increment(vadjustment, 20);
1438 gtk_adjustment_set_lower(vadjustment, 0);
1439 gtk_adjustment_set_upper(vadjustment, totalHeight);
1441 g_signal_emit_by_name( G_OBJECT( vadjustment ), "changed" );
1445 gboolean TextureBrowser_size_allocate( ui::Widget widget, GtkAllocation* allocation, TextureBrowser* textureBrowser ){
1446 textureBrowser->width = allocation->width;
1447 textureBrowser->height = allocation->height;
1448 TextureBrowser_heightChanged( *textureBrowser );
1449 textureBrowser->m_originInvalid = true;
1450 TextureBrowser_queueDraw( *textureBrowser );
1454 gboolean TextureBrowser_expose( ui::Widget widget, GdkEventExpose* event, TextureBrowser* textureBrowser ){
1455 if ( glwidget_make_current( textureBrowser->m_gl_widget ) != FALSE ) {
1456 GlobalOpenGL_debugAssertNoErrors();
1457 TextureBrowser_evaluateHeight( *textureBrowser );
1458 Texture_Draw( *textureBrowser );
1459 GlobalOpenGL_debugAssertNoErrors();
1460 glwidget_swap_buffers( textureBrowser->m_gl_widget );
1466 TextureBrowser g_TextureBrowser;
1468 TextureBrowser& GlobalTextureBrowser(){
1469 return g_TextureBrowser;
1472 bool TextureBrowser_hideUnused(){
1473 return g_TextureBrowser.m_hideUnused;
1476 void TextureBrowser_ToggleHideUnused(){
1477 if ( g_TextureBrowser.m_hideUnused ) {
1478 TextureBrowser_SetHideUnused( g_TextureBrowser, false );
1482 TextureBrowser_SetHideUnused( g_TextureBrowser, true );
1486 void TextureGroups_constructTreeModel( TextureGroups groups, GtkTreeStore* store ){
1487 // put the information from the old textures menu into a treeview
1488 GtkTreeIter iter, child;
1490 TextureGroups::const_iterator i = groups.begin();
1491 while ( i != groups.end() )
1493 const char* dirName = ( *i ).c_str();
1494 const char* firstUnderscore = strchr( dirName, '_' );
1495 StringRange dirRoot( dirName, ( firstUnderscore == 0 ) ? dirName : firstUnderscore + 1 );
1497 TextureGroups::const_iterator next = i;
1499 if ( firstUnderscore != 0
1500 && next != groups.end()
1501 && string_equal_start( ( *next ).c_str(), dirRoot ) ) {
1502 gtk_tree_store_append( store, &iter, NULL );
1503 gtk_tree_store_set( store, &iter, 0, CopiedString( StringRange( dirName, firstUnderscore ) ).c_str(), -1 );
1506 while ( i != groups.end() && string_equal_start( ( *i ).c_str(), dirRoot ) )
1508 gtk_tree_store_append( store, &child, &iter );
1509 gtk_tree_store_set( store, &child, 0, ( *i ).c_str(), -1 );
1515 gtk_tree_store_append( store, &iter, NULL );
1516 gtk_tree_store_set( store, &iter, 0, dirName, -1 );
1522 TextureGroups TextureGroups_constructTreeView(){
1523 TextureGroups groups;
1525 if ( TextureBrowser_showWads() ) {
1526 GlobalFileSystem().forEachArchive( TextureGroupsAddWadCaller( groups ) );
1530 // scan texture dirs and pak files only if not restricting to shaderlist
1531 if ( g_pGameDescription->mGameType != "doom3" && !g_TextureBrowser_shaderlistOnly ) {
1532 GlobalFileSystem().forEachDirectory( "textures/", TextureGroupsAddDirectoryCaller( groups ) );
1535 GlobalShaderSystem().foreachShaderName( TextureGroupsAddShaderCaller( groups ) );
1541 void TextureBrowser_constructTreeStore(){
1542 TextureGroups groups = TextureGroups_constructTreeView();
1543 GtkTreeStore* store = gtk_tree_store_new( 1, G_TYPE_STRING );
1544 TextureGroups_constructTreeModel( groups, store );
1545 std::set<CopiedString>::iterator iter;
1547 GtkTreeModel* model = GTK_TREE_MODEL( store );
1549 gtk_tree_view_set_model( GTK_TREE_VIEW( g_TextureBrowser.m_treeViewTree ), model );
1551 g_object_unref( G_OBJECT( store ) );
1554 void TextureBrowser_constructTreeStoreTags(){
1555 TextureGroups groups;
1556 GtkTreeStore* store = gtk_tree_store_new( 1, G_TYPE_STRING );
1557 GtkTreeModel* model = GTK_TREE_MODEL( g_TextureBrowser.m_all_tags_list );
1559 gtk_tree_view_set_model( GTK_TREE_VIEW( g_TextureBrowser.m_treeViewTags ), model );
1561 g_object_unref( G_OBJECT( store ) );
1564 void TreeView_onRowActivated( GtkTreeView* treeview, GtkTreePath* path, GtkTreeViewColumn* col, gpointer userdata ){
1567 GtkTreeModel* model = gtk_tree_view_get_model( GTK_TREE_VIEW( treeview ) );
1569 if ( gtk_tree_model_get_iter( model, &iter, path ) ) {
1570 gchar dirName[1024];
1573 gtk_tree_model_get( model, &iter, 0, &buffer, -1 );
1574 strcpy( dirName, buffer );
1577 g_TextureBrowser.m_searchedTags = false;
1579 if ( !TextureBrowser_showWads() ) {
1580 strcat( dirName, "/" );
1583 ScopeDisableScreenUpdates disableScreenUpdates( dirName, "Loading Textures" );
1584 TextureBrowser_ShowDirectory( GlobalTextureBrowser(), dirName );
1585 TextureBrowser_queueDraw( GlobalTextureBrowser() );
1589 void TextureBrowser_createTreeViewTree(){
1590 g_TextureBrowser.m_treeViewTree = ui::TreeView();
1591 gtk_tree_view_set_enable_search( GTK_TREE_VIEW( g_TextureBrowser.m_treeViewTree ), FALSE );
1593 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( g_TextureBrowser.m_treeViewTree ), FALSE );
1594 g_TextureBrowser.m_treeViewTree.connect( "row-activated", (GCallback) TreeView_onRowActivated, NULL );
1596 auto renderer = ui::CellRendererText();
1597 gtk_tree_view_insert_column_with_attributes( GTK_TREE_VIEW( g_TextureBrowser.m_treeViewTree ), -1, "", renderer, "text", 0, NULL );
1599 TextureBrowser_constructTreeStore();
1602 void TextureBrowser_addTag();
1603 void TextureBrowser_renameTag();
1604 void TextureBrowser_deleteTag();
1606 void TextureBrowser_createContextMenu( ui::Widget treeview, GdkEventButton *event ){
1607 ui::Widget menu = ui::Menu();
1609 ui::Widget menuitem = ui::MenuItem( "Add tag" );
1610 menuitem.connect( "activate", (GCallback)TextureBrowser_addTag, treeview );
1611 gtk_menu_shell_append( GTK_MENU_SHELL( menu ), menuitem );
1613 menuitem = ui::MenuItem( "Rename tag" );
1614 menuitem.connect( "activate", (GCallback)TextureBrowser_renameTag, treeview );
1615 gtk_menu_shell_append( GTK_MENU_SHELL( menu ), menuitem );
1617 menuitem = ui::MenuItem( "Delete tag" );
1618 menuitem.connect( "activate", (GCallback)TextureBrowser_deleteTag, treeview );
1619 gtk_menu_shell_append( GTK_MENU_SHELL( menu ), menuitem );
1621 gtk_widget_show_all( menu );
1623 gtk_menu_popup( GTK_MENU( menu ), NULL, NULL, NULL, NULL,
1624 ( event != NULL ) ? event->button : 0,
1625 gdk_event_get_time( (GdkEvent*)event ) );
1628 gboolean TreeViewTags_onButtonPressed( ui::Widget treeview, GdkEventButton *event ){
1629 if ( event->type == GDK_BUTTON_PRESS && event->button == 3 ) {
1631 GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( treeview ) );
1633 if ( gtk_tree_view_get_path_at_pos( GTK_TREE_VIEW( treeview ), event->x, event->y, &path, NULL, NULL, NULL ) ) {
1634 gtk_tree_selection_unselect_all( selection );
1635 gtk_tree_selection_select_path( selection, path );
1636 gtk_tree_path_free( path );
1639 TextureBrowser_createContextMenu( treeview, event );
1645 void TextureBrowser_createTreeViewTags(){
1646 g_TextureBrowser.m_treeViewTags = ui::TreeView();
1647 gtk_tree_view_set_enable_search( GTK_TREE_VIEW( g_TextureBrowser.m_treeViewTags ), FALSE );
1649 g_TextureBrowser.m_treeViewTags.connect( "button-press-event", (GCallback)TreeViewTags_onButtonPressed, NULL );
1651 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( g_TextureBrowser.m_treeViewTags ), FALSE );
1653 auto renderer = ui::CellRendererText();
1654 gtk_tree_view_insert_column_with_attributes( GTK_TREE_VIEW( g_TextureBrowser.m_treeViewTags ), -1, "", renderer, "text", 0, NULL );
1656 TextureBrowser_constructTreeStoreTags();
1659 ui::MenuItem TextureBrowser_constructViewMenu( ui::Menu menu ){
1660 ui::MenuItem textures_menu_item = ui::MenuItem(new_sub_menu_item_with_mnemonic( "_View" ));
1662 if ( g_Layout_enableDetachableMenus.m_value ) {
1663 menu_tearoff( menu );
1666 create_check_menu_item_with_mnemonic( menu, "Hide _Unused", "ShowInUse" );
1667 if ( string_empty( g_pGameDescription->getKeyValue( "show_wads" ) ) ) {
1668 create_check_menu_item_with_mnemonic( menu, "Hide Image Missing", "FilterMissing" );
1671 // hide notex and shadernotex on texture browser: no one wants to apply them
1672 create_check_menu_item_with_mnemonic( menu, "Hide Fallback", "FilterFallback" );
1674 menu_separator( menu );
1676 create_menu_item_with_mnemonic( menu, "Show All", "ShowAllTextures" );
1678 // we always want to show shaders but don't want a "Show Shaders" menu for doom3 and .wad file games
1679 if ( g_pGameDescription->mGameType == "doom3" || !string_empty( g_pGameDescription->getKeyValue( "show_wads" ) ) ) {
1680 g_TextureBrowser.m_showShaders = true;
1684 create_check_menu_item_with_mnemonic( menu, "Show shaders", "ToggleShowShaders" );
1687 if ( g_pGameDescription->mGameType != "doom3" && string_empty( g_pGameDescription->getKeyValue( "show_wads" ) ) ) {
1688 create_check_menu_item_with_mnemonic( menu, "Shaders Only", "ToggleShowShaderlistOnly" );
1690 if ( g_TextureBrowser.m_tags ) {
1691 create_menu_item_with_mnemonic( menu, "Show Untagged", "ShowUntagged" );
1694 menu_separator( menu );
1695 create_check_menu_item_with_mnemonic( menu, "Fixed Size", "FixedSize" );
1696 create_check_menu_item_with_mnemonic( menu, "Transparency", "EnableAlpha" );
1698 if ( string_empty( g_pGameDescription->getKeyValue( "show_wads" ) ) ) {
1699 menu_separator( menu );
1700 g_TextureBrowser.m_shader_info_item = ui::Widget(GTK_WIDGET( create_menu_item_with_mnemonic( menu, "Shader Info", "ShaderInfo" ) ));
1701 gtk_widget_set_sensitive( g_TextureBrowser.m_shader_info_item, FALSE );
1705 return textures_menu_item;
1708 ui::MenuItem TextureBrowser_constructToolsMenu( ui::Menu menu ){
1709 ui::MenuItem textures_menu_item = ui::MenuItem(new_sub_menu_item_with_mnemonic( "_Tools" ));
1711 if ( g_Layout_enableDetachableMenus.m_value ) {
1712 menu_tearoff( menu );
1715 create_menu_item_with_mnemonic( menu, "Flush & Reload Shaders", "RefreshShaders" );
1716 create_menu_item_with_mnemonic( menu, "Find / Replace...", "FindReplaceTextures" );
1718 return textures_menu_item;
1721 ui::MenuItem TextureBrowser_constructTagsMenu( ui::Menu menu ){
1722 ui::MenuItem textures_menu_item = ui::MenuItem(new_sub_menu_item_with_mnemonic( "T_ags" ));
1724 if ( g_Layout_enableDetachableMenus.m_value ) {
1725 menu_tearoff( menu );
1728 create_menu_item_with_mnemonic( menu, "Add tag", "AddTag" );
1729 create_menu_item_with_mnemonic( menu, "Rename tag", "RenameTag" );
1730 create_menu_item_with_mnemonic( menu, "Delete tag", "DeleteTag" );
1731 menu_separator( menu );
1732 create_menu_item_with_mnemonic( menu, "Copy tags from selected", "CopyTag" );
1733 create_menu_item_with_mnemonic( menu, "Paste tags to selected", "PasteTag" );
1735 return textures_menu_item;
1738 gboolean TextureBrowser_tagMoveHelper( GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter, GSList** selected ){
1739 g_assert( selected != NULL );
1741 GtkTreeRowReference* rowref = gtk_tree_row_reference_new( model, path );
1742 *selected = g_slist_append( *selected, rowref );
1747 void TextureBrowser_assignTags(){
1748 GSList* selected = NULL;
1750 gchar* tag_assigned;
1752 GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( g_TextureBrowser.m_available_tree ) );
1754 gtk_tree_selection_selected_foreach( selection, (GtkTreeSelectionForeachFunc)TextureBrowser_tagMoveHelper, &selected );
1756 if ( selected != NULL ) {
1757 for ( node = selected; node != NULL; node = node->next )
1759 GtkTreePath* path = gtk_tree_row_reference_get_path( (GtkTreeRowReference*)node->data );
1764 if ( gtk_tree_model_get_iter( GTK_TREE_MODEL( g_TextureBrowser.m_available_store ), &iter, path ) ) {
1765 gtk_tree_model_get( GTK_TREE_MODEL( g_TextureBrowser.m_available_store ), &iter, TAG_COLUMN, &tag_assigned, -1 );
1766 if ( !TagBuilder.CheckShaderTag( g_TextureBrowser.shader.c_str() ) ) {
1767 // create a custom shader/texture entry
1768 IShader* ishader = QERApp_Shader_ForName( g_TextureBrowser.shader.c_str() );
1769 CopiedString filename = ishader->getShaderFileName();
1771 if ( filename.empty() ) {
1773 TagBuilder.AddShaderNode( g_TextureBrowser.shader.c_str(), CUSTOM, TEXTURE );
1777 TagBuilder.AddShaderNode( g_TextureBrowser.shader.c_str(), CUSTOM, SHADER );
1781 TagBuilder.AddShaderTag( g_TextureBrowser.shader.c_str(), (char*)tag_assigned, TAG );
1783 gtk_list_store_remove( g_TextureBrowser.m_available_store, &iter );
1784 gtk_list_store_append( g_TextureBrowser.m_assigned_store, &iter );
1785 gtk_list_store_set( g_TextureBrowser.m_assigned_store, &iter, TAG_COLUMN, (char*)tag_assigned, -1 );
1790 g_slist_foreach( selected, (GFunc)gtk_tree_row_reference_free, NULL );
1793 TagBuilder.SaveXmlDoc();
1795 g_slist_free( selected );
1798 void TextureBrowser_removeTags(){
1799 GSList* selected = NULL;
1803 GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( g_TextureBrowser.m_assigned_tree ) );
1805 gtk_tree_selection_selected_foreach( selection, (GtkTreeSelectionForeachFunc)TextureBrowser_tagMoveHelper, &selected );
1807 if ( selected != NULL ) {
1808 for ( node = selected; node != NULL; node = node->next )
1810 GtkTreePath* path = gtk_tree_row_reference_get_path( (GtkTreeRowReference*)node->data );
1815 if ( gtk_tree_model_get_iter( GTK_TREE_MODEL( g_TextureBrowser.m_assigned_store ), &iter, path ) ) {
1816 gtk_tree_model_get( GTK_TREE_MODEL( g_TextureBrowser.m_assigned_store ), &iter, TAG_COLUMN, &tag, -1 );
1817 TagBuilder.DeleteShaderTag( g_TextureBrowser.shader.c_str(), tag );
1818 gtk_list_store_remove( g_TextureBrowser.m_assigned_store, &iter );
1823 g_slist_foreach( selected, (GFunc)gtk_tree_row_reference_free, NULL );
1825 // Update the "available tags list"
1826 BuildStoreAvailableTags( g_TextureBrowser.m_available_store, g_TextureBrowser.m_assigned_store, g_TextureBrowser.m_all_tags, &g_TextureBrowser );
1829 TagBuilder.SaveXmlDoc();
1831 g_slist_free( selected );
1834 void TextureBrowser_buildTagList(){
1835 GtkTreeIter treeIter;
1836 gtk_list_store_clear( g_TextureBrowser.m_all_tags_list );
1838 std::set<CopiedString>::iterator iter;
1840 for ( iter = g_TextureBrowser.m_all_tags.begin(); iter != g_TextureBrowser.m_all_tags.end(); ++iter )
1842 gtk_list_store_append( g_TextureBrowser.m_all_tags_list, &treeIter );
1843 gtk_list_store_set( g_TextureBrowser.m_all_tags_list, &treeIter, TAG_COLUMN, ( *iter ).c_str(), -1 );
1847 void TextureBrowser_searchTags(){
1848 GSList* selected = NULL;
1852 char tags_searched[256];
1854 GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( g_TextureBrowser.m_treeViewTags ) );
1856 gtk_tree_selection_selected_foreach( selection, (GtkTreeSelectionForeachFunc)TextureBrowser_tagMoveHelper, &selected );
1858 if ( selected != NULL ) {
1859 strcpy( buffer, "/root/*/*[tag='" );
1860 strcpy( tags_searched, "[TAGS] " );
1862 for ( node = selected; node != NULL; node = node->next )
1864 GtkTreePath* path = gtk_tree_row_reference_get_path( (GtkTreeRowReference*)node->data );
1869 if ( gtk_tree_model_get_iter( GTK_TREE_MODEL( g_TextureBrowser.m_all_tags_list ), &iter, path ) ) {
1870 gtk_tree_model_get( GTK_TREE_MODEL( g_TextureBrowser.m_all_tags_list ), &iter, TAG_COLUMN, &tag, -1 );
1872 strcat( buffer, tag );
1873 strcat( tags_searched, tag );
1874 if ( node != g_slist_last( node ) ) {
1875 strcat( buffer, "' and tag='" );
1876 strcat( tags_searched, ", " );
1882 strcat( buffer, "']" );
1884 g_slist_foreach( selected, (GFunc)gtk_tree_row_reference_free, NULL );
1886 g_TextureBrowser.m_found_shaders.clear(); // delete old list
1887 TagBuilder.TagSearch( buffer, g_TextureBrowser.m_found_shaders );
1889 if ( !g_TextureBrowser.m_found_shaders.empty() ) { // found something
1890 size_t shaders_found = g_TextureBrowser.m_found_shaders.size();
1892 globalOutputStream() << "Found " << (unsigned int)shaders_found << " textures and shaders with " << tags_searched << "\n";
1893 ScopeDisableScreenUpdates disableScreenUpdates( "Searching...", "Loading Textures" );
1895 std::set<CopiedString>::iterator iter;
1897 for ( iter = g_TextureBrowser.m_found_shaders.begin(); iter != g_TextureBrowser.m_found_shaders.end(); iter++ )
1899 std::string path = ( *iter ).c_str();
1900 size_t pos = path.find_last_of( "/", path.size() );
1901 std::string name = path.substr( pos + 1, path.size() );
1902 path = path.substr( 0, pos + 1 );
1903 TextureDirectory_loadTexture( path.c_str(), name.c_str() );
1906 g_TextureBrowser.m_searchedTags = true;
1907 g_TextureBrowser_currentDirectory = tags_searched;
1909 g_TextureBrowser.m_nTotalHeight = 0;
1910 TextureBrowser_setOriginY( g_TextureBrowser, 0 );
1911 TextureBrowser_heightChanged( g_TextureBrowser );
1912 TextureBrowser_updateTitle();
1914 g_slist_free( selected );
1917 void TextureBrowser_toggleSearchButton(){
1918 gint page = gtk_notebook_get_current_page( GTK_NOTEBOOK( g_TextureBrowser.m_tag_notebook ) );
1920 if ( page == 0 ) { // tag page
1921 gtk_widget_show_all( g_TextureBrowser.m_search_button );
1924 gtk_widget_hide( g_TextureBrowser.m_search_button );
1928 void TextureBrowser_constructTagNotebook(){
1929 g_TextureBrowser.m_tag_notebook = ui::Widget(gtk_notebook_new());
1930 ui::Widget labelTags = ui::Label( "Tags" );
1931 ui::Widget labelTextures = ui::Label( "Textures" );
1933 gtk_notebook_append_page( GTK_NOTEBOOK( g_TextureBrowser.m_tag_notebook ), g_TextureBrowser.m_scr_win_tree, labelTextures );
1934 gtk_notebook_append_page( GTK_NOTEBOOK( g_TextureBrowser.m_tag_notebook ), g_TextureBrowser.m_scr_win_tags, labelTags );
1936 g_TextureBrowser.m_tag_notebook.connect( "switch-page", G_CALLBACK( TextureBrowser_toggleSearchButton ), NULL );
1938 gtk_widget_show_all( g_TextureBrowser.m_tag_notebook );
1941 void TextureBrowser_constructSearchButton(){
1942 ui::Widget image = ui::Widget(gtk_image_new_from_stock( GTK_STOCK_FIND, GTK_ICON_SIZE_SMALL_TOOLBAR ));
1943 g_TextureBrowser.m_search_button = ui::Button();
1944 g_TextureBrowser.m_search_button.connect( "clicked", G_CALLBACK( TextureBrowser_searchTags ), NULL );
1945 gtk_widget_set_tooltip_text(g_TextureBrowser.m_search_button, "Search with selected tags");
1946 g_TextureBrowser.m_search_button.add(image);
1949 void TextureBrowser_checkTagFile(){
1950 const char SHADERTAG_FILE[] = "shadertags.xml";
1951 CopiedString default_filename, rc_filename;
1952 StringOutputStream stream( 256 );
1954 stream << LocalRcPath_get();
1955 stream << SHADERTAG_FILE;
1956 rc_filename = stream.c_str();
1958 if ( file_exists( rc_filename.c_str() ) ) {
1959 g_TextureBrowser.m_tags = TagBuilder.OpenXmlDoc( rc_filename.c_str() );
1961 if ( g_TextureBrowser.m_tags ) {
1962 globalOutputStream() << "Loading tag file " << rc_filename.c_str() << ".\n";
1967 // load default tagfile
1969 stream << g_pGameDescription->mGameToolsPath.c_str();
1970 stream << SHADERTAG_FILE;
1971 default_filename = stream.c_str();
1973 if ( file_exists( default_filename.c_str() ) ) {
1974 g_TextureBrowser.m_tags = TagBuilder.OpenXmlDoc( default_filename.c_str(), rc_filename.c_str() );
1976 if ( g_TextureBrowser.m_tags ) {
1977 globalOutputStream() << "Loading default tag file " << default_filename.c_str() << ".\n";
1982 globalErrorStream() << "Unable to find default tag file " << default_filename.c_str() << ". No tag support.\n";
1987 void TextureBrowser_SetNotex(){
1988 StringOutputStream name( 256 );
1989 name << GlobalRadiant().getAppPath() << "bitmaps/" NOTEX_BASENAME ".png";
1990 g_notex = name.c_str();
1992 name = StringOutputStream(256);
1993 name << GlobalRadiant().getAppPath() << "bitmaps/" SHADERNOTEX_BASENAME " .png";
1994 g_shadernotex = name.c_str();
1997 ui::Widget TextureBrowser_constructWindow( ui::Window toplevel ){
1998 // The gl_widget and the tag assignment frame should be packed into a GtkVPaned with the slider
1999 // position stored in local.pref. gtk_paned_get_position() and gtk_paned_set_position() don't
2000 // seem to work in gtk 2.4 and the arrow buttons don't handle GTK_FILL, so here's another thing
2001 // for the "once-the-gtk-libs-are-updated-TODO-list" :x
2003 TextureBrowser_checkTagFile();
2004 TextureBrowser_SetNotex();
2006 GlobalShaderSystem().setActiveShadersChangedNotify( ReferenceCaller<TextureBrowser, TextureBrowser_activeShadersChanged>( g_TextureBrowser ) );
2008 g_TextureBrowser.m_parent = toplevel;
2010 ui::Widget table = ui::Table( 3, 3, FALSE );
2011 ui::Widget frame_table;
2012 ui::Widget vbox = ui::VBox( FALSE, 0 );
2013 gtk_table_attach( GTK_TABLE( table ), vbox, 0, 1, 1, 3, GTK_FILL, GTK_FILL, 0, 0 );
2016 ui::Widget menu_bar;
2019 menu_bar = ui::Widget(gtk_menu_bar_new());
2020 auto menu_view = ui::Menu();
2021 auto view_item = TextureBrowser_constructViewMenu( menu_view );
2022 gtk_menu_item_set_submenu( GTK_MENU_ITEM( view_item ), menu_view );
2023 gtk_menu_shell_append( GTK_MENU_SHELL( menu_bar ), view_item );
2025 auto menu_tools = ui::Menu();
2026 auto tools_item = TextureBrowser_constructToolsMenu( menu_tools );
2027 gtk_menu_item_set_submenu( GTK_MENU_ITEM( tools_item ), menu_tools );
2028 gtk_menu_shell_append( GTK_MENU_SHELL( menu_bar ), tools_item );
2030 gtk_table_attach( GTK_TABLE( table ), menu_bar, 0, 3, 0, 1, GTK_FILL, GTK_SHRINK, 0, 0 );
2033 { // Texture TreeView
2034 g_TextureBrowser.m_scr_win_tree = ui::ScrolledWindow();
2035 gtk_container_set_border_width( GTK_CONTAINER( g_TextureBrowser.m_scr_win_tree ), 0 );
2037 // vertical only scrolling for treeview
2038 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( g_TextureBrowser.m_scr_win_tree ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
2040 g_TextureBrowser.m_scr_win_tree.show();
2042 TextureBrowser_createTreeViewTree();
2044 gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW( g_TextureBrowser.m_scr_win_tree ), GTK_WIDGET( g_TextureBrowser.m_treeViewTree ) );
2045 g_TextureBrowser.m_treeViewTree.show();
2047 { // gl_widget scrollbar
2048 ui::Widget w = ui::Widget(gtk_vscrollbar_new( ui::Adjustment( 0,0,0,1,1,0 ) ));
2049 gtk_table_attach( GTK_TABLE( table ), w, 2, 3, 1, 2, GTK_SHRINK, GTK_FILL, 0, 0 );
2051 g_TextureBrowser.m_texture_scroll = w;
2053 auto vadjustment = ui::Adjustment(gtk_range_get_adjustment( GTK_RANGE( g_TextureBrowser.m_texture_scroll ) ));
2054 vadjustment.connect( "value_changed", G_CALLBACK( TextureBrowser_verticalScroll ), &g_TextureBrowser );
2056 widget_set_visible( g_TextureBrowser.m_texture_scroll, g_TextureBrowser.m_showTextureScrollbar );
2059 g_TextureBrowser.m_gl_widget = glwidget_new( FALSE );
2060 g_object_ref( g_TextureBrowser.m_gl_widget._handle );
2062 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 );
2063 gtk_widget_set_can_focus( g_TextureBrowser.m_gl_widget, true );
2065 gtk_table_attach_defaults( GTK_TABLE( table ), g_TextureBrowser.m_gl_widget, 1, 2, 1, 2 );
2066 g_TextureBrowser.m_gl_widget.show();
2068 g_TextureBrowser.m_sizeHandler = g_TextureBrowser.m_gl_widget.connect( "size_allocate", G_CALLBACK( TextureBrowser_size_allocate ), &g_TextureBrowser );
2069 g_TextureBrowser.m_exposeHandler = g_TextureBrowser.m_gl_widget.on_render( G_CALLBACK( TextureBrowser_expose ), &g_TextureBrowser );
2071 g_TextureBrowser.m_gl_widget.connect( "button_press_event", G_CALLBACK( TextureBrowser_button_press ), &g_TextureBrowser );
2072 g_TextureBrowser.m_gl_widget.connect( "button_release_event", G_CALLBACK( TextureBrowser_button_release ), &g_TextureBrowser );
2073 g_TextureBrowser.m_gl_widget.connect( "motion_notify_event", G_CALLBACK( TextureBrowser_motion ), &g_TextureBrowser );
2074 g_TextureBrowser.m_gl_widget.connect( "scroll_event", G_CALLBACK( TextureBrowser_scroll ), &g_TextureBrowser );
2078 if ( g_TextureBrowser.m_tags ) {
2079 { // fill tag GtkListStore
2080 g_TextureBrowser.m_all_tags_list = ui::ListStore(gtk_list_store_new( N_COLUMNS, G_TYPE_STRING ));
2081 GtkTreeSortable* sortable = GTK_TREE_SORTABLE( g_TextureBrowser.m_all_tags_list );
2082 gtk_tree_sortable_set_sort_column_id( sortable, TAG_COLUMN, GTK_SORT_ASCENDING );
2084 TagBuilder.GetAllTags( g_TextureBrowser.m_all_tags );
2085 TextureBrowser_buildTagList();
2088 auto menu_tags = ui::Menu();
2089 auto tags_item = TextureBrowser_constructTagsMenu( menu_tags );
2090 gtk_menu_item_set_submenu( GTK_MENU_ITEM( tags_item ), menu_tags );
2091 gtk_menu_shell_append( GTK_MENU_SHELL( menu_bar ), tags_item );
2094 g_TextureBrowser.m_scr_win_tags = ui::ScrolledWindow();
2095 gtk_container_set_border_width( GTK_CONTAINER( g_TextureBrowser.m_scr_win_tags ), 0 );
2097 // vertical only scrolling for treeview
2098 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( g_TextureBrowser.m_scr_win_tags ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
2100 TextureBrowser_createTreeViewTags();
2102 GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( g_TextureBrowser.m_treeViewTags ) );
2103 gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE );
2105 gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW( g_TextureBrowser.m_scr_win_tags ), GTK_WIDGET( g_TextureBrowser.m_treeViewTags ) );
2106 g_TextureBrowser.m_treeViewTags.show();
2108 { // Texture/Tag notebook
2109 TextureBrowser_constructTagNotebook();
2110 gtk_box_pack_start( GTK_BOX( vbox ), g_TextureBrowser.m_tag_notebook, TRUE, TRUE, 0 );
2112 { // Tag search button
2113 TextureBrowser_constructSearchButton();
2114 gtk_box_pack_end( GTK_BOX( vbox ), g_TextureBrowser.m_search_button, FALSE, FALSE, 0 );
2117 frame_table = ui::Table( 3, 3, FALSE );
2119 g_TextureBrowser.m_tag_frame = ui::Frame( "Tag assignment" );
2120 gtk_frame_set_label_align( GTK_FRAME( g_TextureBrowser.m_tag_frame ), 0.5, 0.5 );
2121 gtk_frame_set_shadow_type( GTK_FRAME( g_TextureBrowser.m_tag_frame ), GTK_SHADOW_NONE );
2123 gtk_table_attach( GTK_TABLE( table ), g_TextureBrowser.m_tag_frame, 1, 3, 2, 3, GTK_FILL, GTK_SHRINK, 0, 0 );
2127 g_TextureBrowser.m_tag_frame.add(frame_table);
2129 { // assigned tag list
2130 ui::Widget scrolled_win = ui::ScrolledWindow();
2131 gtk_container_set_border_width( GTK_CONTAINER( scrolled_win ), 0 );
2132 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scrolled_win ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
2134 g_TextureBrowser.m_assigned_store = ui::ListStore(gtk_list_store_new( N_COLUMNS, G_TYPE_STRING ));
2136 GtkTreeSortable* sortable = GTK_TREE_SORTABLE( g_TextureBrowser.m_assigned_store );
2137 gtk_tree_sortable_set_sort_column_id( sortable, TAG_COLUMN, GTK_SORT_ASCENDING );
2139 auto renderer = ui::CellRendererText();
2141 g_TextureBrowser.m_assigned_tree = ui::TreeView(ui::TreeModel( GTK_TREE_MODEL( g_TextureBrowser.m_assigned_store ) ));
2142 g_TextureBrowser.m_assigned_store.unref();
2143 g_TextureBrowser.m_assigned_tree.connect( "row-activated", (GCallback) TextureBrowser_removeTags, NULL );
2144 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( g_TextureBrowser.m_assigned_tree ), FALSE );
2146 GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( g_TextureBrowser.m_assigned_tree ) );
2147 gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE );
2149 GtkTreeViewColumn* column = ui::TreeViewColumn( "", renderer, {{"text", TAG_COLUMN}} );
2150 gtk_tree_view_append_column( GTK_TREE_VIEW( g_TextureBrowser.m_assigned_tree ), column );
2151 g_TextureBrowser.m_assigned_tree.show();
2153 scrolled_win.show();
2154 gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW( scrolled_win ), GTK_WIDGET( g_TextureBrowser.m_assigned_tree ) );
2156 gtk_table_attach( GTK_TABLE( frame_table ), scrolled_win, 0, 1, 1, 3, GTK_FILL, GTK_FILL, 0, 0 );
2158 { // available tag list
2159 ui::Widget scrolled_win = ui::ScrolledWindow();
2160 gtk_container_set_border_width( GTK_CONTAINER( scrolled_win ), 0 );
2161 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scrolled_win ), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS );
2163 g_TextureBrowser.m_available_store = ui::ListStore(gtk_list_store_new( N_COLUMNS, G_TYPE_STRING ));
2164 GtkTreeSortable* sortable = GTK_TREE_SORTABLE( g_TextureBrowser.m_available_store );
2165 gtk_tree_sortable_set_sort_column_id( sortable, TAG_COLUMN, GTK_SORT_ASCENDING );
2167 auto renderer = ui::CellRendererText();
2169 g_TextureBrowser.m_available_tree = ui::TreeView(ui::TreeModel( GTK_TREE_MODEL( g_TextureBrowser.m_available_store ) ));
2170 g_TextureBrowser.m_available_store.unref();
2171 g_TextureBrowser.m_available_tree.connect( "row-activated", (GCallback) TextureBrowser_assignTags, NULL );
2172 gtk_tree_view_set_headers_visible( GTK_TREE_VIEW( g_TextureBrowser.m_available_tree ), FALSE );
2174 GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( g_TextureBrowser.m_available_tree ) );
2175 gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE );
2177 GtkTreeViewColumn* column = ui::TreeViewColumn( "", renderer, {{"text", TAG_COLUMN}} );
2178 gtk_tree_view_append_column( GTK_TREE_VIEW( g_TextureBrowser.m_available_tree ), column );
2179 g_TextureBrowser.m_available_tree.show();
2181 scrolled_win.show();
2182 gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW( scrolled_win ), GTK_WIDGET( g_TextureBrowser.m_available_tree ) );
2184 gtk_table_attach( GTK_TABLE( frame_table ), scrolled_win, 2, 3, 1, 3, GTK_FILL, GTK_FILL, 0, 0 );
2186 { // tag arrow buttons
2187 auto m_btn_left = ui::Button();
2188 auto m_btn_right = ui::Button();
2189 auto m_arrow_left = ui::Widget(gtk_arrow_new( GTK_ARROW_LEFT, GTK_SHADOW_OUT ));
2190 auto m_arrow_right = ui::Widget(gtk_arrow_new( GTK_ARROW_RIGHT, GTK_SHADOW_OUT ));
2191 m_btn_left.add(m_arrow_left);
2192 m_btn_right.add(m_arrow_right);
2194 // workaround. the size of the tag frame depends of the requested size of the arrow buttons.
2195 gtk_widget_set_size_request( m_arrow_left, -1, 68 );
2196 gtk_widget_set_size_request( m_arrow_right, -1, 68 );
2198 gtk_table_attach( GTK_TABLE( frame_table ), m_btn_left, 1, 2, 1, 2, GTK_SHRINK, GTK_EXPAND, 0, 0 );
2199 gtk_table_attach( GTK_TABLE( frame_table ), m_btn_right, 1, 2, 2, 3, GTK_SHRINK, GTK_EXPAND, 0, 0 );
2201 m_btn_left.connect( "clicked", G_CALLBACK( TextureBrowser_assignTags ), NULL );
2202 m_btn_right.connect( "clicked", G_CALLBACK( TextureBrowser_removeTags ), NULL );
2206 m_arrow_left.show();
2207 m_arrow_right.show();
2209 { // tag fram labels
2210 ui::Widget m_lbl_assigned = ui::Label( "Assigned" );
2211 ui::Widget m_lbl_unassigned = ui::Label( "Available" );
2213 gtk_table_attach( GTK_TABLE( frame_table ), m_lbl_assigned, 0, 1, 0, 1, GTK_EXPAND, GTK_SHRINK, 0, 0 );
2214 gtk_table_attach( GTK_TABLE( frame_table ), m_lbl_unassigned, 2, 3, 0, 1, GTK_EXPAND, GTK_SHRINK, 0, 0 );
2216 m_lbl_assigned.show();
2217 m_lbl_unassigned.show();
2220 else { // no tag support, show the texture tree only
2221 gtk_box_pack_start( GTK_BOX( vbox ), g_TextureBrowser.m_scr_win_tree, TRUE, TRUE, 0 );
2224 // TODO do we need this?
2225 //gtk_container_set_focus_chain(GTK_CONTAINER(hbox_table), NULL);
2230 void TextureBrowser_destroyWindow(){
2231 GlobalShaderSystem().setActiveShadersChangedNotify( Callback() );
2233 g_signal_handler_disconnect( G_OBJECT( g_TextureBrowser.m_gl_widget ), g_TextureBrowser.m_sizeHandler );
2234 g_signal_handler_disconnect( G_OBJECT( g_TextureBrowser.m_gl_widget ), g_TextureBrowser.m_exposeHandler );
2236 g_TextureBrowser.m_gl_widget.unref();
2239 const Vector3& TextureBrowser_getBackgroundColour( TextureBrowser& textureBrowser ){
2240 return textureBrowser.color_textureback;
2243 void TextureBrowser_setBackgroundColour( TextureBrowser& textureBrowser, const Vector3& colour ){
2244 textureBrowser.color_textureback = colour;
2245 TextureBrowser_queueDraw( textureBrowser );
2248 void TextureBrowser_selectionHelper( GtkTreeModel* model, GtkTreePath* path, GtkTreeIter* iter, GSList** selected ){
2249 g_assert( selected != NULL );
2252 gtk_tree_model_get( model, iter, TAG_COLUMN, &name, -1 );
2253 *selected = g_slist_append( *selected, name );
2256 void TextureBrowser_shaderInfo(){
2257 const char* name = TextureBrowser_GetSelectedShader( g_TextureBrowser );
2258 IShader* shader = QERApp_Shader_ForName( name );
2260 DoShaderInfoDlg( name, shader->getShaderFileName(), "Shader Info" );
2265 void TextureBrowser_addTag(){
2268 EMessageBoxReturn result = DoShaderTagDlg( &tag, "Add shader tag" );
2270 if ( result == eIDOK && !tag.empty() ) {
2271 GtkTreeIter iter, iter2;
2272 g_TextureBrowser.m_all_tags.insert( tag.c_str() );
2273 gtk_list_store_append( g_TextureBrowser.m_available_store, &iter );
2274 gtk_list_store_set( g_TextureBrowser.m_available_store, &iter, TAG_COLUMN, tag.c_str(), -1 );
2276 // Select the currently added tag in the available list
2277 GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( g_TextureBrowser.m_available_tree ) );
2278 gtk_tree_selection_select_iter( selection, &iter );
2280 gtk_list_store_append( g_TextureBrowser.m_all_tags_list, &iter2 );
2281 gtk_list_store_set( g_TextureBrowser.m_all_tags_list, &iter2, TAG_COLUMN, tag.c_str(), -1 );
2285 void TextureBrowser_renameTag(){
2286 /* WORKAROUND: The tag treeview is set to GTK_SELECTION_MULTIPLE. Because
2287 gtk_tree_selection_get_selected() doesn't work with GTK_SELECTION_MULTIPLE,
2288 we need to count the number of selected rows first and use
2289 gtk_tree_selection_selected_foreach() then to go through the list of selected
2290 rows (which always containins a single row).
2293 GSList* selected = NULL;
2295 GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( g_TextureBrowser.m_treeViewTags ) );
2296 gtk_tree_selection_selected_foreach( selection, GtkTreeSelectionForeachFunc( TextureBrowser_selectionHelper ), &selected );
2298 if ( g_slist_length( selected ) == 1 ) { // we only rename a single tag
2299 CopiedString newTag;
2300 EMessageBoxReturn result = DoShaderTagDlg( &newTag, "Rename shader tag" );
2302 if ( result == eIDOK && !newTag.empty() ) {
2303 GtkTreeIter iterList;
2305 gchar* oldTag = (char*)selected->data;
2307 bool row = gtk_tree_model_get_iter_first( GTK_TREE_MODEL( g_TextureBrowser.m_all_tags_list ), &iterList ) != 0;
2311 gtk_tree_model_get( GTK_TREE_MODEL( g_TextureBrowser.m_all_tags_list ), &iterList, TAG_COLUMN, &rowTag, -1 );
2313 if ( strcmp( rowTag, oldTag ) == 0 ) {
2314 gtk_list_store_set( g_TextureBrowser.m_all_tags_list, &iterList, TAG_COLUMN, newTag.c_str(), -1 );
2316 row = gtk_tree_model_iter_next( GTK_TREE_MODEL( g_TextureBrowser.m_all_tags_list ), &iterList ) != 0;
2319 TagBuilder.RenameShaderTag( oldTag, newTag.c_str() );
2321 g_TextureBrowser.m_all_tags.erase( (CopiedString)oldTag );
2322 g_TextureBrowser.m_all_tags.insert( newTag );
2324 BuildStoreAssignedTags( g_TextureBrowser.m_assigned_store, g_TextureBrowser.shader.c_str(), &g_TextureBrowser );
2325 BuildStoreAvailableTags( g_TextureBrowser.m_available_store, g_TextureBrowser.m_assigned_store, g_TextureBrowser.m_all_tags, &g_TextureBrowser );
2330 ui::Widget(GTK_WIDGET( g_TextureBrowser.m_parent )).alert( "Select a single tag for renaming." );
2334 void TextureBrowser_deleteTag(){
2335 GSList* selected = NULL;
2337 GtkTreeSelection* selection = gtk_tree_view_get_selection( GTK_TREE_VIEW( g_TextureBrowser.m_treeViewTags ) );
2338 gtk_tree_selection_selected_foreach( selection, GtkTreeSelectionForeachFunc( TextureBrowser_selectionHelper ), &selected );
2340 if ( g_slist_length( selected ) == 1 ) { // we only delete a single tag
2341 auto result = ui::Widget(GTK_WIDGET( g_TextureBrowser.m_parent )).alert( "Are you sure you want to delete the selected tag?", "Delete Tag", ui::alert_type::YESNO, ui::alert_icon::Question );
2343 if ( result == ui::alert_response::YES ) {
2344 GtkTreeIter iterSelected;
2347 gchar* tagSelected = (char*)selected->data;
2349 bool row = gtk_tree_model_get_iter_first( GTK_TREE_MODEL( g_TextureBrowser.m_all_tags_list ), &iterSelected ) != 0;
2353 gtk_tree_model_get( GTK_TREE_MODEL( g_TextureBrowser.m_all_tags_list ), &iterSelected, TAG_COLUMN, &rowTag, -1 );
2355 if ( strcmp( rowTag, tagSelected ) == 0 ) {
2356 gtk_list_store_remove( g_TextureBrowser.m_all_tags_list, &iterSelected );
2359 row = gtk_tree_model_iter_next( GTK_TREE_MODEL( g_TextureBrowser.m_all_tags_list ), &iterSelected ) != 0;
2362 TagBuilder.DeleteTag( tagSelected );
2363 g_TextureBrowser.m_all_tags.erase( (CopiedString)tagSelected );
2365 BuildStoreAssignedTags( g_TextureBrowser.m_assigned_store, g_TextureBrowser.shader.c_str(), &g_TextureBrowser );
2366 BuildStoreAvailableTags( g_TextureBrowser.m_available_store, g_TextureBrowser.m_assigned_store, g_TextureBrowser.m_all_tags, &g_TextureBrowser );
2370 ui::Widget(GTK_WIDGET( g_TextureBrowser.m_parent )).alert( "Select a single tag for deletion." );
2374 void TextureBrowser_copyTag(){
2375 g_TextureBrowser.m_copied_tags.clear();
2376 TagBuilder.GetShaderTags( g_TextureBrowser.shader.c_str(), g_TextureBrowser.m_copied_tags );
2379 void TextureBrowser_pasteTag(){
2380 IShader* ishader = QERApp_Shader_ForName( g_TextureBrowser.shader.c_str() );
2381 CopiedString shader = g_TextureBrowser.shader.c_str();
2383 if ( !TagBuilder.CheckShaderTag( shader.c_str() ) ) {
2384 CopiedString shaderFile = ishader->getShaderFileName();
2385 if ( shaderFile.empty() ) {
2387 TagBuilder.AddShaderNode( shader.c_str(), CUSTOM, TEXTURE );
2392 TagBuilder.AddShaderNode( shader.c_str(), CUSTOM, SHADER );
2395 for ( size_t i = 0; i < g_TextureBrowser.m_copied_tags.size(); ++i )
2397 TagBuilder.AddShaderTag( shader.c_str(), g_TextureBrowser.m_copied_tags[i].c_str(), TAG );
2402 for ( size_t i = 0; i < g_TextureBrowser.m_copied_tags.size(); ++i )
2404 if ( !TagBuilder.CheckShaderTag( shader.c_str(), g_TextureBrowser.m_copied_tags[i].c_str() ) ) {
2405 // the tag doesn't exist - let's add it
2406 TagBuilder.AddShaderTag( shader.c_str(), g_TextureBrowser.m_copied_tags[i].c_str(), TAG );
2413 TagBuilder.SaveXmlDoc();
2414 BuildStoreAssignedTags( g_TextureBrowser.m_assigned_store, shader.c_str(), &g_TextureBrowser );
2415 BuildStoreAvailableTags( g_TextureBrowser.m_available_store, g_TextureBrowser.m_assigned_store, g_TextureBrowser.m_all_tags, &g_TextureBrowser );
2418 void TextureBrowser_RefreshShaders(){
2419 ScopeDisableScreenUpdates disableScreenUpdates( "Processing...", "Loading Shaders" );
2420 GlobalShaderSystem().refresh();
2422 GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(GlobalTextureBrowser().m_treeViewTree));
2423 GtkTreeModel* model = NULL;
2425 if ( gtk_tree_selection_get_selected (selection, &model, &iter) )
2427 gchar dirName[1024];
2430 gtk_tree_model_get( model, &iter, 0, &buffer, -1 );
2431 strcpy( dirName, buffer );
2433 if ( !TextureBrowser_showWads() ) {
2434 strcat( dirName, "/" );
2436 TextureBrowser_ShowDirectory( GlobalTextureBrowser(), dirName );
2437 TextureBrowser_queueDraw( GlobalTextureBrowser() );
2441 void TextureBrowser_ToggleShowShaders(){
2442 g_TextureBrowser.m_showShaders ^= 1;
2443 g_TextureBrowser.m_showshaders_item.update();
2444 TextureBrowser_queueDraw( g_TextureBrowser );
2447 void TextureBrowser_ToggleShowShaderListOnly(){
2448 g_TextureBrowser_shaderlistOnly ^= 1;
2449 g_TextureBrowser.m_showshaderlistonly_item.update();
2451 TextureBrowser_constructTreeStore();
2454 void TextureBrowser_showAll(){
2455 g_TextureBrowser_currentDirectory = "";
2456 g_TextureBrowser.m_searchedTags = false;
2457 TextureBrowser_heightChanged( g_TextureBrowser );
2458 TextureBrowser_updateTitle();
2461 void TextureBrowser_showUntagged(){
2462 auto result = ui::Widget(GTK_WIDGET( g_TextureBrowser.m_parent )).alert( "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 );
2464 if ( result == ui::alert_response::YES ) {
2465 g_TextureBrowser.m_found_shaders.clear();
2466 TagBuilder.GetUntagged( g_TextureBrowser.m_found_shaders );
2467 std::set<CopiedString>::iterator iter;
2469 ScopeDisableScreenUpdates disableScreenUpdates( "Searching untagged textures...", "Loading Textures" );
2471 for ( iter = g_TextureBrowser.m_found_shaders.begin(); iter != g_TextureBrowser.m_found_shaders.end(); iter++ )
2473 std::string path = ( *iter ).c_str();
2474 size_t pos = path.find_last_of( "/", path.size() );
2475 std::string name = path.substr( pos + 1, path.size() );
2476 path = path.substr( 0, pos + 1 );
2477 TextureDirectory_loadTexture( path.c_str(), name.c_str() );
2478 globalErrorStream() << path.c_str() << name.c_str() << "\n";
2481 g_TextureBrowser_currentDirectory = "Untagged";
2482 TextureBrowser_queueDraw( GlobalTextureBrowser() );
2483 TextureBrowser_heightChanged( g_TextureBrowser );
2484 TextureBrowser_updateTitle();
2488 void TextureBrowser_FixedSize(){
2489 g_TextureBrowser_fixedSize ^= 1;
2490 GlobalTextureBrowser().m_fixedsize_item.update();
2491 TextureBrowser_activeShadersChanged( GlobalTextureBrowser() );
2494 void TextureBrowser_FilterMissing(){
2495 g_TextureBrowser_filterMissing ^= 1;
2496 GlobalTextureBrowser().m_filternotex_item.update();
2497 TextureBrowser_activeShadersChanged( GlobalTextureBrowser() );
2498 TextureBrowser_RefreshShaders();
2501 void TextureBrowser_FilterFallback(){
2502 g_TextureBrowser_filterFallback ^= 1;
2503 GlobalTextureBrowser().m_hidenotex_item.update();
2504 TextureBrowser_activeShadersChanged( GlobalTextureBrowser() );
2505 TextureBrowser_RefreshShaders();
2508 void TextureBrowser_EnableAlpha(){
2509 g_TextureBrowser_enableAlpha ^= 1;
2510 GlobalTextureBrowser().m_enablealpha_item.update();
2511 TextureBrowser_activeShadersChanged( GlobalTextureBrowser() );
2514 void TextureBrowser_exportTitle( const StringImportCallback& importer ){
2515 StringOutputStream buffer( 64 );
2516 buffer << "Textures: ";
2517 if ( !string_empty( g_TextureBrowser_currentDirectory.c_str() ) ) {
2518 buffer << g_TextureBrowser_currentDirectory.c_str();
2524 importer( buffer.c_str() );
2528 void TextureScaleImport( TextureBrowser& textureBrowser, int value ){
2532 TextureBrowser_setScale( textureBrowser, 10 );
2535 TextureBrowser_setScale( textureBrowser, 25 );
2538 TextureBrowser_setScale( textureBrowser, 50 );
2541 TextureBrowser_setScale( textureBrowser, 100 );
2544 TextureBrowser_setScale( textureBrowser, 200 );
2548 typedef ReferenceCaller1<TextureBrowser, int, TextureScaleImport> TextureScaleImportCaller;
2550 void TextureScaleExport( TextureBrowser& textureBrowser, const IntImportCallback& importer ){
2551 switch ( textureBrowser.m_textureScale )
2570 typedef ReferenceCaller1<TextureBrowser, const IntImportCallback&, TextureScaleExport> TextureScaleExportCaller;
2573 void UniformTextureSizeImport( TextureBrowser& textureBrowser, int value ){
2576 TextureBrowser_setUniformSize( textureBrowser, value );
2578 typedef ReferenceCaller1<TextureBrowser, int, UniformTextureSizeImport> UniformTextureSizeImportCaller;
2580 void TextureBrowser_constructPreferences( PreferencesPage& page ){
2581 page.appendCheckBox(
2582 "", "Texture scrollbar",
2583 TextureBrowserImportShowScrollbarCaller( GlobalTextureBrowser() ),
2584 BoolExportCaller( GlobalTextureBrowser().m_showTextureScrollbar )
2587 const char* texture_scale[] = { "10%", "25%", "50%", "100%", "200%" };
2589 "Texture Thumbnail Scale",
2590 STRING_ARRAY_RANGE( texture_scale ),
2591 IntImportCallback( TextureScaleImportCaller( GlobalTextureBrowser() ) ),
2592 IntExportCallback( TextureScaleExportCaller( GlobalTextureBrowser() ) )
2596 "Texture Thumbnail Size",
2597 GlobalTextureBrowser().m_uniformTextureSize,
2598 GlobalTextureBrowser().m_uniformTextureSize,
2601 page.appendEntry( "Mousewheel Increment", GlobalTextureBrowser().m_mouseWheelScrollIncrement );
2603 const char* startup_shaders[] = { "None", TextureBrowser_getComonShadersName() };
2604 page.appendCombo( "Load Shaders at Startup", reinterpret_cast<int&>( GlobalTextureBrowser().m_startupShaders ), STRING_ARRAY_RANGE( startup_shaders ) );
2607 void TextureBrowser_constructPage( PreferenceGroup& group ){
2608 PreferencesPage page( group.createPage( "Texture Browser", "Texture Browser Preferences" ) );
2609 TextureBrowser_constructPreferences( page );
2611 void TextureBrowser_registerPreferencesPage(){
2612 PreferencesDialog_addSettingsPage( FreeCaller1<PreferenceGroup&, TextureBrowser_constructPage>() );
2616 #include "preferencesystem.h"
2617 #include "stringio.h"
2619 typedef ReferenceCaller1<TextureBrowser, std::size_t, TextureBrowser_setScale> TextureBrowserSetScaleCaller;
2623 void TextureClipboard_textureSelected( const char* shader );
2625 void TextureBrowser_Construct(){
2626 GlobalCommands_insert( "ShaderInfo", FreeCaller<TextureBrowser_shaderInfo>() );
2627 GlobalCommands_insert( "ShowUntagged", FreeCaller<TextureBrowser_showUntagged>() );
2628 GlobalCommands_insert( "AddTag", FreeCaller<TextureBrowser_addTag>() );
2629 GlobalCommands_insert( "RenameTag", FreeCaller<TextureBrowser_renameTag>() );
2630 GlobalCommands_insert( "DeleteTag", FreeCaller<TextureBrowser_deleteTag>() );
2631 GlobalCommands_insert( "CopyTag", FreeCaller<TextureBrowser_copyTag>() );
2632 GlobalCommands_insert( "PasteTag", FreeCaller<TextureBrowser_pasteTag>() );
2633 GlobalCommands_insert( "RefreshShaders", FreeCaller<VFS_Refresh>() );
2634 GlobalToggles_insert( "ShowInUse", FreeCaller<TextureBrowser_ToggleHideUnused>(), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_hideunused_item ), Accelerator( 'U' ) );
2635 GlobalCommands_insert( "ShowAllTextures", FreeCaller<TextureBrowser_showAll>(), Accelerator( 'A', (GdkModifierType)GDK_CONTROL_MASK ) );
2636 GlobalCommands_insert( "ToggleTextures", FreeCaller<TextureBrowser_toggleShow>(), Accelerator( 'T' ) );
2637 GlobalToggles_insert( "ToggleShowShaders", FreeCaller<TextureBrowser_ToggleShowShaders>(), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_showshaders_item ) );
2638 GlobalToggles_insert( "ToggleShowShaderlistOnly", FreeCaller<TextureBrowser_ToggleShowShaderListOnly>(), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_showshaderlistonly_item ) );
2639 GlobalToggles_insert( "FixedSize", FreeCaller<TextureBrowser_FixedSize>(), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_fixedsize_item ) );
2640 GlobalToggles_insert( "FilterMissing", FreeCaller<TextureBrowser_FilterMissing>(), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_filternotex_item ) );
2641 GlobalToggles_insert( "FilterFallback", FreeCaller<TextureBrowser_FilterFallback>(), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_hidenotex_item ) );
2642 GlobalToggles_insert( "EnableAlpha", FreeCaller<TextureBrowser_EnableAlpha>(), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_enablealpha_item ) );
2644 GlobalPreferenceSystem().registerPreference( "TextureScale",
2645 makeSizeStringImportCallback( TextureBrowserSetScaleCaller( g_TextureBrowser ) ),
2646 SizeExportStringCaller( g_TextureBrowser.m_textureScale )
2648 GlobalPreferenceSystem().registerPreference( "UniformTextureSize",
2649 makeIntStringImportCallback(UniformTextureSizeImportCaller(g_TextureBrowser)),
2650 IntExportStringCaller(g_TextureBrowser.m_uniformTextureSize) );
2651 GlobalPreferenceSystem().registerPreference( "TextureScrollbar",
2652 makeBoolStringImportCallback( TextureBrowserImportShowScrollbarCaller( g_TextureBrowser ) ),
2653 BoolExportStringCaller( GlobalTextureBrowser().m_showTextureScrollbar )
2655 GlobalPreferenceSystem().registerPreference( "ShowShaders", BoolImportStringCaller( GlobalTextureBrowser().m_showShaders ), BoolExportStringCaller( GlobalTextureBrowser().m_showShaders ) );
2656 GlobalPreferenceSystem().registerPreference( "ShowShaderlistOnly", BoolImportStringCaller( g_TextureBrowser_shaderlistOnly ), BoolExportStringCaller( g_TextureBrowser_shaderlistOnly ) );
2657 GlobalPreferenceSystem().registerPreference( "FixedSize", BoolImportStringCaller( g_TextureBrowser_fixedSize ), BoolExportStringCaller( g_TextureBrowser_fixedSize ) );
2658 GlobalPreferenceSystem().registerPreference( "FilterMissing", BoolImportStringCaller( g_TextureBrowser_filterMissing ), BoolExportStringCaller( g_TextureBrowser_filterMissing ) );
2659 GlobalPreferenceSystem().registerPreference( "EnableAlpha", BoolImportStringCaller( g_TextureBrowser_enableAlpha ), BoolExportStringCaller( g_TextureBrowser_enableAlpha ) );
2660 GlobalPreferenceSystem().registerPreference( "LoadShaders", IntImportStringCaller( reinterpret_cast<int&>( GlobalTextureBrowser().m_startupShaders ) ), IntExportStringCaller( reinterpret_cast<int&>( GlobalTextureBrowser().m_startupShaders ) ) );
2661 GlobalPreferenceSystem().registerPreference( "WheelMouseInc", SizeImportStringCaller( GlobalTextureBrowser().m_mouseWheelScrollIncrement ), SizeExportStringCaller( GlobalTextureBrowser().m_mouseWheelScrollIncrement ) );
2662 GlobalPreferenceSystem().registerPreference( "SI_Colors0", Vector3ImportStringCaller( GlobalTextureBrowser().color_textureback ), Vector3ExportStringCaller( GlobalTextureBrowser().color_textureback ) );
2664 g_TextureBrowser.shader = texdef_name_default();
2666 Textures_setModeChangedNotify( ReferenceCaller<TextureBrowser, TextureBrowser_queueDraw>( g_TextureBrowser ) );
2668 TextureBrowser_registerPreferencesPage();
2670 GlobalShaderSystem().attach( g_ShadersObserver );
2672 TextureBrowser_textureSelected = TextureClipboard_textureSelected;
2674 void TextureBrowser_Destroy(){
2675 GlobalShaderSystem().detach( g_ShadersObserver );
2677 Textures_setModeChangedNotify( Callback() );