146 for (
size_t x = 10; x < 490; ++x) {
155 int poly_x[] = { 100, 95, 95, 100, 100, 95, 75, 75, 95, 120, 140, 140, 120, 115, 115, 120, 120, 115, };
156 int poly_y[] = { 20, 25, 50, 55, 100, 100, 120, 145, 165, 165, 145, 120, 100, 100, 55, 50, 25, 20, };
163 {330, 270}, {270, 210}, {210, 270}, {210, 150}, {390, 210}, {450, 270},
164 {450, 150}, {180, 330}, {270, 390}, {390, 390}, {480, 330}, {330, 450},
165 {300, 480}, {360, 480},
168 size_t tris[13][3] = {
169 {0, 1, 2}, {0, 2, 3}, {0, 4, 5}, {0, 1, 4}, {4, 6, 5}, {2, 8, 7},
170 {0, 8, 2}, {0, 5, 9}, {9, 5, 10}, {8, 9, 11}, {8, 11, 12},
171 {9, 13, 11}, {11, 12, 13},
174 for (
size_t t = 0; t < 13; ++t) {
176 verts[tris[t][0]][0], verts[tris[t][0]][1],
177 verts[tris[t][1]][0], verts[tris[t][1]][1],
178 verts[tris[t][2]][0], verts[tris[t][2]][1],
185 bj_rect board = {.w = 10, .h = 10,};
186 for(
size_t y = 0 ; y < 8 ; ++y) {
187 for(
size_t x = 0 ; x < 8 ; ++x) {
188 board.
x = 200 + x * board.
w;
189 board.
y = 50 + y * board.
h;
199 &(
bj_rect) {.x = 200, .y = 50, .w = 80, .h = 80,},
205 for (
int r = 80; r > 0; r -= 20) {
232 (void)w; (void)dirty; (void)user_data;
236static void*
setup(
struct bj_app* app,
void* init_data) {
272static void teardown(
struct bj_app* app,
void* user_data) {
279int main(
int argc,
char* argv[]) {
280 (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)
Header file for Bitmap drawing functions.
static bj_bitmap * canvas
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_clear_bitmap(struct bj_bitmap *bitmap)
Fills the entire bitmap with the clear colour.
bj_bool bj_blit_stretched(const struct bj_bitmap *src, const struct bj_rect *src_area, struct bj_bitmap *dst, const struct bj_rect *dst_area, enum bj_blit_op op)
Stretched bitmap blitting (nearest neighbor).
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.
struct bj_bitmap * bj_create_bitmap(size_t width, size_t height, enum bj_pixel_mode mode, size_t stride)
Creates a new struct bj_bitmap with the specified width and height.
void bj_put_pixel(struct bj_bitmap *bitmap, size_t x, size_t y, uint32_t value)
Change the pixel colour at given coordinate.
void bj_destroy_bitmap(struct bj_bitmap *bitmap)
Deletes a struct bj_bitmap object and releases associated memory.
@ BJ_BLIT_OP_COPY
Copy source to destination (fast path when formats match)
struct bj_render_target bj_render_target
struct bj_bitmap bj_bitmap
struct bj_window bj_window
#define BJ_TRUE
Boolean true value (1).
void bj_draw_rectangle(struct bj_bitmap *bitmap, const struct bj_rect *area, uint32_t pixel)
Draws a rectangle in the given bitmap.
void bj_draw_polyline(struct bj_bitmap *bitmap, size_t count, const int *x, const int *y, bj_bool loop, uint32_t color)
Draw a polyline from C-style coordinate arrays.
void bj_draw_triangle(struct bj_bitmap *bitmap, int x0, int y0, int x1, int y1, int x2, int y2, uint32_t color)
Draws the edges of a triangle given its 3 corners.
void bj_draw_filled_rectangle(struct bj_bitmap *bitmap, const struct bj_rect *area, uint32_t pixel)
Draws a filled rectangle in the given bitmap.
void bj_draw_filled_circle(struct bj_bitmap *bitmap, int cx, int cy, int radius, uint32_t color)
Draw a filled circle onto a bitmap.
void bj_draw_filled_triangle(struct bj_bitmap *bitmap, int x0, int y0, int x1, int y1, int x2, int y2, uint32_t color)
Draws a filled triangle given its 3 corners.
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.
uint16_t w
Width in pixels.
uint16_t h
Height in pixels.
int16_t y
Y coordinate of the top-left corner (pixels, can be negative).
int16_t x
X coordinate of the top-left corner (pixels, can be negative).
Axis-aligned rectangle: a top-left corner plus a width and height.
@ BJ_PIXEL_MODE_XRGB8888
32bpp RGB
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.
@ BJ_WINDOW_FLAG_RESIZABLE
User may resize the window.
Logging utility functions.
Portable main() replacement with platform-aware entry shim.
Header file for general pixel manipulation facilities.
Header file for system interactions.
Header file for bj_window type.