]> git.rm.cloudns.org Git - xonotic/netradiant.git/commitdiff
Option to show transparency in the texture browser
authorMattia Basaglia <mattia.basaglia@gmail.com>
Sun, 19 Jul 2015 13:29:40 +0000 (15:29 +0200)
committerMattia Basaglia <mattia.basaglia@gmail.com>
Sun, 19 Jul 2015 13:29:40 +0000 (15:29 +0200)
radiant/texwindow.cpp

index 142d3c49a7e06d37fa445a9acf0de5f7cad4b44d..0d8f52b638e31a1f39a63b093a1738d09365f4dc 100644 (file)
@@ -134,6 +134,7 @@ namespace
 bool g_TextureBrowser_shaderlistOnly = false;
 bool g_TextureBrowser_fixedSize = false;
 bool g_TextureBrowser_filterNotex = false;
+bool g_TextureBrowser_enableAlpha = false;
 }
 
 class DeferredAdjustment
@@ -203,6 +204,9 @@ typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_fixedSize> Texture
 void TextureBrowser_filterNotex( const BoolImportCallback& importer );
 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_filterNotex> TextureBrowserFilterNotexExport;
 
+void TextureBrowser_enableAlpha( const BoolImportCallback& importer );
+typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_enableAlpha> TextureBrowserEnableAlphaExport;
+
 class TextureBrowser
 {
 public:
@@ -238,6 +242,7 @@ ToggleItem m_showshaders_item;
 ToggleItem m_showshaderlistonly_item;
 ToggleItem m_fixedsize_item;
 ToggleItem m_filternotex_item;
+ToggleItem m_enablealpha_item;
 
 guint m_sizeHandler;
 guint m_exposeHandler;
@@ -307,6 +312,7 @@ TextureBrowser() :
        m_showshaderlistonly_item( TextureBrowserShowShaderlistOnlyExport() ),
        m_fixedsize_item( TextureBrowserFixedSizeExport() ),
        m_filternotex_item( TextureBrowserFilterNotexExport() ),
+       m_enablealpha_item( TextureBrowserEnableAlphaExport() ),
        m_heightChanged( true ),
        m_originInvalid( true ),
        m_scrollAdjustment( TextureBrowser_scrollChanged, this ),
@@ -828,6 +834,11 @@ void TextureBrowser_filterNotex( const BoolImportCallback& importer ){
 }
 typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_filterNotex> TextureBrowser_filterNotexExport;
 
+void TextureBrowser_enableAlpha( const BoolImportCallback& importer ){
+       importer( g_TextureBrowser_enableAlpha );
+}
+typedef FreeCaller1<const BoolImportCallback&, TextureBrowser_enableAlpha> TextureBrowser_enableAlphaExport;
+
 void TextureBrowser_SetHideUnused( TextureBrowser& textureBrowser, bool hideUnused ){
        if ( hideUnused ) {
                textureBrowser.m_hideUnused = true;
@@ -1021,7 +1032,13 @@ void Texture_Draw( TextureBrowser& textureBrowser ){
 
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
        glDisable( GL_DEPTH_TEST );
-       glDisable( GL_BLEND );
+       if ( g_TextureBrowser_enableAlpha ) {
+               glEnable( GL_BLEND );
+               glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+       }
+       else {
+               glDisable( GL_BLEND );
+       }
        glOrtho( 0, textureBrowser.width, originy - textureBrowser.height, originy, -100, 100 );
        glEnable( GL_TEXTURE_2D );
 
@@ -1114,6 +1131,30 @@ void Texture_Draw( TextureBrowser& textureBrowser ){
                                }
                        }
 
+                       // draw checkerboard for transparent textures
+                       if ( g_TextureBrowser_enableAlpha )
+                       {
+                               glDisable( GL_TEXTURE_2D );
+                               glBegin( GL_QUADS );
+                               int font_height = TextureBrowser_fontHeight( textureBrowser );
+                               for ( int i = 0; i < nHeight; i += 8 )
+                                       for ( int j = 0; j < nWidth; j += 8 )
+                                       {
+                                               unsigned char color = (i + j) / 8 % 2 ? 0x66 : 0x99;
+                                               glColor3ub( color, color, color );
+                                               int left = j;
+                                               int right = std::min(j+8, nWidth);
+                                               int top = i;
+                                               int bottom = std::min(i+8, nHeight);
+                                               glVertex2i(x + right, y - nHeight - font_height + top);
+                                               glVertex2i(x + left,  y - nHeight - font_height + top);
+                                               glVertex2i(x + left,  y - nHeight - font_height + bottom);
+                                               glVertex2i(x + right, y - nHeight - font_height + bottom);
+                                       }
+                               glEnd();
+                               glEnable( GL_TEXTURE_2D );
+                       }
+
                        // Draw the texture
                        glBindTexture( GL_TEXTURE_2D, q->texture_number );
                        GlobalOpenGL_debugAssertNoErrors();
@@ -1591,6 +1632,9 @@ GtkMenuItem* TextureBrowser_constructViewMenu( GtkMenu* menu ){
                gtk_widget_set_sensitive( g_TextureBrowser.m_shader_info_item, FALSE );
        }
 
+       menu_separator( menu );
+       create_check_menu_item_with_mnemonic( menu, "Show Transparency", "EnableAlpha" );
+
        return textures_menu_item;
 }
 
@@ -2388,6 +2432,12 @@ void TextureBrowser_FilterNotex(){
        TextureBrowser_activeShadersChanged( GlobalTextureBrowser() );
 }
 
+void TextureBrowser_EnableAlpha(){
+       g_TextureBrowser_enableAlpha ^= 1;
+       GlobalTextureBrowser().m_enablealpha_item.update();
+       TextureBrowser_activeShadersChanged( GlobalTextureBrowser() );
+}
+
 void TextureBrowser_exportTitle( const StringImportCallback& importer ){
        StringOutputStream buffer( 64 );
        buffer << "Textures: ";
@@ -2501,6 +2551,7 @@ void TextureBrowser_Construct(){
        GlobalToggles_insert( "ToggleShowShaderlistOnly", FreeCaller<TextureBrowser_ToggleShowShaderListOnly>(), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_showshaderlistonly_item ) );
        GlobalToggles_insert( "FixedSize", FreeCaller<TextureBrowser_FixedSize>(), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_fixedsize_item ) );
        GlobalToggles_insert( "FilterNotex", FreeCaller<TextureBrowser_FilterNotex>(), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_filternotex_item ) );
+       GlobalToggles_insert( "EnableAlpha", FreeCaller<TextureBrowser_EnableAlpha>(), ToggleItem::AddCallbackCaller( g_TextureBrowser.m_enablealpha_item ) );
 
        GlobalPreferenceSystem().registerPreference( "TextureScale",
                                                                                                 makeSizeStringImportCallback( TextureBrowserSetScaleCaller( g_TextureBrowser ) ),
@@ -2514,6 +2565,7 @@ void TextureBrowser_Construct(){
        GlobalPreferenceSystem().registerPreference( "ShowShaderlistOnly", BoolImportStringCaller( g_TextureBrowser_shaderlistOnly ), BoolExportStringCaller( g_TextureBrowser_shaderlistOnly ) );
        GlobalPreferenceSystem().registerPreference( "FixedSize", BoolImportStringCaller( g_TextureBrowser_fixedSize ), BoolExportStringCaller( g_TextureBrowser_fixedSize ) );
        GlobalPreferenceSystem().registerPreference( "FilterNotex", BoolImportStringCaller( g_TextureBrowser_filterNotex ), BoolExportStringCaller( g_TextureBrowser_filterNotex ) );
+       GlobalPreferenceSystem().registerPreference( "EnableAlpha", BoolImportStringCaller( g_TextureBrowser_enableAlpha ), BoolExportStringCaller( g_TextureBrowser_enableAlpha ) );
        GlobalPreferenceSystem().registerPreference( "LoadShaders", IntImportStringCaller( reinterpret_cast<int&>( GlobalTextureBrowser().m_startupShaders ) ), IntExportStringCaller( reinterpret_cast<int&>( GlobalTextureBrowser().m_startupShaders ) ) );
        GlobalPreferenceSystem().registerPreference( "WheelMouseInc", SizeImportStringCaller( GlobalTextureBrowser().m_mouseWheelScrollIncrement ), SizeExportStringCaller( GlobalTextureBrowser().m_mouseWheelScrollIncrement ) );
        GlobalPreferenceSystem().registerPreference( "SI_Colors0", Vector3ImportStringCaller( GlobalTextureBrowser().color_textureback ), Vector3ExportStringCaller( GlobalTextureBrowser().color_textureback ) );