mirror of
https://github.com/penpot/penpot.git
synced 2025-01-25 07:58:49 -05:00
Merge remote-tracking branch 'origin/main' into staging
This commit is contained in:
commit
0612e71166
5 changed files with 37 additions and 13 deletions
|
@ -246,6 +246,11 @@
|
||||||
dist (distance line-point2 line-point1)]
|
dist (distance line-point2 line-point1)]
|
||||||
(/ num dist)))
|
(/ num dist)))
|
||||||
|
|
||||||
|
(defn almost-zero? [{:keys [x y] :as p}]
|
||||||
|
(assert (point? p))
|
||||||
|
(and (mth/almost-zero? x)
|
||||||
|
(mth/almost-zero? y)))
|
||||||
|
|
||||||
|
|
||||||
;; --- Debug
|
;; --- Debug
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,12 @@
|
||||||
[[p1 _ p3 p4]]
|
[[p1 _ p3 p4]]
|
||||||
(let [v1 (gpt/to-vec p3 p4)
|
(let [v1 (gpt/to-vec p3 p4)
|
||||||
v2 (gpt/to-vec p4 p1)]
|
v2 (gpt/to-vec p4 p1)]
|
||||||
(- 90 (gpt/angle-with-other v1 v2))))
|
;; If one of the vectors is zero it's a rectangle with 0 height or width
|
||||||
|
;; We don't skew these
|
||||||
|
(if (or (gpt/almost-zero? v1)
|
||||||
|
(gpt/almost-zero? v2))
|
||||||
|
0
|
||||||
|
(- 90 (gpt/angle-with-other v1 v2)))))
|
||||||
|
|
||||||
(defn- calculate-height
|
(defn- calculate-height
|
||||||
"Calculates the height of a paralelogram given by the points"
|
"Calculates the height of a paralelogram given by the points"
|
||||||
|
@ -142,7 +147,7 @@
|
||||||
|
|
||||||
(defn- calculate-rotation
|
(defn- calculate-rotation
|
||||||
"Calculates the rotation between two shapes given the resize vector direction"
|
"Calculates the rotation between two shapes given the resize vector direction"
|
||||||
[points-shape1 points-shape2 flip-x flip-y]
|
[center points-shape1 points-shape2 flip-x flip-y]
|
||||||
|
|
||||||
(let [idx-1 0
|
(let [idx-1 0
|
||||||
idx-2 (cond (and flip-x (not flip-y)) 1
|
idx-2 (cond (and flip-x (not flip-y)) 1
|
||||||
|
@ -151,8 +156,8 @@
|
||||||
:else 0)
|
:else 0)
|
||||||
p1 (nth points-shape1 idx-1)
|
p1 (nth points-shape1 idx-1)
|
||||||
p2 (nth points-shape2 idx-2)
|
p2 (nth points-shape2 idx-2)
|
||||||
v1 (gpt/to-vec (gco/center-points points-shape1) p1)
|
v1 (gpt/to-vec center p1)
|
||||||
v2 (gpt/to-vec (gco/center-points points-shape2) p2)
|
v2 (gpt/to-vec center p2)
|
||||||
|
|
||||||
rot-angle (gpt/angle-with-other v1 v2)
|
rot-angle (gpt/angle-with-other v1 v2)
|
||||||
rot-sign (if (> (* (:y v1) (:x v2)) (* (:x v1) (:y v2))) -1 1)]
|
rot-sign (if (> (* (:y v1) (:x v2)) (* (:x v1) (:y v2))) -1 1)]
|
||||||
|
@ -183,14 +188,15 @@
|
||||||
|
|
||||||
stretch-matrix (gmt/multiply stretch-matrix (gmt/skew-matrix skew-angle 0))
|
stretch-matrix (gmt/multiply stretch-matrix (gmt/skew-matrix skew-angle 0))
|
||||||
|
|
||||||
h1 (calculate-height points-temp)
|
h1 (max 1 (calculate-height points-temp))
|
||||||
h2 (calculate-height (transform-points points-rec center stretch-matrix))
|
h2 (max 1 (calculate-height (transform-points points-rec center stretch-matrix)))
|
||||||
h3 (if-not (mth/almost-zero? h2) (/ h1 h2) 1)
|
h3 (if-not (mth/almost-zero? h2) (/ h1 h2) 1)
|
||||||
h3 (if (mth/nan? h3) 1 h3)
|
h3 (if (mth/nan? h3) 1 h3)
|
||||||
|
|
||||||
stretch-matrix (gmt/multiply stretch-matrix (gmt/scale-matrix (gpt/point 1 h3)))
|
stretch-matrix (gmt/multiply stretch-matrix (gmt/scale-matrix (gpt/point 1 h3)))
|
||||||
|
|
||||||
rotation-angle (calculate-rotation
|
rotation-angle (calculate-rotation
|
||||||
|
center
|
||||||
(transform-points points-rec (gco/center-points points-rec) stretch-matrix)
|
(transform-points points-rec (gco/center-points points-rec) stretch-matrix)
|
||||||
points-temp
|
points-temp
|
||||||
flip-x
|
flip-x
|
||||||
|
@ -222,9 +228,13 @@
|
||||||
|
|
||||||
;; This rectangle is the new data for the current rectangle. We want to change our rectangle
|
;; This rectangle is the new data for the current rectangle. We want to change our rectangle
|
||||||
;; to have this width, height, x, y
|
;; to have this width, height, x, y
|
||||||
rect-shape (gco/make-centered-rect center
|
rect-shape (-> (gco/make-centered-rect
|
||||||
(:width points-temp-dim)
|
center
|
||||||
(:height points-temp-dim))
|
(:width points-temp-dim)
|
||||||
|
(:height points-temp-dim))
|
||||||
|
(update :width max 1)
|
||||||
|
(update :height max 1))
|
||||||
|
|
||||||
rect-points (gpr/rect->points rect-shape)
|
rect-points (gpr/rect->points rect-shape)
|
||||||
|
|
||||||
[matrix matrix-inverse] (calculate-adjust-matrix points-temp rect-points (:flip-x shape) (:flip-y shape))
|
[matrix matrix-inverse] (calculate-adjust-matrix points-temp rect-points (:flip-x shape) (:flip-y shape))
|
||||||
|
|
|
@ -90,8 +90,8 @@
|
||||||
path)))
|
path)))
|
||||||
|
|
||||||
(defn- points->components [shape content]
|
(defn- points->components [shape content]
|
||||||
(let [transform (:transform shape)
|
(let [transform (:transform shape (gmt/matrix))
|
||||||
transform-inverse (:transform-inverse shape)
|
transform-inverse (:transform-inverse shape (gmt/matrix))
|
||||||
center (gsh/center-shape shape)
|
center (gsh/center-shape shape)
|
||||||
base-content (gsh/transform-content
|
base-content (gsh/transform-content
|
||||||
content
|
content
|
||||||
|
|
|
@ -36,7 +36,9 @@
|
||||||
(mf/defc radial-gradient [{:keys [id gradient shape]}]
|
(mf/defc radial-gradient [{:keys [id gradient shape]}]
|
||||||
(let [{:keys [x y width height]} (:selrect shape)
|
(let [{:keys [x y width height]} (:selrect shape)
|
||||||
center (gsh/center-shape shape)
|
center (gsh/center-shape shape)
|
||||||
transform (when (= :path (:type shape)) (gsh/transform-matrix shape))]
|
transform (if (= :path (:type shape))
|
||||||
|
(gsh/transform-matrix shape)
|
||||||
|
(gmt/matrix))]
|
||||||
(let [[x y] (if (= (:type shape) :frame) [0 0] [x y])
|
(let [[x y] (if (= (:type shape) :frame) [0 0] [x y])
|
||||||
translate-vec (gpt/point (+ x (* width (:start-x gradient)))
|
translate-vec (gpt/point (+ x (* width (:start-x gradient)))
|
||||||
(+ y (* height (:start-y gradient))))
|
(+ y (* height (:start-y gradient))))
|
||||||
|
|
|
@ -220,6 +220,11 @@
|
||||||
(fn [event]
|
(fn [event]
|
||||||
(dwt/editor-select-all! editor))
|
(dwt/editor-select-all! editor))
|
||||||
|
|
||||||
|
on-composition-start
|
||||||
|
(mf/use-callback
|
||||||
|
(fn [event]
|
||||||
|
(.insertText slate/Editor editor "")))
|
||||||
|
|
||||||
on-change
|
on-change
|
||||||
(mf/use-callback
|
(mf/use-callback
|
||||||
(fn [val]
|
(fn [val]
|
||||||
|
@ -261,7 +266,9 @@
|
||||||
(dom/stop-propagation event)
|
(dom/stop-propagation event)
|
||||||
;; WARN: monky patch
|
;; WARN: monky patch
|
||||||
(obj/set! slate/Transforms "deselect" (constantly nil)))
|
(obj/set! slate/Transforms "deselect" (constantly nil)))
|
||||||
:placeholder (when (= :fixed grow-type) "Type some text here...")}]]]))
|
:on-composition-start on-composition-start
|
||||||
|
;; :placeholder (when (= :fixed grow-type) "Type some text here...")
|
||||||
|
}]]]))
|
||||||
|
|
||||||
(mf/defc text-shape-edit
|
(mf/defc text-shape-edit
|
||||||
{::mf/wrap [mf/memo]
|
{::mf/wrap [mf/memo]
|
||||||
|
|
Loading…
Add table
Reference in a new issue