]> de.git.xonotic.org Git - xonotic/netradiant.git/commitdiff
Radiant:
authorGarux <garux@mail.ru>
Tue, 1 Aug 2017 11:07:22 +0000 (14:07 +0300)
committerGarux <garux@mail.ru>
Tue, 1 Aug 2017 11:07:22 +0000 (14:07 +0300)
binds...
* tex bro: left double click loads directory, containing active shader + focuses on it
right double click loads 'common' directory
misc...
* shader editor gets focus after been hidden behind main window and called again
* patch thicken: significantly more fail safe; correct handling of cycled patches
* fix: was parsing vfs twice; pk3s were being opened twice during runtime
* fix: shortcuts work after startup (plugins bar buttons were stealing focus)

radiant/gtkdlgs.cpp
radiant/patch.cpp
radiant/plugintoolbar.cpp
radiant/qe3.cpp
radiant/texwindow.cpp

index 3780aecc3370e091fea16f8675426dfe36483925..57479b321727d8bdf4334e4319090cf24952af55 100644 (file)
@@ -839,6 +839,7 @@ static void DoGtkTextEditor( const char* filename, guint cursorpos, int length )
 
                // trying to show later
                gtk_widget_show( text_editor );
+               gtk_window_present( GTK_WINDOW( text_editor ) );
 
 #ifdef WIN32
                process_gui();
index 75b1a53d2fe79181cdb82aca0bdc1d68e5d241a6..243cf8640355d3013d2f494e72186e02054e1068 100644 (file)
@@ -2778,31 +2778,31 @@ void Patch::BuildVertexArray(){
 }
 
 
