-
Notifications
You must be signed in to change notification settings - Fork 1
/
menu.cpp
81 lines (71 loc) · 2.34 KB
/
menu.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
#include <sstream>
#include "menu.h"
#include "parseXML.h"
Menu::~Menu() {
SDL_FreeSurface(surfaceOff);
SDL_FreeSurface(surfaceOn);
delete background;
SDL_FreeSurface(backSurface);
}
Menu::Menu() :
io( IOManager::getInstance() ),
words(),
position(),
space(),
parser( "xmlSpec/menu.xml" ),
surfaceOff(io.loadAndSet( parser.getXmlStr("clickoffFile"), true)),
surfaceOn(io.loadAndSet( parser.getXmlStr("clickonFile"), true)),
backSurface(io.loadAndSet( parser.getXmlStr("backgroundFile"), true)),
background(new Frame(backSurface,
parser.getXmlInt("backgroundWidth"),
parser.getXmlInt("backgroundHeight"),
parser.getXmlInt("backgroundSrcX"),
parser.getXmlInt("backgroundSrcY"))),
viewport( Viewport::getInstance() ),
clicks(),
nextIcon(0),
click(0)
{
unsigned int n = parser.getXmlInt("wordsNumber");
position[0] = parser.getXmlInt("wordsX");
position[1] = parser.getXmlInt("wordsY");
std::stringstream strm;
for ( unsigned i = 0; i < n; ++i ) {
strm << "words" << i;
words.push_back( parser.getXmlStr(strm.str()) );
strm.clear(); // clear error flags
strm.str(std::string()); // clear contents
}
space[0] = parser.getXmlInt("wordsSpaceX");
space[1] = parser.getXmlInt("wordsSpaceY");
Frame clickoff(surfaceOff,
parser.getXmlInt("clickoffWidth"),
parser.getXmlInt("clickoffHeight"),
parser.getXmlInt("clickoffSrcX"),
parser.getXmlInt("clickoffSrcX"));
clicks.push_back( clickoff );
Frame clickon(surfaceOn,
parser.getXmlInt("clickonWidth"),
parser.getXmlInt("clickonHeight"),
parser.getXmlInt("clickonSrcX"),
parser.getXmlInt("clickonSrcX"));
clicks.push_back( clickon );
}
void Menu::drawBG() const {
background->draw(viewport.X(), viewport.Y());
}
void Menu::draw() const {
int x = position[0];
int y = position[1];
this->drawBG();
//io.printMessageCenteredAt("================ MAIN MENU ================",60);
for (unsigned i = 0; i < words.size(); ++i) {
io.printMessageAt(words[i], x, y);
y += space[1];
}
y = position[1] + nextIcon*space[1];
clicks[click].draw(viewport.X()+position[0]-space[0]+10, y-13);
}
const string& Menu::getIconClicked() const {
return words[nextIcon];
}