Improve alignment when zoom is applied.

This commit is contained in:
Andrey Antukh 2016-04-26 21:03:26 +03:00
parent 0969d62a50
commit dfe5765d50
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
4 changed files with 10 additions and 11 deletions

View file

@ -119,6 +119,7 @@
(defonce mouse-delta-s (defonce mouse-delta-s
(->> mouse-viewport-s (->> mouse-viewport-s
(rx/sample 10) (rx/sample 10)
(rx/map #(gpt/divide % @zoom-l))
(rx/mapcat (fn [point] (rx/mapcat (fn [point]
(if @alignment-l (if @alignment-l
(uds/align-point point) (uds/align-point point)

View file

@ -37,8 +37,7 @@
(rx/filter empty?) (rx/filter empty?)
(rx/take 1)) (rx/take 1))
stream (->> wb/mouse-delta-s stream (->> wb/mouse-delta-s
(rx/take-until stoper) (rx/take-until stoper))]
(rx/map #(gpt/divide % @wb/zoom-l)))]
(when @wb/alignment-l (when @wb/alignment-l
(rs/emit! (uds/initial-align-shape shape))) (rs/emit! (uds/initial-align-shape shape)))
(rx/subscribe stream #(rs/emit! (uds/move-shape shape %))))) (rx/subscribe stream #(rs/emit! (uds/move-shape shape %)))))

View file

@ -37,7 +37,6 @@
(rx/take 1)) (rx/take 1))
stream (->> wb/mouse-delta-s stream (->> wb/mouse-delta-s
(rx/take-until stoper) (rx/take-until stoper)
(rx/map #(gpt/divide % @wb/zoom-l))
(rx/with-latest-from vector wb/mouse-ctrl-s))] (rx/with-latest-from vector wb/mouse-ctrl-s))]
(when @wb/alignment-l (when @wb/alignment-l
(rs/emit! (uds/initial-vertext-align shape vid))) (rs/emit! (uds/initial-vertext-align shape vid)))

View file

@ -49,26 +49,26 @@
for rect-like shapes." for rect-like shapes."
[shape {dx :x dy :y}] [shape {dx :x dy :y}]
(assoc shape (assoc shape
:x1 (+ (:x1 shape) dx) :x1 (mth/round (+ (:x1 shape) dx))
:y1 (+ (:y1 shape) dy) :y1 (mth/round (+ (:y1 shape) dy))
:x2 (+ (:x2 shape) dx) :x2 (mth/round (+ (:x2 shape) dx))
:y2 (+ (:y2 shape) dy))) :y2 (mth/round (+ (:y2 shape) dy))))
(defn- move-circle (defn- move-circle
"A specialized function for relative movement "A specialized function for relative movement
for circle shapes." for circle shapes."
[shape {dx :x dy :y}] [shape {dx :x dy :y}]
(assoc shape (assoc shape
:cx (+ (:cx shape) dx) :cx (mth/round (+ (:cx shape) dx))
:cy (+ (:cy shape) dy))) :cy (mth/round (+ (:cy shape) dy))))
(defn- move-group (defn- move-group
"A specialized function for relative movement "A specialized function for relative movement
for group shapes." for group shapes."
[shape {dx :x dy :y}] [shape {dx :x dy :y}]
(assoc shape (assoc shape
:dx (+ (:dx shape 0) dx) :dx (mth/round (+ (:dx shape 0) dx))
:dy (+ (:dy shape 0) dy))) :dy (mth/round (+ (:dy shape 0) dy))))
;; --- Absolute Movement ;; --- Absolute Movement