2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "patchmanip.h"
25 #include <gdk/gdkkeysyms.h>
27 #include "debugging/debugging.h"
30 #include "iselection.h"
33 #include "math/vector.h"
34 #include "math/aabb.h"
35 #include "generic/callback.h"
37 #include "gtkutil/menu.h"
38 #include "gtkutil/image.h"
40 #include "mainframe.h"
44 #include "texwindow.h"
50 PatchCreator* g_patchCreator = 0;
52 void Scene_PatchConstructPrefab( scene::Graph& graph, const AABB aabb, const char* shader, EPatchPrefab eType, int axis, std::size_t width = 3, std::size_t height = 3, bool redisperse = false ){
54 GlobalSelectionSystem().setSelectedAll( false );
56 NodeSmartReference node( g_patchCreator->createPatch() );
57 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
59 Patch* patch = Node_getPatch( node );
60 patch->SetShader( shader );
62 patch->ConstructPrefab( aabb, eType, axis, width, height );
64 patch->Redisperse( COL );
65 patch->Redisperse( ROW );
67 patch->controlPointsChanged();
70 scene::Path patchpath( makeReference( GlobalSceneGraph().root() ) );
71 patchpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
72 patchpath.push( makeReference( node.get() ) );
73 Instance_getSelectable( *graph.find( patchpath ) )->setSelected( true );
77 void PatchAutoCapTexture( Patch& patch ) {
79 AABB box = patch.localAABB();
80 float x = box.extents.x();
81 float y = box.extents.y();
82 float z = box.extents.z();
84 int cap_direction = -1;
87 else if ( y < x && y < z )
89 else if ( z < x && z < x )
92 if ( cap_direction >= 0 )
93 patch.ProjectTexture(cap_direction);
95 patch.NaturalTexture();
98 void Patch_AutoCapTexture(){
99 UndoableCommand command( "patchAutoCapTexture" );
100 Scene_forEachVisibleSelectedPatch( &PatchAutoCapTexture );
104 void Patch_makeCaps( Patch& patch, scene::Instance& instance, EPatchCap type, const char* shader ){
105 if ( ( type == eCapEndCap || type == eCapIEndCap )
106 && patch.getWidth() != 5 ) {
107 globalErrorStream() << "cannot create end-cap - patch width != 5\n";
110 if ( ( type == eCapBevel || type == eCapIBevel )
111 && patch.getWidth() != 3 && patch.getWidth() != 5 ) {
112 globalErrorStream() << "cannot create bevel-cap - patch width != 3\n";
115 if ( type == eCapCylinder
116 && patch.getWidth() != 9 ) {
117 globalErrorStream() << "cannot create cylinder-cap - patch width != 9\n";
122 NodeSmartReference cap( g_patchCreator->createPatch() );
123 Node_getTraversable( instance.path().parent() )->insert( cap );
125 Patch* cap_patch = Node_getPatch( cap );
126 patch.MakeCap( cap_patch, type, ROW, true );
127 cap_patch->SetShader( shader );
128 PatchAutoCapTexture(*cap_patch);
130 scene::Path path( instance.path() );
132 path.push( makeReference( cap.get() ) );
133 selectPath( path, true );
137 NodeSmartReference cap( g_patchCreator->createPatch() );
138 Node_getTraversable( instance.path().parent() )->insert( cap );
140 Patch* cap_patch = Node_getPatch( cap );
141 patch.MakeCap( cap_patch, type, ROW, false );
142 cap_patch->SetShader( shader );
143 PatchAutoCapTexture(*cap_patch);
145 scene::Path path( instance.path() );
147 path.push( makeReference( cap.get() ) );
148 selectPath( path, true );
153 typedef std::vector<scene::Instance*> InstanceVector;
158 PATCHCAP_INVERTED_BEVEL,
159 PATCHCAP_INVERTED_ENDCAP,
163 EMessageBoxReturn DoCapDlg( ECapDialog *type );
165 void Scene_PatchDoCap_Selected( scene::Graph& graph, const char* shader ){
168 if ( DoCapDlg( &nType ) == eIDOK ) {
172 case PATCHCAP_INVERTED_BEVEL:
178 case PATCHCAP_INVERTED_ENDCAP:
181 case PATCHCAP_ENDCAP:
184 case PATCHCAP_CYLINDER:
185 eType = eCapCylinder;
188 ERROR_MESSAGE( "invalid patch cap type" );
192 InstanceVector instances;
193 Scene_forEachVisibleSelectedPatchInstance([&](PatchInstance &patch) {
194 instances.push_back(&patch);
196 for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
198 Patch_makeCaps( *Node_getPatch( ( *i )->path().top() ), *( *i ), eType, shader );
203 void Patch_deform( Patch& patch, scene::Instance& instance, const int deform, const int axis ){
206 for ( PatchControlIter i = patch.begin(); i != patch.end(); ++i ){
207 PatchControl& control = *i;
208 int randomNumber = int( deform * ( float( std::rand() ) / float( RAND_MAX ) ) );
209 control.m_vertex[ axis ] += randomNumber;
212 patch.controlPointsChanged();
215 void Scene_PatchDeform( scene::Graph& graph, const int deform, const int axis )
217 InstanceVector instances;
218 Scene_forEachVisibleSelectedPatchInstance([&](PatchInstance &patch) {
219 instances.push_back(&patch);
221 for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
223 Patch_deform( *Node_getPatch( ( *i )->path().top() ), *( *i ), deform, axis );
228 void Patch_thicken( Patch& patch, scene::Instance& instance, const float thickness, bool seams, const int axis ){
230 // Create a new patch node
231 NodeSmartReference node( g_patchCreator->createPatch() );
232 // Insert the node into worldspawn
233 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
235 // Retrieve the contained patch from the node
236 Patch* targetPatch = Node_getPatch( node );
238 // Create the opposite patch with the given thickness = distance
241 targetPatch->createThickenedOpposite( patch, thickness, axis, no12, no34 );
243 // Now select the newly created patches
245 scene::Path patchpath( makeReference( GlobalSceneGraph().root() ) );
246 patchpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
247 patchpath.push( makeReference( node.get() ) );
248 Instance_getSelectable( *GlobalSceneGraph().find( patchpath ) )->setSelected( true );
251 if( seams && thickness != 0.0f){
260 // Now create the four walls
261 for ( ; i < iend; i++ ){
262 // Allocate new patch
263 NodeSmartReference node = NodeSmartReference( g_patchCreator->createPatch() );
264 // Insert each node into worldspawn
265 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
267 // Retrieve the contained patch from the node
268 Patch* wallPatch = Node_getPatch( node );
270 // Create the wall patch by passing i as wallIndex
271 wallPatch->createThickenedWall( patch, *targetPatch, i );
273 if( ( wallPatch->localAABB().extents[0] <= 0.00005 && wallPatch->localAABB().extents[1] <= 0.00005 ) ||
274 ( wallPatch->localAABB().extents[1] <= 0.00005 && wallPatch->localAABB().extents[2] <= 0.00005 ) ||
275 ( wallPatch->localAABB().extents[0] <= 0.00005 && wallPatch->localAABB().extents[2] <= 0.00005 ) ){
276 //globalOutputStream() << "Thicken: Discarding degenerate patch.\n";
277 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->erase( node );
280 // Now select the newly created patches
282 scene::Path patchpath( makeReference( GlobalSceneGraph().root() ) );
283 patchpath.push( makeReference( *Map_GetWorldspawn(g_map) ) );
284 patchpath.push( makeReference( node.get() ) );
285 Instance_getSelectable( *GlobalSceneGraph().find( patchpath ) )->setSelected( true );
290 // Invert the target patch so that it faces the opposite direction
291 targetPatch->InvertMatrix();
294 void Scene_PatchThicken( scene::Graph& graph, const int thickness, bool seams, const int axis )
296 InstanceVector instances;
297 Scene_forEachVisibleSelectedPatchInstance([&](PatchInstance &patch) {
298 instances.push_back(&patch);
300 for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
302 Patch_thicken( *Node_getPatch( ( *i )->path().top() ), *( *i ), thickness, seams, axis );
307 Patch* Scene_GetUltimateSelectedVisiblePatch(){
308 if ( GlobalSelectionSystem().countSelected() != 0 ) {
309 scene::Node& node = GlobalSelectionSystem().ultimateSelected().path().top();
310 if ( node.visible() ) {
311 return Node_getPatch( node );
318 void Scene_PatchCapTexture_Selected( scene::Graph& graph ){
319 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
320 patch.ProjectTexture(Patch::m_CycleCapIndex);
322 Patch::m_CycleCapIndex = ( Patch::m_CycleCapIndex == 0 ) ? 1 : ( Patch::m_CycleCapIndex == 1 ) ? 2 : 0;
326 void Scene_PatchFlipTexture_Selected( scene::Graph& graph, int axis ){
327 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
328 patch.FlipTexture(axis);
332 void Scene_PatchNaturalTexture_Selected( scene::Graph& graph ){
333 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
334 patch.NaturalTexture();
340 void Scene_PatchInsertRemove_Selected( scene::Graph& graph, bool bInsert, bool bColumn, bool bFirst ){
341 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
342 patch.InsertRemove(bInsert, bColumn, bFirst);
346 void Scene_PatchInvert_Selected( scene::Graph& graph ){
347 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
348 patch.InvertMatrix();
352 void Scene_PatchRedisperse_Selected( scene::Graph& graph, EMatrixMajor major ){
353 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
354 patch.Redisperse(major);
358 void Scene_PatchSmooth_Selected( scene::Graph& graph, EMatrixMajor major ){
359 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
364 void Scene_PatchTranspose_Selected( scene::Graph& graph ){
365 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
366 patch.TransposeMatrix();
370 void Scene_PatchSetShader_Selected( scene::Graph& graph, const char* name ){
371 Scene_forEachVisibleSelectedPatch([&](Patch &patch) {
372 patch.SetShader(name);
377 void Scene_PatchGetShader_Selected( scene::Graph& graph, CopiedString& name ){
378 Patch* patch = Scene_GetUltimateSelectedVisiblePatch();
380 name = patch->GetShader();
384 class PatchSelectByShader
388 inline PatchSelectByShader( const char* name )
391 void operator()( PatchInstance& patch ) const {
392 if ( shader_equal( patch.getPatch().GetShader(), m_name ) ) {
393 patch.setSelected( true );
398 void Scene_PatchSelectByShader( scene::Graph& graph, const char* name ){
399 Scene_forEachVisiblePatchInstance([&](PatchInstance &patch) {
400 if (shader_equal(patch.getPatch().GetShader(), name)) {
401 patch.setSelected(true);
407 class PatchFindReplaceShader
410 const char* m_replace;
412 PatchFindReplaceShader( const char* find, const char* replace ) : m_find( find ), m_replace( replace ){
414 void operator()( Patch& patch ) const {
415 if ( shader_equal( patch.GetShader(), m_find ) ) {
416 patch.SetShader( m_replace );
422 bool DoingSearch( const char *repl ){
423 return ( repl == NULL || ( strcmp( "textures/", repl ) == 0 ) );
426 void Scene_PatchFindReplaceShader( scene::Graph& graph, const char* find, const char* replace ){
427 if( DoingSearch( replace ) ){
428 Scene_forEachVisiblePatchInstance( PatchSelectByShader( find ) );
431 Scene_forEachVisiblePatch( PatchFindReplaceShader( find, replace ) );
435 void Scene_PatchFindReplaceShader_Selected( scene::Graph& graph, const char* find, const char* replace ){
436 if( DoingSearch( replace ) ){
437 //do nothing, because alternative is replacing to notex
438 //perhaps deselect ones with not matching shaders here?
441 Scene_forEachVisibleSelectedPatch( PatchFindReplaceShader( find, replace ) );
446 AABB PatchCreator_getBounds(){
447 AABB aabb( aabb_for_minmax( Select_getWorkZone().d_work_min, Select_getWorkZone().d_work_max ) );
449 float gridSize = GetGridSize();
451 if ( aabb.extents[0] == 0 ) {
452 aabb.extents[0] = gridSize;
454 if ( aabb.extents[1] == 0 ) {
455 aabb.extents[1] = gridSize;
457 if ( aabb.extents[2] == 0 ) {
458 aabb.extents[2] = gridSize;
461 if ( aabb_valid( aabb ) ) {
464 return AABB( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
467 void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols );
469 void Patch_XactCylinder(){
470 UndoableCommand undo( "patchCreateXactCylinder" );
472 DoNewPatchDlg( eXactCylinder, 3, 7, 3, 13, 0, 0 );
475 void Patch_XactSphere(){
476 UndoableCommand undo( "patchCreateXactSphere" );
478 DoNewPatchDlg( eXactSphere, 5, 7, 7, 13, 0, 0 );
481 void Patch_XactCone(){
482 UndoableCommand undo( "patchCreateXactCone" );
484 DoNewPatchDlg( eXactCone, 3, 7, 3, 13, 0, 0 );
487 void Patch_Cylinder(){
488 UndoableCommand undo( "patchCreateCylinder" );
490 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eCylinder, GlobalXYWnd_getCurrentViewType() );
493 void Patch_DenseCylinder(){
494 UndoableCommand undo( "patchCreateDenseCylinder" );
496 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eDenseCylinder, GlobalXYWnd_getCurrentViewType() );
499 void Patch_VeryDenseCylinder(){
500 UndoableCommand undo( "patchCreateVeryDenseCylinder" );
502 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eVeryDenseCylinder, GlobalXYWnd_getCurrentViewType() );
505 void Patch_SquareCylinder(){
506 UndoableCommand undo( "patchCreateSquareCylinder" );
508 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eSqCylinder, GlobalXYWnd_getCurrentViewType() );
512 UndoableCommand undo( "patchCreateCaps" );
514 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eEndCap, GlobalXYWnd_getCurrentViewType() );
518 UndoableCommand undo( "patchCreateBevel" );
520 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eBevel, GlobalXYWnd_getCurrentViewType() );
524 UndoableCommand undo( "patchCreateSphere" );
526 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eSphere, GlobalXYWnd_getCurrentViewType() );
529 void Patch_SquareBevel(){
532 void Patch_SquareEndcap(){
536 UndoableCommand undo( "patchCreateCone" );
538 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eCone, GlobalXYWnd_getCurrentViewType() );
542 UndoableCommand undo( "patchCreatePlane" );
544 DoNewPatchDlg( ePlane, 3, 3, 3, 3, 0, 0 );
547 void Patch_InsertFirstColumn(){
548 UndoableCommand undo( "patchInsertFirstColumns" );
550 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, true, true );
553 void Patch_InsertLastColumn(){
554 UndoableCommand undo( "patchInsertLastColumns" );
556 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, true, false );
559 void Patch_InsertFirstRow(){
560 UndoableCommand undo( "patchInsertFirstRows" );
562 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, false, true );
565 void Patch_InsertLastRow(){
566 UndoableCommand undo( "patchInsertLastRows" );
568 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, false, false );
571 void Patch_DeleteFirstColumn(){
572 UndoableCommand undo( "patchDeleteFirstColumns" );
574 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, true, true );
577 void Patch_DeleteLastColumn(){
578 UndoableCommand undo( "patchDeleteLastColumns" );
580 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, true, false );
583 void Patch_DeleteFirstRow(){
584 UndoableCommand undo( "patchDeleteFirstRows" );
586 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, false, true );
589 void Patch_DeleteLastRow(){
590 UndoableCommand undo( "patchDeleteLastRows" );
592 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, false, false );
596 UndoableCommand undo( "patchInvert" );
598 Scene_PatchInvert_Selected( GlobalSceneGraph() );
601 void Patch_RedisperseRows(){
602 UndoableCommand undo( "patchRedisperseRows" );
604 Scene_PatchRedisperse_Selected( GlobalSceneGraph(), ROW );
607 void Patch_RedisperseCols(){
608 UndoableCommand undo( "patchRedisperseColumns" );
610 Scene_PatchRedisperse_Selected( GlobalSceneGraph(), COL );
613 void Patch_SmoothRows(){
614 UndoableCommand undo( "patchSmoothRows" );
616 Scene_PatchSmooth_Selected( GlobalSceneGraph(), ROW );
619 void Patch_SmoothCols(){
620 UndoableCommand undo( "patchSmoothColumns" );
622 Scene_PatchSmooth_Selected( GlobalSceneGraph(), COL );
625 void Patch_Transpose(){
626 UndoableCommand undo( "patchTranspose" );
628 Scene_PatchTranspose_Selected( GlobalSceneGraph() );
632 // FIXME: add support for patch cap creation
633 // Patch_CapCurrent();
634 UndoableCommand undo( "patchCreateCaps" );
636 Scene_PatchDoCap_Selected( GlobalSceneGraph(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
639 void Patch_CycleProjection(){
640 UndoableCommand undo( "patchCycleUVProjectionAxis" );
642 Scene_PatchCapTexture_Selected( GlobalSceneGraph() );
646 void Patch_OverlayOn(){
650 void Patch_OverlayOff(){
653 void Patch_FlipTextureX(){
654 UndoableCommand undo( "patchFlipTextureU" );
656 Scene_PatchFlipTexture_Selected( GlobalSceneGraph(), 0 );
659 void Patch_FlipTextureY(){
660 UndoableCommand undo( "patchFlipTextureV" );
662 Scene_PatchFlipTexture_Selected( GlobalSceneGraph(), 1 );
665 void Patch_NaturalTexture(){
666 UndoableCommand undo( "patchNaturalTexture" );
668 Scene_PatchNaturalTexture_Selected( GlobalSceneGraph() );
671 void Patch_CapTexture(){
672 UndoableCommand command( "patchCapTexture" );
674 Scene_PatchCapTexture_Selected( GlobalSceneGraph() );
677 void Patch_ResetTexture(){
679 if ( DoTextureLayout( &fx, &fy ) == eIDOK ) {
680 UndoableCommand command( "patchTileTexture" );
681 Scene_PatchTileTexture_Selected( GlobalSceneGraph(), fx, fy );
685 void Patch_FitTexture(){
686 UndoableCommand command( "patchFitTexture" );
688 Scene_PatchTileTexture_Selected( GlobalSceneGraph(), 1, 1 );
691 void DoPatchDeformDlg();
694 UndoableCommand undo( "patchDeform" );
699 void DoPatchThickenDlg();
701 void Patch_Thicken(){
702 UndoableCommand undo( "patchThicken" );
711 class filter_patch_all : public PatchFilter
714 bool filter( const Patch& patch ) const {
719 class filter_patch_shader : public PatchFilter
721 const char* m_shader;
723 filter_patch_shader( const char* shader ) : m_shader( shader ){
725 bool filter( const Patch& patch ) const {
726 return shader_equal( patch.GetShader(), m_shader );
730 class filter_patch_flags : public PatchFilter
734 filter_patch_flags( int flags ) : m_flags( flags ){
736 bool filter( const Patch& patch ) const {
737 return ( patch.getShaderFlags() & m_flags ) != 0;
742 filter_patch_all g_filter_patch_all;
743 filter_patch_flags g_filter_patch_clip( QER_CLIP );
744 filter_patch_shader g_filter_patch_commonclip( "textures/common/clip" );
745 filter_patch_shader g_filter_patch_weapclip( "textures/common/weapclip" );
746 filter_patch_flags g_filter_patch_translucent( QER_TRANS | QER_ALPHATEST );
748 void PatchFilters_construct(){
749 add_patch_filter( g_filter_patch_all, EXCLUDE_CURVES );
750 add_patch_filter( g_filter_patch_clip, EXCLUDE_CLIP );
751 add_patch_filter( g_filter_patch_commonclip, EXCLUDE_CLIP );
752 add_patch_filter( g_filter_patch_weapclip, EXCLUDE_CLIP );
753 add_patch_filter( g_filter_patch_translucent, EXCLUDE_TRANSLUCENT );
757 #include "preferences.h"
759 void Patch_constructPreferences( PreferencesPage& page ){
760 page.appendEntry( "Patch Subdivide Threshold", g_PatchSubdivideThreshold );
762 void Patch_constructPage( PreferenceGroup& group ){
763 PreferencesPage page( group.createPage( "Patches", "Patch Display Preferences" ) );
764 Patch_constructPreferences( page );
766 void Patch_registerPreferencesPage(){
767 PreferencesDialog_addDisplayPage( makeCallbackF(Patch_constructPage) );
771 #include "preferencesystem.h"
773 void PatchPreferences_construct(){
774 GlobalPreferenceSystem().registerPreference( "Subdivisions", make_property_string( g_PatchSubdivideThreshold ) );
778 #include "generic/callback.h"
780 void Patch_registerCommands(){
781 GlobalCommands_insert( "InvertCurveTextureX", makeCallbackF(Patch_FlipTextureX), Accelerator( 'I', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
782 GlobalCommands_insert( "InvertCurveTextureY", makeCallbackF(Patch_FlipTextureY), Accelerator( 'I', (GdkModifierType)GDK_SHIFT_MASK ) );
783 GlobalCommands_insert( "NaturalizePatch", makeCallbackF(Patch_NaturalTexture), Accelerator( 'N', (GdkModifierType)GDK_CONTROL_MASK ) );
784 GlobalCommands_insert( "PatchCylinder", makeCallbackF(Patch_Cylinder) );
785 // GlobalCommands_insert( "PatchDenseCylinder", makeCallbackF(Patch_DenseCylinder) );
786 // GlobalCommands_insert( "PatchVeryDenseCylinder", makeCallbackF(Patch_VeryDenseCylinder) );
787 GlobalCommands_insert( "PatchSquareCylinder", makeCallbackF(Patch_SquareCylinder) );
788 GlobalCommands_insert( "PatchXactCylinder", makeCallbackF(Patch_XactCylinder) );
789 GlobalCommands_insert( "PatchXactSphere", makeCallbackF(Patch_XactSphere) );
790 GlobalCommands_insert( "PatchXactCone", makeCallbackF(Patch_XactCone) );
791 GlobalCommands_insert( "PatchEndCap", makeCallbackF(Patch_Endcap) );
792 GlobalCommands_insert( "PatchBevel", makeCallbackF(Patch_Bevel) );
793 // GlobalCommands_insert( "PatchSquareBevel", makeCallbackF(Patch_SquareBevel) );
794 // GlobalCommands_insert( "PatchSquareEndcap", makeCallbackF(Patch_SquareEndcap) );
795 GlobalCommands_insert( "PatchCone", makeCallbackF(Patch_Cone) );
796 GlobalCommands_insert( "PatchSphere", makeCallbackF(Patch_Sphere) );
797 GlobalCommands_insert( "SimplePatchMesh", makeCallbackF(Patch_Plane), Accelerator( 'P', (GdkModifierType)GDK_SHIFT_MASK ) );
798 GlobalCommands_insert( "PatchInsertFirstColumn", makeCallbackF(Patch_InsertFirstColumn), Accelerator( GDK_KEY_KP_Add, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
799 GlobalCommands_insert( "PatchInsertLastColumn", makeCallbackF(Patch_InsertLastColumn) );
800 GlobalCommands_insert( "PatchInsertFirstRow", makeCallbackF(Patch_InsertFirstRow), Accelerator( GDK_KEY_KP_Add, (GdkModifierType)GDK_CONTROL_MASK ) );
801 GlobalCommands_insert( "PatchInsertLastRow", makeCallbackF(Patch_InsertLastRow) );
802 GlobalCommands_insert( "PatchDeleteFirstColumn", makeCallbackF(Patch_DeleteFirstColumn) );
803 GlobalCommands_insert( "PatchDeleteLastColumn", makeCallbackF(Patch_DeleteLastColumn), Accelerator( GDK_KEY_KP_Subtract, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
804 GlobalCommands_insert( "PatchDeleteFirstRow", makeCallbackF(Patch_DeleteFirstRow), Accelerator( GDK_KEY_KP_Subtract, (GdkModifierType)GDK_CONTROL_MASK ) );
805 GlobalCommands_insert( "PatchDeleteLastRow", makeCallbackF(Patch_DeleteLastRow) );
806 GlobalCommands_insert( "InvertCurve", makeCallbackF(Patch_Invert), Accelerator( 'I', (GdkModifierType)GDK_CONTROL_MASK ) );
807 GlobalCommands_insert( "RedisperseRows", makeCallbackF(Patch_RedisperseRows), Accelerator( 'E', (GdkModifierType)GDK_CONTROL_MASK ) );
808 GlobalCommands_insert( "RedisperseCols", makeCallbackF(Patch_RedisperseCols), Accelerator( 'E', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
809 GlobalCommands_insert( "SmoothRows", makeCallbackF(Patch_SmoothRows), Accelerator( 'W', (GdkModifierType)GDK_CONTROL_MASK ) );
810 GlobalCommands_insert( "SmoothCols", makeCallbackF(Patch_SmoothCols), Accelerator( 'W', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
811 GlobalCommands_insert( "MatrixTranspose", makeCallbackF(Patch_Transpose), Accelerator( 'M', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
812 GlobalCommands_insert( "CapCurrentCurve", makeCallbackF(Patch_Cap), Accelerator( 'C', (GdkModifierType)GDK_SHIFT_MASK ) );
813 GlobalCommands_insert( "CycleCapTexturePatch", makeCallbackF(Patch_CycleProjection), Accelerator( 'N', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
814 // GlobalCommands_insert( "MakeOverlayPatch", makeCallbackF(Patch_OverlayOn), Accelerator( 'Y' ) );
815 // GlobalCommands_insert( "ClearPatchOverlays", makeCallbackF(Patch_OverlayOff), Accelerator( 'L', (GdkModifierType)GDK_CONTROL_MASK ) );
816 GlobalCommands_insert( "PatchDeform", makeCallbackF(Patch_Deform) );
817 GlobalCommands_insert( "PatchThicken", makeCallbackF(Patch_Thicken), Accelerator( 'T', (GdkModifierType)GDK_CONTROL_MASK ) );
820 void Patch_constructToolbar( ui::Toolbar toolbar ){
821 toolbar_append_button( toolbar, "Put caps on the current patch (SHIFT + C)", "cap_curve.png", "CapCurrentCurve" );
824 void Patch_constructMenu( ui::Menu menu ){
825 create_menu_item_with_mnemonic( menu, "Simple Patch Mesh...", "SimplePatchMesh" );
826 create_menu_item_with_mnemonic( menu, "Bevel", "PatchBevel" );
827 create_menu_item_with_mnemonic( menu, "End cap", "PatchEndCap" );
828 create_menu_item_with_mnemonic( menu, "Cylinder (9x3)", "PatchCylinder" );
829 create_menu_item_with_mnemonic( menu, "Square Cylinder (9x3)", "PatchSquareCylinder" );
830 create_menu_item_with_mnemonic( menu, "Exact Cylinder...", "PatchXactCylinder" );
831 create_menu_item_with_mnemonic( menu, "Cone (9x3)", "PatchCone" );
832 create_menu_item_with_mnemonic( menu, "Exact Cone...", "PatchXactCone" );
833 create_menu_item_with_mnemonic( menu, "Sphere (9x5)", "PatchSphere" );
834 create_menu_item_with_mnemonic( menu, "Exact Sphere...", "PatchXactSphere" );
836 // ui::Menu menu_in_menu = create_sub_menu_with_mnemonic( menu, "More Cylinders" );
837 // if ( g_Layout_enableDetachableMenus.m_value ) {
838 // menu_tearoff( menu_in_menu );
840 // create_menu_item_with_mnemonic( menu_in_menu, "Dense Cylinder", "PatchDenseCylinder" );
841 // create_menu_item_with_mnemonic( menu_in_menu, "Very Dense Cylinder", "PatchVeryDenseCylinder" );
842 // create_menu_item_with_mnemonic( menu_in_menu, "Square Cylinder", "PatchSquareCylinder" );
846 // create_menu_item_with_mnemonic( menu, "Square Endcap", "PatchSquareBevel" );
847 // create_menu_item_with_mnemonic( menu, "Square Bevel", "PatchSquareEndcap" );
849 menu_separator( menu );
850 create_menu_item_with_mnemonic( menu, "Cap Selection", "CapCurrentCurve" );
851 menu_separator( menu );
853 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Insert/Delete" );
854 if ( g_Layout_enableDetachableMenus.m_value ) {
855 menu_tearoff( menu_in_menu );
857 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) First Columns", "PatchInsertFirstColumn" );
858 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Last Columns", "PatchInsertLastColumn" );
859 menu_separator( menu_in_menu );
860 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) First Rows", "PatchInsertFirstRow" );
861 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Last Rows", "PatchInsertLastRow" );
862 menu_separator( menu_in_menu );
863 create_menu_item_with_mnemonic( menu_in_menu, "Del First (2) Columns", "PatchDeleteFirstColumn" );
864 create_menu_item_with_mnemonic( menu_in_menu, "Del Last (2) Columns", "PatchDeleteLastColumn" );
865 menu_separator( menu_in_menu );
866 create_menu_item_with_mnemonic( menu_in_menu, "Del First (2) Rows", "PatchDeleteFirstRow" );
867 create_menu_item_with_mnemonic( menu_in_menu, "Del Last (2) Rows", "PatchDeleteLastRow" );
869 menu_separator( menu );
871 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Matrix" );
872 if ( g_Layout_enableDetachableMenus.m_value ) {
873 menu_tearoff( menu_in_menu );
875 create_menu_item_with_mnemonic( menu_in_menu, "Invert", "InvertCurve" );
876 create_menu_item_with_mnemonic( menu_in_menu, "Transpose", "MatrixTranspose" );
878 menu_separator( menu_in_menu );
879 create_menu_item_with_mnemonic( menu_in_menu, "Re-disperse Rows", "RedisperseRows" );
880 create_menu_item_with_mnemonic( menu_in_menu, "Re-disperse Columns", "RedisperseCols" );
882 menu_separator( menu_in_menu );
883 create_menu_item_with_mnemonic( menu_in_menu, "Smooth Rows", "SmoothRows" );
884 create_menu_item_with_mnemonic( menu_in_menu, "Smooth Columns", "SmoothCols" );
886 menu_separator( menu );
888 auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Texture" );
889 if ( g_Layout_enableDetachableMenus.m_value ) {
890 menu_tearoff( menu_in_menu );
892 create_menu_item_with_mnemonic( menu_in_menu, "Cycle Projection", "CycleCapTexturePatch" );
893 create_menu_item_with_mnemonic( menu_in_menu, "Naturalize", "NaturalizePatch" );
894 create_menu_item_with_mnemonic( menu_in_menu, "Invert X", "InvertCurveTextureX" );
895 create_menu_item_with_mnemonic( menu_in_menu, "Invert Y", "InvertCurveTextureY" );
898 // menu_separator( menu );
900 // auto menu_in_menu = create_sub_menu_with_mnemonic( menu, "Overlay" );
901 // if ( g_Layout_enableDetachableMenus.m_value ) {
902 // menu_tearoff( menu_in_menu );
904 // create_menu_item_with_mnemonic( menu_in_menu, "Set", "MakeOverlayPatch" );
905 // create_menu_item_with_mnemonic( menu_in_menu, "Clear", "ClearPatchOverlays" );
907 menu_separator( menu );
908 create_menu_item_with_mnemonic( menu, "Deform...", "PatchDeform" );
909 create_menu_item_with_mnemonic( menu, "Thicken...", "PatchThicken" );
913 #include "gtkutil/dialog.h"
914 #include "gtkutil/widget.h"
916 void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols ){
918 GtkWidget* redisperseCheckBox;
920 ui::Window window = MainFrame_getWindow().create_dialog_window("Patch density", G_CALLBACK(dialog_delete_callback ), &dialog );
922 auto accel = ui::AccelGroup(ui::New);
923 window.add_accel_group( accel );
924 auto width = ui::ComboBoxText(ui::New);
925 auto height = ui::ComboBoxText(ui::New);
927 auto hbox = create_dialog_hbox( 4, 4 );
930 auto table = create_dialog_table( 3, 2, 4, 4 );
931 hbox.pack_start( table, TRUE, TRUE, 0 );
933 auto label = ui::Label( "Width:" );
935 table.attach(label, {0, 1, 0, 1}, {GTK_FILL, 0});
936 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
939 auto label = ui::Label( "Height:" );
941 table.attach(label, {0, 1, 1, 2}, {GTK_FILL, 0});
942 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
947 #define D_ITEM( x ) if ( x >= mincols && ( !maxcols || x <= maxcols ) ) gtk_combo_box_text_append_text( combo, #x )
962 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
965 table.attach(combo, {1, 2, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
969 #define D_ITEM( x ) if ( x >= minrows && ( !maxrows || x <= maxrows ) ) gtk_combo_box_text_append_text( combo, #x )
984 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
987 table.attach(combo, {1, 2, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
990 if( prefab != ePlane ){
991 GtkWidget* _redisperseCheckBox = gtk_check_button_new_with_label( "Square" );
992 gtk_widget_set_tooltip_text( _redisperseCheckBox, "Redisperse columns & rows" );
993 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( _redisperseCheckBox ), FALSE );
994 gtk_widget_show( _redisperseCheckBox );
995 gtk_table_attach( table, _redisperseCheckBox, 0, 2, 2, 3,
996 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
997 (GtkAttachOptions) ( 0 ), 0, 0 );
998 redisperseCheckBox = _redisperseCheckBox;
1004 auto vbox = create_dialog_vbox( 4 );
1005 hbox.pack_start( vbox, TRUE, TRUE, 0 );
1007 auto button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
1008 vbox.pack_start( button, FALSE, FALSE, 0 );
1009 widget_make_default( button );
1010 gtk_widget_grab_focus( button );
1011 gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
1014 auto button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
1015 vbox.pack_start( button, FALSE, FALSE, 0 );
1016 gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
1021 // Initialize dialog
1022 gtk_combo_box_set_active( width, ( defcols - mincols ) / 2 );
1023 gtk_combo_box_set_active( height, ( defrows - minrows ) / 2 );
1025 if ( modal_dialog_show( window, dialog ) == eIDOK ) {
1026 int w = gtk_combo_box_get_active( width ) * 2 + mincols;
1027 int h = gtk_combo_box_get_active( height ) * 2 + minrows;
1028 bool redisperse = false;
1029 if( prefab != ePlane ){
1030 redisperse = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( redisperseCheckBox ) ) ? true : false;
1032 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), prefab, GlobalXYWnd_getCurrentViewType(), w, h, redisperse );
1039 void DoPatchDeformDlg(){
1046 ui::Window window = create_dialog_window( MainFrame_getWindow(), "Patch deform", G_CALLBACK( dialog_delete_callback ), &dialog );
1048 GtkAccelGroup* accel = gtk_accel_group_new();
1049 gtk_window_add_accel_group( window, accel );
1052 auto hbox = create_dialog_hbox( 4, 4 );
1053 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
1055 auto table = create_dialog_table( 2, 2, 4, 4 );
1056 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
1058 GtkLabel* label = GTK_LABEL( gtk_label_new( "Max deform:" ) );
1059 gtk_widget_show( GTK_WIDGET( label ) );
1060 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
1061 (GtkAttachOptions) ( GTK_FILL ),
1062 (GtkAttachOptions) ( 0 ), 0, 0 );
1063 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1066 // GtkWidget* entry = gtk_entry_new();
1067 // gtk_entry_set_text( GTK_ENTRY( entry ), "64" );
1068 // gtk_widget_show( entry );
1069 // gtk_table_attach( table, entry, 1, 2, 0, 1,
1070 // (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1071 // (GtkAttachOptions) ( 0 ), 0, 0 );
1076 GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 64, -9999, 9999, 1, 10, 0 ) );
1077 //GtkSpinButton* spin = GTK_SPIN_BUTTON( gtk_spin_button_new( adj, 1, 0 ) );
1078 GtkWidget* spin = gtk_spin_button_new( adj, 1, 0 );
1079 gtk_widget_show( spin );
1080 gtk_table_attach( table, spin, 1, 2, 0, 1,
1081 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1082 (GtkAttachOptions) ( 0 ), 0, 0 );
1083 gtk_widget_set_size_request( spin, 64, -1 );
1084 gtk_spin_button_set_numeric( GTK_SPIN_BUTTON( spin ), TRUE );
1089 // Create the radio button group for choosing the axis
1090 GtkWidget* _rndZ = gtk_radio_button_new_with_label_from_widget( NULL, "Z" );
1091 GtkWidget* _rndY = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_rndZ), "Y" );
1092 GtkWidget* _rndX = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_rndZ), "X" );
1093 gtk_widget_show( _rndZ );
1094 gtk_widget_show( _rndY );
1095 gtk_widget_show( _rndX );
1098 GtkHBox* _hbox = create_dialog_hbox( 4, 4 );
1099 gtk_table_attach( table, GTK_WIDGET( _hbox ), 0, 2, 1, 2,
1100 (GtkAttachOptions) ( GTK_FILL ),
1101 (GtkAttachOptions) ( 0 ), 0, 0 );
1102 gtk_box_pack_start( GTK_BOX( _hbox ), GTK_WIDGET( _rndX ), TRUE, TRUE, 0 );
1103 gtk_box_pack_start( GTK_BOX( _hbox ), GTK_WIDGET( _rndY ), TRUE, TRUE, 0 );
1104 gtk_box_pack_start( GTK_BOX( _hbox ), GTK_WIDGET( _rndZ ), TRUE, TRUE, 0 );
1111 auto vbox = create_dialog_vbox( 4 );
1112 hbox.pack_start( vbox, FALSE, FALSE, 0 );
1114 auto button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
1115 vbox.pack_start( button, FALSE, FALSE, 0 );
1116 widget_make_default( button );
1117 gtk_widget_grab_focus( button );
1118 gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
1121 auto button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
1122 vbox.pack_start( button, FALSE, FALSE, 0 );
1123 gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
1128 if ( modal_dialog_show( window, dialog ) == eIDOK ) {
1129 //int deform = static_cast<int>( atoi( gtk_entry_get_text( GTK_ENTRY( deformW ) ) ) );
1130 gtk_spin_button_update ( GTK_SPIN_BUTTON( deformW ) );
1131 int deform = static_cast<int>( gtk_spin_button_get_value( GTK_SPIN_BUTTON( deformW ) ) );
1133 if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( rndX ) ) ){
1136 else if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( rndY ) ) ){
1139 Scene_PatchDeform( GlobalSceneGraph(), deform, axis );
1141 gtk_widget_destroy( GTK_WIDGET( window ) );
1146 EMessageBoxReturn DoCapDlg( ECapDialog* type ){
1148 ModalDialogButton ok_button( dialog, eIDOK );
1149 ModalDialogButton cancel_button( dialog, eIDCANCEL );
1150 ui::Widget bevel{ui::null};
1151 ui::Widget ibevel{ui::null};
1152 ui::Widget endcap{ui::null};
1153 ui::Widget iendcap{ui::null};
1154 ui::Widget cylinder{ui::null};
1156 ui::Window window = MainFrame_getWindow().create_modal_dialog_window( "Cap", dialog );
1158 auto accel_group = ui::AccelGroup(ui::New);
1159 window.add_accel_group( accel_group );
1162 auto hbox = create_dialog_hbox( 4, 4 );
1166 // Gef: Added a vbox to contain the toggle buttons
1167 auto radio_vbox = create_dialog_vbox( 4 );
1168 hbox.add(radio_vbox);
1171 auto table = ui::Table( 5, 2, FALSE );
1173 radio_vbox.pack_start( table, TRUE, TRUE, 0 );
1174 gtk_table_set_row_spacings( table, 5 );
1175 gtk_table_set_col_spacings( table, 5 );
1178 auto image = new_local_image( "cap_bevel.png" );
1180 table.attach(image, {0, 1, 0, 1}, {GTK_FILL, 0});
1183 auto image = new_local_image( "cap_endcap.png" );
1185 table.attach(image, {0, 1, 1, 2}, {GTK_FILL, 0});
1188 auto image = new_local_image( "cap_ibevel.png" );
1190 table.attach(image, {0, 1, 2, 3}, {GTK_FILL, 0});
1193 auto image = new_local_image( "cap_iendcap.png" );
1195 table.attach(image, {0, 1, 3, 4}, {GTK_FILL, 0});
1198 auto image = new_local_image( "cap_cylinder.png" );
1200 table.attach(image, {0, 1, 4, 5}, {GTK_FILL, 0});
1205 ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Bevel" ));
1207 table.attach(button, {1, 2, 0, 1}, {GTK_FILL | GTK_EXPAND, 0});
1208 group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
1213 ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Endcap" ));
1215 table.attach(button, {1, 2, 1, 2}, {GTK_FILL | GTK_EXPAND, 0});
1216 group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
1221 ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Inverted Bevel" ));
1223 table.attach(button, {1, 2, 2, 3}, {GTK_FILL | GTK_EXPAND, 0});
1224 group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
1229 ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Inverted Endcap" ));
1231 table.attach(button, {1, 2, 3, 4}, {GTK_FILL | GTK_EXPAND, 0});
1232 group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
1237 ui::Widget button = ui::Widget::from(gtk_radio_button_new_with_label( group, "Cylinder" ));
1239 table.attach(button, {1, 2, 4, 5}, {GTK_FILL | GTK_EXPAND, 0});
1240 group = gtk_radio_button_get_group( GTK_RADIO_BUTTON( button ) );
1248 auto vbox = create_dialog_vbox( 4 );
1249 hbox.pack_start( vbox, FALSE, FALSE, 0 );
1251 auto button = create_modal_dialog_button( "OK", ok_button );
1252 vbox.pack_start( button, FALSE, FALSE, 0 );
1253 widget_make_default( button );
1254 gtk_widget_add_accelerator( button , "clicked", accel_group, GDK_KEY_Return, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
1257 auto button = create_modal_dialog_button( "Cancel", cancel_button );
1258 vbox.pack_start( button, FALSE, FALSE, 0 );
1259 gtk_widget_add_accelerator( button , "clicked", accel_group, GDK_KEY_Escape, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
1264 // Initialize dialog
1265 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( bevel ), TRUE );
1267 EMessageBoxReturn ret = modal_dialog_show( window, dialog );
1268 if ( ret == eIDOK ) {
1269 if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( bevel ) ) ) {
1270 *type = PATCHCAP_BEVEL;
1272 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( endcap ) ) ) {
1273 *type = PATCHCAP_ENDCAP;
1275 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( ibevel ) ) ) {
1276 *type = PATCHCAP_INVERTED_BEVEL;
1278 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( iendcap ) ) ) {
1279 *type = PATCHCAP_INVERTED_ENDCAP;
1281 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( cylinder ) ) ) {
1282 *type = PATCHCAP_CYLINDER;
1292 void DoPatchThickenDlg(){
1294 GtkWidget* thicknessW;
1300 ui::Window window = create_dialog_window( MainFrame_getWindow(), "Patch thicken", G_CALLBACK( dialog_delete_callback ), &dialog );
1302 GtkAccelGroup* accel = gtk_accel_group_new();
1303 gtk_window_add_accel_group( window, accel );
1306 auto hbox = create_dialog_hbox( 4, 4 );
1307 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
1309 auto table = create_dialog_table( 2, 4, 4, 4 );
1310 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
1312 GtkLabel* label = GTK_LABEL( gtk_label_new( "Thickness:" ) );
1313 gtk_widget_show( GTK_WIDGET( label ) );
1314 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
1315 (GtkAttachOptions) ( GTK_FILL ),
1316 (GtkAttachOptions) ( 0 ), 0, 0 );
1317 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1320 // GtkWidget* entry = gtk_entry_new();
1321 // gtk_entry_set_text( GTK_ENTRY( entry ), "16" );
1322 // gtk_widget_set_size_request( entry, 40, -1 );
1323 // gtk_widget_show( entry );
1324 // gtk_table_attach( table, entry, 1, 2, 0, 1,
1325 // (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1326 // (GtkAttachOptions) ( 0 ), 0, 0 );
1328 // thicknessW = entry;
1331 GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 16, -9999, 9999, 1, 10, 0 ) );
1332 GtkWidget* spin = gtk_spin_button_new( adj, 1, 0 );
1333 gtk_widget_show( spin );
1334 gtk_table_attach( table, spin, 1, 2, 0, 1,
1335 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1336 (GtkAttachOptions) ( 0 ), 0, 0 );
1337 gtk_widget_set_size_request( spin, 48, -1 );
1338 gtk_spin_button_set_numeric( GTK_SPIN_BUTTON( spin ), TRUE );
1343 // Create the "create seams" label
1344 GtkWidget* _seamsCheckBox = gtk_check_button_new_with_label( "Side walls" );
1345 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( _seamsCheckBox ), TRUE );
1346 gtk_widget_show( _seamsCheckBox );
1347 gtk_table_attach( table, _seamsCheckBox, 2, 4, 0, 1,
1348 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1349 (GtkAttachOptions) ( 0 ), 0, 0 );
1350 seamsW = _seamsCheckBox;
1354 // Create the radio button group for choosing the extrude axis
1355 GtkWidget* _radNormals = gtk_radio_button_new_with_label( NULL, "Normal" );
1356 GtkWidget* _radX = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "X" );
1357 GtkWidget* _radY = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "Y" );
1358 GtkWidget* _radZ = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "Z" );
1359 gtk_widget_show( _radNormals );
1360 gtk_widget_show( _radX );
1361 gtk_widget_show( _radY );
1362 gtk_widget_show( _radZ );
1365 // Pack the buttons into the table
1366 gtk_table_attach( table, _radNormals, 0, 1, 1, 2,
1367 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1368 (GtkAttachOptions) ( 0 ), 0, 0 );
1369 gtk_table_attach( table, _radX, 1, 2, 1, 2,
1370 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1371 (GtkAttachOptions) ( 0 ), 0, 0 );
1372 gtk_table_attach( table, _radY, 2, 3, 1, 2,
1373 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1374 (GtkAttachOptions) ( 0 ), 0, 0 );
1375 gtk_table_attach( table, _radZ, 3, 4, 1, 2,
1376 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1377 (GtkAttachOptions) ( 0 ), 0, 0 );
1384 auto vbox = create_dialog_vbox( 4 );
1385 hbox.pack_start( vbox, FALSE, FALSE, 0 );
1387 auto button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
1388 vbox.pack_start( button, FALSE, FALSE, 0 );
1389 widget_make_default( button );
1390 gtk_widget_grab_focus( button );
1391 gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
1394 auto button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
1395 vbox.pack_start( button, FALSE, FALSE, 0 );
1396 gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
1401 if ( modal_dialog_show( window, dialog ) == eIDOK ) {
1402 int axis = 3; // Extrude along normals
1404 //float thickness = static_cast<float>( atoi( gtk_entry_get_text( GTK_ENTRY( thicknessW ) ) ) );
1405 gtk_spin_button_update ( GTK_SPIN_BUTTON( thicknessW ) );
1406 float thickness = static_cast<float>( gtk_spin_button_get_value( GTK_SPIN_BUTTON( thicknessW ) ) );
1407 seams = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( seamsW )) ? true : false;
1409 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radX))) {
1412 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radY))) {
1415 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radZ))) {
1419 Scene_PatchThicken( GlobalSceneGraph(), thickness, seams, axis );
1422 gtk_widget_destroy( GTK_WIDGET( window ) );