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
24 #include "debugging/debugging.h"
27 #include "iselection.h"
32 #include "stream/stringstream.h"
33 #include "signal/isignal.h"
34 #include "shaderlib.h"
37 #include "gtkutil/idledraw.h"
38 #include "gtkutil/dialog.h"
39 #include "gtkutil/widget.h"
40 #include "brushmanip.h"
42 #include "patchmanip.h"
43 #include "patchdialog.h"
44 #include "selection.h"
45 #include "texwindow.h"
47 #include "mainframe.h"
53 select_workzone_t g_select_workzone;
57 Loops over all selected brushes and stores their
58 world AABBs in the specified array.
60 class CollectSelectedBrushesBounds : public SelectionSystem::Visitor
62 AABB* m_bounds; // array of AABBs
63 Unsigned m_max; // max AABB-elements in array
64 Unsigned& m_count;// count of valid AABBs stored in array
67 CollectSelectedBrushesBounds(AABB* bounds, Unsigned max, Unsigned& count)
75 void visit(scene::Instance& instance) const
77 ASSERT_MESSAGE(m_count <= m_max, "Invalid m_count in CollectSelectedBrushesBounds");
79 // stop if the array is already full
83 Selectable* selectable = Instance_getSelectable(instance);
85 && instance.isSelected())
88 if(Instance_getBrush(instance) != 0)
90 m_bounds[m_count] = instance.worldAABB();
98 Selects all objects that intersect one of the bounding AABBs.
99 The exact intersection-method is specified through TSelectionPolicy
101 template<class TSelectionPolicy>
102 class SelectByBounds : public scene::Graph::Walker
104 AABB* m_aabbs; // selection aabbs
105 Unsigned m_count; // number of aabbs in m_aabbs
106 TSelectionPolicy policy; // type that contains a custom intersection method aabb<->aabb
109 SelectByBounds(AABB* aabbs, Unsigned count)
115 bool pre(const scene::Path& path, scene::Instance& instance) const
117 Selectable* selectable = Instance_getSelectable(instance);
120 Entity* entity = Node_getEntity(path.top());
123 if(string_equal(entity->getKeyValue("classname"), "worldspawn"))
127 if( (path.size() > 1) &&
128 (!path.top().get().isRoot()) &&
132 for(Unsigned i = 0; i < m_count; ++i)
134 if(policy.Evaluate(m_aabbs[i], instance))
136 selectable->setSelected(true);
145 Performs selection operation on the global scenegraph.
146 If delete_bounds_src is true, then the objects which were
147 used as source for the selection aabbs will be deleted.
149 static void DoSelection(bool delete_bounds_src = true)
151 if(GlobalSelectionSystem().Mode() == SelectionSystem::ePrimitive)
153 // we may not need all AABBs since not all selected objects have to be brushes
154 const Unsigned max = (Unsigned)GlobalSelectionSystem().countSelected();
155 AABB* aabbs = new AABB[max];
158 CollectSelectedBrushesBounds collector(aabbs, max, count);
159 GlobalSelectionSystem().foreachSelected(collector);
161 // nothing usable in selection
168 // delete selected objects
169 if(delete_bounds_src)// see deleteSelection
171 UndoableCommand undo("deleteSelected");
175 // select objects with bounds
176 GlobalSceneGraph().traverse(SelectByBounds<TSelectionPolicy>(aabbs, count));
185 SelectionPolicy for SelectByBounds
186 Returns true if box and the AABB of instance intersect
188 class SelectionPolicy_Touching
191 bool Evaluate(const AABB& box, scene::Instance& instance) const
193 const AABB& other(instance.worldAABB());
194 for(Unsigned i = 0; i < 3; ++i)
196 if(fabsf(box.origin[i] - other.origin[i]) > (box.extents[i] + other.extents[i]))
204 SelectionPolicy for SelectByBounds
205 Returns true if the AABB of instance is inside box
207 class SelectionPolicy_Inside
210 bool Evaluate(const AABB& box, scene::Instance& instance) const
212 const AABB& other(instance.worldAABB());
213 for(Unsigned i = 0; i < 3; ++i)
215 if(fabsf(box.origin[i] - other.origin[i]) > (box.extents[i] - other.extents[i]))
222 class DeleteSelected : public scene::Graph::Walker
224 mutable bool m_remove;
225 mutable bool m_removedChild;
228 : m_remove(false), m_removedChild(false)
231 bool pre(const scene::Path& path, scene::Instance& instance) const
233 m_removedChild = false;
235 Selectable* selectable = Instance_getSelectable(instance);
237 && selectable->isSelected()
239 && !path.top().get().isRoot())
243 return false;// dont traverse into child elements
247 void post(const scene::Path& path, scene::Instance& instance) const
252 m_removedChild = false;
254 // delete empty entities
255 Entity* entity = Node_getEntity(path.top());
257 && path.top().get_pointer() != Map_FindWorldspawn(g_map)
258 && Node_getTraversable(path.top())->empty())
260 Path_deleteTop(path);
264 // node should be removed
267 if(Node_isEntity(path.parent()) != 0)
269 m_removedChild = true;
273 Path_deleteTop(path);
278 void Scene_DeleteSelected(scene::Graph& graph)
280 graph.traverse(DeleteSelected());
284 void Select_Delete (void)
286 Scene_DeleteSelected(GlobalSceneGraph());
289 class InvertSelectionWalker : public scene::Graph::Walker
291 SelectionSystem::EMode m_mode;
292 mutable Selectable* m_selectable;
294 InvertSelectionWalker(SelectionSystem::EMode mode)
295 : m_mode(mode), m_selectable(0)
298 bool pre(const scene::Path& path, scene::Instance& instance) const
300 Selectable* selectable = Instance_getSelectable(instance);
305 case SelectionSystem::eEntity:
306 if(Node_isEntity(path.top()) != 0)
308 m_selectable = path.top().get().visible() ? selectable : 0;
311 case SelectionSystem::ePrimitive:
312 m_selectable = path.top().get().visible() ? selectable : 0;
314 case SelectionSystem::eComponent:
320 void post(const scene::Path& path, scene::Instance& instance) const
322 if(m_selectable != 0)
324 m_selectable->setSelected(!m_selectable->isSelected());
330 void Scene_Invert_Selection(scene::Graph& graph)
332 graph.traverse(InvertSelectionWalker(GlobalSelectionSystem().Mode()));
337 Scene_Invert_Selection(GlobalSceneGraph());
340 class ExpandSelectionToEntitiesWalker : public scene::Graph::Walker
342 mutable std::size_t m_depth;
344 ExpandSelectionToEntitiesWalker() : m_depth(0)
347 bool pre(const scene::Path& path, scene::Instance& instance) const
352 NodeSmartReference me(path.top().get());
353 if(me == Map_FindOrInsertWorldspawn(g_map))
356 if(m_depth == 2) // entity depth
358 // traverse and select children if any one is selected
359 if(instance.childSelected())
360 Instance_setSelected(instance, true);
361 return Node_getEntity(path.top())->isContainer() && instance.isSelected();
363 else if(m_depth == 3) // primitive depth
365 Instance_setSelected(instance, true);
370 void post(const scene::Path& path, scene::Instance& instance) const
376 void Scene_ExpandSelectionToEntities()
378 GlobalSceneGraph().traverse(ExpandSelectionToEntitiesWalker());
384 void Selection_UpdateWorkzone()
386 if(GlobalSelectionSystem().countSelected() != 0)
388 Select_GetBounds(g_select_workzone.d_work_min, g_select_workzone.d_work_max);
391 typedef FreeCaller<Selection_UpdateWorkzone> SelectionUpdateWorkzoneCaller;
393 IdleDraw g_idleWorkzone = IdleDraw(SelectionUpdateWorkzoneCaller());
396 const select_workzone_t& Select_getWorkZone()
398 g_idleWorkzone.flush();
399 return g_select_workzone;
402 void UpdateWorkzone_ForSelection()
404 g_idleWorkzone.queueDraw();
407 // update the workzone to the current selection
408 void UpdateWorkzone_ForSelectionChanged(const Selectable& selectable)
410 if(selectable.isSelected())
412 UpdateWorkzone_ForSelection();
416 void Select_SetShader(const char* shader)
418 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
420 Scene_BrushSetShader_Selected(GlobalSceneGraph(), shader);
421 Scene_PatchSetShader_Selected(GlobalSceneGraph(), shader);
423 Scene_BrushSetShader_Component_Selected(GlobalSceneGraph(), shader);
426 void Select_SetTexdef(const TextureProjection& projection)
428 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
430 Scene_BrushSetTexdef_Selected(GlobalSceneGraph(), projection);
432 Scene_BrushSetTexdef_Component_Selected(GlobalSceneGraph(), projection);
435 void Select_SetFlags(const ContentsFlagsValue& flags)
437 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
439 Scene_BrushSetFlags_Selected(GlobalSceneGraph(), flags);
441 Scene_BrushSetFlags_Component_Selected(GlobalSceneGraph(), flags);
444 void Select_GetBounds (Vector3& mins, Vector3& maxs)
447 Scene_BoundsSelected(GlobalSceneGraph(), bounds);
448 maxs = vector3_added(bounds.origin, bounds.extents);
449 mins = vector3_subtracted(bounds.origin, bounds.extents);
452 void Select_GetMid (Vector3& mid)
455 Scene_BoundsSelected(GlobalSceneGraph(), bounds);
456 mid = vector3_snapped(bounds.origin);
460 void Select_FlipAxis (int axis)
462 Vector3 flip(1, 1, 1);
464 GlobalSelectionSystem().scaleSelected(flip);
468 void Select_Scale(float x, float y, float z)
470 GlobalSelectionSystem().scaleSelected(Vector3(x, y, z));
486 inline Matrix4 matrix4_rotation_for_axis90(axis_t axis, sign_t sign)
491 if(sign == eSignPositive)
493 return matrix4_rotation_for_sincos_x(1, 0);
497 return matrix4_rotation_for_sincos_x(-1, 0);
500 if(sign == eSignPositive)
502 return matrix4_rotation_for_sincos_y(1, 0);
506 return matrix4_rotation_for_sincos_y(-1, 0);
508 default://case eAxisZ:
509 if(sign == eSignPositive)
511 return matrix4_rotation_for_sincos_z(1, 0);
515 return matrix4_rotation_for_sincos_z(-1, 0);
520 inline void matrix4_rotate_by_axis90(Matrix4& matrix, axis_t axis, sign_t sign)
522 matrix4_multiply_by_matrix4(matrix, matrix4_rotation_for_axis90(axis, sign));
525 inline void matrix4_pivoted_rotate_by_axis90(Matrix4& matrix, axis_t axis, sign_t sign, const Vector3& pivotpoint)
527 matrix4_translate_by_vec3(matrix, pivotpoint);
528 matrix4_rotate_by_axis90(matrix, axis, sign);
529 matrix4_translate_by_vec3(matrix, vector3_negated(pivotpoint));
532 inline Quaternion quaternion_for_axis90(axis_t axis, sign_t sign)
538 if(sign == eSignPositive)
540 return Quaternion(c_half_sqrt2f, 0, 0, c_half_sqrt2f);
544 return Quaternion(-c_half_sqrt2f, 0, 0, -c_half_sqrt2f);
547 if(sign == eSignPositive)
549 return Quaternion(0, c_half_sqrt2f, 0, c_half_sqrt2f);
553 return Quaternion(0, -c_half_sqrt2f, 0, -c_half_sqrt2f);
555 default://case eAxisZ:
556 if(sign == eSignPositive)
558 return Quaternion(0, 0, c_half_sqrt2f, c_half_sqrt2f);
562 return Quaternion(0, 0, -c_half_sqrt2f, -c_half_sqrt2f);
566 quaternion_for_matrix4_rotation(matrix4_rotation_for_axis90((axis_t)axis, (deg > 0) ? eSignPositive : eSignNegative));
570 void Select_RotateAxis (int axis, float deg)
572 if(fabs(deg) == 90.f)
574 GlobalSelectionSystem().rotateSelected(quaternion_for_axis90((axis_t)axis, (deg > 0) ? eSignPositive : eSignNegative));
581 GlobalSelectionSystem().rotateSelected(quaternion_for_matrix4_rotation(matrix4_rotation_for_x_degrees(deg)));
584 GlobalSelectionSystem().rotateSelected(quaternion_for_matrix4_rotation(matrix4_rotation_for_y_degrees(deg)));
587 GlobalSelectionSystem().rotateSelected(quaternion_for_matrix4_rotation(matrix4_rotation_for_z_degrees(deg)));
594 void Select_ShiftTexture(float x, float y)
596 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
598 Scene_BrushShiftTexdef_Selected(GlobalSceneGraph(), x, y);
599 Scene_PatchTranslateTexture_Selected(GlobalSceneGraph(), x, y);
601 //globalOutputStream() << "shift selected face textures: s=" << x << " t=" << y << '\n';
602 Scene_BrushShiftTexdef_Component_Selected(GlobalSceneGraph(), x, y);
605 void Select_ScaleTexture(float x, float y)
607 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
609 Scene_BrushScaleTexdef_Selected(GlobalSceneGraph(), x, y);
610 Scene_PatchScaleTexture_Selected(GlobalSceneGraph(), x, y);
612 Scene_BrushScaleTexdef_Component_Selected(GlobalSceneGraph(), x, y);
615 void Select_RotateTexture(float amt)
617 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
619 Scene_BrushRotateTexdef_Selected(GlobalSceneGraph(), amt);
620 Scene_PatchRotateTexture_Selected(GlobalSceneGraph(), amt);
622 Scene_BrushRotateTexdef_Component_Selected(GlobalSceneGraph(), amt);
625 // TTimo modified to handle shader architecture:
626 // expects shader names at input, comparison relies on shader names .. texture names no longer relevant
627 void FindReplaceTextures(const char* pFind, const char* pReplace, bool bSelected)
629 if(!texdef_name_valid(pFind))
631 globalErrorStream() << "FindReplaceTextures: invalid texture name: '" << pFind << "', aborted\n";
634 if(!texdef_name_valid(pReplace))
636 globalErrorStream() << "FindReplaceTextures: invalid texture name: '" << pReplace << "', aborted\n";
640 StringOutputStream command;
641 command << "textureFindReplace -find " << pFind << " -replace " << pReplace;
642 UndoableCommand undo(command.c_str());
646 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
648 Scene_BrushFindReplaceShader_Selected(GlobalSceneGraph(), pFind, pReplace);
649 Scene_PatchFindReplaceShader_Selected(GlobalSceneGraph(), pFind, pReplace);
651 Scene_BrushFindReplaceShader_Component_Selected(GlobalSceneGraph(), pFind, pReplace);
655 Scene_BrushFindReplaceShader(GlobalSceneGraph(), pFind, pReplace);
656 Scene_PatchFindReplaceShader(GlobalSceneGraph(), pFind, pReplace);
660 typedef std::vector<const char*> Classnames;
662 bool classnames_match_entity(const Classnames& classnames, Entity* entity)
664 for(Classnames::const_iterator i = classnames.begin(); i != classnames.end(); ++i)
666 if(string_equal(entity->getKeyValue("classname"), *i))
674 class EntityFindByClassnameWalker : public scene::Graph::Walker
676 const Classnames& m_classnames;
678 EntityFindByClassnameWalker(const Classnames& classnames)
679 : m_classnames(classnames)
682 bool pre(const scene::Path& path, scene::Instance& instance) const
684 Entity* entity = Node_getEntity(path.top());
686 && classnames_match_entity(m_classnames, entity))
688 Instance_getSelectable(instance)->setSelected(true);
694 void Scene_EntitySelectByClassnames(scene::Graph& graph, const Classnames& classnames)
696 graph.traverse(EntityFindByClassnameWalker(classnames));
699 class EntityGetSelectedClassnamesWalker : public scene::Graph::Walker
701 Classnames& m_classnames;
703 EntityGetSelectedClassnamesWalker(Classnames& classnames)
704 : m_classnames(classnames)
707 bool pre(const scene::Path& path, scene::Instance& instance) const
709 Selectable* selectable = Instance_getSelectable(instance);
711 && selectable->isSelected())
713 Entity* entity = Node_getEntity(path.top());
716 m_classnames.push_back(entity->getKeyValue("classname"));
723 void Scene_EntityGetClassnames(scene::Graph& graph, Classnames& classnames)
725 graph.traverse(EntityGetSelectedClassnamesWalker(classnames));
728 void Select_AllOfType()
730 if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
732 if(GlobalSelectionSystem().ComponentMode() == SelectionSystem::eFace)
734 GlobalSelectionSystem().setSelectedAllComponents(false);
735 Scene_BrushSelectByShader_Component(GlobalSceneGraph(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
740 Classnames classnames;
741 Scene_EntityGetClassnames(GlobalSceneGraph(), classnames);
742 GlobalSelectionSystem().setSelectedAll(false);
743 if(!classnames.empty())
745 Scene_EntitySelectByClassnames(GlobalSceneGraph(), classnames);
749 Scene_BrushSelectByShader(GlobalSceneGraph(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
750 Scene_PatchSelectByShader(GlobalSceneGraph(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
755 void Select_Inside(void)
757 SelectByBounds<SelectionPolicy_Inside>::DoSelection();
760 void Select_Touching(void)
762 SelectByBounds<SelectionPolicy_Touching>::DoSelection(false);
765 void Select_FitTexture(float horizontal, float vertical)
767 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
769 Scene_BrushFitTexture_Selected(GlobalSceneGraph(), horizontal, vertical);
771 Scene_BrushFitTexture_Component_Selected(GlobalSceneGraph(), horizontal, vertical);
776 inline void hide_node(scene::Node& node, bool hide)
779 ? node.enable(scene::Node::eHidden)
780 : node.disable(scene::Node::eHidden);
783 class HideSelectedWalker : public scene::Graph::Walker
787 HideSelectedWalker(bool hide)
791 bool pre(const scene::Path& path, scene::Instance& instance) const
793 Selectable* selectable = Instance_getSelectable(instance);
795 && selectable->isSelected())
797 hide_node(path.top(), m_hide);
803 void Scene_Hide_Selected(bool hide)
805 GlobalSceneGraph().traverse(HideSelectedWalker(hide));
810 Scene_Hide_Selected(true);
817 GlobalSelectionSystem().setSelectedAll(false);
821 class HideAllWalker : public scene::Graph::Walker
825 HideAllWalker(bool hide)
829 bool pre(const scene::Path& path, scene::Instance& instance) const
831 hide_node(path.top(), m_hide);
836 void Scene_Hide_All(bool hide)
838 GlobalSceneGraph().traverse(HideAllWalker(hide));
841 void Select_ShowAllHidden()
843 Scene_Hide_All(false);
849 void Selection_Flipx()
851 UndoableCommand undo("mirrorSelected -axis x");
855 void Selection_Flipy()
857 UndoableCommand undo("mirrorSelected -axis y");
861 void Selection_Flipz()
863 UndoableCommand undo("mirrorSelected -axis z");
867 void Selection_Rotatex()
869 UndoableCommand undo("rotateSelected -axis x -angle -90");
870 Select_RotateAxis(0,-90);
873 void Selection_Rotatey()
875 UndoableCommand undo("rotateSelected -axis y -angle 90");
876 Select_RotateAxis(1, 90);
879 void Selection_Rotatez()
881 UndoableCommand undo("rotateSelected -axis z -angle -90");
882 Select_RotateAxis(2,-90);
887 void Nudge(int nDim, float fNudge)
889 Vector3 translate(0, 0, 0);
890 translate[nDim] = fNudge;
892 GlobalSelectionSystem().translateSelected(translate);
895 void Selection_NudgeZ(float amount)
897 StringOutputStream command;
898 command << "nudgeSelected -axis z -amount " << amount;
899 UndoableCommand undo(command.c_str());
904 void Selection_MoveDown()
906 Selection_NudgeZ(-GetGridSize());
909 void Selection_MoveUp()
911 Selection_NudgeZ(GetGridSize());
914 void SceneSelectionChange(const Selectable& selectable)
919 SignalHandlerId Selection_boundsChanged;
921 void Selection_construct()
923 typedef FreeCaller1<const Selectable&, SceneSelectionChange> SceneSelectionChangeCaller;
924 GlobalSelectionSystem().addSelectionChangeCallback(SceneSelectionChangeCaller());
925 typedef FreeCaller1<const Selectable&, UpdateWorkzone_ForSelectionChanged> UpdateWorkzoneForSelectionChangedCaller;
926 GlobalSelectionSystem().addSelectionChangeCallback(UpdateWorkzoneForSelectionChangedCaller());
927 typedef FreeCaller<UpdateWorkzone_ForSelection> UpdateWorkzoneForSelectionCaller;
928 Selection_boundsChanged = GlobalSceneGraph().addBoundsChangedCallback(UpdateWorkzoneForSelectionCaller());
931 void Selection_destroy()
933 GlobalSceneGraph().removeBoundsChangedCallback(Selection_boundsChanged);
938 #include <gtk/gtkbox.h>
939 #include <gtk/gtkspinbutton.h>
940 #include <gtk/gtktable.h>
941 #include <gtk/gtklabel.h>
942 #include <gdk/gdkkeysyms.h>
945 inline Quaternion quaternion_for_euler_xyz_degrees(const Vector3& eulerXYZ)
948 return quaternion_for_matrix4_rotation(matrix4_rotation_for_euler_xyz_degrees(eulerXYZ));
950 return quaternion_multiplied_by_quaternion(
951 quaternion_multiplied_by_quaternion(
952 quaternion_for_z(degrees_to_radians(eulerXYZ[2])),
953 quaternion_for_y(degrees_to_radians(eulerXYZ[1]))
955 quaternion_for_x(degrees_to_radians(eulerXYZ[0]))
958 double cx = cos(degrees_to_radians(eulerXYZ[0] * 0.5));
959 double sx = sin(degrees_to_radians(eulerXYZ[0] * 0.5));
960 double cy = cos(degrees_to_radians(eulerXYZ[1] * 0.5));
961 double sy = sin(degrees_to_radians(eulerXYZ[1] * 0.5));
962 double cz = cos(degrees_to_radians(eulerXYZ[2] * 0.5));
963 double sz = sin(degrees_to_radians(eulerXYZ[2] * 0.5));
966 cz * cy * sx - sz * sy * cx,
967 cz * sy * cx + sz * cy * sx,
968 sz * cy * cx - cz * sy * sx,
969 cz * cy * cx + sz * sy * sx
982 static gboolean rotatedlg_apply (GtkWidget *widget, RotateDialog* rotateDialog)
986 eulerXYZ[0] = static_cast<float>(gtk_spin_button_get_value(rotateDialog->x));
987 eulerXYZ[1] = static_cast<float>(gtk_spin_button_get_value(rotateDialog->y));
988 eulerXYZ[2] = static_cast<float>(gtk_spin_button_get_value(rotateDialog->z));
990 StringOutputStream command;
991 command << "rotateSelectedEulerXYZ -x " << eulerXYZ[0] << " -y " << eulerXYZ[1] << " -z " << eulerXYZ[2];
992 UndoableCommand undo(command.c_str());
994 GlobalSelectionSystem().rotateSelected(quaternion_for_euler_xyz_degrees(eulerXYZ));
998 static gboolean rotatedlg_cancel (GtkWidget *widget, RotateDialog* rotateDialog)
1000 gtk_widget_hide(GTK_WIDGET(rotateDialog->window));
1002 gtk_spin_button_set_value(rotateDialog->x, 0.0f); // reset to 0 on close
1003 gtk_spin_button_set_value(rotateDialog->y, 0.0f);
1004 gtk_spin_button_set_value(rotateDialog->z, 0.0f);
1009 static gboolean rotatedlg_ok (GtkWidget *widget, RotateDialog* rotateDialog)
1011 rotatedlg_apply(widget, rotateDialog);
1012 rotatedlg_cancel(widget, rotateDialog);
1016 static gboolean rotatedlg_delete (GtkWidget *widget, GdkEventAny *event, RotateDialog* rotateDialog)
1018 rotatedlg_cancel(widget, rotateDialog);
1022 RotateDialog g_rotate_dialog;
1025 if(g_rotate_dialog.window == NULL)
1027 g_rotate_dialog.window = create_dialog_window(MainFrame_getWindow(), "Arbitrary rotation", G_CALLBACK(rotatedlg_delete), &g_rotate_dialog);
1029 GtkAccelGroup* accel = gtk_accel_group_new();
1030 gtk_window_add_accel_group(g_rotate_dialog.window, accel);
1033 GtkHBox* hbox = create_dialog_hbox(4, 4);
1034 gtk_container_add(GTK_CONTAINER(g_rotate_dialog.window), GTK_WIDGET(hbox));
1036 GtkTable* table = create_dialog_table(3, 2, 4, 4);
1037 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(table), TRUE, TRUE, 0);
1039 GtkWidget* label = gtk_label_new (" X ");
1040 gtk_widget_show (label);
1041 gtk_table_attach(table, label, 0, 1, 0, 1,
1042 (GtkAttachOptions) (0),
1043 (GtkAttachOptions) (0), 0, 0);
1046 GtkWidget* label = gtk_label_new (" Y ");
1047 gtk_widget_show (label);
1048 gtk_table_attach(table, label, 0, 1, 1, 2,
1049 (GtkAttachOptions) (0),
1050 (GtkAttachOptions) (0), 0, 0);
1053 GtkWidget* label = gtk_label_new (" Z ");
1054 gtk_widget_show (label);
1055 gtk_table_attach(table, label, 0, 1, 2, 3,
1056 (GtkAttachOptions) (0),
1057 (GtkAttachOptions) (0), 0, 0);
1060 GtkAdjustment* adj = GTK_ADJUSTMENT(gtk_adjustment_new(0, -359, 359, 1, 10, 0));
1061 GtkSpinButton* spin = GTK_SPIN_BUTTON(gtk_spin_button_new(adj, 1, 0));
1062 gtk_widget_show(GTK_WIDGET(spin));
1063 gtk_table_attach(table, GTK_WIDGET(spin), 1, 2, 0, 1,
1064 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1065 (GtkAttachOptions) (0), 0, 0);
1066 gtk_widget_set_size_request(GTK_WIDGET(spin), 64, -1);
1067 gtk_spin_button_set_wrap(spin, TRUE);
1069 gtk_widget_grab_focus(GTK_WIDGET(spin));
1071 g_rotate_dialog.x = spin;
1074 GtkAdjustment* adj = GTK_ADJUSTMENT(gtk_adjustment_new(0, -359, 359, 1, 10, 0));
1075 GtkSpinButton* spin = GTK_SPIN_BUTTON(gtk_spin_button_new(adj, 1, 0));
1076 gtk_widget_show(GTK_WIDGET(spin));
1077 gtk_table_attach(table, GTK_WIDGET(spin), 1, 2, 1, 2,
1078 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1079 (GtkAttachOptions) (0), 0, 0);
1080 gtk_widget_set_size_request(GTK_WIDGET(spin), 64, -1);
1081 gtk_spin_button_set_wrap(spin, TRUE);
1083 g_rotate_dialog.y = spin;
1086 GtkAdjustment* adj = GTK_ADJUSTMENT(gtk_adjustment_new(0, -359, 359, 1, 10, 0));
1087 GtkSpinButton* spin = GTK_SPIN_BUTTON(gtk_spin_button_new(adj, 1, 0));
1088 gtk_widget_show(GTK_WIDGET(spin));
1089 gtk_table_attach(table, GTK_WIDGET(spin), 1, 2, 2, 3,
1090 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1091 (GtkAttachOptions) (0), 0, 0);
1092 gtk_widget_set_size_request(GTK_WIDGET(spin), 64, -1);
1093 gtk_spin_button_set_wrap(spin, TRUE);
1095 g_rotate_dialog.z = spin;
1099 GtkVBox* vbox = create_dialog_vbox(4);
1100 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(vbox), TRUE, TRUE, 0);
1102 GtkButton* button = create_dialog_button("OK", G_CALLBACK(rotatedlg_ok), &g_rotate_dialog);
1103 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1104 widget_make_default(GTK_WIDGET(button));
1105 gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0);
1108 GtkButton* button = create_dialog_button("Cancel", G_CALLBACK(rotatedlg_cancel), &g_rotate_dialog);
1109 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1110 gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0);
1113 GtkButton* button = create_dialog_button("Apply", G_CALLBACK(rotatedlg_apply), &g_rotate_dialog);
1114 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1120 gtk_widget_show(GTK_WIDGET(g_rotate_dialog.window));
1139 static gboolean scaledlg_apply (GtkWidget *widget, ScaleDialog* scaleDialog)
1143 sx = static_cast<float>(atof(gtk_entry_get_text (GTK_ENTRY (scaleDialog->x))));
1144 sy = static_cast<float>(atof(gtk_entry_get_text (GTK_ENTRY (scaleDialog->y))));
1145 sz = static_cast<float>(atof(gtk_entry_get_text (GTK_ENTRY (scaleDialog->z))));
1147 StringOutputStream command;
1148 command << "scaleSelected -x " << sx << " -y " << sy << " -z " << sz;
1149 UndoableCommand undo(command.c_str());
1151 Select_Scale(sx, sy, sz);
1156 static gboolean scaledlg_cancel (GtkWidget *widget, ScaleDialog* scaleDialog)
1158 gtk_widget_hide(GTK_WIDGET(scaleDialog->window));
1160 gtk_entry_set_text (GTK_ENTRY(scaleDialog->x), "1.0");
1161 gtk_entry_set_text (GTK_ENTRY(scaleDialog->y), "1.0");
1162 gtk_entry_set_text (GTK_ENTRY(scaleDialog->z), "1.0");
1167 static gboolean scaledlg_ok (GtkWidget *widget, ScaleDialog* scaleDialog)
1169 scaledlg_apply(widget, scaleDialog);
1170 scaledlg_cancel(widget, scaleDialog);
1174 static gboolean scaledlg_delete (GtkWidget *widget, GdkEventAny *event, ScaleDialog* scaleDialog)
1176 scaledlg_cancel(widget, scaleDialog);
1180 ScaleDialog g_scale_dialog;
1184 if(g_scale_dialog.window == NULL)
1186 g_scale_dialog.window = create_dialog_window(MainFrame_getWindow(), "Arbitrary scale", G_CALLBACK(scaledlg_delete), &g_scale_dialog);
1188 GtkAccelGroup* accel = gtk_accel_group_new();
1189 gtk_window_add_accel_group(g_scale_dialog.window, accel);
1192 GtkHBox* hbox = create_dialog_hbox(4, 4);
1193 gtk_container_add(GTK_CONTAINER(g_scale_dialog.window), GTK_WIDGET(hbox));
1195 GtkTable* table = create_dialog_table(3, 2, 4, 4);
1196 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(table), TRUE, TRUE, 0);
1198 GtkWidget* label = gtk_label_new (" X ");
1199 gtk_widget_show (label);
1200 gtk_table_attach(table, label, 0, 1, 0, 1,
1201 (GtkAttachOptions) (0),
1202 (GtkAttachOptions) (0), 0, 0);
1205 GtkWidget* label = gtk_label_new (" Y ");
1206 gtk_widget_show (label);
1207 gtk_table_attach(table, label, 0, 1, 1, 2,
1208 (GtkAttachOptions) (0),
1209 (GtkAttachOptions) (0), 0, 0);
1212 GtkWidget* label = gtk_label_new (" Z ");
1213 gtk_widget_show (label);
1214 gtk_table_attach(table, label, 0, 1, 2, 3,
1215 (GtkAttachOptions) (0),
1216 (GtkAttachOptions) (0), 0, 0);
1219 GtkWidget* entry = gtk_entry_new();
1220 gtk_entry_set_text (GTK_ENTRY(entry), "1.0");
1221 gtk_widget_show (entry);
1222 gtk_table_attach(table, entry, 1, 2, 0, 1,
1223 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1224 (GtkAttachOptions) (0), 0, 0);
1226 g_scale_dialog.x = entry;
1229 GtkWidget* entry = gtk_entry_new();
1230 gtk_entry_set_text (GTK_ENTRY(entry), "1.0");
1231 gtk_widget_show (entry);
1232 gtk_table_attach(table, entry, 1, 2, 1, 2,
1233 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1234 (GtkAttachOptions) (0), 0, 0);
1236 g_scale_dialog.y = entry;
1239 GtkWidget* entry = gtk_entry_new();
1240 gtk_entry_set_text (GTK_ENTRY(entry), "1.0");
1241 gtk_widget_show (entry);
1242 gtk_table_attach(table, entry, 1, 2, 2, 3,
1243 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1244 (GtkAttachOptions) (0), 0, 0);
1246 g_scale_dialog.z = entry;
1250 GtkVBox* vbox = create_dialog_vbox(4);
1251 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(vbox), TRUE, TRUE, 0);
1253 GtkButton* button = create_dialog_button("OK", G_CALLBACK(scaledlg_ok), &g_scale_dialog);
1254 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1255 widget_make_default(GTK_WIDGET(button));
1256 gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0);
1259 GtkButton* button = create_dialog_button("Cancel", G_CALLBACK(scaledlg_cancel), &g_scale_dialog);
1260 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1261 gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0);
1264 GtkButton* button = create_dialog_button("Apply", G_CALLBACK(scaledlg_apply), &g_scale_dialog);
1265 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1271 gtk_widget_show(GTK_WIDGET(g_scale_dialog.window));