mirror of
https://github.com/penpot/penpot.git
synced 2025-05-25 07:56:11 +02:00
Move selection ns under shapes.
This commit is contained in:
parent
13e8679713
commit
c1ae4348cd
2 changed files with 61 additions and 44 deletions
|
@ -5,7 +5,7 @@
|
||||||
;; Copyright (c) 2015-2016 Andrey Antukh <niwi@niwi.nz>
|
;; Copyright (c) 2015-2016 Andrey Antukh <niwi@niwi.nz>
|
||||||
;; Copyright (c) 2015-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
;; Copyright (c) 2015-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
||||||
|
|
||||||
(ns uxbox.main.ui.workspace.selection
|
(ns uxbox.main.ui.shapes.selection
|
||||||
"Multiple selection handlers component."
|
"Multiple selection handlers component."
|
||||||
(:require [lentes.core :as l]
|
(:require [lentes.core :as l]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
|
@ -15,6 +15,7 @@
|
||||||
[uxbox.main.data.shapes :as uds]
|
[uxbox.main.data.shapes :as uds]
|
||||||
[uxbox.main.ui.workspace.base :as wb]
|
[uxbox.main.ui.workspace.base :as wb]
|
||||||
[uxbox.main.ui.workspace.rlocks :as rlocks]
|
[uxbox.main.ui.workspace.rlocks :as rlocks]
|
||||||
|
[uxbox.main.ui.shapes.common :as scommon]
|
||||||
[uxbox.main.geom :as geom]
|
[uxbox.main.geom :as geom]
|
||||||
[uxbox.util.geom.point :as gpt]
|
[uxbox.util.geom.point :as gpt]
|
||||||
[uxbox.util.dom :as dom]))
|
[uxbox.util.dom :as dom]))
|
||||||
|
@ -38,6 +39,8 @@
|
||||||
(-> (l/lens focus-selected-shapes)
|
(-> (l/lens focus-selected-shapes)
|
||||||
(l/derive st/state)))
|
(l/derive st/state)))
|
||||||
|
|
||||||
|
(def edition-ref scommon/edition-ref)
|
||||||
|
|
||||||
;; --- Resize
|
;; --- Resize
|
||||||
|
|
||||||
(defn- start-resize
|
(defn- start-resize
|
||||||
|
@ -59,27 +62,6 @@
|
||||||
(rs/emit! (uds/initial-vertext-align shape vid)))
|
(rs/emit! (uds/initial-vertext-align shape vid)))
|
||||||
(rx/subscribe stream on-resize nil on-end))))
|
(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)
|
;; --- Selection Handlers (Component)
|
||||||
|
|
||||||
(mx/defc multiple-selection-handlers
|
(mx/defc multiple-selection-handlers
|
||||||
|
@ -93,22 +75,17 @@
|
||||||
:style {:stroke "#333" :fill "transparent"
|
:style {:stroke "#333" :fill "transparent"
|
||||||
:stroke-opacity "1"}}]]))
|
:stroke-opacity "1"}}]]))
|
||||||
|
|
||||||
(mx/defc path-edition-selection-handlers
|
(mx/defc single-not-editable-selection-handlers
|
||||||
[{:keys [id points] :as shape}]
|
[{:keys [id] :as shape}]
|
||||||
(letfn [(on-mouse-down [index event]
|
(let [{:keys [width height x y]} (geom/outer-rect shape)]
|
||||||
(dom/stop-propagation event)
|
[:g.controls
|
||||||
(rlocks/acquire! :shape/resize)
|
[:rect.main {:x x :y y
|
||||||
(println "on-mouse-down" index)
|
:width width
|
||||||
(start-path-edition id index))
|
:height height
|
||||||
|
:stroke-dasharray "5,5"
|
||||||
#_(rlocks/acquire! :shape/resize [vid id])]
|
:style {:stroke "#333"
|
||||||
(let [tmx (geom/transformation-matrix shape)
|
:fill "transparent"
|
||||||
points (map #(gpt/transform % tmx) points)]
|
:stroke-opacity "1"}}]]))
|
||||||
[: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-selection-handlers
|
(mx/defc single-selection-handlers
|
||||||
[{:keys [id] :as shape}]
|
[{:keys [id] :as shape}]
|
||||||
|
@ -165,18 +142,58 @@
|
||||||
:cx (+ x width)
|
:cx (+ x width)
|
||||||
:cy (+ y height)})]])))
|
: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
|
(mx/defc selection-handlers
|
||||||
{:mixins [mx/reactive mx/static]}
|
{:mixins [mx/reactive mx/static]}
|
||||||
[]
|
[]
|
||||||
(let [shapes (mx/react selected-shapes-ref)
|
(let [shapes (mx/react selected-shapes-ref)
|
||||||
|
edition (mx/react scommon/edition-ref)
|
||||||
shapes-num (count shapes)
|
shapes-num (count shapes)
|
||||||
shape (first shapes)]
|
shape (first shapes)]
|
||||||
(cond
|
(cond
|
||||||
|
(zero? shapes-num)
|
||||||
|
nil
|
||||||
|
|
||||||
(> shapes-num 1)
|
(> shapes-num 1)
|
||||||
(multiple-selection-handlers shapes)
|
(multiple-selection-handlers shapes)
|
||||||
|
|
||||||
(and (= :path (:type shape))
|
:else
|
||||||
(:edition? shape))
|
(cond
|
||||||
(path-edition-selection-handlers shape)
|
(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))))))
|
|
@ -17,14 +17,14 @@
|
||||||
[uxbox.util.geom.point :as gpt]
|
[uxbox.util.geom.point :as gpt]
|
||||||
[uxbox.util.dom :as dom]
|
[uxbox.util.dom :as dom]
|
||||||
[uxbox.util.data :refer (parse-int)]
|
[uxbox.util.data :refer (parse-int)]
|
||||||
|
[uxbox.util.mixins :as mx :include-macros true]
|
||||||
[uxbox.main.ui.keyboard :as kbd]
|
[uxbox.main.ui.keyboard :as kbd]
|
||||||
[uxbox.main.ui.shapes :as uus]
|
[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.base :as wb]
|
||||||
[uxbox.main.ui.workspace.rlocks :as rlocks]
|
[uxbox.main.ui.workspace.rlocks :as rlocks]
|
||||||
[uxbox.main.ui.workspace.drawarea :refer (draw-area)]
|
[uxbox.main.ui.workspace.drawarea :refer (draw-area)]
|
||||||
[uxbox.main.ui.workspace.ruler :refer (ruler)]
|
[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.selrect :refer (selrect)]
|
||||||
[uxbox.main.ui.workspace.grid :refer (grid)])
|
[uxbox.main.ui.workspace.grid :refer (grid)])
|
||||||
(:import goog.events.EventType))
|
(:import goog.events.EventType))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue