]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/patchmanip.cpp
Merge commit 'f8b2b1f25e7e195c0c11e3d2e2ddf308562de77f' into garux-merge
[xonotic/netradiant.git] / radiant / patchmanip.cpp
index bd9d378beee07b6bda85c8b517278827648fb7cc..15faff88c81b31ffeb5b5a86c9d2d497e2fa0a37 100644 (file)
@@ -145,6 +145,7 @@ void Patch_makeCaps( Patch& patch, scene::Instance& instance, EPatchCap type, co
        }
 }
 
+
 typedef std::vector<scene::Instance*> InstanceVector;
 
 enum ECapDialog {
@@ -195,6 +196,32 @@ void Scene_PatchDoCap_Selected( scene::Graph& graph, const char* shader ){
        }
 }
 
+void Patch_deform( Patch& patch, scene::Instance& instance, const int deform ){
+       patch.undoSave();
+
+       for (PatchControlIter i = patch.begin(); i != patch.end(); ++i)
+       {
+               PatchControl& control = *i;
+               int randomNumber = int( deform * (float(std::rand()) / float(RAND_MAX)));
+               control.m_vertex[2] += randomNumber;
+       }
+
+       patch.controlPointsChanged();
+}
+
+void Scene_PatchDeform( scene::Graph& graph, const int deform )
+{
+       InstanceVector instances;
+       Scene_forEachVisibleSelectedPatchInstance([&](PatchInstance &patch) {
+                       instances.push_back(&patch);
+       });
+       for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
+       {
+               Patch_deform( *Node_getPatch( ( *i )->path().top() ), *( *i ), deform );
+       }
+
+}
+
 Patch* Scene_GetUltimateSelectedVisiblePatch(){
        if ( GlobalSelectionSystem().countSelected() != 0 ) {
                scene::Node& node = GlobalSelectionSystem().ultimateSelected().path().top();
@@ -543,6 +570,14 @@ void Patch_FitTexture(){
        Scene_PatchTileTexture_Selected( GlobalSceneGraph(), 1, 1 );
 }
 
+void DoPatchDeformDlg();
+
+void Patch_Deform(){
+       UndoableCommand undo( "patchDeform" );
+
+       DoPatchDeformDlg();
+}
+
 #include "ifilter.h"
 
 
@@ -616,6 +651,10 @@ void PatchPreferences_construct(){
 void Patch_registerCommands(){
        GlobalCommands_insert( "InvertCurveTextureX", makeCallbackF(Patch_FlipTextureX), Accelerator( 'I', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
        GlobalCommands_insert( "InvertCurveTextureY", makeCallbackF(Patch_FlipTextureY), Accelerator( 'I', (GdkModifierType)GDK_SHIFT_MASK ) );
+       GlobalCommands_insert( "IncPatchColumn", makeCallbackF(Patch_InsertInsertColumn), Accelerator( GDK_KP_Add, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
+       GlobalCommands_insert( "IncPatchRow", makeCallbackF(Patch_InsertInsertRow), Accelerator( GDK_KP_Add, (GdkModifierType)GDK_CONTROL_MASK ) );
+       GlobalCommands_insert( "DecPatchColumn", makeCallbackF(Patch_DeleteLastColumn), Accelerator( GDK_KP_Subtract, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
+       GlobalCommands_insert( "DecPatchRow", makeCallbackF(Patch_DeleteLastRow), Accelerator( GDK_KP_Subtract, (GdkModifierType)GDK_CONTROL_MASK ) );
        GlobalCommands_insert( "NaturalizePatch", makeCallbackF(Patch_NaturalTexture), Accelerator( 'N', (GdkModifierType)GDK_CONTROL_MASK ) );
        GlobalCommands_insert( "PatchCylinder", makeCallbackF(Patch_Cylinder) );
        GlobalCommands_insert( "PatchDenseCylinder", makeCallbackF(Patch_DenseCylinder) );
@@ -649,6 +688,7 @@ void Patch_registerCommands(){
        GlobalCommands_insert( "CycleCapTexturePatch", makeCallbackF(Patch_CycleProjection), Accelerator( 'N', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
        GlobalCommands_insert( "MakeOverlayPatch", makeCallbackF(Patch_OverlayOn), Accelerator( 'Y' ) );
        GlobalCommands_insert( "ClearPatchOverlays", makeCallbackF(Patch_OverlayOff), Accelerator( 'L', (GdkModifierType)GDK_CONTROL_MASK ) );
+       GlobalCommands_insert( "PatchDeform", makeCallbackF(Patch_Deform) );
 }
 
 void Patch_constructToolbar( ui::Toolbar toolbar ){
@@ -671,12 +711,12 @@ void Patch_constructMenu( ui::Menu menu ){
        create_menu_item_with_mnemonic( menu, "End cap", "PatchEndCap" );
        create_menu_item_with_mnemonic( menu, "Bevel", "PatchBevel" );
        {
-               auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "More End caps, Bevels" );
-               if ( g_Layout_enableDetachableMenus.m_value ) {
-                       menu_tearoff( menu_in_menu );
-               }
-               create_menu_item_with_mnemonic( menu_in_menu, "Square Endcap", "PatchSquareBevel" );
-               create_menu_item_with_mnemonic( menu_in_menu, "Square Bevel", "PatchSquareEndcap" );
+//             auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "More End caps, Bevels" );
+//             if ( g_Layout_enableDetachableMenus.m_value ) {
+//                     menu_tearoff( menu_in_menu );
+//             }
+               create_menu_item_with_mnemonic( menu, "Square Endcap", "PatchSquareBevel" );
+               create_menu_item_with_mnemonic( menu, "Square Bevel", "PatchSquareEndcap" );
        }
        menu_separator( menu );
        create_menu_item_with_mnemonic( menu, "Cone", "PatchCone" );
@@ -716,24 +756,38 @@ void Patch_constructMenu( ui::Menu menu ){
                        menu_tearoff( menu_in_menu );
                }
                create_menu_item_with_mnemonic( menu_in_menu, "Invert", "InvertCurve" );
-               auto menu_3 = create_sub_menu_with_mnemonic( menu_in_menu, "Re-disperse" );
-               if ( g_Layout_enableDetachableMenus.m_value ) {
-                       menu_tearoff( menu_3 );
-               }
-               create_menu_item_with_mnemonic( menu_3, "Rows", "RedisperseRows" );
-               create_menu_item_with_mnemonic( menu_3, "Columns", "RedisperseCols" );
-               auto menu_4 = create_sub_menu_with_mnemonic( menu_in_menu, "Smooth" );
-               if ( g_Layout_enableDetachableMenus.m_value ) {
-                       menu_tearoff( menu_4 );
-               }
-               create_menu_item_with_mnemonic( menu_4, "Rows", "SmoothRows" );
-               create_menu_item_with_mnemonic( menu_4, "Columns", "SmoothCols" );
+//             auto menu_3 = create_sub_menu_with_mnemonic( menu_in_menu, "Re-disperse" );
+//             if ( g_Layout_enableDetachableMenus.m_value ) {
+//                     menu_tearoff( menu_3 );
+//             }
+               menu_separator( menu_in_menu );
+               create_menu_item_with_mnemonic( menu, "Rows", "RedisperseRows" );
+               create_menu_item_with_mnemonic( menu, "Columns", "RedisperseCols" );
+//             auto menu_4 = create_sub_menu_with_mnemonic( menu_in_menu, "Smooth" );
+//             if ( g_Layout_enableDetachableMenus.m_value ) {
+//                     menu_tearoff( menu_4 );
+//             }
+               create_menu_item_with_mnemonic( menu, "Rows", "SmoothRows" );
+               create_menu_item_with_mnemonic( menu, "Columns", "SmoothCols" );
                create_menu_item_with_mnemonic( menu_in_menu, "Transpose", "MatrixTranspose" );
+
        }
        menu_separator( menu );
        create_menu_item_with_mnemonic( menu, "Cap Selection", "CapCurrentCurve" );
        create_menu_item_with_mnemonic( menu, "Cycle Cap Texture", "CycleCapTexturePatch" );
        menu_separator( menu );
+       {
+               auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Texture" );
+               if ( g_Layout_enableDetachableMenus.m_value ) {
+                       menu_tearoff( menu_in_menu );
+               }
+               create_menu_item_with_mnemonic( menu_in_menu, "Cycle Projection", "CycleCapTexturePatch" );
+               create_menu_item_with_mnemonic( menu_in_menu, "Naturalize", "NaturalizePatch" );
+               create_menu_item_with_mnemonic( menu_in_menu, "Invert X", "InvertCurveTextureX" );
+               create_menu_item_with_mnemonic( menu_in_menu, "Invert Y", "InvertCurveTextureY" );
+
+       }
+       menu_separator( menu );
        {
                auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Overlay" );
                if ( g_Layout_enableDetachableMenus.m_value ) {
@@ -742,6 +796,8 @@ void Patch_constructMenu( ui::Menu menu ){
                create_menu_item_with_mnemonic( menu_in_menu, "Set", "MakeOverlayPatch" );
                create_menu_item_with_mnemonic( menu_in_menu, "Clear", "ClearPatchOverlays" );
        }
+       menu_separator( menu );
+       create_menu_item_with_mnemonic( menu, "Deform...", "PatchDeform" );
 }
 
 
@@ -855,6 +911,66 @@ void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows,
 }
 
 
+void DoPatchDeformDlg(){
+       ModalDialog dialog;
+       GtkWidget* deformW;
+
+       ui::Window window = create_dialog_window( MainFrame_getWindow(), "Patch deform", G_CALLBACK( dialog_delete_callback ), &dialog );
+
+       GtkAccelGroup* accel = gtk_accel_group_new();
+       gtk_window_add_accel_group( window, accel );
+
+       {
+               GtkHBox* hbox = create_dialog_hbox( 4, 4 );
+               gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
+               {
+                       GtkTable* table = create_dialog_table( 2, 2, 4, 4 );
+                       gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
+                       {
+                               GtkLabel* label = GTK_LABEL( gtk_label_new( "Max deform:" ) );
+                               gtk_widget_show( GTK_WIDGET( label ) );
+                               gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
+                                                                 (GtkAttachOptions) ( GTK_FILL ),
+                                                                 (GtkAttachOptions) ( 0 ), 0, 0 );
+                               gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
+                       }
+                       {
+                               GtkWidget* entry = gtk_entry_new();
+                               gtk_entry_set_text( GTK_ENTRY( entry ), "16" );
+                               gtk_widget_show( entry );
+                               gtk_table_attach( table, entry, 1, 2, 0, 1,
+                                                                 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
+                                                                 (GtkAttachOptions) ( 0 ), 0, 0 );
+
+                               deformW = entry;
+                       }
+               }
+               {
+                       auto vbox = create_dialog_vbox( 4 );
+                       gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
+                       {
+                               auto button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
+                               vbox.pack_start( button, FALSE, FALSE, 0 );
+                               widget_make_default( button );
+                               gtk_widget_grab_focus( button  );
+                               gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
+                       }
+                       {
+                               auto button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
+                               vbox.pack_start( button, FALSE, FALSE, 0 );
+                               gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
+                       }
+               }
+       }
+
+       if ( modal_dialog_show( window, dialog ) == eIDOK ) {
+               int deform = static_cast<int>( atoi( gtk_entry_get_text( GTK_ENTRY( deformW ) ) ) );
+               Scene_PatchDeform( GlobalSceneGraph(), deform );
+       }
+
+       gtk_widget_destroy( GTK_WIDGET( window ) );
+}
+
 
 
 EMessageBoxReturn DoCapDlg( ECapDialog* type ){