From fc2399a88537115a2760f0ec819be60ac205d706 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Thu, 10 Feb 2022 10:47:13 +0100 Subject: [PATCH] =?UTF-8?q?:sparkles:=20Rotation=20to=20snap=20to=2015?= =?UTF-8?q?=C2=BA=20intervals=20with=20shift?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGES.md | 2 +- .../app/main/data/workspace/transforms.cljs | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index bcdf071c4..f6dfb0227 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,7 +5,7 @@ ### :boom: Breaking changes ### :sparkles: New features - +- Rotation to snap to 15ยบ intervals with shift [Taiga #2437](https://tree.taiga.io/project/penpot/issue/2437) - Support border radius and stroke properties for images [Taiga #497](https://tree.taiga.io/project/penpot/us/497) - Disallow using same password as user email [Taiga #2454](https://tree.taiga.io/project/penpot/us/2454) - Add configurable nudge amount [Taiga #910](https://tree.taiga.io/project/penpot/us/910) diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index fc0e79248..93cc1fd8e 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -432,24 +432,25 @@ group (gsh/selection-rect shapes) group-center (gsh/center-selrect group) initial-angle (gpt/angle @ms/mouse-position group-center) - calculate-angle (fn [pos ctrl?] + calculate-angle (fn [pos ctrl? shift?] (let [angle (- (gpt/angle pos group-center) initial-angle) angle (if (neg? angle) (+ 360 angle) angle) - modval (mod angle 45) - angle (if ctrl? - (if (< 22.5 modval) - (+ angle (- 45 modval)) - (- angle modval)) - angle) angle (if (= angle 360) 0 + angle) + angle (if ctrl? + (* (mth/floor (/ angle 45)) 45) + angle) + angle (if shift? + (* (mth/floor (/ angle 15)) 15) angle)] angle))] (rx/concat (->> ms/mouse-position (rx/with-latest vector ms/mouse-position-ctrl) - (rx/map (fn [[pos ctrl?]] - (let [delta-angle (calculate-angle pos ctrl?)] + (rx/with-latest vector ms/mouse-position-shift) + (rx/map (fn [[[pos ctrl?] shift?]] + (let [delta-angle (calculate-angle pos ctrl? shift?)] (set-rotation-modifiers delta-angle shapes group-center)))) (rx/take-until stoper)) (rx/of (apply-modifiers (map :id shapes))