diff --git a/doomsday/client/src/ui/widgets/guirootwidget.cpp b/doomsday/client/src/ui/widgets/guirootwidget.cpp index 0b073d6ff7..e78322d0e2 100644 --- a/doomsday/client/src/ui/widgets/guirootwidget.cpp +++ b/doomsday/client/src/ui/widgets/guirootwidget.cpp @@ -50,7 +50,7 @@ DENG2_PIMPL(GuiRootWidget) // Tell all widgets to release their resource allocations. The base // class destructor will destroy all widgets, but this class governs // shared GL resources, so we'll ask the widgets to do this now. - self.notifyTree(&Widget::deinitialize); + self.notifyTree(NotifyArgs(&Widget::deinitialize)); } void initAtlas() @@ -180,6 +180,10 @@ void GuiRootWidget::update() void GuiRootWidget::drawUntil(Widget &until) { - notifyTree(&Widget::draw, &Widget::isVisible, - &Widget::preDrawChildren, &Widget::postDrawChildren, &until); + NotifyArgs args(&Widget::draw); + args.conditionFunc = &Widget::isVisible; + args.preNotifyFunc = &Widget::preDrawChildren; + args.postNotifyFunc = &Widget::postDrawChildren; + args.until = &until; + notifyTree(args); } diff --git a/doomsday/libdeng2/include/de/widgets/widget.h b/doomsday/libdeng2/include/de/widgets/widget.h index affb713b07..8be5222f4a 100644 --- a/doomsday/libdeng2/include/de/widgets/widget.h +++ b/doomsday/libdeng2/include/de/widgets/widget.h @@ -148,19 +148,28 @@ class DENG2_PUBLIC Widget // Utilities. String uniqueName(String const &name) const; - enum NotifyResult { - AbortNotify, - ContinueNotify + + /** + * Arguments for notifyTree() and notifyTreeReversed(). + */ + struct NotifyArgs { + enum Result { + Abort, + Continue + }; + void (Widget::*notifyFunc)(); + bool (Widget::*conditionFunc)() const; + void (Widget::*preNotifyFunc)(); + void (Widget::*postNotifyFunc)(); + Widget *until; + + NotifyArgs(void (Widget::*notify)()) : notifyFunc(notify), + conditionFunc(0), preNotifyFunc(0), postNotifyFunc(0), + until(0) {} }; - NotifyResult notifyTree(void (Widget::*notifyFunc)(), - bool (Widget::*conditionFunc)() const = 0, - void (Widget::*preNotifyFunc)() = 0, - void (Widget::*postNotifyFunc)() = 0, - Widget *until = 0); - void notifyTreeReversed(void (Widget::*notifyFunc)(), - bool (Widget::*conditionFunc)() const = 0, - void (Widget::*preNotifyFunc)() = 0, - void (Widget::*postNotifyFunc)() = 0); + + NotifyArgs::Result notifyTree(NotifyArgs const &args); + void notifyTreeReversed(NotifyArgs const &args); bool dispatchEvent(Event const &event, bool (Widget::*memberFunc)(Event const &)); // Events. diff --git a/doomsday/libdeng2/src/widgets/rootwidget.cpp b/doomsday/libdeng2/src/widgets/rootwidget.cpp index ddab6b4d48..e5121c6e6a 100644 --- a/doomsday/libdeng2/src/widgets/rootwidget.cpp +++ b/doomsday/libdeng2/src/widgets/rootwidget.cpp @@ -120,7 +120,11 @@ void RootWidget::update() void RootWidget::draw() { - notifyTree(&Widget::draw, &Widget::isVisible, &Widget::preDrawChildren, &Widget::postDrawChildren); + NotifyArgs args(&Widget::draw); + args.conditionFunc = &Widget::isVisible; + args.preNotifyFunc = &Widget::preDrawChildren; + args.postNotifyFunc = &Widget::postDrawChildren; + notifyTree(args); Rule::markRulesValid(); // All done for this frame. } diff --git a/doomsday/libdeng2/src/widgets/widget.cpp b/doomsday/libdeng2/src/widgets/widget.cpp index 3fc5876cc5..00825fd275 100644 --- a/doomsday/libdeng2/src/widgets/widget.cpp +++ b/doomsday/libdeng2/src/widgets/widget.cpp @@ -275,67 +275,60 @@ String Widget::uniqueName(String const &name) const return String("#%1.%2").arg(id().asInt64()).arg(name); } -Widget::NotifyResult Widget::notifyTree(void (Widget::*notifyFunc)(), - bool (Widget::*conditionFunc)() const, - void (Widget::*preFunc)(), - void (Widget::*postFunc)(), - Widget *until) +Widget::NotifyArgs::Result Widget::notifyTree(NotifyArgs const &args) { - if(preFunc) + if(args.preNotifyFunc) { - (this->*preFunc)(); + (this->*args.preNotifyFunc)(); } DENG2_FOR_EACH(Instance::Children, i, d->children) { - if(*i == until) + if(*i == args.until) { - return AbortNotify; + return NotifyArgs::Abort; } - if(conditionFunc && !((*i)->*conditionFunc)()) + if(args.conditionFunc && !((*i)->*args.conditionFunc)()) continue; // Skip this one. - ((*i)->*notifyFunc)(); + ((*i)->*args.notifyFunc)(); - if((*i)->notifyTree(notifyFunc, conditionFunc, preFunc, postFunc, until) == AbortNotify) + if((*i)->notifyTree(args) == NotifyArgs::Abort) { - return AbortNotify; + return NotifyArgs::Abort; } } - if(postFunc) + if(args.postNotifyFunc) { - (this->*postFunc)(); + (this->*args.postNotifyFunc)(); } - return ContinueNotify; + return NotifyArgs::Continue; } -void Widget::notifyTreeReversed(void (Widget::*notifyFunc)(), - bool (Widget::*conditionFunc)() const, - void (Widget::*preFunc)(), - void (Widget::*postFunc)()) +void Widget::notifyTreeReversed(NotifyArgs const &args) { - if(preFunc) + if(args.preNotifyFunc) { - (this->*preFunc)(); + (this->*args.preNotifyFunc)(); } for(int i = d->children.size() - 1; i >= 0; --i) { Widget *w = d->children[i]; - if(conditionFunc && !(w->*conditionFunc)()) + if(args.conditionFunc && !(w->*args.conditionFunc)()) continue; // Skip this one. - w->notifyTreeReversed(notifyFunc, conditionFunc, preFunc, postFunc); - (w->*notifyFunc)(); + w->notifyTreeReversed(args); + (w->*args.notifyFunc)(); } - if(postFunc) + if(args.postNotifyFunc) { - (this->*postFunc)(); + (this->*args.postNotifyFunc)(); } } @@ -344,25 +337,24 @@ bool Widget::dispatchEvent(Event const &event, bool (Widget::*memberFunc)(Event // Hidden widgets do not get events. if(isHidden()) return false; + // Routing has priority. + if(d->routing.contains(event.type())) + { + return d->routing[event.type()]->dispatchEvent(event, memberFunc); + } + bool const thisHasFocus = (hasRoot() && root().focus() == this); if(d->behavior.testFlag(HandleEventsOnlyWhenFocused) && !thisHasFocus) { return false; } - if(thisHasFocus) { // The focused widget is offered events before dispatching to the tree. return false; } - // Routing has priority. - if(d->routing.contains(event.type())) - { - return d->routing[event.type()]->dispatchEvent(event, memberFunc); - } - // Tree is traversed in reverse order. for(int i = d->children.size() - 1; i >= 0; --i) { diff --git a/doomsday/libshell/src/textwidget.cpp b/doomsday/libshell/src/textwidget.cpp index d790916095..cb7556ecb6 100644 --- a/doomsday/libshell/src/textwidget.cpp +++ b/doomsday/libshell/src/textwidget.cpp @@ -96,7 +96,11 @@ void TextWidget::drawAndShow() if(!isHidden()) { draw(); - notifyTree(&Widget::draw, &Widget::isVisible); + + NotifyArgs args(&Widget::draw); + args.conditionFunc = &Widget::isVisible; + notifyTree(args); + targetCanvas().show(); } }