|
14 | 14 | [renderer.notification.handlers :as notification.h]
|
15 | 15 | [renderer.notification.views :as notification.v]
|
16 | 16 | [renderer.utils.attribute :as attr]
|
17 |
| - [renderer.utils.bounds :as bounds :refer [Bounds]] |
| 17 | + [renderer.utils.bounds :as bounds :refer [BBox]] |
18 | 18 | [renderer.utils.element :as element]
|
19 | 19 | [renderer.utils.extra :refer [partial-right]]
|
20 | 20 | [renderer.utils.hiccup :as hiccup]
|
|
102 | 102 | parent-el
|
103 | 103 | (recur (parent db (:id parent-el)))))))
|
104 | 104 |
|
105 |
| -(m/=> adjusted-bounds [:-> App uuid? [:maybe Bounds]]) |
106 |
| -(defn adjusted-bounds |
| 105 | +(m/=> adjusted-bbox [:-> App uuid? [:maybe BBox]]) |
| 106 | +(defn adjusted-bbox |
107 | 107 | [db id]
|
108 | 108 | (loop [container (parent-container db id)
|
109 |
| - bounds (hierarchy/bounds (entity db id))] |
110 |
| - (if-not (and container bounds) |
111 |
| - bounds |
112 |
| - (let [[offset-x offset-y _ _] (hierarchy/bounds container) |
113 |
| - [x1 y1 x2 y2] bounds] |
| 109 | + bbox (hierarchy/bbox (entity db id))] |
| 110 | + (if-not (and container bbox) |
| 111 | + bbox |
| 112 | + (let [[offset-x offset-y _ _] (hierarchy/bbox container) |
| 113 | + [min-x min-y max-x max-y] bbox] |
114 | 114 | (recur
|
115 | 115 | (parent-container db (:id container))
|
116 |
| - [(+ x1 offset-x) (+ y1 offset-y) (+ x2 offset-x) (+ y2 offset-y)]))))) |
| 116 | + [(+ min-x offset-x) |
| 117 | + (+ min-y offset-y) |
| 118 | + (+ max-x offset-x) |
| 119 | + (+ max-y offset-y)]))))) |
117 | 120 |
|
118 |
| -(m/=> refresh-bounds [:-> App uuid? App]) |
119 |
| -(defn refresh-bounds |
| 121 | +(m/=> refresh-bbox [:-> App uuid? App]) |
| 122 | +(defn refresh-bbox |
120 | 123 | [db id]
|
121 | 124 | (let [el (entity db id)
|
122 |
| - bounds (if (= (:tag el) :g) |
123 |
| - (let [b (map #(adjusted-bounds db %) (children-ids db id))] |
124 |
| - (when (seq b) (apply bounds/union b))) |
125 |
| - (adjusted-bounds db id))] |
126 |
| - (if (or (not bounds) (element/root? el)) |
| 125 | + bbox (if (= (:tag el) :g) |
| 126 | + (let [b (map #(adjusted-bbox db %) (children-ids db id))] |
| 127 | + (when (seq b) (apply bounds/union b))) |
| 128 | + (adjusted-bbox db id))] |
| 129 | + (if (or (not bbox) (element/root? el)) |
127 | 130 | db
|
128 |
| - (-> (reduce refresh-bounds db (children-ids db id)) |
129 |
| - (update-in (path db id) assoc :bounds bounds))))) |
| 131 | + (-> (reduce refresh-bbox db (children-ids db id)) |
| 132 | + (update-in (path db id) assoc :bbox bbox))))) |
130 | 133 |
|
131 | 134 | (m/=> update-el [:-> App uuid? ifn? [:* any?] App])
|
132 | 135 | (defn update-el
|
133 | 136 | [db id f & more]
|
134 | 137 | (if (locked? db id)
|
135 | 138 | db
|
136 | 139 | (-> (apply update-in db (path db id) f more)
|
137 |
| - (refresh-bounds id)))) |
| 140 | + (refresh-bbox id)))) |
138 | 141 |
|
139 | 142 | (m/=> siblings-selected? [:-> App [:maybe boolean?]])
|
140 | 143 | (defn siblings-selected?
|
|
241 | 244 | (defn update-prop
|
242 | 245 | [db id k & more]
|
243 | 246 | (-> (apply update-in db (path db id k) more)
|
244 |
| - (refresh-bounds id))) |
| 247 | + (refresh-bbox id))) |
245 | 248 |
|
246 | 249 | (m/=> assoc-prop [:function
|
247 | 250 | [:-> App keyword? any? App]
|
|
253 | 256 | (-> (if (str/blank? v)
|
254 | 257 | (update-in db (path db id) dissoc k)
|
255 | 258 | (assoc-in db (path db id k) v))
|
256 |
| - (refresh-bounds id)))) |
| 259 | + (refresh-bbox id)))) |
257 | 260 |
|
258 | 261 | (m/=> dissoc-attr [:function
|
259 | 262 | [:-> App keyword? App]
|
|
276 | 279 | (cond-> db
|
277 | 280 | (not (locked? db id))
|
278 | 281 | (-> (assoc-in (path db id :attrs k) v)
|
279 |
| - (refresh-bounds id))))) |
| 282 | + (refresh-bbox id))))) |
280 | 283 |
|
281 | 284 | (m/=> set-attr [:function
|
282 | 285 | [:-> App keyword? any? App]
|
|
437 | 440 | (:active-document db)
|
438 | 441 | (assoc-in [:documents (:active-document db) :ignored-ids] #{})))
|
439 | 442 |
|
440 |
| -(m/=> bounds [:-> App [:maybe Bounds]]) |
441 |
| -(defn bounds |
| 443 | +(m/=> bbox [:-> App [:maybe BBox]]) |
| 444 | +(defn bbox |
442 | 445 | [db]
|
443 |
| - (element/united-bounds (selected db))) |
| 446 | + (element/united-bbox (selected db))) |
444 | 447 |
|
445 | 448 | (m/=> copy [:-> App App])
|
446 | 449 | (defn copy
|
|
449 | 452 | (cond-> db
|
450 | 453 | (seq els)
|
451 | 454 | (assoc :copied-elements els
|
452 |
| - :copied-bounds (bounds db))))) |
| 455 | + :copied-bbox (bbox db))))) |
453 | 456 |
|
454 | 457 | (m/=> delete [:function
|
455 | 458 | [:-> App App]
|
|
509 | 512 | (let [svgs (reverse (root-svgs db))
|
510 | 513 | pointer-pos (:adjusted-pointer-pos db)]
|
511 | 514 | (or
|
512 |
| - (some #(when (bounds/contained-point? (:bounds %) pointer-pos) %) svgs) |
| 515 | + (some #(when (bounds/contained-point? (:bbox %) pointer-pos) %) svgs) |
513 | 516 | (root db))))
|
514 | 517 |
|
515 | 518 | (m/=> translate [:function
|
|
531 | 534 | (reduce (partial-right place position) db (top-ancestor-ids db)))
|
532 | 535 | ([db id position]
|
533 | 536 | (let [el (entity db id)
|
534 |
| - center (bounds/center (hierarchy/bounds el)) |
| 537 | + center (bounds/center (hierarchy/bbox el)) |
535 | 538 | offset (mat/sub position center)]
|
536 | 539 | (update-el db id hierarchy/translate offset))))
|
537 | 540 |
|
|
544 | 547 | (reduce
|
545 | 548 | (fn [db id]
|
546 | 549 | (let [adjusted-pivot-point (->> (entity db id)
|
547 |
| - :bounds |
| 550 | + :bbox |
548 | 551 | (take 2)
|
549 | 552 | (mat/sub pivot-point))]
|
550 | 553 | (update-el db id hierarchy/scale ratio adjusted-pivot-point)))
|
|
558 | 561 | ([db direction]
|
559 | 562 | (reduce (partial-right align direction) db (selected-ids db)))
|
560 | 563 | ([db id direction]
|
561 |
| - (let [el-bounds (:bounds (entity db id)) |
562 |
| - center (bounds/center el-bounds) |
563 |
| - parent-bounds (:bounds (parent db id)) |
564 |
| - parent-center (bounds/center parent-bounds) |
| 564 | + (let [el-bbox (:bbox (entity db id)) |
| 565 | + center (bounds/center el-bbox) |
| 566 | + parent-bbox (:bbox (parent db id)) |
| 567 | + parent-center (bounds/center parent-bbox) |
565 | 568 | [cx cy] (mat/sub parent-center center)
|
566 |
| - [x1 y1 x2 y2] (mat/sub parent-bounds el-bounds)] |
| 569 | + delta-bbox (mat/sub parent-bbox el-bbox) |
| 570 | + [min-x-delta min-y-delta max-x-delta max-y-delta] delta-bbox] |
567 | 571 | (translate db id (case direction
|
568 |
| - :top [0 y1] |
| 572 | + :top [0 min-y-delta] |
569 | 573 | :center-vertical [0 cy]
|
570 |
| - :bottom [0 y2] |
571 |
| - :left [x1 0] |
| 574 | + :bottom [0 max-y-delta] |
| 575 | + :left [min-x-delta 0] |
572 | 576 | :center-horizontal [cx 0]
|
573 |
| - :right [x2 0]))))) |
| 577 | + :right [max-x-delta 0]))))) |
574 | 578 |
|
575 | 579 | (m/=> ->path [:function
|
576 | 580 | [:-> App App]
|
|
592 | 596 | ([db id]
|
593 | 597 | (update-el db id element/stroke->path)))
|
594 | 598 |
|
595 |
| -(m/=> overlapping-svg [:-> App Bounds Element]) |
| 599 | +(m/=> overlapping-svg [:-> App BBox Element]) |
596 | 600 | (defn overlapping-svg
|
597 |
| - [db el-bounds] |
| 601 | + [db el-bbox] |
598 | 602 | (let [svgs (reverse (root-svgs db))] ; Reverse to select top svgs first.
|
599 | 603 | (or
|
600 |
| - (some #(when (bounds/contained? el-bounds (:bounds %)) %) svgs) |
601 |
| - (some #(when (bounds/intersect? el-bounds (:bounds %)) %) svgs) |
| 604 | + (some #(when (bounds/contained? el-bbox (:bbox %)) %) svgs) |
| 605 | + (some #(when (bounds/intersect? el-bbox (:bbox %)) %) svgs) |
602 | 606 | (root db))))
|
603 | 607 |
|
604 | 608 | (m/=> assoc-parent-id [:-> App Element Element])
|
|
608 | 612 | (not (or (element/root? el) (:parent el)))
|
609 | 613 | (assoc :parent (:id (if (element/svg? el)
|
610 | 614 | (root db)
|
611 |
| - (overlapping-svg db (hierarchy/bounds el))))))) |
| 615 | + (overlapping-svg db (hierarchy/bbox el))))))) |
612 | 616 |
|
613 | 617 | (m/=> create [:-> App map? App])
|
614 | 618 | (defn create
|
|
624 | 628 | child-els (-> (entities db (set (:children el)))
|
625 | 629 | (vals)
|
626 | 630 | (concat (:content el)))
|
627 |
| - [x1 y1] (hierarchy/bounds (entity db (:parent new-el))) |
| 631 | + [min-x min-y] (hierarchy/bbox (entity db (:parent new-el))) |
628 | 632 | add-children (fn [db child-els]
|
629 | 633 | (reduce #(cond-> %1
|
630 | 634 | (db/tag? (:tag %2))
|
|
641 | 645 | (update-prop (:parent new-el) :children #(vec (conj % id)))
|
642 | 646 |
|
643 | 647 | (not (or (element/svg? new-el) (element/root? new-el) (:parent el)))
|
644 |
| - (translate [(- x1) (- y1)]) |
| 648 | + (translate [(- min-x) (- min-y)]) |
645 | 649 |
|
646 | 650 | :always
|
647 |
| - (refresh-bounds id) |
| 651 | + (refresh-bbox id) |
648 | 652 |
|
649 | 653 | child-els
|
650 | 654 | (add-children child-els)))))
|
|
703 | 707 | (let [parent-el (hovered-svg db)]
|
704 | 708 | (reduce (partial-right paste parent-el) (deselect-all db) (:copied-elements db))))
|
705 | 709 | ([db el parent-el]
|
706 |
| - (let [center (bounds/center (:copied-bounds db)) |
707 |
| - el-center (bounds/center (:bounds el)) |
| 710 | + (let [center (bounds/center (:copied-bbox db)) |
| 711 | + el-center (bounds/center (:bbox el)) |
708 | 712 | offset (mat/sub el-center center)
|
709 |
| - el (dissoc el :bounds) |
710 |
| - [s-x1 s-y1] (:bounds parent-el) |
| 713 | + el (dissoc el :bbox) |
| 714 | + [s-x1 s-y1] (:bbox parent-el) |
711 | 715 | pointer-pos (:adjusted-pointer-pos db)]
|
712 | 716 | (reduce
|
713 | 717 | select
|
|
0 commit comments