Better handle zoom on drawing.

This commit is contained in:
Andrey Antukh 2019-08-24 16:25:38 +02:00
parent 786aefe7d8
commit 89d0b632a4

View file

@ -135,22 +135,21 @@
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state stream]
(let [pid (get-in state [:workspace :current]) (let [pid (get-in state [:workspace :current])
zoom (get-in state [:workspace pid :zoom]) {:keys [zoom flags]} (get-in state [:workspace pid])
flags (get-in state [:workspace pid :flags])
align? (refs/alignment-activated? flags) align? (refs/alignment-activated? flags)
stoper (->> (rx/filter #(or (uws/mouse-up? %) (= % :interrupt)) stream) stoper? #(or (uws/mouse-up? %) (= % :interrupt))
(rx/take 1)) stoper (rx/filter stoper? stream)
mouse (->> uws/mouse-position mouse (->> uws/mouse-position
(rx/mapcat #(conditional-align % align?)) (rx/mapcat #(conditional-align % align?))
(rx/with-latest vector uws/mouse-position-ctrl))] (rx/map #(gpt/divide % zoom)))]
(rx/concat (rx/concat
(->> uws/mouse-position (->> mouse
(rx/take 1) (rx/take 1)
(rx/mapcat #(conditional-align % align?))
(rx/map (fn [pt] #(initialize-drawing % pt)))) (rx/map (fn [pt] #(initialize-drawing % pt))))
(->> mouse (->> mouse
(rx/with-latest vector uws/mouse-position-ctrl)
(rx/map (fn [[pt ctrl?]] #(update-drawing % pt ctrl?))) (rx/map (fn [[pt ctrl?]] #(update-drawing % pt ctrl?)))
(rx/take-until stoper)) (rx/take-until stoper))
(rx/of handle-finish-drawing))))))) (rx/of handle-finish-drawing)))))))
@ -189,17 +188,17 @@
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state stream]
(let [pid (get-in state [:workspace :current]) (let [pid (get-in state [:workspace :current])
zoom (get-in state [:workspace pid :zoom]) {:keys [zoom flags]} (get-in state [:workspace pid])
flags (get-in state [:workspace pid :flags])
align? (refs/alignment-activated? flags)
last-point (volatile! @uws/mouse-position) align? (refs/alignment-activated? flags)
last-point (volatile! (gpt/divide @uws/mouse-position zoom))
stoper (->> (rx/filter stoper-event? stream) stoper (->> (rx/filter stoper-event? stream)
(rx/share)) (rx/share))
mouse (->> (rx/sample 10 uws/mouse-position) mouse (->> (rx/sample 10 uws/mouse-position)
(rx/mapcat #(conditional-align % align?))) (rx/mapcat #(conditional-align % align?))
(rx/map #(gpt/divide % zoom)))
points (->> stream points (->> stream
(rx/filter uws/mouse-click?) (rx/filter uws/mouse-click?)
@ -267,12 +266,14 @@
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state stream]
(let [pid (get-in state [:workspace :current]) (let [pid (get-in state [:workspace :current])
zoom (get-in state [:workspace pid :zoom]) {:keys [zoom flags]} (get-in state [:workspace pid])
flags (get-in state [:workspace pid :flags])
align? (refs/alignment-activated? flags) align? (refs/alignment-activated? flags)
stoper (rx/filter stoper-event? stream) stoper (rx/filter stoper-event? stream)
mouse (->> (rx/sample 10 uws/mouse-position) mouse (->> (rx/sample 10 uws/mouse-position)
(rx/mapcat #(conditional-align % align?)))] (rx/mapcat #(conditional-align % align?))
(rx/map #(gpt/divide % zoom)))]
(rx/concat (rx/concat
(rx/of initialize-drawing) (rx/of initialize-drawing)
(->> mouse (->> mouse