gfx2d sketch
This commit is contained in:
@@ -1,16 +1,8 @@
|
||||
fn_wasm_import void wasm_clear(void);
|
||||
fn_wasm_import void wasm_draw_text(isize str, i32 len, f64 x, f64 y, isize font_str, i32 font_len, i32 font_size, f32 r, f32 g, f32 b, f32 a);
|
||||
fn_wasm_import void wasm_draw_rect(f64 x, f64 y, f64 w, f64 h, f32 r, f32 g, f32 b, f32 a);
|
||||
fn_wasm_import f64 wasm_measure_text(isize str, i32 len, isize font_str, i32 font_len, i32 font_size);
|
||||
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_wasm_export char wasm_temp_buff1[128] = {[127] = 0x13};
|
||||
glb_wasm_export i32 wasm_temp_buff1_len = 127;
|
||||
glb_wasm_export char wasm_temp_buff2[128] = {[127] = 0x13};
|
||||
glb_wasm_export i32 wasm_temp_buff2_len = 127;
|
||||
|
||||
glb s8_t font_face = s8_const_lit("open_sans_regular");
|
||||
glb f64 wasm_dpr;
|
||||
glb ma_arena_t *wasm_input_text_arena;
|
||||
glb STACK(app_event_t, 64) wasm_events;
|
||||
@@ -24,40 +16,7 @@ struct wasm_cached_t {
|
||||
} wasm_cached;
|
||||
|
||||
fn void app_update(app_event_t *events, i32 event_count);
|
||||
|
||||
fn void set_clip(r2f64_t rect) {
|
||||
wasm_set_clip(wasm_dpr * rect.min.x, wasm_dpr * rect.min.y, wasm_dpr * (rect.max.x - rect.min.x), wasm_dpr * (rect.max.y - rect.min.y));
|
||||
}
|
||||
|
||||
fn f64 get_font_height(void) {
|
||||
return wasm_get_font_height((isize) font_face.str, font_face.len, 20*wasm_dpr) / wasm_dpr;
|
||||
}
|
||||
|
||||
fn f64 measure_text_ex(char *str, i32 len) {
|
||||
return wasm_measure_text((isize)str, len, (isize) font_face.str, font_face.len, 20*wasm_dpr) / wasm_dpr;
|
||||
}
|
||||
|
||||
fn f64 measure_text(char *str) {
|
||||
return measure_text_ex(str, str_len(str));
|
||||
}
|
||||
|
||||
fn void draw_text(v2f64_t pos, v4f32_t color, s8_t string) {
|
||||
wasm_draw_text((isize)string.str, string.len, wasm_dpr * pos.x, wasm_dpr * pos.y, (isize) font_face.str, font_face.len, 20*wasm_dpr, color.r * 255.f, color.g * 255.f, color.b * 255.f, color.a);
|
||||
}
|
||||
|
||||
fn void draw_textf(v2f64_t pos, char *str, ...) {
|
||||
char buff[1024];
|
||||
va_list args;
|
||||
va_start(args, str);
|
||||
i32 len = stbsp_vsnprintf(buff, sizeof(buff), str, args);
|
||||
va_end(args);
|
||||
|
||||
wasm_draw_text((isize)buff, len, wasm_dpr * pos.x, wasm_dpr * pos.y, (isize) font_face.str, font_face.len, 20*wasm_dpr, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
fn void draw_rect(r2f64_t rect, v4f32_t color) {
|
||||
wasm_draw_rect(wasm_dpr * rect.min.x, wasm_dpr * rect.min.y, wasm_dpr * (rect.max.x - rect.min.x), wasm_dpr * (rect.max.y - rect.min.y), color.r * 255.f, color.g * 255.f, color.b * 255.f, color.a);
|
||||
}
|
||||
fn void app_init(void);
|
||||
|
||||
fn void wasm_add_event(app_event_t event) {
|
||||
if (wasm_events.len < lengthof(wasm_events.data)) {
|
||||
@@ -206,8 +165,6 @@ fn_wasm_export void wasm_update(f64 time, f64 width, f64 height, f64 dpr) {
|
||||
}
|
||||
wasm_dpr = dpr;
|
||||
|
||||
wasm_clear();
|
||||
draw_rect(r2f64(0, 0, window_size.x, window_size.y), white_color_global);
|
||||
app_update(wasm_events.data, wasm_events.len);
|
||||
|
||||
wasm_events.len = 0;
|
||||
@@ -218,4 +175,5 @@ fn_wasm_export void wasm_update(f64 time, f64 width, f64 height, f64 dpr) {
|
||||
fn_wasm_export void wasm_init(void) {
|
||||
core_init();
|
||||
wasm_input_text_arena = ma_push_arena(&tcx.perm, kib(1));
|
||||
app_init();
|
||||
}
|
||||
Reference in New Issue
Block a user