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
350 if(m_depth == 2) // entity depth
352 // traverse and select children if any one is selected
353 if(instance.childSelected())
354 Instance_setSelected(instance, true);
355 return Node_getEntity(path.top())->isContainer() && instance.childSelected();
357 else if(m_depth == 3) // primitive depth
359 Instance_setSelected(instance, true);
364 void post(const scene::Path& path, scene::Instance& instance) const
370 void Scene_ExpandSelectionToEntities()
372 GlobalSceneGraph().traverse(ExpandSelectionToEntitiesWalker());
378 void Selection_UpdateWorkzone()
380 if(GlobalSelectionSystem().countSelected() != 0)
382 Select_GetBounds(g_select_workzone.d_work_min, g_select_workzone.d_work_max);
385 typedef FreeCaller<Selection_UpdateWorkzone> SelectionUpdateWorkzoneCaller;
387 IdleDraw g_idleWorkzone = IdleDraw(SelectionUpdateWorkzoneCaller());
390 const select_workzone_t& Select_getWorkZone()
392 g_idleWorkzone.flush();
393 return g_select_workzone;
396 void UpdateWorkzone_ForSelection()
398 g_idleWorkzone.queueDraw();
401 // update the workzone to the current selection
402 void UpdateWorkzone_ForSelectionChanged(const Selectable& selectable)
404 if(selectable.isSelected())
406 UpdateWorkzone_ForSelection();
410 void Select_SetShader(const char* shader)
412 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
414 Scene_BrushSetShader_Selected(GlobalSceneGraph(), shader);
415 Scene_PatchSetShader_Selected(GlobalSceneGraph(), shader);
417 Scene_BrushSetShader_Component_Selected(GlobalSceneGraph(), shader);
420 void Select_SetTexdef(const TextureProjection& projection)
422 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
424 Scene_BrushSetTexdef_Selected(GlobalSceneGraph(), projection);
426 Scene_BrushSetTexdef_Component_Selected(GlobalSceneGraph(), projection);
429 void Select_SetFlags(const ContentsFlagsValue& flags)
431 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
433 Scene_BrushSetFlags_Selected(GlobalSceneGraph(), flags);
435 Scene_BrushSetFlags_Component_Selected(GlobalSceneGraph(), flags);
438 void Select_GetBounds (Vector3& mins, Vector3& maxs)
441 Scene_BoundsSelected(GlobalSceneGraph(), bounds);
442 maxs = vector3_added(bounds.origin, bounds.extents);
443 mins = vector3_subtracted(bounds.origin, bounds.extents);
446 void Select_GetMid (Vector3& mid)
449 Scene_BoundsSelected(GlobalSceneGraph(), bounds);
450 mid = vector3_snapped(bounds.origin);
454 void Select_FlipAxis (int axis)
456 Vector3 flip(1, 1, 1);
458 GlobalSelectionSystem().scaleSelected(flip);
462 void Select_Scale(float x, float y, float z)
464 GlobalSelectionSystem().scaleSelected(Vector3(x, y, z));
480 inline Matrix4 matrix4_rotation_for_axis90(axis_t axis, sign_t sign)
485 if(sign == eSignPositive)
487 return matrix4_rotation_for_sincos_x(1, 0);
491 return matrix4_rotation_for_sincos_x(-1, 0);
494 if(sign == eSignPositive)
496 return matrix4_rotation_for_sincos_y(1, 0);
500 return matrix4_rotation_for_sincos_y(-1, 0);
502 default://case eAxisZ:
503 if(sign == eSignPositive)
505 return matrix4_rotation_for_sincos_z(1, 0);
509 return matrix4_rotation_for_sincos_z(-1, 0);
514 inline void matrix4_rotate_by_axis90(Matrix4& matrix, axis_t axis, sign_t sign)
516 matrix4_multiply_by_matrix4(matrix, matrix4_rotation_for_axis90(axis, sign));
519 inline void matrix4_pivoted_rotate_by_axis90(Matrix4& matrix, axis_t axis, sign_t sign, const Vector3& pivotpoint)
521 matrix4_translate_by_vec3(matrix, pivotpoint);
522 matrix4_rotate_by_axis90(matrix, axis, sign);
523 matrix4_translate_by_vec3(matrix, vector3_negated(pivotpoint));
526 inline Quaternion quaternion_for_axis90(axis_t axis, sign_t sign)
532 if(sign == eSignPositive)
534 return Quaternion(c_half_sqrt2f, 0, 0, c_half_sqrt2f);
538 return Quaternion(-c_half_sqrt2f, 0, 0, -c_half_sqrt2f);
541 if(sign == eSignPositive)
543 return Quaternion(0, c_half_sqrt2f, 0, c_half_sqrt2f);
547 return Quaternion(0, -c_half_sqrt2f, 0, -c_half_sqrt2f);
549 default://case eAxisZ:
550 if(sign == eSignPositive)
552 return Quaternion(0, 0, c_half_sqrt2f, c_half_sqrt2f);
556 return Quaternion(0, 0, -c_half_sqrt2f, -c_half_sqrt2f);
560 quaternion_for_matrix4_rotation(matrix4_rotation_for_axis90((axis_t)axis, (deg > 0) ? eSignPositive : eSignNegative));
564 void Select_RotateAxis (int axis, float deg)
566 if(fabs(deg) == 90.f)
568 GlobalSelectionSystem().rotateSelected(quaternion_for_axis90((axis_t)axis, (deg > 0) ? eSignPositive : eSignNegative));
575 GlobalSelectionSystem().rotateSelected(quaternion_for_matrix4_rotation(matrix4_rotation_for_x_degrees(deg)));
578 GlobalSelectionSystem().rotateSelected(quaternion_for_matrix4_rotation(matrix4_rotation_for_y_degrees(deg)));
581 GlobalSelectionSystem().rotateSelected(quaternion_for_matrix4_rotation(matrix4_rotation_for_z_degrees(deg)));
588 void Select_ShiftTexture(float x, float y)
590 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
592 Scene_BrushShiftTexdef_Selected(GlobalSceneGraph(), x, y);
593 Scene_PatchTranslateTexture_Selected(GlobalSceneGraph(), x, y);
595 //globalOutputStream() << "shift selected face textures: s=" << x << " t=" << y << '\n';
596 Scene_BrushShiftTexdef_Component_Selected(GlobalSceneGraph(), x, y);
599 void Select_ScaleTexture(float x, float y)
601 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
603 Scene_BrushScaleTexdef_Selected(GlobalSceneGraph(), x, y);
604 Scene_PatchScaleTexture_Selected(GlobalSceneGraph(), x, y);
606 Scene_BrushScaleTexdef_Component_Selected(GlobalSceneGraph(), x, y);
609 void Select_RotateTexture(float amt)
611 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
613 Scene_BrushRotateTexdef_Selected(GlobalSceneGraph(), amt);
614 Scene_PatchRotateTexture_Selected(GlobalSceneGraph(), amt);
616 Scene_BrushRotateTexdef_Component_Selected(GlobalSceneGraph(), amt);
619 // TTimo modified to handle shader architecture:
620 // expects shader names at input, comparison relies on shader names .. texture names no longer relevant
621 void FindReplaceTextures(const char* pFind, const char* pReplace, bool bSelected)
623 if(!texdef_name_valid(pFind))
625 globalErrorStream() << "FindReplaceTextures: invalid texture name: '" << pFind << "', aborted\n";
628 if(!texdef_name_valid(pReplace))
630 globalErrorStream() << "FindReplaceTextures: invalid texture name: '" << pReplace << "', aborted\n";
634 StringOutputStream command;
635 command << "textureFindReplace -find " << pFind << " -replace " << pReplace;
636 UndoableCommand undo(command.c_str());
640 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
642 Scene_BrushFindReplaceShader_Selected(GlobalSceneGraph(), pFind, pReplace);
643 Scene_PatchFindReplaceShader_Selected(GlobalSceneGraph(), pFind, pReplace);
645 Scene_BrushFindReplaceShader_Component_Selected(GlobalSceneGraph(), pFind, pReplace);
649 Scene_BrushFindReplaceShader(GlobalSceneGraph(), pFind, pReplace);
650 Scene_PatchFindReplaceShader(GlobalSceneGraph(), pFind, pReplace);
654 typedef std::vector<const char*> Classnames;
656 bool classnames_match_entity(const Classnames& classnames, Entity* entity)
658 for(Classnames::const_iterator i = classnames.begin(); i != classnames.end(); ++i)
660 if(string_equal(entity->getKeyValue("classname"), *i))
668 class EntityFindByClassnameWalker : public scene::Graph::Walker
670 const Classnames& m_classnames;
672 EntityFindByClassnameWalker(const Classnames& classnames)
673 : m_classnames(classnames)
676 bool pre(const scene::Path& path, scene::Instance& instance) const
678 Entity* entity = Node_getEntity(path.top());
680 && classnames_match_entity(m_classnames, entity))
682 Instance_getSelectable(instance)->setSelected(true);
688 void Scene_EntitySelectByClassnames(scene::Graph& graph, const Classnames& classnames)
690 graph.traverse(EntityFindByClassnameWalker(classnames));
693 class EntityGetSelectedClassnamesWalker : public scene::Graph::Walker
695 Classnames& m_classnames;
697 EntityGetSelectedClassnamesWalker(Classnames& classnames)
698 : m_classnames(classnames)
701 bool pre(const scene::Path& path, scene::Instance& instance) const
703 Selectable* selectable = Instance_getSelectable(instance);
705 && selectable->isSelected())
707 Entity* entity = Node_getEntity(path.top());
710 m_classnames.push_back(entity->getKeyValue("classname"));
717 void Scene_EntityGetClassnames(scene::Graph& graph, Classnames& classnames)
719 graph.traverse(EntityGetSelectedClassnamesWalker(classnames));
722 void Select_AllOfType()
724 if(GlobalSelectionSystem().Mode() == SelectionSystem::eComponent)
726 if(GlobalSelectionSystem().ComponentMode() == SelectionSystem::eFace)
728 GlobalSelectionSystem().setSelectedAllComponents(false);
729 Scene_BrushSelectByShader_Component(GlobalSceneGraph(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
734 Classnames classnames;
735 Scene_EntityGetClassnames(GlobalSceneGraph(), classnames);
736 GlobalSelectionSystem().setSelectedAll(false);
737 if(!classnames.empty())
739 Scene_EntitySelectByClassnames(GlobalSceneGraph(), classnames);
743 Scene_BrushSelectByShader(GlobalSceneGraph(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
744 Scene_PatchSelectByShader(GlobalSceneGraph(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()));
749 void Select_Inside(void)
751 SelectByBounds<SelectionPolicy_Inside>::DoSelection();
754 void Select_Touching(void)
756 SelectByBounds<SelectionPolicy_Touching>::DoSelection(false);
759 void Select_FitTexture(float horizontal, float vertical)
761 if(GlobalSelectionSystem().Mode() != SelectionSystem::eComponent)
763 Scene_BrushFitTexture_Selected(GlobalSceneGraph(), horizontal, vertical);
765 Scene_BrushFitTexture_Component_Selected(GlobalSceneGraph(), horizontal, vertical);
770 inline void hide_node(scene::Node& node, bool hide)
773 ? node.enable(scene::Node::eHidden)
774 : node.disable(scene::Node::eHidden);
777 class HideSelectedWalker : public scene::Graph::Walker
781 HideSelectedWalker(bool hide)
785 bool pre(const scene::Path& path, scene::Instance& instance) const
787 Selectable* selectable = Instance_getSelectable(instance);
789 && selectable->isSelected())
791 hide_node(path.top(), m_hide);
797 void Scene_Hide_Selected(bool hide)
799 GlobalSceneGraph().traverse(HideSelectedWalker(hide));
804 Scene_Hide_Selected(true);
811 GlobalSelectionSystem().setSelectedAll(false);
815 class HideAllWalker : public scene::Graph::Walker
819 HideAllWalker(bool hide)
823 bool pre(const scene::Path& path, scene::Instance& instance) const
825 hide_node(path.top(), m_hide);
830 void Scene_Hide_All(bool hide)
832 GlobalSceneGraph().traverse(HideAllWalker(hide));
835 void Select_ShowAllHidden()
837 Scene_Hide_All(false);
843 void Selection_Flipx()
845 UndoableCommand undo("mirrorSelected -axis x");
849 void Selection_Flipy()
851 UndoableCommand undo("mirrorSelected -axis y");
855 void Selection_Flipz()
857 UndoableCommand undo("mirrorSelected -axis z");
861 void Selection_Rotatex()
863 UndoableCommand undo("rotateSelected -axis x -angle -90");
864 Select_RotateAxis(0,-90);
867 void Selection_Rotatey()
869 UndoableCommand undo("rotateSelected -axis y -angle 90");
870 Select_RotateAxis(1, 90);
873 void Selection_Rotatez()
875 UndoableCommand undo("rotateSelected -axis z -angle -90");
876 Select_RotateAxis(2,-90);
881 void Nudge(int nDim, float fNudge)
883 Vector3 translate(0, 0, 0);
884 translate[nDim] = fNudge;
886 GlobalSelectionSystem().translateSelected(translate);
889 void Selection_NudgeZ(float amount)
891 StringOutputStream command;
892 command << "nudgeSelected -axis z -amount " << amount;
893 UndoableCommand undo(command.c_str());
898 void Selection_MoveDown()
900 Selection_NudgeZ(-GetGridSize());
903 void Selection_MoveUp()
905 Selection_NudgeZ(GetGridSize());
908 void SceneSelectionChange(const Selectable& selectable)
913 SignalHandlerId Selection_boundsChanged;
915 void Selection_construct()
917 typedef FreeCaller1<const Selectable&, SceneSelectionChange> SceneSelectionChangeCaller;
918 GlobalSelectionSystem().addSelectionChangeCallback(SceneSelectionChangeCaller());
919 typedef FreeCaller1<const Selectable&, UpdateWorkzone_ForSelectionChanged> UpdateWorkzoneForSelectionChangedCaller;
920 GlobalSelectionSystem().addSelectionChangeCallback(UpdateWorkzoneForSelectionChangedCaller());
921 typedef FreeCaller<UpdateWorkzone_ForSelection> UpdateWorkzoneForSelectionCaller;
922 Selection_boundsChanged = GlobalSceneGraph().addBoundsChangedCallback(UpdateWorkzoneForSelectionCaller());
925 void Selection_destroy()
927 GlobalSceneGraph().removeBoundsChangedCallback(Selection_boundsChanged);
932 #include <gtk/gtkbox.h>
933 #include <gtk/gtkspinbutton.h>
934 #include <gtk/gtktable.h>
935 #include <gtk/gtklabel.h>
936 #include <gdk/gdkkeysyms.h>
939 inline Quaternion quaternion_for_euler_xyz_degrees(const Vector3& eulerXYZ)
942 return quaternion_for_matrix4_rotation(matrix4_rotation_for_euler_xyz_degrees(eulerXYZ));
944 return quaternion_multiplied_by_quaternion(
945 quaternion_multiplied_by_quaternion(
946 quaternion_for_z(degrees_to_radians(eulerXYZ[2])),
947 quaternion_for_y(degrees_to_radians(eulerXYZ[1]))
949 quaternion_for_x(degrees_to_radians(eulerXYZ[0]))
952 double cx = cos(degrees_to_radians(eulerXYZ[0] * 0.5));
953 double sx = sin(degrees_to_radians(eulerXYZ[0] * 0.5));
954 double cy = cos(degrees_to_radians(eulerXYZ[1] * 0.5));
955 double sy = sin(degrees_to_radians(eulerXYZ[1] * 0.5));
956 double cz = cos(degrees_to_radians(eulerXYZ[2] * 0.5));
957 double sz = sin(degrees_to_radians(eulerXYZ[2] * 0.5));
960 cz * cy * sx - sz * sy * cx,
961 cz * sy * cx + sz * cy * sx,
962 sz * cy * cx - cz * sy * sx,
963 cz * cy * cx + sz * sy * sx
976 static gboolean rotatedlg_apply (GtkWidget *widget, RotateDialog* rotateDialog)
980 eulerXYZ[0] = static_cast<float>(gtk_spin_button_get_value(rotateDialog->x));
981 eulerXYZ[1] = static_cast<float>(gtk_spin_button_get_value(rotateDialog->y));
982 eulerXYZ[2] = static_cast<float>(gtk_spin_button_get_value(rotateDialog->z));
984 StringOutputStream command;
985 command << "rotateSelectedEulerXYZ -x " << eulerXYZ[0] << " -y " << eulerXYZ[1] << " -z " << eulerXYZ[2];
986 UndoableCommand undo(command.c_str());
988 GlobalSelectionSystem().rotateSelected(quaternion_for_euler_xyz_degrees(eulerXYZ));
992 static gboolean rotatedlg_cancel (GtkWidget *widget, RotateDialog* rotateDialog)
994 gtk_widget_hide(GTK_WIDGET(rotateDialog->window));
996 gtk_spin_button_set_value(rotateDialog->x, 0.0f); // reset to 0 on close
997 gtk_spin_button_set_value(rotateDialog->y, 0.0f);
998 gtk_spin_button_set_value(rotateDialog->z, 0.0f);
1003 static gboolean rotatedlg_ok (GtkWidget *widget, RotateDialog* rotateDialog)
1005 rotatedlg_apply(widget, rotateDialog);
1006 rotatedlg_cancel(widget, rotateDialog);
1010 static gboolean rotatedlg_delete (GtkWidget *widget, GdkEventAny *event, RotateDialog* rotateDialog)
1012 rotatedlg_cancel(widget, rotateDialog);
1016 RotateDialog g_rotate_dialog;
1019 if(g_rotate_dialog.window == NULL)
1021 g_rotate_dialog.window = create_dialog_window(MainFrame_getWindow(), "Arbitrary rotation", G_CALLBACK(rotatedlg_delete), &g_rotate_dialog);
1023 GtkAccelGroup* accel = gtk_accel_group_new();
1024 gtk_window_add_accel_group(g_rotate_dialog.window, accel);
1027 GtkHBox* hbox = create_dialog_hbox(4, 4);
1028 gtk_container_add(GTK_CONTAINER(g_rotate_dialog.window), GTK_WIDGET(hbox));
1030 GtkTable* table = create_dialog_table(3, 2, 4, 4);
1031 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(table), TRUE, TRUE, 0);
1033 GtkWidget* label = gtk_label_new (" X ");
1034 gtk_widget_show (label);
1035 gtk_table_attach(table, label, 0, 1, 0, 1,
1036 (GtkAttachOptions) (0),
1037 (GtkAttachOptions) (0), 0, 0);
1040 GtkWidget* label = gtk_label_new (" Y ");
1041 gtk_widget_show (label);
1042 gtk_table_attach(table, label, 0, 1, 1, 2,
1043 (GtkAttachOptions) (0),
1044 (GtkAttachOptions) (0), 0, 0);
1047 GtkWidget* label = gtk_label_new (" Z ");
1048 gtk_widget_show (label);
1049 gtk_table_attach(table, label, 0, 1, 2, 3,
1050 (GtkAttachOptions) (0),
1051 (GtkAttachOptions) (0), 0, 0);
1054 GtkAdjustment* adj = GTK_ADJUSTMENT(gtk_adjustment_new(0, -359, 359, 1, 10, 0));
1055 GtkSpinButton* spin = GTK_SPIN_BUTTON(gtk_spin_button_new(adj, 1, 0));
1056 gtk_widget_show(GTK_WIDGET(spin));
1057 gtk_table_attach(table, GTK_WIDGET(spin), 1, 2, 0, 1,
1058 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1059 (GtkAttachOptions) (0), 0, 0);
1060 gtk_widget_set_size_request(GTK_WIDGET(spin), 64, -1);
1061 gtk_spin_button_set_wrap(spin, TRUE);
1063 gtk_widget_grab_focus(GTK_WIDGET(spin));
1065 g_rotate_dialog.x = spin;
1068 GtkAdjustment* adj = GTK_ADJUSTMENT(gtk_adjustment_new(0, -359, 359, 1, 10, 0));
1069 GtkSpinButton* spin = GTK_SPIN_BUTTON(gtk_spin_button_new(adj, 1, 0));
1070 gtk_widget_show(GTK_WIDGET(spin));
1071 gtk_table_attach(table, GTK_WIDGET(spin), 1, 2, 1, 2,
1072 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1073 (GtkAttachOptions) (0), 0, 0);
1074 gtk_widget_set_size_request(GTK_WIDGET(spin), 64, -1);
1075 gtk_spin_button_set_wrap(spin, TRUE);
1077 g_rotate_dialog.y = spin;
1080 GtkAdjustment* adj = GTK_ADJUSTMENT(gtk_adjustment_new(0, -359, 359, 1, 10, 0));
1081 GtkSpinButton* spin = GTK_SPIN_BUTTON(gtk_spin_button_new(adj, 1, 0));
1082 gtk_widget_show(GTK_WIDGET(spin));
1083 gtk_table_attach(table, GTK_WIDGET(spin), 1, 2, 2, 3,
1084 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1085 (GtkAttachOptions) (0), 0, 0);
1086 gtk_widget_set_size_request(GTK_WIDGET(spin), 64, -1);
1087 gtk_spin_button_set_wrap(spin, TRUE);
1089 g_rotate_dialog.z = spin;
1093 GtkVBox* vbox = create_dialog_vbox(4);
1094 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(vbox), TRUE, TRUE, 0);
1096 GtkButton* button = create_dialog_button("OK", G_CALLBACK(rotatedlg_ok), &g_rotate_dialog);
1097 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1098 widget_make_default(GTK_WIDGET(button));
1099 gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0);
1102 GtkButton* button = create_dialog_button("Cancel", G_CALLBACK(rotatedlg_cancel), &g_rotate_dialog);
1103 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1104 gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0);
1107 GtkButton* button = create_dialog_button("Apply", G_CALLBACK(rotatedlg_apply), &g_rotate_dialog);
1108 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1114 gtk_widget_show(GTK_WIDGET(g_rotate_dialog.window));
1133 static gboolean scaledlg_apply (GtkWidget *widget, ScaleDialog* scaleDialog)
1137 sx = static_cast<float>(atof(gtk_entry_get_text (GTK_ENTRY (scaleDialog->x))));
1138 sy = static_cast<float>(atof(gtk_entry_get_text (GTK_ENTRY (scaleDialog->y))));
1139 sz = static_cast<float>(atof(gtk_entry_get_text (GTK_ENTRY (scaleDialog->z))));
1141 StringOutputStream command;
1142 command << "scaleSelected -x " << sx << " -y " << sy << " -z " << sz;
1143 UndoableCommand undo(command.c_str());
1145 Select_Scale(sx, sy, sz);
1150 static gboolean scaledlg_cancel (GtkWidget *widget, ScaleDialog* scaleDialog)
1152 gtk_widget_hide(GTK_WIDGET(scaleDialog->window));
1154 gtk_entry_set_text (GTK_ENTRY(scaleDialog->x), "1.0");
1155 gtk_entry_set_text (GTK_ENTRY(scaleDialog->y), "1.0");
1156 gtk_entry_set_text (GTK_ENTRY(scaleDialog->z), "1.0");
1161 static gboolean scaledlg_ok (GtkWidget *widget, ScaleDialog* scaleDialog)
1163 scaledlg_apply(widget, scaleDialog);
1164 scaledlg_cancel(widget, scaleDialog);
1168 static gboolean scaledlg_delete (GtkWidget *widget, GdkEventAny *event, ScaleDialog* scaleDialog)
1170 scaledlg_cancel(widget, scaleDialog);
1174 ScaleDialog g_scale_dialog;
1178 if(g_scale_dialog.window == NULL)
1180 g_scale_dialog.window = create_dialog_window(MainFrame_getWindow(), "Arbitrary scale", G_CALLBACK(scaledlg_delete), &g_scale_dialog);
1182 GtkAccelGroup* accel = gtk_accel_group_new();
1183 gtk_window_add_accel_group(g_scale_dialog.window, accel);
1186 GtkHBox* hbox = create_dialog_hbox(4, 4);
1187 gtk_container_add(GTK_CONTAINER(g_scale_dialog.window), GTK_WIDGET(hbox));
1189 GtkTable* table = create_dialog_table(3, 2, 4, 4);
1190 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(table), TRUE, TRUE, 0);
1192 GtkWidget* label = gtk_label_new (" X ");
1193 gtk_widget_show (label);
1194 gtk_table_attach(table, label, 0, 1, 0, 1,
1195 (GtkAttachOptions) (0),
1196 (GtkAttachOptions) (0), 0, 0);
1199 GtkWidget* label = gtk_label_new (" Y ");
1200 gtk_widget_show (label);
1201 gtk_table_attach(table, label, 0, 1, 1, 2,
1202 (GtkAttachOptions) (0),
1203 (GtkAttachOptions) (0), 0, 0);
1206 GtkWidget* label = gtk_label_new (" Z ");
1207 gtk_widget_show (label);
1208 gtk_table_attach(table, label, 0, 1, 2, 3,
1209 (GtkAttachOptions) (0),
1210 (GtkAttachOptions) (0), 0, 0);
1213 GtkWidget* entry = gtk_entry_new();
1214 gtk_entry_set_text (GTK_ENTRY(entry), "1.0");
1215 gtk_widget_show (entry);
1216 gtk_table_attach(table, entry, 1, 2, 0, 1,
1217 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1218 (GtkAttachOptions) (0), 0, 0);
1220 g_scale_dialog.x = entry;
1223 GtkWidget* entry = gtk_entry_new();
1224 gtk_entry_set_text (GTK_ENTRY(entry), "1.0");
1225 gtk_widget_show (entry);
1226 gtk_table_attach(table, entry, 1, 2, 1, 2,
1227 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1228 (GtkAttachOptions) (0), 0, 0);
1230 g_scale_dialog.y = entry;
1233 GtkWidget* entry = gtk_entry_new();
1234 gtk_entry_set_text (GTK_ENTRY(entry), "1.0");
1235 gtk_widget_show (entry);
1236 gtk_table_attach(table, entry, 1, 2, 2, 3,
1237 (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
1238 (GtkAttachOptions) (0), 0, 0);
1240 g_scale_dialog.z = entry;
1244 GtkVBox* vbox = create_dialog_vbox(4);
1245 gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(vbox), TRUE, TRUE, 0);
1247 GtkButton* button = create_dialog_button("OK", G_CALLBACK(scaledlg_ok), &g_scale_dialog);
1248 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1249 widget_make_default(GTK_WIDGET(button));
1250 gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Return, (GdkModifierType)0, (GtkAccelFlags)0);
1253 GtkButton* button = create_dialog_button("Cancel", G_CALLBACK(scaledlg_cancel), &g_scale_dialog);
1254 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1255 gtk_widget_add_accelerator(GTK_WIDGET(button), "clicked", accel, GDK_Escape, (GdkModifierType)0, (GtkAccelFlags)0);
1258 GtkButton* button = create_dialog_button("Apply", G_CALLBACK(scaledlg_apply), &g_scale_dialog);
1259 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(button), FALSE, FALSE, 0);
1265 gtk_widget_show(GTK_WIDGET(g_scale_dialog.window));