]> git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/patchmanip.cpp
Q3map2:
[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( "RedisperseRows", FreeCaller<Patch_RedisperseRows>() );
846         //GlobalCommands_insert( "RedisperseCols", FreeCaller<Patch_RedisperseCols>(), Accelerator( 'E', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
847         GlobalCommands_insert( "RedisperseCols", FreeCaller<Patch_RedisperseCols>() );
848         GlobalCommands_insert( "SmoothRows", FreeCaller<Patch_SmoothRows>(), Accelerator( 'W', (GdkModifierType)GDK_CONTROL_MASK ) );
849         GlobalCommands_insert( "SmoothCols", FreeCaller<Patch_SmoothCols>(), Accelerator( 'W', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
850         GlobalCommands_insert( "MatrixTranspose", FreeCaller<Patch_Transpose>(), Accelerator( 'M', (GdkModifierType)( GDK_SHIFT_MASK | GDK_CONTROL_MASK ) ) );
851         GlobalCommands_insert( "CapCurrentCurve", FreeCaller<Patch_Cap>(), Accelerator( 'C', (GdkModifierType)GDK_SHIFT_MASK ) );
852         GlobalCommands_insert( "CycleCapTexturePatch", FreeCaller<Patch_CycleProjection>(), Accelerator( 'N', (GdkModifierType)GDK_SHIFT_MASK ) );
853 //      GlobalCommands_insert( "MakeOverlayPatch", FreeCaller<Patch_OverlayOn>(), Accelerator( 'Y' ) );
854 //      GlobalCommands_insert( "ClearPatchOverlays", FreeCaller<Patch_OverlayOff>(), Accelerator( 'L', (GdkModifierType)GDK_CONTROL_MASK ) );
855         GlobalCommands_insert( "PatchDeform", FreeCaller<Patch_Deform>() );
856         GlobalCommands_insert( "PatchThicken", FreeCaller<Patch_Thicken>(), Accelerator( 'T', (GdkModifierType)GDK_CONTROL_MASK ) );
857 }
858
859 void Patch_constructToolbar( GtkToolbar* toolbar ){
860         toolbar_append_button( toolbar, "Put caps on the current patch (SHIFT + C)", "curve_cap.png", "CapCurrentCurve" );
861 }
862
863 void Patch_constructMenu( GtkMenu* menu ){
864         create_menu_item_with_mnemonic( menu, "Simple Patch Mesh...", "SimplePatchMesh" );
865         create_menu_item_with_mnemonic( menu, "Bevel", "PatchBevel" );
866         create_menu_item_with_mnemonic( menu, "End cap", "PatchEndCap" );
867         create_menu_item_with_mnemonic( menu, "Cylinder (9x3)", "PatchCylinder" );
868         create_menu_item_with_mnemonic( menu, "Square Cylinder (9x3)", "PatchSquareCylinder" );
869         create_menu_item_with_mnemonic( menu, "Exact Cylinder...", "PatchXactCylinder" );
870         create_menu_item_with_mnemonic( menu, "Cone (9x3)", "PatchCone" );
871         create_menu_item_with_mnemonic( menu, "Exact Cone...", "PatchXactCone" );
872         create_menu_item_with_mnemonic( menu, "Sphere (9x5)", "PatchSphere" );
873         create_menu_item_with_mnemonic( menu, "Exact Sphere...", "PatchXactSphere" );
874 //      {
875 //              GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "More Cylinders" );
876 //              if ( g_Layout_enableDetachableMenus.m_value ) {
877 //                      menu_tearoff( menu_in_menu );
878 //              }
879 //              create_menu_item_with_mnemonic( menu_in_menu, "Dense Cylinder", "PatchDenseCylinder" );
880 //              create_menu_item_with_mnemonic( menu_in_menu, "Very Dense Cylinder", "PatchVeryDenseCylinder" );
881 //              create_menu_item_with_mnemonic( menu_in_menu, "Square Cylinder", "PatchSquareCylinder" );
882 //      }
883 //      {
884 //              //not implemented
885 //              create_menu_item_with_mnemonic( menu, "Square Endcap", "PatchSquareBevel" );
886 //              create_menu_item_with_mnemonic( menu, "Square Bevel", "PatchSquareEndcap" );
887 //      }
888         menu_separator( menu );
889         create_menu_item_with_mnemonic( menu, "Cap Selection", "CapCurrentCurve" );
890         menu_separator( menu );
891         {
892                 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Insert/Delete" );
893                 if ( g_Layout_enableDetachableMenus.m_value ) {
894                         menu_tearoff( menu_in_menu );
895                 }
896                 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) First Columns", "PatchInsertFirstColumn" );
897                 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Last Columns", "PatchInsertLastColumn" );
898                 menu_separator( menu_in_menu );
899                 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) First Rows", "PatchInsertFirstRow" );
900                 create_menu_item_with_mnemonic( menu_in_menu, "Insert (2) Last Rows", "PatchInsertLastRow" );
901                 menu_separator( menu_in_menu );
902                 create_menu_item_with_mnemonic( menu_in_menu, "Del First (2) Columns", "PatchDeleteFirstColumn" );
903                 create_menu_item_with_mnemonic( menu_in_menu, "Del Last (2) Columns", "PatchDeleteLastColumn" );
904                 menu_separator( menu_in_menu );
905                 create_menu_item_with_mnemonic( menu_in_menu, "Del First (2) Rows", "PatchDeleteFirstRow" );
906                 create_menu_item_with_mnemonic( menu_in_menu, "Del Last (2) Rows", "PatchDeleteLastRow" );
907         }
908         menu_separator( menu );
909         {
910                 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Matrix" );
911                 if ( g_Layout_enableDetachableMenus.m_value ) {
912                         menu_tearoff( menu_in_menu );
913                 }
914                 create_menu_item_with_mnemonic( menu_in_menu, "Invert", "InvertCurve" );
915                 create_menu_item_with_mnemonic( menu_in_menu, "Transpose", "MatrixTranspose" );
916
917                 menu_separator( menu_in_menu );
918                 create_menu_item_with_mnemonic( menu_in_menu, "Re-disperse Rows", "RedisperseRows" );
919                 create_menu_item_with_mnemonic( menu_in_menu, "Re-disperse Columns", "RedisperseCols" );
920
921                 menu_separator( menu_in_menu );
922                 create_menu_item_with_mnemonic( menu_in_menu, "Smooth Rows", "SmoothRows" );
923                 create_menu_item_with_mnemonic( menu_in_menu, "Smooth Columns", "SmoothCols" );
924         }
925         menu_separator( menu );
926         {
927                 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Texture" );
928                 if ( g_Layout_enableDetachableMenus.m_value ) {
929                         menu_tearoff( menu_in_menu );
930                 }
931                 create_menu_item_with_mnemonic( menu_in_menu, "Cycle Projection", "CycleCapTexturePatch" );
932                 create_menu_item_with_mnemonic( menu_in_menu, "Naturalize", "NaturalizePatch" );
933                 create_menu_item_with_mnemonic( menu_in_menu, "Invert X", "InvertCurveTextureX" );
934                 create_menu_item_with_mnemonic( menu_in_menu, "Invert Y", "InvertCurveTextureY" );
935
936         }
937 //      menu_separator( menu );
938 //      { //unfinished
939 //              GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic( menu, "Overlay" );
940 //              if ( g_Layout_enableDetachableMenus.m_value ) {
941 //                      menu_tearoff( menu_in_menu );
942 //              }
943 //              create_menu_item_with_mnemonic( menu_in_menu, "Set", "MakeOverlayPatch" );
944 //              create_menu_item_with_mnemonic( menu_in_menu, "Clear", "ClearPatchOverlays" );
945 //      }
946         menu_separator( menu );
947         create_menu_item_with_mnemonic( menu, "Deform...", "PatchDeform" );
948         create_menu_item_with_mnemonic( menu, "Thicken...", "PatchThicken" );
949 }
950
951
952 #include <gtk/gtkbox.h>
953 #include <gtk/gtktable.h>
954 #include <gtk/gtktogglebutton.h>
955 #include <gtk/gtkradiobutton.h>
956 #include <gtk/gtkcombobox.h>
957 #include <gtk/gtkspinbutton.h>
958 #include <gtk/gtklabel.h>
959 #include "gtkutil/dialog.h"
960 #include "gtkutil/widget.h"
961
962 void DoNewPatchDlg( EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols ){
963         ModalDialog dialog;
964         GtkComboBox* width;
965         GtkComboBox* height;
966         GtkWidget* redisperseCheckBox;
967
968         GtkWindow* window = create_dialog_window( MainFrame_getWindow(), "Patch density", G_CALLBACK( dialog_delete_callback ), &dialog );
969
970         GtkAccelGroup* accel = gtk_accel_group_new();
971         gtk_window_add_accel_group( window, accel );
972
973         {
974                 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
975                 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
976                 {
977                         GtkTable* table = create_dialog_table( 3, 2, 4, 4 );
978                         gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
979                         {
980                                 GtkLabel* label = GTK_LABEL( gtk_label_new( "Width:" ) );
981                                 gtk_widget_show( GTK_WIDGET( label ) );
982                                 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
983                                                                   (GtkAttachOptions) ( GTK_FILL ),
984                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
985                                 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
986                         }
987                         {
988                                 GtkLabel* label = GTK_LABEL( gtk_label_new( "Height:" ) );
989                                 gtk_widget_show( GTK_WIDGET( label ) );
990                                 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
991                                                                   (GtkAttachOptions) ( GTK_FILL ),
992                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
993                                 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
994                         }
995
996                         {
997                                 GtkComboBox* combo = GTK_COMBO_BOX( gtk_combo_box_new_text() );
998 #define D_ITEM( x ) if ( x >= mincols && ( !maxcols || x <= maxcols ) ) gtk_combo_box_append_text( combo, # x )
999                                 D_ITEM( 3 );
1000                                 D_ITEM( 5 );
1001                                 D_ITEM( 7 );
1002                                 D_ITEM( 9 );
1003                                 D_ITEM( 11 );
1004                                 D_ITEM( 13 );
1005                                 D_ITEM( 15 );
1006                                 D_ITEM( 17 );
1007                                 D_ITEM( 19 );
1008                                 D_ITEM( 21 );
1009                                 D_ITEM( 23 );
1010                                 D_ITEM( 25 );
1011                                 D_ITEM( 27 );
1012                                 D_ITEM( 29 );
1013                                 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
1014 #undef D_ITEM
1015                                 gtk_widget_show( GTK_WIDGET( combo ) );
1016                                 gtk_table_attach( table, GTK_WIDGET( combo ), 1, 2, 0, 1,
1017                                                                   (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1018                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1019
1020                                 width = combo;
1021                         }
1022                         {
1023                                 GtkComboBox* combo = GTK_COMBO_BOX( gtk_combo_box_new_text() );
1024 #define D_ITEM( x ) if ( x >= minrows && ( !maxrows || x <= maxrows ) ) gtk_combo_box_append_text( combo, # x )
1025                                 D_ITEM( 3 );
1026                                 D_ITEM( 5 );
1027                                 D_ITEM( 7 );
1028                                 D_ITEM( 9 );
1029                                 D_ITEM( 11 );
1030                                 D_ITEM( 13 );
1031                                 D_ITEM( 15 );
1032                                 D_ITEM( 17 );
1033                                 D_ITEM( 19 );
1034                                 D_ITEM( 21 );
1035                                 D_ITEM( 23 );
1036                                 D_ITEM( 25 );
1037                                 D_ITEM( 27 );
1038                                 D_ITEM( 29 );
1039                                 D_ITEM( 31 ); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
1040 #undef D_ITEM
1041                                 gtk_widget_show( GTK_WIDGET( combo ) );
1042                                 gtk_table_attach( table, GTK_WIDGET( combo ), 1, 2, 1, 2,
1043                                                                   (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1044                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1045
1046                                 height = combo;
1047                         }
1048
1049                         if( prefab != ePlane ){
1050                                 GtkWidget* _redisperseCheckBox = gtk_check_button_new_with_label( "Square" );
1051                                 gtk_widget_set_tooltip_text( _redisperseCheckBox, "Redisperse columns & rows" );
1052                                 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( _redisperseCheckBox ), FALSE );
1053                                 gtk_widget_show( _redisperseCheckBox );
1054                                 gtk_table_attach( table, _redisperseCheckBox, 0, 2, 2, 3,
1055                                                                 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1056                                                                 (GtkAttachOptions) ( 0 ), 0, 0 );
1057                                 redisperseCheckBox = _redisperseCheckBox;
1058                         }
1059
1060                 }
1061
1062                 {
1063                         GtkVBox* vbox = create_dialog_vbox( 4 );
1064                         gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
1065                         {
1066                                 GtkButton* button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
1067                                 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1068                                 widget_make_default( GTK_WIDGET( button ) );
1069                                 gtk_widget_grab_focus( GTK_WIDGET( button ) );
1070                                 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
1071                         }
1072                         {
1073                                 GtkButton* button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
1074                                 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1075                                 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
1076                         }
1077                 }
1078         }
1079
1080         // Initialize dialog
1081         gtk_combo_box_set_active( width, ( defcols - mincols ) / 2 );
1082         gtk_combo_box_set_active( height, ( defrows - minrows ) / 2 );
1083
1084         if ( modal_dialog_show( window, dialog ) == eIDOK ) {
1085                 int w = gtk_combo_box_get_active( width ) * 2 + mincols;
1086                 int h = gtk_combo_box_get_active( height ) * 2 + minrows;
1087                 bool redisperse = false;
1088                 if( prefab != ePlane ){
1089                         redisperse = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( redisperseCheckBox ) ) ? true : false;
1090                 }
1091                 Scene_PatchConstructPrefab( GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ), prefab, GlobalXYWnd_getCurrentViewType(), w, h, redisperse );
1092         }
1093
1094         gtk_widget_destroy( GTK_WIDGET( window ) );
1095 }
1096
1097
1098 void DoPatchDeformDlg(){
1099         ModalDialog dialog;
1100         GtkWidget* deformW;
1101
1102     GtkWidget* rndY;
1103         GtkWidget* rndX;
1104
1105         GtkWindow* window = create_dialog_window( MainFrame_getWindow(), "Patch deform", G_CALLBACK( dialog_delete_callback ), &dialog );
1106
1107         GtkAccelGroup* accel = gtk_accel_group_new();
1108         gtk_window_add_accel_group( window, accel );
1109
1110         {
1111                 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
1112                 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
1113                 {
1114                         GtkTable* table = create_dialog_table( 2, 2, 4, 4 );
1115                         gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
1116                         {
1117                                 GtkLabel* label = GTK_LABEL( gtk_label_new( "Max deform:" ) );
1118                                 gtk_widget_show( GTK_WIDGET( label ) );
1119                                 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
1120                                                                   (GtkAttachOptions) ( GTK_FILL ),
1121                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1122                                 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1123                         }
1124 //                      {
1125 //                              GtkWidget* entry = gtk_entry_new();
1126 //                              gtk_entry_set_text( GTK_ENTRY( entry ), "64" );
1127 //                              gtk_widget_show( entry );
1128 //                              gtk_table_attach( table, entry, 1, 2, 0, 1,
1129 //                                                                (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1130 //                                                                (GtkAttachOptions) ( 0 ), 0, 0 );
1131 //
1132 //                              deformW = entry;
1133 //                      }
1134                         {
1135                                 GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 64, -9999, 9999, 1, 10, 0 ) );
1136                                 //GtkSpinButton* spin = GTK_SPIN_BUTTON( gtk_spin_button_new( adj, 1, 0 ) );
1137                                 GtkWidget* spin = gtk_spin_button_new( adj, 1, 0 );
1138                                 gtk_widget_show( spin );
1139                                 gtk_table_attach( table, spin, 1, 2, 0, 1,
1140                                                                   (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1141                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1142                                 gtk_widget_set_size_request( spin, 64, -1 );
1143                                 gtk_spin_button_set_numeric( GTK_SPIN_BUTTON( spin ), TRUE );
1144
1145                                 deformW = spin;
1146                         }
1147                         {
1148                                 // Create the radio button group for choosing the axis
1149                                 GtkWidget* _rndZ = gtk_radio_button_new_with_label_from_widget( NULL, "Z" );
1150                                 GtkWidget* _rndY = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_rndZ), "Y" );
1151                                 GtkWidget* _rndX = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_rndZ), "X" );
1152                                 gtk_widget_show( _rndZ );
1153                                 gtk_widget_show( _rndY );
1154                                 gtk_widget_show( _rndX );
1155
1156
1157                                 GtkHBox* _hbox = create_dialog_hbox( 4, 4 );
1158                                 gtk_table_attach( table, GTK_WIDGET( _hbox ), 0, 2, 1, 2,
1159                                                                   (GtkAttachOptions) ( GTK_FILL ),
1160                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1161                                 gtk_box_pack_start( GTK_BOX( _hbox ), GTK_WIDGET( _rndX ), TRUE, TRUE, 0 );
1162                                 gtk_box_pack_start( GTK_BOX( _hbox ), GTK_WIDGET( _rndY ), TRUE, TRUE, 0 );
1163                                 gtk_box_pack_start( GTK_BOX( _hbox ), GTK_WIDGET( _rndZ ), TRUE, TRUE, 0 );
1164
1165                                 rndX = _rndX;
1166                                 rndY = _rndY;
1167                         }
1168                 }
1169                 {
1170                         GtkVBox* vbox = create_dialog_vbox( 4 );
1171                         gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
1172                         {
1173                                 GtkButton* button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
1174                                 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1175                                 widget_make_default( GTK_WIDGET( button ) );
1176                                 gtk_widget_grab_focus( GTK_WIDGET( button ) );
1177                                 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
1178                         }
1179                         {
1180                                 GtkButton* button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
1181                                 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1182                                 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
1183                         }
1184                 }
1185         }
1186
1187         if ( modal_dialog_show( window, dialog ) == eIDOK ) {
1188                 //int deform = static_cast<int>( atoi( gtk_entry_get_text( GTK_ENTRY( deformW ) ) ) );
1189                 gtk_spin_button_update ( GTK_SPIN_BUTTON( deformW ) );
1190                 int deform = static_cast<int>( gtk_spin_button_get_value( GTK_SPIN_BUTTON( deformW ) ) );
1191                 int axis = 2; //Z
1192                 if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( rndX ) ) ){
1193                         axis = 0;
1194                 }
1195                 else if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( rndY ) ) ){
1196                         axis = 1;
1197                 }
1198                 Scene_PatchDeform( GlobalSceneGraph(), deform, axis );
1199         }
1200         gtk_widget_destroy( GTK_WIDGET( window ) );
1201 }
1202
1203
1204
1205 EMessageBoxReturn DoCapDlg( ECapDialog* type ){
1206         ModalDialog dialog;
1207         ModalDialogButton ok_button( dialog, eIDOK );
1208         ModalDialogButton cancel_button( dialog, eIDCANCEL );
1209         GtkWidget* bevel;
1210         GtkWidget* ibevel;
1211         GtkWidget* endcap;
1212         GtkWidget* iendcap;
1213         GtkWidget* cylinder;
1214
1215         GtkWindow* window = create_modal_dialog_window( MainFrame_getWindow(), "Cap", dialog );
1216
1217         GtkAccelGroup *accel_group = gtk_accel_group_new();
1218         gtk_window_add_accel_group( window, accel_group );
1219
1220         {
1221                 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
1222                 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
1223
1224                 {
1225                         // Gef: Added a vbox to contain the toggle buttons
1226                         GtkVBox* radio_vbox = create_dialog_vbox( 4 );
1227                         gtk_container_add( GTK_CONTAINER( hbox ), GTK_WIDGET( radio_vbox ) );
1228
1229                         {
1230                                 GtkTable* table = GTK_TABLE( gtk_table_new( 5, 2, FALSE ) );
1231                                 gtk_widget_show( GTK_WIDGET( table ) );
1232                                 gtk_box_pack_start( GTK_BOX( radio_vbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
1233                                 gtk_table_set_row_spacings( table, 5 );
1234                                 gtk_table_set_col_spacings( table, 5 );
1235
1236                                 {
1237                                         GtkImage* image = new_local_image( "cap_bevel.png" );
1238                                         gtk_widget_show( GTK_WIDGET( image ) );
1239                                         gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 0, 1,
1240                                                                           (GtkAttachOptions) ( GTK_FILL ),
1241                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1242                                 }
1243                                 {
1244                                         GtkImage* image = new_local_image( "cap_endcap.png" );
1245                                         gtk_widget_show( GTK_WIDGET( image ) );
1246                                         gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 1, 2,
1247                                                                           (GtkAttachOptions) ( GTK_FILL ),
1248                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1249                                 }
1250                                 {
1251                                         GtkImage* image = new_local_image( "cap_ibevel.png" );
1252                                         gtk_widget_show( GTK_WIDGET( image ) );
1253                                         gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 2, 3,
1254                                                                           (GtkAttachOptions) ( GTK_FILL ),
1255                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1256                                 }
1257                                 {
1258                                         GtkImage* image = new_local_image( "cap_iendcap.png" );
1259                                         gtk_widget_show( GTK_WIDGET( image ) );
1260                                         gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 3, 4,
1261                                                                           (GtkAttachOptions) ( GTK_FILL ),
1262                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1263                                 }
1264                                 {
1265                                         GtkImage* image = new_local_image( "cap_cylinder.png" );
1266                                         gtk_widget_show( GTK_WIDGET( image ) );
1267                                         gtk_table_attach( table, GTK_WIDGET( image ), 0, 1, 4, 5,
1268                                                                           (GtkAttachOptions) ( GTK_FILL ),
1269                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1270                                 }
1271
1272                                 GSList* group = 0;
1273                                 {
1274                                         GtkWidget* button = gtk_radio_button_new_with_label( group, "Bevel" );
1275                                         gtk_widget_show( button );
1276                                         gtk_table_attach( table, button, 1, 2, 0, 1,
1277                                                                           (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1278                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1279                                         group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1280
1281                                         bevel = button;
1282                                 }
1283                                 {
1284                                         GtkWidget* button = gtk_radio_button_new_with_label( group, "Endcap" );
1285                                         gtk_widget_show( button );
1286                                         gtk_table_attach( table, button, 1, 2, 1, 2,
1287                                                                           (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1288                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1289                                         group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1290
1291                                         endcap = button;
1292                                 }
1293                                 {
1294                                         GtkWidget* button = gtk_radio_button_new_with_label( group, "Inverted Bevel" );
1295                                         gtk_widget_show( button );
1296                                         gtk_table_attach( table, button, 1, 2, 2, 3,
1297                                                                           (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1298                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1299                                         group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1300
1301                                         ibevel = button;
1302                                 }
1303                                 {
1304                                         GtkWidget* button = gtk_radio_button_new_with_label( group, "Inverted Endcap" );
1305                                         gtk_widget_show( button );
1306                                         gtk_table_attach( table, button, 1, 2, 3, 4,
1307                                                                           (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1308                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1309                                         group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1310
1311                                         iendcap = button;
1312                                 }
1313                                 {
1314                                         GtkWidget* button = gtk_radio_button_new_with_label( group, "Cylinder" );
1315                                         gtk_widget_show( button );
1316                                         gtk_table_attach( table, button, 1, 2, 4, 5,
1317                                                                           (GtkAttachOptions) ( GTK_FILL | GTK_EXPAND ),
1318                                                                           (GtkAttachOptions) ( 0 ), 0, 0 );
1319                                         group = gtk_radio_button_group( GTK_RADIO_BUTTON( button ) );
1320
1321                                         cylinder = button;
1322                                 }
1323                         }
1324                 }
1325
1326                 {
1327                         GtkVBox* vbox = create_dialog_vbox( 4 );
1328                         gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), FALSE, FALSE, 0 );
1329                         {
1330                                 GtkButton* button = create_modal_dialog_button( "OK", ok_button );
1331                                 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1332                                 widget_make_default( GTK_WIDGET( button ) );
1333                                 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel_group, GDK_Return, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
1334                         }
1335                         {
1336                                 GtkButton* button = create_modal_dialog_button( "Cancel", cancel_button );
1337                                 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1338                                 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel_group, GDK_Escape, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
1339                         }
1340                 }
1341         }
1342
1343         // Initialize dialog
1344         gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( bevel ), TRUE );
1345
1346         EMessageBoxReturn ret = modal_dialog_show( window, dialog );
1347         if ( ret == eIDOK ) {
1348                 if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( bevel ) ) ) {
1349                         *type = PATCHCAP_BEVEL;
1350                 }
1351                 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( endcap ) ) ) {
1352                         *type = PATCHCAP_ENDCAP;
1353                 }
1354                 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( ibevel ) ) ) {
1355                         *type = PATCHCAP_INVERTED_BEVEL;
1356                 }
1357                 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( iendcap ) ) ) {
1358                         *type = PATCHCAP_INVERTED_ENDCAP;
1359                 }
1360                 else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( cylinder ) ) ) {
1361                         *type = PATCHCAP_CYLINDER;
1362                 }
1363         }
1364
1365         gtk_widget_destroy( GTK_WIDGET( window ) );
1366
1367         return ret;
1368 }
1369
1370
1371 void DoPatchThickenDlg(){
1372         ModalDialog dialog;
1373         GtkWidget* thicknessW;
1374         GtkWidget* seamsW;
1375         GtkWidget* radX;
1376         GtkWidget* radY;
1377         GtkWidget* radZ;
1378
1379         GtkWindow* window = create_dialog_window( MainFrame_getWindow(), "Patch thicken", G_CALLBACK( dialog_delete_callback ), &dialog );
1380
1381         GtkAccelGroup* accel = gtk_accel_group_new();
1382         gtk_window_add_accel_group( window, accel );
1383
1384         {
1385                 GtkHBox* hbox = create_dialog_hbox( 4, 4 );
1386                 gtk_container_add( GTK_CONTAINER( window ), GTK_WIDGET( hbox ) );
1387                 {
1388                         GtkTable* table = create_dialog_table( 2, 4, 4, 4 );
1389                         gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
1390                         {
1391                                 GtkLabel* label = GTK_LABEL( gtk_label_new( "Thickness:" ) );
1392                                 gtk_widget_show( GTK_WIDGET( label ) );
1393                                 gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
1394                                                                   (GtkAttachOptions) ( GTK_FILL ),
1395                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1396                                 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
1397                         }
1398 //                      {
1399 //                              GtkWidget* entry = gtk_entry_new();
1400 //                              gtk_entry_set_text( GTK_ENTRY( entry ), "16" );
1401 //                              gtk_widget_set_size_request( entry, 40, -1 );
1402 //                              gtk_widget_show( entry );
1403 //                              gtk_table_attach( table, entry, 1, 2, 0, 1,
1404 //                                                                (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1405 //                                                                (GtkAttachOptions) ( 0 ), 0, 0 );
1406 //
1407 //                              thicknessW = entry;
1408 //                      }
1409                         {
1410                                 GtkAdjustment* adj = GTK_ADJUSTMENT( gtk_adjustment_new( 16, -9999, 9999, 1, 10, 0 ) );
1411                                 GtkWidget* spin = gtk_spin_button_new( adj, 1, 0 );
1412                                 gtk_widget_show( spin );
1413                                 gtk_table_attach( table, spin, 1, 2, 0, 1,
1414                                                                   (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1415                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1416                                 gtk_widget_set_size_request( spin, 48, -1 );
1417                                 gtk_spin_button_set_numeric( GTK_SPIN_BUTTON( spin ), TRUE );
1418
1419                                 thicknessW = spin;
1420                         }
1421                         {
1422                                 // Create the "create seams" label
1423                                 GtkWidget* _seamsCheckBox = gtk_check_button_new_with_label( "Side walls" );
1424                                 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( _seamsCheckBox ), TRUE );
1425                                 gtk_widget_show( _seamsCheckBox );
1426                                 gtk_table_attach( table, _seamsCheckBox, 2, 4, 0, 1,
1427                                                                   (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1428                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1429                                 seamsW = _seamsCheckBox;
1430
1431                         }
1432                         {
1433                                 // Create the radio button group for choosing the extrude axis
1434                                 GtkWidget* _radNormals = gtk_radio_button_new_with_label( NULL, "Normal" );
1435                                 GtkWidget* _radX = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "X" );
1436                                 GtkWidget* _radY = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "Y" );
1437                                 GtkWidget* _radZ = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(_radNormals), "Z" );
1438                                 gtk_widget_show( _radNormals );
1439                                 gtk_widget_show( _radX );
1440                                 gtk_widget_show( _radY );
1441                                 gtk_widget_show( _radZ );
1442
1443
1444                                 // Pack the buttons into the table
1445                                 gtk_table_attach( table, _radNormals, 0, 1, 1, 2,
1446                                                                   (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1447                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1448                                 gtk_table_attach( table, _radX, 1, 2, 1, 2,
1449                                                                   (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1450                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1451                                 gtk_table_attach( table, _radY, 2, 3, 1, 2,
1452                                                                   (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1453                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1454                                 gtk_table_attach( table, _radZ, 3, 4, 1, 2,
1455                                                                   (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
1456                                                                   (GtkAttachOptions) ( 0 ), 0, 0 );
1457                                 radX = _radX;
1458                                 radY = _radY;
1459                                 radZ = _radZ;
1460                         }
1461                 }
1462                 {
1463                         GtkVBox* vbox = create_dialog_vbox( 4 );
1464                         gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
1465                         {
1466                                 GtkButton* button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
1467                                 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1468                                 widget_make_default( GTK_WIDGET( button ) );
1469                                 gtk_widget_grab_focus( GTK_WIDGET( button ) );
1470                                 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
1471                         }
1472                         {
1473                                 GtkButton* button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
1474                                 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
1475                                 gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
1476                         }
1477                 }
1478         }
1479
1480         if ( modal_dialog_show( window, dialog ) == eIDOK ) {
1481                 int axis = 3; // Extrude along normals
1482                 bool seams;
1483                 //float thickness = static_cast<float>( atoi( gtk_entry_get_text( GTK_ENTRY( thicknessW ) ) ) );
1484                 gtk_spin_button_update ( GTK_SPIN_BUTTON( thicknessW ) );
1485                 float thickness = static_cast<float>( gtk_spin_button_get_value( GTK_SPIN_BUTTON( thicknessW ) ) );
1486                 seams = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON( seamsW )) ? true : false;
1487
1488                 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radX))) {
1489                         axis = 0;
1490                 }
1491                 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radY))) {
1492                         axis = 1;
1493                 }
1494                 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radZ))) {
1495                         axis = 2;
1496                 }
1497
1498                 Scene_PatchThicken( GlobalSceneGraph(), thickness, seams, axis );
1499         }
1500
1501         gtk_widget_destroy( GTK_WIDGET( window ) );
1502 }