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