File: CMenu.cpp

package info (click to toggle)
blocks-of-the-undead 1.0-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid, trixie
  • size: 4,084 kB
  • sloc: cpp: 6,224; sh: 3,356; makefile: 171
file content (51 lines) | stat: -rw-r--r-- 1,483 bytes parent folder | download | duplicates (4)
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
#include "oodle.h"

CMenu::CMenu(list<CMenuButton*> &buttons, CSprite* cursor, CSurface* background)
             : background(background), cursor(cursor)
{
	FOREACH(list<CMenuButton*>, buttons, i, buttons.push_back((*i)));
}

CMenu::~CMenu()
{
	delete background;
	delete cursor;
}

CMenu::CMenu(list<string> &text, list<CSprite*> &icons, const CVector &pos, CSprite* cursor, CSurface* background)
             : background(background), cursor(cursor)
{
	if (text.size() != icons.size())
	{
		_THROWEX(ex_illegalArguments, "Size of button names != size of icons", "CMenu", "CMenu", 
		           "text = {" << &text << "}, icons = {" << &icons << "}, pos = " 
				   << pos << ", background = {" << background << "}");
	}

	int padding = 10;
	CVector lastPos = pos - CVector(0, padding);

	list<string>::const_iterator i1 = text.begin();
	for (list<CSprite*>::const_iterator i2 = icons.begin(); i2 != icons.end(); ++i2)
	{
		CMenuButton* tmp = new CMenuButton( *i2, COLOR_RED, COLOR_BLACK, *i1, lastPos + CVector(0, padding));
		buttons.push_back( tmp );

		lastPos += CVector(0, tmp->getHeight());
	}
}

void CMenu::draw(CSurface &dest)
{
	dest.blit(*background, 0,0);
	FOREACH(list<CMenuButton*>, buttons  , i, (*i)->draw(dest));
	FOREACH(list<CSprite*>    , bgSprites, i, (*i)->draw(dest));
	cursor->draw(dest);
}

void CMenu::update()
{
	FOREACH(list<CMenuButton*>, buttons  , i, (*i)->update());
	FOREACH(list<CSprite*>    , bgSprites, i, (*i)->update());
	cursor->update();
}