0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-09 16:48:16 -05:00

Add locking mode for rect and circle rendering.

This commit is contained in:
Andrey Antukh 2016-02-03 17:07:47 +02:00
parent 25d4297df5
commit aaf27ed6a8
3 changed files with 25 additions and 15 deletions

View file

@ -198,7 +198,7 @@
(reify
rs/UpdateEvent
(-apply-update [_ state]
(let [size [width height]]
(let [size {:width width :height height}]
(update-in state [:shapes-by-id sid] sh/-resize' size)))))
(defn update-position

View file

@ -116,38 +116,46 @@
;; Resize
(defmethod -resize :builtin/line
[shape [x2 y2]]
[shape {:keys [x2 y2] :as pos}]
(assoc shape
:x2 x2 :y2 y2))
(defmethod -resize :builtin/circle
[{:keys [cx cy rx ry] :as shape} [x2 y2]]
[{:keys [cx cy rx ry] :as shape} {:keys [x2 y2 lock] :as pos}]
(let [x1 (- cx rx)
y1 (- cy ry)
width (- x2 x1)
height (- y2 y1)
height (if lock
width
(- y2 y1))
rx (/ width 2)
ry (/ height 2)
cx (+ x1 (/ width 2))
cy (+ y1 (/ height 2))]
(assoc shape :rx rx :ry ry :cx cx :cy cy)))
(if lock
(assoc shape :rx rx :ry ry :cx cx :cy cy)
(assoc shape :rx rx :ry ry :cx cx :cy cy))))
(defmethod -resize :builtin/rect
[shape [x2 y2]]
[shape {:keys [x2 y2 lock] :as pos}]
(let [{:keys [x y]} shape]
(assoc shape
:width (- x2 x)
:height (- y2 y))))
(if lock
(assoc shape
:width (- x2 x)
:height (- x2 x))
(assoc shape
:width (- x2 x)
:height (- y2 y)))))
(defmethod -resize :default
[shape _]
(throw (ex-info "Not implemented" (select-keys shape [:type]))))
(defmethod -resize' ::rect
[shape [width height]]
[shape {:keys [width height] :as size}]
(merge shape
(when width {:width width})
(when height {:height height})))

View file

@ -22,9 +22,9 @@
(defn- draw-area-render
[own]
(let [shape (rum/react +drawing-shape+)
[x y] (rum/react +drawing-position+)]
position (rum/react +drawing-position+)]
(when shape
(-> (sh/-resize shape [x y])
(-> (sh/-resize shape position)
(sh/-render identity)))))
(def ^:static draw-area
@ -43,19 +43,21 @@
stop @wb/scroll-top
y (+ stop y)
shape (sh/-initialize shape {:x1 x :y1 y :x2 x :y2 y})]
(reset! +drawing-shape+ shape)
(reset! +drawing-position+ [x y])
(reset! +drawing-position+ {:x2 x :y2 y :lock false})
(as-> wb/interactions-b $
(rx/filter #(not= % :shape/movement) $)
(rx/take 1 $)
(rx/take-until $ wb/mouse-s)
(rx/with-latest-from vector wb/mouse-ctrl-s $)
(rx/subscribe $ on-value nil on-complete))))
(on-value [[x y :as pos]]
(on-value [[[x y :as pos] ctrl?]]
(let [stop @wb/scroll-top]
(reset! +drawing-position+
[x (+ y stop)])))
{:x2 x :y2 (+ y stop) :lock ctrl?})))
(on-complete []
(let [shape @+drawing-shape+