]> git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/patchmanip.cpp
e7f543dc27ff71cc1f15b64081be4a4ee3cf30c0
[xonotic/netradiant.git] / radiant / patchmanip.cpp
1 /*
2    Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3    For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5    This file is part of GtkRadiant.
6
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.
11
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.
16
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
20  */
21
22 #include "patchmanip.h"
23
24 #include "debugging/debugging.h"
25
26
27 #include "iselection.h"
28 #include "ipatch.h"
29
30 #include "math/vector.h"
31 #include "math/aabb.h"
32 #include "generic/callback.h"
33
34 #include "gtkutil/menu.h"
35 #include "gtkutil/image.h"
36 #include "map.h"
37 #include "mainframe.h"
38 #include "commands.h"
39 #include "gtkmisc.h"
40 #include "gtkdlgs.h"
41 #include "texwindow.h"
42 #include "xywindow.h"
43 #include "select.h"
44 #include "patch.h"
45 #include "grid.h"
46
47 PatchCreator* g_patchCreator = 0;
48
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 ){
50         Select_Delete();
51         GlobalSelectionSystem().setSelectedAll( false );
52
53         NodeSmartReference node( g_patchCreator->createPatch() );
54         Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
55
56         Patch* patch = Node_getPatch( node );
57         patch->SetShader( shader );
58
59         patch->ConstructPrefab( aabb, eType, axis, width, height );
60         patch->controlPointsChanged();
61
62         {
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 );
67         }
68 }
69
70
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";
75                 return;
76         }
77         if ( ( type == eCapBevel || type == eCapIBevel )
78                  && patch.getWidth() != 3 && patch.getWidth() != 5 ) {
79                 globalErrorStream() << "cannot create bevel-cap - patch width != 3\n";
80                 return;
81         }
82         if ( type == eCapCylinder
83                  && patch.getWidth() != 9 ) {
84                 globalErrorStream() << "cannot create cylinder-cap - patch width != 9\n";
85                 return;
86         }
87
88         {
89                 NodeSmartReference cap( g_patchCreator->createPatch() );
90                 Node_getTraversable( instance.path().parent() )->insert( cap );
91
92                 patch.MakeCap( Node_getPatch( cap ), type, ROW, true );
93                 Node_getPatch( cap )->SetShader( shader );
94
95                 scene::Path path( instance.path() );
96                 path.pop();
97                 path.push( makeReference( cap.get() ) );
98                 selectPath( path, true );
99         }
100
101         {
102                 NodeSmartReference cap( g_patchCreator->createPatch() );
103                 Node_getTraversable( instance.path().parent() )->insert( cap );
104
105                 patch.MakeCap( Node_getPatch( cap ), type, ROW, false );
106                 Node_getPatch( cap )->SetShader( shader );
107
108                 scene::Path path( instance.path() );
109                 path.pop();
110                 path.push( makeReference( cap.get() ) );
111                 selectPath( path, true );
112         }
113 }
114
115 typedef std::vector<scene::Instance*> InstanceVector;
116
117 class PatchStoreInstance
118 {
119 InstanceVector& m_instances;
120 public:
121 PatchStoreInstance( InstanceVector& instances ) : m_instances( instances ){
122 }
123 void operator()( PatchInstance& patch ) const {
124         m_instances.push_back( &patch );
125 }
126 };
127
128 enum ECapDialog {
129         PATCHCAP_BEVEL = 0,
130         PATCHCAP_ENDCAP,
131         PATCHCAP_INVERTED_BEVEL,
132         PATCHCAP_INVERTED_ENDCAP,
133         PATCHCAP_CYLINDER
134 };
135
136 EMessageBoxReturn DoCapDlg( ECapDialog *type );
137
138 void Scene_PatchDoCap_Selected( scene::Graph& graph, const char* shader ){
139         ECapDialog nType;
140
141         if ( DoCapDlg( &nType ) == eIDOK ) {
142                 EPatchCap eType;
143                 switch ( nType )
144                 {
145                 case PATCHCAP_INVERTED_BEVEL:
146                         eType = eCapIBevel;
147                         break;
148                 case PATCHCAP_BEVEL:
149                         eType = eCapBevel;
150                         break;
151                 case PATCHCAP_INVERTED_ENDCAP:
152                         eType = eCapIEndCap;
153                         break;
154                 case PATCHCAP_ENDCAP:
155                         eType = eCapEndCap;
156                         break;
157                 case PATCHCAP_CYLINDER:
158                         eType = eCapCylinder;
159                         break;
160                 default:
161                         ERROR_MESSAGE( "invalid patch cap type" );
162                         return;
163                 }
164
165                 InstanceVector instances;
166                 Scene_forEachVisibleSelectedPatchInstance( PatchStoreInstance( instances ) );
167                 for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
168                 {
169                         Patch_makeCaps( *Node_getPatch( ( *i )->path().top() ), *( *i ), eType, shader );
170                 }
171         }
172 }
173
174 Patch* Scene_GetUltimateSelectedVisiblePatch(){
175         if ( GlobalSelectionSystem().countSelected() != 0 ) {
176                 scene::Node& node = GlobalSelectionSystem().ultimateSelected().path().top();
177                 if ( node.visible() ) {
178                         return Node_getPatch( node );
179                 }
180         }
181         return 0;
182 }
183
184
185 class PatchCapTexture
186 {
187 public:
188 void operator()( Patch& patch ) const {
189         patch.ProjectTexture( Patch::m_CycleCapIndex );
190 }
191 };
192
193 void Scene_PatchCapTexture_Selected( scene::Graph& graph ){
194         Scene_forEachVisibleSelectedPatch( PatchCapTexture() );
195         Patch::m_CycleCapIndex = ( Patch::m_CycleCapIndex == 0 ) ? 1 : ( Patch::m_CycleCapIndex == 1 ) ? 2 : 0;
196         SceneChangeNotify();
197 }
198
199
200 void PatchAutoCapTexture( Patch& patch ) {
201
202         AABB box = patch.localAABB();
203         float x = box.extents.x();
204         float y = box.extents.y();
205         float z = box.extents.z();
206
207         int cap_direction = -1;
208         if ( x < y  && x < z )
209                 cap_direction = 0;
210         else if ( y < x  && y < z )
211                 cap_direction = 1;
212         else if ( z < x  && z < x )
213                 cap_direction = 2;
214
215         if ( cap_direction >= 0 )
216                 patch.ProjectTexture(cap_direction);
217         else
218                 patch.NaturalTexture();
219 }
220
221 void Patch_AutoCapTexture(){
222         UndoableCommand command( "patchAutoCapTexture" );
223         Scene_forEachVisibleSelectedPatch( &PatchAutoCapTexture );
224         SceneChangeNotify();
225 }
226
227 class PatchFlipTexture
228 {
229 int m_axis;
230 public:
231 PatchFlipTexture( int axis ) : m_axis( axis ){
232 }
233 void operator()( Patch& patch ) const {
234         patch.FlipTexture( m_axis );
235 }
236 };
237
238 void Scene_PatchFlipTexture_Selected( scene::Graph& graph, int axis ){
239         Scene_forEachVisibleSelectedPatch( PatchFlipTexture( axis ) );
240 }
241
242 class PatchNaturalTexture
243 {
244 public:
245 void operator()( Patch& patch ) const {
246         patch.NaturalTexture();
247 }
248 };
249
250 void Scene_PatchNaturalTexture_Selected( scene::Graph& graph ){
251         Scene_forEachVisibleSelectedPatch( PatchNaturalTexture() );
252         SceneChangeNotify();
253 }
254
255
256 class PatchInsertRemove
257 {
258 bool m_insert, m_column, m_first;
259 public:
260 PatchInsertRemove( bool insert, bool column, bool first ) : m_insert( insert ), m_column( column ), m_first( first ){
261 }
262 void operator()( Patch& patch ) const {
263         patch.InsertRemove( m_insert, m_column, m_first );
264 }
265 };
266
267 void Scene_PatchInsertRemove_Selected( scene::Graph& graph, bool bInsert, bool bColumn, bool bFirst ){
268         Scene_forEachVisibleSelectedPatch( PatchInsertRemove( bInsert, bColumn, bFirst ) );
269 }
270
271 class PatchInvertMatrix
272 {
273 public:
274 void operator()( Patch& patch ) const {
275         patch.InvertMatrix();
276 }
277 };
278
279 void Scene_PatchInvert_Selected( scene::Graph& graph ){
280         Scene_forEachVisibleSelectedPatch( PatchInvertMatrix() );
281 }
282
283 class PatchRedisperse
284 {
285 EMatrixMajor m_major;
286 public:
287 PatchRedisperse( EMatrixMajor major ) : m_major( major ){
288 }
289 void operator()( Patch& patch ) const {
290         patch.Redisperse( m_major );
291 }
292 };
293
294 void Scene_PatchRedisperse_Selected( scene::Graph& graph, EMatrixMajor major ){
295         Scene_forEachVisibleSelectedPatch( PatchRedisperse( major ) );
296 }
297
298 class PatchSmooth
299 {
300 EMatrixMajor m_major;
301 public:
302 PatchSmooth( EMatrixMajor major ) : m_major( major ){
303 }
304 void operator()( Patch& patch ) const {
305         patch.Smooth( m_major );
306 }
307 };
308
309 void Scene_PatchSmooth_Selected( scene::Graph& graph, EMatrixMajor major ){
310         Scene_forEachVisibleSelectedPatch( PatchSmooth( major ) );
311 }
312
313 class PatchTransposeMatrix
314 {
315 public:
316 void operator()( Patch& patch ) const {
317         patch.TransposeMatrix();
318 }
319 };
320
321 void Scene_PatchTranspose_Selected( scene::Graph& graph ){
322         Scene_forEachVisibleSelectedPatch( PatchTransposeMatrix() );
323 }
324
325 class PatchSetShader
326 {
327 const char* m_name;
328 public:
329 PatchSetShader( const char* name )
330         : m_name( name ){
331 }
332 void operator()( Patch& patch ) const {
333         patch.SetShader( m_name );
334 }
335 };
336
337 void Scene_PatchSetShader_Selected( scene::Graph& graph, const char* name ){
338         Scene_forEachVisibleSelectedPatch( PatchSetShader( name ) );
339         SceneChangeNotify();
340 }
341
342 void Scene_PatchGetShader_Selected( scene::Graph& graph, CopiedString& name ){
343         Patch* patch = Scene_GetUltimateSelectedVisiblePatch();
344         if ( patch != 0 ) {
345                 name = patch->GetShader();
346         }
347 }
348
349 class PatchSelectByShader
350 {
351 const char* m_name;
352 public:
353 inline PatchSelectByShader( const char* name )
354         : m_name( name ){
355 }
356 void operator()( PatchInstance& patch ) const {
357         if ( shader_equal( patch.getPatch().GetShader(), m_name ) ) {
358                 patch.setSelected( true );
359         }
360 }
361 };
362
363 void Scene_PatchSelectByShader( scene::Graph& graph, const char* name ){
364         Scene_forEachVisiblePatchInstance( PatchSelectByShader( name ) );
365 }
366
367
368 class PatchFindReplaceShader
369 {
370 const char* m_find;
371 const char* m_replace;
372 public:
373 PatchFindReplaceShader( const char* find, const char* replace ) : m_find( find ), m_replace( replace ){
374 }
375 void operator()( Patch& patch ) const {
376         if ( shader_equal( patch.GetShader(), m_find ) ) {
377                 patch.SetShader( m_replace );
378         }
379 }
380 };
381
382 void Scene_PatchFindReplaceShader( scene::Graph& graph, const char* find, const char* replace ){
383         Scene_forEachVisiblePatch( PatchFindReplaceShader( find, replace ) );
384 }
385
386 void Scene_PatchFindReplaceShader_Selected( scene::Graph& graph, const char* find, const char* replace ){
387         Scene_forEachVisibleSelectedPatch( PatchFindReplaceShader( find, replace ) );
388 }
389
390
391 AABB PatchCreator_getBounds(){
392         AABB aabb( aabb_for_minmax( Select_getWorkZone().d_work_min, Select_getWorkZone().d_work_max ) );
393
394         float gridSize = GetGridSize();
395
396         if ( aabb.extents[0] == 0 ) {
397                 aabb.extents[0] = gridSize;
398         }
399         if ( aabb.extents[1] == 0 ) {
400                 aabb.extents[1] = gridSize;
401         }
402         if ( aabb.extents[2] == 0 ) {
403                 aabb.extents[2] = gridSize;
404         }
405
406         if ( aabb_valid( aabb ) ) {
407                 return aabb;
408         }
409         return AABB( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
410 }
411
412 void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols );
413
414 void Patch_XactCylinder(){
415         UndoableCommand undo( "patchCreateXactCylinder" );
416
417         DoNewPatchDlg( eXactCylinder, 3, 7, 3, 13, 0, 0 );
418 }
419
420 void Patch_XactSphere(){
421         UndoableCommand undo( "patchCreateXactSphere" );
422
423         DoNewPatchDlg( eXactSphere, 5, 7, 7, 13, 0, 0 );
424 }
425
426 void Patch_XactCone(){
427         UndoableCommand undo( "patchCreateXactCone" );
428
429         DoNewPatchDlg( eXactCone, 3, 7, 3, 13, 0, 0 );
430 }
431
432 void Patch_Cylinder(){
433         UndoableCommand undo( "patchCreateCylinder" );
434
435         Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eCylinder, GlobalXYWnd_getCurrentViewType() );
436 }
437
438 void Patch_DenseCylinder(){
439         UndoableCommand undo( "patchCreateDenseCylinder" );
440
441         Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eDenseCylinder, GlobalXYWnd_getCurrentViewType() );
442 }
443
444 void Patch_VeryDenseCylinder(){
445         UndoableCommand undo( "patchCreateVeryDenseCylinder" );
446
447         Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eVeryDenseCylinder, GlobalXYWnd_getCurrentViewType() );
448 }
449
450 void Patch_SquareCylinder(){
451         UndoableCommand undo( "patchCreateSquareCylinder" );
452
453         Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eSqCylinder, GlobalXYWnd_getCurrentViewType() );
454 }
455
456 void Patch_Endcap(){
457         UndoableCommand undo( "patchCreateCaps" );
458
459         Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eEndCap, GlobalXYWnd_getCurrentViewType() );
460 }
461
462 void Patch_Bevel(){
463         UndoableCommand undo( "patchCreateBevel" );
464
465         Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eBevel, GlobalXYWnd_getCurrentViewType() );
466 }
467
468 void Patch_Sphere(){
469         UndoableCommand undo( "patchCreateSphere" );
470
471         Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eSphere, GlobalXYWnd_getCurrentViewType() );
472 }
473
474 void Patch_SquareBevel(){
475 }
476
477 void Patch_SquareEndcap(){
478 }
479
480 void Patch_Cone(){
481         UndoableCommand undo( "patchCreateCone" );
482
483         Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eCone, GlobalXYWnd_getCurrentViewType() );
484 }
485
486 void Patch_Plane(){
487         UndoableCommand undo( "patchCreatePlane" );
488
489         DoNewPatchDlg( ePlane, 3, 3, 3, 3, 0, 0 );
490 }
491
492 void Patch_InsertInsertColumn(){
493         UndoableCommand undo( "patchInsertColumns" );
494
495         Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, true, false );
496 }
497
498 void Patch_InsertAddColumn(){
499         UndoableCommand undo( "patchAddColumns" );
500
501         Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, true, true );
502 }
503
504 void Patch_InsertInsertRow(){
505         UndoableCommand undo( "patchInsertRows" );
506
507         Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, false, false );
508 }
509
510 void Patch_InsertAddRow(){
511         UndoableCommand undo( "patchAddRows" );
512
513         Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, false, true );
514 }
515
516 void Patch_DeleteFirstColumn(){
517         UndoableCommand undo( "patchDeleteFirstColumns" );
518
519         Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, true, true );
520 }
521
522 void Patch_DeleteLastColumn(){
523         UndoableCommand undo( "patchDeleteLastColumns" );
524
525         Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, true, false );
526 }
527
528 void Patch_DeleteFirstRow(){
529         UndoableCommand undo( "patchDeleteFirstRows" );
530
531         Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, false, true );
532 }
533
534 void Patch_DeleteLastRow(){
535         UndoableCommand undo( "patchDeleteLastRows" );
536
537         Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, false, false );
538 }
539
540 void Patch_Invert(){
541         UndoableCommand undo( "patchInvert" );
542
543         Scene_PatchInvert_Selected( GlobalSceneGraph() );
544 }
545
546 void Patch_RedisperseRows(){
547         UndoableCommand undo( "patchRedisperseRows" );
548
549         Scene_PatchRedisperse_Selected( GlobalSceneGraph(), ROW );
550 }
551
552 void Patch_RedisperseCols(){
553         UndoableCommand undo( "patchRedisperseColumns" );
554
555         Scene_PatchRedisperse_Selected( GlobalSceneGraph(), COL );
556 }
557
558 void Patch_SmoothRows(){
559         UndoableCommand undo( "patchSmoothRows" );
560
561         Scene_PatchSmooth_Selected( GlobalSceneGraph(), ROW );
562 }
563
564 void Patch_SmoothCols(){
565         UndoableCommand undo( "patchSmoothColumns" );
566
567         Scene_PatchSmooth_Selected( GlobalSceneGraph(), COL );
568 }
569
570 void Patch_Transpose(){
571         UndoableCommand undo( "patchTranspose" );
572
573         Scene_PatchTranspose_Selected( GlobalSceneGraph() );
574 }
575
576 void Patch_Cap(){
577         // FIXME: add support for patch cap creation
578         // Patch_CapCurrent();
579         UndoableCommand undo( "patchCreateCaps" );
580
581         Scene_PatchDoCap_Selected( GlobalSceneGraph(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
582 }
583
584 void Patch_CycleProjection(){
585         UndoableCommand undo( "patchCycleUVProjectionAxis" );
586
587         Scene_PatchCapTexture_Selected( GlobalSceneGraph() );
588 }
589
590 ///\todo Unfinished.
591 void Patch_OverlayOn(){
592 }
593
594 ///\todo Unfinished.
595 void Patch_OverlayOff(){
596 }
597
598 void Patch_FlipTextureX(){
599         UndoableCommand undo( "patchFlipTextureU" );
600
601         Scene_PatchFlipTexture_Selected( GlobalSceneGraph(), 0 );
602 }
603
604 void Patch_FlipTextureY(){
605         UndoableCommand undo( "patchFlipTextureV" );
606
607         Scene_PatchFlipTexture_Selected( GlobalSceneGraph(), 1 );
608 }
609
610 void Patch_NaturalTexture(){
611         UndoableCommand undo( "patchNaturalTexture" );
612
613         Scene_PatchNaturalTexture_Selected( GlobalSceneGraph() );
614 }
615
616 void Patch_CapTexture(){
617         UndoableCommand command( "patchCapTexture" );
618
619         Scene_PatchCapTexture_Selected( GlobalSceneGraph() );
620 }
621
622 void Patch_ResetTexture(){
623         float fx, fy;
624         if ( DoTextureLayout( &fx, &fy ) == eIDOK ) {
625                 UndoableCommand command( "patchTileTexture" );
626                 Scene_PatchTileTexture_Selected( GlobalSceneGraph(), fx, fy );
627         }
628 }
629
630 void Patch_FitTexture(){
631         UndoableCommand command( "patchFitTexture" );
632
633         Scene_PatchTileTexture_Selected( GlobalSceneGraph(), 1, 1 );
634 }
635
636 #include "ifilter.h"
637
638
639 class filter_patch_all : public PatchFilter
640 {
641 public:
642 bool filter( const Patch& patch ) const {
643         return true;
644 }
645 };
646
647 class filter_patch_shader : public PatchFilter
648 {
649 const char* m_shader;
650 public:
651 filter_patch_shader( const char* shader ) : m_shader( shader ){
652 }
653 bool filter( const Patch& patch ) const {
654         return shader_equal( patch.GetShader(), m_shader );
655 }
656 };
657
658 class filter_patch_flags : public PatchFilter
659 {
660 int m_flags;
661 public:
662 filter_patch_flags( int flags ) : m_flags( flags ){
663 }
664 bool filter( const Patch& patch ) const {
665         return ( patch.getShaderFlags() & m_flags ) != 0;
666 }
667 };
668
669
670 filter_patch_all g_filter_patch_all;
671 filter_patch_shader g_filter_patch_clip( "textures/common/clip" );
672 filter_patch_shader g_filter_patch_weapclip( "textures/common/weapclip" );
673 filter_patch_flags g_filter_patch_translucent( QER_TRANS );
674
675 void PatchFilters_construct(){
676         add_patch_filter( g_filter_patch_all, EXCLUDE_CURVES );
677         add_patch_filter( g_filter_patch_clip, EXCLUDE_CLIP );
678         add_patch_filter( g_filter_patch_weapclip, EXCLUDE_CLIP );
679         add_patch_filter( g_filter_patch_translucent, EXCLUDE_TRANSLUCENT );
680 }
681
682
683 #include "preferences.h"
684
685 void Patch_constructPreferences( PreferencesPage& page ){
686         page.appendEntry( "Patch Subdivide Threshold", g_PatchSubdivideThreshold );
687 }
688 void Patch_constructPage( PreferenceGroup& group ){
689         PreferencesPage page( group.createPage( "Patches", "Patch Display Preferences" ) );
690         Patch_constructPreferences( page );
691 }
692 void Patch_registerPreferencesPage(){
693         PreferencesDialog_addDisplayPage( FreeCaller1<PreferenceGroup&, Patch_constructPage>() );
694 }
695
696
697 #include "preferencesystem.h"
698
699 void PatchPreferences_construct(){
700         GlobalPreferenceSystem().registerPreference( "Subdivisions", IntImportStringCaller( g_PatchSubdivideThreshold ), IntExportStringCaller( g_PatchSubdivideThreshold ) );
701 }
702
703
704 #include "generic/callback.h"
705
706 void Patch_registerCommands(){
707         GlobalCommands_insert( "InvertCurveTextureX", FreeCaller<Patch_FlipTextureX>(), Accelerator( 'I', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
708         GlobalCommands_insert( "InvertCurveTextureY", FreeCaller<Patch_FlipTextureY>(), Accelerator( 'I', (GdkModifierType)GDK_SHIFT_MASK ) );
709         GlobalCommands_insert( "NaturalizePatch", FreeCaller<Patch_NaturalTexture>(), Accelerator( 'N', (GdkModifierType)GDK_CONTROL_MASK ) );
710         GlobalCommands_insert( "PatchCylinder", FreeCaller<Patch_Cylinder>() );
711         GlobalCommands_insert( "PatchDenseCylinder", FreeCaller<Patch_DenseCylinder>() );
712         GlobalCommands_insert( "PatchVeryDenseCylinder", FreeCaller<Patch_VeryDenseCylinder>() );
713         GlobalCommands_insert( "PatchSquareCylinder", FreeCaller<Patch_SquareCylinder>() );
714         GlobalCommands_insert( "PatchXactCylinder", FreeCaller<Patch_XactCylinder>() );
715         GlobalCommands_insert( "PatchXactSphere", FreeCaller<Patch_XactSphere>() );
716         GlobalCommands_insert( "PatchXactCone", FreeCaller<Patch_XactCone>() );
717         GlobalCommands_insert( "PatchEndCap", FreeCaller<Patch_Endcap>() );
718         GlobalCommands_insert( "PatchBevel", FreeCaller<Patch_Bevel>() );
719         GlobalCommands_insert( "PatchSquareBevel", FreeCaller<Patch_SquareBevel>() );
720         GlobalCommands_insert( "PatchSquareEndcap", FreeCaller<Patch_SquareEndcap>() );
721         GlobalCommands_insert( "PatchCone", FreeCaller<Patch_Cone>() );
722         GlobalCommands_insert( "PatchSphere", FreeCaller<Patch_Sphere>() );
723         GlobalCommands_insert( "SimplePatchMesh", FreeCaller<Patch_Plane>(), Accelerator( 'P', (GdkModifierType)GDK_SHIFT_MASK ) );
724         GlobalCommands_insert( "PatchInsertInsertColumn", FreeCaller<Patch_InsertInsertColumn>(), Accelerator( GDK_KP_Add, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
725         GlobalCommands_insert( "PatchInsertAddColumn", FreeCaller<Patch_InsertAddColumn>() );
726         GlobalCommands_insert( "PatchInsertInsertRow", FreeCaller<Patch_InsertInsertRow>(), Accelerator( GDK_KP_Add, (GdkModifierType)GDK_CONTROL_MASK ) );
727         GlobalCommands_insert( "PatchInsertAddRow", FreeCaller<Patch_InsertAddRow>() );
728         GlobalCommands_insert( "PatchDeleteFirstColumn", FreeCaller<Patch_DeleteFirstColumn>() );
729         GlobalCommands_insert( "PatchDeleteLastColumn", FreeCaller<Patch_DeleteLastColumn>(), Accelerator( GDK_KP_Subtract, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
730         GlobalCommands_insert( "PatchDeleteFirstRow", FreeCaller<Patch_DeleteFirstRow>(), Accelerator( GDK_KP_Subtract, (GdkModifierType)GDK_CONTROL_MASK ) );
731         GlobalCommands_insert( "PatchDeleteLastRow", FreeCaller<Patch_DeleteLastRow>() );
732         GlobalCommands_insert( "InvertCurve", FreeCaller<Patch_Invert>(), Accelerator( 'I', (GdkModifierType)GDK_CONTROL_MASK ) );
733         GlobalCommands_insert( "RedisperseRows", FreeCaller<Patch_RedisperseRows>(), Accelerator( 'E', (GdkModifierType)GDK_CONTROL_MASK ) );
734         GlobalCommands_insert( "RedisperseCols", FreeCaller<Patch_RedisperseCols>(), Accelerator( 'E', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
735         GlobalCommands_insert( "SmoothRows", FreeCaller<Patch_SmoothRows>(), Accelerator( 'W', (GdkModifierType)GDK_CONTROL_MASK ) );
736         GlobalCommands_insert( "SmoothCols", FreeCaller<Patch_SmoothCols>(), Accelerator( 'W', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
737         GlobalCommands_insert( "MatrixTranspose", FreeCaller<Patch_Transpose>(), Accelerator( 'M', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
738         GlobalCommands_insert( "CapCurrentCurve", FreeCaller<Patch_Cap>(), Accelerator( 'C', (GdkModifierType)GDK_SHIFT_MASK ) );
739         GlobalCommands_insert( "CycleCapTexturePatch", FreeCaller<Patch_CycleProjection>(), Accelerator( 'N', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
740         GlobalCommands_insert( "MakeOverlayPatch", FreeCaller<Patch_OverlayOn>(), Accelerator( 'Y' ) );
741         GlobalCommands_insert( "ClearPatchOverlays", FreeCaller<Patch_OverlayOff>(), Accelerator( 'L', (GdkModifierType)GDK_CONTROL_MASK ) );
742 }
743
744 void Patch_constructToolbar( GtkToolbar* toolbar ){
745         toolbar_append_button( toolbar, "Put caps on the current patch (SHIFT + C)", "curve_cap.bmp", "CapCurrentCurve" );
746 }
747
748 void Patch_constructMenu( GtkMenu* menu ){
749         create_menu_item_with_mnemonic( menu, "Cylinder", "PatchCylinder" );
750         {
751                 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "More Cylinders" );
752                 if ( g_Layout_enableDetachableMenus.m_value ) {
753                         menu_tearoff( menu_in_menu );
754                 }
755                 create_menu_item_with_mnemonic( menu_in_menu, "Dense Cylinder", "PatchDenseCylinder" );
756                 create_menu_item_with_mnemonic( menu_in_menu, "Very Dense Cylinder", "PatchVeryDenseCylinder" );
757                 create_menu_item_with_mnemonic( menu_in_menu, "Square Cylinder", "PatchSquareCylinder" );
758                 create_menu_item_with_mnemonic( menu_in_menu, "Exact Cylinder...", "PatchXactCylinder" );
759         }
760         menu_separator( menu );
761         create_menu_item_with_mnemonic( menu, "End cap", "PatchEndCap" );
762         create_menu_item_with_mnemonic( menu, "Bevel", "PatchBevel" );
763         {
764                 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "More End caps, Bevels" );
765                 if ( g_Layout_enableDetachableMenus.m_value ) {
766                         menu_tearoff( menu_in_menu );
767                 }
768                 create_menu_item_with_mnemonic( menu_in_menu, "Square Endcap", "PatchSquareBevel" );
769                 create_menu_item_with_mnemonic( menu_in_menu, "Square Bevel", "PatchSquareEndcap" );
770         }
771         menu_separator( menu );
772         create_menu_item_with_mnemonic( menu, "Cone", "PatchCone" );
773         create_menu_item_with_mnemonic( menu, "Exact Cone...", "PatchXactCone" );
774         menu_separator( menu );
775         create_menu_item_with_mnemonic( menu, "Sphere", "PatchSphere" );
776         create_menu_item_with_mnemonic( menu, "Exact Sphere...", "PatchXactSphere" );
777         menu_separator( menu );
778         create_menu_item_with_mnemonic( menu, "Simple Patch Mesh...", "SimplePatchMesh" );
779         menu_separator( menu );
780         {
781                 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Insert" );
782                 if ( g_Layout_enableDetachableMenus.m_value ) {
783                         menu_tearoff( menu_in_menu );
784                 }
785                 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Columns", "PatchInsertInsertColumn" );
786                 create_menu_item_with_mnemonic( menu_in_menu, "Add (2) Columns", "PatchInsertAddColumn" );
787                 menu_separator( menu_in_menu );
788                 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Rows", "PatchInsertInsertRow" );
789                 create_menu_item_with_mnemonic( menu_in_menu, "Add (2) Rows", "PatchInsertAddRow" );
790         }
791         {
792                 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Delete" );
793                 if ( g_Layout_enableDetachableMenus.m_value ) {
794                         menu_tearoff( menu_in_menu );
795                 }
796                 create_menu_item_with_mnemonic( menu_in_menu, "First (2) Columns", "PatchDeleteFirstColumn" );
797                 create_menu_item_with_mnemonic( menu_in_menu, "Last (2) Columns", "PatchDeleteLastColumn" );
798                 menu_separator( menu_in_menu );
799                 create_menu_item_with_mnemonic( menu_in_menu, "First (2) Rows", "PatchDeleteFirstRow" );
800                 create_menu_item_with_mnemonic( menu_in_menu, "Last (2) Rows", "PatchDeleteLastRow" );
801         }
802         menu_separator( menu );
803         {
804                 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Matrix" );
805                 if ( g_Layout_enableDetachableMenus.m_value ) {
806                         menu_tearoff( menu_in_menu );
807                 }
808                 create_menu_item_with_mnemonic( menu_in_menu, "Invert", "InvertCurve" );
809                 GtkMenu* menu_3 = create_sub_menu_with_mnemonic( menu_in_menu, "Re-disperse" );
810                 if ( g_Layout_enableDetachableMenus.m_value ) {
811                         menu_tearoff( menu_3 );
812                 }
813                 create_menu_item_with_mnemonic( menu_3, "Rows", "RedisperseRows" );
814                 create_menu_item_with_mnemonic( menu_3, "Columns", "RedisperseCols" );
815                 GtkMenu* menu_4 = create_sub_menu_with_mnemonic( menu_in_menu, "Smooth" );
816                 if ( g_Layout_enableDetachableMenus.m_value ) {
817                         menu_tearoff( menu_4 );
818                 }
819                 create_menu_item_with_mnemonic( menu_4, "Rows", "SmoothRows" );
820                 create_menu_item_with_mnemonic( menu_4, "Columns", "SmoothCols" );
821                 create_menu_item_with_mnemonic( menu_in_menu, "Transpose", "MatrixTranspose" );
822         }
823         menu_separator( menu );
824         create_menu_item_with_mnemonic( menu, "Cap Selection", "CapCurrentCurve" );
825         create_menu_item_with_mnemonic( menu, "Cycle Cap Texture", "CycleCapTexturePatch" );
826         menu_separator( menu );
827         {
828                 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Overlay" );
829                 if ( g_Layout_enableDetachableMenus.m_value ) {
830                         menu_tearoff( menu_in_menu );
831                 }
832                 create_menu_item_with_mnemonic( menu_in_menu, "Set", "MakeOverlayPatch" );
833                 create_menu_item_with_mnemonic( menu_in_menu, "Clear", "ClearPatchOverlays" );
834         }
835 }
836
837
838 #include <gtk/gtkbox.h>
839 #include <gtk/gtktable.h>
840 #include <gtk/gtktogglebutton.h>
841 #include <gtk/gtkradiobutton.h>
842 #include <gtk/gtkcombobox.h>
843 #include <gtk/gtklabel.h>
844 #include "gtkutil/dialog.h"
845 #include "gtkutil/widget.h"
846
847 void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols ){
848         ModalDialog dialog;
849         GtkComboBox* width;
850         GtkComboBox* height;
851
852         GtkWindow* window = create_dialog_window( MainFrame_getWindow(), "Patch density", G_CALLBACK( dialog_delete_callback ), &dialog );
853
854         GtkAccelGroup* accel = gtk_accel_group_new();
855         gtk_window_add_accel_group( window, accel );
856
857         {
858                 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
859                 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
860                 {
861                         GtkTable* table = create_dialog_table( 2, 2, 4, 4 );
862                         gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
863                         {
864                                 GtkLabel* label = GTK_LABEL( gtk_label_new( "Width:" ) );
865                                 gtk_widget_show( GTK_WIDGET( label ) );
866                                 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
867                                                                   (GtkAttachOptions) ( GTK_FILL ),
868                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
869                                 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
870                         }
871                         {
872                                 GtkLabel* label = GTK_LABEL( gtk_label_new( "Height:" ) );
873                                 gtk_widget_show( GTK_WIDGET( label ) );
874                                 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
875                                                                   (GtkAttachOptions) ( GTK_FILL ),
876                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
877                                 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
878                         }
879
880                         {
881                                 GtkComboBox* combo = GTK_COMBO_BOX( gtk_combo_box_new_text() );
882 #define D_ITEM( x ) if ( x >= mincols && ( !maxcols || x <= maxcols ) ) gtk_combo_box_append_text( combo, # x )
883                                 D_ITEM( 3 );
884                                 D_ITEM( 5 );
885                                 D_ITEM( 7 );
886                                 D_ITEM( 9 );
887                                 D_ITEM( 11 );
888                                 D_ITEM( 13 );
889                                 D_ITEM( 15 );
890                                 D_ITEM( 17 );
891                                 D_ITEM( 19 );
892                                 D_ITEM( 21 );
893                                 D_ITEM( 23 );
894                                 D_ITEM( 25 );
895                                 D_ITEM( 27 );
896                                 D_ITEM( 29 );
897                                 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
898 #undef D_ITEM
899                                 gtk_widget_show( GTK_WIDGET( combo ) );
900                                 gtk_table_attach( table, GTK_WIDGET( combo ), 1, 2, 0, 1,
901                                                                   (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
902                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
903
904                                 width = combo;
905                         }
906                         {
907                                 GtkComboBox* combo = GTK_COMBO_BOX( gtk_combo_box_new_text() );
908 #define D_ITEM( x ) if ( x >= minrows && ( !maxrows || x <= maxrows ) ) gtk_combo_box_append_text( combo, # x )
909                                 D_ITEM( 3 );
910                                 D_ITEM( 5 );
911                                 D_ITEM( 7 );
912                                 D_ITEM( 9 );
913                                 D_ITEM( 11 );
914                                 D_ITEM( 13 );
915                                 D_ITEM( 15 );
916                                 D_ITEM( 17 );
917                                 D_ITEM( 19 );
918                                 D_ITEM( 21 );
919                                 D_ITEM( 23 );
920                                 D_ITEM( 25 );
921                                 D_ITEM( 27 );
922                                 D_ITEM( 29 );
923                                 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
924 #undef D_ITEM
925                                 gtk_widget_show( GTK_WIDGET( combo ) );
926                                 gtk_table_attach( table, GTK_WIDGET( combo ), 1, 2, 1, 2,
927                                                                   (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
928                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
929
930                                 height = combo;
931                         }
932                 }
933
934                 {
935                         GtkVBox* vbox = create_dialog_vbox( 4 );
936                         gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
937                         {
938                                 GtkButton* button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
939                                 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
940                                 widget_make_default( GTK_WIDGET( button ) );
941                                 gtk_widget_grab_focus( GTK_WIDGET( button ) );
942                                 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
943                         }
944                         {
945                                 GtkButton* button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
946                                 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
947                                 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
948                         }
949                 }
950         }
951
952         // Initialize dialog
953         gtk_combo_box_set_active( width, ( defcols - mincols ) / 2 );
954         gtk_combo_box_set_active( height, ( defrows - minrows ) / 2 );
955
956         if ( modal_dialog_show( window, dialog ) == eIDOK ) {
957                 int w = gtk_combo_box_get_active( width ) * 2 + mincols;
958                 int h = gtk_combo_box_get_active( height ) * 2 + minrows;
959
960                 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), prefab, GlobalXYWnd_getCurrentViewType(), w, h );
961         }
962
963         gtk_widget_destroy( GTK_WIDGET( window ) );
964 }
965
966
967
968
969 EMessageBoxReturn DoCapDlg( ECapDialog* type ){
970         ModalDialog dialog;
971         ModalDialogButton ok_button( dialog, eIDOK );
972         ModalDialogButton cancel_button( dialog, eIDCANCEL );
973         GtkWidget* bevel;
974         GtkWidget* ibevel;
975         GtkWidget* endcap;
976         GtkWidget* iendcap;
977         GtkWidget* cylinder;
978
979         GtkWindow* window = create_modal_dialog_window( MainFrame_getWindow(), "Cap", dialog );
980
981         GtkAccelGroup *accel_group = gtk_accel_group_new();
982         gtk_window_add_accel_group( window, accel_group );
983
984         {
985                 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
986                 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
987
988                 {
989                         // Gef: Added a vbox to contain the toggle buttons
990                         GtkVBox* radio_vbox = create_dialog_vbox( 4 );
991                         gtk_container_add( GTK_CONTAINER( hbox ), GTK_WIDGET( radio_vbox ) );
992
993                         {
994                                 GtkTable* table = GTK_TABLE( gtk_table_new( 5, 2, FALSE ) );
995                                 gtk_widget_show( GTK_WIDGET( table ) );
996                                 gtk_box_pack_start( GTK_BOX( radio_vbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
997                                 gtk_table_set_row_spacings( table, 5 );
998                                 gtk_table_set_col_spacings( table, 5 );
999
1000                                 {
1001                                         GtkImage* image = new_local_image( "cap_bevel.bmp" );
1002                                         gtk_widget_show( GTK_WIDGET( image ) );
1003                                         gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 0, 1,
1004                                                                           (GtkAttachOptions) ( GTK_FILL ),
1005                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1006                                 }
1007                                 {
1008                                         GtkImage* image = new_local_image( "cap_endcap.bmp" );
1009                                         gtk_widget_show( GTK_WIDGET( image ) );
1010                                         gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 1, 2,
1011                                                                           (GtkAttachOptions) ( GTK_FILL ),
1012                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1013                                 }
1014                                 {
1015                                         GtkImage* image = new_local_image( "cap_ibevel.bmp" );
1016                                         gtk_widget_show( GTK_WIDGET( image ) );
1017                                         gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 2, 3,
1018                                                                           (GtkAttachOptions) ( GTK_FILL ),
1019                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1020                                 }
1021                                 {
1022                                         GtkImage* image = new_local_image( "cap_iendcap.bmp" );
1023                                         gtk_widget_show( GTK_WIDGET( image ) );
1024                                         gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 3, 4,
1025                                                                           (GtkAttachOptions) ( GTK_FILL ),
1026                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1027                                 }
1028                                 {
1029                                         GtkImage* image = new_local_image( "cap_cylinder.bmp" );
1030                                         gtk_widget_show( GTK_WIDGET( image ) );
1031                                         gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 4, 5,
1032                                                                           (GtkAttachOptions) ( GTK_FILL ),
1033                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1034                                 }
1035
1036                                 GSList* group = 0;
1037                                 {
1038                                         GtkWidget* button = gtk_radio_button_new_with_label( group, "Bevel" );
1039                                         gtk_widget_show( button );
1040                                         gtk_table_attach( table, button, 1, 2, 0, 1,
1041                                                                           (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1042                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1043                                         group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1044
1045                                         bevel = button;
1046                                 }
1047                                 {
1048                                         GtkWidget* button = gtk_radio_button_new_with_label( group, "Endcap" );
1049                                         gtk_widget_show( button );
1050                                         gtk_table_attach( table, button, 1, 2, 1, 2,
1051                                                                           (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1052                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1053                                         group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1054
1055                                         endcap = button;
1056                                 }
1057                                 {
1058                                         GtkWidget* button = gtk_radio_button_new_with_label( group, "Inverted Bevel" );
1059                                         gtk_widget_show( button );
1060                                         gtk_table_attach( table, button, 1, 2, 2, 3,
1061                                                                           (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1062                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1063                                         group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1064
1065                                         ibevel = button;
1066                                 }
1067                                 {
1068                                         GtkWidget* button = gtk_radio_button_new_with_label( group, "Inverted Endcap" );
1069                                         gtk_widget_show( button );
1070                                         gtk_table_attach( table, button, 1, 2, 3, 4,
1071                                                                           (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1072                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1073                                         group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1074
1075                                         iendcap = button;
1076                                 }
1077                                 {
1078                                         GtkWidget* button = gtk_radio_button_new_with_label( group, "Cylinder" );
1079                                         gtk_widget_show( button );
1080                                         gtk_table_attach( table, button, 1, 2, 4, 5,
1081                                                                           (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1082                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1083                                         group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1084
1085                                         cylinder = button;
1086                                 }
1087                         }
1088                 }
1089
1090                 {
1091                         GtkVBox* vbox = create_dialog_vbox( 4 );
1092                         gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), FALSE, FALSE, 0 );
1093                         {
1094                                 GtkButton* button = create_modal_dialog_button( "OK", ok_button );
1095                                 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1096                                 widget_make_default( GTK_WIDGET( button ) );
1097                                 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel_group, GDK_Return, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
1098                         }
1099                         {
1100                                 GtkButton* button = create_modal_dialog_button( "Cancel", cancel_button );
1101                                 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1102                                 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel_group, GDK_Escape, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
1103                         }
1104                 }
1105         }
1106
1107         // Initialize dialog
1108         gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( bevel ), TRUE );
1109
1110         EMessageBoxReturn ret = modal_dialog_show( window, dialog );
1111         if ( ret == eIDOK ) {
1112                 if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( bevel ) ) ) {
1113                         *type = PATCHCAP_BEVEL;
1114                 }
1115                 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( endcap ) ) ) {
1116                         *type = PATCHCAP_ENDCAP;
1117                 }
1118                 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( ibevel ) ) ) {
1119                         *type = PATCHCAP_INVERTED_BEVEL;
1120                 }
1121                 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( iendcap ) ) ) {
1122                         *type = PATCHCAP_INVERTED_ENDCAP;
1123                 }
1124                 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( cylinder ) ) ) {
1125                         *type = PATCHCAP_CYLINDER;
1126                 }
1127         }
1128
1129         gtk_widget_destroy( GTK_WIDGET( window ) );
1130
1131         return ret;
1132 }