0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 23:49:45 -05:00

Continue work on draw tools.

This commit is contained in:
Andrey Antukh 2016-01-24 13:13:48 +02:00
parent f17da9cb46
commit d4e6471d11
4 changed files with 43 additions and 6 deletions

View file

@ -133,12 +133,12 @@
(-apply-update [_ state]
(let [sid (random-uuid)
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 $
(update-in $ [:pages-by-id pid :shapes] conj sid)
(assoc-in $ [:shapes-by-id sid] shape))))))
(defn delete-shape
"Remove the shape using its id."
[id]

View file

@ -49,26 +49,62 @@
dispatch-by-type
: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
dispatch-by-type
: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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(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
[shape {:keys [dx dy] :as opts}]
(assoc shape
:x (+ (:x shape) dx)
: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
[shape {:keys [width height] :as opts}]
(assoc shape
:width width
:height height))
(defmethod -resize :builtin/line
[shape {:keys [width height] :as opts}]
(throw (ex-info "Not implemented" {})))
(defmethod -rotate ::shape
[shape rotation]
(assoc shape :rotation rotation))

View file

@ -66,9 +66,10 @@
(defmethod shapes/-render :builtin/line
[{:keys [id view-box] :as shape} _]
(let [key (str id)
rfm (svg/calculate-transform shape)
attrs (merge (extract-attrs shape)
(make-debug-attrs shape))]
;; rfm (svg/calculate-transform shape)
attrs (extract-attrs shape)]
;; attrs (merge (extract-attrs shape)
;; (make-debug-attrs shape))]
(html
[:g {:id key :key key}
[:line attrs]])))

View file

@ -17,7 +17,7 @@
{:builtin/icon [:menu/measures :menu/fill :menu/stroke]
:builtin/rect [: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]})
(def +menus-by-id+