summaryrefslogtreecommitdiff
path: root/prge_gui.c
diff options
context:
space:
mode:
Diffstat (limited to 'prge_gui.c')
-rw-r--r--prge_gui.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/prge_gui.c b/prge_gui.c
new file mode 100644
index 0000000..f1d03d7
--- /dev/null
+++ b/prge_gui.c
@@ -0,0 +1,43 @@
+B32 in_rect(V2 pos, V2 start, V2 end)
+{
+ B32 res;
+ res = ((pos.x > start.x) && (pos.x < end.x) &&
+ (pos.y > start.y) && (pos.y < end.y));
+ return res;
+}
+
+B32 button(Window *wnd, U32 shader, Input *input, Arena *arena,
+ Str8 name, V2 center, F32 w, F32 h)
+{
+ B32 res;
+ Mesh *quad;
+ V2 start, end;
+ MAT4 model;
+ Str8 info;
+
+ res = 0;
+
+ quad = mesh_gen_quad(arena, v3fromv2(center), V3_ZERO, w, h);
+
+ shader_set_4fv(shader, "color", v4(1.0f, 0.0f, 0.0f, 1.0f));
+
+ start = v2(center.x-w/2.0f, center.y-h/2.0f);
+ end = v2(center.x+w/2.0f, center.y+h/2.0f);
+ if (in_rect(input->mouse_pos, start, end) &&
+ !input->capture_mouse)
+ {
+ shader_set_4fv(shader, "color", v4(0.0f, 0.0f, 1.0f, 1.0f));
+ if (key_first_press(input->mouse_left))
+ res = 1;
+ }
+
+ model = mat4transl(MAT4_IDENTITY, v3(center.x, wnd->height-center.y, 0.0f));
+
+ shader_set_mat4fv(shader, "model", model);
+
+ mesh_draw(quad);
+
+ mesh_clear(quad);
+
+ return res;
+}