♻️ Removed curves shapes

This commit is contained in:
alonso.torres 2020-11-19 18:12:15 +01:00
parent 55b71a111b
commit e2593c2dad
21 changed files with 41 additions and 511 deletions

View file

@ -99,7 +99,5 @@
;; default
(box/handle-drawing-box))))))
;; Export
#_(def close-drawing-path path/close-drawing-path)

View file

@ -28,10 +28,15 @@
(defn insert-point-segment [state point]
(update-in state [:workspace-drawing :object :segments] (fnil conj []) point))
(defn update-selrect [{:keys [segments] :as shape}]
(let [points (->> segments
(map #(apply gpt/point %)))]
(assoc shape :selrect (gsh/points->selrect points))))
(defn curve-to-path [{:keys [segments] :as shape}]
(let [content (path/segments->content segments)
selrect (gsh/content->selrect content)
points (gsh/rect->points selrect)]
(-> shape
(dissoc :segments)
(assoc :content content)
(assoc :selrect selrect)
(assoc :points points))))
(defn finish-drawing-curve [state]
(update-in
@ -39,7 +44,7 @@
(fn [shape]
(-> shape
(update :segments #(path/simplify % simplify-tolerance))
(update-selrect)))))
(curve-to-path)))))
(defn handle-drawing-curve []
(ptk/reify ::handle-drawing-curve

View file

@ -84,7 +84,7 @@
{:keys [rotation]} shape
shapev (-> (gpt/point width height))
rotation (if (#{:curve :path} (:type shape)) 0 rotation)
rotation (if (= :path (:type shape)) 0 rotation)
;; Vector modifiers depending on the handler
handler-modif (let [[x y] (handler-modifiers handler)] (gpt/point x y))

View file

@ -84,7 +84,6 @@
opts #js {:shape shape}]
[:> shape-container {:shape shape}
(case (:type shape)
:curve [:> path/path-shape opts]
:text [:> text/text-shape opts]
:rect [:> rect/rect-shape opts]
:path [:> path/path-shape opts]

View file

@ -28,7 +28,6 @@
:rect [:layout :fill :stroke :shadow :blur]
:circle [:layout :fill :stroke :shadow :blur]
:path [:layout :fill :stroke :shadow :blur]
:curve [:layout :fill :stroke :shadow :blur]
:image [:image :layout :shadow :blur]
:text [:layout :text :shadow :blur]})

View file

@ -127,7 +127,6 @@
opts #js {:shape shape
:frame frame}]
(case (:type shape)
:curve [:> path-wrapper opts]
:text [:> text-wrapper opts]
:rect [:> rect-wrapper opts]
:path [:> path-wrapper opts]

View file

@ -153,7 +153,6 @@
(geom/translate-to-frame frame))
opts #js {:shape shape}]
(case (:type shape)
:curve [:> path-wrapper opts]
:text [:> text-wrapper opts]
:rect [:> rect-wrapper opts]
:path [:> path-wrapper opts]

View file

@ -45,31 +45,3 @@
:fill "transparent"
:stroke-width (/ 1 zoom)}}])))
#_(mf/defc path-draw-area
[{:keys [shape] :as props}]
(let [locale (i18n/use-locale)
on-click
(fn [event]
(dom/stop-propagation event)
(st/emit! (dw/assign-cursor-tooltip nil)
(dd/close-drawing-path)))
on-mouse-enter
(fn [event]
(let [msg (t locale "workspace.viewport.click-to-close-path")]
(st/emit! (dw/assign-cursor-tooltip msg))))
on-mouse-leave
(fn [event]
(st/emit! (dw/assign-cursor-tooltip nil)))]
[:g.drawing
[:& shapes/shape-wrapper {:shape shape}]
#_(when (not= :curve (:type shape))
[:circle.close-bezier
{:cx x
:cy y
:r 5
:on-click on-click
:on-mouse-enter on-mouse-enter
:on-mouse-leave on-mouse-leave}])]))

View file

