129 bj_info(
"Cursor event, window %p, (%d,%d)",
130 (
void*)p_window, e->
x, e->
y
137 bj_info(
"Button event, window %p, button %d, %s, (%d,%d)",
138 (
void*)p_window, e->
button,
149 const char* action_str =
"pressed";
154 bj_info(
"Key 0x%04X (%s) Scancode 0x%04X (with no mods) was %s",
166 bj_info(
"Enter event, window %p, %s, (%d,%d)",
168 e->
enter ?
"entered" :
"left",
180 bj_info(
"Resize event, window %p, %dx%d", (
void*)p_window, width, height);
183static void*
setup(
struct bj_app* app,
void* init_data) {
223static void teardown(
struct bj_app* app,
void* user_data) {
226 bj_info(
"Total events: %ld cursor, %ld button, %ld key, %ld enter, %ld resize",
235int main(
int argc,
char* argv[]) {
236 (void)argc; (void)argv;
Application lifecycle: callback-driven setup, step, and teardown.
int main(int argc, char *argv[])
static void step(struct bj_app *app, struct bj_tick_info tick, void *user_data)
static void teardown(struct bj_app *app, void *user_data)
bj_audio_play_note_data data
static void * setup(struct bj_app *app, void *init_data)
Recoverable error handling.
Sytem event management API.
void button_callback(bj_window *p_window, const bj_button_event *e, void *data)
void cursor_callback(bj_window *p_window, const bj_cursor_event *e, void *data)
void resize_callback(bj_window *p_window, int width, int height, void *data)
void enter_callback(bj_window *p_window, const bj_enter_event *e, void *data)
void key_callback(bj_window *p_window, const bj_key_event *e, void *data)
int bj_run_app(bj_app_setup_fn setup, bj_app_step_fn step, bj_app_fixed_step_fn fixed_step, bj_app_teardown_fn teardown, void *init_data)
Drive the application lifecycle.
void bj_quit_app(struct bj_app *app, int exit_code)
Signal the given application to exit on the next iteration.
Timing snapshot handed to the step and fixed-step callbacks.
struct bj_window bj_window
int scancode
Scancode (layout-independent)
int button
Button identifier (e.g., BJ_BUTTON_LEFT)
bj_bool enter
BJ_TRUE if entering window, BJ_FALSE if leaving.
enum bj_event_action action
Action (press/release/repeat)
enum bj_event_action action
Action (press/release)
enum bj_key key
Key identifier.
const char * bj_key_name(int key)
Get the string name of a key.
void bj_dispatch_events(void)
Poll and dispatch all pending events.
bj_cursor_callback_fn bj_set_cursor_callback(bj_cursor_callback_fn callback, void *user_data)
Set the global callback for cursor events.
bj_enter_callback_fn bj_set_enter_callback(bj_enter_callback_fn callback, void *user_data)
Set the global callback for mouse enter/leave events.
bj_key_callback_fn bj_set_key_callback(bj_key_callback_fn callback, void *user_data)
Set the global callback for keyboard key events.
bj_button_callback_fn bj_set_button_callback(bj_button_callback_fn callback, void *user_data)
Set the global callback for mouse button events.
@ BJ_PRESS
The key or button was pressed.
@ BJ_RELEASE
The key or button was released.
Represent a mouse cursor movement event.
Represent a mouse enter or leave event.
Represent a keyboard key event.
#define bj_info(...)
Log a message using the BJ_LOG_INFO level.
void * bj_calloc(size_t size)
Allocate size bytes of zero-initialised memory.
void bj_free(void *memory)
Free a previously allocated memory block.
bj_bool bj_begin(int systems, struct bj_error **error)
Initialises the system.
void bj_end(void)
De-initialises the system.
void bj_set_window_should_close(struct bj_window *window)
Flag a given window to be closed.
struct bj_window * bj_bind_window(const char *title, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t flags, struct bj_error **error)
Create a new struct bj_window with the specified attributes.
void bj_set_resize_callback(struct bj_window *window, bj_window_resize_fn fn, void *user_data)
Register the resize callback for window.
bj_bool bj_should_close_window(struct bj_window *window)
Get the close flag state of a window.
void bj_unbind_window(struct bj_window *window)
Deletes a struct bj_window object and releases associated memory.
@ BJ_WINDOW_FLAG_RESIZABLE
User may resize the window.
Logging utility functions.
Portable main() replacement with platform-aware entry shim.
All memory-related functions, including custom allocators.
Header file for system interactions.
Header file for bj_window type.