From 363b2db695214d4c7ada56b54273b8cf7d6739a7 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 22 Aug 2019 23:07:01 +0200 Subject: [PATCH] :sparkles: Improve initial shape drawing impl. --- .../src/uxbox/main/ui/workspace/drawarea.cljs | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/frontend/src/uxbox/main/ui/workspace/drawarea.cljs b/frontend/src/uxbox/main/ui/workspace/drawarea.cljs index a49660a3b..d2b24df18 100644 --- a/frontend/src/uxbox/main/ui/workspace/drawarea.cljs +++ b/frontend/src/uxbox/main/ui/workspace/drawarea.cljs @@ -118,24 +118,13 @@ :y2 (+ (:y point) 2)})] (assoc-in state [:workspace pid :drawing] (assoc shape ::initialized? true)))) - ;; NOTE: this is a new approach for resizing, when all the - ;; subsystem are migrated to the new resize approach, this - ;; function should be moved into uxbox.main.geom ns. (resize-shape [shape point lock?] - (if (= (:type shape) :circle) - (let [rx (mth/abs (- (:x point) (:cx shape))) - ry (mth/abs (- (:y point) (:cy shape)))] - (if lock? - (assoc shape :rx rx :ry ry) - (assoc shape :rx rx :ry rx))) - (let [width (- (:x point) (:x1 shape)) - height (- (:y point) (:y1 shape)) - proportion (:proportion shape 1)] - (assoc shape - :x2 (+ (:x1 shape) width) - :y2 (if lock? - (+ (:y1 shape) (/ width proportion)) - (+ (:y1 shape) height)))))) + (let [shape (-> (geom/shape->rect-shape shape) + (geom/size)) + result (geom/resize-shape :bottom-right shape point lock?) + scale (geom/calculate-scale-ratio shape result) + mtx (geom/generate-resize-matrix :bottom-right shape scale)] + (assoc shape :modifier-mtx mtx))) (update-drawing [state point lock?] (let [pid (get-in state [:workspace :current])]