mirror of
https://github.com/penpot/penpot.git
synced 2025-07-19 16:17:20 +02:00
Add rotatation transformation for rect and circles.
This commit is contained in:
parent
6d980893b9
commit
52f52a5d40
3 changed files with 22 additions and 7 deletions
|
@ -155,10 +155,6 @@
|
||||||
:x2 (+ x1 width)
|
:x2 (+ x1 width)
|
||||||
:y2 (+ y1 height))))
|
:y2 (+ y1 height))))
|
||||||
|
|
||||||
;; (merge shape
|
|
||||||
;; (when width {:width width})
|
|
||||||
;; (when height {:height height})))
|
|
||||||
|
|
||||||
(defmethod -resize' :default
|
(defmethod -resize' :default
|
||||||
[shape _]
|
[shape _]
|
||||||
(throw (ex-info "Not implemented" (select-keys shape [:type]))))
|
(throw (ex-info "Not implemented" (select-keys shape [:type]))))
|
||||||
|
@ -303,6 +299,23 @@
|
||||||
(gmt/translate (- center-x) (- center-y))
|
(gmt/translate (- center-x) (- center-y))
|
||||||
(gmt/scale scale-x scale-y))))
|
(gmt/scale scale-x scale-y))))
|
||||||
|
|
||||||
|
(defmethod -transformation :builtin/rect
|
||||||
|
[{:keys [x1 y1 rotation] :or {rotation 0} :as shape}]
|
||||||
|
(let [{:keys [width height]} (-size shape)
|
||||||
|
center-x (+ x1 (/ width 2))
|
||||||
|
center-y (+ y1 (/ height 2))]
|
||||||
|
(-> (gmt/matrix)
|
||||||
|
(gmt/translate center-x center-y)
|
||||||
|
(gmt/rotate rotation)
|
||||||
|
(gmt/translate (- center-x) (- center-y)))))
|
||||||
|
|
||||||
|
(defmethod -transformation :builtin/circle
|
||||||
|
[{:keys [cx cy rx ry rotation] :or {rotation 0} :as shape}]
|
||||||
|
(-> (gmt/matrix)
|
||||||
|
(gmt/translate cx cy)
|
||||||
|
(gmt/rotate rotation)
|
||||||
|
(gmt/translate (- cx) (- cy))))
|
||||||
|
|
||||||
(declare outer-rect)
|
(declare outer-rect)
|
||||||
|
|
||||||
(defmethod -transformation :builtin/group
|
(defmethod -transformation :builtin/group
|
||||||
|
|
|
@ -70,9 +70,10 @@
|
||||||
(defmethod sh/-render :builtin/circle
|
(defmethod sh/-render :builtin/circle
|
||||||
[{:keys [id] :as shape}]
|
[{:keys [id] :as shape}]
|
||||||
(let [key (str id)
|
(let [key (str id)
|
||||||
|
rfm (sh/-transformation shape)
|
||||||
props (select-keys shape [:cx :cy :rx :ry])
|
props (select-keys shape [:cx :cy :rx :ry])
|
||||||
attrs (-> (extract-style-attrs shape)
|
attrs (-> (extract-style-attrs shape)
|
||||||
(merge {:id key :key key})
|
(merge {:id key :key key :transform (str rfm)})
|
||||||
(merge props))]
|
(merge props))]
|
||||||
(html
|
(html
|
||||||
[:ellipse attrs])))
|
[:ellipse attrs])))
|
||||||
|
@ -80,8 +81,9 @@
|
||||||
(defmethod sh/-render :builtin/rect
|
(defmethod sh/-render :builtin/rect
|
||||||
[{:keys [id x1 y1 x2 y2] :as shape}]
|
[{:keys [id x1 y1 x2 y2] :as shape}]
|
||||||
(let [key (str id)
|
(let [key (str id)
|
||||||
props {:x x1 :y y1 :id key :key key}
|
rfm (sh/-transformation shape)
|
||||||
size (sh/-size shape)
|
size (sh/-size shape)
|
||||||
|
props {:x x1 :y y1 :id key :key key :transform (str rfm)}
|
||||||
attrs (-> (extract-style-attrs shape)
|
attrs (-> (extract-style-attrs shape)
|
||||||
(merge props size))]
|
(merge props size))]
|
||||||
(html
|
(html
|
||||||
|
|
|
@ -102,7 +102,7 @@
|
||||||
(mx/component
|
(mx/component
|
||||||
{:render shape-render
|
{:render shape-render
|
||||||
:name "shape"
|
:name "shape"
|
||||||
:mixins [(mx/local {}) rum/reactive mx/static]}))
|
:mixins [(mx/local {}) rum/reactive]}))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Canvas
|
;; Canvas
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue