aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2011-12-25 16:33:45 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2013-01-05 17:17:50 +0100
commit2d1c84a16c36869ca292b74348f2ef852f2f8a62 (patch)
tree6da35292564452e77dabb315507008da7652b0c0 /src
parent0f42e8231f3af3d518a5c438ec41a3d849d37a29 (diff)
downloadusdx-2d1c84a16c36869ca292b74348f2ef852f2f8a62.tar.gz
usdx-2d1c84a16c36869ca292b74348f2ef852f2f8a62.tar.xz
usdx-2d1c84a16c36869ca292b74348f2ef852f2f8a62.zip
menu: Container could contains and draw DrawableControls
DrawableControls register/unregister itself during construction/destruction at the Container (supplied as owner) and get automatically drawn
Diffstat (limited to 'src')
-rw-r--r--src/menu/container.cpp29
-rw-r--r--src/menu/container.hpp13
-rw-r--r--src/menu/drawable_control.cpp11
-rw-r--r--src/menu/drawable_control.hpp7
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();
};
};