public |
Inheritance Graph
graph BT
EventQueue
click EventQueue "classUtil_1_1UI_1_1EventQueue"
Description
Data structure for event handling.
The event queue manages input events that are created by different generators and consumed by different handlers.
The event generators can be the windowing system or a library that supports game controllers, for example. The different generators can register themselves as event generator using registerEventGenerator() .
Multiple event handlers can be registered using registerEventHandler() . Optionally, a filter function can be given that ensures that only specific events are given to the handler.
During process() , first the event generators are asked for new events. After that, all existing events are filtered and given to the respective event handlers.
Note: This class has to be used from the same thread as the window. For the reasons, seehttp://www.libsdl.org/docs/html/sdlpumpevents.htmlor Section 2.7 ofhttp://www.x.org/docs/X11/xlib.pdf.
Author: Benjamin Eikel
Date: 2012-09-12
Public Types
typedef std::function< std::deque< Event >)> | event_generator_t |
typedef std::function< bool(const Event &)> | event_handler_t |
Public Functions
std::size_t | getNumEventsAvailable() const |
void | pushEvent(const Event & newEvent) |
const Event & | peekEvent() const |
Event | popEvent() |
void | registerEventGenerator(const event_generator_t & generator) |
void | registerEventHandler(const event_handler_t & handler) |
void | process() |
Documentation
typedef
Util::UI::EventQueue::event_generator_t
public |
typedef std::function< std::deque< Event >)> event_generator_t |
Function type for an event generator that returns an array of events.
Defined in Util/UI/EventQueue.h:49
typedef
Util::UI::EventQueue::event_handler_t
public |
typedef std::function< bool(const Event &)> event_handler_t |
Function type for an event handler that receives a single event. The return type indicates if the event has been handled: If the handler returnstrue
, it has handled the event. If the event has not been handled (return valuefalse
), it will be passed to the next handler.
Defined in Util/UI/EventQueue.h:58
function
Util::UI::EventQueue::getNumEventsAvailable
public | const |
std::size_t getNumEventsAvailable( | ) const |
Return the number of unprocessed events that are waiting in the event queue.
Returns
Number of events waiting for processing
Defined in Util/UI/EventQueue.h:86
function
Util::UI::EventQueue::pushEvent
public |
void pushEvent( | const Event & | newEvent ) |
Add a new event to the event queue.
Parameters
- newEvent
- Event that will be inserted
Defined in Util/UI/EventQueue.h:93
function
Util::UI::EventQueue::peekEvent
public | const |
const Event & peekEvent( | ) const |
Read the first element from the event queue without removing it.
Returns
Read-only reference to the first event
Exceptions
- std::logic_error
- if there are no events available
Defined in Util/UI/EventQueue.h:101
function
Util::UI::EventQueue::popEvent
public |
Event popEvent( | ) |
Remove the first element from the event queue and return it.
Returns
Element that has been the first element of the event queue
Exceptions
- std::logic_error
- if there are no events available
Defined in Util/UI/EventQueue.h:109
function
Util::UI::EventQueue::registerEventGenerator
public |
void registerEventGenerator( | const event_generator_t & | generator ) |
Register the given function as an event generator.
Parameters
- generator
- Event generator that creates an array of events
Defined in Util/UI/EventQueue.h:116
function
Util::UI::EventQueue::registerEventHandler
public |
void registerEventHandler( | const event_handler_t & | handler ) |
Register the given function as an event handler.
Parameters
- handler
- Event handler that takes a single event
Defined in Util/UI/EventQueue.h:123
function
Util::UI::EventQueue::process
public |
void process( | ) |
Collect generated events and pass them to handlers.
Note: This function has to be called regularly to ensure the processing of events.
Defined in Util/UI/EventQueue.h:133