Calculate selrect for bezier curves

This commit is contained in:
alonso.torres 2020-11-12 19:50:04 +01:00
parent f3cce1904c
commit d8ab3473bf
10 changed files with 212 additions and 79 deletions

View file

@ -50,14 +50,9 @@
(defn calculate-selrect [shape]
(let [points (->> shape
:content
(mapv #(gpt/point
(-> % :params :x)
(-> % :params :y))))]
(assoc shape
:points points
:selrect (gsh/points->selrect points))))
(assoc shape
:points (gsh/content->points (:content shape))
:selrect (gsh/content->selrect (:content shape))))
(defn init-path []
(ptk/reify ::init-path

View file

@ -24,7 +24,8 @@
[app.main.ui.shapes.filters :as filters]
[app.main.ui.shapes.shape :refer [shape-container]]
[app.main.ui.workspace.shapes.common :as common]
[app.util.geom.path :as ugp]))
[app.util.geom.path :as ugp]
[app.common.geom.shapes.path :as gsp]))
(mf/defc path-wrapper
{::mf/wrap-props false}
@ -53,7 +54,6 @@
:on-double-click on-double-click
:on-mouse-down on-mouse-down
:on-context-menu on-context-menu}
[:& path/path-shape {:shape shape
:background? true}]]))

View file

@ -204,11 +204,14 @@
picking-color?]} local
page-id (mf/use-ctx ctx/current-page-id)
selrect-orig (->> (mf/deref refs/selected-objects)
(gsh/selection-rect))
selrect (-> selrect-orig
(assoc :modifiers (:modifiers local))
(gsh/transform-shape))
selected-objects (mf/deref refs/selected-objects)
selrect-orig (->> selected-objects
(gsh/selection-rect))
selrect (->> selected-objects
(map #(assoc % :modifiers (:modifiers local)))
(map gsh/transform-shape)
(gsh/selection-rect))
alt? (mf/use-state false)
viewport-ref (mf/use-ref nil)
@ -266,18 +269,18 @@
on-pointer-down
(mf/use-callback
(fn [event]
(fn [event]
(let [target (dom/get-target event)]
; Capture mouse pointer to detect the movements even if cursor
; leaves the viewport or the browser itself
; https://developer.mozilla.org/en-US/docs/Web/API/Element/setPointerCapture
; Capture mouse pointer to detect the movements even if cursor
; leaves the viewport or the browser itself
; https://developer.mozilla.org/en-US/docs/Web/API/Element/setPointerCapture
(.setPointerCapture target (.-pointerId event)))))
on-pointer-up
(mf/use-callback
(fn [event]
(fn [event]
(let [target (dom/get-target event)]
; Release pointer on mouse up
; Release pointer on mouse up
(.releasePointerCapture target (.-pointerId event)))))
on-click