From 32502a4b68817886c9ad193b3c4d317555eafa80 Mon Sep 17 00:00:00 2001 From: Gilles Roudiere Date: Sun, 29 Oct 2017 22:00:03 +0100 Subject: Fixes keybord directionnal keys not moving nodes in the 2D editor --- editor/plugins/canvas_item_editor_plugin.cpp | 52 ++++++++++++++-------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'editor') diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 5782edd321..22c81a3b61 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -1205,6 +1205,32 @@ void CanvasItemEditor::_gui_input_viewport_base(const Ref &p_event) if (!viewport_base->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field())) viewport_base->call_deferred("grab_focus"); } + + Ref k = p_event; + if (k.is_valid()) { + if (k->is_pressed() && drag == DRAG_NONE) { + // Move the object with the arrow keys + KeyMoveMODE move_mode = MOVE_VIEW_BASE; + if (k->get_alt()) move_mode = MOVE_LOCAL_BASE; + if (k->get_control() || k->get_metakey()) move_mode = MOVE_LOCAL_WITH_ROT; + + if (k->get_scancode() == KEY_UP) + _key_move(Vector2(0, -1), k->get_shift(), move_mode); + else if (k->get_scancode() == KEY_DOWN) + _key_move(Vector2(0, 1), k->get_shift(), move_mode); + else if (k->get_scancode() == KEY_LEFT) + _key_move(Vector2(-1, 0), k->get_shift(), move_mode); + else if (k->get_scancode() == KEY_RIGHT) + _key_move(Vector2(1, 0), k->get_shift(), move_mode); + else if (k->get_scancode() == KEY_ESCAPE) { + editor_selection->clear(); + viewport->update(); + } else + return; + + accept_event(); + } + } } void CanvasItemEditor::_gui_input_viewport(const Ref &p_event) { @@ -2001,32 +2027,6 @@ void CanvasItemEditor::_gui_input_viewport(const Ref &p_event) { } } } - - Ref k = p_event; - if (k.is_valid()) { - if (k->is_pressed() && drag == DRAG_NONE) { - // Move the object with the arrow keys - KeyMoveMODE move_mode = MOVE_VIEW_BASE; - if (k->get_alt()) move_mode = MOVE_LOCAL_BASE; - if (k->get_control() || k->get_metakey()) move_mode = MOVE_LOCAL_WITH_ROT; - - if (k->get_scancode() == KEY_UP) - _key_move(Vector2(0, -1), k->get_shift(), move_mode); - else if (k->get_scancode() == KEY_DOWN) - _key_move(Vector2(0, 1), k->get_shift(), move_mode); - else if (k->get_scancode() == KEY_LEFT) - _key_move(Vector2(-1, 0), k->get_shift(), move_mode); - else if (k->get_scancode() == KEY_RIGHT) - _key_move(Vector2(1, 0), k->get_shift(), move_mode); - else if (k->get_scancode() == KEY_ESCAPE) { - editor_selection->clear(); - viewport->update(); - } else - return; - - accept_event(); - } - } } void CanvasItemEditor::_draw_text_at_position(Point2 p_position, String p_string, Margin p_side) { -- cgit v1.2.3