From b520ccf825f5076994131c441915fbd3c812426a Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Fri, 23 Nov 2012 20:53:35 +0100 Subject: menu/container: add window_coords_change The children container of a container have to be notified if the window coordinates of the parent changed. The children have to recalculate their own window coordinates. --- src/menu/container.cpp | 18 ++++++++++++++++-- src/menu/container.hpp | 14 ++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/menu/container.cpp b/src/menu/container.cpp index 65b85aec..31155e3c 100644 --- a/src/menu/container.cpp +++ b/src/menu/container.cpp @@ -34,17 +34,19 @@ namespace usdx Container::Container(Container* owner) : DrawableControl(owner), frame(NULL), window_coords(0, 0) { - set_clipping_required(true); + init(owner); } Container::Container(Container* owner, const ContainerHelper& add) : DrawableControl(owner, add), frame(NULL), window_coords(0, 0) { - set_clipping_required(true); + init(owner); } Container::~Container() { + window_coords_connection.disconnect(); + for (std::list::iterator next = controls.begin(), it = next++; it != controls.end(); it = next++) { (*it)->remove_parent(); @@ -53,6 +55,16 @@ namespace usdx controls.clear(); } + void Container::init(Container* parent) + { + set_clipping_required(true); + + if (parent) { + window_coords_connection = parent->window_coords_change.connect( + boost::bind(&Container::recalculate_window_coords, this)); + } + } + void Container::draw(void) { DrawableControl::draw(); @@ -104,6 +116,8 @@ namespace usdx window_coords.set_y(parent->get_window_coords().get_y() + get_parent()->get_height() - (get_top() + get_height())); + + window_coords_change(); } } diff --git a/src/menu/container.hpp b/src/menu/container.hpp index ac7d6129..f9eeacd5 100644 --- a/src/menu/container.hpp +++ b/src/menu/container.hpp @@ -26,6 +26,7 @@ #define CONTAINER_HPP #include +#include #include #include "drawable_control.hpp" @@ -51,6 +52,14 @@ namespace usdx Point window_coords; void recalculate_window_coords(void); + /** + * Connection to recieve window coordinate changes from parent + * container. + */ + boost::signals2::connection window_coords_connection; + + void init(Container* parent); + protected: Container(Container*, const ContainerHelper&); @@ -95,6 +104,11 @@ namespace usdx * @see window_coords */ virtual void set_size(int width, int height); + + /** + * This signal gets emitted, if the window coordinates are changed. + */ + boost::signals2::signal window_coords_change; }; }; -- cgit v1.2.3