37 bj_draw_textf(bmp, 18, (
struct bj_rect){20, 200, 0, 0},
BJ_TEXT_HALIGN_LEFT,
BJ_TEXT_VALIGN_TOP, white,
"Hello, %s!",
"world");
38 bj_draw_textf(bmp, 18, (
struct bj_rect){20, 230, 0, 0},
BJ_TEXT_HALIGN_LEFT,
BJ_TEXT_VALIGN_TOP, white,
"Score: %d Lives: %u", -123, 3);
39 bj_draw_textf(bmp, 18, (
struct bj_rect){20, 260, 0, 0},
BJ_TEXT_HALIGN_LEFT,
BJ_TEXT_VALIGN_TOP, white,
"Zero-pad: %08u Left: %-8u|", 42, 42);
40 bj_draw_textf(bmp, 18, (
struct bj_rect){20, 290, 0, 0},
BJ_TEXT_HALIGN_LEFT,
BJ_TEXT_VALIGN_TOP, white,
"Name: %.5s Pi≈%.3f (note: if %%f not supported, skip)",
"Banjo", 3.14159);
41 bj_draw_textf(bmp, 18, (
struct bj_rect){20, 320, 0, 0},
BJ_TEXT_HALIGN_LEFT,
BJ_TEXT_VALIGN_TOP, white,
"HEX: 0x%08X oct: %o ptr: %p", 0xDEADBEEF, 0755, (
void*)bmp);
42 bj_draw_textf(bmp, 18, (
struct bj_rect){20, 350, 0, 0},
BJ_TEXT_HALIGN_LEFT,
BJ_TEXT_VALIGN_TOP, white,
"Width(*)=%*u Prec(*)=%. *u", 6, 123, 4, 123);
45 unsigned long long big = 18446744073709551615ull;
46 bj_draw_textf(bmp, 18, (
struct bj_rect){20, 380, 0, 0},
BJ_TEXT_HALIGN_LEFT,
BJ_TEXT_VALIGN_TOP, white,
"ll: %llu l: %ld h: %hd hh: %hhu",
47 big, (long)-123456, (short)1234, (
unsigned char)255);
53 bj_blit_text(bmp, 14, (
struct bj_rect){20, 116, 0, 0},
BJ_TEXT_HALIGN_LEFT,
BJ_TEXT_VALIGN_TOP, black, light_grey,
BJ_MASK_BG_OPAQUE,
"OPAQUE band (FG black)");
54 bj_blit_text(bmp, 32, (
struct bj_rect){20, 150, 0, 0},
BJ_TEXT_HALIGN_LEFT,
BJ_TEXT_VALIGN_TOP, black, cyan,
BJ_MASK_BG_REV_TRANSPARENT,
"CARVED cyan");
63 (void)w; (void)dirty; (void)user_data;
67static void*
setup(
struct bj_app* app,
void* init_data) {
93static void teardown(
struct bj_app* app,
void* user_data) {
99int main(
int argc,
char* argv[]) {
100 (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)
static void * setup(struct bj_app *app, void *init_data)
Header file for Bitmap type.
static void on_draw(struct bj_window *w, struct bj_render_target *target, const struct bj_rect *dirty, void *user_data)
void draw(bj_bitmap *bmp)
Sytem event management API.
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.
void bj_draw_textf(struct bj_bitmap *dst, unsigned height, struct bj_rect area, bj_text_halign halign, bj_text_valign valign, uint32_t fg_native, const char *fmt,...)
Prints formatted text into a bitmap, similar to printf.
uint32_t bj_make_bitmap_pixel(struct bj_bitmap *bitmap, uint8_t red, uint8_t green, uint8_t blue)
Returns an opaque value representing a pixel colour, given its RGB composition.
void bj_draw_text(struct bj_bitmap *dst, unsigned height, struct bj_rect area, bj_text_halign halign, bj_text_valign valign, uint32_t fg_native, const char *text)
Prints text using the default foreground colour and transparent background.
void bj_blit_text(struct bj_bitmap *dst, unsigned height, struct bj_rect area, bj_text_halign halign, bj_text_valign valign, uint32_t fg_native, uint32_t bg_native, bj_mask_bg_mode mode, const char *text)
Prints text with explicit foreground/background and background mode.
@ BJ_MASK_BG_OPAQUE
Opaque band: mix(background, foreground, mask)
@ BJ_MASK_BG_REV_TRANSPARENT
Carved: mix(destination, background, 1-mask)
@ BJ_TEXT_HALIGN_LEFT
Align text to the left edge of the area.
@ BJ_TEXT_VALIGN_TOP
Align text to the top edge of the area.
struct bj_render_target bj_render_target
struct bj_bitmap bj_bitmap
struct bj_window bj_window
void bj_dispatch_events(void)
Poll and dispatch all pending events.
void bj_close_on_escape(struct bj_window *window, const struct bj_key_event *event, void *user_data)
Handle the ESC key to close a window.
bj_key_callback_fn bj_set_key_callback(bj_key_callback_fn callback, void *user_data)
Set the global callback for keyboard key events.
Axis-aligned rectangle: a top-left corner plus a width and height.
bj_bool bj_begin(int systems, struct bj_error **error)
Initialises the system.
void bj_end(void)
De-initialises the system.
void bj_set_draw_callback(struct bj_window *window, bj_window_draw_fn fn, void *user_data)
Register the redraw callback for window.
static void bj_invalidate_window(struct bj_window *window)
Mark the whole window as needing a repaint.
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.
struct bj_bitmap * bj_render_target_bitmap(struct bj_render_target *target)
Reach the software framebuffer behind a render target.
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.
Logging utility functions.
Portable main() replacement with platform-aware entry shim.
Header file for system interactions.
Header file for bj_window type.