diff --git a/include/guisan/widgets/container.hpp b/include/guisan/widgets/container.hpp index a366849..dd84dfd 100644 --- a/include/guisan/widgets/container.hpp +++ b/include/guisan/widgets/container.hpp @@ -194,6 +194,7 @@ namespace gcn void draw(Graphics* graphics) override; Rectangle getChildrenArea() override; + void drawChildren(Graphics* graphics); protected: /** diff --git a/src/widgets/container.cpp b/src/widgets/container.cpp index 0a3ed3a..9b5e9b5 100644 --- a/src/widgets/container.cpp +++ b/src/widgets/container.cpp @@ -67,9 +67,7 @@ namespace gcn { Container::~Container() - { - - } + = default; void Container::draw(Graphics* graphics) { @@ -78,6 +76,7 @@ namespace gcn graphics->setColor(getBaseColor()); graphics->fillRectangle(Rectangle(0, 0, getWidth(), getHeight())); } + drawChildren(graphics); } void Container::setOpaque(bool opaque) @@ -162,4 +161,34 @@ namespace gcn { return Rectangle(0, 0, getWidth(), getHeight()); } + + void Container::drawChildren(Graphics* graphics) + { + graphics->pushClipArea(getChildrenArea()); + + std::list children = getChildren(); + for (const auto& iter : children) + { + if (iter->isVisible()) + { + // If the widget has a frame, + // draw it before drawing the widget + if (iter->getFrameSize() > 0) + { + Rectangle rec = iter->getDimension(); + rec.x -= static_cast(iter->getFrameSize()); + rec.y -= static_cast(iter->getFrameSize()); + rec.width += static_cast(2 * iter->getFrameSize()); + rec.height += static_cast(2 * iter->getFrameSize()); + graphics->pushClipArea(rec); + iter->drawFrame(graphics); + graphics->popClipArea(); + } + graphics->pushClipArea(iter->getDimension()); + iter->draw(graphics); + graphics->popClipArea(); + } + } + graphics->popClipArea(); + } } // namespace gcn