From 25fe4f1269628bb2a5cfeb0e32d3062208436cd3 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 24 Nov 2020 09:44:12 +0100 Subject: [PATCH] :recycle: Fixes after review --- common/app/common/geom/shapes.cljc | 22 ++++--- frontend/resources/images/icons/pen.svg | 57 +------------------ frontend/src/app/main/data/workspace.cljs | 2 +- .../app/main/data/workspace/drawing/path.cljs | 33 ++++------- 4 files changed, 30 insertions(+), 84 deletions(-) diff --git a/common/app/common/geom/shapes.cljc b/common/app/common/geom/shapes.cljc index 56fe8ccb6..5109d9d6a 100644 --- a/common/app/common/geom/shapes.cljc +++ b/common/app/common/geom/shapes.cljc @@ -44,18 +44,26 @@ (move shape (gpt/point dx dy)))) ;; --- Resize (Dimensions) -;;; TODO: CHANGE TO USE THE MODIFIERS +;; Fixme: Improve using modifiers instead of calculating the selrect/points (defn resize [shape width height] (us/assert map? shape) (us/assert number? width) (us/assert number? height) - (-> shape - (assoc :width width :height height) - (update :selrect (fn [selrect] - (assoc selrect - :x2 (+ (:x1 selrect) width) - :y2 (+ (:y1 selrect) height)))))) + (let [selrect (-> (:selrect shape) + (assoc :width width) + (assoc :height height) + (assoc :x2 (+ (-> shape :selrect :x1) width)) + (assoc :y2 (+ (-> shape :selrect :y1) height))) + + center (gco/center-selrect selrect) + points (-> selrect gpr/rect->points (gtr/transform-points center (:transform shape)))] + + (-> shape + (assoc :width width) + (assoc :height height) + (assoc :selrect selrect) + (assoc :points points)))) (defn resize-rect [shape attr value] diff --git a/frontend/resources/images/icons/pen.svg b/frontend/resources/images/icons/pen.svg index 9cd783355..cc3c91147 100644 --- a/frontend/resources/images/icons/pen.svg +++ b/frontend/resources/images/icons/pen.svg @@ -1,56 +1,3 @@ - - - - - - image/svg+xml - - - - - - - + + diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index c760d812c..f75a89a67 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -1662,7 +1662,7 @@ "e" #(st/emit! (dwd/select-for-drawing :circle)) "t" #(st/emit! dwtxt/start-edit-if-selected (dwd/select-for-drawing :text)) - "w" #(st/emit! (dwd/select-for-drawing :path)) + "p" #(st/emit! (dwd/select-for-drawing :path)) "ctrl+c" #(st/emit! copy-selected) "ctrl+v" #(st/emit! paste) "ctrl+x" #(st/emit! copy-selected delete-selected) diff --git a/frontend/src/app/main/data/workspace/drawing/path.cljs b/frontend/src/app/main/data/workspace/drawing/path.cljs index 0cc24d467..024e6baee 100644 --- a/frontend/src/app/main/data/workspace/drawing/path.cljs +++ b/frontend/src/app/main/data/workspace/drawing/path.cljs @@ -101,12 +101,7 @@ ;; EVENTS (defn init-path [id] - (ptk/reify ::init-path - ptk/UpdateEvent - (update [_ state] - (-> state - #_(assoc-in [:workspace-drawing :object :initialized?] true) - #_(assoc-in [:workspace-local :edit-path :last-point] nil))))) + (ptk/reify ::init-path)) (defn finish-path [id] (ptk/reify ::finish-path @@ -347,13 +342,11 @@ (make-drag-stream stream %) (make-dbl-click-stream stream %))))] - (->> (rx/concat - (rx/of (init-path id)) - (rx/merge mousemove-events - mousedown-events) - (rx/of (finish-path id)))))))) - - + (rx/concat + (rx/of (init-path id)) + (rx/merge mousemove-events + mousedown-events) + (rx/of (finish-path id))))))) (defn stop-path-edit [] (ptk/reify ::stop-path-edit @@ -417,13 +410,13 @@ (watch [_ state stream] (let [id (get-in state [:workspace-local :edition]) page-id (:current-page-id state) - old-content (get-in state [:workspace-data :pages-index page-id :objects id :content]) - old-selrect (get-in state [:workspace-data :pages-index page-id :objects id :selrect]) - old-points (get-in state [:workspace-data :pages-index page-id :objects id :points]) - content-modifiers (get-in state [:workspace-local :edit-path id :content-modifiers]) + shape (get-in state [:workspace-data :pages-index page-id :objects id]) + {old-content :content old-selrect :selrect old-points :points} shape + content-modifiers (get-in state [:workspace-local :edit-path id :content-modifiers] {}) new-content (ugp/apply-content-modifiers old-content content-modifiers) new-selrect (gsh/content->selrect new-content) new-points (gsh/rect->points new-selrect) + rch [{:type :mod-obj :id id :page-id page-id @@ -456,9 +449,8 @@ old-content (get-in state [:workspace-local :edit-path id :old-content]) old-selrect (gsh/content->selrect old-content) old-points (gsh/rect->points old-content) - new-content (get-in state [:workspace-data :pages-index page-id :objects id :content]) - new-selrect (get-in state [:workspace-data :pages-index page-id :objects id :selrect]) - new-points (get-in state [:workspace-data :pages-index page-id :objects id :points]) + shape (get-in state [:workspace-data :pages-index page-id :objects id]) + {new-content :content new-selrect :selrect new-points :points} shape rch [{:type :mod-obj :id id @@ -491,7 +483,6 @@ content (get-in state (get-path state :content)) old-content (get-in state [:workspace-local :edit-path id :old-content]) mode (get-in state [:workspace-local :edit-path id :edit-mode])] - (cond (not= content old-content) (rx/of (save-path-content)