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"
24 #include "debugging/debugging.h"
27 #include "iselection.h"
30 #include "math/vector.h"
31 #include "math/aabb.h"
32 #include "generic/callback.h"
34 #include "gtkutil/menu.h"
35 #include "gtkutil/image.h"
37 #include "mainframe.h"
41 #include "texwindow.h"
47 PatchCreator* g_patchCreator = 0;
49 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 ){
51 GlobalSelectionSystem().setSelectedAll( false );
53 NodeSmartReference node( g_patchCreator->createPatch() );
54 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
56 Patch* patch = Node_getPatch( node );
57 patch->SetShader( shader );
59 patch->ConstructPrefab( aabb, eType, axis, width, height );
61 patch->Redisperse( COL );
62 patch->Redisperse( ROW );
64 patch->controlPointsChanged();
67 scene::Path patchpath( makeReference( GlobalSceneGraph().root() ) );
68 patchpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
69 patchpath.push( makeReference( node.get() ) );
70 Instance_getSelectable( *graph.find( patchpath ) )->setSelected( true );
75 void Patch_makeCaps( Patch& patch, scene::Instance& instance, EPatchCap type, const char* shader ){
76 if ( ( type == eCapEndCap || type == eCapIEndCap )
77 && patch.getWidth() != 5 ) {
78 globalErrorStream() << "cannot create end-cap - patch width != 5\n";
81 if ( ( type == eCapBevel || type == eCapIBevel )
82 && patch.getWidth() != 3 && patch.getWidth() != 5 ) {
83 globalErrorStream() << "cannot create bevel-cap - patch width != 3\n";
86 if ( type == eCapCylinder
87 && patch.getWidth() != 9 ) {
88 globalErrorStream() << "cannot create cylinder-cap - patch width != 9\n";
93 NodeSmartReference cap( g_patchCreator->createPatch() );
94 Node_getTraversable( instance.path().parent() )->insert( cap );
96 patch.MakeCap( Node_getPatch( cap ), type, ROW, true );
97 Node_getPatch( cap )->SetShader( shader );
99 scene::Path path( instance.path() );
101 path.push( makeReference( cap.get() ) );
102 selectPath( path, true );
106 NodeSmartReference cap( g_patchCreator->createPatch() );
107 Node_getTraversable( instance.path().parent() )->insert( cap );
109 patch.MakeCap( Node_getPatch( cap ), type, ROW, false );
110 Node_getPatch( cap )->SetShader( shader );
112 scene::Path path( instance.path() );
114 path.push( makeReference( cap.get() ) );
115 selectPath( path, true );
120 typedef std::vector<scene::Instance*> InstanceVector;
122 class PatchStoreInstance
124 InstanceVector& m_instances;
126 PatchStoreInstance( InstanceVector& instances ) : m_instances( instances ){
128 void operator()( PatchInstance& patch ) const {
129 m_instances.push_back( &patch );
136 PATCHCAP_INVERTED_BEVEL,
137 PATCHCAP_INVERTED_ENDCAP,
141 EMessageBoxReturn DoCapDlg( ECapDialog *type );
143 void Scene_PatchDoCap_Selected( scene::Graph& graph, const char* shader ){
146 if ( DoCapDlg( &nType ) == eIDOK ) {
150 case PATCHCAP_INVERTED_BEVEL:
156 case PATCHCAP_INVERTED_ENDCAP:
159 case PATCHCAP_ENDCAP:
162 case PATCHCAP_CYLINDER:
163 eType = eCapCylinder;
166 ERROR_MESSAGE( "invalid patch cap type" );
170 InstanceVector instances;
171 Scene_forEachVisibleSelectedPatchInstance( PatchStoreInstance( instances ) );
172 for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
174 Patch_makeCaps( *Node_getPatch( ( *i )->path().top() ), *( *i ), eType, shader );
179 void Patch_deform( Patch& patch, scene::Instance& instance, const int deform, const int axis ){
182 for ( PatchControlIter i = patch.begin(); i != patch.end(); ++i ){
183 PatchControl& control = *i;
184 int randomNumber = int( deform * ( float( std::rand() ) / float( RAND_MAX ) ) );
185 control.m_vertex[ axis ] += randomNumber;
188 patch.controlPointsChanged();
191 void Scene_PatchDeform( scene::Graph& graph, const int deform, const int axis )
193 InstanceVector instances;
194 Scene_forEachVisibleSelectedPatchInstance( PatchStoreInstance( instances ) );
195 for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
197 Patch_deform( *Node_getPatch( ( *i )->path().top() ), *( *i ), deform, axis );
202 void Patch_thicken( Patch& patch, scene::Instance& instance, const float thickness, bool seams, const int axis ){
204 // Create a new patch node
205 NodeSmartReference node( g_patchCreator->createPatch() );
206 // Insert the node into worldspawn
207 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
209 // Retrieve the contained patch from the node
210 Patch* targetPatch = Node_getPatch( node );
212 // Create the opposite patch with the given thickness = distance
215 targetPatch->createThickenedOpposite( patch, thickness, axis, no12, no34 );
217 // Now select the newly created patches
219 scene::Path patchpath( makeReference( GlobalSceneGraph().root() ) );
220 patchpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
221 patchpath.push( makeReference( node.get() ) );
222 Instance_getSelectable( *GlobalSceneGraph().find( patchpath ) )->setSelected( true );
225 if( seams && thickness != 0.0f){
234 // Now create the four walls
235 for ( ; i < iend; i++ ){
236 // Allocate new patch
237 NodeSmartReference node = NodeSmartReference( g_patchCreator->createPatch() );
238 // Insert each node into worldspawn
239 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
241 // Retrieve the contained patch from the node
242 Patch* wallPatch = Node_getPatch( node );
244 // Create the wall patch by passing i as wallIndex
245 wallPatch->createThickenedWall( patch, *targetPatch, i );
247 if( ( wallPatch->localAABB().extents[0] <= 0.00005 && wallPatch->localAABB().extents[1] <= 0.00005 ) ||
248 ( wallPatch->localAABB().extents[1] <= 0.00005 && wallPatch->localAABB().extents[2] <= 0.00005 ) ||
249 ( wallPatch->localAABB().extents[0] <= 0.00005 && wallPatch->localAABB().extents[2] <= 0.00005 ) ){
250 //globalOutputStream() << "Thicken: Discarding degenerate patch.\n";
251 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->erase( node );
254 // Now select the newly created patches
256 scene::Path patchpath( makeReference( GlobalSceneGraph().root() ) );
257 patchpath.push( makeReference( *Map_GetWorldspawn(g_map) ) );
258 patchpath.push( makeReference( node.get() ) );
259 Instance_getSelectable( *GlobalSceneGraph().find( patchpath ) )->setSelected( true );
264 // Invert the target patch so that it faces the opposite direction
265 targetPatch->InvertMatrix();
268 void Scene_PatchThicken( scene::Graph& graph, const int thickness, bool seams, const int axis )
270 InstanceVector instances;
271 Scene_forEachVisibleSelectedPatchInstance( PatchStoreInstance( instances ) );
272 for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
274 Patch_thicken( *Node_getPatch( ( *i )->path().top() ), *( *i ), thickness, seams, axis );
279 Patch* Scene_GetUltimateSelectedVisiblePatch(){
280 if ( GlobalSelectionSystem().countSelected() != 0 ) {
281 scene::Node& node = GlobalSelectionSystem().ultimateSelected().path().top();
282 if ( node.visible() ) {
283 return Node_getPatch( node );
290 class PatchCapTexture
293 void operator()( Patch& patch ) const {
294 patch.ProjectTexture( Patch::m_CycleCapIndex );
298 void Scene_PatchCapTexture_Selected( scene::Graph& graph ){
299 Scene_forEachVisibleSelectedPatch( PatchCapTexture() );
300 Patch::m_CycleCapIndex = ( Patch::m_CycleCapIndex == 0 ) ? 1 : ( Patch::m_CycleCapIndex == 1 ) ? 2 : 0;
304 class PatchFlipTexture
308 PatchFlipTexture( int axis ) : m_axis( axis ){
310 void operator()( Patch& patch ) const {
311 patch.FlipTexture( m_axis );
315 void Scene_PatchFlipTexture_Selected( scene::Graph& graph, int axis ){
316 Scene_forEachVisibleSelectedPatch( PatchFlipTexture( axis ) );
319 class PatchNaturalTexture
322 void operator()( Patch& patch ) const {
323 patch.NaturalTexture();
327 void Scene_PatchNaturalTexture_Selected( scene::Graph& graph ){
328 Scene_forEachVisibleSelectedPatch( PatchNaturalTexture() );
333 class PatchInsertRemove
335 bool m_insert, m_column, m_first;
337 PatchInsertRemove( bool insert, bool column, bool first ) : m_insert( insert ), m_column( column ), m_first( first ){
339 void operator()( Patch& patch ) const {
340 patch.InsertRemove( m_insert, m_column, m_first );
344 void Scene_PatchInsertRemove_Selected( scene::Graph& graph, bool bInsert, bool bColumn, bool bFirst ){
345 Scene_forEachVisibleSelectedPatch( PatchInsertRemove( bInsert, bColumn, bFirst ) );
348 class PatchInvertMatrix
351 void operator()( Patch& patch ) const {
352 patch.InvertMatrix();
356 void Scene_PatchInvert_Selected( scene::Graph& graph ){
357 Scene_forEachVisibleSelectedPatch( PatchInvertMatrix() );
360 class PatchRedisperse
362 EMatrixMajor m_major;
364 PatchRedisperse( EMatrixMajor major ) : m_major( major ){
366 void operator()( Patch& patch ) const {
367 patch.Redisperse( m_major );
371 void Scene_PatchRedisperse_Selected( scene::Graph& graph, EMatrixMajor major ){
372 Scene_forEachVisibleSelectedPatch( PatchRedisperse( major ) );
377 EMatrixMajor m_major;
379 PatchSmooth( EMatrixMajor major ) : m_major( major ){
381 void operator()( Patch& patch ) const {
382 patch.Smooth( m_major );
386 void Scene_PatchSmooth_Selected( scene::Graph& graph, EMatrixMajor major ){
387 Scene_forEachVisibleSelectedPatch( PatchSmooth( major ) );
390 class PatchTransposeMatrix
393 void operator()( Patch& patch ) const {
394 patch.TransposeMatrix();
398 void Scene_PatchTranspose_Selected( scene::Graph& graph ){
399 Scene_forEachVisibleSelectedPatch( PatchTransposeMatrix() );
406 PatchSetShader( const char* name )
409 void operator()( Patch& patch ) const {
410 patch.SetShader( m_name );
414 void Scene_PatchSetShader_Selected( scene::Graph& graph, const char* name ){
415 Scene_forEachVisibleSelectedPatch( PatchSetShader( name ) );
419 void Scene_PatchGetShader_Selected( scene::Graph& graph, CopiedString& name ){
420 Patch* patch = Scene_GetUltimateSelectedVisiblePatch();
422 name = patch->GetShader();
426 class PatchSelectByShader
430 inline PatchSelectByShader( const char* name )
433 void operator()( PatchInstance& patch ) const {
434 if ( shader_equal( patch.getPatch().GetShader(), m_name ) ) {
435 patch.setSelected( true );
440 void Scene_PatchSelectByShader( scene::Graph& graph, const char* name ){
441 Scene_forEachVisiblePatchInstance( PatchSelectByShader( name ) );
445 class PatchFindReplaceShader
448 const char* m_replace;
450 PatchFindReplaceShader( const char* find, const char* replace ) : m_find( find ), m_replace( replace ){
452 void operator()( Patch& patch ) const {
453 if ( shader_equal( patch.GetShader(), m_find ) ) {
454 patch.SetShader( m_replace );
460 bool DoingSearch( const char *repl ){
461 return ( repl == NULL || ( strcmp( "textures/", repl ) == 0 ) );
464 void Scene_PatchFindReplaceShader( scene::Graph& graph, const char* find, const char* replace ){
465 if( DoingSearch( replace ) ){
466 Scene_forEachVisiblePatchInstance( PatchSelectByShader( find ) );
469 Scene_forEachVisiblePatch( PatchFindReplaceShader( find, replace ) );
473 void Scene_PatchFindReplaceShader_Selected( scene::Graph& graph, const char* find, const char* replace ){
474 if( DoingSearch( replace ) ){
475 //do nothing, because alternative is replacing to notex
476 //perhaps deselect ones with not matching shaders here?
479 Scene_forEachVisibleSelectedPatch( PatchFindReplaceShader( find, replace ) );
484 AABB PatchCreator_getBounds(){
485 AABB aabb( aabb_for_minmax( Select_getWorkZone().d_work_min, Select_getWorkZone().d_work_max ) );
487 float gridSize = GetGridSize();
489 if ( aabb.extents[0] == 0 ) {
490 aabb.extents[0] = gridSize;
492 if ( aabb.extents[1] == 0 ) {
493 aabb.extents[1] = gridSize;
495 if ( aabb.extents[2] == 0 ) {
496 aabb.extents[2] = gridSize;
499 if ( aabb_valid( aabb ) ) {
502 return AABB( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
505 void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols );
507 void Patch_XactCylinder(){
508 UndoableCommand undo( "patchCreateXactCylinder" );
510 DoNewPatchDlg( eXactCylinder, 3, 7, 3, 13, 0, 0 );
513 void Patch_XactSphere(){
514 UndoableCommand undo( "patchCreateXactSphere" );
516 DoNewPatchDlg( eXactSphere, 5, 7, 7, 13, 0, 0 );
519 void Patch_XactCone(){
520 UndoableCommand undo( "patchCreateXactCone" );
522 DoNewPatchDlg( eXactCone, 3, 7, 3, 13, 0, 0 );
525 void Patch_Cylinder(){
526 UndoableCommand undo( "patchCreateCylinder" );
528 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eCylinder, GlobalXYWnd_getCurrentViewType() );
531 void Patch_DenseCylinder(){
532 UndoableCommand undo( "patchCreateDenseCylinder" );
534 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eDenseCylinder, GlobalXYWnd_getCurrentViewType() );
537 void Patch_VeryDenseCylinder(){
538 UndoableCommand undo( "patchCreateVeryDenseCylinder" );
540 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eVeryDenseCylinder, GlobalXYWnd_getCurrentViewType() );
543 void Patch_SquareCylinder(){
544 UndoableCommand undo( "patchCreateSquareCylinder" );
546 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eSqCylinder, GlobalXYWnd_getCurrentViewType() );
550 UndoableCommand undo( "patchCreateCaps" );
552 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eEndCap, GlobalXYWnd_getCurrentViewType() );
556 UndoableCommand undo( "patchCreateBevel" );
558 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eBevel, GlobalXYWnd_getCurrentViewType() );
562 UndoableCommand undo( "patchCreateSphere" );
564 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eSphere, GlobalXYWnd_getCurrentViewType() );
567 void Patch_SquareBevel(){
570 void Patch_SquareEndcap(){
574 UndoableCommand undo( "patchCreateCone" );
576 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eCone, GlobalXYWnd_getCurrentViewType() );
580 UndoableCommand undo( "patchCreatePlane" );
582 DoNewPatchDlg( ePlane, 3, 3, 3, 3, 0, 0 );
585 void Patch_InsertFirstColumn(){
586 UndoableCommand undo( "patchInsertFirstColumns" );
588 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, true, true );
591 void Patch_InsertLastColumn(){
592 UndoableCommand undo( "patchInsertLastColumns" );
594 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, true, false );
597 void Patch_InsertFirstRow(){
598 UndoableCommand undo( "patchInsertFirstRows" );
600 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, false, true );
603 void Patch_InsertLastRow(){
604 UndoableCommand undo( "patchInsertLastRows" );
606 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, false, false );
609 void Patch_DeleteFirstColumn(){
610 UndoableCommand undo( "patchDeleteFirstColumns" );
612 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, true, true );
615 void Patch_DeleteLastColumn(){
616 UndoableCommand undo( "patchDeleteLastColumns" );
618 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, true, false );
621 void Patch_DeleteFirstRow(){
622 UndoableCommand undo( "patchDeleteFirstRows" );
624 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, false, true );
627 void Patch_DeleteLastRow(){
628 UndoableCommand undo( "patchDeleteLastRows" );
630 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, false, false );
634 UndoableCommand undo( "patchInvert" );
636 Scene_PatchInvert_Selected( GlobalSceneGraph() );
639 void Patch_RedisperseRows(){
640 UndoableCommand undo( "patchRedisperseRows" );
642 Scene_PatchRedisperse_Selected( GlobalSceneGraph(), ROW );
645 void Patch_RedisperseCols(){
646 UndoableCommand undo( "patchRedisperseColumns" );
648 Scene_PatchRedisperse_Selected( GlobalSceneGraph(), COL );
651 void Patch_SmoothRows(){
652 UndoableCommand undo( "patchSmoothRows" );
654 Scene_PatchSmooth_Selected( GlobalSceneGraph(), ROW );
657 void Patch_SmoothCols(){
658 UndoableCommand undo( "patchSmoothColumns" );
660 Scene_PatchSmooth_Selected( GlobalSceneGraph(), COL );
663 void Patch_Transpose(){
664 UndoableCommand undo( "patchTranspose" );
666 Scene_PatchTranspose_Selected( GlobalSceneGraph() );
670 // FIXME: add support for patch cap creation
671 // Patch_CapCurrent();
672 UndoableCommand undo( "patchCreateCaps" );
674 Scene_PatchDoCap_Selected( GlobalSceneGraph(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
677 void Patch_CycleProjection(){
678 UndoableCommand undo( "patchCycleUVProjectionAxis" );
680 Scene_PatchCapTexture_Selected( GlobalSceneGraph() );
684 void Patch_OverlayOn(){
688 void Patch_OverlayOff(){
691 void Patch_FlipTextureX(){
692 UndoableCommand undo( "patchFlipTextureU" );
694 Scene_PatchFlipTexture_Selected( GlobalSceneGraph(), 0 );
697 void Patch_FlipTextureY(){
698 UndoableCommand undo( "patchFlipTextureV" );
700 Scene_PatchFlipTexture_Selected( GlobalSceneGraph(), 1 );
703 void Patch_NaturalTexture(){
704 UndoableCommand undo( "patchNaturalTexture" );
706 Scene_PatchNaturalTexture_Selected( GlobalSceneGraph() );
709 void Patch_CapTexture(){
710 UndoableCommand command( "patchCapTexture" );
711 Scene_PatchCapTexture_Selected( GlobalSceneGraph() );
714 void Patch_ResetTexture(){
716 if ( DoTextureLayout( &fx, &fy ) == eIDOK ) {
717 UndoableCommand command( "patchTileTexture" );
718 Scene_PatchTileTexture_Selected( GlobalSceneGraph(), fx, fy );
722 void Patch_FitTexture(){
723 UndoableCommand command( "patchFitTexture" );
724 Scene_PatchTileTexture_Selected( GlobalSceneGraph(), 1, 1 );
727 void DoPatchDeformDlg();
730 UndoableCommand undo( "patchDeform" );
735 void DoPatchThickenDlg();
737 void Patch_Thicken(){
738 UndoableCommand undo( "patchThicken" );
748 class filter_patch_all : public PatchFilter
751 bool filter( const Patch& patch ) const {
756 class filter_patch_shader : public PatchFilter
758 const char* m_shader;
760 filter_patch_shader( const char* shader ) : m_shader( shader ){
762 bool filter( const Patch& patch ) const {
763 return shader_equal( patch.GetShader(), m_shader );
767 class filter_patch_flags : public PatchFilter
771 filter_patch_flags( int flags ) : m_flags( flags ){
773 bool filter( const Patch& patch ) const {
774 return ( patch.getShaderFlags() & m_flags ) != 0;
779 filter_patch_all g_filter_patch_all;
780 filter_patch_flags g_filter_patch_clip( QER_CLIP );
781 filter_patch_shader g_filter_patch_commonclip( "textures/common/clip" );
782 filter_patch_shader g_filter_patch_weapclip( "textures/common/weapclip" );
783 filter_patch_flags g_filter_patch_translucent( QER_TRANS | QER_ALPHATEST );
785 void PatchFilters_construct(){
786 add_patch_filter( g_filter_patch_all, EXCLUDE_CURVES );
787 add_patch_filter( g_filter_patch_clip, EXCLUDE_CLIP );
788 add_patch_filter( g_filter_patch_commonclip, EXCLUDE_CLIP );
789 add_patch_filter( g_filter_patch_weapclip, EXCLUDE_CLIP );
790 add_patch_filter( g_filter_patch_translucent, EXCLUDE_TRANSLUCENT );
794 #include "preferences.h"
796 void Patch_constructPreferences( PreferencesPage& page ){
797 page.appendEntry( "Patch Subdivide Threshold", g_PatchSubdivideThreshold );
799 void Patch_constructPage( PreferenceGroup& group ){
800 PreferencesPage page( group.createPage( "Patches", "Patch Display Preferences" ) );
801 Patch_constructPreferences( page );
803 void Patch_registerPreferencesPage(){
804 PreferencesDialog_addDisplayPage( FreeCaller1<PreferenceGroup&, Patch_constructPage>() );
808 #include "preferencesystem.h"
810 void PatchPreferences_construct(){
811 GlobalPreferenceSystem().registerPreference( "Subdivisions", IntImportStringCaller( g_PatchSubdivideThreshold ), IntExportStringCaller( g_PatchSubdivideThreshold ) );
815 #include "generic/callback.h"
817 void Patch_registerCommands(){
818 GlobalCommands_insert( "InvertCurveTextureX", FreeCaller<Patch_FlipTextureX>(), Accelerator( 'I', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
819 GlobalCommands_insert( "InvertCurveTextureY", FreeCaller<Patch_FlipTextureY>(), Accelerator( 'I', (GdkModifierType)GDK_SHIFT_MASK ) );
820 GlobalCommands_insert( "NaturalizePatch", FreeCaller<Patch_NaturalTexture>(), Accelerator( 'N', (GdkModifierType)GDK_CONTROL_MASK ) );
821 GlobalCommands_insert( "PatchCylinder", FreeCaller<Patch_Cylinder>() );
822 // GlobalCommands_insert( "PatchDenseCylinder", FreeCaller<Patch_DenseCylinder>() );
823 // GlobalCommands_insert( "PatchVeryDenseCylinder", FreeCaller<Patch_VeryDenseCylinder>() );
824 GlobalCommands_insert( "PatchSquareCylinder", FreeCaller<Patch_SquareCylinder>() );
825 GlobalCommands_insert( "PatchXactCylinder", FreeCaller<Patch_XactCylinder>() );
826 GlobalCommands_insert( "PatchXactSphere", FreeCaller<Patch_XactSphere>() );
827 GlobalCommands_insert( "PatchXactCone", FreeCaller<Patch_XactCone>() );
828 GlobalCommands_insert( "PatchEndCap", FreeCaller<Patch_Endcap>() );
829 GlobalCommands_insert( "PatchBevel", FreeCaller<Patch_Bevel>() );
830 // GlobalCommands_insert( "PatchSquareBevel", FreeCaller<Patch_SquareBevel>() );
831 // GlobalCommands_insert( "PatchSquareEndcap", FreeCaller<Patch_SquareEndcap>() );
832 GlobalCommands_insert( "PatchCone", FreeCaller<Patch_Cone>() );
833 GlobalCommands_insert( "PatchSphere", FreeCaller<Patch_Sphere>() );
834 GlobalCommands_insert( "SimplePatchMesh", FreeCaller<Patch_Plane>(), Accelerator( 'P', (GdkModifierType)GDK_SHIFT_MASK ) );
835 GlobalCommands_insert( "PatchInsertFirstColumn", FreeCaller<Patch_InsertFirstColumn>(), Accelerator( GDK_KP_Add, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
836 GlobalCommands_insert( "PatchInsertLastColumn", FreeCaller<Patch_InsertLastColumn>() );
837 GlobalCommands_insert( "PatchInsertFirstRow", FreeCaller<Patch_InsertFirstRow>(), Accelerator( GDK_KP_Add, (GdkModifierType)GDK_CONTROL_MASK ) );
838 GlobalCommands_insert( "PatchInsertLastRow", FreeCaller<Patch_InsertLastRow>() );
839 GlobalCommands_insert( "PatchDeleteFirstColumn", FreeCaller<Patch_DeleteFirstColumn>() );
840 GlobalCommands_insert( "PatchDeleteLastColumn", FreeCaller<Patch_DeleteLastColumn>(), Accelerator( GDK_KP_Subtract, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
841 GlobalCommands_insert( "PatchDeleteFirstRow", FreeCaller<Patch_DeleteFirstRow>() );
842 GlobalCommands_insert( "PatchDeleteLastRow", FreeCaller<Patch_DeleteLastRow>(), Accelerator( GDK_KP_Subtract, (GdkModifierType)GDK_CONTROL_MASK ) );
843 GlobalCommands_insert( "InvertCurve", FreeCaller<Patch_Invert>(), Accelerator( 'I', (GdkModifierType)GDK_CONTROL_MASK ) );
844 //GlobalCommands_insert( "RedisperseRows", FreeCaller<Patch_RedisperseRows>(), Accelerator( 'E', (GdkModifierType)GDK_CONTROL_MASK ) );
845 GlobalCommands_insert( "RedisperseRows", FreeCaller<Patch_RedisperseRows>() );
846 //GlobalCommands_insert( "RedisperseCols", FreeCaller<Patch_RedisperseCols>(), Accelerator( 'E', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
847 GlobalCommands_insert( "RedisperseCols", FreeCaller<Patch_RedisperseCols>() );
848 GlobalCommands_insert( "SmoothRows", FreeCaller<Patch_SmoothRows>(), Accelerator( 'W', (GdkModifierType)GDK_CONTROL_MASK ) );
849 GlobalCommands_insert( "SmoothCols", FreeCaller<Patch_SmoothCols>(), Accelerator( 'W', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
850 GlobalCommands_insert( "MatrixTranspose", FreeCaller<Patch_Transpose>(), Accelerator( 'M', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
851 GlobalCommands_insert( "CapCurrentCurve", FreeCaller<Patch_Cap>(), Accelerator( 'C', (GdkModifierType)GDK_SHIFT_MASK ) );
852 GlobalCommands_insert( "CycleCapTexturePatch", FreeCaller<Patch_CycleProjection>(), Accelerator( 'N', (GdkModifierType)GDK_SHIFT_MASK ) );
853 // GlobalCommands_insert( "MakeOverlayPatch", FreeCaller<Patch_OverlayOn>(), Accelerator( 'Y' ) );
854 // GlobalCommands_insert( "ClearPatchOverlays", FreeCaller<Patch_OverlayOff>(), Accelerator( 'L', (GdkModifierType)GDK_CONTROL_MASK ) );
855 GlobalCommands_insert( "PatchDeform", FreeCaller<Patch_Deform>() );
856 GlobalCommands_insert( "PatchThicken", FreeCaller<Patch_Thicken>(), Accelerator( 'T', (GdkModifierType)GDK_CONTROL_MASK ) );
859 void Patch_constructToolbar( GtkToolbar* toolbar ){
860 toolbar_append_button( toolbar, "Put caps on the current patch (SHIFT + C)", "curve_cap.png", "CapCurrentCurve" );
863 void Patch_constructMenu( GtkMenu* menu ){
864 create_menu_item_with_mnemonic( menu, "Simple Patch Mesh...", "SimplePatchMesh" );
865 create_menu_item_with_mnemonic( menu, "Bevel", "PatchBevel" );
866 create_menu_item_with_mnemonic( menu, "End cap", "PatchEndCap" );
867 create_menu_item_with_mnemonic( menu, "Cylinder (9x3)", "PatchCylinder" );
868 create_menu_item_with_mnemonic( menu, "Square Cylinder (9x3)", "PatchSquareCylinder" );
869 create_menu_item_with_mnemonic( menu, "Exact Cylinder...", "PatchXactCylinder" );
870 create_menu_item_with_mnemonic( menu, "Cone (9x3)", "PatchCone" );
871 create_menu_item_with_mnemonic( menu, "Exact Cone...", "PatchXactCone" );
872 create_menu_item_with_mnemonic( menu, "Sphere (9x5)", "PatchSphere" );
873 create_menu_item_with_mnemonic( menu, "Exact Sphere...", "PatchXactSphere" );
875 // GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "More Cylinders" );
876 // if ( g_Layout_enableDetachableMenus.m_value ) {
877 // menu_tearoff( menu_in_menu );
879 // create_menu_item_with_mnemonic( menu_in_menu, "Dense Cylinder", "PatchDenseCylinder" );
880 // create_menu_item_with_mnemonic( menu_in_menu, "Very Dense Cylinder", "PatchVeryDenseCylinder" );
881 // create_menu_item_with_mnemonic( menu_in_menu, "Square Cylinder", "PatchSquareCylinder" );
885 // create_menu_item_with_mnemonic( menu, "Square Endcap", "PatchSquareBevel" );
886 // create_menu_item_with_mnemonic( menu, "Square Bevel", "PatchSquareEndcap" );
888 menu_separator( menu );
889 create_menu_item_with_mnemonic( menu, "Cap Selection", "CapCurrentCurve" );
890 menu_separator( menu );
892 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Insert/Delete" );
893 if ( g_Layout_enableDetachableMenus.m_value ) {
894 menu_tearoff( menu_in_menu );
896 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) First Columns", "PatchInsertFirstColumn" );
897 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Last Columns", "PatchInsertLastColumn" );
898 menu_separator( menu_in_menu );
899 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) First Rows", "PatchInsertFirstRow" );
900 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Last Rows", "PatchInsertLastRow" );
901 menu_separator( menu_in_menu );
902 create_menu_item_with_mnemonic( menu_in_menu, "Del First (2) Columns", "PatchDeleteFirstColumn" );
903 create_menu_item_with_mnemonic( menu_in_menu, "Del Last (2) Columns", "PatchDeleteLastColumn" );
904 menu_separator( menu_in_menu );
905 create_menu_item_with_mnemonic( menu_in_menu, "Del First (2) Rows", "PatchDeleteFirstRow" );
906 create_menu_item_with_mnemonic( menu_in_menu, "Del Last (2) Rows", "PatchDeleteLastRow" );
908 menu_separator( menu );
910 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Matrix" );
911 if ( g_Layout_enableDetachableMenus.m_value ) {
912 menu_tearoff( menu_in_menu );
914 create_menu_item_with_mnemonic( menu_in_menu, "Invert", "InvertCurve" );
915 create_menu_item_with_mnemonic( menu_in_menu, "Transpose", "MatrixTranspose" );
917 menu_separator( menu_in_menu );
918 create_menu_item_with_mnemonic( menu_in_menu, "Re-disperse Rows", "RedisperseRows" );
919 create_menu_item_with_mnemonic( menu_in_menu, "Re-disperse Columns", "RedisperseCols" );
921 menu_separator( menu_in_menu );
922 create_menu_item_with_mnemonic( menu_in_menu, "Smooth Rows", "SmoothRows" );
923 create_menu_item_with_mnemonic( menu_in_menu, "Smooth Columns", "SmoothCols" );
925 menu_separator( menu );
927 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Texture" );
928 if ( g_Layout_enableDetachableMenus.m_value ) {
929 menu_tearoff( menu_in_menu );
931 create_menu_item_with_mnemonic( menu_in_menu, "Cycle Projection", "CycleCapTexturePatch" );
932 create_menu_item_with_mnemonic( menu_in_menu, "Naturalize", "NaturalizePatch" );
933 create_menu_item_with_mnemonic( menu_in_menu, "Invert X", "InvertCurveTextureX" );
934 create_menu_item_with_mnemonic( menu_in_menu, "Invert Y", "InvertCurveTextureY" );
937 // menu_separator( menu );
939 // GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Overlay" );
940 // if ( g_Layout_enableDetachableMenus.m_value ) {
941 // menu_tearoff( menu_in_menu );
943 // create_menu_item_with_mnemonic( menu_in_menu, "Set", "MakeOverlayPatch" );
944 // create_menu_item_with_mnemonic( menu_in_menu, "Clear", "ClearPatchOverlays" );
946 menu_separator( menu );
947 create_menu_item_with_mnemonic( menu, "Deform...", "PatchDeform" );
948 create_menu_item_with_mnemonic( menu, "Thicken...", "PatchThicken" );
952 #include <gtk/gtkbox.h>
953 #include <gtk/gtktable.h>
954 #include <gtk/gtktogglebutton.h>
955 #include <gtk/gtkradiobutton.h>
956 #include <gtk/gtkcombobox.h>
957 #include <gtk/gtkspinbutton.h>
958 #include <gtk/gtklabel.h>
959 #include "gtkutil/dialog.h"
960 #include "gtkutil/widget.h"
962 void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols ){
966 GtkWidget* redisperseCheckBox;
968 GtkWindow* window = create_dialog_window( MainFrame_getWindow(), "Patch density", G_CALLBACK( dialog_delete_callback ), &dialog );
970 GtkAccelGroup* accel = gtk_accel_group_new();
971 gtk_window_add_accel_group( window, accel );
974 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
975 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
977 GtkTable* table = create_dialog_table( 3, 2, 4, 4 );
978 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
980 GtkLabel* label = GTK_LABEL( gtk_label_new( "Width:" ) );
981 gtk_widget_show( GTK_WIDGET( label ) );
982 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
983 (GtkAttachOptions) ( GTK_FILL ),
984 (GtkAttachOptions) ( 0 ), 0, 0 );
985 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
988 GtkLabel* label = GTK_LABEL( gtk_label_new( "Height:" ) );
989 gtk_widget_show( GTK_WIDGET( label ) );
990 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
991 (GtkAttachOptions) ( GTK_FILL ),
992 (GtkAttachOptions) ( 0 ), 0, 0 );
993 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
997 GtkComboBox* combo = GTK_COMBO_BOX( gtk_combo_box_new_text() );
998 #define D_ITEM( x ) if ( x >= mincols && ( !maxcols || x <= maxcols ) ) gtk_combo_box_append_text( combo, # x )
1013 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
1015 gtk_widget_show( GTK_WIDGET( combo ) );
1016 gtk_table_attach( table, GTK_WIDGET( combo ), 1, 2, 0, 1,
1017 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1018 (GtkAttachOptions) ( 0 ), 0, 0 );
1023 GtkComboBox* combo = GTK_COMBO_BOX( gtk_combo_box_new_text() );
1024 #define D_ITEM( x ) if ( x >= minrows && ( !maxrows || x <= maxrows ) ) gtk_combo_box_append_text( combo, # x )
1039 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
1041 gtk_widget_show( GTK_WIDGET( combo ) );
1042 gtk_table_attach( table, GTK_WIDGET( combo ), 1, 2, 1, 2,
1043 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1044 (GtkAttachOptions) ( 0 ), 0, 0 );
1049 if( prefab != ePlane ){
1050 GtkWidget* _redisperseCheckBox = gtk_check_button_new_with_label( "Square" );
1051 gtk_widget_set_tooltip_text( _redisperseCheckBox, "Redisperse columns & rows" );
1052 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( _redisperseCheckBox ), FALSE );
1053 gtk_widget_show( _redisperseCheckBox );
1054 gtk_table_attach( table, _redisperseCheckBox, 0, 2, 2, 3,
1055 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1056 (GtkAttachOptions) ( 0 ), 0, 0 );
1057 redisperseCheckBox = _redisperseCheckBox;
1063 GtkVBox* vbox = create_dialog_vbox( 4 );
1064 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
1066 GtkButton* button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
1067 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1068 widget_make_default( GTK_WIDGET( button ) );
1069 gtk_widget_grab_focus( GTK_WIDGET( button ) );
1070 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
1073 GtkButton* button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
1074 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1075 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
1080 // Initialize dialog
1081 gtk_combo_box_set_active( width, ( defcols - mincols ) / 2 );
1082 gtk_combo_box_set_active( height, ( defrows - minrows ) / 2 );
1084 if ( modal_dialog_show( window, dialog ) == eIDOK ) {
1085 int w = gtk_combo_box_get_active( width ) * 2 + mincols;
1086 int h = gtk_combo_box_get_active( height ) * 2 + minrows;
1087 bool redisperse = false;
1088 if( prefab != ePlane ){
1089 redisperse = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( redisperseCheckBox ) ) ? true : false;
1091 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), prefab, GlobalXYWnd_getCurrentViewType(), w, h, redisperse );
1094 gtk_widget_destroy( GTK_WIDGET( window ) );
1098 void DoPatchDeformDlg(){
1105 GtkWindow* window = create_dialog_window( MainFrame_getWindow(), "Patch deform", G_CALLBACK( dialog_delete_callback ), &dialog );
1107 GtkAccelGroup* accel = gtk_accel_group_new();
1108 gtk_window_add_accel_group( window, accel );
1111 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
1112 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
1114 GtkTable* table = create_dialog_table( 2, 2, 4, 4 );
1115 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
1117 GtkLabel* label = GTK_LABEL( gtk_label_new( "Max deform:" ) );
1118 gtk_widget_show( GTK_WIDGET( label ) );
1119 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
1120 (GtkAttachOptions) ( GTK_FILL ),
1121 (GtkAttachOptions) ( 0 ), 0, 0 );
1122 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1125 // GtkWidget* entry = gtk_entry_new();
1126 // gtk_entry_set_text( GTK_ENTRY( entry ), "64" );
1127 // gtk_widget_show( entry );
1128 // gtk_table_attach( table, entry, 1, 2, 0, 1,
1129 // (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1130 // (GtkAttachOptions) ( 0 ), 0, 0 );
1135 GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 64, -9999, 9999, 1, 10, 0 ) );
1136 //GtkSpinButton* spin = GTK_SPIN_BUTTON( gtk_spin_button_new( adj, 1, 0 ) );
1137 GtkWidget* spin = gtk_spin_button_new( adj, 1, 0 );
1138 gtk_widget_show( spin );
1139 gtk_table_attach( table, spin, 1, 2, 0, 1,
1140 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1141 (GtkAttachOptions) ( 0 ), 0, 0 );
1142 gtk_widget_set_size_request( spin, 64, -1 );
1143 gtk_spin_button_set_numeric( GTK_SPIN_BUTTON( spin ), TRUE );
1148 // Create the radio button group for choosing the axis
1149 GtkWidget* _rndZ = gtk_radio_button_new_with_label_from_widget( NULL, "Z" );
1150 GtkWidget* _rndY = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_rndZ), "Y" );
1151 GtkWidget* _rndX = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_rndZ), "X" );
1152 gtk_widget_show( _rndZ );
1153 gtk_widget_show( _rndY );
1154 gtk_widget_show( _rndX );
1157 GtkHBox* _hbox = create_dialog_hbox( 4, 4 );
1158 gtk_table_attach( table, GTK_WIDGET( _hbox ), 0, 2, 1, 2,
1159 (GtkAttachOptions) ( GTK_FILL ),
1160 (GtkAttachOptions) ( 0 ), 0, 0 );
1161 gtk_box_pack_start( GTK_BOX( _hbox ), GTK_WIDGET( _rndX ), TRUE, TRUE, 0 );
1162 gtk_box_pack_start( GTK_BOX( _hbox ), GTK_WIDGET( _rndY ), TRUE, TRUE, 0 );
1163 gtk_box_pack_start( GTK_BOX( _hbox ), GTK_WIDGET( _rndZ ), TRUE, TRUE, 0 );
1170 GtkVBox* vbox = create_dialog_vbox( 4 );
1171 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
1173 GtkButton* button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
1174 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1175 widget_make_default( GTK_WIDGET( button ) );
1176 gtk_widget_grab_focus( GTK_WIDGET( button ) );
1177 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
1180 GtkButton* button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
1181 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1182 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
1187 if ( modal_dialog_show( window, dialog ) == eIDOK ) {
1188 //int deform = static_cast<int>( atoi( gtk_entry_get_text( GTK_ENTRY( deformW ) ) ) );
1189 gtk_spin_button_update ( GTK_SPIN_BUTTON( deformW ) );
1190 int deform = static_cast<int>( gtk_spin_button_get_value( GTK_SPIN_BUTTON( deformW ) ) );
1192 if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( rndX ) ) ){
1195 else if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( rndY ) ) ){
1198 Scene_PatchDeform( GlobalSceneGraph(), deform, axis );
1200 gtk_widget_destroy( GTK_WIDGET( window ) );
1205 EMessageBoxReturn DoCapDlg( ECapDialog* type ){
1207 ModalDialogButton ok_button( dialog, eIDOK );
1208 ModalDialogButton cancel_button( dialog, eIDCANCEL );
1213 GtkWidget* cylinder;
1215 GtkWindow* window = create_modal_dialog_window( MainFrame_getWindow(), "Cap", dialog );
1217 GtkAccelGroup *accel_group = gtk_accel_group_new();
1218 gtk_window_add_accel_group( window, accel_group );
1221 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
1222 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
1225 // Gef: Added a vbox to contain the toggle buttons
1226 GtkVBox* radio_vbox = create_dialog_vbox( 4 );
1227 gtk_container_add( GTK_CONTAINER( hbox ), GTK_WIDGET( radio_vbox ) );
1230 GtkTable* table = GTK_TABLE( gtk_table_new( 5, 2, FALSE ) );
1231 gtk_widget_show( GTK_WIDGET( table ) );
1232 gtk_box_pack_start( GTK_BOX( radio_vbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
1233 gtk_table_set_row_spacings( table, 5 );
1234 gtk_table_set_col_spacings( table, 5 );
1237 GtkImage* image = new_local_image( "cap_bevel.png" );
1238 gtk_widget_show( GTK_WIDGET( image ) );
1239 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 0, 1,
1240 (GtkAttachOptions) ( GTK_FILL ),
1241 (GtkAttachOptions) ( 0 ), 0, 0 );
1244 GtkImage* image = new_local_image( "cap_endcap.png" );
1245 gtk_widget_show( GTK_WIDGET( image ) );
1246 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 1, 2,
1247 (GtkAttachOptions) ( GTK_FILL ),
1248 (GtkAttachOptions) ( 0 ), 0, 0 );
1251 GtkImage* image = new_local_image( "cap_ibevel.png" );
1252 gtk_widget_show( GTK_WIDGET( image ) );
1253 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 2, 3,
1254 (GtkAttachOptions) ( GTK_FILL ),
1255 (GtkAttachOptions) ( 0 ), 0, 0 );
1258 GtkImage* image = new_local_image( "cap_iendcap.png" );
1259 gtk_widget_show( GTK_WIDGET( image ) );
1260 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 3, 4,
1261 (GtkAttachOptions) ( GTK_FILL ),
1262 (GtkAttachOptions) ( 0 ), 0, 0 );
1265 GtkImage* image = new_local_image( "cap_cylinder.png" );
1266 gtk_widget_show( GTK_WIDGET( image ) );
1267 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 4, 5,
1268 (GtkAttachOptions) ( GTK_FILL ),
1269 (GtkAttachOptions) ( 0 ), 0, 0 );
1274 GtkWidget* button = gtk_radio_button_new_with_label( group, "Bevel" );
1275 gtk_widget_show( button );
1276 gtk_table_attach( table, button, 1, 2, 0, 1,
1277 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1278 (GtkAttachOptions) ( 0 ), 0, 0 );
1279 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1284 GtkWidget* button = gtk_radio_button_new_with_label( group, "Endcap" );
1285 gtk_widget_show( button );
1286 gtk_table_attach( table, button, 1, 2, 1, 2,
1287 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1288 (GtkAttachOptions) ( 0 ), 0, 0 );
1289 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1294 GtkWidget* button = gtk_radio_button_new_with_label( group, "Inverted Bevel" );
1295 gtk_widget_show( button );
1296 gtk_table_attach( table, button, 1, 2, 2, 3,
1297 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1298 (GtkAttachOptions) ( 0 ), 0, 0 );
1299 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1304 GtkWidget* button = gtk_radio_button_new_with_label( group, "Inverted Endcap" );
1305 gtk_widget_show( button );
1306 gtk_table_attach( table, button, 1, 2, 3, 4,
1307 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1308 (GtkAttachOptions) ( 0 ), 0, 0 );
1309 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1314 GtkWidget* button = gtk_radio_button_new_with_label( group, "Cylinder" );
1315 gtk_widget_show( button );
1316 gtk_table_attach( table, button, 1, 2, 4, 5,
1317 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1318 (GtkAttachOptions) ( 0 ), 0, 0 );
1319 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1327 GtkVBox* vbox = create_dialog_vbox( 4 );
1328 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), FALSE, FALSE, 0 );
1330 GtkButton* button = create_modal_dialog_button( "OK", ok_button );
1331 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1332 widget_make_default( GTK_WIDGET( button ) );
1333 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel_group, GDK_Return, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
1336 GtkButton* button = create_modal_dialog_button( "Cancel", cancel_button );
1337 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1338 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel_group, GDK_Escape, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
1343 // Initialize dialog
1344 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( bevel ), TRUE );
1346 EMessageBoxReturn ret = modal_dialog_show( window, dialog );
1347 if ( ret == eIDOK ) {
1348 if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( bevel ) ) ) {
1349 *type = PATCHCAP_BEVEL;
1351 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( endcap ) ) ) {
1352 *type = PATCHCAP_ENDCAP;
1354 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( ibevel ) ) ) {
1355 *type = PATCHCAP_INVERTED_BEVEL;
1357 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( iendcap ) ) ) {
1358 *type = PATCHCAP_INVERTED_ENDCAP;
1360 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( cylinder ) ) ) {
1361 *type = PATCHCAP_CYLINDER;
1365 gtk_widget_destroy( GTK_WIDGET( window ) );
1371 void DoPatchThickenDlg(){
1373 GtkWidget* thicknessW;
1379 GtkWindow* window = create_dialog_window( MainFrame_getWindow(), "Patch thicken", G_CALLBACK( dialog_delete_callback ), &dialog );
1381 GtkAccelGroup* accel = gtk_accel_group_new();
1382 gtk_window_add_accel_group( window, accel );
1385 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
1386 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
1388 GtkTable* table = create_dialog_table( 2, 4, 4, 4 );
1389 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
1391 GtkLabel* label = GTK_LABEL( gtk_label_new( "Thickness:" ) );
1392 gtk_widget_show( GTK_WIDGET( label ) );
1393 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
1394 (GtkAttachOptions) ( GTK_FILL ),
1395 (GtkAttachOptions) ( 0 ), 0, 0 );
1396 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1399 // GtkWidget* entry = gtk_entry_new();
1400 // gtk_entry_set_text( GTK_ENTRY( entry ), "16" );
1401 // gtk_widget_set_size_request( entry, 40, -1 );
1402 // gtk_widget_show( entry );
1403 // gtk_table_attach( table, entry, 1, 2, 0, 1,
1404 // (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1405 // (GtkAttachOptions) ( 0 ), 0, 0 );
1407 // thicknessW = entry;
1410 GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 16, -9999, 9999, 1, 10, 0 ) );
1411 GtkWidget* spin = gtk_spin_button_new( adj, 1, 0 );
1412 gtk_widget_show( spin );
1413 gtk_table_attach( table, spin, 1, 2, 0, 1,
1414 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1415 (GtkAttachOptions) ( 0 ), 0, 0 );
1416 gtk_widget_set_size_request( spin, 48, -1 );
1417 gtk_spin_button_set_numeric( GTK_SPIN_BUTTON( spin ), TRUE );
1422 // Create the "create seams" label
1423 GtkWidget* _seamsCheckBox = gtk_check_button_new_with_label( "Side walls" );
1424 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( _seamsCheckBox ), TRUE );
1425 gtk_widget_show( _seamsCheckBox );
1426 gtk_table_attach( table, _seamsCheckBox, 2, 4, 0, 1,
1427 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1428 (GtkAttachOptions) ( 0 ), 0, 0 );
1429 seamsW = _seamsCheckBox;
1433 // Create the radio button group for choosing the extrude axis
1434 GtkWidget* _radNormals = gtk_radio_button_new_with_label( NULL, "Normal" );
1435 GtkWidget* _radX = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "X" );
1436 GtkWidget* _radY = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "Y" );
1437 GtkWidget* _radZ = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "Z" );
1438 gtk_widget_show( _radNormals );
1439 gtk_widget_show( _radX );
1440 gtk_widget_show( _radY );
1441 gtk_widget_show( _radZ );
1444 // Pack the buttons into the table
1445 gtk_table_attach( table, _radNormals, 0, 1, 1, 2,
1446 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1447 (GtkAttachOptions) ( 0 ), 0, 0 );
1448 gtk_table_attach( table, _radX, 1, 2, 1, 2,
1449 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1450 (GtkAttachOptions) ( 0 ), 0, 0 );
1451 gtk_table_attach( table, _radY, 2, 3, 1, 2,
1452 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1453 (GtkAttachOptions) ( 0 ), 0, 0 );
1454 gtk_table_attach( table, _radZ, 3, 4, 1, 2,
1455 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1456 (GtkAttachOptions) ( 0 ), 0, 0 );
1463 GtkVBox* vbox = create_dialog_vbox( 4 );
1464 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
1466 GtkButton* button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
1467 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1468 widget_make_default( GTK_WIDGET( button ) );
1469 gtk_widget_grab_focus( GTK_WIDGET( button ) );
1470 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
1473 GtkButton* button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
1474 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1475 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
1480 if ( modal_dialog_show( window, dialog ) == eIDOK ) {
1481 int axis = 3; // Extrude along normals
1483 //float thickness = static_cast<float>( atoi( gtk_entry_get_text( GTK_ENTRY( thicknessW ) ) ) );
1484 gtk_spin_button_update ( GTK_SPIN_BUTTON( thicknessW ) );
1485 float thickness = static_cast<float>( gtk_spin_button_get_value( GTK_SPIN_BUTTON( thicknessW ) ) );
1486 seams = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( seamsW )) ? true : false;
1488 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radX))) {
1491 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radY))) {
1494 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radZ))) {
1498 Scene_PatchThicken( GlobalSceneGraph(), thickness, seams, axis );
1501 gtk_widget_destroy( GTK_WIDGET( window ) );