summaryrefslogtreecommitdiff
path: root/prge_gui.c
blob: b4be331a33d590963f209635256558d0aa65a9cb (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
B32 inrect(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;
}

void beginui(Shader shader, PRGEWindow wnd)
{
	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;
	V4	color;

	pressed = 0;

	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 (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 = translmat4(MAT4_IDENTITY, v3(center.x, prgectx->wnd.h-center.y, 0.0f));

	setmat4fv(shader.id, "model", model);
	set4fv(shader.id, "color", color);

	draw_mesh(quad);

	clear_mesh(&quad);

	return pressed;
}