|
QuasarEngine
Cross-platform 3D engine and editor
|
Calls a handler only when an event has the type that the handler expects. More...
#include <quasar/events/EventDispatcher.h>
Public Member Functions | |
| EventDispatcher (Event &event) | |
| Creates a dispatcher for an event. The event must stay alive while the dispatcher is used. | |
| template<EventClass T, std::predicate< T & > Handler> | |
| bool | Dispatch (Handler &&handler) |
| Calls the handler if the event is of type T. | |
Calls a handler only when an event has the type that the handler expects.
Create a dispatcher for the received event, then call Dispatch() once for each event class to handle:
Adding a new event class does not require any change here: Dispatch() only relies on GetStaticType().
|
inline |
Calls the handler if the event is of type T.
When the handler returns true, the event is marked as handled. A handled event stays handled: a handler that returns false never clears the flag set by another one.
| T | Event class expected by the handler. |
| handler | Function that takes a T& and returns true if it handled the event. |