2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
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.
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.
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
22 #include "patchmanip.h"
24 #include "debugging/debugging.h"
27 #include "iselection.h"
30 #include "math/vector.h"
31 #include "math/aabb.h"
32 #include "generic/callback.h"
34 #include "gtkutil/menu.h"
35 #include "gtkutil/image.h"
37 #include "mainframe.h"
41 #include "texwindow.h"
47 PatchCreator* g_patchCreator = 0;
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)
52 GlobalSelectionSystem().setSelectedAll(false);
54 NodeSmartReference node(g_patchCreator->createPatch());
55 Node_getTraversable(Map_FindOrInsertWorldspawn(g_map))->insert(node);
57 Patch* patch = Node_getPatch(node);
58 patch->SetShader(shader);
60 patch->ConstructPrefab(aabb, eType, axis, width, height);
61 patch->controlPointsChanged();
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);
72 void Patch_makeCaps(Patch& patch, scene::Instance& instance, EPatchCap type, const char* shader)
74 if((type == eCapEndCap || type == eCapIEndCap)
75 && patch.getWidth() != 5)
77 globalErrorStream() << "cannot create end-cap - patch width != 5\n";
80 if((type == eCapBevel || type == eCapIBevel)
81 && patch.getWidth() != 3 && patch.getWidth() != 5)
83 globalErrorStream() << "cannot create bevel-cap - patch width != 3\n";
86 if(type == eCapCylinder
87 && patch.getWidth() != 9)
89 globalErrorStream() << "cannot create cylinder-cap - patch width != 9\n";
94 NodeSmartReference cap(g_patchCreator->createPatch());
95 Node_getTraversable(instance.path().parent())->insert(cap);
97 patch.MakeCap(Node_getPatch(cap), type, ROW, true);
98 Node_getPatch(cap)->SetShader(shader);
100 scene::Path path(instance.path());
102 path.push(makeReference(cap.get()));
103 selectPath(path, true);
107 NodeSmartReference cap(g_patchCreator->createPatch());
108 Node_getTraversable(instance.path().parent())->insert(cap);
110 patch.MakeCap(Node_getPatch(cap), type, ROW, false);
111 Node_getPatch(cap)->SetShader(shader);
113 scene::Path path(instance.path());
115 path.push(makeReference(cap.get()));
116 selectPath(path, true);
120 typedef std::vector<scene::Instance*> InstanceVector;
122 class PatchStoreInstance
124 InstanceVector& m_instances;
126 PatchStoreInstance(InstanceVector& instances) : m_instances(instances)
129 void operator()(PatchInstance& patch) const
131 m_instances.push_back(&patch);
138 PATCHCAP_INVERTED_BEVEL,
139 PATCHCAP_INVERTED_ENDCAP,
143 EMessageBoxReturn DoCapDlg(ECapDialog *type);
145 void Scene_PatchDoCap_Selected(scene::Graph& graph, const char* shader)
149 if(DoCapDlg(&nType) == eIDOK)
154 case PATCHCAP_INVERTED_BEVEL:
160 case PATCHCAP_INVERTED_ENDCAP:
163 case PATCHCAP_ENDCAP:
166 case PATCHCAP_CYLINDER:
167 eType = eCapCylinder;
170 ERROR_MESSAGE("invalid patch cap type");
174 InstanceVector instances;
175 Scene_forEachVisibleSelectedPatchInstance(PatchStoreInstance(instances));
176 for(InstanceVector::const_iterator i = instances.begin(); i != instances.end(); ++i)
178 Patch_makeCaps(* Node_getPatch((*i)->path().top()), *(*i), eType, shader);
183 Patch* Scene_GetUltimateSelectedVisiblePatch()
185 if(GlobalSelectionSystem().countSelected() != 0)
187 scene::Node& node = GlobalSelectionSystem().ultimateSelected().path().top();
190 return Node_getPatch(node);
197 class PatchCapTexture
200 void operator()(Patch& patch) const
202 patch.ProjectTexture(Patch::m_CycleCapIndex);
206 void Scene_PatchCapTexture_Selected(scene::Graph& graph)
208 Scene_forEachVisibleSelectedPatch(PatchCapTexture());
209 Patch::m_CycleCapIndex = (Patch::m_CycleCapIndex == 0) ? 1 : (Patch::m_CycleCapIndex == 1) ? 2 : 0;
213 class PatchFlipTexture
217 PatchFlipTexture(int axis) : m_axis(axis)
220 void operator()(Patch& patch) const
222 patch.FlipTexture(m_axis);
226 void Scene_PatchFlipTexture_Selected(scene::Graph& graph, int axis)
228 Scene_forEachVisibleSelectedPatch(PatchFlipTexture(axis));
231 class PatchNaturalTexture
234 void operator()(Patch& patch) const
236 patch.NaturalTexture();
240 void Scene_PatchNaturalTexture_Selected(scene::Graph& graph)
242 Scene_forEachVisibleSelectedPatch(PatchNaturalTexture());
247 class PatchInsertRemove
249 bool m_insert, m_column, m_first;
251 PatchInsertRemove(bool insert, bool column, bool first) : m_insert(insert), m_column(column), m_first(first)
254 void operator()(Patch& patch) const
256 patch.InsertRemove(m_insert, m_column, m_first);
260 void Scene_PatchInsertRemove_Selected(scene::Graph& graph, bool bInsert, bool bColumn, bool bFirst)
262 Scene_forEachVisibleSelectedPatch(PatchInsertRemove(bInsert, bColumn, bFirst));
265 class PatchInvertMatrix
268 void operator()(Patch& patch) const
270 patch.InvertMatrix();
274 void Scene_PatchInvert_Selected(scene::Graph& graph)
276 Scene_forEachVisibleSelectedPatch(PatchInvertMatrix());
279 class PatchRedisperse
281 EMatrixMajor m_major;
283 PatchRedisperse(EMatrixMajor major) : m_major(major)
286 void operator()(Patch& patch) const
288 patch.Redisperse(m_major);
292 void Scene_PatchRedisperse_Selected(scene::Graph& graph, EMatrixMajor major)
294 Scene_forEachVisibleSelectedPatch(PatchRedisperse(major));
299 EMatrixMajor m_major;
301 PatchSmooth(EMatrixMajor major) : m_major(major)
304 void operator()(Patch& patch) const
306 patch.Smooth(m_major);
310 void Scene_PatchSmooth_Selected(scene::Graph& graph, EMatrixMajor major)
312 Scene_forEachVisibleSelectedPatch(PatchSmooth(major));
315 class PatchTransposeMatrix
318 void operator()(Patch& patch) const
320 patch.TransposeMatrix();
324 void Scene_PatchTranspose_Selected(scene::Graph& graph)
326 Scene_forEachVisibleSelectedPatch(PatchTransposeMatrix());
333 PatchSetShader(const char* name)
337 void operator()(Patch& patch) const
339 patch.SetShader(m_name);
343 void Scene_PatchSetShader_Selected(scene::Graph& graph, const char* name)
345 Scene_forEachVisibleSelectedPatch(PatchSetShader(name));
349 void Scene_PatchGetShader_Selected(scene::Graph& graph, CopiedString& name)
351 Patch* patch = Scene_GetUltimateSelectedVisiblePatch();
354 name = patch->GetShader();
358 class PatchSelectByShader
362 inline PatchSelectByShader(const char* name)
366 void operator()(PatchInstance& patch) const
368 if(shader_equal(patch.getPatch().GetShader(), m_name))
370 patch.setSelected(true);
375 void Scene_PatchSelectByShader(scene::Graph& graph, const char* name)
377 Scene_forEachVisiblePatchInstance(PatchSelectByShader(name));
381 class PatchFindReplaceShader
384 const char* m_replace;
386 PatchFindReplaceShader(const char* find, const char* replace) : m_find(find), m_replace(replace)
389 void operator()(Patch& patch) const
391 if(shader_equal(patch.GetShader(), m_find))
393 patch.SetShader(m_replace);
398 void Scene_PatchFindReplaceShader(scene::Graph& graph, const char* find, const char* replace)
400 Scene_forEachVisiblePatch(PatchFindReplaceShader(find, replace));
403 void Scene_PatchFindReplaceShader_Selected(scene::Graph& graph, const char* find, const char* replace)
405 Scene_forEachVisibleSelectedPatch(PatchFindReplaceShader(find, replace));
409 AABB PatchCreator_getBounds()
411 AABB aabb(aabb_for_minmax(Select_getWorkZone().d_work_min, Select_getWorkZone().d_work_max));
413 float gridSize = GetGridSize();
415 if(aabb.extents[0] == 0)
417 aabb.extents[0] = gridSize;
419 if(aabb.extents[1] == 0)
421 aabb.extents[1] = gridSize;
423 if(aabb.extents[2] == 0)
425 aabb.extents[2] = gridSize;
432 return AABB(Vector3(0, 0, 0), Vector3(64, 64, 64));
435 void Patch_Cylinder()
437 UndoableCommand undo("patchCreateCylinder");
439 Scene_PatchConstructPrefab(GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()), eCylinder, GlobalXYWnd_getCurrentViewType());
442 void Patch_DenseCylinder()
444 UndoableCommand undo("patchCreateDenseCylinder");
446 Scene_PatchConstructPrefab(GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()), eDenseCylinder, GlobalXYWnd_getCurrentViewType());
449 void Patch_VeryDenseCylinder()
451 UndoableCommand undo("patchCreateVeryDenseCylinder");
453 Scene_PatchConstructPrefab(GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()), eVeryDenseCylinder, GlobalXYWnd_getCurrentViewType());
456 void Patch_SquareCylinder()
458 UndoableCommand undo("patchCreateSquareCylinder");
460 Scene_PatchConstructPrefab(GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()), eSqCylinder, GlobalXYWnd_getCurrentViewType());
465 UndoableCommand undo("patchCreateCaps");
467 Scene_PatchConstructPrefab(GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()), eEndCap, GlobalXYWnd_getCurrentViewType());
472 UndoableCommand undo("patchCreateBevel");
474 Scene_PatchConstructPrefab(GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()), eBevel, GlobalXYWnd_getCurrentViewType());
479 UndoableCommand undo("patchCreateSphere");
481 Scene_PatchConstructPrefab(GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()), eSphere, GlobalXYWnd_getCurrentViewType());
484 void Patch_SquareBevel()
488 void Patch_SquareEndcap()
494 UndoableCommand undo("patchCreateCone");
496 Scene_PatchConstructPrefab(GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()), eCone, GlobalXYWnd_getCurrentViewType());
499 void DoNewPatchDlg();
503 UndoableCommand undo("patchCreatePlane");
508 void Patch_InsertInsertColumn()
510 UndoableCommand undo("patchInsertColumns");
512 Scene_PatchInsertRemove_Selected(GlobalSceneGraph(), true, true, false);
515 void Patch_InsertAddColumn()
517 UndoableCommand undo("patchAddColumns");
519 Scene_PatchInsertRemove_Selected(GlobalSceneGraph(), true, true, true);
522 void Patch_InsertInsertRow()
524 UndoableCommand undo("patchInsertRows");
526 Scene_PatchInsertRemove_Selected(GlobalSceneGraph(), true, false, false);
529 void Patch_InsertAddRow()
531 UndoableCommand undo("patchAddRows");
533 Scene_PatchInsertRemove_Selected(GlobalSceneGraph(), true, false, true);
536 void Patch_DeleteFirstColumn()
538 UndoableCommand undo("patchDeleteFirstColumns");
540 Scene_PatchInsertRemove_Selected(GlobalSceneGraph(), false, true, true);
543 void Patch_DeleteLastColumn()
545 UndoableCommand undo("patchDeleteLastColumns");
547 Scene_PatchInsertRemove_Selected(GlobalSceneGraph(), false, true, false);
550 void Patch_DeleteFirstRow()
552 UndoableCommand undo("patchDeleteFirstRows");
554 Scene_PatchInsertRemove_Selected(GlobalSceneGraph(), false, false, true);
557 void Patch_DeleteLastRow()
559 UndoableCommand undo("patchDeleteLastRows");
561 Scene_PatchInsertRemove_Selected(GlobalSceneGraph(), false, false, false);
566 UndoableCommand undo("patchInvert");
568 Scene_PatchInvert_Selected(GlobalSceneGraph());
571 void Patch_RedisperseRows()
573 UndoableCommand undo("patchRedisperseRows");
575 Scene_PatchRedisperse_Selected(GlobalSceneGraph(), ROW);
578 void Patch_RedisperseCols()
580 UndoableCommand undo("patchRedisperseColumns");
582 Scene_PatchRedisperse_Selected(GlobalSceneGraph(), COL);
585 void Patch_SmoothRows()
587 UndoableCommand undo("patchSmoothRows");
589 Scene_PatchSmooth_Selected(GlobalSceneGraph(), ROW);
592 void Patch_SmoothCols()
594 UndoableCommand undo("patchSmoothColumns");
596 Scene_PatchSmooth_Selected(GlobalSceneGraph(), COL);
599 void Patch_Transpose()
601 UndoableCommand undo("patchTranspose");
603 Scene_PatchTranspose_Selected(GlobalSceneGraph());
608 // FIXME: add support for patch cap creation
609 // Patch_CapCurrent();
610 UndoableCommand undo("patchCreateCaps");
612 Scene_PatchDoCap_Selected(GlobalSceneGraph(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
615 void Patch_CycleProjection()
617 UndoableCommand undo("patchCycleUVProjectionAxis");
619 Scene_PatchCapTexture_Selected(GlobalSceneGraph());
623 void Patch_OverlayOn()
628 void Patch_OverlayOff()
632 void Patch_FlipTextureX()
634 UndoableCommand undo("patchFlipTextureU");
636 Scene_PatchFlipTexture_Selected(GlobalSceneGraph(), 0);
639 void Patch_FlipTextureY()
641 UndoableCommand undo("patchFlipTextureV");
643 Scene_PatchFlipTexture_Selected(GlobalSceneGraph(), 1);
646 void Patch_NaturalTexture()
648 UndoableCommand undo("patchNaturalTexture");
650 Scene_PatchNaturalTexture_Selected(GlobalSceneGraph());
659 class filter_patch_all : public PatchFilter
662 bool filter(const Patch& patch) const
668 class filter_patch_shader : public PatchFilter
670 const char* m_shader;
672 filter_patch_shader(const char* shader) : m_shader(shader)
675 bool filter(const Patch& patch) const
677 return shader_equal(patch.GetShader(), m_shader);
681 class filter_patch_flags : public PatchFilter
685 filter_patch_flags(int flags) : m_flags(flags)
688 bool filter(const Patch& patch) const
690 return (patch.getShaderFlags() & m_flags) != 0;
695 filter_patch_all g_filter_patch_all;
696 filter_patch_shader g_filter_patch_clip("textures/common/clip");
697 filter_patch_shader g_filter_patch_weapclip("textures/common/weapclip");
698 filter_patch_flags g_filter_patch_translucent(QER_TRANS);
700 void PatchFilters_construct()
702 add_patch_filter(g_filter_patch_all, EXCLUDE_CURVES);
703 add_patch_filter(g_filter_patch_clip, EXCLUDE_CLIP);
704 add_patch_filter(g_filter_patch_weapclip, EXCLUDE_CLIP);
705 add_patch_filter(g_filter_patch_translucent, EXCLUDE_TRANSLUCENT);
709 #include "preferences.h"
711 void Patch_constructPreferences(PreferencesPage& page)
713 page.appendEntry("Patch Subdivide Threshold", g_PatchSubdivideThreshold);
715 void Patch_constructPage(PreferenceGroup& group)
717 PreferencesPage page(group.createPage("Patches", "Patch Display Preferences"));
718 Patch_constructPreferences(page);
720 void Patch_registerPreferencesPage()
722 PreferencesDialog_addDisplayPage(FreeCaller1<PreferenceGroup&, Patch_constructPage>());
726 #include "preferencesystem.h"
728 void PatchPreferences_construct()
730 GlobalPreferenceSystem().registerPreference("Subdivisions", IntImportStringCaller(g_PatchSubdivideThreshold), IntExportStringCaller(g_PatchSubdivideThreshold));
734 #include "generic/callback.h"
736 void Patch_registerCommands()
738 GlobalCommands_insert("InvertCurveTextureX", FreeCaller<Patch_FlipTextureX>(), Accelerator('I', (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK)));
739 GlobalCommands_insert("InvertCurveTextureY", FreeCaller<Patch_FlipTextureY>(), Accelerator('I', (GdkModifierType)GDK_SHIFT_MASK));
740 GlobalCommands_insert("IncPatchColumn", FreeCaller<Patch_InsertInsertColumn>(), Accelerator(GDK_KP_Add, (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK)));
741 GlobalCommands_insert("IncPatchRow", FreeCaller<Patch_InsertInsertRow>(), Accelerator(GDK_KP_Add, (GdkModifierType)GDK_CONTROL_MASK));
742 GlobalCommands_insert("DecPatchColumn", FreeCaller<Patch_DeleteLastColumn>(), Accelerator(GDK_KP_Subtract, (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK)));
743 GlobalCommands_insert("DecPatchRow", FreeCaller<Patch_DeleteLastRow>(), Accelerator(GDK_KP_Subtract, (GdkModifierType)GDK_CONTROL_MASK));
744 GlobalCommands_insert("NaturalizePatch", FreeCaller<Patch_NaturalTexture>(), Accelerator('N', (GdkModifierType)GDK_CONTROL_MASK));
745 GlobalCommands_insert("PatchCylinder", FreeCaller<Patch_Cylinder>());
746 GlobalCommands_insert("PatchDenseCylinder", FreeCaller<Patch_DenseCylinder>());
747 GlobalCommands_insert("PatchVeryDenseCylinder", FreeCaller<Patch_VeryDenseCylinder>());
748 GlobalCommands_insert("PatchSquareCylinder", FreeCaller<Patch_SquareCylinder>());
749 GlobalCommands_insert("PatchEndCap", FreeCaller<Patch_Endcap>());
750 GlobalCommands_insert("PatchBevel", FreeCaller<Patch_Bevel>());
751 GlobalCommands_insert("PatchSquareBevel", FreeCaller<Patch_SquareBevel>());
752 GlobalCommands_insert("PatchSquareEndcap", FreeCaller<Patch_SquareEndcap>());
753 GlobalCommands_insert("PatchCone", FreeCaller<Patch_Cone>());
754 GlobalCommands_insert("PatchSphere", FreeCaller<Patch_Sphere>());
755 GlobalCommands_insert("SimplePatchMesh", FreeCaller<Patch_Plane>(), Accelerator('P', (GdkModifierType)GDK_SHIFT_MASK));
756 GlobalCommands_insert("PatchInsertInsertColumn", FreeCaller<Patch_InsertInsertColumn>());
757 GlobalCommands_insert("PatchInsertAddColumn", FreeCaller<Patch_InsertAddColumn>());
758 GlobalCommands_insert("PatchInsertInsertRow", FreeCaller<Patch_InsertInsertRow>());
759 GlobalCommands_insert("PatchInsertAddRow", FreeCaller<Patch_InsertAddRow>());
760 GlobalCommands_insert("PatchDeleteFirstColumn", FreeCaller<Patch_DeleteFirstColumn>());
761 GlobalCommands_insert("PatchDeleteLastColumn", FreeCaller<Patch_DeleteLastColumn>());
762 GlobalCommands_insert("PatchDeleteFirstRow", FreeCaller<Patch_DeleteFirstRow>());
763 GlobalCommands_insert("PatchDeleteLastRow", FreeCaller<Patch_DeleteLastRow>());
764 GlobalCommands_insert("InvertCurve", FreeCaller<Patch_Invert>(), Accelerator('I', (GdkModifierType)GDK_CONTROL_MASK));
765 GlobalCommands_insert("RedisperseRows", FreeCaller<Patch_RedisperseRows>(), Accelerator('E', (GdkModifierType)GDK_CONTROL_MASK));
766 GlobalCommands_insert("RedisperseCols", FreeCaller<Patch_RedisperseCols>(), Accelerator('E', (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK)));
767 GlobalCommands_insert("SmoothRows", FreeCaller<Patch_SmoothRows>(), Accelerator('W', (GdkModifierType)GDK_CONTROL_MASK));
768 GlobalCommands_insert("SmoothCols", FreeCaller<Patch_SmoothCols>(), Accelerator('W', (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK)));
769 GlobalCommands_insert("MatrixTranspose", FreeCaller<Patch_Transpose>(), Accelerator('M', (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK)));
770 GlobalCommands_insert("CapCurrentCurve", FreeCaller<Patch_Cap>(), Accelerator('C', (GdkModifierType)GDK_SHIFT_MASK));
771 GlobalCommands_insert("CycleCapTexturePatch", FreeCaller<Patch_CycleProjection>(), Accelerator('N', (GdkModifierType)(GDK_SHIFT_MASK|GDK_CONTROL_MASK)));
772 GlobalCommands_insert("MakeOverlayPatch", FreeCaller<Patch_OverlayOn>(), Accelerator('Y'));
773 GlobalCommands_insert("ClearPatchOverlays", FreeCaller<Patch_OverlayOff>(), Accelerator('L', (GdkModifierType)GDK_CONTROL_MASK));
776 void Patch_constructToolbar(GtkToolbar* toolbar)
778 toolbar_append_button(toolbar, "Put caps on the current patch (SHIFT + C)", "curve_cap.bmp", "CapCurrentCurve");
781 void Patch_constructMenu(GtkMenu* menu)
783 create_menu_item_with_mnemonic(menu, "Cylinder", "PatchCylinder");
785 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "More Cylinders");
786 if (g_Layout_enableDetachableMenus.m_value)
787 menu_tearoff (menu_in_menu);
788 create_menu_item_with_mnemonic(menu_in_menu, "Dense Cylinder", "PatchDenseCylinder");
789 create_menu_item_with_mnemonic(menu_in_menu, "Very Dense Cylinder", "PatchVeryDenseCylinder");
790 create_menu_item_with_mnemonic(menu_in_menu, "Square Cylinder", "PatchSquareCylinder");
792 menu_separator (menu);
793 create_menu_item_with_mnemonic(menu, "End cap", "PatchEndCap");
794 create_menu_item_with_mnemonic(menu, "Bevel", "PatchBevel");
796 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "More End caps, Bevels");
797 if (g_Layout_enableDetachableMenus.m_value)
798 menu_tearoff (menu_in_menu);
799 create_menu_item_with_mnemonic(menu_in_menu, "Square Endcap", "PatchSquareBevel");
800 create_menu_item_with_mnemonic(menu_in_menu, "Square Bevel", "PatchSquareEndcap");
802 menu_separator (menu);
803 create_menu_item_with_mnemonic(menu, "Cone", "PatchCone");
804 create_menu_item_with_mnemonic(menu, "Sphere", "PatchSphere");
805 menu_separator (menu);
806 create_menu_item_with_mnemonic(menu, "Simple Patch Mesh...", "SimplePatchMesh");
807 menu_separator (menu);
809 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Insert");
810 if (g_Layout_enableDetachableMenus.m_value)
811 menu_tearoff (menu_in_menu);
812 create_menu_item_with_mnemonic(menu_in_menu, "Insert (2) Columns", "PatchInsertInsertColumn");
813 create_menu_item_with_mnemonic(menu_in_menu, "Add (2) Columns", "PatchInsertAddColumn");
814 menu_separator (menu_in_menu);
815 create_menu_item_with_mnemonic(menu_in_menu, "Insert (2) Rows", "PatchInsertInsertRow");
816 create_menu_item_with_mnemonic(menu_in_menu, "Add (2) Rows", "PatchInsertAddRow");
819 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Delete");
820 if (g_Layout_enableDetachableMenus.m_value)
821 menu_tearoff (menu_in_menu);
822 create_menu_item_with_mnemonic(menu_in_menu, "First (2) Columns", "PatchDeleteFirstColumn");
823 create_menu_item_with_mnemonic(menu_in_menu, "Last (2) Columns", "PatchDeleteLastColumn");
824 menu_separator (menu_in_menu);
825 create_menu_item_with_mnemonic(menu_in_menu, "First (2) Rows", "PatchDeleteFirstRow");
826 create_menu_item_with_mnemonic(menu_in_menu, "Last (2) Rows", "PatchDeleteLastRow");
828 menu_separator (menu);
830 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Matrix");
831 if (g_Layout_enableDetachableMenus.m_value)
832 menu_tearoff (menu_in_menu);
833 create_menu_item_with_mnemonic(menu_in_menu, "Invert", "InvertCurve");
834 GtkMenu* menu_3 = create_sub_menu_with_mnemonic (menu_in_menu, "Re-disperse");
835 if (g_Layout_enableDetachableMenus.m_value)
836 menu_tearoff (menu_3);
837 create_menu_item_with_mnemonic(menu_3, "Rows", "RedisperseRows");
838 create_menu_item_with_mnemonic(menu_3, "Columns", "RedisperseCols");
839 GtkMenu* menu_4 = create_sub_menu_with_mnemonic (menu_in_menu, "Smooth");
840 if (g_Layout_enableDetachableMenus.m_value)
841 menu_tearoff (menu_4);
842 create_menu_item_with_mnemonic(menu_4, "Rows", "SmoothRows");
843 create_menu_item_with_mnemonic(menu_4, "Columns", "SmoothCols");
844 create_menu_item_with_mnemonic(menu_in_menu, "Transpose", "MatrixTranspose");
846 menu_separator (menu);
847 create_menu_item_with_mnemonic(menu, "Cap Selection", "CapCurrentCurve");
848 create_menu_item_with_mnemonic(menu, "Cycle Cap Texture", "CycleCapTexturePatch");
849 menu_separator (menu);
851 GtkMenu* menu_in_menu = create_sub_menu_with_mnemonic (menu, "Overlay");
852 if (g_Layout_enableDetachableMenus.m_value)
853 menu_tearoff (menu_in_menu);
854 create_menu_item_with_mnemonic(menu_in_menu, "Set", "MakeOverlayPatch");
855 create_menu_item_with_mnemonic(menu_in_menu, "Clear", "ClearPatchOverlays");
860 #include <gtk/gtkbox.h>
861 #include <gtk/gtktable.h>
862 #include <gtk/gtktogglebutton.h>
863 #include <gtk/gtkradiobutton.h>
864 #include <gtk/gtkcombobox.h>
865 #include <gtk/gtklabel.h>
866 #include "gtkutil/dialog.h"
867 #include "gtkutil/widget.h"
875 GtkWindow* window = create_dialog_window(MainFrame_getWindow(), "Patch density", G_CALLBACK(dialog_delete_callback), &dialog);
877 GtkAccelGroup* accel = gtk_accel_group_new();
878 gtk_window_add_accel_group(window, accel);
881 GtkHBox* hbox = create_dialog_hbox(4, 4);
882 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(hbox));
884 GtkTable* table = create_dialog_table(2, 2, 4, 4);
885 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(table), TRUE, TRUE, 0);
887 GtkLabel* label = GTK_LABEL(gtk_label_new("Width:"));
888 gtk_widget_show(GTK_WIDGET(label));
889 gtk_table_attach(table, GTK_WIDGET(label), 0, 1, 0, 1,
890 (GtkAttachOptions) (GTK_FILL),
891 (GtkAttachOptions) (0), 0, 0);
892 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
895 GtkLabel* label = GTK_LABEL(gtk_label_new("Height:"));
896 gtk_widget_show(GTK_WIDGET(label));
897 gtk_table_attach(table, GTK_WIDGET(label), 0, 1, 1, 2,
898 (GtkAttachOptions) (GTK_FILL),
899 (GtkAttachOptions) (0), 0, 0);
900 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
904 GtkComboBox* combo = GTK_COMBO_BOX(gtk_combo_box_new_text());
905 gtk_combo_box_append_text(combo, "3");
906 gtk_combo_box_append_text(combo, "5");
907 gtk_combo_box_append_text(combo, "7");
908 gtk_combo_box_append_text(combo, "9");
909 gtk_combo_box_append_text(combo, "11");
910 gtk_combo_box_append_text(combo, "13");
911 gtk_combo_box_append_text(combo, "15");
912 gtk_combo_box_append_text(combo, "17");
913 gtk_combo_box_append_text(combo, "19");
914 gtk_combo_box_append_text(combo, "21");
915 gtk_combo_box_append_text(combo, "23");
916 gtk_combo_box_append_text(combo, "25");
917 gtk_combo_box_append_text(combo, "27");
918 gtk_combo_box_append_text(combo, "29");
919 gtk_combo_box_append_text(combo, "31"); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
920 gtk_widget_show(GTK_WIDGET(combo));
921 gtk_table_attach(table, GTK_WIDGET(combo), 1, 2, 0, 1,
922 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
923 (GtkAttachOptions) (0), 0, 0);
928 GtkComboBox* combo = GTK_COMBO_BOX(gtk_combo_box_new_text());
929 gtk_combo_box_append_text(combo, "3");
930 gtk_combo_box_append_text(combo, "5");
931 gtk_combo_box_append_text(combo, "7");
932 gtk_combo_box_append_text(combo, "9");
933 gtk_combo_box_append_text(combo, "11");
934 gtk_combo_box_append_text(combo, "13");
935 gtk_combo_box_append_text(combo, "15");
936 gtk_combo_box_append_text(combo, "17");
937 gtk_combo_box_append_text(combo, "19");
938 gtk_combo_box_append_text(combo, "21");
939 gtk_combo_box_append_text(combo, "23");
940 gtk_combo_box_append_text(combo, "25");
941 gtk_combo_box_append_text(combo, "27");
942 gtk_combo_box_append_text(combo, "29");
943 gtk_combo_box_append_text(combo, "31"); // MAX_PATCH_SIZE is 32, so we should be able to do 31...
944 gtk_widget_show(GTK_WIDGET(combo));
945 gtk_table_attach(table, GTK_WIDGET(combo), 1, 2, 1, 2,
946 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
947 (GtkAttachOptions) (0), 0, 0);
954 GtkVBox* vbox = create_dialog_vbox(4);
955 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(vbox), TRUE, TRUE, 0);
957 GtkButton* button = create_dialog_button("OK", G_CALLBACK(dialog_button_ok), &dialog);
958 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
959 widget_make_default(GTK_WIDGET(button));
960 gtk_widget_grab_focus(GTK_WIDGET(button));
961 gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0);
964 GtkButton* button = create_dialog_button("Cancel", G_CALLBACK(dialog_button_cancel), &dialog);
965 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
966 gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0);
972 gtk_combo_box_set_active(width, 0);
973 gtk_combo_box_set_active(height, 0);
975 if(modal_dialog_show(window, dialog) == eIDOK)
977 int w = gtk_combo_box_get_active(width) * 2 + 3;
978 int h = gtk_combo_box_get_active(height) * 2 + 3;
980 Scene_PatchConstructPrefab(GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()), ePlane, GlobalXYWnd_getCurrentViewType(), w, h);
983 gtk_widget_destroy(GTK_WIDGET(window));
989 EMessageBoxReturn DoCapDlg(ECapDialog* type)
992 ModalDialogButton ok_button(dialog, eIDOK);
993 ModalDialogButton cancel_button(dialog, eIDCANCEL);
1000 GtkWindow* window = create_modal_dialog_window(MainFrame_getWindow(), "Cap", dialog);
1002 GtkAccelGroup *accel_group = gtk_accel_group_new();
1003 gtk_window_add_accel_group(window, accel_group);
1006 GtkHBox* hbox = create_dialog_hbox(4, 4);
1007 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(hbox));
1010 // Gef: Added a vbox to contain the toggle buttons
1011 GtkVBox* radio_vbox = create_dialog_vbox(4);
1012 gtk_container_add(GTK_CONTAINER(hbox), GTK_WIDGET(radio_vbox));
1015 GtkTable* table = GTK_TABLE(gtk_table_new(5, 2, FALSE));
1016 gtk_widget_show(GTK_WIDGET(table));
1017 gtk_box_pack_start(GTK_BOX(radio_vbox), GTK_WIDGET(table), TRUE, TRUE, 0);
1018 gtk_table_set_row_spacings(table, 5);
1019 gtk_table_set_col_spacings(table, 5);
1022 GtkImage* image = new_local_image("cap_bevel.bmp");
1023 gtk_widget_show(GTK_WIDGET(image));
1024 gtk_table_attach(table, GTK_WIDGET(image), 0, 1, 0, 1,
1025 (GtkAttachOptions) (GTK_FILL),
1026 (GtkAttachOptions) (0), 0, 0);
1029 GtkImage* image = new_local_image("cap_endcap.bmp");
1030 gtk_widget_show(GTK_WIDGET(image));
1031 gtk_table_attach(table, GTK_WIDGET(image), 0, 1, 1, 2,
1032 (GtkAttachOptions) (GTK_FILL),
1033 (GtkAttachOptions) (0), 0, 0);
1036 GtkImage* image = new_local_image("cap_ibevel.bmp");
1037 gtk_widget_show(GTK_WIDGET(image));
1038 gtk_table_attach(table, GTK_WIDGET(image), 0, 1, 2, 3,
1039 (GtkAttachOptions) (GTK_FILL),
1040 (GtkAttachOptions) (0), 0, 0);
1043 GtkImage* image = new_local_image("cap_iendcap.bmp");
1044 gtk_widget_show(GTK_WIDGET(image));
1045 gtk_table_attach(table, GTK_WIDGET(image), 0, 1, 3, 4,
1046 (GtkAttachOptions) (GTK_FILL),
1047 (GtkAttachOptions) (0), 0, 0);
1050 GtkImage* image = new_local_image("cap_cylinder.bmp");
1051 gtk_widget_show(GTK_WIDGET(image));
1052 gtk_table_attach(table, GTK_WIDGET(image), 0, 1, 4, 5,
1053 (GtkAttachOptions) (GTK_FILL),
1054 (GtkAttachOptions) (0), 0, 0);
1059 GtkWidget* button = gtk_radio_button_new_with_label (group, "Bevel");
1060 gtk_widget_show (button);
1061 gtk_table_attach(table, button, 1, 2, 0, 1,
1062 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND),
1063 (GtkAttachOptions) (0), 0, 0);
1064 group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
1069 GtkWidget* button = gtk_radio_button_new_with_label (group, "Endcap");
1070 gtk_widget_show (button);
1071 gtk_table_attach(table, button, 1, 2, 1, 2,
1072 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND),
1073 (GtkAttachOptions) (0), 0, 0);
1074 group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
1079 GtkWidget* button = gtk_radio_button_new_with_label (group, "Inverted Bevel");
1080 gtk_widget_show (button);
1081 gtk_table_attach(table, button, 1, 2, 2, 3,
1082 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND),
1083 (GtkAttachOptions) (0), 0, 0);
1084 group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
1089 GtkWidget* button = gtk_radio_button_new_with_label (group, "Inverted Endcap");
1090 gtk_widget_show (button);
1091 gtk_table_attach(table, button, 1, 2, 3, 4,
1092 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND),
1093 (GtkAttachOptions) (0), 0, 0);
1094 group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
1099 GtkWidget* button = gtk_radio_button_new_with_label (group, "Cylinder");
1100 gtk_widget_show (button);
1101 gtk_table_attach(table, button, 1, 2, 4, 5,
1102 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND),
1103 (GtkAttachOptions) (0), 0, 0);
1104 group = gtk_radio_button_group (GTK_RADIO_BUTTON (button));
1112 GtkVBox* vbox = create_dialog_vbox(4);
1113 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(vbox), FALSE, FALSE, 0);
1115 GtkButton* button = create_modal_dialog_button("OK", ok_button);
1116 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1117 widget_make_default(GTK_WIDGET(button));
1118 gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel_group, GDK_Return, (GdkModifierType)0, GTK_ACCEL_VISIBLE);
1121 GtkButton* button = create_modal_dialog_button("Cancel", cancel_button);
1122 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1123 gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel_group, GDK_Escape, (GdkModifierType)0, GTK_ACCEL_VISIBLE);
1128 // Initialize dialog
1129 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bevel), TRUE);
1131 EMessageBoxReturn ret = modal_dialog_show(window, dialog);
1134 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (bevel)))
1135 *type = PATCHCAP_BEVEL;
1136 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(endcap)))
1137 *type = PATCHCAP_ENDCAP;
1138 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ibevel)))
1139 *type = PATCHCAP_INVERTED_BEVEL;
1140 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(iendcap)))
1141 *type = PATCHCAP_INVERTED_ENDCAP;
1142 else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cylinder)))
1143 *type = PATCHCAP_CYLINDER;
1146 gtk_widget_destroy(GTK_WIDGET(window));