-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.cpp
85 lines (66 loc) · 2.14 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
81
82
83
84
#include <sstream>
#include "menu.h"
#include "parseXML.h"
Menu::~Menu() {
SDL_FreeSurface(surfaceOff);
SDL_FreeSurface(surfaceOn);
}
Menu::Menu() :
io( IOManager::getInstance() ),
words(),
parser( "xmlSpec/menu.xml" ),
position( parser.getXmlInt("wordsX"), parser.getXmlInt("wordsY") ),
space(),
surfaceOff(io.loadAndSet( parser.getXmlStr("clickoffFile"), true)),
surfaceOn(io.loadAndSet( parser.getXmlStr("clickonFile"), true)),
clicks(),
nextIcon(0),
click(OFF)
{
unsigned int n = parser.getXmlInt("wordsNumber");
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( FrameFactory::getInstance().getFrame(name) ),
//Frame( const std::string&, SDL_Surface*);
Frame clickoff("clickoff" , surfaceOff);
clicks.push_back( clickoff );
Frame clickon("clickon" , surfaceOn);
clicks.push_back( clickon );
/*
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::draw() const {
int x = position[0];
int y = position[1];
for (unsigned i = 0; i < words.size(); ++i) {
io.printMessageAt(words[i], x, y);
y += space[1];
}
y = position[1] + nextIcon*space[1];
// To draw the lamp, I'm using the Frame::draw method
// that does NOT adjust for the viewport position.
// Thus, we'll draw the lamp relative to (0, 0):
clicks[click].draw(0, 0, position[0]-space[0], y);
}
const string& Menu::getIconClicked() const {
return words[nextIcon];
}