From 0a1bc3e9998185c7693c08a391899832792e005a Mon Sep 17 00:00:00 2001 From: Dimitris Panokostas Date: Sat, 9 Nov 2024 17:30:50 +0100 Subject: [PATCH] Fixed container would not draw child objects when draw was called on it If we had a container with child objects, they would not be updated/drawn when the container's "draw" function was called. --- include/guisan/widgets/container.hpp | 1 + src/widgets/container.cpp | 36 +++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) 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..d97991f 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,35 @@ namespace gcn { return Rectangle(0, 0, getWidth(), getHeight()); } + + void Container::drawChildren(Graphics* graphics) + { + graphics->pushClipArea(getChildrenArea()); + + std::list children = getChildren(); + std::list::iterator iter; + for (iter = children.begin(); iter != children.end(); ++iter) + { + 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 -= (*iter)->getFrameSize(); + rec.y -= (*iter)->getFrameSize(); + rec.width += 2 * (*iter)->getFrameSize(); + rec.height += 2 * (*iter)->getFrameSize(); + graphics->pushClipArea(rec); + (*iter)->drawFrame(graphics); + graphics->popClipArea(); + } + graphics->pushClipArea((*iter)->getDimension()); + (*iter)->draw(graphics); + graphics->popClipArea(); + } + } + graphics->popClipArea(); + } } // namespace gcn