diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/menu/container.cpp | 29 | ||||
-rw-r--r-- | src/menu/container.hpp | 13 | ||||
-rw-r--r-- | src/menu/drawable_control.cpp | 11 | ||||
-rw-r--r-- | src/menu/drawable_control.hpp | 7 |
4 files changed, 35 insertions, 25 deletions
diff --git a/src/menu/container.cpp b/src/menu/container.cpp index 3bed894e..d39ac736 100644 --- a/src/menu/container.cpp +++ b/src/menu/container.cpp @@ -28,32 +28,31 @@ namespace usdx { - Container::Container(Control* parent) - : DrawableControl(parent) + Container::Container(Container* owner) + : DrawableControl(owner) { } Container::~Container() { + controls.clear(); + } + + void Container::draw(void) + { for (std::list<DrawableControl*>::iterator it = controls.begin(); it != controls.end(); it++) { - delete *it; + (*it)->repaint(); } - - controls.clear(); } - void Container::repaint(void) + void Container::add(DrawableControl *child) { - if (get_visible()) { - draw(); - - for (std::list<DrawableControl*>::const_iterator it = - controls.begin(); - it != controls.end(); it++) { + controls.push_back(child); + } - (*it)->repaint(); - } - } + void Container::remove(DrawableControl *child) + { + controls.remove(child); } }; diff --git a/src/menu/container.hpp b/src/menu/container.hpp index 6ee6bde2..a558462e 100644 --- a/src/menu/container.hpp +++ b/src/menu/container.hpp @@ -28,7 +28,6 @@ #define CONTAINER_HPP #include <list> - #include "drawable_control.hpp" namespace usdx @@ -38,15 +37,15 @@ namespace usdx private: std::list<DrawableControl*> controls; + protected: + virtual void draw(void); + public: - Container(Control* parent); + Container(Container* parent); virtual ~Container(); - /** - * Method for redraw all contained objects. - */ - void repaint(void); - + void add(DrawableControl *child); + void remove(DrawableControl *child); }; }; diff --git a/src/menu/drawable_control.cpp b/src/menu/drawable_control.cpp index 895193f4..bf2ddc74 100644 --- a/src/menu/drawable_control.cpp +++ b/src/menu/drawable_control.cpp @@ -25,15 +25,22 @@ */ #include "drawable_control.hpp" +#include "container.hpp" namespace usdx { - DrawableControl::DrawableControl(Control* parent) - : Control(parent) + DrawableControl::DrawableControl(Container* parent) + : Control(parent), parent(parent) { + if (parent) { + parent->add(this); + } } DrawableControl::~DrawableControl() { + if (parent) { + parent->remove(this); + } } }; diff --git a/src/menu/drawable_control.hpp b/src/menu/drawable_control.hpp index d8b10d10..fcab05da 100644 --- a/src/menu/drawable_control.hpp +++ b/src/menu/drawable_control.hpp @@ -34,10 +34,15 @@ namespace usdx { + class Container; + class DrawableControl : public Drawable, public Control { + private: + Container* parent; + public: - DrawableControl(Control* parent); + DrawableControl(Container* parent); virtual ~DrawableControl(); }; }; |