Custom menu
Fork of Menu by
Navigator.cpp@4:396eff5be1a1, 2015-03-03 (annotated)
- Committer:
- LeoHsueh
- Date:
- Tue Mar 03 03:57:46 2015 +0000
- Revision:
- 4:396eff5be1a1
- Parent:
- 3:3fceb6ff921e
Fix to use FunctionPointer.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pyeh9 | 1:84d263c8932d | 1 | #include "Navigator.h" |
pyeh9 | 1:84d263c8932d | 2 | |
LeoHsueh | 3:3fceb6ff921e | 3 | Navigator::Navigator(Menu *root, TextLCD *lcd) : |
LeoHsueh | 3:3fceb6ff921e | 4 | root(root), activeMenu(root), _lcd(lcd) { |
pyeh9 | 1:84d263c8932d | 5 | cursorPos = 0; |
pyeh9 | 2:2654dc659298 | 6 | printMenu(); |
LeoHsueh | 3:3fceb6ff921e | 7 | } |
LeoHsueh | 3:3fceb6ff921e | 8 | |
LeoHsueh | 3:3fceb6ff921e | 9 | void Navigator::printMenu() { |
LeoHsueh | 3:3fceb6ff921e | 10 | _lcd->cls(); |
LeoHsueh | 3:3fceb6ff921e | 11 | _lcd->printf("%s\n", activeMenu->menuID); |
LeoHsueh | 3:3fceb6ff921e | 12 | _lcd->printf(">%s\n", activeMenu->selections[cursorPos].selText); |
pyeh9 | 1:84d263c8932d | 13 | } |
pyeh9 | 1:84d263c8932d | 14 | |
LeoHsueh | 3:3fceb6ff921e | 15 | void Navigator::actionNone() { |
LeoHsueh | 3:3fceb6ff921e | 16 | if (_lastAction != none) { |
LeoHsueh | 3:3fceb6ff921e | 17 | |
pyeh9 | 1:84d263c8932d | 18 | } |
LeoHsueh | 3:3fceb6ff921e | 19 | _lastAction = none; |
pyeh9 | 1:84d263c8932d | 20 | } |
pyeh9 | 1:84d263c8932d | 21 | |
LeoHsueh | 3:3fceb6ff921e | 22 | void Navigator::actionUp() { |
LeoHsueh | 3:3fceb6ff921e | 23 | if (_lastAction != up) { |
LeoHsueh | 3:3fceb6ff921e | 24 | if (cursorPos > 0) { |
LeoHsueh | 3:3fceb6ff921e | 25 | cursorPos--; |
LeoHsueh | 3:3fceb6ff921e | 26 | printMenu(); |
LeoHsueh | 3:3fceb6ff921e | 27 | } |
pyeh9 | 1:84d263c8932d | 28 | } |
LeoHsueh | 3:3fceb6ff921e | 29 | _lastAction = up; |
pyeh9 | 1:84d263c8932d | 30 | } |
pyeh9 | 1:84d263c8932d | 31 | |
LeoHsueh | 3:3fceb6ff921e | 32 | void Navigator::actionDown() { |
LeoHsueh | 3:3fceb6ff921e | 33 | if (_lastAction != down) { |
LeoHsueh | 3:3fceb6ff921e | 34 | if (cursorPos < (activeMenu->selections.size() - 1)) { |
LeoHsueh | 3:3fceb6ff921e | 35 | cursorPos++; |
pyeh9 | 1:84d263c8932d | 36 | printMenu(); |
pyeh9 | 1:84d263c8932d | 37 | } |
pyeh9 | 1:84d263c8932d | 38 | } |
LeoHsueh | 3:3fceb6ff921e | 39 | _lastAction = down; |
LeoHsueh | 3:3fceb6ff921e | 40 | } |
LeoHsueh | 3:3fceb6ff921e | 41 | |
LeoHsueh | 3:3fceb6ff921e | 42 | void Navigator::actionBack() { |
LeoHsueh | 3:3fceb6ff921e | 43 | if (_lastAction != back) { |
LeoHsueh | 3:3fceb6ff921e | 44 | if (activeMenu->parent != NULL) { |
LeoHsueh | 3:3fceb6ff921e | 45 | activeMenu = activeMenu->parent; |
LeoHsueh | 3:3fceb6ff921e | 46 | cursorPos = 0; |
LeoHsueh | 3:3fceb6ff921e | 47 | printMenu(); |
LeoHsueh | 3:3fceb6ff921e | 48 | } |
LeoHsueh | 3:3fceb6ff921e | 49 | } |
LeoHsueh | 3:3fceb6ff921e | 50 | _lastAction = back; |
pyeh9 | 1:84d263c8932d | 51 | } |
pyeh9 | 1:84d263c8932d | 52 | |
LeoHsueh | 3:3fceb6ff921e | 53 | void Navigator::actionEnter() { |
LeoHsueh | 3:3fceb6ff921e | 54 | if (_lastAction != enter) { |
LeoHsueh | 3:3fceb6ff921e | 55 | if (activeMenu->selections[cursorPos].fun != NULL) { |
LeoHsueh | 4:396eff5be1a1 | 56 | activeMenu->selections[cursorPos].fun->call(); |
LeoHsueh | 3:3fceb6ff921e | 57 | printMenu(); |
LeoHsueh | 3:3fceb6ff921e | 58 | } |
LeoHsueh | 3:3fceb6ff921e | 59 | if (activeMenu->selections[cursorPos].childMenu != NULL) { |
LeoHsueh | 3:3fceb6ff921e | 60 | activeMenu = activeMenu->selections[cursorPos].childMenu; |
LeoHsueh | 3:3fceb6ff921e | 61 | cursorPos = 0; |
LeoHsueh | 3:3fceb6ff921e | 62 | printMenu(); |
LeoHsueh | 3:3fceb6ff921e | 63 | } |
pyeh9 | 1:84d263c8932d | 64 | } |
LeoHsueh | 3:3fceb6ff921e | 65 | _lastAction = enter; |
pyeh9 | 1:84d263c8932d | 66 | } |
pyeh9 | 1:84d263c8932d | 67 | |
LeoHsueh | 3:3fceb6ff921e | 68 | void Navigator::actionHome() { |
LeoHsueh | 3:3fceb6ff921e | 69 | if (_lastAction != home) { |
LeoHsueh | 3:3fceb6ff921e | 70 | activeMenu = root; |
LeoHsueh | 3:3fceb6ff921e | 71 | cursorPos = 0; |
pyeh9 | 1:84d263c8932d | 72 | printMenu(); |
pyeh9 | 1:84d263c8932d | 73 | } |
LeoHsueh | 3:3fceb6ff921e | 74 | _lastAction = home; |
LeoHsueh | 3:3fceb6ff921e | 75 | } |