From e353d67b022dfd10934598464df9f24ca9726098 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 20 Jan 2016 22:41:37 +0200 Subject: [PATCH] Add helper for resolve/translate shape position into real canvas coords. This is necesary to know the real shape position in a canves when shape is part of group or subgroup and each group has its own coordinate system. --- src/uxbox/shapes.cljs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/uxbox/shapes.cljs b/src/uxbox/shapes.cljs index 6327a98056..908d2da8bc 100644 --- a/src/uxbox/shapes.cljs +++ b/src/uxbox/shapes.cljs @@ -1,6 +1,7 @@ (ns uxbox.shapes (:require [uxbox.util.matrix :as mtx] - [uxbox.util.math :as mth])) + [uxbox.util.math :as mth] + [uxbox.state :as st])) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Types @@ -148,3 +149,18 @@ y' (:y shape)] (assoc shape :x (- x' x) :y (- y' y)))) +(defn resolve-position + "Recursively resolve the real shape position in + the canvas." + [{:keys [width height x y group] :as shape}] + (if group + (let [group (get-in @st/state [:shapes-by-id group]) + result (resolve-position + (assoc group + :x (+ (:x group) x) + :y (+ (:y group) y)))] + (assoc shape + :x (:x result) + :y (:y result))) + shape)) +