diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2017-09-17 12:44:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-17 12:44:36 +0200 |
commit | 53990c7bb9377982a0dc5aaae7a75f046189c9bc (patch) | |
tree | 7258fe9725a1dbbfba10246c914bebdd42bf0d9a | |
parent | 2db9973ad4f363cac9848ffa65f6a78b6c2814b4 (diff) | |
parent | d9b68c5f5d391f9e45a5a8cb92aa44dcec164c54 (diff) |
Merge pull request #11196 from poke1024/canvas-old-rect
Adds display of old bounding box as suggested by Zephilinox in issue …
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.cpp | 22 | ||||
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.h | 2 |
2 files changed, 24 insertions, 0 deletions
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<Node2D>(canvas_item)->edit_get_pivot(); if (Object::cast_to<Control>(canvas_item)) se->undo_pivot = Object::cast_to<Control>(canvas_item)->get_pivot_offset(); + + se->pre_drag_xform = canvas_item->get_global_transform_with_canvas(); } if (selection.size() == 1 && Object::cast_to<Node2D>(selection[0])) { @@ -1411,6 +1413,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) { se->undo_pivot = Object::cast_to<Node2D>(canvas_item)->edit_get_pivot(); if (Object::cast_to<Control>(canvas_item)) se->undo_pivot = Object::cast_to<Control>(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<InputEvent> &p_event) { se->undo_pivot = Object::cast_to<Node2D>(canvas_item)->edit_get_pivot(); if (Object::cast_to<Control>(canvas_item)) se->undo_pivot = Object::cast_to<Control>(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<InputEvent> &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; } }; |