]> git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/patchmanip.cpp
Radiant:
[xonotic/netradiant.git] / radiant / patchmanip.cpp
1 /*
2    Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3    For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5    This file is part of GtkRadiant.
6
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    GtkRadiant is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 #include "patchmanip.h"
23
24 #include "debugging/debugging.h"
25
26
27 #include "iselection.h"
28 #include "ipatch.h"
29
30 #include "math/vector.h"
31 #include "math/aabb.h"
32 #include "generic/callback.h"
33
34 #include "gtkutil/menu.h"
35 #include "gtkutil/image.h"
36 #include "map.h"
37 #include "mainframe.h"
38 #include "commands.h"
39 #include "gtkmisc.h"
40 #include "gtkdlgs.h"
41 #include "texwindow.h"
42 #include "xywindow.h"
43 #include "select.h"
44 #include "patch.h"
45 #include "grid.h"
46
47 PatchCreator* g_patchCreator = 0;
48
49 void Scene_PatchConstructPrefab( scene::Graph& graph, const AABB aabb, const char* shader, EPatchPrefab eType, int axis, std::size_t width = 3, std::size_t height = 3, bool redisperse = false ){
50         Select_Delete();
51         GlobalSelectionSystem().setSelectedAll( false );
52
53         NodeSmartReference node( g_patchCreator->createPatch() );
54         Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
55
56         Patch* patch = Node_getPatch( node );
57         patch->SetShader( shader );
58
59         patch->ConstructPrefab( aabb, eType, axis, width, height );
60         if( redisperse ){
61                 patch->Redisperse( COL );
62                 patch->Redisperse( ROW );
63         }
64         patch->controlPointsChanged();
65
66         {
67                 scene::Path patchpath( makeReference( GlobalSceneGraph().root() ) );
68                 patchpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
69                 patchpath.push( makeReference( node.get() ) );
70                 Instance_getSelectable( *graph.find( patchpath ) )->setSelected( true );
71         }
72 }
73
74
75 void Patch_makeCaps( Patch& patch, scene::Instance& instance, EPatchCap type, const char* shader ){
76         if ( ( type == eCapEndCap || type == eCapIEndCap )
77                  && patch.getWidth() != 5 ) {
78                 globalErrorStream() << "cannot create end-cap - patch width != 5\n";
79                 return;
80         }
81         if ( ( type == eCapBevel || type == eCapIBevel )
82                  && patch.getWidth() != 3 && patch.getWidth() != 5 ) {
83                 globalErrorStream() << "cannot create bevel-cap - patch width != 3\n";
84                 return;
85         }
86         if ( type == eCapCylinder
87                  && patch.getWidth() != 9 ) {
88                 globalErrorStream() << "cannot create cylinder-cap - patch width != 9\n";
89                 return;
90         }
91
92         {
93                 NodeSmartReference cap( g_patchCreator->createPatch() );
94                 Node_getTraversable( instance.path().parent() )->insert( cap );
95
96                 patch.MakeCap( Node_getPatch( cap ), type, ROW, true );
97                 Node_getPatch( cap )->SetShader( shader );
98
99                 scene::Path path( instance.path() );
100                 path.pop();
101                 path.push( makeReference( cap.get() ) );
102                 selectPath( path, true );
103         }
104
105         {
106                 NodeSmartReference cap( g_patchCreator->createPatch() );
107                 Node_getTraversable( instance.path().parent() )->insert( cap );
108
109                 patch.MakeCap( Node_getPatch( cap ), type, ROW, false );
110                 Node_getPatch( cap )->SetShader( shader );
111
112                 scene::Path path( instance.path() );
113                 path.pop();
114                 path.push( makeReference( cap.get() ) );
115                 selectPath( path, true );
116         }
117 }
118
119
120 typedef std::vector<scene::Instance*> InstanceVector;
121
122 class PatchStoreInstance
123 {
124 InstanceVector& m_instances;
125 public:
126 PatchStoreInstance( InstanceVector& instances ) : m_instances( instances ){
127 }
128 void operator()( PatchInstance& patch ) const {
129         m_instances.push_back( &patch );
130 }
131 };
132
133 enum ECapDialog {
134         PATCHCAP_BEVEL = 0,
135         PATCHCAP_ENDCAP,
136         PATCHCAP_INVERTED_BEVEL,
137         PATCHCAP_INVERTED_ENDCAP,
138         PATCHCAP_CYLINDER
139 };
140
141 EMessageBoxReturn DoCapDlg( ECapDialog *type );
142
143 void Scene_PatchDoCap_Selected( scene::Graph& graph, const char* shader ){
144         ECapDialog nType;
145
146         if ( DoCapDlg( &nType ) == eIDOK ) {
147                 EPatchCap eType;
148                 switch ( nType )
149                 {
150                 case PATCHCAP_INVERTED_BEVEL:
151                         eType = eCapIBevel;
152                         break;
153                 case PATCHCAP_BEVEL:
154                         eType = eCapBevel;
155                         break;
156                 case PATCHCAP_INVERTED_ENDCAP:
157                         eType = eCapIEndCap;
158                         break;
159                 case PATCHCAP_ENDCAP:
160                         eType = eCapEndCap;
161                         break;
162                 case PATCHCAP_CYLINDER:
163                         eType = eCapCylinder;
164                         break;
165                 default:
166                         ERROR_MESSAGE( "invalid patch cap type" );
167                         return;
168                 }
169
170                 InstanceVector instances;
171                 Scene_forEachVisibleSelectedPatchInstance( PatchStoreInstance( instances ) );
172                 for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
173                 {
174                         Patch_makeCaps( *Node_getPatch( ( *i )->path().top() ), *( *i ), eType, shader );
175                 }
176         }
177 }
178
179 void Patch_deform( Patch& patch, scene::Instance& instance, const int deform, const int axis ){
180         patch.undoSave();
181
182         for ( PatchControlIter i = patch.begin(); i != patch.end(); ++i ){
183                 PatchControl& control = *i;
184                 int randomNumber = int( deform * ( float( std::rand() ) / float( RAND_MAX ) ) );
185                 control.m_vertex[ axis ] += randomNumber;
186         }
187
188         patch.controlPointsChanged();
189 }
190
191 void Scene_PatchDeform( scene::Graph& graph, const int deform, const int axis )
192 {
193         InstanceVector instances;
194         Scene_forEachVisibleSelectedPatchInstance( PatchStoreInstance( instances ) );
195         for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
196         {
197                 Patch_deform( *Node_getPatch( ( *i )->path().top() ), *( *i ), deform, axis );
198         }
199
200 }
201
202 void Patch_thicken( Patch& patch, scene::Instance& instance, const float thickness, bool seams, const int axis ){
203
204                 // Create a new patch node
205                 NodeSmartReference node( g_patchCreator->createPatch() );
206                 // Insert the node into worldspawn
207                 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
208
209                 // Retrieve the contained patch from the node
210                 Patch* targetPatch = Node_getPatch( node );
211
212                 // Create the opposite patch with the given thickness = distance
213                 bool no12 = true;
214                 bool no34 = true;
215                 targetPatch->createThickenedOpposite( patch, thickness, axis, no12, no34 );
216
217                 // Now select the newly created patches
218                 {
219                         scene::Path patchpath( makeReference( GlobalSceneGraph().root() ) );
220                         patchpath.push( makeReference( *Map_GetWorldspawn( g_map ) ) );
221                         patchpath.push( makeReference( node.get() ) );
222                         Instance_getSelectable( *GlobalSceneGraph().find( patchpath ) )->setSelected( true );
223                 }
224
225                 if( seams && thickness != 0.0f){
226                         int i = 0;
227                         if ( no12 ){
228                                 i = 2;
229                         }
230                         int iend = 4;
231                         if ( no34 ){
232                                 iend = 2;
233                         }
234                         // Now create the four walls
235                         for ( ; i < iend; i++ ){
236                                 // Allocate new patch
237                                 NodeSmartReference node = NodeSmartReference( g_patchCreator->createPatch() );
238                                 // Insert each node into worldspawn
239                                 Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->insert( node );
240
241                                 // Retrieve the contained patch from the node
242                                 Patch* wallPatch = Node_getPatch( node );
243
244                                 // Create the wall patch by passing i as wallIndex
245                                 wallPatch->createThickenedWall( patch, *targetPatch, i );
246
247                                 if( ( wallPatch->localAABB().extents[0] <= 0.00005 && wallPatch->localAABB().extents[1] <= 0.00005 ) ||
248                                         ( wallPatch->localAABB().extents[1] <= 0.00005 && wallPatch->localAABB().extents[2] <= 0.00005 ) ||
249                                         ( wallPatch->localAABB().extents[0] <= 0.00005 && wallPatch->localAABB().extents[2] <= 0.00005 ) ){
250                                         //globalOutputStream() << "Thicken: Discarding degenerate patch.\n";
251                                         Node_getTraversable( Map_FindOrInsertWorldspawn( g_map ) )->erase( node );
252                                 }
253                                 else
254                                 // Now select the newly created patches
255                                 {
256                                         scene::Path patchpath( makeReference( GlobalSceneGraph().root() ) );
257                                         patchpath.push( makeReference( *Map_GetWorldspawn(g_map) ) );
258                                         patchpath.push( makeReference( node.get() ) );
259                                         Instance_getSelectable( *GlobalSceneGraph().find( patchpath ) )->setSelected( true );
260                                 }
261                         }
262                 }
263
264                 // Invert the target patch so that it faces the opposite direction
265                 targetPatch->InvertMatrix();
266 }
267
268 void Scene_PatchThicken( scene::Graph& graph, const int thickness, bool seams, const int axis )
269 {
270         InstanceVector instances;
271         Scene_forEachVisibleSelectedPatchInstance( PatchStoreInstance( instances ) );
272         for ( InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i )
273         {
274                 Patch_thicken( *Node_getPatch( ( *i )->path().top() ), *( *i ), thickness, seams, axis );
275         }
276
277 }
278
279 Patch* Scene_GetUltimateSelectedVisiblePatch(){
280         if ( GlobalSelectionSystem().countSelected() != 0 ) {
281                 scene::Node& node = GlobalSelectionSystem().ultimateSelected().path().top();
282                 if ( node.visible() ) {
283                         return Node_getPatch( node );
284                 }
285         }
286         return 0;
287 }
288
289
290 class PatchCapTexture
291 {
292 public:
293 void operator()( Patch& patch ) const {
294         patch.ProjectTexture( Patch::m_CycleCapIndex );
295 }
296 };
297
298 void Scene_PatchCapTexture_Selected( scene::Graph& graph ){
299         Scene_forEachVisibleSelectedPatch( PatchCapTexture() );
300         Patch::m_CycleCapIndex = ( Patch::m_CycleCapIndex == 0 ) ? 1 : ( Patch::m_CycleCapIndex == 1 ) ? 2 : 0;
301         SceneChangeNotify();
302 }
303
304 class PatchFlipTexture
305 {
306 int m_axis;
307 public:
308 PatchFlipTexture( int axis ) : m_axis( axis ){
309 }
310 void operator()( Patch& patch ) const {
311         patch.FlipTexture( m_axis );
312 }
313 };
314
315 void Scene_PatchFlipTexture_Selected( scene::Graph& graph, int axis ){
316         Scene_forEachVisibleSelectedPatch( PatchFlipTexture( axis ) );
317 }
318
319 class PatchNaturalTexture
320 {
321 public:
322 void operator()( Patch& patch ) const {
323         patch.NaturalTexture();
324 }
325 };
326
327 void Scene_PatchNaturalTexture_Selected( scene::Graph& graph ){
328         Scene_forEachVisibleSelectedPatch( PatchNaturalTexture() );
329         SceneChangeNotify();
330 }
331
332
333 class PatchInsertRemove
334 {
335 bool m_insert, m_column, m_first;
336 public:
337 PatchInsertRemove( bool insert, bool column, bool first ) : m_insert( insert ), m_column( column ), m_first( first ){
338 }
339 void operator()( Patch& patch ) const {
340         patch.InsertRemove( m_insert, m_column, m_first );
341 }
342 };
343
344 void Scene_PatchInsertRemove_Selected( scene::Graph& graph, bool bInsert, bool bColumn, bool bFirst ){
345         Scene_forEachVisibleSelectedPatch( PatchInsertRemove( bInsert, bColumn, bFirst ) );
346 }
347
348 class PatchInvertMatrix
349 {
350 public:
351 void operator()( Patch& patch ) const {
352         patch.InvertMatrix();
353 }
354 };
355
356 void Scene_PatchInvert_Selected( scene::Graph& graph ){
357         Scene_forEachVisibleSelectedPatch( PatchInvertMatrix() );
358 }
359
360 class PatchRedisperse
361 {
362 EMatrixMajor m_major;
363 public:
364 PatchRedisperse( EMatrixMajor major ) : m_major( major ){
365 }
366 void operator()( Patch& patch ) const {
367         patch.Redisperse( m_major );
368 }
369 };
370
371 void Scene_PatchRedisperse_Selected( scene::Graph& graph, EMatrixMajor major ){
372         Scene_forEachVisibleSelectedPatch( PatchRedisperse( major ) );
373 }
374
375 class PatchSmooth
376 {
377 EMatrixMajor m_major;
378 public:
379 PatchSmooth( EMatrixMajor major ) : m_major( major ){
380 }
381 void operator()( Patch& patch ) const {
382         patch.Smooth( m_major );
383 }
384 };
385
386 void Scene_PatchSmooth_Selected( scene::Graph& graph, EMatrixMajor major ){
387         Scene_forEachVisibleSelectedPatch( PatchSmooth( major ) );
388 }
389
390 class PatchTransposeMatrix
391 {
392 public:
393 void operator()( Patch& patch ) const {
394         patch.TransposeMatrix();
395 }
396 };
397
398 void Scene_PatchTranspose_Selected( scene::Graph& graph ){
399         Scene_forEachVisibleSelectedPatch( PatchTransposeMatrix() );
400 }
401
402 class PatchSetShader
403 {
404 const char* m_name;
405 public:
406 PatchSetShader( const char* name )
407         : m_name( name ){
408 }
409 void operator()( Patch& patch ) const {
410         patch.SetShader( m_name );
411 }
412 };
413
414 void Scene_PatchSetShader_Selected( scene::Graph& graph, const char* name ){
415         Scene_forEachVisibleSelectedPatch( PatchSetShader( name ) );
416         SceneChangeNotify();
417 }
418
419 void Scene_PatchGetShader_Selected( scene::Graph& graph, CopiedString& name ){
420         Patch* patch = Scene_GetUltimateSelectedVisiblePatch();
421         if ( patch != 0 ) {
422                 name = patch->GetShader();
423         }
424 }
425
426 class PatchSelectByShader
427 {
428 const char* m_name;
429 public:
430 inline PatchSelectByShader( const char* name )
431         : m_name( name ){
432 }
433 void operator()( PatchInstance& patch ) const {
434         if ( shader_equal( patch.getPatch().GetShader(), m_name ) ) {
435                 patch.setSelected( true );
436         }
437 }
438 };
439
440 void Scene_PatchSelectByShader( scene::Graph& graph, const char* name ){
441         Scene_forEachVisiblePatchInstance( PatchSelectByShader( name ) );
442 }
443
444
445 class PatchFindReplaceShader
446 {
447 const char* m_find;
448 const char* m_replace;
449 public:
450 PatchFindReplaceShader( const char* find, const char* replace ) : m_find( find ), m_replace( replace ){
451 }
452 void operator()( Patch& patch ) const {
453         if ( shader_equal( patch.GetShader(), m_find ) ) {
454                 patch.SetShader( m_replace );
455         }
456 }
457 };
458
459 namespace{
460 bool DoingSearch( const char *repl ){
461         return ( repl == NULL || ( strcmp( "textures/", repl ) == 0 ) );
462 }
463 }
464 void Scene_PatchFindReplaceShader( scene::Graph& graph, const char* find, const char* replace ){
465         if( DoingSearch( replace ) ){
466                 Scene_forEachVisiblePatchInstance( PatchSelectByShader( find ) );
467         }
468         else{
469                 Scene_forEachVisiblePatch( PatchFindReplaceShader( find, replace ) );
470         }
471 }
472
473 void Scene_PatchFindReplaceShader_Selected( scene::Graph& graph, const char* find, const char* replace ){
474         if( DoingSearch( replace ) ){
475                 //do nothing, because alternative is replacing to notex
476                 //perhaps deselect ones with not matching shaders here?
477         }
478         else{
479                 Scene_forEachVisibleSelectedPatch( PatchFindReplaceShader( find, replace ) );
480         }
481 }
482
483
484 AABB PatchCreator_getBounds(){
485         AABB aabb( aabb_for_minmax( Select_getWorkZone().d_work_min, Select_getWorkZone().d_work_max ) );
486
487         float gridSize = GetGridSize();
488
489         if ( aabb.extents[0] == 0 ) {
490                 aabb.extents[0] = gridSize;
491         }
492         if ( aabb.extents[1] == 0 ) {
493                 aabb.extents[1] = gridSize;
494         }
495         if ( aabb.extents[2] == 0 ) {
496                 aabb.extents[2] = gridSize;
497         }
498
499         if ( aabb_valid( aabb ) ) {
500                 return aabb;
501         }
502         return AABB( Vector3( 0, 0, 0 ), Vector3( 64, 64, 64 ) );
503 }
504
505 void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols );
506
507 void Patch_XactCylinder(){
508         UndoableCommand undo( "patchCreateXactCylinder" );
509
510         DoNewPatchDlg( eXactCylinder, 3, 7, 3, 13, 0, 0 );
511 }
512
513 void Patch_XactSphere(){
514         UndoableCommand undo( "patchCreateXactSphere" );
515
516         DoNewPatchDlg( eXactSphere, 5, 7, 7, 13, 0, 0 );
517 }
518
519 void Patch_XactCone(){
520         UndoableCommand undo( "patchCreateXactCone" );
521
522         DoNewPatchDlg( eXactCone, 3, 7, 3, 13, 0, 0 );
523 }
524
525 void Patch_Cylinder(){
526         UndoableCommand undo( "patchCreateCylinder" );
527
528         Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eCylinder, GlobalXYWnd_getCurrentViewType() );
529 }
530
531 void Patch_DenseCylinder(){
532         UndoableCommand undo( "patchCreateDenseCylinder" );
533
534         Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eDenseCylinder, GlobalXYWnd_getCurrentViewType() );
535 }
536
537 void Patch_VeryDenseCylinder(){
538         UndoableCommand undo( "patchCreateVeryDenseCylinder" );
539
540         Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eVeryDenseCylinder, GlobalXYWnd_getCurrentViewType() );
541 }
542
543 void Patch_SquareCylinder(){
544         UndoableCommand undo( "patchCreateSquareCylinder" );
545
546         Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eSqCylinder, GlobalXYWnd_getCurrentViewType() );
547 }
548
549 void Patch_Endcap(){
550         UndoableCommand undo( "patchCreateCaps" );
551
552         Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eEndCap, GlobalXYWnd_getCurrentViewType() );
553 }
554
555 void Patch_Bevel(){
556         UndoableCommand undo( "patchCreateBevel" );
557
558         Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eBevel, GlobalXYWnd_getCurrentViewType() );
559 }
560
561 void Patch_Sphere(){
562         UndoableCommand undo( "patchCreateSphere" );
563
564         Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eSphere, GlobalXYWnd_getCurrentViewType() );
565 }
566
567 void Patch_SquareBevel(){
568 }
569
570 void Patch_SquareEndcap(){
571 }
572
573 void Patch_Cone(){
574         UndoableCommand undo( "patchCreateCone" );
575
576         Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), eCone, GlobalXYWnd_getCurrentViewType() );
577 }
578
579 void Patch_Plane(){
580         UndoableCommand undo( "patchCreatePlane" );
581
582         DoNewPatchDlg( ePlane, 3, 3, 3, 3, 0, 0 );
583 }
584
585 void Patch_InsertFirstColumn(){
586         UndoableCommand undo( "patchInsertFirstColumns" );
587
588         Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, true, true );
589 }
590
591 void Patch_InsertLastColumn(){
592         UndoableCommand undo( "patchInsertLastColumns" );
593
594         Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, true, false );
595 }
596
597 void Patch_InsertFirstRow(){
598         UndoableCommand undo( "patchInsertFirstRows" );
599
600         Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, false, true );
601 }
602
603 void Patch_InsertLastRow(){
604         UndoableCommand undo( "patchInsertLastRows" );
605
606         Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), true, false, false );
607 }
608
609 void Patch_DeleteFirstColumn(){
610         UndoableCommand undo( "patchDeleteFirstColumns" );
611
612         Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, true, true );
613 }
614
615 void Patch_DeleteLastColumn(){
616         UndoableCommand undo( "patchDeleteLastColumns" );
617
618         Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, true, false );
619 }
620
621 void Patch_DeleteFirstRow(){
622         UndoableCommand undo( "patchDeleteFirstRows" );
623
624         Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, false, true );
625 }
626
627 void Patch_DeleteLastRow(){
628         UndoableCommand undo( "patchDeleteLastRows" );
629
630         Scene_PatchInsertRemove_Selected( GlobalSceneGraph(), false, false, false );
631 }
632
633 void Patch_Invert(){
634         UndoableCommand undo( "patchInvert" );
635
636         Scene_PatchInvert_Selected( GlobalSceneGraph() );
637 }
638
639 void Patch_RedisperseRows(){
640         UndoableCommand undo( "patchRedisperseRows" );
641
642         Scene_PatchRedisperse_Selected( GlobalSceneGraph(), ROW );
643 }
644
645 void Patch_RedisperseCols(){
646         UndoableCommand undo( "patchRedisperseColumns" );
647
648         Scene_PatchRedisperse_Selected( GlobalSceneGraph(), COL );
649 }
650
651 void Patch_SmoothRows(){
652         UndoableCommand undo( "patchSmoothRows" );
653
654         Scene_PatchSmooth_Selected( GlobalSceneGraph(), ROW );
655 }
656
657 void Patch_SmoothCols(){
658         UndoableCommand undo( "patchSmoothColumns" );
659
660         Scene_PatchSmooth_Selected( GlobalSceneGraph(), COL );
661 }
662
663 void Patch_Transpose(){
664         UndoableCommand undo( "patchTranspose" );
665
666         Scene_PatchTranspose_Selected( GlobalSceneGraph() );
667 }
668
669 void Patch_Cap(){
670         // FIXME: add support for patch cap creation
671         // Patch_CapCurrent();
672         UndoableCommand undo( "patchCreateCaps" );
673
674         Scene_PatchDoCap_Selected( GlobalSceneGraph(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
675 }
676
677 void Patch_CycleProjection(){
678         UndoableCommand undo( "patchCycleUVProjectionAxis" );
679
680         Scene_PatchCapTexture_Selected( GlobalSceneGraph() );
681 }
682
683 ///\todo Unfinished.
684 void Patch_OverlayOn(){
685 }
686
687 ///\todo Unfinished.
688 void Patch_OverlayOff(){
689 }
690
691 void Patch_FlipTextureX(){
692         UndoableCommand undo( "patchFlipTextureU" );
693
694         Scene_PatchFlipTexture_Selected( GlobalSceneGraph(), 0 );
695 }
696
697 void Patch_FlipTextureY(){
698         UndoableCommand undo( "patchFlipTextureV" );
699
700         Scene_PatchFlipTexture_Selected( GlobalSceneGraph(), 1 );
701 }
702
703 void Patch_NaturalTexture(){
704         UndoableCommand undo( "patchNaturalTexture" );
705
706         Scene_PatchNaturalTexture_Selected( GlobalSceneGraph() );
707 }
708
709 void Patch_CapTexture(){
710         UndoableCommand command( "patchCapTexture" );
711         Scene_PatchCapTexture_Selected( GlobalSceneGraph() );
712 }
713
714 void Patch_ResetTexture(){
715         float fx, fy;
716         if ( DoTextureLayout( &fx, &fy ) == eIDOK ) {
717                 UndoableCommand command( "patchTileTexture" );
718                 Scene_PatchTileTexture_Selected( GlobalSceneGraph(), fx, fy );
719         }
720 }
721
722 void Patch_FitTexture(){
723         UndoableCommand command( "patchFitTexture" );
724         Scene_PatchTileTexture_Selected( GlobalSceneGraph(), 1, 1 );
725 }
726
727 void DoPatchDeformDlg();
728
729 void Patch_Deform(){
730         UndoableCommand undo( "patchDeform" );
731
732         DoPatchDeformDlg();
733 }
734
735 void DoPatchThickenDlg();
736
737 void Patch_Thicken(){
738         UndoableCommand undo( "patchThicken" );
739
740         DoPatchThickenDlg();
741 }
742
743
744
745 #include "ifilter.h"
746
747
748 class filter_patch_all : public PatchFilter
749 {
750 public:
751 bool filter( const Patch& patch ) const {
752         return true;
753 }
754 };
755
756 class filter_patch_shader : public PatchFilter
757 {
758 const char* m_shader;
759 public:
760 filter_patch_shader( const char* shader ) : m_shader( shader ){
761 }
762 bool filter( const Patch& patch ) const {
763         return shader_equal( patch.GetShader(), m_shader );
764 }
765 };
766
767 class filter_patch_flags : public PatchFilter
768 {
769 int m_flags;
770 public:
771 filter_patch_flags( int flags ) : m_flags( flags ){
772 }
773 bool filter( const Patch& patch ) const {
774         return ( patch.getShaderFlags() & m_flags ) != 0;
775 }
776 };
777
778
779 filter_patch_all g_filter_patch_all;
780 filter_patch_flags g_filter_patch_clip( QER_CLIP );
781 filter_patch_shader g_filter_patch_commonclip( "textures/common/clip" );
782 filter_patch_shader g_filter_patch_weapclip( "textures/common/weapclip" );
783 filter_patch_flags g_filter_patch_translucent( QER_TRANS | QER_ALPHATEST );
784
785 void PatchFilters_construct(){
786         add_patch_filter( g_filter_patch_all, EXCLUDE_CURVES );
787         add_patch_filter( g_filter_patch_clip, EXCLUDE_CLIP );
788         add_patch_filter( g_filter_patch_commonclip, EXCLUDE_CLIP );
789         add_patch_filter( g_filter_patch_weapclip, EXCLUDE_CLIP );
790         add_patch_filter( g_filter_patch_translucent, EXCLUDE_TRANSLUCENT );
791 }
792
793
794 #include "preferences.h"
795
796 void Patch_constructPreferences( PreferencesPage& page ){
797         page.appendEntry( "Patch Subdivide Threshold", g_PatchSubdivideThreshold );
798 }
799 void Patch_constructPage( PreferenceGroup& group ){
800         PreferencesPage page( group.createPage( "Patches", "Patch Display Preferences" ) );
801         Patch_constructPreferences( page );
802 }
803 void Patch_registerPreferencesPage(){
804         PreferencesDialog_addDisplayPage( FreeCaller1<PreferenceGroup&, Patch_constructPage>() );
805 }
806
807
808 #include "preferencesystem.h"
809
810 void PatchPreferences_construct(){
811         GlobalPreferenceSystem().registerPreference( "Subdivisions", IntImportStringCaller( g_PatchSubdivideThreshold ), IntExportStringCaller( g_PatchSubdivideThreshold ) );
812 }
813
814
815 #include "generic/callback.h"
816
817 void Patch_registerCommands(){
818         GlobalCommands_insert( "InvertCurveTextureX", FreeCaller<Patch_FlipTextureX>(), Accelerator( 'I', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
819         GlobalCommands_insert( "InvertCurveTextureY", FreeCaller<Patch_FlipTextureY>(), Accelerator( 'I', (GdkModifierType)GDK_SHIFT_MASK ) );
820         GlobalCommands_insert( "NaturalizePatch", FreeCaller<Patch_NaturalTexture>(), Accelerator( 'N', (GdkModifierType)GDK_CONTROL_MASK ) );
821         GlobalCommands_insert( "PatchCylinder", FreeCaller<Patch_Cylinder>() );
822 //      GlobalCommands_insert( "PatchDenseCylinder", FreeCaller<Patch_DenseCylinder>() );
823 //      GlobalCommands_insert( "PatchVeryDenseCylinder", FreeCaller<Patch_VeryDenseCylinder>() );
824         GlobalCommands_insert( "PatchSquareCylinder", FreeCaller<Patch_SquareCylinder>() );
825         GlobalCommands_insert( "PatchXactCylinder", FreeCaller<Patch_XactCylinder>() );
826         GlobalCommands_insert( "PatchXactSphere", FreeCaller<Patch_XactSphere>() );
827         GlobalCommands_insert( "PatchXactCone", FreeCaller<Patch_XactCone>() );
828         GlobalCommands_insert( "PatchEndCap", FreeCaller<Patch_Endcap>() );
829         GlobalCommands_insert( "PatchBevel", FreeCaller<Patch_Bevel>() );
830 //      GlobalCommands_insert( "PatchSquareBevel", FreeCaller<Patch_SquareBevel>() );
831 //      GlobalCommands_insert( "PatchSquareEndcap", FreeCaller<Patch_SquareEndcap>() );
832         GlobalCommands_insert( "PatchCone", FreeCaller<Patch_Cone>() );
833         GlobalCommands_insert( "PatchSphere", FreeCaller<Patch_Sphere>() );
834         GlobalCommands_insert( "SimplePatchMesh", FreeCaller<Patch_Plane>(), Accelerator( 'P', (GdkModifierType)GDK_SHIFT_MASK ) );
835         GlobalCommands_insert( "PatchInsertFirstColumn", FreeCaller<Patch_InsertFirstColumn>(), Accelerator( GDK_KP_Add, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
836         GlobalCommands_insert( "PatchInsertLastColumn", FreeCaller<Patch_InsertLastColumn>() );
837         GlobalCommands_insert( "PatchInsertFirstRow", FreeCaller<Patch_InsertFirstRow>(), Accelerator( GDK_KP_Add, (GdkModifierType)GDK_CONTROL_MASK ) );
838         GlobalCommands_insert( "PatchInsertLastRow", FreeCaller<Patch_InsertLastRow>() );
839         GlobalCommands_insert( "PatchDeleteFirstColumn", FreeCaller<Patch_DeleteFirstColumn>() );
840         GlobalCommands_insert( "PatchDeleteLastColumn", FreeCaller<Patch_DeleteLastColumn>(), Accelerator( GDK_KP_Subtract, (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
841         GlobalCommands_insert( "PatchDeleteFirstRow", FreeCaller<Patch_DeleteFirstRow>() );
842         GlobalCommands_insert( "PatchDeleteLastRow", FreeCaller<Patch_DeleteLastRow>(), Accelerator( GDK_KP_Subtract, (GdkModifierType)GDK_CONTROL_MASK ) );
843         GlobalCommands_insert( "InvertCurve", FreeCaller<Patch_Invert>(), Accelerator( 'I', (GdkModifierType)GDK_CONTROL_MASK ) );
844         GlobalCommands_insert( "RedisperseRows", FreeCaller<Patch_RedisperseRows>(), Accelerator( 'E', (GdkModifierType)GDK_CONTROL_MASK ) );
845         GlobalCommands_insert( "RedisperseCols", FreeCaller<Patch_RedisperseCols>(), Accelerator( 'E', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
846         GlobalCommands_insert( "SmoothRows", FreeCaller<Patch_SmoothRows>(), Accelerator( 'W', (GdkModifierType)GDK_CONTROL_MASK ) );
847         GlobalCommands_insert( "SmoothCols", FreeCaller<Patch_SmoothCols>(), Accelerator( 'W', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
848         GlobalCommands_insert( "MatrixTranspose", FreeCaller<Patch_Transpose>(), Accelerator( 'M', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
849         GlobalCommands_insert( "CapCurrentCurve", FreeCaller<Patch_Cap>(), Accelerator( 'C', (GdkModifierType)GDK_SHIFT_MASK ) );
850         GlobalCommands_insert( "CycleCapTexturePatch", FreeCaller<Patch_CycleProjection>(), Accelerator( 'N', (GdkModifierType)GDK_SHIFT_MASK ) );
851 //      GlobalCommands_insert( "MakeOverlayPatch", FreeCaller<Patch_OverlayOn>(), Accelerator( 'Y' ) );
852 //      GlobalCommands_insert( "ClearPatchOverlays", FreeCaller<Patch_OverlayOff>(), Accelerator( 'L', (GdkModifierType)GDK_CONTROL_MASK ) );
853         GlobalCommands_insert( "PatchDeform", FreeCaller<Patch_Deform>() );
854         GlobalCommands_insert( "PatchThicken", FreeCaller<Patch_Thicken>(), Accelerator( 'T', (GdkModifierType)GDK_CONTROL_MASK ) );
855 }
856
857 void Patch_constructToolbar( GtkToolbar* toolbar ){
858         toolbar_append_button( toolbar, "Put caps on the current patch (SHIFT + C)", "curve_cap.png", "CapCurrentCurve" );
859 }
860
861 void Patch_constructMenu( GtkMenu* menu ){
862         create_menu_item_with_mnemonic( menu, "Simple Patch Mesh...", "SimplePatchMesh" );
863         create_menu_item_with_mnemonic( menu, "Bevel", "PatchBevel" );
864         create_menu_item_with_mnemonic( menu, "End cap", "PatchEndCap" );
865         create_menu_item_with_mnemonic( menu, "Cylinder (9x3)", "PatchCylinder" );
866         create_menu_item_with_mnemonic( menu, "Square Cylinder (9x3)", "PatchSquareCylinder" );
867         create_menu_item_with_mnemonic( menu, "Exact Cylinder...", "PatchXactCylinder" );
868         create_menu_item_with_mnemonic( menu, "Cone (9x3)", "PatchCone" );
869         create_menu_item_with_mnemonic( menu, "Exact Cone...", "PatchXactCone" );
870         create_menu_item_with_mnemonic( menu, "Sphere (9x5)", "PatchSphere" );
871         create_menu_item_with_mnemonic( menu, "Exact Sphere...", "PatchXactSphere" );
872 //      {
873 //              GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "More Cylinders" );
874 //              if ( g_Layout_enableDetachableMenus.m_value ) {
875 //                      menu_tearoff( menu_in_menu );
876 //              }
877 //              create_menu_item_with_mnemonic( menu_in_menu, "Dense Cylinder", "PatchDenseCylinder" );
878 //              create_menu_item_with_mnemonic( menu_in_menu, "Very Dense Cylinder", "PatchVeryDenseCylinder" );
879 //              create_menu_item_with_mnemonic( menu_in_menu, "Square Cylinder", "PatchSquareCylinder" );
880 //      }
881 //      {
882 //              //not implemented
883 //              create_menu_item_with_mnemonic( menu, "Square Endcap", "PatchSquareBevel" );
884 //              create_menu_item_with_mnemonic( menu, "Square Bevel", "PatchSquareEndcap" );
885 //      }
886         menu_separator( menu );
887         create_menu_item_with_mnemonic( menu, "Cap Selection", "CapCurrentCurve" );
888         menu_separator( menu );
889         {
890                 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Insert/Delete" );
891                 if ( g_Layout_enableDetachableMenus.m_value ) {
892                         menu_tearoff( menu_in_menu );
893                 }
894                 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) First Columns", "PatchInsertFirstColumn" );
895                 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Last Columns", "PatchInsertLastColumn" );
896                 menu_separator( menu_in_menu );
897                 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) First Rows", "PatchInsertFirstRow" );
898                 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Last Rows", "PatchInsertLastRow" );
899                 menu_separator( menu_in_menu );
900                 create_menu_item_with_mnemonic( menu_in_menu, "Del First (2) Columns", "PatchDeleteFirstColumn" );
901                 create_menu_item_with_mnemonic( menu_in_menu, "Del Last (2) Columns", "PatchDeleteLastColumn" );
902                 menu_separator( menu_in_menu );
903                 create_menu_item_with_mnemonic( menu_in_menu, "Del First (2) Rows", "PatchDeleteFirstRow" );
904                 create_menu_item_with_mnemonic( menu_in_menu, "Del Last (2) Rows", "PatchDeleteLastRow" );
905         }
906         menu_separator( menu );
907         {
908                 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Matrix" );
909                 if ( g_Layout_enableDetachableMenus.m_value ) {
910                         menu_tearoff( menu_in_menu );
911                 }
912                 create_menu_item_with_mnemonic( menu_in_menu, "Invert", "InvertCurve" );
913                 create_menu_item_with_mnemonic( menu_in_menu, "Transpose", "MatrixTranspose" );
914
915                 menu_separator( menu_in_menu );
916                 create_menu_item_with_mnemonic( menu_in_menu, "Re-disperse Rows", "RedisperseRows" );
917                 create_menu_item_with_mnemonic( menu_in_menu, "Re-disperse Columns", "RedisperseCols" );
918
919                 menu_separator( menu_in_menu );
920                 create_menu_item_with_mnemonic( menu_in_menu, "Smooth Rows", "SmoothRows" );
921                 create_menu_item_with_mnemonic( menu_in_menu, "Smooth Columns", "SmoothCols" );
922         }
923         menu_separator( menu );
924         {
925                 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Texture" );
926                 if ( g_Layout_enableDetachableMenus.m_value ) {
927                         menu_tearoff( menu_in_menu );
928                 }
929                 create_menu_item_with_mnemonic( menu_in_menu, "Cycle Projection", "CycleCapTexturePatch" );
930                 create_menu_item_with_mnemonic( menu_in_menu, "Naturalize", "NaturalizePatch" );
931                 create_menu_item_with_mnemonic( menu_in_menu, "Invert X", "InvertCurveTextureX" );
932                 create_menu_item_with_mnemonic( menu_in_menu, "Invert Y", "InvertCurveTextureY" );
933
934         }
935 //      menu_separator( menu );
936 //      { //unfinished
937 //              GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Overlay" );
938 //              if ( g_Layout_enableDetachableMenus.m_value ) {
939 //                      menu_tearoff( menu_in_menu );
940 //              }
941 //              create_menu_item_with_mnemonic( menu_in_menu, "Set", "MakeOverlayPatch" );
942 //              create_menu_item_with_mnemonic( menu_in_menu, "Clear", "ClearPatchOverlays" );
943 //      }
944         menu_separator( menu );
945         create_menu_item_with_mnemonic( menu, "Deform...", "PatchDeform" );
946         create_menu_item_with_mnemonic( menu, "Thicken...", "PatchThicken" );
947 }
948
949
950 #include <gtk/gtkbox.h>
951 #include <gtk/gtktable.h>
952 #include <gtk/gtktogglebutton.h>
953 #include <gtk/gtkradiobutton.h>
954 #include <gtk/gtkcombobox.h>
955 #include <gtk/gtkspinbutton.h>
956 #include <gtk/gtklabel.h>
957 #include "gtkutil/dialog.h"
958 #include "gtkutil/widget.h"
959
960 void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols ){
961         ModalDialog dialog;
962         GtkComboBox* width;
963         GtkComboBox* height;
964         GtkWidget* redisperseCheckBox;
965
966         GtkWindow* window = create_dialog_window( MainFrame_getWindow(), "Patch density", G_CALLBACK( dialog_delete_callback ), &dialog );
967
968         GtkAccelGroup* accel = gtk_accel_group_new();
969         gtk_window_add_accel_group( window, accel );
970
971         {
972                 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
973                 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
974                 {
975                         GtkTable* table = create_dialog_table( 3, 2, 4, 4 );
976                         gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
977                         {
978                                 GtkLabel* label = GTK_LABEL( gtk_label_new( "Width:" ) );
979                                 gtk_widget_show( GTK_WIDGET( label ) );
980                                 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
981                                                                   (GtkAttachOptions) ( GTK_FILL ),
982                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
983                                 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
984                         }
985                         {
986                                 GtkLabel* label = GTK_LABEL( gtk_label_new( "Height:" ) );
987                                 gtk_widget_show( GTK_WIDGET( label ) );
988                                 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
989                                                                   (GtkAttachOptions) ( GTK_FILL ),
990                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
991                                 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
992                         }
993
994                         {
995                                 GtkComboBox* combo = GTK_COMBO_BOX( gtk_combo_box_new_text() );
996 #define D_ITEM( x ) if ( x >= mincols && ( !maxcols || x <= maxcols ) ) gtk_combo_box_append_text( combo, # x )
997                                 D_ITEM( 3 );
998                                 D_ITEM( 5 );
999                                 D_ITEM( 7 );
1000                                 D_ITEM( 9 );
1001                                 D_ITEM( 11 );
1002                                 D_ITEM( 13 );
1003                                 D_ITEM( 15 );
1004                                 D_ITEM( 17 );
1005                                 D_ITEM( 19 );
1006                                 D_ITEM( 21 );
1007                                 D_ITEM( 23 );
1008                                 D_ITEM( 25 );
1009                                 D_ITEM( 27 );
1010                                 D_ITEM( 29 );
1011                                 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
1012 #undef D_ITEM
1013                                 gtk_widget_show( GTK_WIDGET( combo ) );
1014                                 gtk_table_attach( table, GTK_WIDGET( combo ), 1, 2, 0, 1,
1015                                                                   (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1016                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1017
1018                                 width = combo;
1019                         }
1020                         {
1021                                 GtkComboBox* combo = GTK_COMBO_BOX( gtk_combo_box_new_text() );
1022 #define D_ITEM( x ) if ( x >= minrows && ( !maxrows || x <= maxrows ) ) gtk_combo_box_append_text( combo, # x )
1023                                 D_ITEM( 3 );
1024                                 D_ITEM( 5 );
1025                                 D_ITEM( 7 );
1026                                 D_ITEM( 9 );
1027                                 D_ITEM( 11 );
1028                                 D_ITEM( 13 );
1029                                 D_ITEM( 15 );
1030                                 D_ITEM( 17 );
1031                                 D_ITEM( 19 );
1032                                 D_ITEM( 21 );
1033                                 D_ITEM( 23 );
1034                                 D_ITEM( 25 );
1035                                 D_ITEM( 27 );
1036                                 D_ITEM( 29 );
1037                                 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
1038 #undef D_ITEM
1039                                 gtk_widget_show( GTK_WIDGET( combo ) );
1040                                 gtk_table_attach( table, GTK_WIDGET( combo ), 1, 2, 1, 2,
1041                                                                   (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1042                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1043
1044                                 height = combo;
1045                         }
1046
1047                         if( prefab != ePlane ){
1048                                 GtkWidget* _redisperseCheckBox = gtk_check_button_new_with_label( "Square" );
1049                                 gtk_widget_set_tooltip_text( _redisperseCheckBox, "Redisperse columns & rows" );
1050                                 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( _redisperseCheckBox ), FALSE );
1051                                 gtk_widget_show( _redisperseCheckBox );
1052                                 gtk_table_attach( table, _redisperseCheckBox, 0, 2, 2, 3,
1053                                                                 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1054                                                                 (GtkAttachOptions) ( 0 ), 0, 0 );
1055                                 redisperseCheckBox = _redisperseCheckBox;
1056                         }
1057
1058                 }
1059
1060                 {
1061                         GtkVBox* vbox = create_dialog_vbox( 4 );
1062                         gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
1063                         {
1064                                 GtkButton* button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
1065                                 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1066                                 widget_make_default( GTK_WIDGET( button ) );
1067                                 gtk_widget_grab_focus( GTK_WIDGET( button ) );
1068                                 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
1069                         }
1070                         {
1071                                 GtkButton* button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
1072                                 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1073                                 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
1074                         }
1075                 }
1076         }
1077
1078         // Initialize dialog
1079         gtk_combo_box_set_active( width, ( defcols - mincols ) / 2 );
1080         gtk_combo_box_set_active( height, ( defrows - minrows ) / 2 );
1081
1082         if ( modal_dialog_show( window, dialog ) == eIDOK ) {
1083                 int w = gtk_combo_box_get_active( width ) * 2 + mincols;
1084                 int h = gtk_combo_box_get_active( height ) * 2 + minrows;
1085                 bool redisperse = false;
1086                 if( prefab != ePlane ){
1087                         redisperse = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( redisperseCheckBox ) ) ? true : false;
1088                 }
1089                 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), prefab, GlobalXYWnd_getCurrentViewType(), w, h, redisperse );
1090         }
1091
1092         gtk_widget_destroy( GTK_WIDGET( window ) );
1093 }
1094
1095
1096 void DoPatchDeformDlg(){
1097         ModalDialog dialog;
1098         GtkWidget* deformW;
1099
1100     GtkWidget* rndY;
1101         GtkWidget* rndX;
1102
1103         GtkWindow* window = create_dialog_window( MainFrame_getWindow(), "Patch deform", G_CALLBACK( dialog_delete_callback ), &dialog );
1104
1105         GtkAccelGroup* accel = gtk_accel_group_new();
1106         gtk_window_add_accel_group( window, accel );
1107
1108         {
1109                 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
1110                 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
1111                 {
1112                         GtkTable* table = create_dialog_table( 2, 2, 4, 4 );
1113                         gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
1114                         {
1115                                 GtkLabel* label = GTK_LABEL( gtk_label_new( "Max deform:" ) );
1116                                 gtk_widget_show( GTK_WIDGET( label ) );
1117                                 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
1118                                                                   (GtkAttachOptions) ( GTK_FILL ),
1119                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1120                                 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1121                         }
1122 //                      {
1123 //                              GtkWidget* entry = gtk_entry_new();
1124 //                              gtk_entry_set_text( GTK_ENTRY( entry ), "64" );
1125 //                              gtk_widget_show( entry );
1126 //                              gtk_table_attach( table, entry, 1, 2, 0, 1,
1127 //                                                                (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1128 //                                                                (GtkAttachOptions) ( 0 ), 0, 0 );
1129 //
1130 //                              deformW = entry;
1131 //                      }
1132                         {
1133                                 GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 64, -9999, 9999, 1, 10, 0 ) );
1134                                 //GtkSpinButton* spin = GTK_SPIN_BUTTON( gtk_spin_button_new( adj, 1, 0 ) );
1135                                 GtkWidget* spin = gtk_spin_button_new( adj, 1, 0 );
1136                                 gtk_widget_show( spin );
1137                                 gtk_table_attach( table, spin, 1, 2, 0, 1,
1138                                                                   (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1139                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1140                                 gtk_widget_set_size_request( spin, 64, -1 );
1141                                 gtk_spin_button_set_numeric( GTK_SPIN_BUTTON( spin ), TRUE );
1142
1143                                 deformW = spin;
1144                         }
1145                         {
1146                                 // Create the radio button group for choosing the axis
1147                                 GtkWidget* _rndZ = gtk_radio_button_new_with_label_from_widget( NULL, "Z" );
1148                                 GtkWidget* _rndY = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_rndZ), "Y" );
1149                                 GtkWidget* _rndX = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_rndZ), "X" );
1150                                 gtk_widget_show( _rndZ );
1151                                 gtk_widget_show( _rndY );
1152                                 gtk_widget_show( _rndX );
1153
1154
1155                                 GtkHBox* _hbox = create_dialog_hbox( 4, 4 );
1156                                 gtk_table_attach( table, GTK_WIDGET( _hbox ), 0, 2, 1, 2,
1157                                                                   (GtkAttachOptions) ( GTK_FILL ),
1158                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1159                                 gtk_box_pack_start( GTK_BOX( _hbox ), GTK_WIDGET( _rndX ), TRUE, TRUE, 0 );
1160                                 gtk_box_pack_start( GTK_BOX( _hbox ), GTK_WIDGET( _rndY ), TRUE, TRUE, 0 );
1161                                 gtk_box_pack_start( GTK_BOX( _hbox ), GTK_WIDGET( _rndZ ), TRUE, TRUE, 0 );
1162
1163                                 rndX = _rndX;
1164                                 rndY = _rndY;
1165                         }
1166                 }
1167                 {
1168                         GtkVBox* vbox = create_dialog_vbox( 4 );
1169                         gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
1170                         {
1171                                 GtkButton* button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
1172                                 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1173                                 widget_make_default( GTK_WIDGET( button ) );
1174                                 gtk_widget_grab_focus( GTK_WIDGET( button ) );
1175                                 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
1176                         }
1177                         {
1178                                 GtkButton* button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
1179                                 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1180                                 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
1181                         }
1182                 }
1183         }
1184
1185         if ( modal_dialog_show( window, dialog ) == eIDOK ) {
1186                 //int deform = static_cast<int>( atoi( gtk_entry_get_text( GTK_ENTRY( deformW ) ) ) );
1187                 gtk_spin_button_update ( GTK_SPIN_BUTTON( deformW ) );
1188                 int deform = static_cast<int>( gtk_spin_button_get_value( GTK_SPIN_BUTTON( deformW ) ) );
1189                 int axis = 2; //Z
1190                 if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( rndX ) ) ){
1191                         axis = 0;
1192                 }
1193                 else if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( rndY ) ) ){
1194                         axis = 1;
1195                 }
1196                 Scene_PatchDeform( GlobalSceneGraph(), deform, axis );
1197         }
1198         gtk_widget_destroy( GTK_WIDGET( window ) );
1199 }
1200
1201
1202
1203 EMessageBoxReturn DoCapDlg( ECapDialog* type ){
1204         ModalDialog dialog;
1205         ModalDialogButton ok_button( dialog, eIDOK );
1206         ModalDialogButton cancel_button( dialog, eIDCANCEL );
1207         GtkWidget* bevel;
1208         GtkWidget* ibevel;
1209         GtkWidget* endcap;
1210         GtkWidget* iendcap;
1211         GtkWidget* cylinder;
1212
1213         GtkWindow* window = create_modal_dialog_window( MainFrame_getWindow(), "Cap", dialog );
1214
1215         GtkAccelGroup *accel_group = gtk_accel_group_new();
1216         gtk_window_add_accel_group( window, accel_group );
1217
1218         {
1219                 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
1220                 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
1221
1222                 {
1223                         // Gef: Added a vbox to contain the toggle buttons
1224                         GtkVBox* radio_vbox = create_dialog_vbox( 4 );
1225                         gtk_container_add( GTK_CONTAINER( hbox ), GTK_WIDGET( radio_vbox ) );
1226
1227                         {
1228                                 GtkTable* table = GTK_TABLE( gtk_table_new( 5, 2, FALSE ) );
1229                                 gtk_widget_show( GTK_WIDGET( table ) );
1230                                 gtk_box_pack_start( GTK_BOX( radio_vbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
1231                                 gtk_table_set_row_spacings( table, 5 );
1232                                 gtk_table_set_col_spacings( table, 5 );
1233
1234                                 {
1235                                         GtkImage* image = new_local_image( "cap_bevel.png" );
1236                                         gtk_widget_show( GTK_WIDGET( image ) );
1237                                         gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 0, 1,
1238                                                                           (GtkAttachOptions) ( GTK_FILL ),
1239                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1240                                 }
1241                                 {
1242                                         GtkImage* image = new_local_image( "cap_endcap.png" );
1243                                         gtk_widget_show( GTK_WIDGET( image ) );
1244                                         gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 1, 2,
1245                                                                           (GtkAttachOptions) ( GTK_FILL ),
1246                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1247                                 }
1248                                 {
1249                                         GtkImage* image = new_local_image( "cap_ibevel.png" );
1250                                         gtk_widget_show( GTK_WIDGET( image ) );
1251                                         gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 2, 3,
1252                                                                           (GtkAttachOptions) ( GTK_FILL ),
1253                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1254                                 }
1255                                 {
1256                                         GtkImage* image = new_local_image( "cap_iendcap.png" );
1257                                         gtk_widget_show( GTK_WIDGET( image ) );
1258                                         gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 3, 4,
1259                                                                           (GtkAttachOptions) ( GTK_FILL ),
1260                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1261                                 }
1262                                 {
1263                                         GtkImage* image = new_local_image( "cap_cylinder.png" );
1264                                         gtk_widget_show( GTK_WIDGET( image ) );
1265                                         gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 4, 5,
1266                                                                           (GtkAttachOptions) ( GTK_FILL ),
1267                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1268                                 }
1269
1270                                 GSList* group = 0;
1271                                 {
1272                                         GtkWidget* button = gtk_radio_button_new_with_label( group, "Bevel" );
1273                                         gtk_widget_show( button );
1274                                         gtk_table_attach( table, button, 1, 2, 0, 1,
1275                                                                           (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1276                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1277                                         group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1278
1279                                         bevel = button;
1280                                 }
1281                                 {
1282                                         GtkWidget* button = gtk_radio_button_new_with_label( group, "Endcap" );
1283                                         gtk_widget_show( button );
1284                                         gtk_table_attach( table, button, 1, 2, 1, 2,
1285                                                                           (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1286                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1287                                         group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1288
1289                                         endcap = button;
1290                                 }
1291                                 {
1292                                         GtkWidget* button = gtk_radio_button_new_with_label( group, "Inverted Bevel" );
1293                                         gtk_widget_show( button );
1294                                         gtk_table_attach( table, button, 1, 2, 2, 3,
1295                                                                           (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1296                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1297                                         group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1298
1299                                         ibevel = button;
1300                                 }
1301                                 {
1302                                         GtkWidget* button = gtk_radio_button_new_with_label( group, "Inverted Endcap" );
1303                                         gtk_widget_show( button );
1304                                         gtk_table_attach( table, button, 1, 2, 3, 4,
1305                                                                           (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1306                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1307                                         group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1308
1309                                         iendcap = button;
1310                                 }
1311                                 {
1312                                         GtkWidget* button = gtk_radio_button_new_with_label( group, "Cylinder" );
1313                                         gtk_widget_show( button );
1314                                         gtk_table_attach( table, button, 1, 2, 4, 5,
1315                                                                           (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1316                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1317                                         group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1318
1319                                         cylinder = button;
1320                                 }
1321                         }
1322                 }
1323
1324                 {
1325                         GtkVBox* vbox = create_dialog_vbox( 4 );
1326                         gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), FALSE, FALSE, 0 );
1327                         {
1328                                 GtkButton* button = create_modal_dialog_button( "OK", ok_button );
1329                                 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1330                                 widget_make_default( GTK_WIDGET( button ) );
1331                                 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel_group, GDK_Return, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
1332                         }
1333                         {
1334                                 GtkButton* button = create_modal_dialog_button( "Cancel", cancel_button );
1335                                 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1336                                 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel_group, GDK_Escape, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
1337                         }
1338                 }
1339         }
1340
1341         // Initialize dialog
1342         gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( bevel ), TRUE );
1343
1344         EMessageBoxReturn ret = modal_dialog_show( window, dialog );
1345         if ( ret == eIDOK ) {
1346                 if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( bevel ) ) ) {
1347                         *type = PATCHCAP_BEVEL;
1348                 }
1349                 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( endcap ) ) ) {
1350                         *type = PATCHCAP_ENDCAP;
1351                 }
1352                 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( ibevel ) ) ) {
1353                         *type = PATCHCAP_INVERTED_BEVEL;
1354                 }
1355                 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( iendcap ) ) ) {
1356                         *type = PATCHCAP_INVERTED_ENDCAP;
1357                 }
1358                 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( cylinder ) ) ) {
1359                         *type = PATCHCAP_CYLINDER;
1360                 }
1361         }
1362
1363         gtk_widget_destroy( GTK_WIDGET( window ) );
1364
1365         return ret;
1366 }
1367
1368
1369 void DoPatchThickenDlg(){
1370         ModalDialog dialog;
1371         GtkWidget* thicknessW;
1372         GtkWidget* seamsW;
1373         GtkWidget* radX;
1374         GtkWidget* radY;
1375         GtkWidget* radZ;
1376
1377         GtkWindow* window = create_dialog_window( MainFrame_getWindow(), "Patch thicken", G_CALLBACK( dialog_delete_callback ), &dialog );
1378
1379         GtkAccelGroup* accel = gtk_accel_group_new();
1380         gtk_window_add_accel_group( window, accel );
1381
1382         {
1383                 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
1384                 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
1385                 {
1386                         GtkTable* table = create_dialog_table( 2, 4, 4, 4 );
1387                         gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
1388                         {
1389                                 GtkLabel* label = GTK_LABEL( gtk_label_new( "Thickness:" ) );
1390                                 gtk_widget_show( GTK_WIDGET( label ) );
1391                                 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
1392                                                                   (GtkAttachOptions) ( GTK_FILL ),
1393                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1394                                 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1395                         }
1396 //                      {
1397 //                              GtkWidget* entry = gtk_entry_new();
1398 //                              gtk_entry_set_text( GTK_ENTRY( entry ), "16" );
1399 //                              gtk_widget_set_size_request( entry, 40, -1 );
1400 //                              gtk_widget_show( entry );
1401 //                              gtk_table_attach( table, entry, 1, 2, 0, 1,
1402 //                                                                (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1403 //                                                                (GtkAttachOptions) ( 0 ), 0, 0 );
1404 //
1405 //                              thicknessW = entry;
1406 //                      }
1407                         {
1408                                 GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 16, -9999, 9999, 1, 10, 0 ) );
1409                                 GtkWidget* spin = gtk_spin_button_new( adj, 1, 0 );
1410                                 gtk_widget_show( spin );
1411                                 gtk_table_attach( table, spin, 1, 2, 0, 1,
1412                                                                   (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1413                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1414                                 gtk_widget_set_size_request( spin, 48, -1 );
1415                                 gtk_spin_button_set_numeric( GTK_SPIN_BUTTON( spin ), TRUE );
1416
1417                                 thicknessW = spin;
1418                         }
1419                         {
1420                                 // Create the "create seams" label
1421                                 GtkWidget* _seamsCheckBox = gtk_check_button_new_with_label( "Side walls" );
1422                                 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( _seamsCheckBox ), TRUE );
1423                                 gtk_widget_show( _seamsCheckBox );
1424                                 gtk_table_attach( table, _seamsCheckBox, 2, 4, 0, 1,
1425                                                                   (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1426                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1427                                 seamsW = _seamsCheckBox;
1428
1429                         }
1430                         {
1431                                 // Create the radio button group for choosing the extrude axis
1432                                 GtkWidget* _radNormals = gtk_radio_button_new_with_label( NULL, "Normal" );
1433                                 GtkWidget* _radX = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "X" );
1434                                 GtkWidget* _radY = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "Y" );
1435                                 GtkWidget* _radZ = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "Z" );
1436                                 gtk_widget_show( _radNormals );
1437                                 gtk_widget_show( _radX );
1438                                 gtk_widget_show( _radY );
1439                                 gtk_widget_show( _radZ );
1440
1441
1442                                 // Pack the buttons into the table
1443                                 gtk_table_attach( table, _radNormals, 0, 1, 1, 2,
1444                                                                   (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1445                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1446                                 gtk_table_attach( table, _radX, 1, 2, 1, 2,
1447                                                                   (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1448                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1449                                 gtk_table_attach( table, _radY, 2, 3, 1, 2,
1450                                                                   (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1451                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1452                                 gtk_table_attach( table, _radZ, 3, 4, 1, 2,
1453                                                                   (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1454                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1455                                 radX = _radX;
1456                                 radY = _radY;
1457                                 radZ = _radZ;
1458                         }
1459                 }
1460                 {
1461                         GtkVBox* vbox = create_dialog_vbox( 4 );
1462                         gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
1463                         {
1464                                 GtkButton* button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
1465                                 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1466                                 widget_make_default( GTK_WIDGET( button ) );
1467                                 gtk_widget_grab_focus( GTK_WIDGET( button ) );
1468                                 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
1469                         }
1470                         {
1471                                 GtkButton* button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
1472                                 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1473                                 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
1474                         }
1475                 }
1476         }
1477
1478         if ( modal_dialog_show( window, dialog ) == eIDOK ) {
1479                 int axis = 3; // Extrude along normals
1480                 bool seams;
1481                 //float thickness = static_cast<float>( atoi( gtk_entry_get_text( GTK_ENTRY( thicknessW ) ) ) );
1482                 gtk_spin_button_update ( GTK_SPIN_BUTTON( thicknessW ) );
1483                 float thickness = static_cast<float>( gtk_spin_button_get_value( GTK_SPIN_BUTTON( thicknessW ) ) );
1484                 seams = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( seamsW )) ? true : false;
1485
1486                 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radX))) {
1487                         axis = 0;
1488                 }
1489                 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radY))) {
1490                         axis = 1;
1491                 }
1492                 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radZ))) {
1493                         axis = 2;
1494                 }
1495
1496                 Scene_PatchThicken( GlobalSceneGraph(), thickness, seams, axis );
1497         }
1498
1499         gtk_widget_destroy( GTK_WIDGET( window ) );
1500 }