diff --git a/eek/eek-element.c b/eek/eek-element.c index 978fce2d..4600749c 100644 --- a/eek/eek-element.c +++ b/eek/eek-element.c @@ -298,7 +298,9 @@ eek_element_get_name (EekElement *element) * @element: an #EekElement * @bounds: bounding box of @element * - * Set the bounding box of @element to @bounds. + * Set the bounding box of @element to @bounds. Note that if @element + * has parent, X and Y positions of @bounds are relative to the parent + * position. */ void eek_element_set_bounds (EekElement *element, @@ -313,7 +315,10 @@ eek_element_set_bounds (EekElement *element, * @element: an #EekElement * @bounds: pointer where bounding box of @element will be stored * - * Get the bounding box of @element. + * Get the bounding box of @element. Note that if @element has + * parent, X and Y positions of @bounds are relative to the parent + * position. To obtain the absolute position, use + * #eek_element_get_absolute_position(). */ void eek_element_get_bounds (EekElement *element, @@ -322,3 +327,33 @@ eek_element_get_bounds (EekElement *element, g_return_if_fail (EEK_IS_ELEMENT(element)); EEK_ELEMENT_GET_CLASS(element)->get_bounds (element, bounds); } + +/** + * eek_element_get_absolute_position: + * @element: an #EekElement + * @x: pointer where the X coordinate of @element will be stored + * @y: pointer where the Y coordinate of @element will be stored + * + * Compute the absolute position of @element. + */ +void +eek_element_get_absolute_position (EekElement *element, + gdouble *x, + gdouble *y) +{ + EekContainer *parent; + EekBounds bounds; + gdouble ax, ay; + + eek_element_get_bounds (element, &bounds); + ax = bounds.x; + ay = bounds.y; + while ((parent = eek_element_get_parent (element)) != NULL) { + eek_element_get_bounds (EEK_ELEMENT(parent), &bounds); + ax += bounds.x; + ay += bounds.y; + element = EEK_ELEMENT(parent); + } + *x = ax; + *y = ay; +} diff --git a/eek/eek-element.h b/eek/eek-element.h index bb12735b..2b11da90 100644 --- a/eek/eek-element.h +++ b/eek/eek-element.h @@ -61,21 +61,25 @@ struct _EekElementClass EekBounds *bounds); }; -GType eek_element_get_type (void) G_GNUC_CONST; +GType eek_element_get_type (void) G_GNUC_CONST; -void eek_element_set_parent (EekElement *element, - EekContainer *parent); -EekContainer *eek_element_get_parent (EekElement *element); -void eek_element_set_name (EekElement *element, - const gchar *name); +void eek_element_set_parent (EekElement *element, + EekContainer *parent); +EekContainer *eek_element_get_parent (EekElement *element); +void eek_element_set_name (EekElement *element, + const gchar *name); -G_CONST_RETURN gchar *eek_element_get_name (EekElement *element); +G_CONST_RETURN gchar *eek_element_get_name (EekElement *element); -void eek_element_set_bounds (EekElement *element, - EekBounds *bounds); +void eek_element_set_bounds (EekElement *element, + EekBounds *bounds); -void eek_element_get_bounds (EekElement *element, - EekBounds *bounds); +void eek_element_get_bounds (EekElement *element, + EekBounds *bounds); + +void eek_element_get_absolute_position (EekElement *element, + gdouble *x, + gdouble *y); G_END_DECLS #endif /* EEK_ELEMENT_H */