Enable controlled mode on path drawing.

Allowing draw more precise lines aligned each
15degree in the circle with previous having
the previous point as center.
This commit is contained in:
Andrey Antukh 2016-08-24 17:05:39 +03:00
parent 62eb224ac0
commit 547faa16a9
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95

View file

@ -33,6 +33,13 @@
;; --- Draw Area (Component) ;; --- Draw Area (Component)
(declare watch-draw-actions) (declare watch-draw-actions)
(declare on-init-draw)
(defn- watch-draw-actions
[]
(let [stream (->> (rx/map first rlocks/stream)
(rx/filter #(= % :ui/draw)))]
(rx/subscribe stream on-init-draw)))
(defn- draw-area-will-mount (defn- draw-area-will-mount
[own] [own]
@ -60,19 +67,12 @@
;; --- Drawing Initialization ;; --- Drawing Initialization
(declare on-init)
(declare on-init-draw-icon) (declare on-init-draw-icon)
(declare on-init-draw-path) (declare on-init-draw-path)
(declare on-init-draw-free-path) (declare on-init-draw-free-path)
(declare on-init-draw-generic) (declare on-init-draw-generic)
(defn- watch-draw-actions (defn- on-init-draw
[]
(let [stream (->> (rx/map first rlocks/stream)
(rx/filter #(= % :ui/draw)))]
(rx/subscribe stream on-init)))
(defn- on-init
"Function execution when draw shape operation is requested. "Function execution when draw shape operation is requested.
This is a entry point for the draw interaction." This is a entry point for the draw interaction."
[] []
@ -84,6 +84,8 @@
(on-init-draw-path shape)) (on-init-draw-path shape))
(on-init-draw-generic shape)))) (on-init-draw-generic shape))))
;; --- Icon Drawing
(defn- on-init-draw-icon (defn- on-init-draw-icon
[shape] [shape]
(let [{:keys [x y]} (gpt/divide @wb/mouse-canvas-a @wb/zoom-ref) (let [{:keys [x y]} (gpt/divide @wb/mouse-canvas-a @wb/zoom-ref)
@ -94,6 +96,23 @@
(uds/select-first-shape)) (uds/select-first-shape))
(rlocks/release! :ui/draw))) (rlocks/release! :ui/draw)))
;; --- Path Drawing
(def ^:private immanted-zones
(let [transform #(vector (- % 7) (+ % 7) %)]
(concat
(mapv transform (range 0 181 15))
(mapv (comp transform -) (range 0 181 15)))))
(defn- align-position
[angle pos]
(reduce (fn [pos [a1 a2 v]]
(if (< a1 angle a2)
(reduced (gpt/update-angle pos v))
pos))
pos
immanted-zones))
(defn- on-init-draw-path (defn- on-init-draw-path
[shape] [shape]
(let [mouse (->> (rx/sample 10 wb/mouse-viewport-s) (let [mouse (->> (rx/sample 10 wb/mouse-viewport-s)
@ -158,8 +177,16 @@
(reset! drawing-shape shape))) (reset! drawing-shape shape)))
(on-draw [[point ctrl?]] (on-draw [[point ctrl?]]
(let [shape (update-point @drawing-shape point @counter)] (if ctrl?
(reset! drawing-shape shape))) (let [center (get-in @drawing-shape [:points (dec @counter)])
point (as-> point $
(gpt/subtract $ center)
(align-position (gpt/angle $) $)
(gpt/add $ center))]
(->> (update-point @drawing-shape point @counter)
(reset! drawing-shape)))
(->> (update-point @drawing-shape point @counter)
(reset! drawing-shape))))
(on-end [] (on-end []
(let [shape (normalize-shape @drawing-shape)] (let [shape (normalize-shape @drawing-shape)]