0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-03 04:49:03 -05:00

Add lock mode for mouse resize interaction.

Signed-off-by: Andrey Antukh <niwi@niwi.nz>
This commit is contained in:
Andrey Antukh 2016-02-29 17:52:34 +02:00
parent 5c7188eeba
commit ffaca0f459
2 changed files with 37 additions and 38 deletions

View file

@ -117,36 +117,38 @@
:ry (mth/abs (- y2 y1)))) :ry (mth/abs (- y2 y1))))
(defmethod move-vertex ::rect (defmethod move-vertex ::rect
[shape vid {dx :x dy :y}] [shape vid {dx :x dy :y lock :lock}]
(case vid (let [[dx dy] (if lock [dx dx] [dx dy])]
1 (assoc shape (case vid
:x1 (+ (:x1 shape) dx) 1 (assoc shape
:y1 (+ (:y1 shape) dy)) :x1 (+ (:x1 shape) dx)
2 (assoc shape :y1 (+ (:y1 shape) dy))
:x2 (+ (:x2 shape) dx) 2 (assoc shape
:y1 (+ (:y1 shape) dy)) :x2 (+ (:x2 shape) dx)
3 (assoc shape :y1 (+ (:y1 shape) dy))
:x1 (+ (:x1 shape) dx) 3 (assoc shape
:y2 (+ (:y2 shape) dy)) :x1 (+ (:x1 shape) dx)
4 (assoc shape :y2 (+ (:y2 shape) dy))
:x2 (+ (:x2 shape) dx) 4 (assoc shape
:y2 (+ (:y2 shape) dy)))) :x2 (+ (:x2 shape) dx)
:y2 (+ (:y2 shape) dy)))))
(defmethod move-vertex :builtin/circle (defmethod move-vertex :builtin/circle
[shape vid {dx :x dy :y}] [shape vid {dx :x dy :y lock :lock}]
(case vid (let [[dx dy] (if lock [dx dx] [dx dy])]
1 (assoc shape (case vid
:rx (- (:rx shape) dx) 1 (assoc shape
:ry (- (:ry shape) dy)) :rx (- (:rx shape) dx)
2 (assoc shape :ry (- (:ry shape) dy))
:rx (+ (:rx shape) dx) 2 (assoc shape
:ry (- (:ry shape) dy)) :rx (+ (:rx shape) dx)
3 (assoc shape :ry (- (:ry shape) dy))
:rx (- (:rx shape) dx) 3 (assoc shape
:ry (+ (:ry shape) dy)) :rx (- (:rx shape) dx)
4 (assoc shape :ry (+ (:ry shape) dy))
:rx (+ (:rx shape) dx) 4 (assoc shape
:ry (+ (:ry shape) dy)))) :rx (+ (:rx shape) dx)
:ry (+ (:ry shape) dy)))))
;; FIXME: lock mode ;; FIXME: lock mode

View file

@ -16,23 +16,20 @@
[uxbox.util.dom :as dom])) [uxbox.util.dom :as dom]))
(define-once :resize-subscriptions (define-once :resize-subscriptions
(letfn [(init [{:keys [payload]}] (letfn [(init [event]
(println payload) (let [payload (:payload event)
(let [stoper (->> uuc/actions-s stoper (->> uuc/actions-s
(rx/map :type) (rx/map :type)
(rx/pr-log "kaka:") (rx/pr-log "kaka:")
(rx/filter #(= :nothing %)) (rx/filter #(= :nothing %))
(rx/take 1))] (rx/take 1))]
(as-> uuwb/mouse-delta-s $ (as-> uuwb/mouse-delta-s $
(rx/take-until stoper $) (rx/take-until stoper $)
(rx/subscribe (rx/with-latest-from vector uuwb/mouse-ctrl-s $)
$ #(on-value payload %) nil on-complete)))) (rx/subscribe $ #(on-value payload %)))))
(on-complete [] (on-value [{:keys [vid shape]} [delta ctrl?]]
(println "on-complete")) (let [params {:vid vid :delta (assoc delta :lock ctrl?)}]
(on-value [{:keys [vid shape]} delta]
(let [params {:vid vid :delta delta}]
(rs/emit! (uds/update-vertex-position shape params))))] (rs/emit! (uds/update-vertex-position shape params))))]
(as-> uuc/actions-s $ (as-> uuc/actions-s $