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 ){
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 );
60 patch->controlPointsChanged();
63 scene::Path patchpath( makeReference( GlobalSceneGraph().root() ) );
64 patchpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
65 patchpath.push( makeReference( node.get() ) );
66 Instance_getSelectable( *graph.find( patchpath ) )->setSelected( true );
71 void Patch_makeCaps( Patch& patch, scene::Instance& instance, EPatchCap type, const char* shader ){
72 if ( ( type == eCapEndCap || type == eCapIEndCap )
73 && patch.getWidth() != 5 ) {
74 globalErrorStream() << "cannot create end-cap - patch width != 5\n";
77 if ( ( type == eCapBevel || type == eCapIBevel )
78 && patch.getWidth() != 3 && patch.getWidth() != 5 ) {
79 globalErrorStream() << "cannot create bevel-cap - patch width != 3\n";
82 if ( type == eCapCylinder
83 && patch.getWidth() != 9 ) {
84 globalErrorStream() << "cannot create cylinder-cap - patch width != 9\n";
89 NodeSmartReference cap( g_patchCreator->createPatch() );
90 Node_getTraversable( instance.path().parent() )->insert( cap );
92 patch.MakeCap( Node_getPatch( cap ), type, ROW, true );
93 Node_getPatch( cap )->SetShader( shader );
95 scene::Path path( instance.path() );
97 path.push( makeReference( cap.get() ) );
98 selectPath( path, true );
102 NodeSmartReference cap( g_patchCreator->createPatch() );
103 Node_getTraversable( instance.path().parent() )->insert( cap );
105 patch.MakeCap( Node_getPatch( cap ), type, ROW, false );
106 Node_getPatch( cap )->SetShader( shader );
108 scene::Path path( instance.path() );
110 path.push( makeReference( cap.get() ) );
111 selectPath( path, true );
116 typedef std::vector<scene::Instance*> InstanceVector;
118 class PatchStoreInstance
120 InstanceVector& m_instances;
122 PatchStoreInstance( InstanceVector& instances ) : m_instances( instances ){
124 void operator()( PatchInstance& patch ) const {
125 m_instances.push_back( &patch );
132 PATCHCAP_INVERTED_BEVEL,
133 PATCHCAP_INVERTED_ENDCAP,
137 EMessageBoxReturn DoCapDlg( ECapDialog *type );
139 void Scene_PatchDoCap_Selected( scene::Graph& graph, const char* shader ){
142 if ( DoCapDlg( &nType ) == eIDOK ) {
146 case PATCHCAP_INVERTED_BEVEL:
152 case PATCHCAP_INVERTED_ENDCAP:
155 case PATCHCAP_ENDCAP:
158 case PATCHCAP_CYLINDER:
159 eType = eCapCylinder;
162 ERROR_MESSAGE( "invalid patch cap type" );
166 InstanceVector instances;
167 Scene_forEachVisibleSelectedPatchInstance( PatchStoreInstance( instances ) );
168 for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
170 Patch_makeCaps( *Node_getPatch( ( *i )->path().top() ), *( *i ), eType, shader );
175 void Patch_deform( Patch& patch, scene::Instance& instance, const int deform ){
178 for (PatchControlIter i = patch.begin(); i != patch.end(); ++i)
180 PatchControl& control = *i;
181 int randomNumber = int( deform * (float(std::rand()) / float(RAND_MAX)));
182 control.m_vertex[2] += randomNumber;
185 patch.controlPointsChanged();
188 void Scene_PatchDeform( scene::Graph& graph, const int deform )
190 InstanceVector instances;
191 Scene_forEachVisibleSelectedPatchInstance( PatchStoreInstance( instances ) );
192 for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
194 Patch_deform( *Node_getPatch( ( *i )->path().top() ), *( *i ), deform );
199 void Patch_thicken( Patch& patch, scene::Instance& instance, const float thickness, bool seams, const int axis ){
201 // Create a new patch node
202 NodeSmartReference node( g_patchCreator->createPatch() );
203 // Insert the node into worldspawn
204 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
206 // Retrieve the contained patch from the node
207 Patch* targetPatch = Node_getPatch( node );
209 // Create the opposite patch with the given thickness = distance
212 targetPatch->createThickenedOpposite( patch, thickness, axis, no12, no34 );
214 // Now select the newly created patches
216 scene::Path patchpath( makeReference( GlobalSceneGraph().root() ) );
217 patchpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
218 patchpath.push( makeReference( node.get() ) );
219 Instance_getSelectable( *GlobalSceneGraph().find( patchpath ) )->setSelected( true );
222 if( seams && thickness != 0.0f){
231 // Now create the four walls
232 for ( ; i < iend; i++ ){
233 // Allocate new patch
234 NodeSmartReference node = NodeSmartReference( g_patchCreator->createPatch() );
235 // Insert each node into worldspawn
236 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
238 // Retrieve the contained patch from the node
239 Patch* wallPatch = Node_getPatch( node );
241 // Create the wall patch by passing i as wallIndex
242 wallPatch->createThickenedWall( patch, *targetPatch, i );
244 if( ( wallPatch->localAABB().extents[0] <= 0.00005 && wallPatch->localAABB().extents[1] <= 0.00005 ) ||
245 ( wallPatch->localAABB().extents[1] <= 0.00005 && wallPatch->localAABB().extents[2] <= 0.00005 ) ||
246 ( wallPatch->localAABB().extents[0] <= 0.00005 && wallPatch->localAABB().extents[2] <= 0.00005 ) ){
247 //globalOutputStream() << "Thicken: Discarding degenerate patch.\n";
248 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->erase( node );
251 // Now select the newly created patches
253 scene::Path patchpath( makeReference( GlobalSceneGraph().root() ) );
254 patchpath.push( makeReference( *Map_GetWorldspawn(g_map) ) );
255 patchpath.push( makeReference( node.get() ) );
256 Instance_getSelectable( *GlobalSceneGraph().find( patchpath ) )->setSelected( true );
261 // Invert the target patch so that it faces the opposite direction
262 targetPatch->InvertMatrix();
265 void Scene_PatchThicken( scene::Graph& graph, const int thickness, bool seams, const int axis )
267 InstanceVector instances;
268 Scene_forEachVisibleSelectedPatchInstance( PatchStoreInstance( instances ) );
269 for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
271 Patch_thicken( *Node_getPatch( ( *i )->path().top() ), *( *i ), thickness, seams, axis );
276 Patch* Scene_GetUltimateSelectedVisiblePatch(){
277 if ( GlobalSelectionSystem().countSelected() != 0 ) {
278 scene::Node& node = GlobalSelectionSystem().ultimateSelected().path().top();
279 if ( node.visible() ) {
280 return Node_getPatch( node );
287 class PatchCapTexture
290 void operator()( Patch& patch ) const {
291 patch.ProjectTexture( Patch::m_CycleCapIndex );
295 void Scene_PatchCapTexture_Selected( scene::Graph& graph ){
296 Scene_forEachVisibleSelectedPatch( PatchCapTexture() );
297 Patch::m_CycleCapIndex = ( Patch::m_CycleCapIndex == 0 ) ? 1 : ( Patch::m_CycleCapIndex == 1 ) ? 2 : 0;
301 class PatchFlipTexture
305 PatchFlipTexture( int axis ) : m_axis( axis ){
307 void operator()( Patch& patch ) const {
308 patch.FlipTexture( m_axis );
312 void Scene_PatchFlipTexture_Selected( scene::Graph& graph, int axis ){
313 Scene_forEachVisibleSelectedPatch( PatchFlipTexture( axis ) );
316 class PatchNaturalTexture
319 void operator()( Patch& patch ) const {
320 patch.NaturalTexture();
324 void Scene_PatchNaturalTexture_Selected( scene::Graph& graph ){
325 Scene_forEachVisibleSelectedPatch( PatchNaturalTexture() );
330 class PatchInsertRemove
332 bool m_insert, m_column, m_first;
334 PatchInsertRemove( bool insert, bool column, bool first ) : m_insert( insert ), m_column( column ), m_first( first ){
336 void operator()( Patch& patch ) const {
337 patch.InsertRemove( m_insert, m_column, m_first );
341 void Scene_PatchInsertRemove_Selected( scene::Graph& graph, bool bInsert, bool bColumn, bool bFirst ){
342 Scene_forEachVisibleSelectedPatch( PatchInsertRemove( bInsert, bColumn, bFirst ) );
345 class PatchInvertMatrix
348 void operator()( Patch& patch ) const {
349 patch.InvertMatrix();
353 void Scene_PatchInvert_Selected( scene::Graph& graph ){
354 Scene_forEachVisibleSelectedPatch( PatchInvertMatrix() );
357 class PatchRedisperse
359 EMatrixMajor m_major;
361 PatchRedisperse( EMatrixMajor major ) : m_major( major ){
363 void operator()( Patch& patch ) const {
364 patch.Redisperse( m_major );
368 void Scene_PatchRedisperse_Selected( scene::Graph& graph, EMatrixMajor major ){
369 Scene_forEachVisibleSelectedPatch( PatchRedisperse( major ) );
374 EMatrixMajor m_major;
376 PatchSmooth( EMatrixMajor major ) : m_major( major ){
378 void operator()( Patch& patch ) const {
379 patch.Smooth( m_major );
383 void Scene_PatchSmooth_Selected( scene::Graph& graph, EMatrixMajor major ){
384 Scene_forEachVisibleSelectedPatch( PatchSmooth( major ) );
387 class PatchTransposeMatrix
390 void operator()( Patch& patch ) const {
391 patch.TransposeMatrix();
395 void Scene_PatchTranspose_Selected( scene::Graph& graph ){
396 Scene_forEachVisibleSelectedPatch( PatchTransposeMatrix() );
403 PatchSetShader( const char* name )
406 void operator()( Patch& patch ) const {
407 patch.SetShader( m_name );
411 void Scene_PatchSetShader_Selected( scene::Graph& graph, const char* name ){
412 Scene_forEachVisibleSelectedPatch( PatchSetShader( name ) );
416 void Scene_PatchGetShader_Selected( scene::Graph& graph, CopiedString& name ){
417 Patch* patch = Scene_GetUltimateSelectedVisiblePatch();
419 name = patch->GetShader();
423 class PatchSelectByShader
427 inline PatchSelectByShader( const char* name )
430 void operator()( PatchInstance& patch ) const {
431 if ( shader_equal( patch.getPatch().GetShader(), m_name ) ) {
432 patch.setSelected( true );
437 void Scene_PatchSelectByShader( scene::Graph& graph, const char* name ){
438 Scene_forEachVisiblePatchInstance( PatchSelectByShader( name ) );
442 class PatchFindReplaceShader
445 const char* m_replace;
447 PatchFindReplaceShader( const char* find, const char* replace ) : m_find( find ), m_replace( replace ){
449 void operator()( Patch& patch ) const {
450 if ( shader_equal( patch.GetShader(), m_find ) ) {
451 patch.SetShader( m_replace );
457 bool DoingSearch( const char *repl ){
458 return ( repl == NULL || ( strcmp( "textures/", repl ) == 0 ) );
461 void Scene_PatchFindReplaceShader( scene::Graph& graph, const char* find, const char* replace ){
462 if( DoingSearch( replace ) ){
463 Scene_forEachVisiblePatchInstance( PatchSelectByShader( find ) );
466 Scene_forEachVisiblePatch( PatchFindReplaceShader( find, replace ) );
470 void Scene_PatchFindReplaceShader_Selected( scene::Graph& graph, const char* find, const char* replace ){
471 if( DoingSearch( replace ) ){
472 //do nothing, because alternative is replacing to notex
473 //perhaps deselect ones with not matching shaders here?
476 Scene_forEachVisibleSelectedPatch( PatchFindReplaceShader( find, replace ) );
481 AABB PatchCreator_getBounds(){
482 AABB aabb( aabb_for_minmax( Select_getWorkZone().d_work_min, Select_getWorkZone().d_work_max ) );
484 float gridSize = GetGridSize();
486 if ( aabb.extents[0] == 0 ) {
487 aabb.extents[0] = gridSize;
489 if ( aabb.extents[1] == 0 ) {
490 aabb.extents[1] = gridSize;
492 if ( aabb.extents[2] == 0 ) {
493 aabb.extents[2] = gridSize;
496 if ( aabb_valid( aabb ) ) {
499 return AABB( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
502 void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols );
504 void Patch_XactCylinder(){
505 UndoableCommand undo( "patchCreateXactCylinder" );
507 DoNewPatchDlg( eXactCylinder, 3, 7, 3, 13, 0, 0 );
510 void Patch_XactSphere(){
511 UndoableCommand undo( "patchCreateXactSphere" );
513 DoNewPatchDlg( eXactSphere, 5, 7, 7, 13, 0, 0 );
516 void Patch_XactCone(){
517 UndoableCommand undo( "patchCreateXactCone" );
519 DoNewPatchDlg( eXactCone, 3, 7, 3, 13, 0, 0 );
522 void Patch_Cylinder(){
523 UndoableCommand undo( "patchCreateCylinder" );
525 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eCylinder, GlobalXYWnd_getCurrentViewType() );
528 void Patch_DenseCylinder(){
529 UndoableCommand undo( "patchCreateDenseCylinder" );
531 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eDenseCylinder, GlobalXYWnd_getCurrentViewType() );
534 void Patch_VeryDenseCylinder(){
535 UndoableCommand undo( "patchCreateVeryDenseCylinder" );
537 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eVeryDenseCylinder, GlobalXYWnd_getCurrentViewType() );
540 void Patch_SquareCylinder(){
541 UndoableCommand undo( "patchCreateSquareCylinder" );
543 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eSqCylinder, GlobalXYWnd_getCurrentViewType() );
547 UndoableCommand undo( "patchCreateCaps" );
549 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eEndCap, GlobalXYWnd_getCurrentViewType() );
553 UndoableCommand undo( "patchCreateBevel" );
555 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eBevel, GlobalXYWnd_getCurrentViewType() );
559 UndoableCommand undo( "patchCreateSphere" );
561 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eSphere, GlobalXYWnd_getCurrentViewType() );
564 void Patch_SquareBevel(){
567 void Patch_SquareEndcap(){
571 UndoableCommand undo( "patchCreateCone" );
573 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eCone, GlobalXYWnd_getCurrentViewType() );
577 UndoableCommand undo( "patchCreatePlane" );
579 DoNewPatchDlg( ePlane, 3, 3, 3, 3, 0, 0 );
582 void Patch_InsertInsertColumn(){
583 UndoableCommand undo( "patchInsertColumns" );
585 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, true, false );
588 void Patch_InsertAddColumn(){
589 UndoableCommand undo( "patchAddColumns" );
591 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, true, true );
594 void Patch_InsertInsertRow(){
595 UndoableCommand undo( "patchInsertRows" );
597 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, false, false );
600 void Patch_InsertAddRow(){
601 UndoableCommand undo( "patchAddRows" );
603 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, false, true );
606 void Patch_DeleteFirstColumn(){
607 UndoableCommand undo( "patchDeleteFirstColumns" );
609 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, true, true );
612 void Patch_DeleteLastColumn(){
613 UndoableCommand undo( "patchDeleteLastColumns" );
615 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, true, false );
618 void Patch_DeleteFirstRow(){
619 UndoableCommand undo( "patchDeleteFirstRows" );
621 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, false, true );
624 void Patch_DeleteLastRow(){
625 UndoableCommand undo( "patchDeleteLastRows" );
627 Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, false, false );
631 UndoableCommand undo( "patchInvert" );
633 Scene_PatchInvert_Selected( GlobalSceneGraph() );
636 void Patch_RedisperseRows(){
637 UndoableCommand undo( "patchRedisperseRows" );
639 Scene_PatchRedisperse_Selected( GlobalSceneGraph(), ROW );
642 void Patch_RedisperseCols(){
643 UndoableCommand undo( "patchRedisperseColumns" );
645 Scene_PatchRedisperse_Selected( GlobalSceneGraph(), COL );
648 void Patch_SmoothRows(){
649 UndoableCommand undo( "patchSmoothRows" );
651 Scene_PatchSmooth_Selected( GlobalSceneGraph(), ROW );
654 void Patch_SmoothCols(){
655 UndoableCommand undo( "patchSmoothColumns" );
657 Scene_PatchSmooth_Selected( GlobalSceneGraph(), COL );
660 void Patch_Transpose(){
661 UndoableCommand undo( "patchTranspose" );
663 Scene_PatchTranspose_Selected( GlobalSceneGraph() );
667 // FIXME: add support for patch cap creation
668 // Patch_CapCurrent();
669 UndoableCommand undo( "patchCreateCaps" );
671 Scene_PatchDoCap_Selected( GlobalSceneGraph(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
674 void Patch_CycleProjection(){
675 UndoableCommand undo( "patchCycleUVProjectionAxis" );
677 Scene_PatchCapTexture_Selected( GlobalSceneGraph() );
681 void Patch_OverlayOn(){
685 void Patch_OverlayOff(){
688 void Patch_FlipTextureX(){
689 UndoableCommand undo( "patchFlipTextureU" );
691 Scene_PatchFlipTexture_Selected( GlobalSceneGraph(), 0 );
694 void Patch_FlipTextureY(){
695 UndoableCommand undo( "patchFlipTextureV" );
697 Scene_PatchFlipTexture_Selected( GlobalSceneGraph(), 1 );
700 void Patch_NaturalTexture(){
701 UndoableCommand undo( "patchNaturalTexture" );
703 Scene_PatchNaturalTexture_Selected( GlobalSceneGraph() );
706 void Patch_CapTexture(){
707 UndoableCommand command( "patchCapTexture" );
708 Scene_PatchCapTexture_Selected( GlobalSceneGraph() );
711 void Patch_ResetTexture(){
713 if ( DoTextureLayout( &fx, &fy ) == eIDOK ) {
714 UndoableCommand command( "patchTileTexture" );
715 Scene_PatchTileTexture_Selected( GlobalSceneGraph(), fx, fy );
719 void Patch_FitTexture(){
720 UndoableCommand command( "patchFitTexture" );
721 Scene_PatchTileTexture_Selected( GlobalSceneGraph(), 1, 1 );
724 void DoPatchDeformDlg();
727 UndoableCommand undo( "patchDeform" );
732 void DoPatchThickenDlg();
734 void Patch_Thicken(){
735 UndoableCommand undo( "patchThicken" );
745 class filter_patch_all : public PatchFilter
748 bool filter( const Patch& patch ) const {
753 class filter_patch_shader : public PatchFilter
755 const char* m_shader;
757 filter_patch_shader( const char* shader ) : m_shader( shader ){
759 bool filter( const Patch& patch ) const {
760 return shader_equal( patch.GetShader(), m_shader );
764 class filter_patch_flags : public PatchFilter
768 filter_patch_flags( int flags ) : m_flags( flags ){
770 bool filter( const Patch& patch ) const {
771 return ( patch.getShaderFlags() & m_flags ) != 0;
776 filter_patch_all g_filter_patch_all;
777 filter_patch_flags g_filter_patch_clip( QER_CLIP );
778 filter_patch_shader g_filter_patch_commonclip( "textures/common/clip" );
779 filter_patch_shader g_filter_patch_weapclip( "textures/common/weapclip" );
780 filter_patch_flags g_filter_patch_translucent( QER_TRANS | QER_ALPHATEST );
782 void PatchFilters_construct(){
783 add_patch_filter( g_filter_patch_all, EXCLUDE_CURVES );
784 add_patch_filter( g_filter_patch_clip, EXCLUDE_CLIP );
785 add_patch_filter( g_filter_patch_commonclip, EXCLUDE_CLIP );
786 add_patch_filter( g_filter_patch_weapclip, EXCLUDE_CLIP );
787 add_patch_filter( g_filter_patch_translucent, EXCLUDE_TRANSLUCENT );
791 #include "preferences.h"
793 void Patch_constructPreferences( PreferencesPage& page ){
794 page.appendEntry( "Patch Subdivide Threshold", g_PatchSubdivideThreshold );
796 void Patch_constructPage( PreferenceGroup& group ){
797 PreferencesPage page( group.createPage( "Patches", "Patch Display Preferences" ) );
798 Patch_constructPreferences( page );
800 void Patch_registerPreferencesPage(){
801 PreferencesDialog_addDisplayPage( FreeCaller1<PreferenceGroup&, Patch_constructPage>() );
805 #include "preferencesystem.h"
807 void PatchPreferences_construct(){
808 GlobalPreferenceSystem().registerPreference( "Subdivisions", IntImportStringCaller( g_PatchSubdivideThreshold ), IntExportStringCaller( g_PatchSubdivideThreshold ) );
812 #include "generic/callback.h"
814 void Patch_registerCommands(){
815 GlobalCommands_insert( "InvertCurveTextureX", FreeCaller<Patch_FlipTextureX>(), Accelerator( 'I', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
816 GlobalCommands_insert( "InvertCurveTextureY", FreeCaller<Patch_FlipTextureY>(), Accelerator( 'I', (GdkModifierType)GDK_SHIFT_MASK ) );
817 GlobalCommands_insert( "NaturalizePatch", FreeCaller<Patch_NaturalTexture>(), Accelerator( 'N', (GdkModifierType)GDK_CONTROL_MASK ) );
818 GlobalCommands_insert( "PatchCylinder", FreeCaller<Patch_Cylinder>() );
819 GlobalCommands_insert( "PatchDenseCylinder", FreeCaller<Patch_DenseCylinder>() );
820 GlobalCommands_insert( "PatchVeryDenseCylinder", FreeCaller<Patch_VeryDenseCylinder>() );
821 GlobalCommands_insert( "PatchSquareCylinder", FreeCaller<Patch_SquareCylinder>() );
822 GlobalCommands_insert( "PatchXactCylinder", FreeCaller<Patch_XactCylinder>() );
823 GlobalCommands_insert( "PatchXactSphere", FreeCaller<Patch_XactSphere>() );
824 GlobalCommands_insert( "PatchXactCone", FreeCaller<Patch_XactCone>() );
825 GlobalCommands_insert( "PatchEndCap", FreeCaller<Patch_Endcap>() );
826 GlobalCommands_insert( "PatchBevel", FreeCaller<Patch_Bevel>() );
827 GlobalCommands_insert( "PatchSquareBevel", FreeCaller<Patch_SquareBevel>() );
828 GlobalCommands_insert( "PatchSquareEndcap", FreeCaller<Patch_SquareEndcap>() );
829 GlobalCommands_insert( "PatchCone", FreeCaller<Patch_Cone>() );
830 GlobalCommands_insert( "PatchSphere", FreeCaller<Patch_Sphere>() );
831 GlobalCommands_insert( "SimplePatchMesh", FreeCaller<Patch_Plane>(), Accelerator( 'P', (GdkModifierType)GDK_SHIFT_MASK ) );
832 GlobalCommands_insert( "PatchInsertInsertColumn", FreeCaller<Patch_InsertInsertColumn>(), Accelerator( GDK_KP_Add, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
833 GlobalCommands_insert( "PatchInsertAddColumn", FreeCaller<Patch_InsertAddColumn>() );
834 GlobalCommands_insert( "PatchInsertInsertRow", FreeCaller<Patch_InsertInsertRow>(), Accelerator( GDK_KP_Add, (GdkModifierType)GDK_CONTROL_MASK ) );
835 GlobalCommands_insert( "PatchInsertAddRow", FreeCaller<Patch_InsertAddRow>() );
836 GlobalCommands_insert( "PatchDeleteFirstColumn", FreeCaller<Patch_DeleteFirstColumn>() );
837 GlobalCommands_insert( "PatchDeleteLastColumn", FreeCaller<Patch_DeleteLastColumn>(), Accelerator( GDK_KP_Subtract, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
838 GlobalCommands_insert( "PatchDeleteFirstRow", FreeCaller<Patch_DeleteFirstRow>() );
839 GlobalCommands_insert( "PatchDeleteLastRow", FreeCaller<Patch_DeleteLastRow>(), Accelerator( GDK_KP_Subtract, (GdkModifierType)GDK_CONTROL_MASK ) );
840 GlobalCommands_insert( "InvertCurve", FreeCaller<Patch_Invert>(), Accelerator( 'I', (GdkModifierType)GDK_CONTROL_MASK ) );
841 GlobalCommands_insert( "RedisperseRows", FreeCaller<Patch_RedisperseRows>(), Accelerator( 'E', (GdkModifierType)GDK_CONTROL_MASK ) );
842 GlobalCommands_insert( "RedisperseCols", FreeCaller<Patch_RedisperseCols>(), Accelerator( 'E', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
843 GlobalCommands_insert( "SmoothRows", FreeCaller<Patch_SmoothRows>(), Accelerator( 'W', (GdkModifierType)GDK_CONTROL_MASK ) );
844 GlobalCommands_insert( "SmoothCols", FreeCaller<Patch_SmoothCols>(), Accelerator( 'W', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
845 GlobalCommands_insert( "MatrixTranspose", FreeCaller<Patch_Transpose>(), Accelerator( 'M', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
846 GlobalCommands_insert( "CapCurrentCurve", FreeCaller<Patch_Cap>(), Accelerator( 'C', (GdkModifierType)GDK_SHIFT_MASK ) );
847 GlobalCommands_insert( "CycleCapTexturePatch", FreeCaller<Patch_CycleProjection>(), Accelerator( 'N', (GdkModifierType)GDK_SHIFT_MASK ) );
848 GlobalCommands_insert( "MakeOverlayPatch", FreeCaller<Patch_OverlayOn>(), Accelerator( 'Y' ) );
849 GlobalCommands_insert( "ClearPatchOverlays", FreeCaller<Patch_OverlayOff>(), Accelerator( 'L', (GdkModifierType)GDK_CONTROL_MASK ) );
850 GlobalCommands_insert( "PatchDeform", FreeCaller<Patch_Deform>() );
851 GlobalCommands_insert( "PatchThicken", FreeCaller<Patch_Thicken>() );
854 void Patch_constructToolbar( GtkToolbar* toolbar ){
855 toolbar_append_button( toolbar, "Put caps on the current patch (SHIFT + C)", "curve_cap.png", "CapCurrentCurve" );
858 void Patch_constructMenu( GtkMenu* menu ){
859 create_menu_item_with_mnemonic( menu, "Cylinder", "PatchCylinder" );
861 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "More Cylinders" );
862 if ( g_Layout_enableDetachableMenus.m_value ) {
863 menu_tearoff( menu_in_menu );
865 create_menu_item_with_mnemonic( menu_in_menu, "Dense Cylinder", "PatchDenseCylinder" );
866 create_menu_item_with_mnemonic( menu_in_menu, "Very Dense Cylinder", "PatchVeryDenseCylinder" );
867 create_menu_item_with_mnemonic( menu_in_menu, "Square Cylinder", "PatchSquareCylinder" );
868 create_menu_item_with_mnemonic( menu_in_menu, "Exact Cylinder...", "PatchXactCylinder" );
870 menu_separator( menu );
871 create_menu_item_with_mnemonic( menu, "End cap", "PatchEndCap" );
872 create_menu_item_with_mnemonic( menu, "Bevel", "PatchBevel" );
874 // GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "More End caps, Bevels" );
875 // if ( g_Layout_enableDetachableMenus.m_value ) {
876 // menu_tearoff( menu_in_menu );
878 create_menu_item_with_mnemonic( menu, "Square Endcap", "PatchSquareBevel" );
879 create_menu_item_with_mnemonic( menu, "Square Bevel", "PatchSquareEndcap" );
881 menu_separator( menu );
882 create_menu_item_with_mnemonic( menu, "Cone", "PatchCone" );
883 create_menu_item_with_mnemonic( menu, "Exact Cone...", "PatchXactCone" );
884 menu_separator( menu );
885 create_menu_item_with_mnemonic( menu, "Sphere", "PatchSphere" );
886 create_menu_item_with_mnemonic( menu, "Exact Sphere...", "PatchXactSphere" );
887 menu_separator( menu );
888 create_menu_item_with_mnemonic( menu, "Simple Patch Mesh...", "SimplePatchMesh" );
889 menu_separator( menu );
891 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Insert" );
892 if ( g_Layout_enableDetachableMenus.m_value ) {
893 menu_tearoff( menu_in_menu );
895 create_menu_item_with_mnemonic( menu_in_menu, "Add (2) Columns", "PatchInsertAddColumn" );
896 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Columns", "PatchInsertInsertColumn" );
897 menu_separator( menu_in_menu );
898 create_menu_item_with_mnemonic( menu_in_menu, "Add (2) Rows", "PatchInsertAddRow" );
899 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Rows", "PatchInsertInsertRow" );
902 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Delete" );
903 if ( g_Layout_enableDetachableMenus.m_value ) {
904 menu_tearoff( menu_in_menu );
906 create_menu_item_with_mnemonic( menu_in_menu, "First (2) Columns", "PatchDeleteFirstColumn" );
907 create_menu_item_with_mnemonic( menu_in_menu, "Last (2) Columns", "PatchDeleteLastColumn" );
908 menu_separator( menu_in_menu );
909 create_menu_item_with_mnemonic( menu_in_menu, "First (2) Rows", "PatchDeleteFirstRow" );
910 create_menu_item_with_mnemonic( menu_in_menu, "Last (2) Rows", "PatchDeleteLastRow" );
912 menu_separator( menu );
914 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Matrix" );
915 if ( g_Layout_enableDetachableMenus.m_value ) {
916 menu_tearoff( menu_in_menu );
918 create_menu_item_with_mnemonic( menu_in_menu, "Invert", "InvertCurve" );
919 create_menu_item_with_mnemonic( menu_in_menu, "Transpose", "MatrixTranspose" );
920 // GtkMenu* menu_3 = create_sub_menu_with_mnemonic( menu_in_menu, "Re-disperse" );
921 // if ( g_Layout_enableDetachableMenus.m_value ) {
922 // menu_tearoff( menu_3 );
924 menu_separator( menu_in_menu );
925 create_menu_item_with_mnemonic( menu_in_menu, "Re-disperse Rows", "RedisperseRows" );
926 create_menu_item_with_mnemonic( menu_in_menu, "Re-disperse Columns", "RedisperseCols" );
927 // GtkMenu* menu_4 = create_sub_menu_with_mnemonic( menu_in_menu, "Smooth" );
928 // if ( g_Layout_enableDetachableMenus.m_value ) {
929 // menu_tearoff( menu_4 );
931 menu_separator( menu_in_menu );
932 create_menu_item_with_mnemonic( menu_in_menu, "Smooth Rows", "SmoothRows" );
933 create_menu_item_with_mnemonic( menu_in_menu, "Smooth Columns", "SmoothCols" );
935 menu_separator( menu );
936 create_menu_item_with_mnemonic( menu, "Cap Selection", "CapCurrentCurve" );
937 menu_separator( menu );
939 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Texture" );
940 if ( g_Layout_enableDetachableMenus.m_value ) {
941 menu_tearoff( menu_in_menu );
943 create_menu_item_with_mnemonic( menu_in_menu, "Cycle Projection", "CycleCapTexturePatch" );
944 create_menu_item_with_mnemonic( menu_in_menu, "Naturalize", "NaturalizePatch" );
945 create_menu_item_with_mnemonic( menu_in_menu, "Invert X", "InvertCurveTextureX" );
946 create_menu_item_with_mnemonic( menu_in_menu, "Invert Y", "InvertCurveTextureY" );
949 menu_separator( menu );
951 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Overlay" );
952 if ( g_Layout_enableDetachableMenus.m_value ) {
953 menu_tearoff( menu_in_menu );
955 create_menu_item_with_mnemonic( menu_in_menu, "Set", "MakeOverlayPatch" );
956 create_menu_item_with_mnemonic( menu_in_menu, "Clear", "ClearPatchOverlays" );
958 menu_separator( menu );
959 create_menu_item_with_mnemonic( menu, "Deform...", "PatchDeform" );
960 create_menu_item_with_mnemonic( menu, "Thicken...", "PatchThicken" );
964 #include <gtk/gtkbox.h>
965 #include <gtk/gtktable.h>
966 #include <gtk/gtktogglebutton.h>
967 #include <gtk/gtkradiobutton.h>
968 #include <gtk/gtkcombobox.h>
969 #include <gtk/gtklabel.h>
970 #include "gtkutil/dialog.h"
971 #include "gtkutil/widget.h"
973 void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols ){
978 GtkWindow* window = create_dialog_window( MainFrame_getWindow(), "Patch density", G_CALLBACK( dialog_delete_callback ), &dialog );
980 GtkAccelGroup* accel = gtk_accel_group_new();
981 gtk_window_add_accel_group( window, accel );
984 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
985 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
987 GtkTable* table = create_dialog_table( 2, 2, 4, 4 );
988 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
990 GtkLabel* label = GTK_LABEL( gtk_label_new( "Width:" ) );
991 gtk_widget_show( GTK_WIDGET( label ) );
992 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
993 (GtkAttachOptions) ( GTK_FILL ),
994 (GtkAttachOptions) ( 0 ), 0, 0 );
995 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
998 GtkLabel* label = GTK_LABEL( gtk_label_new( "Height:" ) );
999 gtk_widget_show( GTK_WIDGET( label ) );
1000 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
1001 (GtkAttachOptions) ( GTK_FILL ),
1002 (GtkAttachOptions) ( 0 ), 0, 0 );
1003 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1007 GtkComboBox* combo = GTK_COMBO_BOX( gtk_combo_box_new_text() );
1008 #define D_ITEM( x ) if ( x >= mincols && ( !maxcols || x <= maxcols ) ) gtk_combo_box_append_text( combo, # x )
1023 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
1025 gtk_widget_show( GTK_WIDGET( combo ) );
1026 gtk_table_attach( table, GTK_WIDGET( combo ), 1, 2, 0, 1,
1027 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1028 (GtkAttachOptions) ( 0 ), 0, 0 );
1033 GtkComboBox* combo = GTK_COMBO_BOX( gtk_combo_box_new_text() );
1034 #define D_ITEM( x ) if ( x >= minrows && ( !maxrows || x <= maxrows ) ) gtk_combo_box_append_text( combo, # x )
1049 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
1051 gtk_widget_show( GTK_WIDGET( combo ) );
1052 gtk_table_attach( table, GTK_WIDGET( combo ), 1, 2, 1, 2,
1053 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1054 (GtkAttachOptions) ( 0 ), 0, 0 );
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;
1086 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), prefab, GlobalXYWnd_getCurrentViewType(), w, h );
1089 gtk_widget_destroy( GTK_WIDGET( window ) );
1093 void DoPatchDeformDlg(){
1097 GtkWindow* window = create_dialog_window( MainFrame_getWindow(), "Patch deform", G_CALLBACK( dialog_delete_callback ), &dialog );
1099 GtkAccelGroup* accel = gtk_accel_group_new();
1100 gtk_window_add_accel_group( window, accel );
1103 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
1104 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
1106 GtkTable* table = create_dialog_table( 2, 2, 4, 4 );
1107 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
1109 GtkLabel* label = GTK_LABEL( gtk_label_new( "Max deform:" ) );
1110 gtk_widget_show( GTK_WIDGET( label ) );
1111 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
1112 (GtkAttachOptions) ( GTK_FILL ),
1113 (GtkAttachOptions) ( 0 ), 0, 0 );
1114 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1117 GtkWidget* entry = gtk_entry_new();
1118 gtk_entry_set_text( GTK_ENTRY( entry ), "16" );
1119 gtk_widget_show( entry );
1120 gtk_table_attach( table, entry, 1, 2, 0, 1,
1121 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1122 (GtkAttachOptions) ( 0 ), 0, 0 );
1128 GtkVBox* vbox = create_dialog_vbox( 4 );
1129 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
1131 GtkButton* button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
1132 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1133 widget_make_default( GTK_WIDGET( button ) );
1134 gtk_widget_grab_focus( GTK_WIDGET( button ) );
1135 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
1138 GtkButton* button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
1139 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1140 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
1145 if ( modal_dialog_show( window, dialog ) == eIDOK ) {
1146 int deform = static_cast<int>( atoi( gtk_entry_get_text( GTK_ENTRY( deformW ) ) ) );
1147 Scene_PatchDeform( GlobalSceneGraph(), deform );
1150 gtk_widget_destroy( GTK_WIDGET( window ) );
1155 EMessageBoxReturn DoCapDlg( ECapDialog* type ){
1157 ModalDialogButton ok_button( dialog, eIDOK );
1158 ModalDialogButton cancel_button( dialog, eIDCANCEL );
1163 GtkWidget* cylinder;
1165 GtkWindow* window = create_modal_dialog_window( MainFrame_getWindow(), "Cap", dialog );
1167 GtkAccelGroup *accel_group = gtk_accel_group_new();
1168 gtk_window_add_accel_group( window, accel_group );
1171 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
1172 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
1175 // Gef: Added a vbox to contain the toggle buttons
1176 GtkVBox* radio_vbox = create_dialog_vbox( 4 );
1177 gtk_container_add( GTK_CONTAINER( hbox ), GTK_WIDGET( radio_vbox ) );
1180 GtkTable* table = GTK_TABLE( gtk_table_new( 5, 2, FALSE ) );
1181 gtk_widget_show( GTK_WIDGET( table ) );
1182 gtk_box_pack_start( GTK_BOX( radio_vbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
1183 gtk_table_set_row_spacings( table, 5 );
1184 gtk_table_set_col_spacings( table, 5 );
1187 GtkImage* image = new_local_image( "cap_bevel.png" );
1188 gtk_widget_show( GTK_WIDGET( image ) );
1189 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 0, 1,
1190 (GtkAttachOptions) ( GTK_FILL ),
1191 (GtkAttachOptions) ( 0 ), 0, 0 );
1194 GtkImage* image = new_local_image( "cap_endcap.png" );
1195 gtk_widget_show( GTK_WIDGET( image ) );
1196 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 1, 2,
1197 (GtkAttachOptions) ( GTK_FILL ),
1198 (GtkAttachOptions) ( 0 ), 0, 0 );
1201 GtkImage* image = new_local_image( "cap_ibevel.png" );
1202 gtk_widget_show( GTK_WIDGET( image ) );
1203 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 2, 3,
1204 (GtkAttachOptions) ( GTK_FILL ),
1205 (GtkAttachOptions) ( 0 ), 0, 0 );
1208 GtkImage* image = new_local_image( "cap_iendcap.png" );
1209 gtk_widget_show( GTK_WIDGET( image ) );
1210 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 3, 4,
1211 (GtkAttachOptions) ( GTK_FILL ),
1212 (GtkAttachOptions) ( 0 ), 0, 0 );
1215 GtkImage* image = new_local_image( "cap_cylinder.png" );
1216 gtk_widget_show( GTK_WIDGET( image ) );
1217 gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 4, 5,
1218 (GtkAttachOptions) ( GTK_FILL ),
1219 (GtkAttachOptions) ( 0 ), 0, 0 );
1224 GtkWidget* button = gtk_radio_button_new_with_label( group, "Bevel" );
1225 gtk_widget_show( button );
1226 gtk_table_attach( table, button, 1, 2, 0, 1,
1227 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1228 (GtkAttachOptions) ( 0 ), 0, 0 );
1229 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1234 GtkWidget* button = gtk_radio_button_new_with_label( group, "Endcap" );
1235 gtk_widget_show( button );
1236 gtk_table_attach( table, button, 1, 2, 1, 2,
1237 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1238 (GtkAttachOptions) ( 0 ), 0, 0 );
1239 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1244 GtkWidget* button = gtk_radio_button_new_with_label( group, "Inverted Bevel" );
1245 gtk_widget_show( button );
1246 gtk_table_attach( table, button, 1, 2, 2, 3,
1247 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1248 (GtkAttachOptions) ( 0 ), 0, 0 );
1249 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1254 GtkWidget* button = gtk_radio_button_new_with_label( group, "Inverted Endcap" );
1255 gtk_widget_show( button );
1256 gtk_table_attach( table, button, 1, 2, 3, 4,
1257 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1258 (GtkAttachOptions) ( 0 ), 0, 0 );
1259 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1264 GtkWidget* button = gtk_radio_button_new_with_label( group, "Cylinder" );
1265 gtk_widget_show( button );
1266 gtk_table_attach( table, button, 1, 2, 4, 5,
1267 (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1268 (GtkAttachOptions) ( 0 ), 0, 0 );
1269 group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1277 GtkVBox* vbox = create_dialog_vbox( 4 );
1278 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), FALSE, FALSE, 0 );
1280 GtkButton* button = create_modal_dialog_button( "OK", ok_button );
1281 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1282 widget_make_default( GTK_WIDGET( button ) );
1283 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel_group, GDK_Return, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
1286 GtkButton* button = create_modal_dialog_button( "Cancel", cancel_button );
1287 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1288 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel_group, GDK_Escape, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
1293 // Initialize dialog
1294 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( bevel ), TRUE );
1296 EMessageBoxReturn ret = modal_dialog_show( window, dialog );
1297 if ( ret == eIDOK ) {
1298 if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( bevel ) ) ) {
1299 *type = PATCHCAP_BEVEL;
1301 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( endcap ) ) ) {
1302 *type = PATCHCAP_ENDCAP;
1304 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( ibevel ) ) ) {
1305 *type = PATCHCAP_INVERTED_BEVEL;
1307 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( iendcap ) ) ) {
1308 *type = PATCHCAP_INVERTED_ENDCAP;
1310 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( cylinder ) ) ) {
1311 *type = PATCHCAP_CYLINDER;
1315 gtk_widget_destroy( GTK_WIDGET( window ) );
1321 void DoPatchThickenDlg(){
1323 GtkWidget* thicknessW;
1328 GtkWidget* radNormals;
1330 GtkWindow* window = create_dialog_window( MainFrame_getWindow(), "Patch thicken", G_CALLBACK( dialog_delete_callback ), &dialog );
1332 GtkAccelGroup* accel = gtk_accel_group_new();
1333 gtk_window_add_accel_group( window, accel );
1336 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
1337 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
1339 GtkTable* table = create_dialog_table( 2, 4, 4, 4 );
1340 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
1342 GtkLabel* label = GTK_LABEL( gtk_label_new( "Thickness:" ) );
1343 gtk_widget_show( GTK_WIDGET( label ) );
1344 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
1345 (GtkAttachOptions) ( GTK_FILL ),
1346 (GtkAttachOptions) ( 0 ), 0, 0 );
1347 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1350 GtkWidget* entry = gtk_entry_new();
1351 gtk_entry_set_text( GTK_ENTRY( entry ), "16" );
1352 gtk_widget_set_size_request( entry, 40, -1 );
1353 gtk_widget_show( entry );
1354 gtk_table_attach( table, entry, 1, 2, 0, 1,
1355 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1356 (GtkAttachOptions) ( 0 ), 0, 0 );
1361 // Create the "create seams" label
1362 GtkWidget* _seamsCheckBox = gtk_check_button_new_with_label( "Side walls" );
1363 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( _seamsCheckBox ), TRUE );
1364 gtk_widget_show( _seamsCheckBox );
1365 gtk_table_attach( table, _seamsCheckBox, 3, 4, 0, 1,
1366 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1367 (GtkAttachOptions) ( 0 ), 0, 0 );
1368 seamsW = _seamsCheckBox;
1372 // Create the radio button group for choosing the extrude axis
1373 GtkWidget* _radNormals = gtk_radio_button_new_with_label( NULL, "Normal" );
1374 GtkWidget* _radX = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "X" );
1375 GtkWidget* _radY = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "Y" );
1376 GtkWidget* _radZ = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "Z" );
1377 gtk_widget_show( _radNormals );
1378 gtk_widget_show( _radX );
1379 gtk_widget_show( _radY );
1380 gtk_widget_show( _radZ );
1383 // Pack the buttons into the table
1384 gtk_table_attach( table, _radNormals, 0, 1, 1, 2,
1385 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1386 (GtkAttachOptions) ( 0 ), 0, 0 );
1387 gtk_table_attach( table, _radX, 1, 2, 1, 2,
1388 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1389 (GtkAttachOptions) ( 0 ), 0, 0 );
1390 gtk_table_attach( table, _radY, 2, 3, 1, 2,
1391 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1392 (GtkAttachOptions) ( 0 ), 0, 0 );
1393 gtk_table_attach( table, _radZ, 3, 4, 1, 2,
1394 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1395 (GtkAttachOptions) ( 0 ), 0, 0 );
1399 radNormals = _radNormals;
1403 GtkVBox* vbox = create_dialog_vbox( 4 );
1404 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
1406 GtkButton* button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
1407 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1408 widget_make_default( GTK_WIDGET( button ) );
1409 gtk_widget_grab_focus( GTK_WIDGET( button ) );
1410 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
1413 GtkButton* button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
1414 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1415 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
1420 if ( modal_dialog_show( window, dialog ) == eIDOK ) {
1423 float thickness = static_cast<float>( atoi( gtk_entry_get_text( GTK_ENTRY( thicknessW ) ) ) );
1424 seams = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( seamsW )) ? true : false;
1426 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radX))) {
1429 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radY))) {
1432 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radZ))) {
1436 // Extrude along normals
1439 Scene_PatchThicken( GlobalSceneGraph(), thickness, seams, axis );
1442 gtk_widget_destroy( GTK_WIDGET( window ) );