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.
This commit is contained in:
Andrey Antukh
2016-01-20 22:41:37 +02:00
parent b65e0d754a
commit e353d67b02

View File

@@ -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))