summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGilles Roudiere <gilles.roudiere@gmail.com>2017-08-31 23:27:05 +0200
committerGilles Roudiere <gilles.roudiere@gmail.com>2017-09-17 23:19:05 +0200
commit7c24a26bc29df3e4746d092690d2e8f577a312ac (patch)
tree9e764bd08f2cd55186b6ed7a8eed3549f3de7dad
parentbf6d7add01d3139b39a152bba2dc6727b20d304c (diff)
Use shift to move anchors on a single axis
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp68
1 files changed, 42 insertions, 26 deletions
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index b55c6ea11d..c9e2fdb06a 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -1611,6 +1611,36 @@ void CanvasItemEditor::_viewport_base_gui_input(const Ref<InputEvent> &p_event)
continue;
}
+ bool uniform = m->get_shift();
+ bool symmetric = m->get_alt();
+
+ switch (drag) {
+ case DRAG_ALL:
+ case DRAG_NODE_2D:
+ dto -= drag_from - drag_point_from;
+ if (uniform) {
+ if (ABS(dto.x - drag_point_from.x) > ABS(dto.y - drag_point_from.y)) {
+ dto.y = drag_point_from.y;
+ } else {
+ dto.x = drag_point_from.x;
+ }
+ }
+ break;
+ case DRAG_ANCHOR_TOP_LEFT:
+ case DRAG_ANCHOR_TOP_RIGHT:
+ case DRAG_ANCHOR_BOTTOM_RIGHT:
+ case DRAG_ANCHOR_BOTTOM_LEFT:
+ case DRAG_ANCHOR_ALL:
+ if (uniform) {
+ if (ABS(dto.x - drag_from.x) > ABS(dto.y - drag_from.y)) {
+ dto.y = drag_from.y;
+ } else {
+ dto.x = drag_from.x;
+ }
+ }
+ break;
+ }
+
Control *control = Object::cast_to<Control>(canvas_item);
if (control) {
// Drag and snap the anchor
@@ -1618,49 +1648,35 @@ void CanvasItemEditor::_viewport_base_gui_input(const Ref<InputEvent> &p_event)
switch (drag) {
case DRAG_ANCHOR_TOP_LEFT:
- control->set_anchor(MARGIN_LEFT, _anchor_snap(anchor.x, NULL, control->get_anchor(MARGIN_RIGHT)), false, false);
- control->set_anchor(MARGIN_TOP, _anchor_snap(anchor.y, NULL, control->get_anchor(MARGIN_BOTTOM)), false, false);
+ control->set_anchor(MARGIN_LEFT, (uniform) ? anchor.x : _anchor_snap(anchor.x, NULL, control->get_anchor(MARGIN_RIGHT)), false, false);
+ control->set_anchor(MARGIN_TOP, (uniform) ? anchor.y : _anchor_snap(anchor.y, NULL, control->get_anchor(MARGIN_BOTTOM)), false, false);
continue;
break;
case DRAG_ANCHOR_TOP_RIGHT:
- control->set_anchor(MARGIN_RIGHT, _anchor_snap(anchor.x, NULL, control->get_anchor(MARGIN_LEFT)), false, false);
- control->set_anchor(MARGIN_TOP, _anchor_snap(anchor.y, NULL, control->get_anchor(MARGIN_BOTTOM)), false, false);
+ control->set_anchor(MARGIN_RIGHT, (uniform) ? anchor.x : _anchor_snap(anchor.x, NULL, control->get_anchor(MARGIN_LEFT)), false, false);
+ control->set_anchor(MARGIN_TOP, (uniform) ? anchor.y : _anchor_snap(anchor.y, NULL, control->get_anchor(MARGIN_BOTTOM)), false, false);
continue;
break;
case DRAG_ANCHOR_BOTTOM_RIGHT:
- control->set_anchor(MARGIN_RIGHT, _anchor_snap(anchor.x, NULL, control->get_anchor(MARGIN_LEFT)), false, false);
- control->set_anchor(MARGIN_BOTTOM, _anchor_snap(anchor.y, NULL, control->get_anchor(MARGIN_TOP)), false, false);
+ control->set_anchor(MARGIN_RIGHT, (uniform) ? anchor.x : _anchor_snap(anchor.x, NULL, control->get_anchor(MARGIN_LEFT)), false, false);
+ control->set_anchor(MARGIN_BOTTOM, (uniform) ? anchor.y : _anchor_snap(anchor.y, NULL, control->get_anchor(MARGIN_TOP)), false, false);
continue;
break;
case DRAG_ANCHOR_BOTTOM_LEFT:
- control->set_anchor(MARGIN_LEFT, _anchor_snap(anchor.x, NULL, control->get_anchor(MARGIN_RIGHT)), false, false);
- control->set_anchor(MARGIN_BOTTOM, _anchor_snap(anchor.y, NULL, control->get_anchor(MARGIN_TOP)), false, false);
+ control->set_anchor(MARGIN_LEFT, (uniform) ? anchor.x : _anchor_snap(anchor.x, NULL, control->get_anchor(MARGIN_RIGHT)), false, false);
+ control->set_anchor(MARGIN_BOTTOM, (uniform) ? anchor.y : _anchor_snap(anchor.y, NULL, control->get_anchor(MARGIN_TOP)), false, false);
continue;
break;
case DRAG_ANCHOR_ALL:
- control->set_anchor(MARGIN_LEFT, _anchor_snap(anchor.x));
- control->set_anchor(MARGIN_RIGHT, _anchor_snap(anchor.x));
- control->set_anchor(MARGIN_TOP, _anchor_snap(anchor.y));
- control->set_anchor(MARGIN_BOTTOM, _anchor_snap(anchor.y));
+ control->set_anchor(MARGIN_LEFT, (uniform) ? anchor.x : _anchor_snap(anchor.x));
+ control->set_anchor(MARGIN_RIGHT, (uniform) ? anchor.x : _anchor_snap(anchor.x));
+ control->set_anchor(MARGIN_TOP, (uniform) ? anchor.y : _anchor_snap(anchor.y));
+ control->set_anchor(MARGIN_BOTTOM, (uniform) ? anchor.y : _anchor_snap(anchor.y));
continue;
break;
}
}
- bool uniform = m->get_shift();
- bool symmetric = m->get_alt();
-
- if (drag == DRAG_ALL || drag == DRAG_NODE_2D)
- dto -= drag_from - drag_point_from;
-
- if (uniform && (drag == DRAG_ALL || drag == DRAG_NODE_2D)) {
- if (ABS(dto.x - drag_point_from.x) > ABS(dto.y - drag_point_from.y)) {
- dto.y = drag_point_from.y;
- } else {
- dto.x = drag_point_from.x;
- }
- }
-
dfrom = drag_point_from;
dto = snap_point(dto, drag_point_from);