X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=radiant%2Fpatchmanip.cpp;h=7a764976f4395ff34850c725bb19305707923533;hb=b25e4389ba4d089fc94cc3860774c8510b843042;hp=ceca948de79954d58c3141c1f2bdc64359a6c50d;hpb=18d60f90d7603cb420150739251cf98519c57406;p=xonotic%2Fnetradiant.git diff --git a/radiant/patchmanip.cpp b/radiant/patchmanip.cpp index ceca948d..7a764976 100644 --- a/radiant/patchmanip.cpp +++ b/radiant/patchmanip.cpp @@ -145,6 +145,7 @@ void Patch_makeCaps( Patch& patch, scene::Instance& instance, EPatchCap type, co } } + typedef std::vector InstanceVector; enum ECapDialog { @@ -195,6 +196,111 @@ 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 ); + } + +} + +void Patch_thicken( Patch& patch, scene::Instance& instance, const float thickness, bool seams, const int axis ){ + + // Create a new patch node + NodeSmartReference node( g_patchCreator->createPatch() ); + // Insert the node into worldspawn + Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node ); + + // Retrieve the contained patch from the node + Patch* targetPatch = Node_getPatch( node ); + + // Create the opposite patch with the given thickness = distance + bool no12 = true; + bool no34 = true; + targetPatch->createThickenedOpposite( patch, thickness, axis, no12, no34 ); + + // Now select the newly created patches + { + scene::Path patchpath( makeReference( GlobalSceneGraph().root() ) ); + patchpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) ); + patchpath.push( makeReference( node.get() ) ); + Instance_getSelectable( *GlobalSceneGraph().find( patchpath ) )->setSelected( true ); + } + + if( seams && thickness != 0.0f){ + int i = 0; + if ( no12 ){ + i = 2; + } + int iend = 4; + if ( no34 ){ + iend = 2; + } + // Now create the four walls + for ( ; i < iend; i++ ){ + // Allocate new patch + NodeSmartReference node = NodeSmartReference( g_patchCreator->createPatch() ); + // Insert each node into worldspawn + Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node ); + + // Retrieve the contained patch from the node + Patch* wallPatch = Node_getPatch( node ); + + // Create the wall patch by passing i as wallIndex + wallPatch->createThickenedWall( patch, *targetPatch, i ); + + if( ( wallPatch->localAABB().extents[0] <= 0.00005 && wallPatch->localAABB().extents[1] <= 0.00005 ) || + ( wallPatch->localAABB().extents[1] <= 0.00005 && wallPatch->localAABB().extents[2] <= 0.00005 ) || + ( wallPatch->localAABB().extents[0] <= 0.00005 && wallPatch->localAABB().extents[2] <= 0.00005 ) ){ + //globalOutputStream() << "Thicken: Discarding degenerate patch.\n"; + Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->erase( node ); + } + else + // Now select the newly created patches + { + scene::Path patchpath( makeReference( GlobalSceneGraph().root() ) ); + patchpath.push( makeReference( *Map_GetWorldspawn(g_map) ) ); + patchpath.push( makeReference( node.get() ) ); + Instance_getSelectable( *GlobalSceneGraph().find( patchpath ) )->setSelected( true ); + } + } + } + + // Invert the target patch so that it faces the opposite direction + targetPatch->InvertMatrix(); +} + +void Scene_PatchThicken( scene::Graph& graph, const int thickness, bool seams, const int axis ) +{ + InstanceVector instances; + Scene_forEachVisibleSelectedPatchInstance([&](PatchInstance &patch) { + instances.push_back(&patch); + }); + for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i ) + { + Patch_thicken( *Node_getPatch( ( *i )->path().top() ), *( *i ), thickness, seams, axis ); + } + +} + Patch* Scene_GetUltimateSelectedVisiblePatch(){ if ( GlobalSelectionSystem().countSelected() != 0 ) { scene::Node& node = GlobalSelectionSystem().ultimateSelected().path().top(); @@ -272,6 +378,20 @@ void Scene_PatchGetShader_Selected( scene::Graph& graph, CopiedString& name ){ } } +class PatchSelectByShader +{ +const char* m_name; +public: +inline PatchSelectByShader( const char* name ) + : m_name( name ){ +} +void operator()( PatchInstance& patch ) const { + if ( shader_equal( patch.getPatch().GetShader(), m_name ) ) { + patch.setSelected( true ); + } +} +}; + void Scene_PatchSelectByShader( scene::Graph& graph, const char* name ){ Scene_forEachVisiblePatchInstance([&](PatchInstance &patch) { if (shader_equal(patch.getPatch().GetShader(), name)) { @@ -281,20 +401,42 @@ void Scene_PatchSelectByShader( scene::Graph& graph, const char* name ){ } +class PatchFindReplaceShader +{ +const char* m_find; +const char* m_replace; +public: +PatchFindReplaceShader( const char* find, const char* replace ) : m_find( find ), m_replace( replace ){ +} +void operator()( Patch& patch ) const { + if ( shader_equal( patch.GetShader(), m_find ) ) { + patch.SetShader( m_replace ); + } +} +}; + +namespace{ +bool DoingSearch( const char *repl ){ + return ( repl == NULL || ( strcmp( "textures/", repl ) == 0 ) ); +} +} void Scene_PatchFindReplaceShader( scene::Graph& graph, const char* find, const char* replace ){ - Scene_forEachVisiblePatch([&](Patch &patch) { - if (shader_equal(patch.GetShader(), find)) { - patch.SetShader(replace); - } - }); + if( DoingSearch( replace ) ){ + Scene_forEachVisiblePatchInstance( PatchSelectByShader( find ) ); + } + else{ + Scene_forEachVisiblePatch( PatchFindReplaceShader( find, replace ) ); + } } void Scene_PatchFindReplaceShader_Selected( scene::Graph& graph, const char* find, const char* replace ){ - Scene_forEachVisibleSelectedPatch([&](Patch &patch) { - if (shader_equal(patch.GetShader(), find)) { - patch.SetShader(replace); - } - }); + if( DoingSearch( replace ) ){ + //do nothing, because alternative is replacing to notex + //perhaps deselect ones with not matching shaders here? + } + else{ + Scene_forEachVisibleSelectedPatch( PatchFindReplaceShader( find, replace ) ); + } } @@ -543,6 +685,23 @@ void Patch_FitTexture(){ Scene_PatchTileTexture_Selected( GlobalSceneGraph(), 1, 1 ); } +void DoPatchDeformDlg(); + +void Patch_Deform(){ + UndoableCommand undo( "patchDeform" ); + + DoPatchDeformDlg(); +} + +void DoPatchThickenDlg(); + +void Patch_Thicken(){ + UndoableCommand undo( "patchThicken" ); + + DoPatchThickenDlg(); +} + + #include "ifilter.h" @@ -600,55 +759,61 @@ void Patch_constructPage( PreferenceGroup& group ){ Patch_constructPreferences( page ); } void Patch_registerPreferencesPage(){ - PreferencesDialog_addDisplayPage( FreeCaller() ); + PreferencesDialog_addDisplayPage( makeCallbackF(Patch_constructPage) ); } #include "preferencesystem.h" void PatchPreferences_construct(){ - GlobalPreferenceSystem().registerPreference( "Subdivisions", IntImportStringCaller( g_PatchSubdivideThreshold ), IntExportStringCaller( g_PatchSubdivideThreshold ) ); + GlobalPreferenceSystem().registerPreference( "Subdivisions", make_property_string( g_PatchSubdivideThreshold ) ); } #include "generic/callback.h" void Patch_registerCommands(){ - GlobalCommands_insert( "InvertCurveTextureX", FreeCaller(), Accelerator( 'I', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) ); - GlobalCommands_insert( "InvertCurveTextureY", FreeCaller(), Accelerator( 'I', (GdkModifierType)GDK_SHIFT_MASK ) ); - GlobalCommands_insert( "NaturalizePatch", FreeCaller(), Accelerator( 'N', (GdkModifierType)GDK_CONTROL_MASK ) ); - GlobalCommands_insert( "PatchCylinder", FreeCaller() ); - GlobalCommands_insert( "PatchDenseCylinder", FreeCaller() ); - GlobalCommands_insert( "PatchVeryDenseCylinder", FreeCaller() ); - GlobalCommands_insert( "PatchSquareCylinder", FreeCaller() ); - GlobalCommands_insert( "PatchXactCylinder", FreeCaller() ); - GlobalCommands_insert( "PatchXactSphere", FreeCaller() ); - GlobalCommands_insert( "PatchXactCone", FreeCaller() ); - GlobalCommands_insert( "PatchEndCap", FreeCaller() ); - GlobalCommands_insert( "PatchBevel", FreeCaller() ); - GlobalCommands_insert( "PatchSquareBevel", FreeCaller() ); - GlobalCommands_insert( "PatchSquareEndcap", FreeCaller() ); - GlobalCommands_insert( "PatchCone", FreeCaller() ); - GlobalCommands_insert( "PatchSphere", FreeCaller() ); - GlobalCommands_insert( "SimplePatchMesh", FreeCaller(), Accelerator( 'P', (GdkModifierType)GDK_SHIFT_MASK ) ); - GlobalCommands_insert( "PatchInsertInsertColumn", FreeCaller(), Accelerator( GDK_KEY_KP_Add, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) ); - GlobalCommands_insert( "PatchInsertAddColumn", FreeCaller() ); - GlobalCommands_insert( "PatchInsertInsertRow", FreeCaller(), Accelerator( GDK_KEY_KP_Add, (GdkModifierType)GDK_CONTROL_MASK ) ); - GlobalCommands_insert( "PatchInsertAddRow", FreeCaller() ); - GlobalCommands_insert( "PatchDeleteFirstColumn", FreeCaller() ); - GlobalCommands_insert( "PatchDeleteLastColumn", FreeCaller(), Accelerator( GDK_KEY_KP_Subtract, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) ); - GlobalCommands_insert( "PatchDeleteFirstRow", FreeCaller(), Accelerator( GDK_KEY_KP_Subtract, (GdkModifierType)GDK_CONTROL_MASK ) ); - GlobalCommands_insert( "PatchDeleteLastRow", FreeCaller() ); - GlobalCommands_insert( "InvertCurve", FreeCaller(), Accelerator( 'I', (GdkModifierType)GDK_CONTROL_MASK ) ); - GlobalCommands_insert( "RedisperseRows", FreeCaller(), Accelerator( 'E', (GdkModifierType)GDK_CONTROL_MASK ) ); - GlobalCommands_insert( "RedisperseCols", FreeCaller(), Accelerator( 'E', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) ); - GlobalCommands_insert( "SmoothRows", FreeCaller(), Accelerator( 'W', (GdkModifierType)GDK_CONTROL_MASK ) ); - GlobalCommands_insert( "SmoothCols", FreeCaller(), Accelerator( 'W', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) ); - GlobalCommands_insert( "MatrixTranspose", FreeCaller(), Accelerator( 'M', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) ); - GlobalCommands_insert( "CapCurrentCurve", FreeCaller(), Accelerator( 'C', (GdkModifierType)GDK_SHIFT_MASK ) ); - GlobalCommands_insert( "CycleCapTexturePatch", FreeCaller(), Accelerator( 'N', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) ); - GlobalCommands_insert( "MakeOverlayPatch", FreeCaller(), Accelerator( 'Y' ) ); - GlobalCommands_insert( "ClearPatchOverlays", FreeCaller(), Accelerator( 'L', (GdkModifierType)GDK_CONTROL_MASK ) ); + 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) ); + GlobalCommands_insert( "PatchVeryDenseCylinder", makeCallbackF(Patch_VeryDenseCylinder) ); + GlobalCommands_insert( "PatchSquareCylinder", makeCallbackF(Patch_SquareCylinder) ); + GlobalCommands_insert( "PatchXactCylinder", makeCallbackF(Patch_XactCylinder) ); + GlobalCommands_insert( "PatchXactSphere", makeCallbackF(Patch_XactSphere) ); + GlobalCommands_insert( "PatchXactCone", makeCallbackF(Patch_XactCone) ); + GlobalCommands_insert( "PatchEndCap", makeCallbackF(Patch_Endcap) ); + GlobalCommands_insert( "PatchBevel", makeCallbackF(Patch_Bevel) ); + GlobalCommands_insert( "PatchSquareBevel", makeCallbackF(Patch_SquareBevel) ); + GlobalCommands_insert( "PatchSquareEndcap", makeCallbackF(Patch_SquareEndcap) ); + GlobalCommands_insert( "PatchCone", makeCallbackF(Patch_Cone) ); + GlobalCommands_insert( "PatchSphere", makeCallbackF(Patch_Sphere) ); + GlobalCommands_insert( "SimplePatchMesh", makeCallbackF(Patch_Plane), Accelerator( 'P', (GdkModifierType)GDK_SHIFT_MASK ) ); + GlobalCommands_insert( "PatchInsertInsertColumn", makeCallbackF(Patch_InsertInsertColumn), Accelerator( GDK_KEY_KP_Add, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) ); + GlobalCommands_insert( "PatchInsertAddColumn", makeCallbackF(Patch_InsertAddColumn) ); + GlobalCommands_insert( "PatchInsertInsertRow", makeCallbackF(Patch_InsertInsertRow), Accelerator( GDK_KEY_KP_Add, (GdkModifierType)GDK_CONTROL_MASK ) ); + GlobalCommands_insert( "PatchInsertAddRow", makeCallbackF(Patch_InsertAddRow) ); + GlobalCommands_insert( "PatchDeleteFirstColumn", makeCallbackF(Patch_DeleteFirstColumn) ); + GlobalCommands_insert( "PatchDeleteLastColumn", makeCallbackF(Patch_DeleteLastColumn), Accelerator( GDK_KEY_KP_Subtract, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) ); + GlobalCommands_insert( "PatchDeleteFirstRow", makeCallbackF(Patch_DeleteFirstRow), Accelerator( GDK_KEY_KP_Subtract, (GdkModifierType)GDK_CONTROL_MASK ) ); + GlobalCommands_insert( "PatchDeleteLastRow", makeCallbackF(Patch_DeleteLastRow) ); + GlobalCommands_insert( "InvertCurve", makeCallbackF(Patch_Invert), Accelerator( 'I', (GdkModifierType)GDK_CONTROL_MASK ) ); + GlobalCommands_insert( "RedisperseRows", makeCallbackF(Patch_RedisperseRows), Accelerator( 'E', (GdkModifierType)GDK_CONTROL_MASK ) ); + GlobalCommands_insert( "RedisperseCols", makeCallbackF(Patch_RedisperseCols), Accelerator( 'E', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) ); + GlobalCommands_insert( "SmoothRows", makeCallbackF(Patch_SmoothRows), Accelerator( 'W', (GdkModifierType)GDK_CONTROL_MASK ) ); + GlobalCommands_insert( "SmoothCols", makeCallbackF(Patch_SmoothCols), Accelerator( 'W', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) ); + GlobalCommands_insert( "MatrixTranspose", makeCallbackF(Patch_Transpose), Accelerator( 'M', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) ); + GlobalCommands_insert( "CapCurrentCurve", makeCallbackF(Patch_Cap), Accelerator( 'C', (GdkModifierType)GDK_SHIFT_MASK ) ); + 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) ); + GlobalCommands_insert( "PatchThicken", makeCallbackF(Patch_Thicken) ); } void Patch_constructToolbar( ui::Toolbar toolbar ){ @@ -671,12 +836,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" ); @@ -692,11 +857,11 @@ void Patch_constructMenu( ui::Menu menu ){ if ( g_Layout_enableDetachableMenus.m_value ) { menu_tearoff( menu_in_menu ); } - create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Columns", "PatchInsertInsertColumn" ); create_menu_item_with_mnemonic( menu_in_menu, "Add (2) Columns", "PatchInsertAddColumn" ); + create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Columns", "PatchInsertInsertColumn" ); menu_separator( menu_in_menu ); - create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Rows", "PatchInsertInsertRow" ); create_menu_item_with_mnemonic( menu_in_menu, "Add (2) Rows", "PatchInsertAddRow" ); + create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Rows", "PatchInsertInsertRow" ); } { auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Delete" ); @@ -716,24 +881,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 +921,9 @@ 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" ); + create_menu_item_with_mnemonic( menu, "Thicken...", "PatchThicken" ); } @@ -750,14 +932,13 @@ void Patch_constructMenu( ui::Menu menu ){ void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols ){ ModalDialog dialog; - GtkComboBox* width; - GtkComboBox* height; ui::Window window = MainFrame_getWindow().create_dialog_window("Patch density", G_CALLBACK(dialog_delete_callback ), &dialog ); auto accel = ui::AccelGroup(ui::New); window.add_accel_group( accel ); - + auto width = ui::ComboBoxText(ui::New); + auto height = ui::ComboBoxText(ui::New); { auto hbox = create_dialog_hbox( 4, 4 ); window.add(hbox); @@ -778,7 +959,7 @@ void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, } { - auto combo = ui::ComboBoxText(ui::New); + auto combo = width; #define D_ITEM( x ) if ( x >= mincols && ( !maxcols || x <= maxcols ) ) gtk_combo_box_text_append_text( combo, #x ) D_ITEM( 3 ); D_ITEM( 5 ); @@ -798,11 +979,9 @@ void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, #undef D_ITEM combo.show(); table.attach(combo, {1, 2, 0, 1}, {GTK_EXPAND | GTK_FILL, 0}); - - width = combo; } { - auto combo = ui::ComboBoxText(ui::New); + auto combo = height; #define D_ITEM( x ) if ( x >= minrows && ( !maxrows || x <= maxrows ) ) gtk_combo_box_text_append_text( combo, #x ) D_ITEM( 3 ); D_ITEM( 5 ); @@ -822,8 +1001,6 @@ void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, #undef D_ITEM combo.show(); table.attach(combo, {1, 2, 1, 2}, {GTK_EXPAND | GTK_FILL, 0}); - - height = combo; } } @@ -860,6 +1037,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 ); + + { + auto hbox = create_dialog_hbox( 4, 4 ); + gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) ); + { + auto 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 ); + hbox.pack_start( vbox, FALSE, FALSE, 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( atoi( gtk_entry_get_text( GTK_ENTRY( deformW ) ) ) ); + Scene_PatchDeform( GlobalSceneGraph(), deform ); + } + + gtk_widget_destroy( GTK_WIDGET( window ) ); +} + EMessageBoxReturn DoCapDlg( ECapDialog* type ){ @@ -921,7 +1158,7 @@ EMessageBoxReturn DoCapDlg( ECapDialog* type ){ GSList* group = 0; { - ui::Widget button = ui::Widget(gtk_radio_button_new_with_label( group, "Bevel" )); + ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Bevel" )); button.show(); table.attach(button, {1, 2, 0, 1}, {GTK_FILL | GTK_EXPAND, 0}); group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) ); @@ -929,7 +1166,7 @@ EMessageBoxReturn DoCapDlg( ECapDialog* type ){ bevel = button; } { - ui::Widget button = ui::Widget(gtk_radio_button_new_with_label( group, "Endcap" )); + ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Endcap" )); button.show(); table.attach(button, {1, 2, 1, 2}, {GTK_FILL | GTK_EXPAND, 0}); group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) ); @@ -937,7 +1174,7 @@ EMessageBoxReturn DoCapDlg( ECapDialog* type ){ endcap = button; } { - ui::Widget button = ui::Widget(gtk_radio_button_new_with_label( group, "Inverted Bevel" )); + ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Inverted Bevel" )); button.show(); table.attach(button, {1, 2, 2, 3}, {GTK_FILL | GTK_EXPAND, 0}); group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) ); @@ -945,7 +1182,7 @@ EMessageBoxReturn DoCapDlg( ECapDialog* type ){ ibevel = button; } { - ui::Widget button = ui::Widget(gtk_radio_button_new_with_label( group, "Inverted Endcap" )); + ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Inverted Endcap" )); button.show(); table.attach(button, {1, 2, 3, 4}, {GTK_FILL | GTK_EXPAND, 0}); group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) ); @@ -953,7 +1190,7 @@ EMessageBoxReturn DoCapDlg( ECapDialog* type ){ iendcap = button; } { - ui::Widget button = ui::Widget(gtk_radio_button_new_with_label( group, "Cylinder" )); + ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Cylinder" )); button.show(); table.attach(button, {1, 2, 4, 5}, {GTK_FILL | GTK_EXPAND, 0}); group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) ); @@ -1006,3 +1243,128 @@ EMessageBoxReturn DoCapDlg( ECapDialog* type ){ return ret; } + + +void DoPatchThickenDlg(){ + ModalDialog dialog; + GtkWidget* thicknessW; + GtkWidget* seamsW; + GtkWidget* radX; + GtkWidget* radY; + GtkWidget* radZ; + GtkWidget* radNormals; + + ui::Window window = create_dialog_window( MainFrame_getWindow(), "Patch thicken", G_CALLBACK( dialog_delete_callback ), &dialog ); + + GtkAccelGroup* accel = gtk_accel_group_new(); + gtk_window_add_accel_group( window, accel ); + + { + auto hbox = create_dialog_hbox( 4, 4 ); + gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) ); + { + auto table = create_dialog_table( 2, 4, 4, 4 ); + gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 ); + { + GtkLabel* label = GTK_LABEL( gtk_label_new( "Thickness:" ) ); + 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_set_size_request( entry, 40, -1 ); + gtk_widget_show( entry ); + gtk_table_attach( table, entry, 1, 2, 0, 1, + (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ), + (GtkAttachOptions) ( 0 ), 0, 0 ); + + thicknessW = entry; + } + { + // Create the "create seams" label + GtkWidget* _seamsCheckBox = gtk_check_button_new_with_label( "Side walls" ); + gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( _seamsCheckBox ), TRUE ); + gtk_widget_show( _seamsCheckBox ); + gtk_table_attach( table, _seamsCheckBox, 3, 4, 0, 1, + (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ), + (GtkAttachOptions) ( 0 ), 0, 0 ); + seamsW = _seamsCheckBox; + + } + { + // Create the radio button group for choosing the extrude axis + GtkWidget* _radNormals = gtk_radio_button_new_with_label( NULL, "Normal" ); + GtkWidget* _radX = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "X" ); + GtkWidget* _radY = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "Y" ); + GtkWidget* _radZ = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "Z" ); + gtk_widget_show( _radNormals ); + gtk_widget_show( _radX ); + gtk_widget_show( _radY ); + gtk_widget_show( _radZ ); + + + // Pack the buttons into the table + gtk_table_attach( table, _radNormals, 0, 1, 1, 2, + (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ), + (GtkAttachOptions) ( 0 ), 0, 0 ); + gtk_table_attach( table, _radX, 1, 2, 1, 2, + (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ), + (GtkAttachOptions) ( 0 ), 0, 0 ); + gtk_table_attach( table, _radY, 2, 3, 1, 2, + (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ), + (GtkAttachOptions) ( 0 ), 0, 0 ); + gtk_table_attach( table, _radZ, 3, 4, 1, 2, + (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ), + (GtkAttachOptions) ( 0 ), 0, 0 ); + radX = _radX; + radY = _radY; + radZ = _radZ; + radNormals = _radNormals; + } + } + { + auto vbox = create_dialog_vbox( 4 ); + hbox.pack_start( vbox, FALSE, FALSE, 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 axis; + bool seams; + float thickness = static_cast( atoi( gtk_entry_get_text( GTK_ENTRY( thicknessW ) ) ) ); + seams = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( seamsW )) ? true : false; + + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radX))) { + axis = 0; + } + else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radY))) { + axis = 1; + } + else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radZ))) { + axis = 2; + } + else { + // Extrude along normals + axis = 3; + } + Scene_PatchThicken( GlobalSceneGraph(), thickness, seams, axis ); + } + + gtk_widget_destroy( GTK_WIDGET( window ) ); +}