0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-12 15:51:37 -05:00

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])
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?

View file

@ -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)))))