From 4ce0b50c04b9a83d19b015f3c7412b3c68b2051b Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 28 Feb 2017 18:44:35 +0100 Subject: [PATCH] Fix proportion locking mode on drawing shape. Fixes issue #61 --- .../src/uxbox/main/data/workspace/drawing.cljs | 16 ++++++++-------- frontend/src/uxbox/main/geom.cljs | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/frontend/src/uxbox/main/data/workspace/drawing.cljs b/frontend/src/uxbox/main/data/workspace/drawing.cljs index 363ed8917..a5a8ecaea 100644 --- a/frontend/src/uxbox/main/data/workspace/drawing.cljs +++ b/frontend/src/uxbox/main/data/workspace/drawing.cljs @@ -92,8 +92,8 @@ (let [shape (get-in state [:workspace :drawing]) shape (geom/setup shape {:x1 (:x point) :y1 (:y point) - :x2 (inc (:x point)) - :y2 (inc (:y point))})] + :x2 (+ (:x point) 2) + :y2 (+ (:y point) 2)})] (assoc-in state [:workspace :drawing] shape)))) (defn initialize-drawing @@ -103,21 +103,21 @@ ;; --- Update Draw Area State -(deftype UpdateDrawing [position] +(deftype UpdateDrawing [position lock?] ptk/UpdateEvent (update [_ state] (let [{:keys [id] :as shape} (-> (get-in state [:workspace :drawing]) (geom/shape->rect-shape) (geom/size)) - result (geom/resize-shape :bottom-right shape position false) + result (geom/resize-shape :bottom-right shape position lock?) scale (geom/calculate-scale-ratio shape result) resize-mtx (geom/generate-resize-matrix :bottom-right shape scale)] (assoc-in state [:workspace :modifiers id] {:resize resize-mtx})))) (defn update-drawing - [position] - {:pre [(gpt/point? position)]} - (UpdateDrawing. position)) + [position lock?] + {:pre [(gpt/point? position) (boolean? lock?)]} + (UpdateDrawing. position lock?)) ;; --- Finish Drawin @@ -261,7 +261,7 @@ (do (st/emit! (initialize-drawing point)) (vreset! start? false)) - (st/emit! (update-drawing (assoc point :lock ctrl?))))) + (st/emit! (update-drawing point ctrl?)))) (on-finish [] (if @start? diff --git a/frontend/src/uxbox/main/geom.cljs b/frontend/src/uxbox/main/geom.cljs index c0c5526ad..21287c907 100644 --- a/frontend/src/uxbox/main/geom.cljs +++ b/frontend/src/uxbox/main/geom.cljs @@ -342,7 +342,7 @@ :top-left (let [width (- (:x2 shape) x) height (- (:y2 shape) y) - proportion (:proportion shape)] + proportion (:proportion shape 1)] (assoc shape :width width :height (if lock? (/ width proportion) height))) @@ -350,7 +350,7 @@ :top-right (let [width (- x (:x1 shape)) height (- (:y2 shape) y) - proportion (:proportion shape)] + proportion (:proportion shape 1)] (assoc shape :width width :height (if lock? (/ width proportion) height))) @@ -358,7 +358,7 @@ :top (let [width (- (:x2 shape) (:x1 shape)) height (- (:y2 shape) y) - proportion (:proportion shape)] + proportion (:proportion shape 1)] (assoc shape :width width :height (if lock? (/ width proportion) height))) @@ -366,7 +366,7 @@ :bottom-left (let [width (- (:x2 shape) x) height (- y (:y1 shape)) - proportion (:proportion shape)] + proportion (:proportion shape 1)] (assoc shape :width width :height (if lock? (/ width proportion) height))) @@ -374,7 +374,7 @@ :bottom-right (let [width (- x (:x1 shape)) height (- y (:y1 shape)) - proportion (:proportion shape)] + proportion (:proportion shape 1)] (assoc shape :width width :height (if lock? (/ width proportion) height))) @@ -382,7 +382,7 @@ :bottom (let [width (- (:x2 shape) (:x1 shape)) height (- y (:y1 shape)) - proportion (:proportion shape)] + proportion (:proportion shape 1)] (assoc shape :width width :height (if lock? (/ width proportion) height))) @@ -390,7 +390,7 @@ :left (let [width (- (:x2 shape) x) height (- (:y2 shape) (:y1 shape)) - proportion (:proportion shape)] + proportion (:proportion shape 1)] (assoc shape :width width :height (if lock? (/ width proportion) height))) @@ -398,7 +398,7 @@ :right (let [width (- x (:x1 shape)) height (- (:y2 shape) (:y1 shape)) - proportion (:proportion shape)] + proportion (:proportion shape 1)] (assoc shape :width width :height (if lock? (/ width proportion) height)))))