mirror of
https://github.com/penpot/penpot.git
synced 2025-01-23 23:18:48 -05:00
Rename :points
attr to :segments
on path shape.
This commit is contained in:
parent
340a5b3da2
commit
e8fcb38597
5 changed files with 48 additions and 39 deletions
|
@ -122,7 +122,7 @@
|
||||||
(deftype FinishPathDrawing []
|
(deftype FinishPathDrawing []
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(update-in state [:workspace :drawing :points] #(vec (butlast %)))))
|
(update-in state [:workspace :drawing :segments] #(vec (butlast %)))))
|
||||||
|
|
||||||
(defn finish-path-drawing
|
(defn finish-path-drawing
|
||||||
[]
|
[]
|
||||||
|
@ -133,7 +133,7 @@
|
||||||
(deftype InsertDrawingPathPoint [point]
|
(deftype InsertDrawingPathPoint [point]
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(update-in state [:workspace :drawing :points] (fnil conj []) point)))
|
(update-in state [:workspace :drawing :segments] (fnil conj []) point)))
|
||||||
|
|
||||||
(defn insert-drawing-path-point
|
(defn insert-drawing-path-point
|
||||||
[point]
|
[point]
|
||||||
|
@ -145,9 +145,10 @@
|
||||||
(deftype UpdateDrawingPathPoint [index point]
|
(deftype UpdateDrawingPathPoint [index point]
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(let [points (count (get-in state [:workspace :drawing :points]))]
|
(let [segments (count (get-in state [:workspace :drawing :segments]))
|
||||||
|
exists? (< -1 index segments)]
|
||||||
(cond-> state
|
(cond-> state
|
||||||
(< -1 index points) (assoc-in [:workspace :drawing :points index] point)))))
|
exists? (assoc-in [:workspace :drawing :segments index] point)))))
|
||||||
|
|
||||||
(defn update-drawing-path-point
|
(defn update-drawing-path-point
|
||||||
[index point]
|
[index point]
|
||||||
|
@ -174,7 +175,7 @@
|
||||||
(deftype SimplifyDrawingPath [tolerance]
|
(deftype SimplifyDrawingPath [tolerance]
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
(update-in state [:workspace :drawing :points] pth/simplify tolerance)))
|
(update-in state [:workspace :drawing :segments] pth/simplify tolerance)))
|
||||||
|
|
||||||
(defn simplify-drawing-path
|
(defn simplify-drawing-path
|
||||||
[tolerance]
|
[tolerance]
|
||||||
|
|
|
@ -5,8 +5,7 @@
|
||||||
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
|
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
|
||||||
|
|
||||||
(ns uxbox.main.geom
|
(ns uxbox.main.geom
|
||||||
(:require [cljs.pprint :refer [pprint]]
|
(:require [uxbox.util.geom.matrix :as gmt]
|
||||||
[uxbox.util.geom.matrix :as gmt]
|
|
||||||
[uxbox.util.geom.point :as gpt]
|
[uxbox.util.geom.point :as gpt]
|
||||||
[uxbox.util.math :as mth]
|
[uxbox.util.math :as mth]
|
||||||
[uxbox.main.store :as st]))
|
[uxbox.main.store :as st]))
|
||||||
|
@ -61,11 +60,11 @@
|
||||||
"A specialized function for relative movement
|
"A specialized function for relative movement
|
||||||
for path shapes."
|
for path shapes."
|
||||||
[shape {dx :x dy :y}]
|
[shape {dx :x dy :y}]
|
||||||
(let [points (:points shape)
|
(let [segments (:segments shape)
|
||||||
xf (comp
|
xf (comp
|
||||||
(map #(update % :x + dx))
|
(map #(update % :x + dx))
|
||||||
(map #(update % :y + dy)))]
|
(map #(update % :y + dy)))]
|
||||||
(assoc shape :points (into [] xf points))))
|
(assoc shape :segments (into [] xf segments))))
|
||||||
|
|
||||||
;; --- Absolute Movement
|
;; --- Absolute Movement
|
||||||
|
|
||||||
|
@ -134,15 +133,15 @@
|
||||||
:path (size-path shape)))
|
:path (size-path shape)))
|
||||||
|
|
||||||
(defn- size-path
|
(defn- size-path
|
||||||
[{:keys [points x1 y1 x2 y2] :as shape}]
|
[{:keys [segments x1 y1 x2 y2] :as shape}]
|
||||||
(if (and x1 y1 x2 y2)
|
(if (and x1 y1 x2 y2)
|
||||||
(assoc shape
|
(assoc shape
|
||||||
:width (- x2 x1)
|
:width (- x2 x1)
|
||||||
:height (- y2 y1))
|
:height (- y2 y1))
|
||||||
(let [minx (apply min (map :x points))
|
(let [minx (apply min (map :x segments))
|
||||||
miny (apply min (map :y points))
|
miny (apply min (map :y segments))
|
||||||
maxx (apply max (map :x points))
|
maxx (apply max (map :x segments))
|
||||||
maxy (apply max (map :y points))]
|
maxy (apply max (map :y segments))]
|
||||||
(assoc shape
|
(assoc shape
|
||||||
:width (- maxx minx)
|
:width (- maxx minx)
|
||||||
:height (- maxy miny)))))
|
:height (- maxy miny)))))
|
||||||
|
@ -169,7 +168,7 @@
|
||||||
The point should exists before, this function
|
The point should exists before, this function
|
||||||
does not adds it automatically."
|
does not adds it automatically."
|
||||||
[shape index point]
|
[shape index point]
|
||||||
(assoc-in shape [:points index] point))
|
(assoc-in shape [:segments index] point))
|
||||||
|
|
||||||
;; --- Setup Proportions
|
;; --- Setup Proportions
|
||||||
|
|
||||||
|
@ -407,11 +406,11 @@
|
||||||
(assoc :id id))))
|
(assoc :id id))))
|
||||||
|
|
||||||
(defn- path->rect-shape
|
(defn- path->rect-shape
|
||||||
[state {:keys [points] :as shape}]
|
[state {:keys [segments] :as shape}]
|
||||||
(let [minx (apply min (map :x points))
|
(let [minx (apply min (map :x segments))
|
||||||
miny (apply min (map :y points))
|
miny (apply min (map :y segments))
|
||||||
maxx (apply max (map :x points))
|
maxx (apply max (map :x segments))
|
||||||
maxy (apply max (map :y points))]
|
maxy (apply max (map :y segments))]
|
||||||
(assoc shape
|
(assoc shape
|
||||||
:x1 minx
|
:x1 minx
|
||||||
:y1 miny
|
:y1 miny
|
||||||
|
@ -485,9 +484,9 @@
|
||||||
(assoc shape :cx cx :cy cy :rx rx :ry ry)))
|
(assoc shape :cx cx :cy cy :rx rx :ry ry)))
|
||||||
|
|
||||||
(defn- transform-path
|
(defn- transform-path
|
||||||
[{:keys [points] :as shape} xfmt]
|
[{:keys [segments] :as shape} xfmt]
|
||||||
(let [points (mapv #(gpt/transform % xfmt) points)]
|
(let [segments (mapv #(gpt/transform % xfmt) segments)]
|
||||||
(assoc shape :points points)))
|
(assoc shape :segments segments)))
|
||||||
|
|
||||||
;; --- Outer Rect
|
;; --- Outer Rect
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
(ns uxbox.main.ui.shapes.path
|
(ns uxbox.main.ui.shapes.path
|
||||||
(:require [potok.core :as ptk]
|
(:require [potok.core :as ptk]
|
||||||
|
[cuerdas.core :as str :include-macros true]
|
||||||
[uxbox.main.store :as st]
|
[uxbox.main.store :as st]
|
||||||
[uxbox.main.ui.shapes.common :as common]
|
[uxbox.main.ui.shapes.common :as common]
|
||||||
[uxbox.main.ui.shapes.attrs :as attrs]
|
[uxbox.main.ui.shapes.attrs :as attrs]
|
||||||
|
@ -14,7 +15,6 @@
|
||||||
[uxbox.util.geom.matrix :as gmt]
|
[uxbox.util.geom.matrix :as gmt]
|
||||||
[uxbox.util.geom.point :as gpt]
|
[uxbox.util.geom.point :as gpt]
|
||||||
[uxbox.util.mixins :as mx :include-macros true]))
|
[uxbox.util.mixins :as mx :include-macros true]))
|
||||||
|
|
||||||
;; --- Path Component
|
;; --- Path Component
|
||||||
|
|
||||||
(declare path-shape)
|
(declare path-shape)
|
||||||
|
@ -39,12 +39,25 @@
|
||||||
;; --- Path Shape
|
;; --- Path Shape
|
||||||
|
|
||||||
(defn- render-path
|
(defn- render-path
|
||||||
[{:keys [points close?] :as shape}]
|
[{:keys [segments close?] :as shape}]
|
||||||
(let [start (first points)
|
(let [numsegs (count segments)]
|
||||||
init (str "M " (:x start) " " (:y start))
|
(loop [buffer []
|
||||||
path (reduce #(str %1 " L" (:x %2) " " (:y %2)) init points)]
|
index 0]
|
||||||
(cond-> path
|
(cond
|
||||||
close? (str " Z"))))
|
(>= 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
|
(mx/defc path-shape
|
||||||
{:mixins [mx/static]}
|
{:mixins [mx/static]}
|
||||||
|
|
|
@ -327,12 +327,12 @@
|
||||||
(rx/subscribe stream on-move))))
|
(rx/subscribe stream on-move))))
|
||||||
|
|
||||||
(mx/defc path-edition-selection-handlers
|
(mx/defc path-edition-selection-handlers
|
||||||
[{:keys [id points] :as shape} zoom]
|
[{:keys [id segments] :as shape} zoom]
|
||||||
(letfn [(on-mouse-down [index event]
|
(letfn [(on-mouse-down [index event]
|
||||||
(dom/stop-propagation event)
|
(dom/stop-propagation event)
|
||||||
(start-path-edition id index))]
|
(start-path-edition id index))]
|
||||||
[:g.controls
|
[: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
|
[:circle {:cx x :cy y
|
||||||
:r (/ 6.0 zoom)
|
:r (/ 6.0 zoom)
|
||||||
:on-mouse-down (partial on-mouse-down index)
|
:on-mouse-down (partial on-mouse-down index)
|
||||||
|
|
|
@ -48,7 +48,7 @@
|
||||||
(shapes/render-component)))
|
(shapes/render-component)))
|
||||||
|
|
||||||
(mx/defc path-draw-area
|
(mx/defc path-draw-area
|
||||||
[{:keys [points] :as shape}]
|
[{:keys [segments] :as shape}]
|
||||||
(letfn [(on-click [event]
|
(letfn [(on-click [event]
|
||||||
(dom/stop-propagation event)
|
(dom/stop-propagation event)
|
||||||
(st/emit! (udw/set-tooltip nil)
|
(st/emit! (udw/set-tooltip nil)
|
||||||
|
@ -56,12 +56,8 @@
|
||||||
(on-mouse-enter [event]
|
(on-mouse-enter [event]
|
||||||
(st/emit! (udw/set-tooltip "Click to close the path")))
|
(st/emit! (udw/set-tooltip "Click to close the path")))
|
||||||
(on-mouse-leave [event]
|
(on-mouse-leave [event]
|
||||||
(st/emit! (udw/set-tooltip nil)))
|
(st/emit! (udw/set-tooltip nil)))]
|
||||||
(drop-last-point [shape]
|
(when-let [{:keys [x y] :as segment} (first segments)]
|
||||||
(let [points (:points shape)
|
|
||||||
points (vec (butlast points))]
|
|
||||||
(assoc shape :points points :close? true)))]
|
|
||||||
(when-let [{:keys [x y]} (first points)]
|
|
||||||
[:g
|
[:g
|
||||||
(-> (assoc shape :drawing? true)
|
(-> (assoc shape :drawing? true)
|
||||||
(shapes/render-component))
|
(shapes/render-component))
|
||||||
|
|
Loading…
Add table
Reference in a new issue