-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenuitems.cpp
executable file
·63 lines (58 loc) · 1.59 KB
/
menuitems.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
#include "menuitems.hpp"
#include "main.hpp"
MenuItems::MenuItems()
{
currentY = 0;
}
void MenuItems::add(char* name, TextParams* fontName, bool center, float seperation)
{
int leftX, rightX;
int upperY, lowerY;
int tempW, tempH;
TTF_SizeText(fontName->font, name, &tempW, &tempH);
if(center)
leftX = (float)(screenWidth - tempW)/2.0f;
else
leftX = 0;
upperY = currentY + seperation;
lowerY = upperY + tempH;
rightX = leftX + tempW;
currentY = lowerY;
menuEntries.push_back(new menuItem(name, leftX, rightX, upperY, lowerY, fontName));
}
void MenuItems::add(char* name, bool center, float seperation)
{
add(name, &fontMiddle, center, seperation);
}
void MenuItems::add(char* name, bool center, int x, int y)
{
int leftX, rightX;
int upperY, lowerY;
int tempW, tempH;
TTF_SizeText(fontMiddle.font, name, &tempW, &tempH);
if(center)
leftX = (float)(screenWidth - tempW)/2.0f;
else
leftX = x;
rightX = leftX + tempW;
upperY = y;
lowerY = upperY + tempH;
menuEntries.push_back(new menuItem(name, leftX, rightX, upperY, lowerY, &fontMiddle));
}
void MenuItems::displayButtons()
{
for(unsigned ii = 0; ii < menuEntries.size(); ii++)
{
drawText(menuEntries[ii]->leftX,menuEntries[ii]->upperY, *menuEntries[ii]->fontName, menuEntries[ii]->displayName);
}
}
int MenuItems::processClick(int x,int y)
{
for(unsigned ii = 0; ii < menuEntries.size(); ii++)
{
if(x >= menuEntries[ii]->leftX && x <= menuEntries[ii]->rightX
&& y >= menuEntries[ii]->upperY && y <= menuEntries[ii]->lowerY)
return ii;
}
return -1;
}