Debian Codegraph @

Oodle/src/CMenu.cpp

raw
1 #include "oodle.h"
2
3 CMenu::CMenu(list<CMenuButton*> &buttons, CSprite* cursor, CSurface* background)
4 : background(background), cursor(cursor)
5 {
6 FOREACH(list<CMenuButton*>, buttons, i, buttons.push_back((*i)));
7 }
8
9 CMenu::~CMenu()
10 {
11 delete background;
12 delete cursor;
13 }
14
15 CMenu::CMenu(list<string> &text, list<CSprite*> &icons, const CVector &pos, CSprite* cursor, CSurface* background)
16 : background(background), cursor(cursor)
17 {
18 if (text.size() != icons.size())
19 {
20 _THROWEX(ex_illegalArguments, "Size of button names != size of icons", "CMenu", "CMenu",
21 "text = {" << &text << "}, icons = {" << &icons << "}, pos = "
22 << pos << ", background = {" << background << "}");
23 }
24
25 int padding = 10;
26 CVector lastPos = pos - CVector(0, padding);
27
28 list<string>::const_iterator i1 = text.begin();
29 for (list<CSprite*>::const_iterator i2 = icons.begin(); i2 != icons.end(); ++i2)
30 {
31 CMenuButton* tmp = new CMenuButton( *i2, COLOR_RED, COLOR_BLACK, *i1, lastPos + CVector(0, padding));
32 buttons.push_back( tmp );
33
34 lastPos += CVector(0, tmp->getHeight());
35 }
36 }
37
38 void CMenu::draw(CSurface &dest)
39 {
40 dest.blit(*background, 0,0);
41 FOREACH(list<CMenuButton*>, buttons , i, (*i)->draw(dest));
42 FOREACH(list<CSprite*> , bgSprites, i, (*i)->draw(dest));
43 cursor->draw(dest);
44 }
45
46 void CMenu::update()
47 {
48 FOREACH(list<CMenuButton*>, buttons , i, (*i)->update());
49 FOREACH(list<CSprite*> , bgSprites, i, (*i)->update());
50 cursor->update();
51 }