mirror of
https://github.com/penpot/penpot.git
synced 2025-05-09 21:16:38 +02:00
Add locking mode for rect and circle rendering.
This commit is contained in:
parent
25d4297df5
commit
aaf27ed6a8
3 changed files with 25 additions and 15 deletions
|
@ -198,7 +198,7 @@
|
||||||
(reify
|
(reify
|
||||||
rs/UpdateEvent
|
rs/UpdateEvent
|
||||||
(-apply-update [_ state]
|
(-apply-update [_ state]
|
||||||
(let [size [width height]]
|
(let [size {:width width :height height}]
|
||||||
(update-in state [:shapes-by-id sid] sh/-resize' size)))))
|
(update-in state [:shapes-by-id sid] sh/-resize' size)))))
|
||||||
|
|
||||||
(defn update-position
|
(defn update-position
|
||||||
|
|
|
@ -116,38 +116,46 @@
|
||||||
;; Resize
|
;; Resize
|
||||||
|
|
||||||
(defmethod -resize :builtin/line
|
(defmethod -resize :builtin/line
|
||||||
[shape [x2 y2]]
|
[shape {:keys [x2 y2] :as pos}]
|
||||||
(assoc shape
|
(assoc shape
|
||||||
:x2 x2 :y2 y2))
|
:x2 x2 :y2 y2))
|
||||||
|
|
||||||
(defmethod -resize :builtin/circle
|
(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)
|
(let [x1 (- cx rx)
|
||||||
y1 (- cy ry)
|
y1 (- cy ry)
|
||||||
|
|
||||||
width (- x2 x1)
|
width (- x2 x1)
|
||||||
height (- y2 y1)
|
height (if lock
|
||||||
|
width
|
||||||
|
(- y2 y1))
|
||||||
|
|
||||||
rx (/ width 2)
|
rx (/ width 2)
|
||||||
ry (/ height 2)
|
ry (/ height 2)
|
||||||
|
|
||||||
cx (+ x1 (/ width 2))
|
cx (+ x1 (/ width 2))
|
||||||
cy (+ y1 (/ height 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
|
(defmethod -resize :builtin/rect
|
||||||
[shape [x2 y2]]
|
[shape {:keys [x2 y2 lock] :as pos}]
|
||||||
(let [{:keys [x y]} shape]
|
(let [{:keys [x y]} shape]
|
||||||
(assoc shape
|
(if lock
|
||||||
:width (- x2 x)
|
(assoc shape
|
||||||
:height (- y2 y))))
|
:width (- x2 x)
|
||||||
|
:height (- x2 x))
|
||||||
|
(assoc shape
|
||||||
|
:width (- x2 x)
|
||||||
|
:height (- y2 y)))))
|
||||||
|
|
||||||
(defmethod -resize :default
|
(defmethod -resize :default
|
||||||
[shape _]
|
[shape _]
|
||||||
(throw (ex-info "Not implemented" (select-keys shape [:type]))))
|
(throw (ex-info "Not implemented" (select-keys shape [:type]))))
|
||||||
|
|
||||||
(defmethod -resize' ::rect
|
(defmethod -resize' ::rect
|
||||||
[shape [width height]]
|
[shape {:keys [width height] :as size}]
|
||||||
(merge shape
|
(merge shape
|
||||||
(when width {:width width})
|
(when width {:width width})
|
||||||
(when height {:height height})))
|
(when height {:height height})))
|
||||||
|
|
|
@ -22,9 +22,9 @@
|
||||||
(defn- draw-area-render
|
(defn- draw-area-render
|
||||||
[own]
|
[own]
|
||||||
(let [shape (rum/react +drawing-shape+)
|
(let [shape (rum/react +drawing-shape+)
|
||||||
[x y] (rum/react +drawing-position+)]
|
position (rum/react +drawing-position+)]
|
||||||
(when shape
|
(when shape
|
||||||
(-> (sh/-resize shape [x y])
|
(-> (sh/-resize shape position)
|
||||||
(sh/-render identity)))))
|
(sh/-render identity)))))
|
||||||
|
|
||||||
(def ^:static draw-area
|
(def ^:static draw-area
|
||||||
|
@ -43,19 +43,21 @@
|
||||||
stop @wb/scroll-top
|
stop @wb/scroll-top
|
||||||
y (+ stop y)
|
y (+ stop y)
|
||||||
shape (sh/-initialize shape {:x1 x :y1 y :x2 x :y2 y})]
|
shape (sh/-initialize shape {:x1 x :y1 y :x2 x :y2 y})]
|
||||||
|
|
||||||
(reset! +drawing-shape+ shape)
|
(reset! +drawing-shape+ shape)
|
||||||
(reset! +drawing-position+ [x y])
|
(reset! +drawing-position+ {:x2 x :y2 y :lock false})
|
||||||
|
|
||||||
(as-> wb/interactions-b $
|
(as-> wb/interactions-b $
|
||||||
(rx/filter #(not= % :shape/movement) $)
|
(rx/filter #(not= % :shape/movement) $)
|
||||||
(rx/take 1 $)
|
(rx/take 1 $)
|
||||||
(rx/take-until $ wb/mouse-s)
|
(rx/take-until $ wb/mouse-s)
|
||||||
|
(rx/with-latest-from vector wb/mouse-ctrl-s $)
|
||||||
(rx/subscribe $ on-value nil on-complete))))
|
(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]
|
(let [stop @wb/scroll-top]
|
||||||
(reset! +drawing-position+
|
(reset! +drawing-position+
|
||||||
[x (+ y stop)])))
|
{:x2 x :y2 (+ y stop) :lock ctrl?})))
|
||||||
|
|
||||||
(on-complete []
|
(on-complete []
|
||||||
(let [shape @+drawing-shape+
|
(let [shape @+drawing-shape+
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue