This commit is contained in:
krzosa
2024-12-31 14:48:19 +01:00
parent 3f9f90466b
commit 05d49eefe8
19 changed files with 262 additions and 195 deletions

View File

@@ -5,7 +5,7 @@ fn_wasm_import f64 wasm_measure_text(isize str, i32 len, isize font_str, i32 fo
fn_wasm_import f64 wasm_get_font_height(isize font_str, i32 font_len, i32 font_size);
fn_wasm_import void wasm_set_clip(f64 x, f64 y, f64 w, f64 h);
glb s8_t font_face = s8_const_lit("open_sans_regular");
global s8_t font_face = s8_const_lit("open_sans_regular");
fn void set_clip(r2f64_t rect) {
@@ -52,17 +52,17 @@ typedef enum {
typedef struct gfx2d_cmd_t gfx2d_cmd_t;
struct gfx2d_cmd_t {
gfx2d_cmd_t *next;
gfx2d_kind_t kind;
r2f64_t rect;
v4f32_t color;
s8_t text;
r2f64_t rect;
v4f32_t color;
s8_t text;
};
typedef struct gfx2d_t gfx2d_t;
struct gfx2d_t {
ma_arena_t *ma;
gfx2d_cmd_t *cmds;
i32 cmds_len;
gfx2d_cmd_t *first;
gfx2d_cmd_t *last;
app_event_t *ev;
};
@@ -73,9 +73,7 @@ void gfx2d_begin(gfx2d_t *gfx, app_event_t *ev) {
void gfx2d_end(gfx2d_t *gfx) {
app_event_t *ev = gfx->ev;
r2f64_t window = (r2f64_t){0, 0, ev->window_size.x, ev->window_size.y};
for (i32 i = 0; i < gfx->cmds_len; i += 1) {
gfx2d_cmd_t *cmd = gfx->cmds + i;
for (gfx2d_cmd_t *cmd = gfx->first; cmd; cmd = cmd->next) {
if (cmd->kind == gfx2d_kind_clear) {
wasm_clear();
draw_rect(window, cmd->color);
@@ -90,15 +88,13 @@ void gfx2d_end(gfx2d_t *gfx) {
}
}
gfx->cmds_len = 0;
ma_set0(gfx->ma);
gfx->first = gfx->last = NULL;
}
void gfx2d_add_cmd(gfx2d_t *gfx, gfx2d_cmd_t cmd) {
gfx2d_cmd_t *c = ma_push_type(gfx->ma, gfx2d_cmd_t);
gfx2d_cmd_t *c = ma_push_type(tcx.temp, gfx2d_cmd_t);
*c = cmd;
if (gfx->cmds_len == 0) gfx->cmds = c;
gfx->cmds_len += 1;
SLLQ_APPEND(gfx->first, gfx->last, c);
}
void gfx2d_clear(gfx2d_t *gfx, v4f32_t color) {