From c1ae4348cd9ab4e1e842b729674f70e5fa67315f Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 23 Aug 2016 16:26:13 +0300 Subject: [PATCH] Move selection ns under shapes. --- .../ui/{workspace => shapes}/selection.cljs | 101 ++++++++++-------- src/uxbox/main/ui/workspace/canvas.cljs | 4 +- 2 files changed, 61 insertions(+), 44 deletions(-) rename src/uxbox/main/ui/{workspace => shapes}/selection.cljs (84%) diff --git a/src/uxbox/main/ui/workspace/selection.cljs b/src/uxbox/main/ui/shapes/selection.cljs similarity index 84% rename from src/uxbox/main/ui/workspace/selection.cljs rename to src/uxbox/main/ui/shapes/selection.cljs index ce063b146..5dd7232ee 100644 --- a/src/uxbox/main/ui/workspace/selection.cljs +++ b/src/uxbox/main/ui/shapes/selection.cljs @@ -5,7 +5,7 @@ ;; Copyright (c) 2015-2016 Andrey Antukh ;; Copyright (c) 2015-2016 Juan de la Cruz -(ns uxbox.main.ui.workspace.selection +(ns uxbox.main.ui.shapes.selection "Multiple selection handlers component." (:require [lentes.core :as l] [beicon.core :as rx] @@ -15,6 +15,7 @@ [uxbox.main.data.shapes :as uds] [uxbox.main.ui.workspace.base :as wb] [uxbox.main.ui.workspace.rlocks :as rlocks] + [uxbox.main.ui.shapes.common :as scommon] [uxbox.main.geom :as geom] [uxbox.util.geom.point :as gpt] [uxbox.util.dom :as dom])) @@ -38,6 +39,8 @@ (-> (l/lens focus-selected-shapes) (l/derive st/state))) +(def edition-ref scommon/edition-ref) + ;; --- Resize (defn- start-resize @@ -59,27 +62,6 @@ (rs/emit! (uds/initial-vertext-align shape vid))) (rx/subscribe stream on-resize nil on-end)))) - -;; --- Path Edition - -(defn start-path-edition - [shape-id index] - (letfn [(on-move [delta] - (println "on-move" delta) - (rs/emit! (uds/update-path shape-id index delta))) - (on-end [] - (rlocks/release! :shape/resize))] - (let [stoper (->> wb/events-s - (rx/map first) - (rx/filter #(= % :mouse/up)) - (rx/take 1)) - stream (rx/take-until stoper wb/mouse-delta-s)] - (rlocks/acquire! :shape/resize) - (when @wb/alignment-ref - (rs/emit! (uds/initial-vertext-align shape-id index))) - (rx/subscribe stream on-move nil on-end)))) - - ;; --- Selection Handlers (Component) (mx/defc multiple-selection-handlers @@ -93,22 +75,17 @@ :style {:stroke "#333" :fill "transparent" :stroke-opacity "1"}}]])) -(mx/defc path-edition-selection-handlers - [{:keys [id points] :as shape}] - (letfn [(on-mouse-down [index event] - (dom/stop-propagation event) - (rlocks/acquire! :shape/resize) - (println "on-mouse-down" index) - (start-path-edition id index)) - - #_(rlocks/acquire! :shape/resize [vid id])] - (let [tmx (geom/transformation-matrix shape) - points (map #(gpt/transform % tmx) points)] - [:g.controls - (for [[index {:keys [x y]}] (map-indexed vector points)] - [:circle {:cx x :cy y :r 3 - :on-mouse-down (partial on-mouse-down index) - :fill "red"}])]))) +(mx/defc single-not-editable-selection-handlers + [{:keys [id] :as shape}] + (let [{:keys [width height x y]} (geom/outer-rect shape)] + [:g.controls + [:rect.main {:x x :y y + :width width + :height height + :stroke-dasharray "5,5" + :style {:stroke "#333" + :fill "transparent" + :stroke-opacity "1"}}]])) (mx/defc single-selection-handlers [{:keys [id] :as shape}] @@ -165,18 +142,58 @@ :cx (+ x width) :cy (+ y height)})]]))) +(defn start-path-edition + [shape-id index] + (letfn [(on-move [delta] + (println "on-move" delta) + (rs/emit! (uds/update-path shape-id index delta))) + (on-end [] + (rlocks/release! :shape/resize))] + (let [stoper (->> wb/events-s + (rx/map first) + (rx/filter #(= % :mouse/up)) + (rx/take 1)) + stream (rx/take-until stoper wb/mouse-delta-s)] + (rlocks/acquire! :shape/resize) + (when @wb/alignment-ref + (rs/emit! (uds/initial-vertext-align shape-id index))) + (rx/subscribe stream on-move nil on-end)))) + +(mx/defc path-edition-selection-handlers + [{:keys [id points] :as shape}] + (letfn [(on-mouse-down [index event] + (dom/stop-propagation event) + (rlocks/acquire! :shape/resize) + (start-path-edition id index))] + (let [ + ;;tmx (geom/transformation-matrix shape) + ;;points (map #(gpt/transform % tmx) points) + ] + [:g.controls + (for [[index {:keys [x y]}] (map-indexed vector points)] + [:circle {:cx x :cy y :r 3 + :on-mouse-down (partial on-mouse-down index) + :fill "red"}])]))) + (mx/defc selection-handlers {:mixins [mx/reactive mx/static]} [] (let [shapes (mx/react selected-shapes-ref) + edition (mx/react scommon/edition-ref) shapes-num (count shapes) shape (first shapes)] (cond + (zero? shapes-num) + nil + (> shapes-num 1) (multiple-selection-handlers shapes) - (and (= :path (:type shape)) - (:edition? shape)) - (path-edition-selection-handlers shape) + :else + (cond + (and (= :path (:type shape)) + (= @edition-ref (:id shape))) + (path-edition-selection-handlers shape) - (= shapes-num 1) (single-selection-handlers (first shapes))))) + :else + (single-selection-handlers (first shapes)))))) diff --git a/src/uxbox/main/ui/workspace/canvas.cljs b/src/uxbox/main/ui/workspace/canvas.cljs index f947d14f7..e9d6263dc 100644 --- a/src/uxbox/main/ui/workspace/canvas.cljs +++ b/src/uxbox/main/ui/workspace/canvas.cljs @@ -17,14 +17,14 @@ [uxbox.util.geom.point :as gpt] [uxbox.util.dom :as dom] [uxbox.util.data :refer (parse-int)] + [uxbox.util.mixins :as mx :include-macros true] [uxbox.main.ui.keyboard :as kbd] [uxbox.main.ui.shapes :as uus] - [uxbox.util.mixins :as mx :include-macros true] + [uxbox.main.ui.shapes.selection :refer (selection-handlers)] [uxbox.main.ui.workspace.base :as wb] [uxbox.main.ui.workspace.rlocks :as rlocks] [uxbox.main.ui.workspace.drawarea :refer (draw-area)] [uxbox.main.ui.workspace.ruler :refer (ruler)] - [uxbox.main.ui.workspace.selection :refer (selection-handlers)] [uxbox.main.ui.workspace.selrect :refer (selrect)] [uxbox.main.ui.workspace.grid :refer (grid)]) (:import goog.events.EventType))