kiba-engine
Data Structures | Typedefs | Enumerations | Functions
event.h File Reference

Event system. More...

#include <kiba/defines.h>
Include dependency graph for event.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  event_context
 Context used to store data of an event. More...
 

Typedefs

typedef struct event_context event_context
 Context used to store data of an event.
 
typedef enum engine_event_code engine_event_code
 Engine internal event codes. More...
 
typedef b8(* on_event_function) (u16 event_code, void *sender, void *listener, event_context context)
 Function signature for event callbacks. More...
 

Enumerations

enum  engine_event_code {
  EVENT_CODE_APPLICATION_QUIT , EVENT_CODE_KEY_PRESSED , EVENT_CODE_KEY_RELEASED , EVENT_CODE_MOUSE_MOVED ,
  EVENT_CODE_MOUSE_WHEEL , EVENT_CODE_WINDOW_RESIZE , EVENT_CODE_WINDOW_MINIMIZED , EVENT_CODE_WINDOW_RAISED ,
  ENGINE_EVENT_CODE_MAX = 0x00FF , APPLICATION_EVENT_CODE_MAX = 0xFFFF
}
 Engine internal event codes. More...
 

Functions

b8 event_initialize (void)
 Initialize the event system. More...
 
void event_shutdown (void)
 Shutdown event system. More...
 
KB_API b8 event_register (u16 event_code, void *listener, on_event_function on_event, b8 append)
 Register a callback for a particular event type. More...
 
KB_API b8 event_unregister (u16 event_code, void *listener, on_event_function on_event)
 Unregister a callback for a particular event type. More...
 
KB_API b8 event_fire (u16 event_code, void *sender, event_context context)
 Fire an event. More...
 

Detailed Description

Event system.

Provides inteface to register event listener and fire events. The event code range from engine_event_code::ENGINE_EVENT_CODE_MAX to engine_event_code::APPLICATION_EVENT_CODE_MAX can be used by the application.

Definition in file event.h.

Typedef Documentation

◆ engine_event_code

Engine internal event codes.

Applications must not use the range of values from 0 to ENGINE_EVENT_CODE_MAX. Instead it should use the range starting right after until APPLICATION_EVENT_CODE_MAX for event codes.

◆ on_event_function

typedef b8(* on_event_function) (u16 event_code, void *sender, void *listener, event_context context)

Function signature for event callbacks.

Parameters
event_codethe code of the event passed to it
senderany kind of data set by the sender, can be NULL
listenerthe data which was provided to register the callback
contextcontextual data of the event passed to it
Returns
true if the event was handled properly, false if the event system should continue to process the event

Definition at line 73 of file event.h.

Enumeration Type Documentation

◆ engine_event_code

Engine internal event codes.

Applications must not use the range of values from 0 to ENGINE_EVENT_CODE_MAX. Instead it should use the range starting right after until APPLICATION_EVENT_CODE_MAX for event codes.

Enumerator
ENGINE_EVENT_CODE_MAX 

End of internal code range.

APPLICATION_EVENT_CODE_MAX 

End of external code range.

Definition at line 49 of file event.h.

Function Documentation

◆ event_fire()

KB_API b8 event_fire ( u16  event_code,
void *  sender,
event_context  context 
)

Fire an event.

The event system will propagate the event to all registered listeners.

Parameters
event_codethe code of the event being fired
sendercustom sender data which will be forwarded into the listeners' callbacks
contextcontextual data for the event being fired
Returns
true if a registered listener handled the event, false otherwise

Definition at line 81 of file event.c.

◆ event_initialize()

b8 event_initialize ( void  )

Initialize the event system.

Prepares the internal state to process and forward events. Must be called once before using the event system.

Returns
false if an error occurred, true if succesful

Definition at line 40 of file event.c.

Here is the call graph for this function:

◆ event_register()

KB_API b8 event_register ( u16  event_code,
void *  listener,
on_event_function  on_event,
b8  append 
)

Register a callback for a particular event type.

Parameters
event_codethe event code to listen for
listenercustom data which will be passed to the callback when it is called
on_eventthe callback to be called by the event system
appendregister at the end of the priority list (true) or at the beginning (false)
Returns
true if the callback was registered successfully, false otherwise

Definition at line 47 of file event.c.

Here is the call graph for this function:

◆ event_shutdown()

void event_shutdown ( void  )

Shutdown event system.

Definition at line 45 of file event.c.

◆ event_unregister()

KB_API b8 event_unregister ( u16  event_code,
void *  listener,
on_event_function  on_event 
)

Unregister a callback for a particular event type.

Parameters
event_codethe event code to unregister from
listenercustom data originally passed to the event_register call
on_eventthe callback to be unregistered
Returns
true if the callback was unregistered successfully, false otherwise (e.g. not found)

Definition at line 67 of file event.c.

Here is the call graph for this function: