diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2012-11-23 20:53:35 +0100 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2013-01-18 19:34:21 +0100 |
commit | b520ccf825f5076994131c441915fbd3c812426a (patch) | |
tree | 6f09beb3ee373e2ad60de4b6ae9006384dcae71d /src/menu | |
parent | 05560e6e019a8e823ba1c8fe82037d305b82f4c4 (diff) | |
download | usdx-b520ccf825f5076994131c441915fbd3c812426a.tar.gz usdx-b520ccf825f5076994131c441915fbd3c812426a.tar.xz usdx-b520ccf825f5076994131c441915fbd3c812426a.zip |
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.
Diffstat (limited to '')
-rw-r--r-- | src/menu/container.cpp | 18 | ||||
-rw-r--r-- | 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<DrawableControl*>::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 <list> +#include <boost/signals2.hpp> #include <log4cpp/Category.hh> #include "drawable_control.hpp" @@ -51,6 +52,14 @@ namespace usdx Point<int> 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<void ()> window_coords_change; }; }; |