Text rendering with built-in fonts, ANSI colours, and printf-style formatting.
Text rendering with built-in fonts, ANSI colours, and printf-style formatting.Banjo includes bitmap text rendering with a built-in font. No external font files are needed. Text can be rendered with ANSI escape codes for inline colours, printf-style formatting, and various transparency modes.
bj_draw_text(bmp, 20, 20, 18, white,
"\x1B[31mRED\x1B[0m normal");
bj_draw_text(bmp, 20, 52, 18, white,
"\x1B[94mBrightBlue\x1B[0m + default");
bj_draw_text(bmp, 20, 84, 18, white,
"\x1B[38;2;255;128;0mTruecolor Orange\x1B[0m");
bj_draw_textf(bmp, 20, 230, 18, white,
"Score: %d Lives: %u", -123, 3);
bj_draw_textf(bmp, 20, 260, 18, white,
"Zero-pad: %08u Left: %-8u|", 42, 42);
bj_draw_textf(bmp, 20, 290, 18, white,
"Name: %.5s Pi≈%.3f (note: if %%f not supported, skip)",
"Banjo", 3.14159);
bj_draw_textf(bmp, 20, 320, 18, white,
"HEX: 0x%08X oct: %o ptr: %p", 0xDEADBEEF, 0755, (
void*)bmp);
bj_draw_textf(bmp, 20, 350, 18, white,
"Width(*)=%*u Prec(*)=%. *u", 6, 123, 4, 123);
unsigned long long big = 18446744073709551615ull;
bj_draw_textf(bmp, 20, 380, 18, white,
"ll: %llu l: %ld h: %hd hh: %hhu",
big, (long)-123456, (short)1234, (unsigned char)255);
}
void* user_data
) {
(void)w; (void)dirty; (void)user_data;
}
static void*
setup(
struct bj_app* app,
void* init_data) {
(void)init_data;
return 0;
}
return 0;
}
static void step(
struct bj_app* app,
struct bj_tick_info tick,
void* user_data) {
(void)tick;
(void)user_data;
}
}
static void teardown(
struct bj_app* app,
void* user_data) {
(void)user_data;
}
int main(
int argc,
char* argv[]) {
(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.
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_blit_text(struct bj_bitmap *dst, int x, int y, unsigned height, 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.
void bj_draw_textf(struct bj_bitmap *bitmap, int x, int y, unsigned height, uint32_t fg_native, const char *fmt,...)
Prints formatted text into a bitmap, similar to printf.
void bj_draw_text(struct bj_bitmap *dst, int x, int y, unsigned height, uint32_t fg_native, const char *text)
Prints text using the default foreground colour and transparent background.
@ BJ_MASK_BG_OPAQUE
Opaque band: mix(background, foreground, mask)
@ BJ_MASK_BG_REV_TRANSPARENT
Carved: mix(destination, background, 1-mask)
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.