diff options
-rw-r--r-- | src/menu/container.cpp | 5 | ||||
-rw-r--r-- | src/menu/container.hpp | 2 | ||||
-rw-r--r-- | src/menu/drawable_control.cpp | 24 | ||||
-rw-r--r-- | src/menu/drawable_control.hpp | 13 | ||||
-rw-r--r-- | src/menu/frame.cpp | 21 | ||||
-rw-r--r-- | src/menu/frame.hpp | 10 |
6 files changed, 70 insertions, 5 deletions
diff --git a/src/menu/container.cpp b/src/menu/container.cpp index 379dd7c1..755a8b3b 100644 --- a/src/menu/container.cpp +++ b/src/menu/container.cpp @@ -37,6 +37,11 @@ namespace usdx { } + Container::Container(Container* owner, const ContainerHelper& add) + : DrawableControl(owner, add), frame(NULL) + { + } + Container::~Container() { controls.clear(); diff --git a/src/menu/container.hpp b/src/menu/container.hpp index dd5a8a32..9b30b117 100644 --- a/src/menu/container.hpp +++ b/src/menu/container.hpp @@ -45,6 +45,8 @@ namespace usdx std::list<DrawableControl*> controls; protected: + Container(Container*, const ContainerHelper&); + virtual void draw(void); public: diff --git a/src/menu/drawable_control.cpp b/src/menu/drawable_control.cpp index 6967d5fc..222ef3d5 100644 --- a/src/menu/drawable_control.cpp +++ b/src/menu/drawable_control.cpp @@ -35,15 +35,33 @@ namespace usdx DrawableControl::DrawableControl(Container* parent) : Control(parent), parent(parent) { - if (parent) { - parent->add(this); - } + ContainerHelper(this).add(parent); + } + + DrawableControl::DrawableControl(Container* parent, + const ContainerHelper& helper) + : Control(parent), parent(parent) + { + helper.add(parent); } DrawableControl::~DrawableControl() { if (parent) { parent->remove(this); + parent = NULL; + } + } + + DrawableControl::ContainerHelper::ContainerHelper(DrawableControl* self) : + self(self) + { + } + + void DrawableControl::ContainerHelper::add(Container* c) const + { + if (c) { + c->add(self); } } }; diff --git a/src/menu/drawable_control.hpp b/src/menu/drawable_control.hpp index 5605ab62..a2f672c6 100644 --- a/src/menu/drawable_control.hpp +++ b/src/menu/drawable_control.hpp @@ -41,8 +41,21 @@ namespace usdx { private: static log4cpp::Category& log; + + protected: Container* parent; + class ContainerHelper + { + private: + DrawableControl* self; + + public: + ContainerHelper(DrawableControl*); + virtual void add(Container*) const; + }; + DrawableControl(Container*, const ContainerHelper&); + public: DrawableControl(Container*); virtual ~DrawableControl(); diff --git a/src/menu/frame.cpp b/src/menu/frame.cpp index d3695392..cbf073f5 100644 --- a/src/menu/frame.cpp +++ b/src/menu/frame.cpp @@ -32,17 +32,22 @@ namespace usdx log4cpp::Category::getInstance("usdx.menu.frame"); Frame::Frame(Container* parent) - : Container(parent), background(NULL) + : Container(parent, FrameContainerHelper(this)), background(NULL) { } Frame::Frame(Container* parent, FrameBackground* background) - : Container(parent), background(background) + : Container(parent, FrameContainerHelper(this)), background(background) { } Frame::~Frame() { + if (parent) { + parent->removeFrame(); + parent = NULL; + } + if (background) { delete background; background = NULL; @@ -71,4 +76,16 @@ namespace usdx Container::draw(); } + + Frame::FrameContainerHelper::FrameContainerHelper(Frame* self) : + ContainerHelper(self), self(self) + { + } + + void Frame::FrameContainerHelper::add(Container* c) const + { + if (c) { + c->setFrame(self); + } + } }; diff --git a/src/menu/frame.hpp b/src/menu/frame.hpp index 6a2b0892..7b2e315a 100644 --- a/src/menu/frame.hpp +++ b/src/menu/frame.hpp @@ -42,6 +42,16 @@ namespace usdx FrameBackground* background; protected: + class FrameContainerHelper : public ContainerHelper + { + private: + Frame* self; + + public: + FrameContainerHelper(Frame*); + virtual void add(Container*) const; + }; + virtual void draw(void); public: |