Start use one unique stream for send user events (mouse and keyboard).

This commit is contained in:
Andrey Antukh 2017-01-15 23:01:27 +01:00
parent bc1ffc7f4f
commit 7a7059e172
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
12 changed files with 225 additions and 104 deletions

View file

@ -12,6 +12,7 @@
[uxbox.main.refs :as refs]
[uxbox.main.streams :as streams]
[uxbox.main.geom :as geom]
[uxbox.main.user-events :as uev]
[uxbox.main.data.shapes :as uds]
[uxbox.main.ui.keyboard :as kbd]
[uxbox.util.geom.point :as gpt]
@ -20,6 +21,8 @@
;; --- Refs
;; FIXME: use the predefined lenses under uxbox.main.lenses
(def edition-ref
(-> (l/in [:workspace :edition])
(l/derive st/state)))
@ -42,17 +45,16 @@
(rlocks/release! :shape/move)
(st/emit! (uds/apply-displacement shape)))
(on-start [shape]
(let [stoper (->> (rx/map first streams/events-s)
(rx/filter #(= % :mouse/up))
(let [stoper (->> streams/events
(rx/filter uev/mouse-up?)
(rx/take 1))
stream (->> streams/mouse-delta-s
stream (->> streams/mouse-position-deltas
(rx/take-until stoper))
on-move (partial on-move shape)
on-stop (partial on-stop shape)]
(when @refs/selected-alignment
(st/emit! (uds/initial-align-shape shape)))
(rx/subscribe stream on-move nil on-stop)))]
(rlocks/acquire! :shape/move)
(run! on-start @selected-ref)))

View file

@ -15,6 +15,7 @@
[uxbox.main.refs :as refs]
[uxbox.main.streams :as streams]
[uxbox.main.workers :as uwrk]
[uxbox.main.user-events :as uev]
[uxbox.main.data.shapes :as uds]
[uxbox.main.ui.shapes.common :as scommon]
[uxbox.main.geom :as geom]
@ -213,18 +214,19 @@
(let [shape (->> (geom/shape->rect-shape shape)
(geom/size))
stoper (->> streams/events-s
(rx/map first)
(rx/filter #(= % :mouse/up))
stoper (->> streams/events
(rx/filter uev/mouse-up?)
(rx/take 1))
stream (->> streams/mouse-canvas-s
stream (->> streams/canvas-mouse-position
(rx/map #(gpt/divide % @refs/selected-zoom))
(rx/mapcat (fn [point]
(if @refs/selected-alignment
(uwrk/align-point point)
(rx/of point))))
(rx/take-until stoper)
(rx/with-latest-from vector streams/mouse-ctrl-s)
(rx/with-latest-from vector streams/mouse-position-ctrl)
(rx/scan accumulate-width shape)
(rx/map (partial calculate-ratio shape)))]
(rlocks/acquire! :shape/resize)
@ -320,11 +322,11 @@
(st/emit! (uds/update-path shape-id index delta)))
(on-end []
(rlocks/release! :shape/resize))]
(let [stoper (->> streams/events-s
(let [stoper (->> streams/events
(rx/map first)
(rx/filter #(= % :mouse/up))
(rx/take 1))
stream (rx/take-until stoper streams/mouse-delta-s)]
stream (rx/take-until stoper streams/mouse-position-deltas)]
(rlocks/acquire! :shape/resize)
(when @refs/selected-alignment
(st/emit! (uds/initial-path-point-align shape-id index)))