Simplified event handling model in GUI to be less obtuse and more predictable
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3795 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
432b1598c3
commit
45f030b4da
@ -149,16 +149,21 @@ bool EventHandler::onWidgetActivated(GUIEngine::Widget* w)
|
||||
Widget* parent = w->m_event_handler;
|
||||
if(w->m_event_handler != NULL)
|
||||
{
|
||||
/* Find topmost parent. Stop looping if a widget event handler's is itself, to not fall
|
||||
/* Find all parents. Stop looping if a widget event handler's is itself, to not fall
|
||||
in an infinite loop (this can happen e.g. in checkboxes, where they need to be
|
||||
notified of clicks onto themselves so they can toggle their state. ) */
|
||||
while(parent->m_event_handler != NULL && parent->m_event_handler != parent)
|
||||
{
|
||||
parent->transmitEvent(w, w->m_properties[PROP_ID]);
|
||||
parent = parent->m_event_handler;
|
||||
}
|
||||
|
||||
/* notify the found event event handler, and also notify the main callback if the
|
||||
parent event handler says so */
|
||||
if(parent->transmitEvent(w, w->m_properties[PROP_ID]))
|
||||
{
|
||||
transmitEvent(parent, parent->m_properties[PROP_ID]);
|
||||
}
|
||||
}
|
||||
else transmitEvent(w, w->m_properties[PROP_ID]);
|
||||
|
||||
@ -192,9 +197,7 @@ void EventHandler::processAction(const int action, const unsigned int value, Inp
|
||||
On the way, also notify everyone in the chain of the left press. */
|
||||
while (widget_to_call->m_event_handler != NULL && widget_to_call->m_event_handler != widget_to_call)
|
||||
{
|
||||
if (widget_to_call->leftPressed())
|
||||
transmitEvent(w, w->m_properties[PROP_ID]);
|
||||
|
||||
widget_to_call->leftPressed();
|
||||
widget_to_call = widget_to_call->m_event_handler;
|
||||
}
|
||||
|
||||
@ -218,9 +221,7 @@ void EventHandler::processAction(const int action, const unsigned int value, Inp
|
||||
On the way, also notify everyone in the chain of the right press */
|
||||
while(widget_to_call->m_event_handler != NULL && widget_to_call->m_event_handler != widget_to_call)
|
||||
{
|
||||
if(widget_to_call->rightPressed())
|
||||
transmitEvent(widget_to_call, w->m_properties[PROP_ID]);
|
||||
|
||||
widget_to_call->rightPressed();
|
||||
widget_to_call = widget_to_call->m_event_handler;
|
||||
}
|
||||
|
||||
|
@ -125,8 +125,7 @@ namespace GUIEngine
|
||||
public:
|
||||
/**
|
||||
* This is set to NULL by default; set to something else in a widget to mean
|
||||
* that events happening on this widget should not go straight into the
|
||||
* event handler. Instead, they will first be passed to m_event_handler->transmitEvent,
|
||||
* that events happening on this widget should also be passed to m_event_handler->transmitEvent,
|
||||
* which is usually the parent analysing events from its children.
|
||||
* This is especially useful with logical widgets built with more than
|
||||
* one irrlicht widgets (e.g. Spinner, Ribbon)
|
||||
@ -153,8 +152,10 @@ namespace GUIEngine
|
||||
|
||||
virtual void update(float delta) { }
|
||||
|
||||
/** used when you set parents - see m_event_handler explainations below.
|
||||
returns whether main event callback should be notified or not */
|
||||
/** All widgets, including their parents (m_event_handler) will be notified on event through
|
||||
this call. Must return whether main (GUI engine user) event callback should be notified or not.
|
||||
Note that in the case of a hierarchy of widgets (with m_event_handler), only the topmost widget
|
||||
of the chain decides whether the main handler is notified; return value is not read for others. */
|
||||
virtual bool transmitEvent(Widget* w, std::string& originator) { return true; }
|
||||
|
||||
/**
|
||||
|
@ -219,11 +219,6 @@ bool RibbonGridWidget::transmitEvent(Widget* w, std::string& originator)
|
||||
return false;
|
||||
}
|
||||
|
||||
// if it's something else, it might be a ribbon child with its own parent
|
||||
if(w->m_event_handler != NULL && w->m_event_handler != this)
|
||||
return w->m_event_handler->transmitEvent(w, originator);
|
||||
|
||||
// if we got there, must be a ribbon itself. in this case we can just transmit the event directly
|
||||
return true;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user