]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/texwindow.cpp
Merge commit '833d947959e424126907d552840203a557097e8f' into master-merge
[xonotic/netradiant.git] / radiant / texwindow.cpp
index f1cc83f5bee9abd7a5429a6dc0c77e33eccdf0ff..1e213b5745b8ab7b673c401d2a6bbfcaa84001eb 100644 (file)
@@ -332,55 +332,18 @@ bool m_hideUnused;
 bool m_rmbSelected;
 bool m_searchedTags;
 bool m_tags;
+bool m_move_started;
 // The uniform size (in pixels) that textures are resized to when m_resizeTextures is true.
 int m_uniformTextureSize;
 int m_uniformTextureMinSize;
 
 // Return the display width of a texture in the texture browser
-/*void getTextureWH( qtexture_t* tex, int *width, int *height ){
-       if ( !g_TextureBrowser_fixedSize ) {
-               // Don't use uniform size
-               *width = (int)( tex->width * ( (float)m_textureScale / 100 ) );
-               *height = (int)( tex->height * ( (float)m_textureScale / 100 ) );
-
-       }
-       else if ( tex->width >= tex->height ) {
-               // Texture is square, or wider than it is tall
-               if ( tex->width >= m_uniformTextureSize ){
-                       *width = m_uniformTextureSize;
-                       *height = (int)( m_uniformTextureSize * ( (float)tex->height / tex->width ) );
-               }
-               else if ( tex->width <= m_uniformTextureMinSize ){
-                       *width = m_uniformTextureMinSize;
-                       *height = (int)( m_uniformTextureMinSize * ( (float)tex->height / tex->width ) );
-               }
-               else {
-                       *width = tex->width;
-                       *height = tex->height;
-               }
-       }
-       else {
-               // Texture taller than it is wide
-               if ( tex->height >= m_uniformTextureSize ){
-                       *height = m_uniformTextureSize;
-                       *width = (int)( m_uniformTextureSize * ( (float)tex->width / tex->height ) );
-               }
-               else if ( tex->height <= m_uniformTextureMinSize ){
-                       *height = m_uniformTextureMinSize;
-                       *width = (int)( m_uniformTextureMinSize * ( (float)tex->width / tex->height ) );
-               }
-               else {
-                       *width = tex->width;
-                       *height = tex->height;
-               }
-       }
-}
-
-*/
 void getTextureWH( qtexture_t* tex, int &W, int &H ){
                // Don't use uniform size
                W = (int)( tex->width * ( (float)m_textureScale / 100 ) );
                H = (int)( tex->height * ( (float)m_textureScale / 100 ) );
+               if ( W < 1 ) W = 1;
+               if ( H < 1 ) H = 1;
 
        if ( g_TextureBrowser_fixedSize ){
                if      ( W >= H ) {
@@ -433,7 +396,8 @@ TextureBrowser() :
        m_searchedTags( false ),
        m_tags( false ),
        m_uniformTextureSize( 160 ),
-       m_uniformTextureMinSize( 48 ){
+       m_uniformTextureMinSize( 48 ),
+       m_move_started( false ){
 }
 };
 
@@ -538,7 +502,7 @@ void Texture_NextPos( TextureBrowser& textureBrowser, TextureLayout& layout, qte
        textureBrowser.getTextureWH( q, nWidth, nHeight );
        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
                layout.current_x = 8;
-               layout.current_y -= layout.current_row + TextureBrowser_fontHeight( textureBrowser ) + 4;
+               layout.current_y -= layout.current_row + TextureBrowser_fontHeight( textureBrowser ) + 4;//+4
                layout.current_row = 0;
        }
 
@@ -1104,12 +1068,15 @@ void TextureBrowser_Focus( TextureBrowser& textureBrowser, const char* name ){
                // we have found when texdef->name and the shader name match
                // NOTE: as everywhere else for our comparisons, we are not case sensitive
                if ( shader_equal( name, shader->getName() ) ) {
-                       int textureHeight = (int)( q->height * ( (float)textureBrowser.m_textureScale / 100 ) )
-                                                               + 2 * TextureBrowser_fontHeight( textureBrowser );
+                       //int textureHeight = (int)( q->height * ( (float)textureBrowser.m_textureScale / 100 ) ) + 2 * TextureBrowser_fontHeight( textureBrowser );
+                       int textureWidth, textureHeight;
+                       textureBrowser.getTextureWH( q, textureWidth, textureHeight );
+                       textureHeight += 2 * TextureBrowser_fontHeight( textureBrowser );
+
 
                        int originy = TextureBrowser_getOriginY( textureBrowser );
                        if ( y > originy ) {
-                               originy = y;
+                               originy = y + 4;
                        }
 
                        if ( y - textureHeight < originy - textureBrowser.height ) {
@@ -1207,14 +1174,24 @@ void TextureBrowser_trackingDelta( int x, int y, unsigned int state, void* data
        }
 }
 
-void TextureBrowser_Tracking_MouseDown( TextureBrowser& textureBrowser ){
-       textureBrowser.m_freezePointer.freeze_pointer( textureBrowser.m_gl_widget, TextureBrowser_trackingDelta, &textureBrowser );
-}
-
 void TextureBrowser_Tracking_MouseUp( TextureBrowser& textureBrowser ){
+       textureBrowser.m_move_started = false;
+       /* NetRadiantCustom did this instead:
+       textureBrowser.m_freezePointer.unfreeze_pointer( textureBrowser.m_gl_widget ); */
+
        textureBrowser.m_freezePointer.unfreeze_pointer( textureBrowser.m_gl_widget );
 }
 
+void TextureBrowser_Tracking_MouseDown( TextureBrowser& textureBrowser ){
+       if( textureBrowser.m_move_started ){
+               TextureBrowser_Tracking_MouseUp( textureBrowser );
+       }
+       textureBrowser.m_move_started = true;
+       /* NetRadiantCustom did this instead:
+       textureBrowser.m_freezePointer.freeze_pointer( textureBrowser.m_parent, textureBrowser.m_gl_widget, TextureBrowser_trackingDelta, &textureBrowser ); */
+       textureBrowser.m_freezePointer.freeze_pointer( textureBrowser.m_gl_widget, TextureBrowser_trackingDelta, &textureBrowser );
+}
+
 void TextureBrowser_Selection_MouseDown( TextureBrowser& textureBrowser, guint32 flags, int pointx, int pointy ){
        SelectTexture( textureBrowser, pointx, textureBrowser.height - 1 - pointy, ( flags & GDK_SHIFT_MASK ) != 0 );
 }
@@ -1301,38 +1278,14 @@ void Texture_Draw( TextureBrowser& textureBrowser ){
                        // if !texture_showinuse: (some textures displayed may not be in use)
                        // draw an additional square around with 0.5 1 0.5 color
                        glLineWidth( 1 );
-                       // shader border:
-                       if ( !shader->IsDefault() ) {
-                       //real 1px white/black stipple
-                               glColor3f( 0, 0, 0 );
-                               glDisable( GL_TEXTURE_2D );
-
-                               float xf = (float)x;
-                               float yf = (float)( y - TextureBrowser_fontHeight( textureBrowser ) );
-                               glBegin( GL_LINE_LOOP );
-                               glVertex2f( xf - 1.5,yf + 1.5 );
-                               glVertex2f( xf - 1.5,yf - nHeight - 1.5 );
-                               glVertex2f( xf + 1.5 + nWidth,yf - nHeight - 1.5 );
-                               glVertex2f( xf + 1.5 + nWidth,yf + 1.5 );
-
-                               glEnd();
-
-                               glEnable( GL_LINE_STIPPLE );
-                               glLineStipple( 1, 0x0FFF );
-
-                               glBegin( GL_LINE_LOOP );
-                               glColor3f( 1, 1, 1 );
-
-                               glVertex2f( xf - 1.5,yf + 1.5 );
-                               glVertex2f( xf - 1.5,yf - nHeight - 1.5 );
-                               glVertex2f( xf + 1.5 + nWidth,yf - nHeight - 1.5 );
-                               glVertex2f( xf + 1.5 + nWidth,yf + 1.5 );
-
-                               glEnd();
-                               glDisable( GL_LINE_STIPPLE );
-                               glEnable( GL_TEXTURE_2D );
-
-                       }
+                       const float xf = (float)x;
+                       const float yf = (float)( y - TextureBrowser_fontHeight( textureBrowser ) );
+                       float xfMax = xf + 1.5 + nWidth;
+                       float xfMin = xf - 1.5;
+                       float yfMax = yf + 1.5;
+                       float yfMin = yf - nHeight - 1.5;
+
+                       //selected texture
                        if ( shader_equal( TextureBrowser_GetSelectedShader( textureBrowser ), shader->getName() ) ) {
                                glLineWidth( 2 );
                                if ( textureBrowser.m_rmbSelected ) {
@@ -1341,33 +1294,59 @@ void Texture_Draw( TextureBrowser& textureBrowser ){
                                else {
                                        glColor3f( 1,0,0 );
                                }
+                               xfMax += .5;
+                               xfMin -= .5;
+                               yfMax += .5;
+                               yfMin -= .5;
                                glDisable( GL_TEXTURE_2D );
-
                                glBegin( GL_LINE_LOOP );
-                               glVertex2i( x - 4,y - TextureBrowser_fontHeight( textureBrowser ) + 4 );
-                               glVertex2i( x - 4,y - TextureBrowser_fontHeight( textureBrowser ) - nHeight - 4 );
-                               glVertex2i( x + 4 + nWidth,y - TextureBrowser_fontHeight( textureBrowser ) - nHeight - 4 );
-                               glVertex2i( x + 4 + nWidth,y - TextureBrowser_fontHeight( textureBrowser ) + 4 );
+                               glVertex2f( xfMin ,yfMax );
+                               glVertex2f( xfMin ,yfMin );
+                               glVertex2f( xfMax ,yfMin );
+                               glVertex2f( xfMax ,yfMax );
                                glEnd();
-
                                glEnable( GL_TEXTURE_2D );
-                               glLineWidth( 1 );
                        }
                        // highlight in-use textures
                        else if ( !textureBrowser.m_hideUnused && shader->IsInUse() ) {
-                       //1px with float
-                               float xf = (float)x;
-                               float yf = (float)( y - TextureBrowser_fontHeight( textureBrowser ) );
                                glColor3f( 0.5,1,0.5 );
                                glDisable( GL_TEXTURE_2D );
                                glBegin( GL_LINE_LOOP );
-                               glVertex2f( xf - 3.5,yf + 3.5 );
-                               glVertex2f( xf - 3.5,yf - nHeight - 3.5 );
-                               glVertex2f( xf + 3.5 + nWidth,yf - nHeight - 3.5 );
-                               glVertex2f( xf + 3.5 + nWidth,yf + 3.5 );
+                               glVertex2f( xfMin ,yfMax );
+                               glVertex2f( xfMin ,yfMin );
+                               glVertex2f( xfMax ,yfMin );
+                               glVertex2f( xfMax ,yfMax );
                                glEnd();
                                glEnable( GL_TEXTURE_2D );
                        }
+                       // shader white border:
+                       else if ( !shader->IsDefault() ) {
+                               glColor3f( 1, 1, 1 );
+                               glDisable( GL_TEXTURE_2D );
+                               glBegin( GL_LINE_LOOP );
+                               glVertex2f( xfMin ,yfMax );
+                               glVertex2f( xfMin ,yfMin );
+                               glVertex2f( xfMax ,yfMin );
+                               glVertex2f( xfMax ,yfMax );
+                               glEnd();
+                               glEnable( GL_TEXTURE_2D );
+                       }
+
+                       // shader stipple:
+                       if ( !shader->IsDefault() ) {
+                               glEnable( GL_LINE_STIPPLE );
+                               glLineStipple( 1, 0xF000 );
+                               glDisable( GL_TEXTURE_2D );
+                               glBegin( GL_LINE_LOOP );
+                               glColor3f( 0, 0, 0 );
+                               glVertex2f( xfMin ,yfMax );
+                               glVertex2f( xfMin ,yfMin );
+                               glVertex2f( xfMax ,yfMin );
+                               glVertex2f( xfMax ,yfMax );
+                               glEnd();
+                               glDisable( GL_LINE_STIPPLE );
+                               glEnable( GL_TEXTURE_2D );
+                       }
 
                        // draw checkerboard for transparent textures
                        if ( g_TextureBrowser_enableAlpha )
@@ -1412,7 +1391,7 @@ void Texture_Draw( TextureBrowser& textureBrowser ){
                        glDisable( GL_TEXTURE_2D );
                        glColor3f( 1,1,1 );
 
-                       glRasterPos2i( x, y - TextureBrowser_fontHeight( textureBrowser ) + 5 );
+                       glRasterPos2i( x, y - TextureBrowser_fontHeight( textureBrowser ) + 2 );//+5
 
                        // don't draw the directory name
                        const char* name = shader->getName();
@@ -1579,9 +1558,10 @@ gboolean TextureBrowser_button_press( ui::Widget widget, GdkEventButton* event,
                        }
                }
        }
-       else if ( event->type == GDK_2BUTTON_PRESS ) {
+       else if ( event->type == GDK_2BUTTON_PRESS && event->button == 1 ) {
                #define GARUX_DISABLE_2BUTTON
                #ifndef GARUX_DISABLE_2BUTTON
+               CopiedString texName = textureBrowser->shader;
                const char* sh = textureBrowser->shader.c_str();
                char* dir = strrchr( sh, '/' );
                if( dir != NULL ){
@@ -1592,13 +1572,14 @@ gboolean TextureBrowser_button_press( ui::Widget widget, GdkEventButton* event,
                                if( *dir != '\0'){
                                        ScopeDisableScreenUpdates disableScreenUpdates( dir, "Loading Textures" );
                                        TextureBrowser_ShowDirectory( *textureBrowser, dir );
+                                       TextureBrowser_Focus( *textureBrowser, textureBrowser->shader.c_str() );
                                        TextureBrowser_queueDraw( *textureBrowser );
                                }
                        }
                }
                #endif
        }
-       else if ( event->type == GDK_3BUTTON_PRESS ) {
+       else if ( event->type == GDK_2BUTTON_PRESS && event->button == 3 ) {
                ScopeDisableScreenUpdates disableScreenUpdates( TextureBrowser_getCommonShadersDir(), "Loading Textures" );
                TextureBrowser_ShowDirectory( *textureBrowser, TextureBrowser_getCommonShadersDir() );
                TextureBrowser_queueDraw( *textureBrowser );
@@ -2228,7 +2209,7 @@ void TextureBrowser_checkTagFile(){
                }
                else
                {
-                       globalErrorStream() << "Unable to find default tag file " << default_filename.c_str() << ". No tag support.\n";
+                       globalOutputStream() << "Unable to find default tag file " << default_filename.c_str() << ". No tag support. Plugins -> ShaderPlug -> Create tag file: to start using tags\n";
                }
        }
 }