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