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