@ -215,44 +215,6 @@
:resize-side [:> resize-side-handler props])))])))
;; --- Selection Handlers (Component)
(mf/defc path-edition-selection-handlers
[{:keys [shape modifiers zoom color] :as props}]
(letfn [(on-mouse-down [event index]
(dom/stop-propagation event)
;; TODO: this need code ux refactor
(let [stoper (get-edition-stream-stoper)
stream (->> (ms/mouse-position-deltas @ms/mouse-position)
(rx/take-until stoper))]
;; (when @refs/selected-alignment
;; (st/emit! (dw/initial-path-point-align (:id shape) index)))
(rx/subscribe stream #(on-handler-move % index))))
(get-edition-stream-stoper []
(let [stoper? #(and (ms/mouse-event? %) (= (:type %) :up))]
(rx/merge
(rx/filter stoper? st/stream)
(->> st/stream
(rx/filter #(= % :interrupt))
(rx/take 1)))))
(on-handler-move [delta index]
(st/emit! (dw/update-path (:id shape) index delta)))]
(let [transform (geom/transform-matrix shape)
displacement (:displacement modifiers)
segments (cond->> (:segments shape)
displacement (map #(gpt/transform % displacement)))]
[:g.controls
(for [[index {:keys [x y]}] (map-indexed vector segments)]
(let [{:keys [x y]} (gpt/transform (gpt/point x y) transform)]
[:circle {:cx x :cy y
:r (/ 6.0 zoom)
:key index
:on-mouse-down #(on-mouse-down % index)
:fill "#ffffff"
:stroke color
:style {:cursor cur/move-pointer}}]))])))
;; TODO: add specs for clarity
(mf/defc text-edition-selection-handlers
@ -372,12 +334,6 @@
[:& path-editor {:zoom zoom
:shape shape}]
(and (= type :curve)
(= edition (:id shape)))
[:& path-edition-selection-handlers {:shape shape
:zoom zoom
:color color}]
:else
[:& single-selection-handlers {:shape shape
:zoom zoom

View file

@ -108,7 +108,6 @@
:on-mouse-leave on-mouse-leave
:style {:cursor (if @alt? cur/duplicate nil)}}
(case (:type shape)
:curve [:> path/path-wrapper opts]
:path [:> path/path-wrapper opts]
:text [:> text/text-wrapper opts]
:group [:> group-wrapper opts]

View file

@ -28,7 +28,7 @@
outline-type (case (:type shape)
:circle "ellipse"
(:curve :path) "path"
:path "path"
"rect")
common {:fill "transparent"
@ -44,7 +44,7 @@
:rx (/ width 2)
:ry (/ height 2)}
(:curve :path)
:path
{:d (path/render-path shape)}
{:x x

View file

@ -129,7 +129,6 @@
:rect i/box
:circle i/circle
:text i/text
:curve i/curve
:path i/curve
:frame i/artboard
:group i/folder
@ -141,7 +140,7 @@
i/layers))
(defn is-shape? [type]
#{:shape :rect :circle :text :curve :path :frame :group})
#{:shape :rect :circle :text :path :frame :group})
(defn parse-entry [{:keys [redo-changes]}]
(->> redo-changes

View file

@ -39,7 +39,6 @@
:circle i/circle
:path i/curve
:rect i/box
:curve i/curve
:text i/text
:group (if (some? (:component-id shape))
i/component

View file

@ -48,7 +48,6 @@
:icon [:& icon/options {:shape shape}]
:circle [:& circle/options {:shape shape}]
:path [:& path/options {:shape shape}]
:curve [:& path/options {:shape shape}]
:image [:& image/options {:shape shape}]
nil)
[:& exports-menu

View file

@ -213,3 +213,18 @@
opposite (gpt/add point (gpt/negate phv))]
opposite))
(defn segments->content [segments]
(let [initial (first segments)
closed? (= (first segments) (last segments))
lines (if closed?
(take (- (count segments) 2) (rest segments))
(rest segments))]
(d/concat [{:command :move-to
:params (select-keys initial [:x :y])}]
(->> lines
(mapv #(hash-map :command :line-to
:params (select-keys % [:x :y]))))
(when closed?
[{:command :close-path}]))))

View file

@ -32,6 +32,4 @@
(let [shape (gsh/transform-shape shape)]
(case (:type shape)
:frame (-> shape :selrect frame-snap-points)
(:path :curve) (-> shape :selrect selrect-snap-points)
(into #{(gsh/center-shape shape)} (:points shape)))
))
(into #{(gsh/center-shape shape)} (:points shape)))))