-Vector3 getAverageNormal(const Vector3& normal1, const Vector3& normal2, double thickness)
+Vector3 getAverageNormal(const Vector3& normal1, const Vector3& normal2)
 {
        // Beware of normals with 0 length
-       if ( ( fabs( normal1[0] ) + fabs( normal1[1] ) + fabs( normal1[2] ) ) == 0 ) return normal2;
-       if ( ( fabs( normal2[0] ) + fabs( normal2[1] ) + fabs( normal2[2] ) ) == 0) return normal1;
+       if ( vector3_length_squared( normal1 ) == 0 ) return normal2;
+       if ( vector3_length_squared( normal2 ) == 0 ) return normal1;
 
        // Both normals have length > 0
-       Vector3 n1 = vector3_normalised( normal1 );
-       Vector3 n2 = vector3_normalised( normal2 );
+       //Vector3 n1 = vector3_normalised( normal1 );
+       //Vector3 n2 = vector3_normalised( normal2 );
 
        // Get the angle bisector
-       Vector3 normal = vector3_normalised (n1 + n2);
+       if( vector3_length_squared( normal1 + normal2 ) == 0 ) return normal1;
+
+       Vector3 normal = vector3_normalised (normal1 + normal2);
 
        // Now calculate the length correction out of the angle
        // of the two normals
                /* float factor = cos(n1.angle(n2) * 0.5); */
-       float factor = (float) vector3_dot( n1, n2 );
+       float factor = (float) vector3_dot( normal1, normal2 );
        if ( factor > 1.0 ) factor = 1;
+       if ( factor < -1.0 ) factor = -1;
        factor = acos( factor );
 
        factor = cos( factor * 0.5 );
 
-       // Stretch the normal to fit the required thickness
-       normal *= thickness;
-
        // Check for div by zero (if the normals are antiparallel)
        // and stretch the resulting normal, if necessary
        if (factor != 0)
@@ -2846,7 +2846,7 @@ void Patch::createThickenedOpposite(const Patch& sourcePatch,
                        break;
        }
 
-       //check if certain seams are required
+       //check if certain seams are required + cycling in normals calculation is needed
        //( endpoints != startpoints ) - not a cylinder or something
        for (std::size_t col = 0; col < m_width; col++){
                if( vector3_length_squared( sourcePatch.ctrlAt( 0, col ).m_vertex - sourcePatch.ctrlAt( m_height - 1, col ).m_vertex ) > 0.1f ){
@@ -2878,10 +2878,10 @@ void Patch::createThickenedOpposite(const Patch& sourcePatch,
                                // The col tangents (empty if 0,0,0)
                                Vector3 colTangent[2] = { Vector3(0,0,0), Vector3(0,0,0) };
 
-                               // Are we at the beginning/end of the column?
-                               if (col == 0 || col == m_width - 1)
+                               // Are we at the beginning/end of the row? + not cylinder
+                               if ( (col == 0 || col == m_width - 1) && !no34 )
                                {
-                                       // Get the next row index
+                                       // Get the next col index
                                        std::size_t nextCol = (col == m_width - 1) ? (col - 1) : (col + 1);
 
                                        const PatchControl& colNeighbour = sourcePatch.ctrlAt(row, nextCol);
@@ -2890,13 +2890,29 @@ void Patch::createThickenedOpposite(const Patch& sourcePatch,
                                        colTangent[0] = colNeighbour.m_vertex - curCtrl.m_vertex;
                                        // Reverse it if we're at the end of the column
                                        colTangent[0] *= (col == m_width - 1) ? -1 : +1;
+                                       //normalize
+                                       if ( vector3_length_squared( colTangent[0] ) != 0 ) vector3_normalise( colTangent[0] );
                                }
                                // We are in between, two tangents can be calculated
                                else
                                {
                                        // Take two neighbouring vertices that should form a line segment
-                                       const PatchControl& neighbour1 = sourcePatch.ctrlAt(row, col+1);
-                                       const PatchControl& neighbour2 = sourcePatch.ctrlAt(row, col-1);
+                                       std::size_t nextCol, prevCol;
+                                       if( col == 0 ){
+                                               nextCol = col+1;
+                                               prevCol = m_width-2;
+                                       }
+                                       else if( col == m_width - 1 ){
+                                               nextCol = 1;
+                                               prevCol = col-1;
+                                       }
+                                       else{
+                                               nextCol = col+1;
+                                               prevCol = col-1;
+                                       }
+                                       const PatchControl& neighbour1 = sourcePatch.ctrlAt(row, nextCol);
+                                       const PatchControl& neighbour2 = sourcePatch.ctrlAt(row, prevCol);
+
 
                                        // Calculate both available tangents
                                        colTangent[0] = neighbour1.m_vertex - curCtrl.m_vertex;
@@ -2905,10 +2921,13 @@ void Patch::createThickenedOpposite(const Patch& sourcePatch,
                                        // Reverse the second one
                                        colTangent[1] *= -1;
 
+                                       //normalize b4 stuff
+                                       if ( vector3_length_squared( colTangent[0] ) != 0 ) vector3_normalise( colTangent[0] );
+                                       if ( vector3_length_squared( colTangent[1] ) != 0 ) vector3_normalise( colTangent[1] );
+
                                        // Cull redundant tangents (parallel)
-                                       if ( ( fabs( colTangent[1][0] + colTangent[0][0] ) + fabs( colTangent[1][1] + colTangent[0][1] ) + fabs( colTangent[1][2] + colTangent[0][2] ) ) < 0.00001 ||
-                                               ( fabs( colTangent[1][0] - colTangent[0][0] ) + fabs( colTangent[1][1] - colTangent[0][1] ) + fabs( colTangent[1][2] - colTangent[0][2] ) ) < 0.00001 )
-                                       {
+                                       if ( vector3_length_squared( colTangent[1] + colTangent[0] ) == 0 ||
+                                               vector3_length_squared( colTangent[1] - colTangent[0] ) == 0 ){
                                                colTangent[1] = Vector3(0,0,0);
                                        }
                                }
@@ -2917,7 +2936,7 @@ void Patch::createThickenedOpposite(const Patch& sourcePatch,
                                Vector3 rowTangent[2] = { Vector3(0,0,0), Vector3(0,0,0) };
 
                                // Are we at the beginning or the end?
-                               if (row == 0 || row == m_height - 1)
+                               if ( (row == 0 || row == m_height - 1) && !no12 )
                                {
                                        // Yes, only calculate one row tangent
                                        // Get the next row index
@@ -2929,12 +2948,27 @@ void Patch::createThickenedOpposite(const Patch& sourcePatch,
                                        rowTangent[0] = rowNeighbour.m_vertex - curCtrl.m_vertex;
                                        // Reverse it accordingly
                                        rowTangent[0] *= (row == m_height - 1) ? -1 : +1;
+                                       //normalize
+                                       if ( vector3_length_squared( rowTangent[0] ) != 0 ) vector3_normalise( rowTangent[0] );
                                }
                                else
                                {
                                        // Two tangents to calculate
-                                       const PatchControl& rowNeighbour1 = sourcePatch.ctrlAt(row + 1, col);
-                                       const PatchControl& rowNeighbour2 = sourcePatch.ctrlAt(row - 1, col);
+                                       std::size_t nextRow, prevRow;
+                                       if( row == 0 ){
+                                               nextRow = row+1;
+                                               prevRow = m_height-2;
+                                       }
+                                       else if( row == m_height - 1 ){
+                                               nextRow = 1;
+                                               prevRow = row-1;
+                                       }
+                                       else{
+                                               nextRow = row+1;
+                                               prevRow = row-1;
+                                       }
+                                       const PatchControl& rowNeighbour1 = sourcePatch.ctrlAt(nextRow, col);
+                                       const PatchControl& rowNeighbour2 = sourcePatch.ctrlAt(prevRow, col);
 
                                        // First tangent
                                        rowTangent[0] = rowNeighbour1.m_vertex - curCtrl.m_vertex;
@@ -2943,47 +2977,109 @@ void Patch::createThickenedOpposite(const Patch& sourcePatch,
                                        // Reverse the second one
                                        rowTangent[1] *= -1;
 
-                                       // Cull redundant tangents
-                                       if ( ( fabs( rowTangent[1][0] + rowTangent[0][0] ) + fabs( rowTangent[1][1] + rowTangent[0][1] ) + fabs( rowTangent[1][2] + rowTangent[0][2] ) ) < 0.00001 ||
-                                               ( fabs( rowTangent[1][0] - rowTangent[0][0] ) + fabs( rowTangent[1][1] - rowTangent[0][1] ) + fabs( rowTangent[1][2] - rowTangent[0][2] ) ) < 0.00001 )
-                                       {
+                                       //normalize b4 stuff
+                                       if ( vector3_length_squared( rowTangent[0] ) != 0 ) vector3_normalise( rowTangent[0] );
+                                       if ( vector3_length_squared( rowTangent[1] ) != 0 ) vector3_normalise( rowTangent[1] );
+
+                                       // Cull redundant tangents (parallel)
+                                       if ( vector3_length_squared( rowTangent[1] + rowTangent[0] ) == 0 ||
+                                               vector3_length_squared( rowTangent[1] - rowTangent[0] ) == 0 ){
                                                rowTangent[1] = Vector3(0,0,0);
                                        }
                                }
 
-                               // If two column tangents are available, take the length-corrected average
-                               if ( ( fabs( colTangent[1][0] ) + fabs( colTangent[1][1] ) + fabs( colTangent[1][2] ) ) > 0)
-                               {
-                                       // Two column normals to calculate
-                                       Vector3 normal1 = vector3_normalised( vector3_cross( rowTangent[0], colTangent[0] ) );
-                                       Vector3 normal2 = vector3_normalised( vector3_cross( rowTangent[0], colTangent[1] ) );
 
-                                       normal = getAverageNormal(normal1, normal2, thickness);
+                               //clean parallel pairs...
+                               if ( vector3_length_squared( rowTangent[0] + colTangent[0] ) == 0 ||
+                                       vector3_length_squared( rowTangent[0] - colTangent[0] ) == 0 ){
+                                       rowTangent[0] = Vector3(0,0,0);
+                               }
+                               if ( vector3_length_squared( rowTangent[1] + colTangent[1] ) == 0 ||
+                                       vector3_length_squared( rowTangent[1] - colTangent[1] ) == 0 ){
+                                       rowTangent[1] = Vector3(0,0,0);
+                               }
+                               if ( vector3_length_squared( rowTangent[0] + colTangent[1] ) == 0 ||
+                                       vector3_length_squared( rowTangent[0] - colTangent[1] ) == 0 ){
+                                       colTangent[1] = Vector3(0,0,0);
+                               }
+                               if ( vector3_length_squared( rowTangent[1] + colTangent[0] ) == 0 ||
+                                       vector3_length_squared( rowTangent[1] - colTangent[0] ) == 0 ){
+                                       rowTangent[1] = Vector3(0,0,0);
+                               }
 
-                                       // Scale the normal down, as it is multiplied with thickness later on
-                                       normal /= thickness;
+                               //clean dummies
+                               if ( vector3_length_squared( colTangent[0] ) == 0 ){
+                                       colTangent[0] = colTangent[1];
+                                       colTangent[1] = Vector3(0,0,0);
                                }
-                               else
-                               {
-                                       // One column tangent available, maybe we have a second rowtangent?
-                                       if ( ( fabs( rowTangent[1][0] ) + fabs( rowTangent[1][1] ) + fabs( rowTangent[1][2] ) ) > 0)
+                               if ( vector3_length_squared( rowTangent[0] ) == 0 ){
+                                       rowTangent[0] = rowTangent[1];
+                                       rowTangent[1] = Vector3(0,0,0);
+                               }
+                               if( vector3_length_squared( rowTangent[0] ) == 0 || vector3_length_squared( colTangent[0] ) == 0 ){
+                                       normal = extrudeAxis;
+
+                               }
+                               else{
+                                       // If two column + two row tangents are available, take the length-corrected average
+                                       if ( ( fabs( colTangent[1][0] ) + fabs( colTangent[1][1] ) + fabs( colTangent[1][2] ) ) > 0 &&
+                                                       ( fabs( rowTangent[1][0] ) + fabs( rowTangent[1][1] ) + fabs( rowTangent[1][2] ) ) > 0 )
                                        {
-                                               // Two row normals to calculate
+                                               // Two column normals to calculate
                                                Vector3 normal1 = vector3_normalised( vector3_cross( rowTangent[0], colTangent[0] ) );
-                                               Vector3 normal2 = vector3_normalised( vector3_cross( rowTangent[1], colTangent[0] ) );
+                                               Vector3 normal2 = vector3_normalised( vector3_cross( rowTangent[1], colTangent[1] ) );
 
-                                               normal = getAverageNormal(normal1, normal2, thickness);
+                                               normal = getAverageNormal(normal1, normal2);
+                                               /*globalOutputStream() << "0\n";
+                                               globalOutputStream() << normal1 << "\n";
+                                               globalOutputStream() << normal2 << "\n";
+                                               globalOutputStream() << normal << "\n";*/
+
+                                       }
+                                       // If two column tangents are available, take the length-corrected average
+                                       else if ( ( fabs( colTangent[1][0] ) + fabs( colTangent[1][1] ) + fabs( colTangent[1][2] ) ) > 0)
+                                       {
+                                               // Two column normals to calculate
+                                               Vector3 normal1 = vector3_normalised( vector3_cross( rowTangent[0], colTangent[0] ) );
+                                               Vector3 normal2 = vector3_normalised( vector3_cross( rowTangent[0], colTangent[1] ) );
+
+                                               normal = getAverageNormal(normal1, normal2);
+                                               /*globalOutputStream() << "1\n";
+                                               globalOutputStream() << normal1 << "\n";
+                                               globalOutputStream() << normal2 << "\n";
+                                               globalOutputStream() << normal << "\n";*/
 
-                                               // Scale the normal down, as it is multiplied with thickness later on
-                                               normal /= thickness;
                                        }
                                        else
                                        {
-                                               if ( vector3_length_squared( vector3_cross( rowTangent[0], colTangent[0] ) ) > 0 ){
-                                                       normal = vector3_normalised( vector3_cross( rowTangent[0], colTangent[0] ) );
+                                               // One column tangent available, maybe we have a second rowtangent?
+                                               if ( ( fabs( rowTangent[1][0] ) + fabs( rowTangent[1][1] ) + fabs( rowTangent[1][2] ) ) > 0)
+                                               {
+                                                       // Two row normals to calculate
+                                                       Vector3 normal1 = vector3_normalised( vector3_cross( rowTangent[0], colTangent[0] ) );
+                                                       Vector3 normal2 = vector3_normalised( vector3_cross( rowTangent[1], colTangent[0] ) );
+
+                                                       normal = getAverageNormal(normal1, normal2);
+                                                       /*globalOutputStream() << "2\n";
+                                                       globalOutputStream() << rowTangent[0] << "\n";
+                                                       globalOutputStream() << colTangent[0] << "\n";
+                                                       globalOutputStream() << vector3_cross( rowTangent[0], colTangent[0]) << "\n";
+                                                       globalOutputStream() << normal1 << "\n";
+                                                       globalOutputStream() << normal2 << "\n";
+                                                       globalOutputStream() << normal << "\n";*/
+
                                                }
-                                               else{
-                                                       normal = extrudeAxis;
+                                               else
+                                               {
+                                                       if ( vector3_length_squared( vector3_cross( rowTangent[0], colTangent[0] ) ) > 0 ){
+                                                               normal = vector3_normalised( vector3_cross( rowTangent[0], colTangent[0] ) );
+                                                               /*globalOutputStream() << "3\n";
+                                                               globalOutputStream() << (float)vector3_length_squared( vector3_cross( rowTangent[0], colTangent[0] ) ) << "\n";
+                                                               globalOutputStream() << normal << "\n";*/
+                                                       }
+                                                       else{
+                                                               normal = extrudeAxis;
+                                                       }
                                                }
                                        }
                                }
index 03ef2074b659455dbf2c73683be05d57787b4bf7..8fd420d73046cc1b6ef65bdc96d12bf83da2ea2c 100644 (file)
@@ -82,7 +82,11 @@ inline GtkToolbarChildType gtktoolbarchildtype_for_toolbarbuttontype( IToolbarBu
 }
 
 void toolbar_insert( GtkToolbar *toolbar, const char* icon, const char* text, const char* tooltip, IToolbarButton::EType type, GtkSignalFunc handler, gpointer data ){
-       gtk_toolbar_append_element( toolbar, gtktoolbarchildtype_for_toolbarbuttontype( type ), 0, text, tooltip, "", GTK_WIDGET( new_plugin_image( icon ) ), handler, data );
+       GtkWidget* widget = gtk_toolbar_append_element( toolbar, gtktoolbarchildtype_for_toolbarbuttontype( type ), 0, text, tooltip, "", GTK_WIDGET( new_plugin_image( icon ) ), handler, data );
+       if( type != IToolbarButton::eSpace ){
+               GTK_WIDGET_UNSET_FLAGS( widget, GTK_CAN_FOCUS );
+               GTK_WIDGET_UNSET_FLAGS( widget, GTK_CAN_DEFAULT );
+       }
 }
 
 void ActivateToolbarButton( GtkWidget *widget, gpointer data ){
index 1bce60b9a38acb676709ad12a4edcefa765c3a2d..82d5d85571d3233f08fbffaffa78741547ef181c 100644 (file)
@@ -83,7 +83,7 @@ void QE_InitVFS(){
        // if we have a mod dir
        if ( !string_equal( gamename, basegame ) ) {
                // ~/.<gameprefix>/<fs_game>
-               if ( userRoot ) {
+               if ( userRoot && !string_equal( globalRoot, userRoot ) ) {
                        StringOutputStream userGamePath( 256 );
                        userGamePath << userRoot << gamename << '/';
                        GlobalFileSystem().initDirectory( userGamePath.c_str() );
@@ -98,7 +98,7 @@ void QE_InitVFS(){
        }
 
        // ~/.<gameprefix>/<fs_main>
-       if ( userRoot ) {
+       if ( userRoot && !string_equal( globalRoot, userRoot ) ) {
                StringOutputStream userBasePath( 256 );
                userBasePath << userRoot << basegame << '/';
                GlobalFileSystem().initDirectory( userBasePath.c_str() );
index 0dbb6a0b736e1f1eeb7d059fbf5edaca4dfe3785..d18a152e8333fdc3efcbe67ef4bcc3bc2c1ba118 100644 (file)
@@ -1423,8 +1423,9 @@ gboolean TextureBrowser_button_press( GtkWidget* widget, GdkEventButton* event,
                        }
                }
        }
-       else if ( event->type == GDK_2BUTTON_PRESS ) {
-               const char* sh = textureBrowser->shader.c_str();
+       else if ( event->type == GDK_2BUTTON_PRESS && event->button == 1 ) {
+               CopiedString texName = textureBrowser->shader;
+               const char* sh = texName.c_str();
                char* dir = strrchr( sh, '/' );
                if( dir != NULL ){
                        *(dir + 1) = '\0';
@@ -1434,12 +1435,13 @@ gboolean TextureBrowser_button_press( GtkWidget* 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 );
                                }
                        }
                }
        }
-       else if ( event->type == GDK_3BUTTON_PRESS ) {
+       else if ( event->type == GDK_2BUTTON_PRESS && event->button == 3 ) {
                ScopeDisableScreenUpdates disableScreenUpdates( TextureBrowser_getComonShadersDir(), "Loading Textures" );
                TextureBrowser_ShowDirectory( *textureBrowser, TextureBrowser_getComonShadersDir() );
                TextureBrowser_queueDraw( *textureBrowser );