summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/editor/plugins/canvas_item_editor_plugin.cpp49
-rw-r--r--tools/editor/plugins/canvas_item_editor_plugin.h8
2 files changed, 41 insertions, 16 deletions
diff --git a/tools/editor/plugins/canvas_item_editor_plugin.cpp b/tools/editor/plugins/canvas_item_editor_plugin.cpp
index f38ac167be..01ca5a1135 100644
--- a/tools/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/tools/editor/plugins/canvas_item_editor_plugin.cpp
@@ -270,7 +270,7 @@ void CanvasItemEditor::_find_canvas_items_at_rect(const Rect2& p_rect,Node* p_no
}
-void CanvasItemEditor::_key_move(const Vector2& p_dir, bool p_snap) {
+void CanvasItemEditor::_key_move(const Vector2& p_dir, bool p_snap, KeyMoveMODE p_move_mode) {
if (drag!=DRAG_NONE)
@@ -298,18 +298,36 @@ void CanvasItemEditor::_key_move(const Vector2& p_dir, bool p_snap) {
continue;
- Vector2 drag = transform.affine_inverse().basis_xform(p_dir);
- drag = canvas_item->get_global_transform_with_canvas().affine_inverse().basis_xform(drag);
-
+ Vector2 drag = p_dir;
if (p_snap)
drag*=snap;
undo_redo->add_undo_method(canvas_item,"edit_set_state",canvas_item->edit_get_state());
- Rect2 local_rect = canvas_item->get_item_rect();
- local_rect.pos+=drag;
- //canvas_item->edit_set_rect(local_rect);
- undo_redo->add_do_method(canvas_item,"edit_set_rect",local_rect);
+ if (p_move_mode == MOVE_VIEW_BASE) {
+
+ // drag = transform.affine_inverse().basis_xform(p_dir); // zoom sensitive
+ drag = canvas_item->get_global_transform_with_canvas().affine_inverse().basis_xform(drag);
+ Rect2 local_rect = canvas_item->get_item_rect();
+ local_rect.pos+=drag;
+ undo_redo->add_do_method(canvas_item,"edit_set_rect",local_rect);
+
+ } else { // p_move_mode==MOVE_LOCAL_BASE || p_move_mode==MOVE_LOCAL_WITH_ROT
+
+ if (Node2D *node_2d = canvas_item->cast_to<Node2D>()) {
+
+ if (p_move_mode == MOVE_LOCAL_WITH_ROT) {
+ Matrix32 m;
+ m.rotate( node_2d->get_rot() );
+ drag = m.xform(drag);
+ }
+ node_2d->set_pos(node_2d->get_pos() + drag);
+
+ } else if (Control *control = canvas_item->cast_to<Control>()) {
+
+ control->set_pos(control->get_pos()+drag);
+ }
+ }
}
undo_redo->commit_action();
@@ -1113,19 +1131,20 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) {
const InputEventKey &k=p_event.key;
- if (p_event.key.mod.alt || p_event.key.mod.control || p_event.key.mod.meta)
- return;
-
if (k.pressed && drag==DRAG_NONE) {
+ KeyMoveMODE move_mode = MOVE_VIEW_BASE;
+ if (k.mod.alt) move_mode = MOVE_LOCAL_BASE;
+ if (k.mod.control || k.mod.meta) move_mode = MOVE_LOCAL_WITH_ROT;
+
if (k.scancode==KEY_UP)
- _key_move(Vector2(0,-1),k.mod.shift);
+ _key_move( Vector2(0,-1), k.mod.shift, move_mode );
else if (k.scancode==KEY_DOWN)
- _key_move(Vector2(0,1),k.mod.shift);
+ _key_move( Vector2(0,1), k.mod.shift, move_mode );
else if (k.scancode==KEY_LEFT)
- _key_move(Vector2(-1,0),k.mod.shift);
+ _key_move( Vector2(-1,0), k.mod.shift, move_mode );
else if (k.scancode==KEY_RIGHT)
- _key_move(Vector2(1,0),k.mod.shift);
+ _key_move( Vector2(1,0), k.mod.shift, move_mode );
else if (k.scancode==KEY_ESCAPE) {
editor_selection->clear();
viewport->update();
diff --git a/tools/editor/plugins/canvas_item_editor_plugin.h b/tools/editor/plugins/canvas_item_editor_plugin.h
index 488fe67584..256847e8ef 100644
--- a/tools/editor/plugins/canvas_item_editor_plugin.h
+++ b/tools/editor/plugins/canvas_item_editor_plugin.h
@@ -122,6 +122,12 @@ class CanvasItemEditor : public VBoxContainer {
};
+ enum KeyMoveMODE {
+ MOVE_VIEW_BASE,
+ MOVE_LOCAL_BASE,
+ MOVE_LOCAL_WITH_ROT
+ };
+
EditorSelection *editor_selection;
Tool tool;
@@ -220,7 +226,7 @@ class CanvasItemEditor : public VBoxContainer {
void _remove_canvas_item(CanvasItem *p_canvas_item);
void _clear_canvas_items();
void _visibility_changed(ObjectID p_canvas_item);
- void _key_move(const Vector2& p_dir, bool p_snap);
+ void _key_move(const Vector2& p_dir, bool p_snap, KeyMoveMODE p_move_mode);
DragType _find_drag_type(const Matrix32& p_xform, const Rect2& p_local_rect, const Point2& p_click, Vector2& r_point);