#include "oodle.h" CMenu::CMenu(list &buttons, CSprite* cursor, CSurface* background) : background(background), cursor(cursor) { FOREACH(list, buttons, i, buttons.push_back((*i))); } CMenu::~CMenu() { delete background; delete cursor; } CMenu::CMenu(list &text, list &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::const_iterator i1 = text.begin(); for (list::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, buttons , i, (*i)->draw(dest)); FOREACH(list , bgSprites, i, (*i)->draw(dest)); cursor->draw(dest); } void CMenu::update() { FOREACH(list, buttons , i, (*i)->update()); FOREACH(list , bgSprites, i, (*i)->update()); cursor->update(); }