Banjo API 0.0.1
C99 game development API
|
Data Structures | |
struct | bj_enter_event_t |
struct | bj_cursor_event_t |
struct | bj_button_event_t |
struct | bj_key_event_t |
struct | bj_event_t |
union | bj_event_t.__unnamed0__ |
Typedefs | |
typedef enum bj_key_t | bj_key |
typedef enum bj_event_action_t | bj_event_action |
typedef struct bj_enter_event_t | bj_enter_event |
typedef struct bj_cursor_event_t | bj_cursor_event |
typedef struct bj_button_event_t | bj_button_event |
typedef struct bj_key_event_t | bj_key_event |
typedef enum bj_event_type_t | bj_event_type |
typedef struct bj_event_t | bj_event |
typedef void(* | bj_enter_callback_fn_t) (bj_window *, const bj_enter_event *, void *) |
typedef void(* | bj_cursor_callback_fn_t) (bj_window *p_window, const bj_cursor_event *, void *) |
typedef void(* | bj_button_callback_fn_t) (bj_window *p_window, const bj_button_event *, void *) |
typedef void(* | bj_key_callback_fn_t) (bj_window *p_window, const bj_key_event *, void *) |
Handle input events such as keyboard, mouse and focus.
The event system provides a simple callback interface for handling user interactions with windows, including cursor movement, button presses, keyboard input, and window enter/leave detection.
Events are dispatched via polling with bj_dispatch_events.
struct bj_enter_event_t |
Represent a mouse enter or leave event.
Data Fields | ||
---|---|---|
bj_bool | enter | BJ_TRUE if entering window, BJ_FALSE if leaving. |
int | x | Cursor x position. |
int | y | Cursor y position. |
struct bj_cursor_event_t |
struct bj_button_event_t |
Represent a mouse button event.
Data Fields | ||
---|---|---|
bj_event_action | action | Action (press/release) |
int | button | Button identifier (e.g., BJ_BUTTON_LEFT) |
int | x | Cursor x position. |
int | y | Cursor y position. |
struct bj_key_event_t |
Represent a keyboard key event.
Data Fields | ||
---|---|---|
bj_event_action | action | Action (press/release/repeat) |
bj_key | key | Key identifier. |
int | scancode | Scancode (layout-independent) |
struct bj_event_t |
Represent a generic window-related event.
This union-based structure wraps all types of input events.
Data Fields | ||
---|---|---|
union bj_event_t.__unnamed0__ | __unnamed__ | |
bj_event_type | type | Type of event. |
bj_window * | window | Target window. |
union bj_event_t.__unnamed0__ |
Data Fields | ||
---|---|---|
bj_button_event | button | Button event data. |
bj_cursor_event | cursor | Cursor event data. |
bj_enter_event | enter | Enter/leave event data. |
bj_key_event | key | Key event data. |
#define BJ_BUTTON_1 1 |
First button.
#define BJ_BUTTON_2 2 |
Second button.
#define BJ_BUTTON_3 3 |
Third button.
#define BJ_BUTTON_4 4 |
Fourth button.
#define BJ_BUTTON_5 5 |
Fifth button.
#define BJ_BUTTON_DOWN BJ_BUTTON_5 |
Scroll down mouse button.
#define BJ_BUTTON_LEFT BJ_BUTTON_1 |
Left mouse button.
#define BJ_BUTTON_MIDDLE BJ_BUTTON_2 |
Middle mouse button.
#define BJ_BUTTON_RIGHT BJ_BUTTON_3 |
Right mouse button.
#define BJ_BUTTON_UP BJ_BUTTON_4 |
Scroll up mouse button.
#define BJ_KEY_APOSTROPHE BJ_KEY_OEM_7 |
Alias for BJ_KEY_OEM_7.
#define BJ_KEY_BACKSLASH BJ_KEY_OEM_5 |
Alias for BJ_KEY_OEM_5.
#define BJ_KEY_BACKSPACE BJ_KEY_BACK |
Alias for BJ_KEY_BACK.
#define BJ_KEY_CAPSLOCK BJ_KEY_CAPITAL |
Alias for BJ_KEY_CAPITAL.
#define BJ_KEY_COMMA BJ_KEY_OEM_COMMA |
Alias for BJ_KEY_OEM_COMMA.
#define BJ_KEY_ENTER BJ_KEY_RETURN |
Alias for BJ_KEY_RETURN.
#define BJ_KEY_GRAVE_ACCENT BJ_KEY_OEM_3 |
Alias for BJ_KEY_OEM_3.
#define BJ_KEY_HANGUL BJ_KEY_KANA |
Alias for BJ_KEY_KANA.
#define BJ_KEY_HANJA BJ_KEY_KANJI |
Alias for BJ_KEY_KANJI.
#define BJ_KEY_LEFT_ALT BJ_KEY_LMENU |
Alias for BJ_KEY_LMENU.
#define BJ_KEY_LEFT_BRACKET BJ_KEY_OEM_4 |
Alias for BJ_KEY_OEM_4.
#define BJ_KEY_LEFT_CONTROL BJ_KEY_LCONTROL |
Alias for BJ_KEY_LCONTROL.
#define BJ_KEY_LEFT_OS BJ_KEY_LWIN |
Alias for BJ_KEY_LWIN.
#define BJ_KEY_LEFT_SHIT BJ_KEY_LSHIFT |
Alias for BJ_KEY_LSHIFT.
#define BJ_KEY_MINUS BJ_KEY_OEM_MINUS |
Alias for BJ_KEY_OEM_MINUS.
#define BJ_KEY_PAGE_DOWN BJ_KEY_NEXT |
Alias for BJ_KEY_NEXT.
#define BJ_KEY_PAGE_UP BJ_KEY_PRIOR |
Alias for BJ_KEY_PRIOR.
#define BJ_KEY_PERIOD BJ_KEY_OEM_PERIOD |
Alias for BJ_KEY_OEM_PERIOD.
#define BJ_KEY_PLUS BJ_KEY_OEM_PLUS |
Alias for BJ_KEY_OEM_PLUS.
#define BJ_KEY_PRINT_SCREEN BJ_KEY_SNAPSHOT |
Alias for BJ_KEY_SNAPSHOT.
#define BJ_KEY_RIGHT_ALT BJ_KEY_RMENU |
Alias for BJ_KEY_RMENU.
#define BJ_KEY_RIGHT_BRACKET BJ_KEY_OEM_6 |
Alias for BJ_KEY_OEM_6.
#define BJ_KEY_RIGHT_CONTROL BJ_KEY_RCONTROL |
Alias for BJ_KEY_RCONTROL.
#define BJ_KEY_RIGHT_OS BJ_KEY_RWIN |
Alias for BJ_KEY_RWIN.
#define BJ_KEY_RIGHT_SHIFT BJ_KEY_RSHIFT |
Alias for BJ_KEY_RSHIFT.
#define BJ_KEY_SEMICOLON BJ_KEY_OEM_1 |
Alias for BJ_KEY_OEM_1.
#define BJ_KEY_SLASH BJ_KEY_OEM_2 |
Alias for BJ_KEY_OEM_2.
typedef void(* bj_button_callback_fn_t) (bj_window *p_window, const bj_button_event *, void *) |
Define the callback type for mouse button events.
Called when a mouse button is pressed or released.
typedef struct bj_button_event_t bj_button_event |
Represent a mouse button event.
typedef void(* bj_cursor_callback_fn_t) (bj_window *p_window, const bj_cursor_event *, void *) |
Define the callback type for cursor movement events.
Called when the cursor moves inside a window.
typedef struct bj_cursor_event_t bj_cursor_event |
Represent a mouse cursor movement event.
typedef void(* bj_enter_callback_fn_t) (bj_window *, const bj_enter_event *, void *) |
Define the callback type for enter events.
Called when the cursor enters or exits a window.
typedef struct bj_enter_event_t bj_enter_event |
Represent a mouse enter or leave event.
typedef struct bj_event_t bj_event |
Represent a generic window-related event.
This union-based structure wraps all types of input events.
typedef enum bj_event_action_t bj_event_action |
Define event action types for keys or mouse buttons.
typedef enum bj_event_type_t bj_event_type |
Identify the type of a generic event.
List of possible keys on a keyboard.
The values are directly taken from the [VK codes in Microsoft API] (https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes) This also includes the annotated documentation of each key.
Even if all values from the abovementioned page are present in this enum, not all are used by Banjo and some are never returned by key events.
Values for 0-9 and A-Z keys directly directly correspond to their ASCII equivalent.
typedef void(* bj_key_callback_fn_t) (bj_window *p_window, const bj_key_event *, void *) |
Define the callback type for keyboard key events.
Called when a key is pressed, released, or repeated.
typedef struct bj_key_event_t bj_key_event |
Represent a keyboard key event.
enum bj_event_action_t |
enum bj_event_type_t |
enum bj_key_t |
List of possible keys on a keyboard.
The values are directly taken from the [VK codes in Microsoft API] (https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes) This also includes the annotated documentation of each key.
Even if all values from the abovementioned page are present in this enum, not all are used by Banjo and some are never returned by key events.
Values for 0-9 and A-Z keys directly directly correspond to their ASCII equivalent.
void bj_close_on_escape | ( | bj_window * | p_window, |
const bj_key_event * | p_event, | ||
void * | p_user_data ) |
Handle the ESC key to close a window.
This utility callback closes the window when BJ_KEY_ESCAPE is pressed. Can be passed directly to bj_set_key_callback or called manually by your event system.
p_window | Target window pointer (must not be NULL). |
p_event | Key event data (must not be NULL). |
p_user_data | Opaque user pointer provided at callback registration. Not used by this function. |
void bj_dispatch_event | ( | const bj_event * | p_event | ) |
Dispatch a single event to registered callbacks.
Invokes the appropriate callback(s) associated with the event type. Does not take ownership of p_event
; the caller manages its lifetime.
p_event | Pointer to the event to dispatch (must not be NULL). |
void bj_dispatch_events | ( | void | ) |
Poll and dispatch all pending events.
This function checks for new input events and invokes the appropriate registered callbacks.
const char * bj_key_name | ( | int | key | ) |
Poll the next pending event from the system queue.
Retrieves and removes the next event, if any.
If no events are available, returns BJ_FALSE and does not modify p_event
.
p_event | Pointer to a bj_event structure to be filled (must not be NULL). |
BJ_TRUE | An event was retrieved and written to p_event . |
BJ_FALSE | No event available. |
void bj_push_button_event | ( | bj_window * | p_window, |
int | button, | ||
bj_event_action | action, | ||
int | x, | ||
int | y ) |
Push a mouse button event.
Represents a mouse button press or release within a window.
p_window | Pointer to the window receiving the event. |
button | The mouse button identifier. |
action | The action performed (press or release). |
x | The x-coordinate of the cursor at the event. |
y | The y-coordinate of the cursor at the event. |
void bj_push_cursor_event | ( | bj_window * | p_window, |
int | x, | ||
int | y ) |
Push a cursor movement event.
Indicates the cursor has moved within the specified window.
p_window | Pointer to the window receiving the event. |
x | The new x-coordinate of the cursor. |
y | The new y-coordinate of the cursor. |
Push an enter or leave window event.
Indicates whether the cursor entered or left the specified window.
p_window | Pointer to the window receiving the event. |
enter | BJ_TRUE if cursor entered the window, BJ_FALSE if left. |
x | The x-coordinate of the cursor at the event. |
y | The y-coordinate of the cursor at the event. |
void bj_push_event | ( | const bj_event * | e | ) |
Push a custom event to the internal event queue.
Typically used by the platform backend to post low-level events into the event processing system.
e | Pointer to the event to push. |
void bj_push_key_event | ( | bj_window * | p_window, |
bj_event_action | action, | ||
bj_key | key, | ||
int | scancode ) |
Push a keyboard event into the event system.
This function creates and queues a keyboard event reflecting a key press, release, or repeat.
p_window | Pointer to the window receiving the event. |
action | The key event action (press, release, repeat). |
key | The key code that triggered the event. |
scancode | The platform-specific scancode of the key. |
bj_button_callback_fn_t bj_set_button_callback | ( | bj_button_callback_fn_t | p_callback, |
void * | p_user_data ) |
Set the global callback for mouse button events.
p_callback | The new callback function |
p_user_data | Location to user-provided data. |
bj_cursor_callback_fn_t bj_set_cursor_callback | ( | bj_cursor_callback_fn_t | p_callback, |
void * | p_user_data ) |
Set the global callback for cursor events.
p_callback | The new callback function |
p_user_data | Location to user-provided data. |
bj_enter_callback_fn_t bj_set_enter_callback | ( | bj_enter_callback_fn_t | p_callback, |
void * | p_user_data ) |
Set the global callback for mouse enter/leave events.
p_callback | The new callback function |
p_user_data | Location to user-provided data. |
bj_key_callback_fn_t bj_set_key_callback | ( | bj_key_callback_fn_t | p_callback, |
void * | p_user_data ) |
Set the global callback for keyboard key events.
p_callback | The new callback function |
p_user_data | Location to user-provided data. |