cmdfx 0.1.0
Lightweight game engine for your terminal
|
Events API for CmdFX. More...
Go to the source code of this file.
Classes | |
struct | CmdFX_ResizeEvent |
The payload for the CMDFX_EVENT_RESIZE event. More... | |
struct | CmdFX_KeyEvent |
The payload for the CMDFX_EVENT_KEY event. More... | |
struct | CmdFX_Event |
The main event structure for CmdFX. More... | |
Macros | |
#define | EVENT_TICK 10 |
The time between event loop iterations, in milliseconds. | |
#define | CMDFX_EVENT_RESIZE 0 |
Called when the terminal is resized. | |
#define | CMDFX_EVENT_KEY 1 |
Called when a key is pressed. | |
#define | CMDFX_EVENT_MOUSE 2 |
Called when the mouse is moved or clicked. | |
Typedefs | |
typedef struct CmdFX_ResizeEvent | CmdFX_ResizeEvent |
The payload for the CMDFX_EVENT_RESIZE event. | |
typedef struct CmdFX_KeyEvent | CmdFX_KeyEvent |
The payload for the CMDFX_EVENT_KEY event. | |
typedef int(* | EventCallback) (struct CmdFX_Event *event) |
Represents an event callback. | |
typedef struct CmdFX_Event | CmdFX_Event |
The main event structure for CmdFX. | |
Functions | |
int | addCmdFXEventListener (unsigned int id, EventCallback callback) |
Adds an event listener. | |
EventCallback * | getCmdFXEventListener (unsigned int eventId, unsigned int listenerId) |
Gets an event listener. | |
int | removeCmdFXEventListener (unsigned int eventId, unsigned int listenerId) |
Removes an event listener. | |
const EventCallback ** | dispatchCmdFXEvent (CmdFX_Event *event) |
Dispatches an event. | |
int | beginCmdFXEventLoop () |
Starts the event loop for CmdFX. | |
int | endCmdFXEventLoop () |
Ends the event loop for CmdFX. | |
Events API for CmdFX.
#define CMDFX_EVENT_KEY 1 |
Called when a key is pressed.
The data is a pointer to a struct CmdFX_KeyEvent
.
#define CMDFX_EVENT_MOUSE 2 |
Called when the mouse is moved or clicked.
The data is a pointer to a struct CmdFX_MouseEvent
.
#define CMDFX_EVENT_RESIZE 0 |
Called when the terminal is resized.
The data is a pointer to a struct CmdFX_ResizeEvent
.
#define EVENT_TICK 10 |
The time between event loop iterations, in milliseconds.
This value is used to determine how often the event loop should check for events. A lower value will result in more frequent event checks, but may consume more CPU resources. A higher value will result in less frequent event checks, but may cause events to be missed. This is usually set to avoid a "busy loop" that consumes too many resources.
The value used for CmdFX events is 10 milliseconds.
typedef struct CmdFX_Event CmdFX_Event |
The main event structure for CmdFX.
id | The event ID. |
time | The time the event was created, in milliseconds. |
data | A pointer to the data associated with the event. |
int addCmdFXEventListener | ( | unsigned int | id, |
EventCallback | callback ) |
Adds an event listener.
The listener will be called when the event with the specified ID is dispatched. The library has an internal limit of 1,024 listeners across all events.
id | The event ID. |
callback | The event callback. |
int beginCmdFXEventLoop | ( | ) |
Starts the event loop for CmdFX.
This method is called automatically if a listener is added.
const EventCallback ** dispatchCmdFXEvent | ( | CmdFX_Event * | event | ) |
Dispatches an event.
event | The event to dispatch. |
int endCmdFXEventLoop | ( | ) |
Ends the event loop for CmdFX.
EventCallback * getCmdFXEventListener | ( | unsigned int | eventId, |
unsigned int | listenerId ) |
Gets an event listener.
eventId | The ID of the event to remove the listener from. |
listenerId | The ID of the event listener to retrieve. |
int removeCmdFXEventListener | ( | unsigned int | eventId, |
unsigned int | listenerId ) |
Removes an event listener.
eventId | The ID of the event to remove the listener from. |
listenerId | The ID of the event listener to remove. |