/* * TextMenu.cpp * * Created on: Dec 10, 2009 * Author: crueger */ #include #include #include #include "defs.hpp" #include "Menu/TextMenu.hpp" #include "Menu/MenuItem.hpp" TextMenu::TextMenu(ostream& _outputter, string _title, char _spacer,int _length) : outputter(_outputter), title(_title), spacer(_spacer), length(_length), quit(false) { } TextMenu::TextMenu(ostream& _outputter, string _title) : outputter(_outputter), title(_title), spacer(STD_MENU_TITLE_SPACER), length(STD_MENU_LENGTH), quit(false) { } TextMenu::~TextMenu() { for(list::iterator it=items.begin(); it != items.end(); it++) delete (*it); } void TextMenu::addItem(MenuItem* item) { items.push_back(item); } void TextMenu::removeItem(MenuItem* item) { items.remove(item); } void TextMenu::doQuit(){ quit = true; } bool TextMenu::hasQuit(){ return quit; } void TextMenu::showEntry(MenuItem* entry){ outputter << entry->formatEntry() << "\n"; } void TextMenu::display() { char choice; do { int pre = floor((length - title.length()) /2.0); int post = ceil((length - title.length()) /2.0); for(int i=0;i> choice; for_each(items.begin(), items.end(), boost::bind(&MenuItem::checkTrigger,_1,choice)); }while (!hasQuit()); }