summaryrefslogtreecommitdiff
path: root/prge_gui.c
blob: f1d03d78cf19db70a9bd97b06ca60d0063d524db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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;
}