mirror of
https://github.com/penpot/penpot.git
synced 2025-02-03 21:09:00 -05:00
Continue work on draw tools.
This commit is contained in:
parent
f17da9cb46
commit
d4e6471d11
4 changed files with 43 additions and 6 deletions
|
@ -133,12 +133,12 @@
|
||||||
(-apply-update [_ state]
|
(-apply-update [_ state]
|
||||||
(let [sid (random-uuid)
|
(let [sid (random-uuid)
|
||||||
pid (get-in state [:workspace :page])
|
pid (get-in state [:workspace :page])
|
||||||
shape (merge shape props {:id sid :page pid})]
|
shape (merge (sh/-initialize shape props)
|
||||||
|
shape {:id sid :page pid})]
|
||||||
(as-> state $
|
(as-> state $
|
||||||
(update-in $ [:pages-by-id pid :shapes] conj sid)
|
(update-in $ [:pages-by-id pid :shapes] conj sid)
|
||||||
(assoc-in $ [:shapes-by-id sid] shape))))))
|
(assoc-in $ [:shapes-by-id sid] shape))))))
|
||||||
|
|
||||||
|
|
||||||
(defn delete-shape
|
(defn delete-shape
|
||||||
"Remove the shape using its id."
|
"Remove the shape using its id."
|
||||||
[id]
|
[id]
|
||||||
|
|
|
@ -49,26 +49,62 @@
|
||||||
dispatch-by-type
|
dispatch-by-type
|
||||||
:hierarchy #'+hierarchy+)
|
:hierarchy #'+hierarchy+)
|
||||||
|
|
||||||
|
;; Used for calculate the outer rect that wraps
|
||||||
|
;; up the whole underlying shape. Mostly used
|
||||||
|
;; for calculate the shape or shapes selection
|
||||||
|
;; rectangle.
|
||||||
|
|
||||||
(defmulti -outer-rect
|
(defmulti -outer-rect
|
||||||
dispatch-by-type
|
dispatch-by-type
|
||||||
:hierarchy #'+hierarchy+)
|
:hierarchy #'+hierarchy+)
|
||||||
|
|
||||||
|
;; Used for create the final shape data structure
|
||||||
|
;; from initial shape data structure and final
|
||||||
|
;; canvas position.
|
||||||
|
|
||||||
|
(defmulti -initialize
|
||||||
|
dispatch-by-type
|
||||||
|
:hierarchy #'+hierarchy+)
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Implementation
|
;; Implementation
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(defmethod -initialize ::shape
|
||||||
|
[shape props]
|
||||||
|
(merge shape props))
|
||||||
|
|
||||||
|
(defmethod -initialize :builtin/line
|
||||||
|
[shape {:keys [x y width height]}]
|
||||||
|
(merge shape
|
||||||
|
{:x1 x :y1 y
|
||||||
|
:x2 (+ x width)
|
||||||
|
:y2 (+ y height)}))
|
||||||
|
|
||||||
(defmethod -move ::shape
|
(defmethod -move ::shape
|
||||||
[shape {:keys [dx dy] :as opts}]
|
[shape {:keys [dx dy] :as opts}]
|
||||||
(assoc shape
|
(assoc shape
|
||||||
:x (+ (:x shape) dx)
|
:x (+ (:x shape) dx)
|
||||||
:y (+ (:y shape) dy)))
|
:y (+ (:y shape) dy)))
|
||||||
|
|
||||||
|
(defmethod -move :builtin/line
|
||||||
|
[shape {:keys [dx dy] :as opts}]
|
||||||
|
(assoc shape
|
||||||
|
:x1 (+ (:x1 shape) dx)
|
||||||
|
:y1 (+ (:y1 shape) dy)
|
||||||
|
:x2 (+ (:x2 shape) dx)
|
||||||
|
:y2 (+ (:y2 shape) dy)))
|
||||||
|
|
||||||
(defmethod -resize ::shape
|
(defmethod -resize ::shape
|
||||||
[shape {:keys [width height] :as opts}]
|
[shape {:keys [width height] :as opts}]
|
||||||
(assoc shape
|
(assoc shape
|
||||||
:width width
|
:width width
|
||||||
:height height))
|
:height height))
|
||||||
|
|
||||||
|
(defmethod -resize :builtin/line
|
||||||
|
[shape {:keys [width height] :as opts}]
|
||||||
|
(throw (ex-info "Not implemented" {})))
|
||||||
|
|
||||||
(defmethod -rotate ::shape
|
(defmethod -rotate ::shape
|
||||||
[shape rotation]
|
[shape rotation]
|
||||||
(assoc shape :rotation rotation))
|
(assoc shape :rotation rotation))
|
||||||
|
|
|
@ -66,9 +66,10 @@
|
||||||
(defmethod shapes/-render :builtin/line
|
(defmethod shapes/-render :builtin/line
|
||||||
[{:keys [id view-box] :as shape} _]
|
[{:keys [id view-box] :as shape} _]
|
||||||
(let [key (str id)
|
(let [key (str id)
|
||||||
rfm (svg/calculate-transform shape)
|
;; rfm (svg/calculate-transform shape)
|
||||||
attrs (merge (extract-attrs shape)
|
attrs (extract-attrs shape)]
|
||||||
(make-debug-attrs shape))]
|
;; attrs (merge (extract-attrs shape)
|
||||||
|
;; (make-debug-attrs shape))]
|
||||||
(html
|
(html
|
||||||
[:g {:id key :key key}
|
[:g {:id key :key key}
|
||||||
[:line attrs]])))
|
[:line attrs]])))
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
{:builtin/icon [:menu/measures :menu/fill :menu/stroke]
|
{:builtin/icon [:menu/measures :menu/fill :menu/stroke]
|
||||||
:builtin/rect [:menu/measures :menu/fill :menu/stroke]
|
:builtin/rect [:menu/measures :menu/fill :menu/stroke]
|
||||||
:builtin/circle [:menu/measures :menu/fill :menu/stroke]
|
:builtin/circle [:menu/measures :menu/fill :menu/stroke]
|
||||||
:builtin/line [:menu/measures :menu/stroke]
|
:builtin/line [:menu/stroke]
|
||||||
:builtin/group [:menu/measures]})
|
:builtin/group [:menu/measures]})
|
||||||
|
|
||||||
(def +menus-by-id+
|
(def +menus-by-id+
|
||||||
|
|
Loading…
Add table
Reference in a new issue