From dfe5765d50be1c2308ddefda5291eb5ce5be8b13 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 26 Apr 2016 21:03:26 +0300 Subject: [PATCH] Improve alignment when zoom is applied. --- src/uxbox/ui/workspace/base.cljs | 1 + src/uxbox/ui/workspace/movement.cljs | 3 +-- src/uxbox/ui/workspace/resize.cljs | 1 - src/uxbox/util/geom.cljs | 16 ++++++++-------- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/uxbox/ui/workspace/base.cljs b/src/uxbox/ui/workspace/base.cljs index bed48a2fc..cc383503b 100644 --- a/src/uxbox/ui/workspace/base.cljs +++ b/src/uxbox/ui/workspace/base.cljs @@ -119,6 +119,7 @@ (defonce mouse-delta-s (->> mouse-viewport-s (rx/sample 10) + (rx/map #(gpt/divide % @zoom-l)) (rx/mapcat (fn [point] (if @alignment-l (uds/align-point point) diff --git a/src/uxbox/ui/workspace/movement.cljs b/src/uxbox/ui/workspace/movement.cljs index 9f3249a39..0537ed789 100644 --- a/src/uxbox/ui/workspace/movement.cljs +++ b/src/uxbox/ui/workspace/movement.cljs @@ -37,8 +37,7 @@ (rx/filter empty?) (rx/take 1)) stream (->> wb/mouse-delta-s - (rx/take-until stoper) - (rx/map #(gpt/divide % @wb/zoom-l)))] + (rx/take-until stoper))] (when @wb/alignment-l (rs/emit! (uds/initial-align-shape shape))) (rx/subscribe stream #(rs/emit! (uds/move-shape shape %))))) diff --git a/src/uxbox/ui/workspace/resize.cljs b/src/uxbox/ui/workspace/resize.cljs index 2bc353afd..8520995c3 100644 --- a/src/uxbox/ui/workspace/resize.cljs +++ b/src/uxbox/ui/workspace/resize.cljs @@ -37,7 +37,6 @@ (rx/take 1)) stream (->> wb/mouse-delta-s (rx/take-until stoper) - (rx/map #(gpt/divide % @wb/zoom-l)) (rx/with-latest-from vector wb/mouse-ctrl-s))] (when @wb/alignment-l (rs/emit! (uds/initial-vertext-align shape vid))) diff --git a/src/uxbox/util/geom.cljs b/src/uxbox/util/geom.cljs index e30ed33e0..42ec854d8 100644 --- a/src/uxbox/util/geom.cljs +++ b/src/uxbox/util/geom.cljs @@ -49,26 +49,26 @@ for rect-like shapes." [shape {dx :x dy :y}] (assoc shape - :x1 (+ (:x1 shape) dx) - :y1 (+ (:y1 shape) dy) - :x2 (+ (:x2 shape) dx) - :y2 (+ (:y2 shape) dy))) + :x1 (mth/round (+ (:x1 shape) dx)) + :y1 (mth/round (+ (:y1 shape) dy)) + :x2 (mth/round (+ (:x2 shape) dx)) + :y2 (mth/round (+ (:y2 shape) dy)))) (defn- move-circle "A specialized function for relative movement for circle shapes." [shape {dx :x dy :y}] (assoc shape - :cx (+ (:cx shape) dx) - :cy (+ (:cy shape) dy))) + :cx (mth/round (+ (:cx shape) dx)) + :cy (mth/round (+ (:cy shape) dy)))) (defn- move-group "A specialized function for relative movement for group shapes." [shape {dx :x dy :y}] (assoc shape - :dx (+ (:dx shape 0) dx) - :dy (+ (:dy shape 0) dy))) + :dx (mth/round (+ (:dx shape 0) dx)) + :dy (mth/round (+ (:dy shape 0) dy)))) ;; --- Absolute Movement