diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2025-02-14 17:30:28 +0100 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2025-02-14 17:30:28 +0100 |
commit | 7d92468a5d298ec6dd6455482ff0521efecf9541 (patch) | |
tree | a060fa81ed5b9187f8b98178582f7abbca69e29f /examples | |
parent | 9eb170e70a7be9ed418152ad1b679473fbe0c35a (diff) | |
download | reduced_system_layer-7d92468a5d298ec6dd6455482ff0521efecf9541.zip |
Adjust wasm code and examples for new features
Diffstat (limited to 'examples')
-rw-r--r-- | examples/echo.c | 4 | ||||
-rw-r--r-- | examples/graph.c | 54 | ||||
-rw-r--r-- | examples/sinewave.c | 8 | ||||
-rw-r--r-- | examples/ui.c | 45 |
4 files changed, 56 insertions, 55 deletions
diff --git a/examples/echo.c b/examples/echo.c index 1671be7..7d25001 100644 --- a/examples/echo.c +++ b/examples/echo.c @@ -43,7 +43,7 @@ i32 main(i32 argc, c8 **argv) { for (;;) { i64 n = network_recv( 0, - (IP_Address) { + (Network_Address) { .protocol = IPv4_UDP, .port = PORT, .v4_address = { 0, 0, 0, 0 }, @@ -77,7 +77,7 @@ i32 main(i32 argc, c8 **argv) { network_send( 0, - (IP_Address) { + (Network_Address) { .protocol = IPv4_UDP, .port = PORT, .v4_address = { 127, 0, 0, 1 }, diff --git a/examples/graph.c b/examples/graph.c index c1c84f2..75f83fa 100644 --- a/examples/graph.c +++ b/examples/graph.c @@ -61,11 +61,13 @@ void draw_node(i64 node_index) { color = (vec4_f32) { 0.f, .5f, 0.f, 1.f }; // green color fill_ellipse( - (Brush) { .color = color }, - n.x - n.radius, - n.y - n.radius, - n.radius * 2, - n.radius * 2 + color, + (Box) { + n.x - n.radius, + n.y - n.radius, + n.radius * 2, + n.radius * 2, + } ); } @@ -85,11 +87,11 @@ void draw_edge(i64 edge_index) { color = (vec4_f32) { 0.f, .5f, 0.f, 1.f }; // green color fill_line( - (Brush) { .color = color }, - n0.x, - n0.y, - n1.x, - n1.y, + color, + (vec2[2]) { + { n0.x, n0.y }, + { n1.x, n1.y }, + }, e.width ); } @@ -112,13 +114,14 @@ void update_node(i64 node_index) { Node n = world.nodes[node_index]; - world.nodes[node_index].hover = ellipse_contains( - n.x - n.radius, - n.y - n.radius, - n.radius * 2, - n.radius * 2, - g_platform.cursor_x, - g_platform.cursor_y + world.nodes[node_index].hover = hit_ellipse( + (Box) { + n.x - n.radius, + n.y - n.radius, + n.radius * 2, + n.radius * 2, + }, + (vec2) { g_platform.cursor_x, g_platform.cursor_y } ); } @@ -130,14 +133,13 @@ void update_edge(i64 edge_index) { Node n0 = world.nodes[e.src]; Node n1 = world.nodes[e.dst]; - world.edges[edge_index].hover = line_contains( - n0.x, - n0.y, - n1.x, - n1.y, + world.edges[edge_index].hover = hit_line( + (vec2[2]) { + { n0.x, n0.y }, + { n1.x, n1.y }, + }, e.width, - g_platform.cursor_x, - g_platform.cursor_y + (vec2) { g_platform.cursor_x, g_platform.cursor_y } ); } @@ -502,7 +504,7 @@ void update_and_render_frame(void) { // Render - fill_rectangle((Brush) { .color = { .7f, .8f, .9f, 1.f } }, 0, 0, g_platform.real_width, g_platform.real_height); + fill_rectangle_quick((vec4_f32) { .7f, .8f, .9f, 1.f }, (Box) { 0, 0, g_platform.real_width, g_platform.real_height }); if (adding_edge) { f64 x0 = world.nodes[adding_src].x; @@ -515,7 +517,7 @@ void update_and_render_frame(void) { y1 = world.nodes[adding_dst].y; } - fill_line((Brush) { .color = { .5f, 0.f, .5f, 1.f } }, x0, y0, x1, y1, 30); + fill_line((vec4_f32) { .5f, 0.f, .5f, 1.f }, (vec2[2]) { { x0, y0 }, { x1, y1 } }, 30); } draw_graph(); diff --git a/examples/sinewave.c b/examples/sinewave.c index 0c33803..d5072da 100644 --- a/examples/sinewave.c +++ b/examples/sinewave.c @@ -9,11 +9,11 @@ b8 ui_button(f64 x, f64 y, f64 width, f64 height) { b8 is_pressed = has_cursor && g_platform.key_down[BUTTON_LEFT]; if (is_pressed) - fill_rectangle(RGB(1.f, 1.f, 1.f), x, y, width, height); + fill_rectangle((vec4_f32) { 1.f, 1.f, 1.f, 1.f }, (Box) { x, y, width, height }); else if (has_cursor) - fill_rectangle(RGB(.8f, .8f, 0.f), x, y, width, height); + fill_rectangle((vec4_f32) { .8f, .8f, 0.f, 1.f }, (Box) { x, y, width, height }); else - fill_rectangle(RGB(.8f, .8f, .2f), x, y, width, height); + fill_rectangle((vec4_f32) { .8f, .8f, .2f, 1.f }, (Box) { x, y, width, height }); return has_cursor && g_platform.key_pressed[BUTTON_LEFT]; } @@ -22,7 +22,7 @@ void update_and_render_frame(void) { i32 num_events = handle_main_window_events(); if (num_events > 0) { - fill_rectangle(RGB(.1f, .1f, .1f), 0, 0, g_platform.frame_width, g_platform.frame_height); + fill_rectangle((vec4_f32) { .1f, .1f, .1f, 1.f }, (Box) { 0, 0, g_platform.frame_width, g_platform.frame_height }); if (ui_button(100, 100, 200, 200)) queue_primary_sound(0, PRIMARY_SOUND_SAMPLE_RATE, frames); diff --git a/examples/ui.c b/examples/ui.c index a3ca476..af9b89d 100644 --- a/examples/ui.c +++ b/examples/ui.c @@ -14,27 +14,26 @@ i64 selection = 0; void update_and_render_frame(void) { wait_main_window_events(); - Brush background = RGB(.2f, .1f, 0.f); - background.quick = 1; + vec4_f32 background = { .2f, .1f, 0.f, 1.f }; - Brush white = RGB(1.f, 1.f, 1.f); - Brush green = RGB(0.f, 1.f, 0.f); - Brush dark_green = RGB(.1f, .5f, .1f); - Brush red = RGB(1.f, 0.f, 0.f); - Brush light_red = RGB(1.f, .5f, .5f); - Brush light_green = RGB(.5f, 1.f, .5f); + vec4_f32 white = { 1.f, 1.f, 1.f, 1.f }; + vec4_f32 green = { 0.f, 1.f, 0.f, 1.f }; + vec4_f32 dark_green = { .1f, .5f, .1f, 1.f }; + vec4_f32 red = { 1.f, 0.f, 0.f, 1.f }; + vec4_f32 light_red = { 1.f, .5f, .5f, 1.f }; + vec4_f32 light_green = { .5f, 1.f, .5f, 1.f }; - fill_rectangle(background, 0, 0, g_platform.real_width, g_platform.real_height); + fill_rectangle_quick(background, (Box) { 0, 0, g_platform.real_width, g_platform.real_height }); if (g_platform.cursor_x >= 40 && g_platform.cursor_x < 100 && g_platform.cursor_y >= 40 && g_platform.cursor_y < 100) { button_0_down = g_platform.key_down[BUTTON_LEFT]; if (button_0_down) - fill_rectangle(white, 40, 40, 60, 60); + fill_rectangle(white, (Box) { 40, 40, 60, 60 }); else - fill_rectangle(green, 40, 40, 60, 60); + fill_rectangle(green, (Box) { 40, 40, 60, 60 }); } else { button_0_down = 0; - fill_rectangle(dark_green, 40, 40, 60, 60); + fill_rectangle(dark_green, (Box) { 40, 40, 60, 60 }); } if (g_platform.cursor_x >= 40 && g_platform.cursor_x < 100 && g_platform.cursor_y >= 120 && g_platform.cursor_y < 180) { @@ -42,17 +41,17 @@ void update_and_render_frame(void) { if (g_platform.key_pressed[BUTTON_LEFT]) button_1_checked = !button_1_checked; if (button_1_down) - fill_rectangle(white, 40, 120, 60, 60); + fill_rectangle(white, (Box) { 40, 120, 60, 60 }); else if (button_1_checked) - fill_rectangle(light_red, 40, 120, 60, 60); + fill_rectangle(light_red, (Box) { 40, 120, 60, 60 }); else - fill_rectangle(light_green, 40, 120, 60, 60); + fill_rectangle(light_green, (Box) { 40, 120, 60, 60 }); } else { button_1_down = 0; if (button_1_checked) - fill_rectangle(red, 40, 120, 60, 60); + fill_rectangle(red, (Box) { 40, 120, 60, 60 }); else - fill_rectangle(green, 40, 120, 60, 60); + fill_rectangle(green, (Box) { 40, 120, 60, 60 }); } f64 w = g_platform.real_width / 2.0; @@ -66,7 +65,7 @@ void update_and_render_frame(void) { g_platform.cursor_y >= y0 && g_platform.cursor_y < y0 + h) color = (vec4_f32) { 1.f, 1.f, 1.f, 1.f }; - for (i64 i = 0; i < g_platform.input_size; ++i) + for (i64 i = 0; i < g_platform.input_len; ++i) if (g_platform.input[i].ctrl) switch (g_platform.input[i].key) { case KEY_V: { @@ -104,7 +103,7 @@ void update_and_render_frame(void) { len += utf8_write(text[i0 + i], buf + len); if (len > 0) - p_clipboard_write_text(len, buf); + write_clipboard_text(len, buf); for (i64 i = 0; i1 + i < text_len; ++i) text[i0 + i] = text[i1 + i]; @@ -123,7 +122,7 @@ void update_and_render_frame(void) { len += utf8_write(text[i0 + i], buf + len); if (len > 0) - p_clipboard_write_text(len, buf); + write_clipboard_text(len, buf); } break; default:; @@ -222,9 +221,9 @@ void update_and_render_frame(void) { text[i] = g_platform.drop_files[0].data[i]; } - draw_text_area(RGB(0.f, 0.f, 0.f), x0 + 8, y0 - 8, w, h, 10., 10., text_len, text); - draw_text_area((Brush) { .color = color, }, x0, y0, w, h, 10., 10., text_len, text); - draw_text_cursor((Brush) { .xor_color = 1, .color = { 1.f, 1.f, 1.f, 1.f }, }, x0, y0, w, h, 10., 10., cursor, selection, text_len, text); + draw_text_cursor((vec4_f32) { 1.f, 1.f, 1.f, 1.f }, (Box) { x0, y0, w, h }, (vec2) { 10., 10. }, text_len, text, cursor, selection); + draw_text_area((vec4_f32) { 0.f, 0.f, 0.f, 1.f }, (Box) { x0 + 8, y0 - 8, w, h }, (vec2) { 10., 10. }, text_len, text); + draw_text_area(color, (Box) { x0, y0, w, h }, (vec2) { 10., 10. }, text_len, text); render_main_window_frame(); } |