Banjo API 0.0.1
Multi-purpose C99 API
Loading...
Searching...
No Matches
window.c

How to open and close windows.

How to open and close windows.

#define BJ_AUTOMAIN_CALLBACKS
#include <banjo/event.h>
#include <banjo/log.h>
#include <banjo/main.h>
#include <banjo/system.h>
#include <banjo/window.h>
bj_window* window = 0;
void key_callback(bj_window* p_window, const bj_key_event* e, void* data) {
(void)data;
(void)p_window;
switch(e->action) {
case BJ_PRESS:
bj_info("Pressed");
break;
case BJ_RELEASE:
bj_info("Released");
break;
case BJ_REPEAT:
bj_info("Repeat");
break;
}
}
int bj_app_begin(void** user_data, int argc, char* argv[]) {
(void)user_data; (void)argc; (void)argv;
bj_error* p_error = 0;
if(!bj_begin(&p_error)) {
bj_err("Error 0x%08X: %s", p_error->code, p_error->message);
return bj_callback_exit_error;
}
window = bj_window_new("Simple Banjo Window", 100, 100, 800, 600, 0);
bj_set_key_callback(key_callback, 0);
return bj_callback_continue;
}
int bj_app_iterate(void* user_data) {
(void)user_data;
return bj_window_should_close(window)
? bj_callback_exit_success
: bj_callback_continue;
}
int bj_app_end(void* user_data, int status) {
(void)user_data;
bj_window_del(window);
bj_end(0);
return status;
}
uint32_t code
Error code.
Definition error.h:132
char message[BJ_ERROR_MESSAGE_MAX_LEN+1]
Optional error description.
Definition error.h:133
Error structure.
Definition error.h:131
bj_event_action action
Action (press/release/repeat)
Definition event.h:331
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.
void bj_dispatch_events(void)
Poll and dispatch all pending events.
struct bj_key_event_t bj_key_event
Represent a keyboard key event.
@ BJ_PRESS
The key or button was pressed.
Definition event.h:294
@ BJ_REPEAT
The key is being held (repeats)
Definition event.h:295
@ BJ_RELEASE
The key or button was released.
Definition event.h:293
#define bj_info(...)
Log a message using the BJ_LOG_INFO level.
Definition log.h:103
#define bj_err(...)
Log a message using the BJ_LOG_ERROR level.
Definition log.h:131
void bj_end(bj_error **p_error)
De-initializes the system.
bj_bool bj_begin(bj_error **p_error)
Initializes the system.
bj_window * bj_window_new(const char *p_title, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t flags)
Create a new bj_window with the specified attributes.
bj_bool bj_window_should_close(bj_window *p_window)
Get the close flag state of a window.
struct bj_window_t bj_window
Opaque typedef for the window type.
Definition window.h:17
void bj_window_set_should_close(bj_window *p_window)
Flag a given window to be closed.
void bj_window_del(bj_window *p_window)
Deletes a bj_window object and releases associated memory.
Logging utility functions.
Header file for system interactions.
Header file for bj_window type.