Fix proportion locking mode on drawing shape.

Fixes issue #61
This commit is contained in:
Andrey Antukh 2017-02-28 18:44:35 +01:00
parent 9238a76156
commit 4ce0b50c04
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
2 changed files with 16 additions and 16 deletions

View file

@ -92,8 +92,8 @@
(let [shape (get-in state [:workspace :drawing]) (let [shape (get-in state [:workspace :drawing])
shape (geom/setup shape {:x1 (:x point) shape (geom/setup shape {:x1 (:x point)
:y1 (:y point) :y1 (:y point)
:x2 (inc (:x point)) :x2 (+ (:x point) 2)
:y2 (inc (:y point))})] :y2 (+ (:y point) 2)})]
(assoc-in state [:workspace :drawing] shape)))) (assoc-in state [:workspace :drawing] shape))))
(defn initialize-drawing (defn initialize-drawing
@ -103,21 +103,21 @@
;; --- Update Draw Area State ;; --- Update Draw Area State
(deftype UpdateDrawing [position] (deftype UpdateDrawing [position lock?]
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(let [{:keys [id] :as shape} (-> (get-in state [:workspace :drawing]) (let [{:keys [id] :as shape} (-> (get-in state [:workspace :drawing])
(geom/shape->rect-shape) (geom/shape->rect-shape)
(geom/size)) (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) scale (geom/calculate-scale-ratio shape result)
resize-mtx (geom/generate-resize-matrix :bottom-right shape scale)] resize-mtx (geom/generate-resize-matrix :bottom-right shape scale)]
(assoc-in state [:workspace :modifiers id] {:resize resize-mtx})))) (assoc-in state [:workspace :modifiers id] {:resize resize-mtx}))))
(defn update-drawing (defn update-drawing
[position] [position lock?]
{:pre [(gpt/point? position)]} {:pre [(gpt/point? position) (boolean? lock?)]}
(UpdateDrawing. position)) (UpdateDrawing. position lock?))
;; --- Finish Drawin ;; --- Finish Drawin
@ -261,7 +261,7 @@
(do (do
(st/emit! (initialize-drawing point)) (st/emit! (initialize-drawing point))
(vreset! start? false)) (vreset! start? false))
(st/emit! (update-drawing (assoc point :lock ctrl?))))) (st/emit! (update-drawing point ctrl?))))
(on-finish [] (on-finish []
(if @start? (if @start?

View file

@ -342,7 +342,7 @@
:top-left :top-left
(let [width (- (:x2 shape) x) (let [width (- (:x2 shape) x)
height (- (:y2 shape) y) height (- (:y2 shape) y)
proportion (:proportion shape)] proportion (:proportion shape 1)]
(assoc shape (assoc shape
:width width :width width
:height (if lock? (/ width proportion) height))) :height (if lock? (/ width proportion) height)))
@ -350,7 +350,7 @@
:top-right :top-right
(let [width (- x (:x1 shape)) (let [width (- x (:x1 shape))
height (- (:y2 shape) y) height (- (:y2 shape) y)
proportion (:proportion shape)] proportion (:proportion shape 1)]
(assoc shape (assoc shape
:width width :width width
:height (if lock? (/ width proportion) height))) :height (if lock? (/ width proportion) height)))
@ -358,7 +358,7 @@
:top :top
(let [width (- (:x2 shape) (:x1 shape)) (let [width (- (:x2 shape) (:x1 shape))
height (- (:y2 shape) y) height (- (:y2 shape) y)
proportion (:proportion shape)] proportion (:proportion shape 1)]
(assoc shape (assoc shape
:width width :width width
:height (if lock? (/ width proportion) height))) :height (if lock? (/ width proportion) height)))
@ -366,7 +366,7 @@
:bottom-left :bottom-left
(let [width (- (:x2 shape) x) (let [width (- (:x2 shape) x)
height (- y (:y1 shape)) height (- y (:y1 shape))
proportion (:proportion shape)] proportion (:proportion shape 1)]
(assoc shape (assoc shape
:width width :width width
:height (if lock? (/ width proportion) height))) :height (if lock? (/ width proportion) height)))
@ -374,7 +374,7 @@
:bottom-right :bottom-right
(let [width (- x (:x1 shape)) (let [width (- x (:x1 shape))
height (- y (:y1 shape)) height (- y (:y1 shape))
proportion (:proportion shape)] proportion (:proportion shape 1)]
(assoc shape (assoc shape
:width width :width width
:height (if lock? (/ width proportion) height))) :height (if lock? (/ width proportion) height)))
@ -382,7 +382,7 @@
:bottom :bottom
(let [width (- (:x2 shape) (:x1 shape)) (let [width (- (:x2 shape) (:x1 shape))
height (- y (:y1 shape)) height (- y (:y1 shape))
proportion (:proportion shape)] proportion (:proportion shape 1)]
(assoc shape (assoc shape
:width width :width width
:height (if lock? (/ width proportion) height))) :height (if lock? (/ width proportion) height)))
@ -390,7 +390,7 @@
:left :left
(let [width (- (:x2 shape) x) (let [width (- (:x2 shape) x)
height (- (:y2 shape) (:y1 shape)) height (- (:y2 shape) (:y1 shape))
proportion (:proportion shape)] proportion (:proportion shape 1)]
(assoc shape (assoc shape
:width width :width width
:height (if lock? (/ width proportion) height))) :height (if lock? (/ width proportion) height)))
@ -398,7 +398,7 @@
:right :right
(let [width (- x (:x1 shape)) (let [width (- x (:x1 shape))
height (- (:y2 shape) (:y1 shape)) height (- (:y2 shape) (:y1 shape))
proportion (:proportion shape)] proportion (:proportion shape 1)]
(assoc shape (assoc shape
:width width :width width
:height (if lock? (/ width proportion) height))))) :height (if lock? (/ width proportion) height)))))