diff --git a/common/src/app/common/geom/shapes.cljc b/common/src/app/common/geom/shapes.cljc index 8d56036a0b..54c07a5701 100644 --- a/common/src/app/common/geom/shapes.cljc +++ b/common/src/app/common/geom/shapes.cljc @@ -160,6 +160,7 @@ (dm/export gpr/join-selrects) (dm/export gpr/contains-selrect?) (dm/export gpr/contains-point?) +(dm/export gpr/close-selrect?) (dm/export gtr/move) (dm/export gtr/absolute-move) @@ -170,6 +171,7 @@ (dm/export gtr/calculate-adjust-matrix) (dm/export gtr/update-group-selrect) (dm/export gtr/update-mask-selrect) +(dm/export gtr/update-bool-selrect) (dm/export gtr/transform-shape) (dm/export gtr/transform-selrect) (dm/export gtr/transform-selrect-matrix) @@ -194,7 +196,7 @@ (dm/export gin/rect-contains-shape?) ;; Bool -(dm/export gsb/update-bool-selrect) + (dm/export gsb/calc-bool-content) ;; Constraints diff --git a/common/src/app/common/geom/shapes/bool.cljc b/common/src/app/common/geom/shapes/bool.cljc index f404e680c8..a3a4645440 100644 --- a/common/src/app/common/geom/shapes/bool.cljc +++ b/common/src/app/common/geom/shapes/bool.cljc @@ -7,8 +7,6 @@ (ns app.common.geom.shapes.bool (:require [app.common.data :as d] - [app.common.geom.shapes.path :as gsp] - [app.common.geom.shapes.transforms :as gtr] [app.common.path.bool :as pb] [app.common.path.shapes-to-path :as stp])) @@ -25,17 +23,5 @@ (into [] extract-content-xf (:shapes shape))] (pb/content-bool (:bool-type shape) shapes-content))) -(defn update-bool-selrect - "Calculates the selrect+points for the boolean shape" - [shape children objects] - (let [bool-content (calc-bool-content shape objects) - shape (assoc shape :bool-content bool-content) - [points selrect] (gsp/content->points+selrect shape bool-content)] - - (if (and (some? selrect) (d/not-empty? points)) - (-> shape - (assoc :selrect selrect) - (assoc :points points)) - (gtr/update-group-selrect shape children)))) diff --git a/common/src/app/common/geom/shapes/modifiers.cljc b/common/src/app/common/geom/shapes/modifiers.cljc index 3c77f4a6fc..36265536ab 100644 --- a/common/src/app/common/geom/shapes/modifiers.cljc +++ b/common/src/app/common/geom/shapes/modifiers.cljc @@ -133,13 +133,17 @@ [modif-tree objects parent] (letfn [(apply-modifiers [modif-tree child] - (let [modifiers (dm/get-in modif-tree [(:id child) :modifiers])] - (cond-> child - (and (not (cph/group-shape? child)) (some? modifiers)) - (gtr/transform-shape modifiers) + (let [modifiers (-> (dm/get-in modif-tree [(:id child) :modifiers]) + (ctm/select-geometry))] + (cond + (cph/group-like-shape? child) + (gtr/apply-group-modifiers child objects modif-tree) - (cph/group-shape? child) - (gtr/apply-group-modifiers objects modif-tree)))) + (some? modifiers) + (gtr/transform-shape child modifiers) + + :else + child))) (set-child-modifiers [parent [layout-line modif-tree] child] (let [[modifiers layout-line] @@ -208,7 +212,8 @@ [objects ignore-constraints [modif-tree autolayouts] parent] (let [parent-id (:id parent) root? (= uuid/zero parent-id) - modifiers (dm/get-in modif-tree [parent-id :modifiers]) + modifiers (-> (dm/get-in modif-tree [parent-id :modifiers]) + (ctm/select-geometry)) transformed-parent (gtr/transform-shape parent modifiers) has-modifiers? (ctm/child-modifiers? modifiers) @@ -233,10 +238,9 @@ (defn- apply-structure-modifiers [objects modif-tree] (letfn [(apply-shape [objects [id {:keys [modifiers]}]] - (if (ctm/has-structure? modifiers) - (let [shape (get objects id)] - (update objects id ctm/apply-structure-modifiers modifiers)) - objects))] + (cond-> objects + (ctm/has-structure? modifiers) + (update id ctm/apply-structure-modifiers modifiers)))] (reduce apply-shape objects modif-tree))) (defn- apply-partial-objects-modifiers diff --git a/common/src/app/common/geom/shapes/transforms.cljc b/common/src/app/common/geom/shapes/transforms.cljc index f2c63f5df6..e8c942fd63 100644 --- a/common/src/app/common/geom/shapes/transforms.cljc +++ b/common/src/app/common/geom/shapes/transforms.cljc @@ -10,6 +10,7 @@ [app.common.data.macros :as dm] [app.common.geom.matrix :as gmt] [app.common.geom.point :as gpt] + [app.common.geom.shapes.bool :as gshb] [app.common.geom.shapes.common :as gco] [app.common.geom.shapes.path :as gpa] [app.common.geom.shapes.rect :as gpr] @@ -408,6 +409,20 @@ (assoc :flip-x (-> mask :flip-x)) (assoc :flip-y (-> mask :flip-y))))) +(defn update-bool-selrect + "Calculates the selrect+points for the boolean shape" + [shape children objects] + + (let [bool-content (gshb/calc-bool-content shape objects) + shape (assoc shape :bool-content bool-content) + [points selrect] (gpa/content->points+selrect shape bool-content)] + + (if (and (some? selrect) (d/not-empty? points)) + (-> shape + (assoc :selrect selrect) + (assoc :points points)) + (update-group-selrect shape children)))) + (defn transform-shape ([shape] (let [modifiers (:modifiers shape)] @@ -513,6 +528,9 @@ (cph/mask-shape? group) (update-mask-selrect group children) + (cph/bool-shape? group) + (transform-shape group modifiers) + (cph/group-shape? group) (update-group-selrect group children) diff --git a/common/src/app/common/pages/changes.cljc b/common/src/app/common/pages/changes.cljc index 9e60acfd0d..cee62de190 100644 --- a/common/src/app/common/pages/changes.cljc +++ b/common/src/app/common/pages/changes.cljc @@ -11,7 +11,6 @@ [app.common.data.macros :as dm] [app.common.exceptions :as ex] [app.common.geom.shapes :as gsh] - [app.common.geom.shapes.bool :as gshb] [app.common.math :as mth] [app.common.pages.common :refer [component-sync-attrs]] [app.common.pages.helpers :as cph] @@ -170,7 +169,7 @@ group (= :bool (:type group)) - (gshb/update-bool-selrect group children objects) + (gsh/update-bool-selrect group children objects) (:masked-group? group) (set-mask-selrect group children) diff --git a/common/src/app/common/pages/changes_builder.cljc b/common/src/app/common/pages/changes_builder.cljc index 52eae30f86..77e232f3bd 100644 --- a/common/src/app/common/pages/changes_builder.cljc +++ b/common/src/app/common/pages/changes_builder.cljc @@ -12,8 +12,6 @@ [app.common.geom.matrix :as gmt] [app.common.geom.point :as gpt] [app.common.geom.shapes :as gsh] - [app.common.geom.shapes.bool :as gshb] - [app.common.geom.shapes.rect :as gshr] [app.common.math :as mth] [app.common.pages :as cp] [app.common.pages.helpers :as cph] @@ -419,7 +417,7 @@ (every? #(apply gpt/close? %) (d/zip old-val new-val)) (= attr :selrect) - (gshr/close-selrect? old-val new-val) + (gsh/close-selrect? old-val new-val) :else (= old-val new-val))] @@ -438,7 +436,7 @@ nil ;; so it does not need resize (= (:type parent) :bool) - (gshb/update-bool-selrect parent children objects) + (gsh/update-bool-selrect parent children objects) (= (:type parent) :group) (if (:masked-group? parent) diff --git a/frontend/src/app/main/data/workspace/modifiers.cljs b/frontend/src/app/main/data/workspace/modifiers.cljs index f76c36d0f9..9b3766e595 100644 --- a/frontend/src/app/main/data/workspace/modifiers.cljs +++ b/frontend/src/app/main/data/workspace/modifiers.cljs @@ -150,6 +150,19 @@ child-set (set (get-in objects [target-frame :shapes])) layout? (ctl/layout? objects target-frame) + set-parent-ids + (fn [modif-tree shapes target-frame] + (reduce + (fn [modif-tree id] + (update-in + modif-tree + [id :modifiers] + #(-> % + (ctm/change-property :frame-id target-frame) + (ctm/change-property :parent-id target-frame)))) + modif-tree + shapes)) + update-frame-modifiers (fn [modif-tree [original-frame shapes]] (let [shapes (->> shapes (d/removev #(= target-frame %))) @@ -160,7 +173,8 @@ (cond-> modif-tree (not= original-frame target-frame) (-> (update-in [original-frame :modifiers] ctm/remove-children shapes) - (update-in [target-frame :modifiers] ctm/add-children shapes drop-index)) + (update-in [target-frame :modifiers] ctm/add-children shapes drop-index) + (set-parent-ids shapes target-frame)) (and layout? (= original-frame target-frame)) (update-in [target-frame :modifiers] ctm/add-children shapes drop-index))))]