diff --git a/frontend/src/uxbox/main/geom.cljs b/frontend/src/uxbox/main/geom.cljs index aa6843a8f..44fa50d6f 100644 --- a/frontend/src/uxbox/main/geom.cljs +++ b/frontend/src/uxbox/main/geom.cljs @@ -565,7 +565,6 @@ ;; --- Outer Rect (declare selection-rect-generic) -(declare selection-rect-group) (defn rotation-matrix "Generate a rotation matrix from shape." @@ -590,25 +589,15 @@ ([shape] (selection-rect @st/state shape)) ([state shape] - (let [{:keys [displacement resize]} (:modifiers shape)] + (let [modifier (:modifier-mtx shape)] (-> (shape->rect-shape shape) (assoc :type :rect :id (:id shape)) - (transform (or resize (gmt/matrix))) - (transform (or displacement (gmt/matrix))) + (transform (or modifier (gmt/matrix))) (rotate-shape) (size))))) ;; --- Helpers -(defn resolve-parent - "Recursively resolve the real shape parent." - ([shape] - (resolve-parent @st/state shape)) - ([state {:keys [group] :as shape}] - (if group - (resolve-parent state (get-in state [:shapes group])) - shape))) - (defn contained-in? "Check if a shape is contained in the provided selection rect." diff --git a/frontend/src/uxbox/main/ui/shapes/path.cljs b/frontend/src/uxbox/main/ui/shapes/path.cljs index 0a20942d4..07f3fd152 100644 --- a/frontend/src/uxbox/main/ui/shapes/path.cljs +++ b/frontend/src/uxbox/main/ui/shapes/path.cljs @@ -14,7 +14,8 @@ [uxbox.main.store :as st] [uxbox.main.ui.shapes.attrs :as attrs] [uxbox.main.ui.shapes.common :as common] - [uxbox.util.data :refer [classnames normalize-props]])) + [uxbox.util.data :refer [classnames normalize-props]] + [uxbox.util.geom.matrix :as gmt])) ;; --- Path Component @@ -22,8 +23,7 @@ (mf/defc path-component [{:keys [shape] :as props}] - (let [modifiers (mf/deref (refs/selected-modifiers (:id shape))) - selected (mf/deref refs/selected-shapes) + (let [selected (mf/deref refs/selected-shapes) selected? (contains? selected (:id shape))] (letfn [(on-mouse-down [event] (common/on-mouse-down event shape selected)) @@ -35,7 +35,6 @@ :on-double-click on-double-click :on-mouse-down on-mouse-down} [:& path-shape {:shape shape - :modifiers modifiers :background? true}]]))) ;; --- Path Shape @@ -62,12 +61,13 @@ (recur buffer (inc index))))))) (mf/defc path-shape - [{:keys [shape modifiers background?] :as props}] - (let [{:keys [resize displacement]} modifiers - shape (cond-> shape - displacement (geom/transform displacement) - resize (geom/transform resize)) - moving? (boolean displacement) + [{:keys [shape background?] :as props}] + (let [modifier-mtx (:modifier-mtx shape) + shape (cond + (gmt/matrix? modifier-mtx) (geom/transform shape modifier-mtx) + :else shape) + + moving? (boolean modifier-mtx) pdata (render-path shape) props {:id (str (:id shape)) diff --git a/frontend/src/uxbox/main/ui/workspace/selection.cljs b/frontend/src/uxbox/main/ui/workspace/selection.cljs index 119349b1b..87430604b 100644 --- a/frontend/src/uxbox/main/ui/workspace/selection.cljs +++ b/frontend/src/uxbox/main/ui/workspace/selection.cljs @@ -190,9 +190,8 @@ :style {:cursor "pointer"}}])]))) (mf/defc multiple-selection-handlers - [{:keys [shapes modifiers zoom] :as props}] + [{:keys [shapes zoom] :as props}] (let [shape (->> shapes - (map #(assoc % :modifiers (get modifiers (:id %)))) (map #(geom/selection-rect %)) (geom/shapes->rect-shape) (geom/selection-rect)) @@ -202,18 +201,9 @@ :zoom zoom :on-click on-click}])) -(mf/defc single-selection-handlers - [{:keys [shape zoom modifiers] :as props}] - (let [on-click #(do (dom/stop-propagation %2) - (start-resize %1 #{(:id shape)} shape)) - shape (-> (assoc shape :modifiers modifiers) - (geom/selection-rect))] - [:& controls {:shape shape :zoom zoom :on-click on-click}])) - (mf/defc text-edition-selection-handlers - [{:keys [shape modifiers zoom] :as props}] - (let [{:keys [x1 y1 width height] :as shape} (-> (assoc shape :modifiers modifiers) - (geom/selection-rect))] + [{:keys [shape zoom] :as props}] + (let [{:keys [x1 y1 width height] :as shape} (geom/selection-rect shape)] [:g.controls [:rect.main {:x x1 :y y1 :width width @@ -224,6 +214,13 @@ :stroke-opacity "0.5" :fill "transparent"}}]])) +(mf/defc single-selection-handlers + [{:keys [shape zoom] :as props}] + (let [on-click #(do (dom/stop-propagation %2) + (start-resize %1 #{(:id shape)} shape)) + shape (geom/selection-rect shape)] + [:& controls {:shape shape :zoom zoom :on-click on-click}])) + (def ^:private shapes-map-iref (-> (l/key :shapes) (l/derive st/state))) @@ -233,34 +230,27 @@ (let [shapes-map (mf/deref shapes-map-iref) shapes (map #(get shapes-map %) (:selected wst)) edition? (:edition wst) - modifiers (:modifiers wst) zoom (:zoom wst 1) num (count shapes) {:keys [id type] :as shape} (first shapes)] - (cond (zero? num) nil (> num 1) [:& multiple-selection-handlers {:shapes shapes - :modifiers modifiers :zoom zoom}] (and (= type :text) (= edition? (:id shape))) [:& text-edition-selection-handlers {:shape shape - :modifiers (get modifiers id) :zoom zoom}] (and (= type :path) (= edition? (:id shape))) [:& path-edition-selection-handlers {:shape shape - :zoom zoom - :modifiers (get modifiers id)}] - + :zoom zoom}] :else [:& single-selection-handlers {:shape shape - :modifiers (get modifiers id) :zoom zoom}])))