|
Last change
on this file since 381df6 was d20ed5, checked in by Frederik Heber <heber@…>, 16 years ago |
|
Added basic menu and action framework
- Added action base class
- Added class to make actions from methods
- Added Menu base class
- Added TextMenu class to produce text menus
- Added MenuItem base class for menu items
- Added ActionMenuItem for menu items using an action
- Added SubMenuItem class for menu items presenting a submenu
- Added SeperatorItem class for menu seperators without functioninality
Signed-off-by: Tillmann Crueger <crueger@…>
|
-
Property mode
set to
100644
|
|
File size:
997 bytes
|
| Line | |
|---|
| 1 | /*
|
|---|
| 2 | * TextMenu.cpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: Dec 10, 2009
|
|---|
| 5 | * Author: crueger
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #include <boost/bind.hpp>
|
|---|
| 9 | #include <iostream>
|
|---|
| 10 | #include "TextMenu.hpp"
|
|---|
| 11 | #include "MenuItem.hpp"
|
|---|
| 12 |
|
|---|
| 13 | TextMenu::TextMenu(ostream& _outputter, string _title) :
|
|---|
| 14 | outputter(_outputter),
|
|---|
| 15 | title(_title),
|
|---|
| 16 | quit(false)
|
|---|
| 17 | {
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | TextMenu::~TextMenu()
|
|---|
| 21 | {
|
|---|
| 22 | // TODO Auto-generated destructor stub
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 | void TextMenu::addItem(MenuItem* item) {
|
|---|
| 27 | items.push_back(item);
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | void TextMenu::removeItem(MenuItem* item) {
|
|---|
| 31 | items.remove(item);
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | void TextMenu::doQuit(){
|
|---|
| 35 | quit = true;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | bool TextMenu::hasQuit(){
|
|---|
| 39 | return quit;
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | void TextMenu::showEntry(MenuItem* entry){
|
|---|
| 43 | outputter << entry->formatEntry() << "\n";
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | void TextMenu::display() {
|
|---|
| 47 | char choice;
|
|---|
| 48 | do {
|
|---|
| 49 | outputter << title << "\n";
|
|---|
| 50 | for_each(items.begin(), items.end(), boost::bind(&TextMenu::showEntry,this,_1));
|
|---|
| 51 | outputter.flush();
|
|---|
| 52 |
|
|---|
| 53 | cin >> choice;
|
|---|
| 54 |
|
|---|
| 55 | for_each(items.begin(), items.end(), boost::bind(&MenuItem::checkTrigger,_1,choice));
|
|---|
| 56 | }while (!hasQuit());
|
|---|
| 57 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.