From 78ff81ffa80c5740715df823052ea39affb7d86b Mon Sep 17 00:00:00 2001 From: RustyStriker <61246040+RustyStriker@users.noreply.github.com> Date: Sun, 9 May 2021 10:23:13 +0300 Subject: [PATCH] Fix rect/hexagon not centering properly when holding alt (#121) --- core/editor/src/tools/rectangle.rs | 9 ++++++++- core/editor/src/tools/shape.rs | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/core/editor/src/tools/rectangle.rs b/core/editor/src/tools/rectangle.rs index 3bc4e2612..3be9b3b28 100644 --- a/core/editor/src/tools/rectangle.rs +++ b/core/editor/src/tools/rectangle.rs @@ -143,7 +143,14 @@ fn make_operation(data: &RectangleToolData, tool_data: &DocumentToolData) -> Ope (x0, y0, x0 + max_dist * x_dir, y0 + max_dist * y_dir) } } else { - let (x0, y0) = if data.center_around_cursor { (x0 - 2.0 * (x1 - x0), y0 - 2.0 * (y1 - y0)) } else { (x0, y0) }; + let (x0, y0) = if data.center_around_cursor { + let delta_x = x1 - x0; + let delta_y = y1 - y0; + + (x0 - delta_x, y0 - delta_y) + } else { + (x0, y0) + }; (x0, y0, x1, y1) }; diff --git a/core/editor/src/tools/shape.rs b/core/editor/src/tools/shape.rs index dddfb09ec..4f6d232bb 100644 --- a/core/editor/src/tools/shape.rs +++ b/core/editor/src/tools/shape.rs @@ -145,7 +145,14 @@ fn make_operation(data: &ShapeToolData, tool_data: &DocumentToolData) -> Operati (x0, y0, x0 + max_dist * x_dir, y0 + max_dist * y_dir) } } else { - let (x0, y0) = if data.center_around_cursor { (x0 - 2.0 * (x1 - x0), y0 - 2.0 * (y1 - y0)) } else { (x0, y0) }; + let (x0, y0) = if data.center_around_cursor { + let delta_x = x1 - x0; + let delta_y = y1 - y0; + + (x0 - delta_x, y0 - delta_y) + } else { + (x0, y0) + }; (x0, y0, x1, y1) };