-
Notifications
You must be signed in to change notification settings - Fork 1
/
ui.cpp
105 lines (82 loc) · 1.92 KB
/
ui.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
William Francis
Corrigan Farley
Randy Tobias
*/
#include "ui.h"
#include "globals.h"
UI::UI()
{
for (int i = 0; i<10; i++)
{
slot_area[i][0] = i * SLOT_WIDTH; //min x
slot_area[i][1] = SCREEN_HEIGHT - SLOT_HEIGHT; //min y
slot_area[i][2] = i * SLOT_WIDTH + SLOT_WIDTH; //max x
slot_area[i][3] = SCREEN_HEIGHT; //max y
slot_obj[i] = NULL; //ID of obj in slot i
}
}
void UI::setSlotArea(int id, float xmin, float ymin, float xmax, float ymax)
{
slot_area[id][0] = xmin;
slot_area[id][1] = ymin;
slot_area[id][2] = xmax;
slot_area[id][3] = ymax;
}
float UI::getSlotMinX(int id)
{
return slot_area[id][0];
}
float UI::getSlotMinY(int id)
{
return slot_area[id][1];
}
float UI::getSlotMaxX(int id)
{
return slot_area[id][2];
}
float UI::getSlotMaxY(int id)
{
return slot_area[id][3];
}
//return -1 if mouse wasn't in a slot
int UI::getSlotNum(float mouseX, float mouseY)
{
for (int i=0; i<10; i++)
{
if (mouseX >= slot_area[i][0] && mouseX <= slot_area[i][2] && mouseY >= slot_area[i][1] && mouseY <= slot_area[i][3])
return i;
}
return -1;
}
GameObject* UI::getSlotObj(int id)
{
return slot_obj[id];
}
void UI::setSlotObj(int id, GameObject *obj)
{
slot_obj[id] = obj;
}
void UI::draw()
{
for (int i = 0; i<=10; i++)
{
//glTranslatef(0,0,-1.0);
glBegin(GL_QUADS);
glColor4f(0.0,0.0,1.0,0.5);
glVertex3f(0,SCREEN_HEIGHT, 1);
glVertex3f(0,SCREEN_HEIGHT - SLOT_HEIGHT, 1);
glVertex3f(SLOT_WIDTH * i,SCREEN_HEIGHT - SLOT_HEIGHT, 1);
glVertex3f(SLOT_WIDTH * i,SCREEN_HEIGHT, 1);
glEnd();
glBegin(GL_QUADS);
glColor4f(0.0,1.0,1.0,0.5);
glVertex3f(5,SCREEN_HEIGHT -5, 0);
glVertex3f(5,SCREEN_HEIGHT - SLOT_HEIGHT + 5, 0);
glVertex3f(SLOT_WIDTH * i -5,SCREEN_HEIGHT - SLOT_HEIGHT + 5, 0);
glVertex3f(SLOT_WIDTH * i- 5,SCREEN_HEIGHT - 5 , 0);
glEnd();
// Reset original translate
//glTranslatef(-0,-0,1.0);
}
}