From 9e556f9eba03c579acabaa496bc5703332a1e045 Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Sat, 31 Aug 2024 10:54:18 +0200 Subject: [PATCH] * Apply Guichan's changes from b50089aa71c0625f5273c468ac169b71f8bba664 (August 28th 2008) Widget::getTop has been added. --- TODO | 2 +- include/guisan/widget.hpp | 24 +++++++++++++++++++----- src/widget.cpp | 16 ++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/TODO b/TODO index 15841d8..d680912 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,4 @@ -* Continue rebasing from b50089aa71c0625f5273c468ac169b71f8bba664 +* Continue rebasing from 8090b4fbd0cb73c092307a5b551929275b8aef5a * Add a focus listener interface. * Make focus apply synchronously. * Graphics and input objects for DirectX. diff --git a/include/guisan/widget.hpp b/include/guisan/widget.hpp index 7414a33..a046a0d 100644 --- a/include/guisan/widget.hpp +++ b/include/guisan/widget.hpp @@ -188,6 +188,16 @@ namespace gcn */ virtual Widget* getParent() const; + /** + * Gets the top widget, or top parent, of this widget. + * + * @return The top widget, or top parent, of this widget. + * NULL if no top widget exists + * (that is this widget doesn't have a parent). + * @since 1.1.0 + */ + virtual Widget* getTop() const; + /** * Sets the width of the widget. * @@ -883,21 +893,25 @@ namespace gcn * Moves a widget to the top of this widget. The moved widget will be * drawn above all other widgets in this widget. * + * This method is safe to call at any times. + * * @param widget The widget to move to the top. * @see moveToBottom * @since 0.1.0 */ - virtual void moveToTop(Widget* widget) { }; + virtual void moveToTop(Widget* widget) {} /** * Moves a widget in this widget to the bottom of this widget. * The moved widget will be drawn below all other widgets in this widget. * + * This method is safe to call at any times. + * * @param widget The widget to move to the bottom. * @see moveToTop * @since 0.1.0 */ - virtual void moveToBottom(Widget* widget) { }; + virtual void moveToBottom(Widget* widget) {} /** * Focuses the next widget in the widget. @@ -905,7 +919,7 @@ namespace gcn * @see moveToBottom * @since 0.1.0 */ - virtual void focusNext() { }; + virtual void focusNext() {} /** * Focuses the previous widget in the widget. @@ -913,7 +927,7 @@ namespace gcn * @see moveToBottom * @since 0.1.0 */ - virtual void focusPrevious() { }; + virtual void focusPrevious() {} /** * Tries to show a specific part of a widget by moving it. Used if the @@ -923,7 +937,7 @@ namespace gcn * @param area The area to show. * @since 0.1.0 */ - virtual void showWidgetPart(Widget* widget, Rectangle area) { }; + virtual void showWidgetPart(Widget* widget, Rectangle area) {} /** * Sets an id of a widget. An id can be useful if a widget needs to be diff --git a/src/widget.cpp b/src/widget.cpp index 73c17d2..7e6fe30 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -743,4 +743,20 @@ namespace gcn mParent->showWidgetPart(this, rectangle); } } + + Widget* Widget::getTop() const + { + if (getParent() == NULL) return NULL; + + Widget* widget = getParent(); + Widget* parent = getParent()->getParent(); + + while (parent != NULL) + { + widget = parent; + parent = parent->getParent(); + } + + return widget; + } }