From 795cba2d73677995f98cde3b4d8cea10c17f81fd Mon Sep 17 00:00:00 2001 From: Marcus Elg Date: Sun, 12 Apr 2020 11:19:19 +0200 Subject: Relative scale snapping 2D --- editor/plugins/canvas_item_editor_plugin.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 2f7747d0ff..43a88a32c8 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -1919,6 +1919,7 @@ bool CanvasItemEditor::_gui_input_scale(const Ref &p_event) { Point2 offset = drag_to_local - drag_from_local; Size2 scale = canvas_item->call("get_scale"); + Size2 original_scale = scale; float ratio = scale.y / scale.x; if (drag_type == DRAG_SCALE_BOTH) { Size2 scale_factor = drag_to_local / drag_from_local; @@ -1931,6 +1932,7 @@ bool CanvasItemEditor::_gui_input_scale(const Ref &p_event) { Size2 scale_factor = Vector2(offset.x, -offset.y) / SCALE_HANDLE_DISTANCE; Size2 parent_scale = parent_xform.get_scale(); scale_factor *= Vector2(1.0 / parent_scale.x, 1.0 / parent_scale.y); + if (drag_type == DRAG_SCALE_X) { scale.x += scale_factor.x; if (uniform) { @@ -1945,8 +1947,13 @@ bool CanvasItemEditor::_gui_input_scale(const Ref &p_event) { } if (snap_scale && !is_ctrl) { - scale.x = roundf(scale.x / snap_scale_step) * snap_scale_step; - scale.y = roundf(scale.y / snap_scale_step) * snap_scale_step; + if (snap_relative) { + scale.x = original_scale.x * (roundf((scale.x / original_scale.x) / snap_scale_step) * snap_scale_step); + scale.y = original_scale.y * (roundf((scale.y / original_scale.y) / snap_scale_step) * snap_scale_step); + } else { + scale.x = roundf(scale.x / snap_scale_step) * snap_scale_step; + scale.y = roundf(scale.y / snap_scale_step) * snap_scale_step; + } } canvas_item->call("set_scale", scale); -- cgit v1.2.3