.. _event definitions: .. include:: ../../defs.hrst Event Definitions ################# Event definitions are used to enable the Dispatcher to consume specific events. Defining an event definition can be done via the following macro: .. literalinclude:: ../../../../src/obscura/event_system/event_definitions/event_definition.hxx :lines: 19-45 :language: c++ Key Event Definition -------------------- The event definition for key events are implemented as follows: .. literalinclude:: ../../../../src/obscura/event_system/event_definitions/key_event_definitions.hxx :language: c++ Example ^^^^^^^ This example shows how key events can be used. The example implements a listener for key events, registers it with the dispatcher and then sends various events to the dispatcher and dispatches them. .. literalinclude:: ../../../../examples/listen_to_events/listen_to_key_events.cxx :language: c++ Mouse Event Definition ---------------------- Mouse events are emitted whenever a mouse movement or mouse click is being done. The event definition for mouse events are implemented as follows: .. literalinclude:: ../../../../src/obscura/event_system/event_definitions/mouse_event_definitions.hxx :language: c++ Example ^^^^^^^ This example shows how key events can be used. The example implements a listener for mouse events, registers it with the dispatcher and then sends various events to the dispatcher and dispatches them. .. literalinclude:: ../../../../examples/listen_to_events/listen_to_mouse_events.cxx :language: c++ Loop Event Definition --------------------- Loop events are triggered by the game loop(s). The events that are emitted are ``TickEvent``s that are either emitted for each tick or emitted at the end of the loop. Here is how loop events are implemented .. literalinclude:: ../../../../src/obscura/event_system/event_definitions/loop_event_definitions.hxx :language: c++ Example ^^^^^^^ .. literalinclude:: ../../../../examples/listen_to_events/listen_to_loop_events.cxx :language: c++ Window Event Definition ----------------------- Window events are emitted whenever there is a change to the window. The events are defined as follows: .. literalinclude:: ../../../../src/obscura/event_system/event_definitions/window_event_defintions.hxx :language: c++ Example ^^^^^^^ .. literalinclude:: ../../../../examples/listen_to_events/listen_to_window_events.cxx :language: c++ Custom Event Definition ----------------------- For creating a custom event that can be used with |Obscura| you have to implement a respective event definition and pass the definition to the :ref:`Dispatcher `. The following example shows how to define a custom event definition and how to use it in combination with the dispatcher: .. literalinclude:: ../../../../examples/use_custom_event.cxx :language: c++