Rename :points attr to :segments on path shape.

This commit is contained in:
Andrey Antukh 2017-02-14 21:57:28 +01:00
parent 340a5b3da2
commit e8fcb38597
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
5 changed files with 48 additions and 39 deletions

View file

@ -6,6 +6,7 @@
(ns uxbox.main.ui.shapes.path
(:require [potok.core :as ptk]
[cuerdas.core :as str :include-macros true]
[uxbox.main.store :as st]
[uxbox.main.ui.shapes.common :as common]
[uxbox.main.ui.shapes.attrs :as attrs]
@ -14,7 +15,6 @@
[uxbox.util.geom.matrix :as gmt]
[uxbox.util.geom.point :as gpt]
[uxbox.util.mixins :as mx :include-macros true]))
;; --- Path Component
(declare path-shape)
@ -39,12 +39,25 @@
;; --- Path Shape
(defn- render-path
[{:keys [points close?] :as shape}]
(let [start (first points)
init (str "M " (:x start) " " (:y start))
path (reduce #(str %1 " L" (:x %2) " " (:y %2)) init points)]
(cond-> path
close? (str " Z"))))
[{:keys [segments close?] :as shape}]
(let [numsegs (count segments)]
(loop [buffer []
index 0]
(cond
(>= index numsegs)
(if close?
(str/join " " (conj buffer "Z"))
(str/join " " buffer))
(zero? index)
(let [{:keys [x y] :as segment} (nth segments index)
buffer (conj buffer (str/istr "M~{x},~{y}"))]
(recur buffer (inc index)))
:else
(let [{:keys [x y] :as segment} (nth segments index)
buffer (conj buffer (str/istr "L~{x},~{y}"))]
(recur buffer (inc index)))))))
(mx/defc path-shape
{:mixins [mx/static]}

View file

@ -327,12 +327,12 @@
(rx/subscribe stream on-move))))
(mx/defc path-edition-selection-handlers
[{:keys [id points] :as shape} zoom]
[{:keys [id segments] :as shape} zoom]
(letfn [(on-mouse-down [index event]
(dom/stop-propagation event)
(start-path-edition id index))]
[:g.controls
(for [[index {:keys [x y]}] (map-indexed vector points)]
(for [[index {:keys [x y]}] (map-indexed vector segments)]
[:circle {:cx x :cy y
:r (/ 6.0 zoom)
:on-mouse-down (partial on-mouse-down index)

View file

@ -48,7 +48,7 @@
(shapes/render-component)))
(mx/defc path-draw-area
[{:keys [points] :as shape}]
[{:keys [segments] :as shape}]
(letfn [(on-click [event]
(dom/stop-propagation event)
(st/emit! (udw/set-tooltip nil)
@ -56,12 +56,8 @@
(on-mouse-enter [event]
(st/emit! (udw/set-tooltip "Click to close the path")))
(on-mouse-leave [event]
(st/emit! (udw/set-tooltip nil)))
(drop-last-point [shape]
(let [points (:points shape)
points (vec (butlast points))]
(assoc shape :points points :close? true)))]
(when-let [{:keys [x y]} (first points)]
(st/emit! (udw/set-tooltip nil)))]
(when-let [{:keys [x y] :as segment} (first segments)]
[:g
(-> (assoc shape :drawing? true)
(shapes/render-component))