summaryrefslogtreecommitdiff
path: root/examples/ui.c
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2025-01-14 06:33:54 +0100
committerMitya Selivanov <automainint@guattari.tech>2025-01-14 06:33:54 +0100
commitdced6f7768e02252af11f9b41017d75c66b47d81 (patch)
tree008f4cb816a09b776013d5903b34fb89c01cf042 /examples/ui.c
parentc9208089c6074575342d529f494295c13269a1aa (diff)
downloadreduced_system_layer-dced6f7768e02252af11f9b41017d75c66b47d81.zip
Correct examples for changed graphics procs
Diffstat (limited to 'examples/ui.c')
-rw-r--r--examples/ui.c50
1 files changed, 28 insertions, 22 deletions
diff --git a/examples/ui.c b/examples/ui.c
index 389e2b4..8f1294a 100644
--- a/examples/ui.c
+++ b/examples/ui.c
@@ -1,3 +1,4 @@
+#define MAX_FRAME_DURATION 100
#include "../graphics.c"
b8 button_0_down = 0;
@@ -13,19 +14,27 @@ i64 selection = 0;
void update_and_render_frame(void) {
p_wait_events();
- for (i32 j = 0; j < g_platform.frame_height; ++j)
- for (i32 i = 0; i < g_platform.frame_width; ++i)
- g_platform.pixels[j * g_platform.frame_width + i] = (vec3_f32) { .2f, .1f, 0.f };
+ Brush background = RGB(.2f, .1f, 0.f);
+ background.quick = 1;
+
+ 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);
+
+ fill_rectangle(background, 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(OP_SET, (vec3_f32) { 1.f, 1.f, 1.f }, 40, 40, 60, 60);
+ fill_rectangle(white, 40, 40, 60, 60);
else
- fill_rectangle(OP_SET, (vec3_f32) { 0.f, 1.f, 0.f }, 40, 40, 60, 60);
+ fill_rectangle(green, 40, 40, 60, 60);
} else {
button_0_down = 0;
- fill_rectangle(OP_SET, (vec3_f32) { .1f, .5f, .1f }, 40, 40, 60, 60);
+ fill_rectangle(dark_green, 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) {
@@ -33,23 +42,23 @@ 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(OP_SET, (vec3_f32) { 1.f, 1.f, 1.f }, 40, 120, 60, 60);
+ fill_rectangle(white, 40, 120, 60, 60);
else if (button_1_checked)
- fill_rectangle(OP_SET, (vec3_f32) { 1.f, .5f, .5f }, 40, 120, 60, 60);
+ fill_rectangle(light_red, 40, 120, 60, 60);
else
- fill_rectangle(OP_SET, (vec3_f32) { .5f, 1.f, .5f }, 40, 120, 60, 60);
+ fill_rectangle(light_green, 40, 120, 60, 60);
} else {
button_1_down = 0;
if (button_1_checked)
- fill_rectangle(OP_SET, (vec3_f32) { 1.f, 0.f, 0.f }, 40, 120, 60, 60);
+ fill_rectangle(red, 40, 120, 60, 60);
else
- fill_rectangle(OP_SET, (vec3_f32) { 0.f, 1.f, 0.f }, 40, 120, 60, 60);
+ fill_rectangle(green, 40, 120, 60, 60);
}
- i64 w = g_platform.frame_width / 2;
- i64 h = g_platform.frame_height / 2;
- i64 x0 = w / 2;
- i64 y0 = h / 2;
+ f64 w = g_platform.real_width / 2.0;
+ f64 h = g_platform.real_height / 2.0;
+ f64 x0 = w / 2.0;
+ f64 y0 = h / 2.0;
vec3_f32 color = { 1.f, .5f, .5f };
@@ -204,9 +213,9 @@ void update_and_render_frame(void) {
}
}
- draw_text_area((vec3_f32) {0}, x0 + 8, y0 - 8, w, h, 10., 10., text_len, text);
- draw_text_area(color, x0, y0, w, h, 10., 10., text_len, text);
- draw_selection_cursor((vec3_f32) { 1.f, 1.f, 1.f }, x0, y0, w, h, 10., 10., cursor, selection, text_len, text);
+ 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 = with_alpha(color, 1.f) }, x0, y0, w, h, 10., 10., text_len, text);
+ draw_selection_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);
p_render_frame();
}
@@ -216,10 +225,7 @@ i32 main(i32 argc, c8 **argv) {
(void) argv;
g_platform = (Platform) {
- .title = "UI",
- .frame_width = 960,
- .frame_height = 720,
- .exact_resolution = 1,
+ .title = "UI",
};
p_event_loop();