menu v1

Fork of Menu by Peihsun Yeh

Committer:
jjcimon
Date:
Wed May 13 11:40:22 2015 +0000
Revision:
3:3cdd377f5899
Parent:
2:2654dc659298
Beta private,

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pyeh9 1:84d263c8932d 1 #include "Navigator.h"
jjcimon 3:3cdd377f5899 2 #include "SMARTGPU.h"
jjcimon 3:3cdd377f5899 3 //
jjcimon 3:3cdd377f5899 4 #include <stdio.h>
jjcimon 3:3cdd377f5899 5 #include <iostream>
pyeh9 1:84d263c8932d 6
jjcimon 3:3cdd377f5899 7 Navigator::Navigator(Menu *root, RPG &rpg, SMARTGPU *lcd) : activeMenu(root), rpg(rpg), lcd(lcd)
pyeh9 1:84d263c8932d 8 {
pyeh9 1:84d263c8932d 9 bottom = root->selections.size();
pyeh9 1:84d263c8932d 10 cursorPos = 0;
pyeh9 1:84d263c8932d 11 cursorLine = 1;
pyeh9 1:84d263c8932d 12 button = 0;
pyeh9 1:84d263c8932d 13 lastButton = 0;
pyeh9 2:2654dc659298 14
pyeh9 2:2654dc659298 15 printMenu();
pyeh9 2:2654dc659298 16 printCursor();
pyeh9 1:84d263c8932d 17 }
pyeh9 1:84d263c8932d 18
pyeh9 1:84d263c8932d 19 void Navigator::printMenu()
pyeh9 1:84d263c8932d 20 {
jjcimon 3:3cdd377f5899 21 lcd->erase();
jjcimon 3:3cdd377f5899 22
pyeh9 1:84d263c8932d 23 if(bottom == 1){ // the current Menu only has one selection
jjcimon 3:3cdd377f5899 24 //lcd->printf("%s\n", activeMenu->selections[0].selText);
jjcimon 3:3cdd377f5899 25 //activeMenu->selections[0].selText;
jjcimon 3:3cdd377f5899 26 lcd->string(70,10,300,220,YELLOW,FONT4,TRANS,activeMenu->selections[0].selText); //write a string on the screen
pyeh9 1:84d263c8932d 27 } else {
jjcimon 3:3cdd377f5899 28 // if(cursorLine == 4){ // if we're at the bottom
jjcimon 3:3cdd377f5899 29 // lcd->printf("%s\n", activeMenu->selections[cursorPos-1].selText);
jjcimon 3:3cdd377f5899 30 lcd->string(5,5,300,220,WHITE,FONT6,TRANS,activeMenu->selections[4].selText); //write a string on the screen
jjcimon 3:3cdd377f5899 31 lcd->string(30,40,300,220,WHITE,FONT6,TRANS,(activeMenu->selections[0].selText)); //write a string on the screen
jjcimon 3:3cdd377f5899 32 lcd->string(30,80,300,220,WHITE,FONT6,TRANS,activeMenu->selections[1].selText); //write a string on the screen
jjcimon 3:3cdd377f5899 33 lcd->string(30,120,300,220,WHITE,FONT6,TRANS,(activeMenu->selections[2].selText)); //write a string on the screen
jjcimon 3:3cdd377f5899 34 lcd->string(30,160,300,220,WHITE,FONT6,TRANS,activeMenu->selections[3].selText); //write a string on the screen
jjcimon 3:3cdd377f5899 35
jjcimon 3:3cdd377f5899 36 // } else {
jjcimon 3:3cdd377f5899 37
jjcimon 3:3cdd377f5899 38 // lcd->string(30,30,300,220,WHITE,FONT6,TRANS,activeMenu->selections[0].selText); //write a string on the screen
jjcimon 3:3cdd377f5899 39 // lcd->string(30,70,300,220,WHITE,FONT6,TRANS,activeMenu->selections[1].selText); //write a string on the screen
jjcimon 3:3cdd377f5899 40 // lcd->string(30,110,300,220,WHITE,FONT6,TRANS,(activeMenu->selections[2].selText)); //write a string on the screen
jjcimon 3:3cdd377f5899 41 // lcd->string(30,150,300,220,WHITE,FONT6,TRANS,activeMenu->selections[3].selText); //write a string on the screen
jjcimon 3:3cdd377f5899 42 //}
pyeh9 1:84d263c8932d 43 }
pyeh9 1:84d263c8932d 44 }
pyeh9 1:84d263c8932d 45
pyeh9 1:84d263c8932d 46 void Navigator::printCursor()
pyeh9 1:84d263c8932d 47 {
jjcimon 3:3cdd377f5899 48
jjcimon 3:3cdd377f5899 49
jjcimon 3:3cdd377f5899 50 if(activeMenu->selections[cursorPos].childMenu == NULL)
jjcimon 3:3cdd377f5899 51 // printf("No child menu\n");
jjcimon 3:3cdd377f5899 52 lcd->string(10,200,300,220,WHITE,FONT2,TRANS,"_ "); //write a string on the screen
jjcimon 3:3cdd377f5899 53
jjcimon 3:3cdd377f5899 54 else
jjcimon 3:3cdd377f5899 55 lcd->string(10,200,300,220,WHITE,FONT2,TRANS, activeMenu->selections[cursorPos].childMenu->menuID); //write a string on the screen
jjcimon 3:3cdd377f5899 56
jjcimon 3:3cdd377f5899 57 //printf("child menu: %s\n", activeMenu->selections[cursorPos].childMenu->menuID);
pyeh9 1:84d263c8932d 58
jjcimon 3:3cdd377f5899 59 // lcd->locate(0,0); cursorPos cursorLine
jjcimon 3:3cdd377f5899 60 if(cursorPos == 0){
jjcimon 3:3cdd377f5899 61 lcd->string(15,40,300,220,WHITE,FONT6,TRANS,">");
jjcimon 3:3cdd377f5899 62 lcd->string(15,80,300,220,WHITE,FONT6,TRANS," ");
jjcimon 3:3cdd377f5899 63 lcd->string(15,120,300,220,WHITE,FONT6,TRANS," ");
jjcimon 3:3cdd377f5899 64 lcd->string(15,160,300,220,WHITE,FONT6,TRANS," ");
jjcimon 3:3cdd377f5899 65 } else if(cursorPos == 1){
jjcimon 3:3cdd377f5899 66 lcd->string(15,40,300,220,WHITE,FONT6,TRANS," ");
jjcimon 3:3cdd377f5899 67 lcd->string(15,80,300,220,WHITE,FONT6,TRANS,">");
jjcimon 3:3cdd377f5899 68 lcd->string(15,120,300,220,WHITE,FONT6,TRANS," ");
jjcimon 3:3cdd377f5899 69 lcd->string(15,160,300,220,WHITE,FONT6,TRANS," ");
jjcimon 3:3cdd377f5899 70 } else if(cursorPos == 2){
jjcimon 3:3cdd377f5899 71 lcd->string(15,40,300,220,WHITE,FONT6,TRANS," ");
jjcimon 3:3cdd377f5899 72 lcd->string(15,80,300,220,WHITE,FONT6,TRANS," ");
jjcimon 3:3cdd377f5899 73 lcd->string(15,120,300,220,WHITE,FONT6,TRANS,">");
jjcimon 3:3cdd377f5899 74 lcd->string(15,160,300,220,WHITE,FONT6,TRANS," ");
jjcimon 3:3cdd377f5899 75 } else if(cursorPos == 3){
jjcimon 3:3cdd377f5899 76 lcd->string(15,40,300,220,WHITE,FONT6,TRANS," ");
jjcimon 3:3cdd377f5899 77 lcd->string(15,80,300,220,WHITE,FONT6,TRANS," ");
jjcimon 3:3cdd377f5899 78 lcd->string(15,120,300,220,WHITE,FONT6,TRANS," ");
jjcimon 3:3cdd377f5899 79 lcd->string(15,160,300,220,WHITE,FONT6,TRANS,">");
pyeh9 1:84d263c8932d 80 }
pyeh9 1:84d263c8932d 81 }
pyeh9 1:84d263c8932d 82
pyeh9 1:84d263c8932d 83 void Navigator::poll()
pyeh9 1:84d263c8932d 84 {
jjcimon 3:3cdd377f5899 85
pyeh9 1:84d263c8932d 86 if((direction = rpg.dir())!=0){ //Get Dir
pyeh9 1:84d263c8932d 87 wait(0.2);
pyeh9 1:84d263c8932d 88 if(direction == 1) moveDown();
pyeh9 1:84d263c8932d 89 else if(direction == -1) moveUp();
pyeh9 1:84d263c8932d 90 }
pyeh9 1:84d263c8932d 91
jjcimon 3:3cdd377f5899 92 if ((button = rpg.pb()) && !lastButton){ //prevents multiple selections when button is held down
pyeh9 1:84d263c8932d 93 wait(0.2);
pyeh9 1:84d263c8932d 94 if(activeMenu->selections[cursorPos].fun != NULL){
pyeh9 1:84d263c8932d 95 (activeMenu->selections[cursorPos].fun)();
pyeh9 1:84d263c8932d 96 }
pyeh9 1:84d263c8932d 97 if(activeMenu->selections[cursorPos].childMenu != NULL){
pyeh9 1:84d263c8932d 98 activeMenu = activeMenu->selections[cursorPos].childMenu;
pyeh9 1:84d263c8932d 99 bottom = activeMenu->selections.size();
pyeh9 1:84d263c8932d 100 cursorPos = 0;
pyeh9 1:84d263c8932d 101 cursorLine = 1;
pyeh9 1:84d263c8932d 102 printMenu();
pyeh9 1:84d263c8932d 103 printCursor();
pyeh9 1:84d263c8932d 104 }
pyeh9 1:84d263c8932d 105 }
pyeh9 1:84d263c8932d 106 lastButton = button;
pyeh9 1:84d263c8932d 107 }
pyeh9 1:84d263c8932d 108
pyeh9 1:84d263c8932d 109 void Navigator::moveUp()
pyeh9 1:84d263c8932d 110 {
pyeh9 1:84d263c8932d 111 if(cursorLine == 1){
pyeh9 1:84d263c8932d 112 printMenu();
jjcimon 3:3cdd377f5899 113 } else if(cursorLine == 5){
pyeh9 1:84d263c8932d 114 cursorLine = 1;
pyeh9 1:84d263c8932d 115 }
pyeh9 1:84d263c8932d 116
pyeh9 1:84d263c8932d 117 if(cursorPos != 0){
pyeh9 1:84d263c8932d 118 cursorPos--;
pyeh9 1:84d263c8932d 119 printMenu();
pyeh9 1:84d263c8932d 120 }
pyeh9 1:84d263c8932d 121 printCursor();
pyeh9 1:84d263c8932d 122 }
pyeh9 1:84d263c8932d 123
pyeh9 1:84d263c8932d 124 void Navigator::moveDown()
pyeh9 1:84d263c8932d 125 {
pyeh9 1:84d263c8932d 126 if(cursorLine == 1){
jjcimon 3:3cdd377f5899 127 cursorLine = 5;
jjcimon 3:3cdd377f5899 128 } else if(cursorLine == 5){
pyeh9 1:84d263c8932d 129 printMenu();
pyeh9 1:84d263c8932d 130 }
pyeh9 1:84d263c8932d 131
pyeh9 1:84d263c8932d 132 if(cursorPos != (bottom-1)){
pyeh9 1:84d263c8932d 133 cursorPos++;
pyeh9 1:84d263c8932d 134 printMenu();
pyeh9 1:84d263c8932d 135 }
pyeh9 1:84d263c8932d 136 printCursor();
pyeh9 1:84d263c8932d 137 }