Baseline for testing
Diff: Navigator.cpp
- Revision:
- 3:8395f7ab6d3e
- Parent:
- 2:2654dc659298
--- a/Navigator.cpp Tue Mar 05 21:24:37 2013 +0000 +++ b/Navigator.cpp Thu Jul 25 00:42:49 2019 +0000 @@ -1,5 +1,5 @@ #include "Navigator.h" - +/* Navigator::Navigator(Menu *root, RPG &rpg, TextLCD *lcd) : activeMenu(root), rpg(rpg), lcd(lcd) { bottom = root->selections.size(); @@ -11,42 +11,122 @@ printMenu(); printCursor(); } - +*/ +Navigator::Navigator(Menu *root, LCD *lcd) : activeMenu(root), lcd(lcd) +{ + top = 0; + bottom = root->selections.size(); + cursorPos = 0; + cursorLine = 0; + button = 0; + lastButton = 0; +} void Navigator::printMenu() { - lcd->cls(); - if(bottom == 1){ // the current Menu only has one selection - lcd->printf("%s\n", activeMenu->selections[0].selText); - } else { - if(cursorLine == 2){ // if we're at the bottom - lcd->printf("%s\n", activeMenu->selections[cursorPos-1].selText); - lcd->printf("%s\n", activeMenu->selections[cursorPos].selText); - } else { - lcd->printf("%s\n", activeMenu->selections[cursorPos].selText); - lcd->printf("%s\n", activeMenu->selections[cursorPos+1].selText); + for (int i=0;i<lcd->rows();i++) + { + if ((top+i) < activeMenu->selections.size()) + { + lcd->writeLine(i,activeMenu->selections[top+i].selText); } + else + { + lcd->writeLine(i,""); + } } + + lcd->dump(NULL); } void Navigator::printCursor() { - if(activeMenu->selections[cursorPos].childMenu == NULL) printf("No child menu\n"); - else printf("child menu: %s\n", activeMenu->selections[cursorPos].childMenu->menuID); - - lcd->locate(0,0); - if(cursorLine == 1){ - lcd->putc('>'); - lcd->locate(0,1); - lcd->putc(' '); - } else if(cursorLine == 2){ - lcd->putc(' '); - lcd->locate(0,1); - lcd->putc('>'); + + + int tmp = activeMenu->selections.size() - cursorPos; + fprintf(stdout,"%d %d %d \n\r", tmp, cursorPos, activeMenu->selections.size() ); + + for(int i=0;i<lcd->rows();i++) + { + lcd->locate(i,0); + + if (i==cursorLine) { + lcd->character(i,0,'>'); + } + else + { + lcd->character(i,0,' '); + } + } + + lcd->dump(NULL); + +} + + +void Navigator::selectMenu() +{ + + printf ("SEL:%d %d ", + cursorLine , cursorPos ); + + if(activeMenu->selections[cursorPos].childMenu != NULL) + { + activeMenu = activeMenu->selections[cursorPos].childMenu; + + cursorPos = 0; + cursorLine = 0; + + printMenu(); + printCursor(); + } + else + { + activeMenu->selections[cursorPos].select(); } -} + + -void Navigator::poll() + +} + +void Navigator::update(char cmd) { + /* + switch (cmd) + { + case 'U' : + case 'u' : + moveUp(); + break; + case 'D' : + case 'd' : + moveDown(); + break; + case 'a' : + case 'A' : + case '0x32' : + if(activeMenu->selections[cursorPos].fun != NULL) + { + (activeMenu->selections[cursorPos].fun)(); + } + if(activeMenu->selections[cursorPos].childMenu != NULL) + { + activeMenu = activeMenu->selections[cursorPos].childMenu; + bottom = activeMenu->selections.size(); + cursorPos = 0; + cursorLine = 1; + printMenu(); + printCursor(); + } + break; + default: + break; + }; + */ + + + /* + if((direction = rpg.dir())!=0){ //Get Dir wait(0.2); if(direction == 1) moveDown(); @@ -67,35 +147,66 @@ printCursor(); } } + */ + lastButton = button; } +void Navigator::pageDown () +{ + if(cursorPos < bottom ) + { + bottom -= lcd->rows(); + top -= lcd->rows(); + } +} + +void Navigator::pageUp () +{ + if(cursorPos >= top ) + { + bottom += lcd->rows(); + top += lcd->rows(); + } +} + void Navigator::moveUp() -{ - if(cursorLine == 1){ - printMenu(); - } else if(cursorLine == 2){ - cursorLine = 1; +{ + cursorLine--; + if (cursorLine < 0 ) { + cursorLine = lcd->rows() -1 ; + if (top > 0 ) top -=4; // page menu if needed } - - if(cursorPos != 0){ + + + if(cursorPos > 0) + { cursorPos--; - printMenu(); - } + } + printCursor(); + //printMenu(); + + + printf ("UP:%d %d ", cursorLine , cursorPos ); } void Navigator::moveDown() { - if(cursorLine == 1){ - cursorLine = 2; - } else if(cursorLine == 2){ - printMenu(); + + cursorLine++; + if (cursorLine >= lcd->rows() ) { + cursorLine = 0; + if (top < activeMenu->selections.size() ) top +=4; // page menu if needed + } + + if(cursorPos < activeMenu->selections.size()){ + cursorPos++; } - if(cursorPos != (bottom-1)){ - cursorPos++; - printMenu(); - } printCursor(); + //printMenu(); + + printf ("DOWN:%d %d ", + cursorLine , cursorPos ); } \ No newline at end of file