Baseline for testing
Navigator.cpp@3:8395f7ab6d3e, 2019-07-25 (annotated)
- Committer:
- foxbrianr
- Date:
- Thu Jul 25 00:42:49 2019 +0000
- Revision:
- 3:8395f7ab6d3e
- Parent:
- 2:2654dc659298
Baseline for testing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pyeh9 | 1:84d263c8932d | 1 | #include "Navigator.h" |
foxbrianr | 3:8395f7ab6d3e | 2 | /* |
pyeh9 | 1:84d263c8932d | 3 | Navigator::Navigator(Menu *root, RPG &rpg, TextLCD *lcd) : activeMenu(root), rpg(rpg), lcd(lcd) |
pyeh9 | 1:84d263c8932d | 4 | { |
pyeh9 | 1:84d263c8932d | 5 | bottom = root->selections.size(); |
pyeh9 | 1:84d263c8932d | 6 | cursorPos = 0; |
pyeh9 | 1:84d263c8932d | 7 | cursorLine = 1; |
pyeh9 | 1:84d263c8932d | 8 | button = 0; |
pyeh9 | 1:84d263c8932d | 9 | lastButton = 0; |
pyeh9 | 2:2654dc659298 | 10 | |
pyeh9 | 2:2654dc659298 | 11 | printMenu(); |
pyeh9 | 2:2654dc659298 | 12 | printCursor(); |
pyeh9 | 1:84d263c8932d | 13 | } |
foxbrianr | 3:8395f7ab6d3e | 14 | */ |
foxbrianr | 3:8395f7ab6d3e | 15 | Navigator::Navigator(Menu *root, LCD *lcd) : activeMenu(root), lcd(lcd) |
foxbrianr | 3:8395f7ab6d3e | 16 | { |
foxbrianr | 3:8395f7ab6d3e | 17 | top = 0; |
foxbrianr | 3:8395f7ab6d3e | 18 | bottom = root->selections.size(); |
foxbrianr | 3:8395f7ab6d3e | 19 | cursorPos = 0; |
foxbrianr | 3:8395f7ab6d3e | 20 | cursorLine = 0; |
foxbrianr | 3:8395f7ab6d3e | 21 | button = 0; |
foxbrianr | 3:8395f7ab6d3e | 22 | lastButton = 0; |
foxbrianr | 3:8395f7ab6d3e | 23 | } |
pyeh9 | 1:84d263c8932d | 24 | void Navigator::printMenu() |
pyeh9 | 1:84d263c8932d | 25 | { |
foxbrianr | 3:8395f7ab6d3e | 26 | for (int i=0;i<lcd->rows();i++) |
foxbrianr | 3:8395f7ab6d3e | 27 | { |
foxbrianr | 3:8395f7ab6d3e | 28 | if ((top+i) < activeMenu->selections.size()) |
foxbrianr | 3:8395f7ab6d3e | 29 | { |
foxbrianr | 3:8395f7ab6d3e | 30 | lcd->writeLine(i,activeMenu->selections[top+i].selText); |
pyeh9 | 1:84d263c8932d | 31 | } |
foxbrianr | 3:8395f7ab6d3e | 32 | else |
foxbrianr | 3:8395f7ab6d3e | 33 | { |
foxbrianr | 3:8395f7ab6d3e | 34 | lcd->writeLine(i,""); |
foxbrianr | 3:8395f7ab6d3e | 35 | } |
pyeh9 | 1:84d263c8932d | 36 | } |
foxbrianr | 3:8395f7ab6d3e | 37 | |
foxbrianr | 3:8395f7ab6d3e | 38 | lcd->dump(NULL); |
pyeh9 | 1:84d263c8932d | 39 | } |
pyeh9 | 1:84d263c8932d | 40 | |
pyeh9 | 1:84d263c8932d | 41 | void Navigator::printCursor() |
pyeh9 | 1:84d263c8932d | 42 | { |
foxbrianr | 3:8395f7ab6d3e | 43 | |
foxbrianr | 3:8395f7ab6d3e | 44 | |
foxbrianr | 3:8395f7ab6d3e | 45 | int tmp = activeMenu->selections.size() - cursorPos; |
foxbrianr | 3:8395f7ab6d3e | 46 | fprintf(stdout,"%d %d %d \n\r", tmp, cursorPos, activeMenu->selections.size() ); |
foxbrianr | 3:8395f7ab6d3e | 47 | |
foxbrianr | 3:8395f7ab6d3e | 48 | for(int i=0;i<lcd->rows();i++) |
foxbrianr | 3:8395f7ab6d3e | 49 | { |
foxbrianr | 3:8395f7ab6d3e | 50 | lcd->locate(i,0); |
foxbrianr | 3:8395f7ab6d3e | 51 | |
foxbrianr | 3:8395f7ab6d3e | 52 | if (i==cursorLine) { |
foxbrianr | 3:8395f7ab6d3e | 53 | lcd->character(i,0,'>'); |
foxbrianr | 3:8395f7ab6d3e | 54 | } |
foxbrianr | 3:8395f7ab6d3e | 55 | else |
foxbrianr | 3:8395f7ab6d3e | 56 | { |
foxbrianr | 3:8395f7ab6d3e | 57 | lcd->character(i,0,' '); |
foxbrianr | 3:8395f7ab6d3e | 58 | } |
foxbrianr | 3:8395f7ab6d3e | 59 | } |
foxbrianr | 3:8395f7ab6d3e | 60 | |
foxbrianr | 3:8395f7ab6d3e | 61 | lcd->dump(NULL); |
foxbrianr | 3:8395f7ab6d3e | 62 | |
foxbrianr | 3:8395f7ab6d3e | 63 | } |
foxbrianr | 3:8395f7ab6d3e | 64 | |
foxbrianr | 3:8395f7ab6d3e | 65 | |
foxbrianr | 3:8395f7ab6d3e | 66 | void Navigator::selectMenu() |
foxbrianr | 3:8395f7ab6d3e | 67 | { |
foxbrianr | 3:8395f7ab6d3e | 68 | |
foxbrianr | 3:8395f7ab6d3e | 69 | printf ("SEL:%d %d ", |
foxbrianr | 3:8395f7ab6d3e | 70 | cursorLine , cursorPos ); |
foxbrianr | 3:8395f7ab6d3e | 71 | |
foxbrianr | 3:8395f7ab6d3e | 72 | if(activeMenu->selections[cursorPos].childMenu != NULL) |
foxbrianr | 3:8395f7ab6d3e | 73 | { |
foxbrianr | 3:8395f7ab6d3e | 74 | activeMenu = activeMenu->selections[cursorPos].childMenu; |
foxbrianr | 3:8395f7ab6d3e | 75 | |
foxbrianr | 3:8395f7ab6d3e | 76 | cursorPos = 0; |
foxbrianr | 3:8395f7ab6d3e | 77 | cursorLine = 0; |
foxbrianr | 3:8395f7ab6d3e | 78 | |
foxbrianr | 3:8395f7ab6d3e | 79 | printMenu(); |
foxbrianr | 3:8395f7ab6d3e | 80 | printCursor(); |
foxbrianr | 3:8395f7ab6d3e | 81 | } |
foxbrianr | 3:8395f7ab6d3e | 82 | else |
foxbrianr | 3:8395f7ab6d3e | 83 | { |
foxbrianr | 3:8395f7ab6d3e | 84 | activeMenu->selections[cursorPos].select(); |
pyeh9 | 1:84d263c8932d | 85 | } |
foxbrianr | 3:8395f7ab6d3e | 86 | |
foxbrianr | 3:8395f7ab6d3e | 87 | |
pyeh9 | 1:84d263c8932d | 88 | |
foxbrianr | 3:8395f7ab6d3e | 89 | |
foxbrianr | 3:8395f7ab6d3e | 90 | } |
foxbrianr | 3:8395f7ab6d3e | 91 | |
foxbrianr | 3:8395f7ab6d3e | 92 | void Navigator::update(char cmd) |
pyeh9 | 1:84d263c8932d | 93 | { |
foxbrianr | 3:8395f7ab6d3e | 94 | /* |
foxbrianr | 3:8395f7ab6d3e | 95 | switch (cmd) |
foxbrianr | 3:8395f7ab6d3e | 96 | { |
foxbrianr | 3:8395f7ab6d3e | 97 | case 'U' : |
foxbrianr | 3:8395f7ab6d3e | 98 | case 'u' : |
foxbrianr | 3:8395f7ab6d3e | 99 | moveUp(); |
foxbrianr | 3:8395f7ab6d3e | 100 | break; |
foxbrianr | 3:8395f7ab6d3e | 101 | case 'D' : |
foxbrianr | 3:8395f7ab6d3e | 102 | case 'd' : |
foxbrianr | 3:8395f7ab6d3e | 103 | moveDown(); |
foxbrianr | 3:8395f7ab6d3e | 104 | break; |
foxbrianr | 3:8395f7ab6d3e | 105 | case 'a' : |
foxbrianr | 3:8395f7ab6d3e | 106 | case 'A' : |
foxbrianr | 3:8395f7ab6d3e | 107 | case '0x32' : |
foxbrianr | 3:8395f7ab6d3e | 108 | if(activeMenu->selections[cursorPos].fun != NULL) |
foxbrianr | 3:8395f7ab6d3e | 109 | { |
foxbrianr | 3:8395f7ab6d3e | 110 | (activeMenu->selections[cursorPos].fun)(); |
foxbrianr | 3:8395f7ab6d3e | 111 | } |
foxbrianr | 3:8395f7ab6d3e | 112 | if(activeMenu->selections[cursorPos].childMenu != NULL) |
foxbrianr | 3:8395f7ab6d3e | 113 | { |
foxbrianr | 3:8395f7ab6d3e | 114 | activeMenu = activeMenu->selections[cursorPos].childMenu; |
foxbrianr | 3:8395f7ab6d3e | 115 | bottom = activeMenu->selections.size(); |
foxbrianr | 3:8395f7ab6d3e | 116 | cursorPos = 0; |
foxbrianr | 3:8395f7ab6d3e | 117 | cursorLine = 1; |
foxbrianr | 3:8395f7ab6d3e | 118 | printMenu(); |
foxbrianr | 3:8395f7ab6d3e | 119 | printCursor(); |
foxbrianr | 3:8395f7ab6d3e | 120 | } |
foxbrianr | 3:8395f7ab6d3e | 121 | break; |
foxbrianr | 3:8395f7ab6d3e | 122 | default: |
foxbrianr | 3:8395f7ab6d3e | 123 | break; |
foxbrianr | 3:8395f7ab6d3e | 124 | }; |
foxbrianr | 3:8395f7ab6d3e | 125 | */ |
foxbrianr | 3:8395f7ab6d3e | 126 | |
foxbrianr | 3:8395f7ab6d3e | 127 | |
foxbrianr | 3:8395f7ab6d3e | 128 | /* |
foxbrianr | 3:8395f7ab6d3e | 129 | |
pyeh9 | 1:84d263c8932d | 130 | if((direction = rpg.dir())!=0){ //Get Dir |
pyeh9 | 1:84d263c8932d | 131 | wait(0.2); |
pyeh9 | 1:84d263c8932d | 132 | if(direction == 1) moveDown(); |
pyeh9 | 1:84d263c8932d | 133 | else if(direction == -1) moveUp(); |
pyeh9 | 1:84d263c8932d | 134 | } |
pyeh9 | 1:84d263c8932d | 135 | |
pyeh9 | 1:84d263c8932d | 136 | if ((button = rpg.pb()) && !lastButton){ //prevents multiple selections when button is held down |
pyeh9 | 1:84d263c8932d | 137 | wait(0.2); |
pyeh9 | 1:84d263c8932d | 138 | if(activeMenu->selections[cursorPos].fun != NULL){ |
pyeh9 | 1:84d263c8932d | 139 | (activeMenu->selections[cursorPos].fun)(); |
pyeh9 | 1:84d263c8932d | 140 | } |
pyeh9 | 1:84d263c8932d | 141 | if(activeMenu->selections[cursorPos].childMenu != NULL){ |
pyeh9 | 1:84d263c8932d | 142 | activeMenu = activeMenu->selections[cursorPos].childMenu; |
pyeh9 | 1:84d263c8932d | 143 | bottom = activeMenu->selections.size(); |
pyeh9 | 1:84d263c8932d | 144 | cursorPos = 0; |
pyeh9 | 1:84d263c8932d | 145 | cursorLine = 1; |
pyeh9 | 1:84d263c8932d | 146 | printMenu(); |
pyeh9 | 1:84d263c8932d | 147 | printCursor(); |
pyeh9 | 1:84d263c8932d | 148 | } |
pyeh9 | 1:84d263c8932d | 149 | } |
foxbrianr | 3:8395f7ab6d3e | 150 | */ |
foxbrianr | 3:8395f7ab6d3e | 151 | |
pyeh9 | 1:84d263c8932d | 152 | lastButton = button; |
pyeh9 | 1:84d263c8932d | 153 | } |
pyeh9 | 1:84d263c8932d | 154 | |
foxbrianr | 3:8395f7ab6d3e | 155 | void Navigator::pageDown () |
foxbrianr | 3:8395f7ab6d3e | 156 | { |
foxbrianr | 3:8395f7ab6d3e | 157 | if(cursorPos < bottom ) |
foxbrianr | 3:8395f7ab6d3e | 158 | { |
foxbrianr | 3:8395f7ab6d3e | 159 | bottom -= lcd->rows(); |
foxbrianr | 3:8395f7ab6d3e | 160 | top -= lcd->rows(); |
foxbrianr | 3:8395f7ab6d3e | 161 | } |
foxbrianr | 3:8395f7ab6d3e | 162 | } |
foxbrianr | 3:8395f7ab6d3e | 163 | |
foxbrianr | 3:8395f7ab6d3e | 164 | void Navigator::pageUp () |
foxbrianr | 3:8395f7ab6d3e | 165 | { |
foxbrianr | 3:8395f7ab6d3e | 166 | if(cursorPos >= top ) |
foxbrianr | 3:8395f7ab6d3e | 167 | { |
foxbrianr | 3:8395f7ab6d3e | 168 | bottom += lcd->rows(); |
foxbrianr | 3:8395f7ab6d3e | 169 | top += lcd->rows(); |
foxbrianr | 3:8395f7ab6d3e | 170 | } |
foxbrianr | 3:8395f7ab6d3e | 171 | } |
foxbrianr | 3:8395f7ab6d3e | 172 | |
pyeh9 | 1:84d263c8932d | 173 | void Navigator::moveUp() |
foxbrianr | 3:8395f7ab6d3e | 174 | { |
foxbrianr | 3:8395f7ab6d3e | 175 | cursorLine--; |
foxbrianr | 3:8395f7ab6d3e | 176 | if (cursorLine < 0 ) { |
foxbrianr | 3:8395f7ab6d3e | 177 | cursorLine = lcd->rows() -1 ; |
foxbrianr | 3:8395f7ab6d3e | 178 | if (top > 0 ) top -=4; // page menu if needed |
pyeh9 | 1:84d263c8932d | 179 | } |
foxbrianr | 3:8395f7ab6d3e | 180 | |
foxbrianr | 3:8395f7ab6d3e | 181 | |
foxbrianr | 3:8395f7ab6d3e | 182 | if(cursorPos > 0) |
foxbrianr | 3:8395f7ab6d3e | 183 | { |
pyeh9 | 1:84d263c8932d | 184 | cursorPos--; |
foxbrianr | 3:8395f7ab6d3e | 185 | } |
foxbrianr | 3:8395f7ab6d3e | 186 | |
pyeh9 | 1:84d263c8932d | 187 | printCursor(); |
foxbrianr | 3:8395f7ab6d3e | 188 | //printMenu(); |
foxbrianr | 3:8395f7ab6d3e | 189 | |
foxbrianr | 3:8395f7ab6d3e | 190 | |
foxbrianr | 3:8395f7ab6d3e | 191 | printf ("UP:%d %d ", cursorLine , cursorPos ); |
pyeh9 | 1:84d263c8932d | 192 | } |
pyeh9 | 1:84d263c8932d | 193 | |
pyeh9 | 1:84d263c8932d | 194 | void Navigator::moveDown() |
pyeh9 | 1:84d263c8932d | 195 | { |
foxbrianr | 3:8395f7ab6d3e | 196 | |
foxbrianr | 3:8395f7ab6d3e | 197 | cursorLine++; |
foxbrianr | 3:8395f7ab6d3e | 198 | if (cursorLine >= lcd->rows() ) { |
foxbrianr | 3:8395f7ab6d3e | 199 | cursorLine = 0; |
foxbrianr | 3:8395f7ab6d3e | 200 | if (top < activeMenu->selections.size() ) top +=4; // page menu if needed |
foxbrianr | 3:8395f7ab6d3e | 201 | } |
foxbrianr | 3:8395f7ab6d3e | 202 | |
foxbrianr | 3:8395f7ab6d3e | 203 | if(cursorPos < activeMenu->selections.size()){ |
foxbrianr | 3:8395f7ab6d3e | 204 | cursorPos++; |
pyeh9 | 1:84d263c8932d | 205 | } |
pyeh9 | 1:84d263c8932d | 206 | |
pyeh9 | 1:84d263c8932d | 207 | printCursor(); |
foxbrianr | 3:8395f7ab6d3e | 208 | //printMenu(); |
foxbrianr | 3:8395f7ab6d3e | 209 | |
foxbrianr | 3:8395f7ab6d3e | 210 | printf ("DOWN:%d %d ", |
foxbrianr | 3:8395f7ab6d3e | 211 | cursorLine , cursorPos ); |
pyeh9 | 1:84d263c8932d | 212 | } |