From d9b68c5f5d391f9e45a5a8cb92aa44dcec164c54 Mon Sep 17 00:00:00 2001 From: poke1024 Date: Tue, 12 Sep 2017 19:11:53 +0200 Subject: adds display of old bounding box as suggested by Zephilinox in issue #10936 --- editor/plugins/canvas_item_editor_plugin.cpp | 22 ++++++++++++++++++++++ editor/plugins/canvas_item_editor_plugin.h | 2 ++ 2 files changed, 24 insertions(+) (limited to 'editor/plugins') diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index ad01d0a31e..b28da54c6d 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -845,6 +845,8 @@ void CanvasItemEditor::_prepare_drag(const Point2 &p_click_pos) { se->undo_pivot = Object::cast_to(canvas_item)->edit_get_pivot(); if (Object::cast_to(canvas_item)) se->undo_pivot = Object::cast_to(canvas_item)->get_pivot_offset(); + + se->pre_drag_xform = canvas_item->get_global_transform_with_canvas(); } if (selection.size() == 1 && Object::cast_to(selection[0])) { @@ -1411,6 +1413,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref &p_event) { se->undo_pivot = Object::cast_to(canvas_item)->edit_get_pivot(); if (Object::cast_to(canvas_item)) se->undo_pivot = Object::cast_to(canvas_item)->get_pivot_offset(); + se->pre_drag_xform = canvas_item->get_global_transform_with_canvas(); return; } @@ -1432,6 +1435,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref &p_event) { se->undo_pivot = Object::cast_to(canvas_item)->edit_get_pivot(); if (Object::cast_to(canvas_item)) se->undo_pivot = Object::cast_to(canvas_item)->get_pivot_offset(); + se->pre_drag_xform = canvas_item->get_global_transform_with_canvas(); return; } @@ -1441,6 +1445,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref &p_event) { if (drag != DRAG_NONE) { drag_from = transform.affine_inverse().xform(click); se->undo_state = canvas_item->edit_get_state(); + se->pre_drag_xform = canvas_item->get_global_transform_with_canvas(); return; } } @@ -1993,6 +1998,23 @@ void CanvasItemEditor::_viewport_draw() { Rect2 rect = canvas_item->get_item_rect(); + if (drag != DRAG_NONE && drag != DRAG_PIVOT) { + const Transform2D pre_drag_xform = transform * se->pre_drag_xform; + const Color pre_drag_color = Color(0.4, 0.6, 1, 0.7); + + Vector2 pre_drag_endpoints[4] = { + + pre_drag_xform.xform(rect.position), + pre_drag_xform.xform(rect.position + Vector2(rect.size.x, 0)), + pre_drag_xform.xform(rect.position + rect.size), + pre_drag_xform.xform(rect.position + Vector2(0, rect.size.y)) + }; + + for (int i = 0; i < 4; i++) { + viewport->draw_line(pre_drag_endpoints[i], pre_drag_endpoints[(i + 1) % 4], pre_drag_color, 2); + } + } + Transform2D xform = transform * canvas_item->get_global_transform_with_canvas(); VisualServer::get_singleton()->canvas_item_add_set_transform(ci, xform); diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index 2e1a2eac5f..e81988668b 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -58,6 +58,8 @@ public: Vector2 prev_pivot; float prev_anchors[4]; + Transform2D pre_drag_xform; + CanvasItemEditorSelectedItem() { prev_rot = 0; } }; -- cgit v1.2.3