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( "RedisperseCols", FreeCaller<Patch_RedisperseCols>(), Accelerator( 'E', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
846 GlobalCommands_insert( "SmoothRows", FreeCaller<Patch_SmoothRows>(), Accelerator( 'W', (GdkModifierType)GDK_CONTROL_MASK ) );
847 GlobalCommands_insert( "SmoothCols", FreeCaller<Patch_SmoothCols>(), Accelerator( 'W', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
848 GlobalCommands_insert( "MatrixTranspose", FreeCaller<Patch_Transpose>(), Accelerator( 'M', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
849 GlobalCommands_insert( "CapCurrentCurve", FreeCaller<Patch_Cap>(), Accelerator( 'C', (GdkModifierType)GDK_SHIFT_MASK ) );
850 GlobalCommands_insert( "CycleCapTexturePatch", FreeCaller<Patch_CycleProjection>(), Accelerator( 'N', (GdkModifierType)GDK_SHIFT_MASK ) );
851 // GlobalCommands_insert( "MakeOverlayPatch", FreeCaller<Patch_OverlayOn>(), Accelerator( 'Y' ) );
852 // GlobalCommands_insert( "ClearPatchOverlays", FreeCaller<Patch_OverlayOff>(), Accelerator( 'L', (GdkModifierType)GDK_CONTROL_MASK ) );
853 GlobalCommands_insert( "PatchDeform", FreeCaller<Patch_Deform>() );
854 GlobalCommands_insert( "PatchThicken", FreeCaller<Patch_Thicken>(), Accelerator( 'T', (GdkModifierType)GDK_CONTROL_MASK ) );
857 void Patch_constructToolbar( GtkToolbar* toolbar ){
858 toolbar_append_button( toolbar, "Put caps on the current patch (SHIFT + C)", "curve_cap.png", "CapCurrentCurve" );
861 void Patch_constructMenu( GtkMenu* menu ){
862 create_menu_item_with_mnemonic( menu, "Simple Patch Mesh...", "SimplePatchMesh" );
863 create_menu_item_with_mnemonic( menu, "Bevel", "PatchBevel" );
864 create_menu_item_with_mnemonic( menu, "End cap", "PatchEndCap" );
865 create_menu_item_with_mnemonic( menu, "Cylinder (9x3)", "PatchCylinder" );
866 create_menu_item_with_mnemonic( menu, "Square Cylinder (9x3)", "PatchSquareCylinder" );
867 create_menu_item_with_mnemonic( menu, "Exact Cylinder...", "PatchXactCylinder" );
868 create_menu_item_with_mnemonic( menu, "Cone (9x3)", "PatchCone" );
869 create_menu_item_with_mnemonic( menu, "Exact Cone...", "PatchXactCone" );
870 create_menu_item_with_mnemonic( menu, "Sphere (9x5)", "PatchSphere" );
871 create_menu_item_with_mnemonic( menu, "Exact Sphere...", "PatchXactSphere" );
873 // GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "More Cylinders" );
874 // if ( g_Layout_enableDetachableMenus.m_value ) {
875 // menu_tearoff( menu_in_menu );
877 // create_menu_item_with_mnemonic( menu_in_menu, "Dense Cylinder", "PatchDenseCylinder" );
878 // create_menu_item_with_mnemonic( menu_in_menu, "Very Dense Cylinder", "PatchVeryDenseCylinder" );
879 // create_menu_item_with_mnemonic( menu_in_menu, "Square Cylinder", "PatchSquareCylinder" );
883 // create_menu_item_with_mnemonic( menu, "Square Endcap", "PatchSquareBevel" );
884 // create_menu_item_with_mnemonic( menu, "Square Bevel", "PatchSquareEndcap" );
886 menu_separator( menu );
887 create_menu_item_with_mnemonic( menu, "Cap Selection", "CapCurrentCurve" );
888 menu_separator( menu );
890 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Insert/Delete" );
891 if ( g_Layout_enableDetachableMenus.m_value ) {
892 menu_tearoff( menu_in_menu );
894 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) First Columns", "PatchInsertFirstColumn" );
895 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Last Columns", "PatchInsertLastColumn" );
896 menu_separator( menu_in_menu );
897 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) First Rows", "PatchInsertFirstRow" );
898 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Last Rows", "PatchInsertLastRow" );
899 menu_separator( menu_in_menu );
900 create_menu_item_with_mnemonic( menu_in_menu, "Del First (2) Columns", "PatchDeleteFirstColumn" );
901 create_menu_item_with_mnemonic( menu_in_menu, "Del Last (2) Columns", "PatchDeleteLastColumn" );
902 menu_separator( menu_in_menu );
903 create_menu_item_with_mnemonic( menu_in_menu, "Del First (2) Rows", "PatchDeleteFirstRow" );
904 create_menu_item_with_mnemonic( menu_in_menu, "Del Last (2) Rows", "PatchDeleteLastRow" );
906 menu_separator( menu );
908 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Matrix" );
909 if ( g_Layout_enableDetachableMenus.m_value ) {
910 menu_tearoff( menu_in_menu );
912 create_menu_item_with_mnemonic( menu_in_menu, "Invert", "InvertCurve" );
913 create_menu_item_with_mnemonic( menu_in_menu, "Transpose", "MatrixTranspose" );
915 menu_separator( menu_in_menu );
916 create_menu_item_with_mnemonic( menu_in_menu, "Re-disperse Rows", "RedisperseRows" );
917 create_menu_item_with_mnemonic( menu_in_menu, "Re-disperse Columns", "RedisperseCols" );
919 menu_separator( menu_in_menu );
920 create_menu_item_with_mnemonic( menu_in_menu, "Smooth Rows", "SmoothRows" );
921 create_menu_item_with_mnemonic( menu_in_menu, "Smooth Columns", "SmoothCols" );
923 menu_separator( menu );
925 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Texture" );
926 if ( g_Layout_enableDetachableMenus.m_value ) {
927 menu_tearoff( menu_in_menu );
929 create_menu_item_with_mnemonic( menu_in_menu, "Cycle Projection", "CycleCapTexturePatch" );
930 create_menu_item_with_mnemonic( menu_in_menu, "Naturalize", "NaturalizePatch" );
931 create_menu_item_with_mnemonic( menu_in_menu, "Invert X", "InvertCurveTextureX" );
932 create_menu_item_with_mnemonic( menu_in_menu, "Invert Y", "InvertCurveTextureY" );
935 // menu_separator( menu );
937 // GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Overlay" );
938 // if ( g_Layout_enableDetachableMenus.m_value ) {
939 // menu_tearoff( menu_in_menu );
941 // create_menu_item_with_mnemonic( menu_in_menu, "Set", "MakeOverlayPatch" );
942 // create_menu_item_with_mnemonic( menu_in_menu, "Clear", "ClearPatchOverlays" );
944 menu_separator( menu );
945 create_menu_item_with_mnemonic( menu, "Deform...", "PatchDeform" );
946 create_menu_item_with_mnemonic( menu, "Thicken...", "PatchThicken" );
950 #include <gtk/gtkbox.h>
951 #include <gtk/gtktable.h>
952 #include <gtk/gtktogglebutton.h>
953 #include <gtk/gtkradiobutton.h>
954 #include <gtk/gtkcombobox.h>
955 #include <gtk/gtkspinbutton.h>
956 #include <gtk/gtklabel.h>
957 #include "gtkutil/dialog.h"
958 #include "gtkutil/widget.h"
960 void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols ){
964 GtkWidget* redisperseCheckBox;
966 GtkWindow* window = create_dialog_window( MainFrame_getWindow(), "Patch density", G_CALLBACK( dialog_delete_callback ), &dialog );
968 GtkAccelGroup* accel = gtk_accel_group_new();
969 gtk_window_add_accel_group( window, accel );
972 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
973 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
975 GtkTable* table = create_dialog_table( 3, 2, 4, 4 );
976 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
978 GtkLabel* label = GTK_LABEL( gtk_label_new( "Width:" ) );
979 gtk_widget_show( GTK_WIDGET( label ) );
980 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
981 (GtkAttachOptions) ( GTK_FILL ),
982 (GtkAttachOptions) ( 0 ), 0, 0 );
983 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
986 GtkLabel* label = GTK_LABEL( gtk_label_new( "Height:" ) );
987 gtk_widget_show( GTK_WIDGET( label ) );
988 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
989 (GtkAttachOptions) ( GTK_FILL ),
990 (GtkAttachOptions) ( 0 ), 0, 0 );
991 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
995 GtkComboBox* combo = GTK_COMBO_BOX( gtk_combo_box_new_text() );
996 #define D_ITEM( x ) if ( x >= mincols && ( !maxcols || x <= maxcols ) ) gtk_combo_box_append_text( combo, # x )
1011 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
1013 gtk_widget_show( GTK_WIDGET( combo ) );
1014 gtk_table_attach( table, GTK_WIDGET( combo ), 1, 2, 0, 1,
1015 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1016 (GtkAttachOptions) ( 0 ), 0, 0 );
1021 GtkComboBox* combo = GTK_COMBO_BOX( gtk_combo_box_new_text() );
1022 #define D_ITEM( x ) if ( x >= minrows && ( !maxrows || x <= maxrows ) ) gtk_combo_box_append_text( combo, # x )
1037 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
1039 gtk_widget_show( GTK_WIDGET( combo ) );
1040 gtk_table_attach( table, GTK_WIDGET( combo ), 1, 2, 1, 2,
1041 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1042 (GtkAttachOptions) ( 0 ), 0, 0 );
1047 if( prefab != ePlane ){
1048 GtkWidget* _redisperseCheckBox = gtk_check_button_new_with_label( "Square" );
1049 gtk_widget_set_tooltip_text( _redisperseCheckBox, "Redisperse columns & rows" );
1050 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( _redisperseCheckBox ), FALSE );
1051 gtk_widget_show( _redisperseCheckBox );
1052 gtk_table_attach( table, _redisperseCheckBox, 0, 2, 2, 3,
1053 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1054 (GtkAttachOptions) ( 0 ), 0, 0 );
1055 redisperseCheckBox = _redisperseCheckBox;
1061 GtkVBox* vbox = create_dialog_vbox( 4 );
1062 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
1064 GtkButton* button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
1065 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1066 widget_make_default( GTK_WIDGET( button ) );
1067 gtk_widget_grab_focus( GTK_WIDGET( button ) );
1068 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
1071 GtkButton* button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
1072 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1073 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
1078 // Initialize dialog
1079 gtk_combo_box_set_active( width, ( defcols - mincols ) / 2 );
1080 gtk_combo_box_set_active( height, ( defrows - minrows ) / 2 );
1082 if ( modal_dialog_show( window, dialog ) == eIDOK ) {
1083 int w = gtk_combo_box_get_active( width ) * 2 + mincols;
1084 int h = gtk_combo_box_get_active( height ) * 2 + minrows;
1085 bool redisperse = false;
1086 if( prefab != ePlane ){
1087 redisperse = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( redisperseCheckBox ) ) ? true : false;
1089 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), prefab, GlobalXYWnd_getCurrentViewType(), w, h, redisperse );
1092 gtk_widget_destroy( GTK_WIDGET( window ) );
1096 void DoPatchDeformDlg(){
1103 GtkWindow* window = create_dialog_window( MainFrame_getWindow(), "Patch deform", G_CALLBACK( dialog_delete_callback ), &dialog );
1105 GtkAccelGroup* accel = gtk_accel_group_new();
1106 gtk_window_add_accel_group( window, accel );
1109 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
1110 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
1112 GtkTable* table = create_dialog_table( 2, 2, 4, 4 );
1113 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
1115 GtkLabel* label = GTK_LABEL( gtk_label_new( "Max deform:" ) );
1116 gtk_widget_show( GTK_WIDGET( label ) );
1117 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
1118 (GtkAttachOptions) ( GTK_FILL ),
1119 (GtkAttachOptions) ( 0 ), 0, 0 );
1120 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1123 // GtkWidget* entry = gtk_entry_new();
1124 // gtk_entry_set_text( GTK_ENTRY( entry ), "64" );
1125 // gtk_widget_show( entry );
1126 // gtk_table_attach( table, entry, 1, 2, 0, 1,
1127 // (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1128 // (GtkAttachOptions) ( 0 ), 0, 0 );
1133 GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 64, -9999, 9999, 1, 10, 0 ) );
1134 //GtkSpinButton* spin = GTK_SPIN_BUTTON( gtk_spin_button_new( adj, 1, 0 ) );
1135 GtkWidget* spin = gtk_spin_button_new( adj, 1, 0 );
1136 gtk_widget_show( spin );
1137 gtk_table_attach( table, spin, 1, 2, 0, 1,
1138 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1139 (GtkAttachOptions) ( 0 ), 0, 0 );
1140 gtk_widget_set_size_request( spin, 64, -1 );
1141 gtk_spin_button_set_numeric( GTK_SPIN_BUTTON( spin ), TRUE );
1146 // Create the radio button group for choosing the axis
1147 GtkWidget* _rndZ = gtk_radio_button_new_with_label_from_widget( NULL, "Z" );
1148 GtkWidget* _rndY = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_rndZ), "Y" );
1149 GtkWidget* _rndX = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_rndZ), "X" );
1150 gtk_widget_show( _rndZ );
1151 gtk_widget_show( _rndY );
1152 gtk_widget_show( _rndX );
1155 GtkHBox* _hbox = create_dialog_hbox( 4, 4 );
1156 gtk_table_attach( table, GTK_WIDGET( _hbox ), 0, 2, 1, 2,
1157 (GtkAttachOptions) ( GTK_FILL ),
1158 (GtkAttachOptions) ( 0 ), 0, 0 );
1159 gtk_box_pack_start( GTK_BOX( _hbox ), GTK_WIDGET( _rndX ), TRUE, TRUE, 0 );
1160 gtk_box_pack_start( GTK_BOX( _hbox ), GTK_WIDGET( _rndY ), TRUE, TRUE, 0 );
1161 gtk_box_pack_start( GTK_BOX( _hbox ), GTK_WIDGET( _rndZ ), TRUE, TRUE, 0 );
1168 GtkVBox* vbox = create_dialog_vbox( 4 );
1169 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
1171 GtkButton* button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
1172 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1173 widget_make_default( GTK_WIDGET( button ) );
1174 gtk_widget_grab_focus( GTK_WIDGET( button ) );
1175 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
1178 GtkButton* button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
1179 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1180 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
1185 if ( modal_dialog_show( window, dialog ) == eIDOK ) {
1186 //int deform = static_cast<int>( atoi( gtk_entry_get_text( GTK_ENTRY( deformW ) ) ) );
1187 gtk_spin_button_update ( GTK_SPIN_BUTTON( deformW ) );
1188 int deform = static_cast<int>( gtk_spin_button_get_value( GTK_SPIN_BUTTON( deformW ) ) );
1190 if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( rndX ) ) ){
1193 else if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( rndY ) ) ){
1196 Scene_PatchDeform( GlobalSceneGraph(), deform, axis );
1198 gtk_widget_destroy( GTK_WIDGET( window ) );
1203 EMessageBoxReturn DoCapDlg( ECapDialog* type ){
1205 ModalDialogButton ok_button( dialog, eIDOK );
1206 ModalDialogButton cancel_button( dialog, eIDCANCEL );
1211 GtkWidget* cylinder;
1213 GtkWindow* window = create_modal_dialog_window( MainFrame_getWindow(), "Cap", dialog );
1215 GtkAccelGroup *accel_group = gtk_accel_group_new();
1216 gtk_window_add_accel_group( window, accel_group );
1219 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
1220 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
1223 // Gef: Added a vbox to contain the toggle buttons
1224 GtkVBox* radio_vbox = create_dialog_vbox( 4 );
1225 gtk_container_add( GTK_CONTAINER( hbox ), GTK_WIDGET( radio_vbox ) );
1228 GtkTable* table = GTK_TABLE( gtk_table_new( 5, 2, FALSE ) );
1229 gtk_widget_show( GTK_WIDGET( table ) );
1230 gtk_box_pack_start( GTK_BOX( radio_vbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
1231 gtk_table_set_row_spacings( table, 5 );
1232 gtk_table_set_col_spacings( table, 5 );
1235 GtkImage* image = new_local_image( "cap_bevel.png" );
1236 gtk_widget_show( GTK_WIDGET( image ) );
1237 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 0, 1,
1238 (GtkAttachOptions) ( GTK_FILL ),
1239 (GtkAttachOptions) ( 0 ), 0, 0 );
1242 GtkImage* image = new_local_image( "cap_endcap.png" );
1243 gtk_widget_show( GTK_WIDGET( image ) );
1244 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 1, 2,
1245 (GtkAttachOptions) ( GTK_FILL ),
1246 (GtkAttachOptions) ( 0 ), 0, 0 );
1249 GtkImage* image = new_local_image( "cap_ibevel.png" );
1250 gtk_widget_show( GTK_WIDGET( image ) );
1251 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 2, 3,
1252 (GtkAttachOptions) ( GTK_FILL ),
1253 (GtkAttachOptions) ( 0 ), 0, 0 );
1256 GtkImage* image = new_local_image( "cap_iendcap.png" );
1257 gtk_widget_show( GTK_WIDGET( image ) );
1258 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 3, 4,
1259 (GtkAttachOptions) ( GTK_FILL ),
1260 (GtkAttachOptions) ( 0 ), 0, 0 );
1263 GtkImage* image = new_local_image( "cap_cylinder.png" );
1264 gtk_widget_show( GTK_WIDGET( image ) );
1265 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 4, 5,
1266 (GtkAttachOptions) ( GTK_FILL ),
1267 (GtkAttachOptions) ( 0 ), 0, 0 );
1272 GtkWidget* button = gtk_radio_button_new_with_label( group, "Bevel" );
1273 gtk_widget_show( button );
1274 gtk_table_attach( table, button, 1, 2, 0, 1,
1275 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1276 (GtkAttachOptions) ( 0 ), 0, 0 );
1277 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1282 GtkWidget* button = gtk_radio_button_new_with_label( group, "Endcap" );
1283 gtk_widget_show( button );
1284 gtk_table_attach( table, button, 1, 2, 1, 2,
1285 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1286 (GtkAttachOptions) ( 0 ), 0, 0 );
1287 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1292 GtkWidget* button = gtk_radio_button_new_with_label( group, "Inverted Bevel" );
1293 gtk_widget_show( button );
1294 gtk_table_attach( table, button, 1, 2, 2, 3,
1295 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1296 (GtkAttachOptions) ( 0 ), 0, 0 );
1297 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1302 GtkWidget* button = gtk_radio_button_new_with_label( group, "Inverted Endcap" );
1303 gtk_widget_show( button );
1304 gtk_table_attach( table, button, 1, 2, 3, 4,
1305 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1306 (GtkAttachOptions) ( 0 ), 0, 0 );
1307 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1312 GtkWidget* button = gtk_radio_button_new_with_label( group, "Cylinder" );
1313 gtk_widget_show( button );
1314 gtk_table_attach( table, button, 1, 2, 4, 5,
1315 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1316 (GtkAttachOptions) ( 0 ), 0, 0 );
1317 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1325 GtkVBox* vbox = create_dialog_vbox( 4 );
1326 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), FALSE, FALSE, 0 );
1328 GtkButton* button = create_modal_dialog_button( "OK", ok_button );
1329 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1330 widget_make_default( GTK_WIDGET( button ) );
1331 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel_group, GDK_Return, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
1334 GtkButton* button = create_modal_dialog_button( "Cancel", cancel_button );
1335 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1336 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel_group, GDK_Escape, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
1341 // Initialize dialog
1342 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( bevel ), TRUE );
1344 EMessageBoxReturn ret = modal_dialog_show( window, dialog );
1345 if ( ret == eIDOK ) {
1346 if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( bevel ) ) ) {
1347 *type = PATCHCAP_BEVEL;
1349 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( endcap ) ) ) {
1350 *type = PATCHCAP_ENDCAP;
1352 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( ibevel ) ) ) {
1353 *type = PATCHCAP_INVERTED_BEVEL;
1355 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( iendcap ) ) ) {
1356 *type = PATCHCAP_INVERTED_ENDCAP;
1358 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( cylinder ) ) ) {
1359 *type = PATCHCAP_CYLINDER;
1363 gtk_widget_destroy( GTK_WIDGET( window ) );
1369 void DoPatchThickenDlg(){
1371 GtkWidget* thicknessW;
1377 GtkWindow* window = create_dialog_window( MainFrame_getWindow(), "Patch thicken", G_CALLBACK( dialog_delete_callback ), &dialog );
1379 GtkAccelGroup* accel = gtk_accel_group_new();
1380 gtk_window_add_accel_group( window, accel );
1383 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
1384 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
1386 GtkTable* table = create_dialog_table( 2, 4, 4, 4 );
1387 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
1389 GtkLabel* label = GTK_LABEL( gtk_label_new( "Thickness:" ) );
1390 gtk_widget_show( GTK_WIDGET( label ) );
1391 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
1392 (GtkAttachOptions) ( GTK_FILL ),
1393 (GtkAttachOptions) ( 0 ), 0, 0 );
1394 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1397 // GtkWidget* entry = gtk_entry_new();
1398 // gtk_entry_set_text( GTK_ENTRY( entry ), "16" );
1399 // gtk_widget_set_size_request( entry, 40, -1 );
1400 // gtk_widget_show( entry );
1401 // gtk_table_attach( table, entry, 1, 2, 0, 1,
1402 // (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1403 // (GtkAttachOptions) ( 0 ), 0, 0 );
1405 // thicknessW = entry;
1408 GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 16, -9999, 9999, 1, 10, 0 ) );
1409 GtkWidget* spin = gtk_spin_button_new( adj, 1, 0 );
1410 gtk_widget_show( spin );
1411 gtk_table_attach( table, spin, 1, 2, 0, 1,
1412 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1413 (GtkAttachOptions) ( 0 ), 0, 0 );
1414 gtk_widget_set_size_request( spin, 48, -1 );
1415 gtk_spin_button_set_numeric( GTK_SPIN_BUTTON( spin ), TRUE );
1420 // Create the "create seams" label
1421 GtkWidget* _seamsCheckBox = gtk_check_button_new_with_label( "Side walls" );
1422 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( _seamsCheckBox ), TRUE );
1423 gtk_widget_show( _seamsCheckBox );
1424 gtk_table_attach( table, _seamsCheckBox, 2, 4, 0, 1,
1425 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1426 (GtkAttachOptions) ( 0 ), 0, 0 );
1427 seamsW = _seamsCheckBox;
1431 // Create the radio button group for choosing the extrude axis
1432 GtkWidget* _radNormals = gtk_radio_button_new_with_label( NULL, "Normal" );
1433 GtkWidget* _radX = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "X" );
1434 GtkWidget* _radY = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "Y" );
1435 GtkWidget* _radZ = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "Z" );
1436 gtk_widget_show( _radNormals );
1437 gtk_widget_show( _radX );
1438 gtk_widget_show( _radY );
1439 gtk_widget_show( _radZ );
1442 // Pack the buttons into the table
1443 gtk_table_attach( table, _radNormals, 0, 1, 1, 2,
1444 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1445 (GtkAttachOptions) ( 0 ), 0, 0 );
1446 gtk_table_attach( table, _radX, 1, 2, 1, 2,
1447 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1448 (GtkAttachOptions) ( 0 ), 0, 0 );
1449 gtk_table_attach( table, _radY, 2, 3, 1, 2,
1450 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1451 (GtkAttachOptions) ( 0 ), 0, 0 );
1452 gtk_table_attach( table, _radZ, 3, 4, 1, 2,
1453 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1454 (GtkAttachOptions) ( 0 ), 0, 0 );
1461 GtkVBox* vbox = create_dialog_vbox( 4 );
1462 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
1464 GtkButton* button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
1465 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1466 widget_make_default( GTK_WIDGET( button ) );
1467 gtk_widget_grab_focus( GTK_WIDGET( button ) );
1468 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
1471 GtkButton* button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
1472 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1473 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
1478 if ( modal_dialog_show( window, dialog ) == eIDOK ) {
1479 int axis = 3; // Extrude along normals
1481 //float thickness = static_cast<float>( atoi( gtk_entry_get_text( GTK_ENTRY( thicknessW ) ) ) );
1482 gtk_spin_button_update ( GTK_SPIN_BUTTON( thicknessW ) );
1483 float thickness = static_cast<float>( gtk_spin_button_get_value( GTK_SPIN_BUTTON( thicknessW ) ) );
1484 seams = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( seamsW )) ? true : false;
1486 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radX))) {
1489 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radY))) {
1492 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radZ))) {
1496 Scene_PatchThicken( GlobalSceneGraph(), thickness, seams, axis );
1499 gtk_widget_destroy( GTK_WIDGET( window ) );