From 077cfee0200d569826cc15ecc24a7e40ec637e52 Mon Sep 17 00:00:00 2001 From: Freddie Witherden Date: Sun, 17 Aug 2008 18:22:38 +0000 Subject: [PATCH] Add widgetGetCurrentlyMousedOver to return the widget that currently has the mouse over it. git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5834 4a71c877-e1ca-e34f-864e-861f7616d084 --- lib/betawidget/widget.c | 25 +++++++++++++++++++++++++ lib/betawidget/widget.h | 13 ++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/betawidget/widget.c b/lib/betawidget/widget.c index 53bc4defe..9dcbcccc9 100644 --- a/lib/betawidget/widget.c +++ b/lib/betawidget/widget.c @@ -1226,6 +1226,31 @@ widget *widgetGetCurrentlyFocused(widget *self) return self; } +widget *widgetGetCurrentlyMousedOver(widget *self) +{ + int i; + + // Make sure we have the mouse + if (!self->hasMouse) + { + return NULL; + } + + // See if any of our children are moused over + for (i = 0; i < vectorSize(self->children); i++) + { + widget *child = vectorAt(self->children, i); + + if (child->hasMouse) + { + return widgetGetCurrentlyMousedOver(child); + } + } + + // None of our children have the mouse; return ourself + return self; +} + bool widgetHandleEventImpl(widget *self, const event *evt) { // If the event should be passed onto our children diff --git a/lib/betawidget/widget.h b/lib/betawidget/widget.h index 659ce0168..81d0c8152 100644 --- a/lib/betawidget/widget.h +++ b/lib/betawidget/widget.h @@ -815,11 +815,22 @@ void widgetDestroy(widget *self); * Should none of self's child widgets have focus (but it does) then self is * returned. * - * @param self The widget to get the further down focused child of. + * @param self The widget to get the furthest down focused child of. * @return A pointer to the widget, or NULL if self is not focused. */ widget *widgetGetCurrentlyFocused(widget *self); +/** + * Very much the same as widgetGetCurrentlyFocused except that it returns a + * pointer to the widget furthest down the hierarchy which currently has the + * mouse over it. Like with widgetGetCurrentlyFocused should self not have the + * mouse over it, NULL is returned. + * + * @param self The widget to get the furthest down moused-over child of. + * @param A pointer to the widget, or NULL if self does not have the mouse. + */ +widget *widgetGetCurrentlyMousedOver(widget *self); + /** * If the widget is capable of holding keyboard focus and does not currently * hold it then this method will bring it into focus. Should ->parent not be