diff options
Diffstat (limited to 'prge_gui.c')
-rw-r--r-- | prge_gui.c | 59 |
1 files changed, 38 insertions, 21 deletions
@@ -1,4 +1,4 @@ -B32 in_rect(V2 pos, V2 start, V2 end) +B32 inrect(V2 pos, V2 start, V2 end) { B32 res; res = ((pos.x > start.x) && (pos.x < end.x) && @@ -6,38 +6,55 @@ B32 in_rect(V2 pos, V2 start, V2 end) return res; } -B32 button(Window *wnd, U32 shader, Input *input, Arena *arena, - Str8 name, V2 center, F32 w, F32 h) +void beginui(Shader shader, PRGEWindow wnd) { - B32 res; - Mesh *quad; + MAT4 proj; + + glUseProgram(shader.id); + proj = ortho(0.0f, (F32)wnd.w, 0.0f, (F32)wnd.h, -1.0f, 1.0f); + setmat4fv(shader.id, PRGE_SHADER_PROJ_MAT, proj); + glDisable(GL_DEPTH_TEST); +} + +void endui(void) +{ + glEnable(GL_DEPTH_TEST); + glUseProgram(0); +} + +B32 button(PRGEContext *prgectx, Shader shader, const char *name, V2 center, F32 w, F32 h) +{ + B32 pressed; + Mesh quad; V2 start, end; - MAT4 model; - Str8 info; - res = 0; + MAT4 model; + V4 color; - quad = mesh_gen_quad(arena, v3fromv2(center), V3_ZERO, w, h); + pressed = 0; - shader_set_4fv(shader, "color", v4(1.0f, 0.0f, 0.0f, 1.0f)); + quad = gen_quad(prgectx->tmpa, v3fromv2(center), V3_ZERO, w, h); + 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; + + if (inrect(prgectx->in.mouse_pos, start, end) && !prgectx->in.capture_mouse) { + color = v4(0.0f, 0.0f, 1.0f, 1.0f); + if (is_key_pressed(prgectx->in.mouse_left)) { + sys_printf("%s\n", name); + pressed = 1; + } } - model = mat4transl(MAT4_IDENTITY, v3(center.x, wnd->height-center.y, 0.0f)); + model = translmat4(MAT4_IDENTITY, v3(center.x, prgectx->wnd.h-center.y, 0.0f)); - shader_set_mat4fv(shader, "model", model); + setmat4fv(shader.id, "model", model); + set4fv(shader.id, "color", color); - mesh_draw(quad); + draw_mesh(quad); - mesh_clear(quad); + clear_mesh(&quad); - return res; + return pressed; } |