-
Notifications
You must be signed in to change notification settings - Fork 4
/
MenuController.cpp
executable file
·61 lines (41 loc) · 1.18 KB
/
MenuController.cpp
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
52
53
54
55
56
57
58
59
60
61
#include "MenuController.h"
void MenuController::takeControl(MenuItem* item) {
if (!item) { return; }
currentItem = item;
currentItem->activate();
exiting = 0;
}
MenuController::MenuController() {}
MenuController::MenuController(MenuItem* root, MenuItemDrawer* drawer) {
// TODO: check if root is NULL and throw an error
currentItem = root;
this->drawer = drawer;
};
void MenuController::next() {
if(exiting) exiting = 0;
if(currentItem)
currentItem->doNext();
}
void MenuController::prev() {
if(exiting) exiting = 0;
if(currentItem)
currentItem->doPrev();
}
void MenuController::select() {
if(!currentItem) return;
MenuItem* ret = currentItem->action();
if (ret)
takeControl(ret);
}
void MenuController::back() {
if(!currentItem) return;
if(!currentItem->back())
return;
currentItem->deactivate();
if (currentItem->getParent())
takeControl(currentItem->getParent());
else
exiting = 1;
}
void MenuController::draw() { drawer->draw(currentItem); }
int MenuController::canExit() { return exiting; }