mbed menu system

Committer:
mbedDevLondon
Date:
Thu Feb 28 00:38:31 2013 +0000
Revision:
0:a5ece7312edc
initial port to mbed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedDevLondon 0:a5ece7312edc 1 //
mbedDevLondon 0:a5ece7312edc 2 // MainMenu.cpp
mbedDevLondon 0:a5ece7312edc 3 // menuSystem
mbedDevLondon 0:a5ece7312edc 4 //
mbedDevLondon 0:a5ece7312edc 5 // Created by BradDSmith on 2013-02-26.
mbedDevLondon 0:a5ece7312edc 6 // Copyright (c) 2013 BradDSmith. All rights reserved.
mbedDevLondon 0:a5ece7312edc 7 //
mbedDevLondon 0:a5ece7312edc 8
mbedDevLondon 0:a5ece7312edc 9 #include "MainMenu.h"
mbedDevLondon 0:a5ece7312edc 10
mbedDevLondon 0:a5ece7312edc 11 #include "console.h"
mbedDevLondon 0:a5ece7312edc 12
mbedDevLondon 0:a5ece7312edc 13 MainMenu::MainMenu()
mbedDevLondon 0:a5ece7312edc 14 {
mbedDevLondon 0:a5ece7312edc 15 highlightedItem = 0;
mbedDevLondon 0:a5ece7312edc 16 maxitems = MAXITEMS;
mbedDevLondon 0:a5ece7312edc 17 }
mbedDevLondon 0:a5ece7312edc 18
mbedDevLondon 0:a5ece7312edc 19 void MainMenu::setMaxItems(int max)
mbedDevLondon 0:a5ece7312edc 20 {
mbedDevLondon 0:a5ece7312edc 21 maxitems = max;
mbedDevLondon 0:a5ece7312edc 22 }
mbedDevLondon 0:a5ece7312edc 23
mbedDevLondon 0:a5ece7312edc 24 void MainMenu::setMenuItem(int locID, int menuID, const char * menuText, int x, int y)
mbedDevLondon 0:a5ece7312edc 25 {
mbedDevLondon 0:a5ece7312edc 26 if(locID <maxitems){
mbedDevLondon 0:a5ece7312edc 27 menuItem[locID].initialize(menuID, (char *)menuText,x, y);
mbedDevLondon 0:a5ece7312edc 28 }
mbedDevLondon 0:a5ece7312edc 29 }
mbedDevLondon 0:a5ece7312edc 30
mbedDevLondon 0:a5ece7312edc 31 void MainMenu::printMenu()
mbedDevLondon 0:a5ece7312edc 32 {
mbedDevLondon 0:a5ece7312edc 33 for (int i = 0; i < maxitems; i++) {
mbedDevLondon 0:a5ece7312edc 34 menuItem[i].print();
mbedDevLondon 0:a5ece7312edc 35 }
mbedDevLondon 0:a5ece7312edc 36
mbedDevLondon 0:a5ece7312edc 37 menuItem[highlightedItem].highlight();
mbedDevLondon 0:a5ece7312edc 38 }
mbedDevLondon 0:a5ece7312edc 39
mbedDevLondon 0:a5ece7312edc 40 void MainMenu::highlightNextItem()
mbedDevLondon 0:a5ece7312edc 41 {
mbedDevLondon 0:a5ece7312edc 42 menuItem[highlightedItem].removeHighLight();
mbedDevLondon 0:a5ece7312edc 43
mbedDevLondon 0:a5ece7312edc 44 highlightedItem++;
mbedDevLondon 0:a5ece7312edc 45 if(highlightedItem >= maxitems)highlightedItem = 0;
mbedDevLondon 0:a5ece7312edc 46
mbedDevLondon 0:a5ece7312edc 47 menuItem[highlightedItem].highlight();
mbedDevLondon 0:a5ece7312edc 48 }
mbedDevLondon 0:a5ece7312edc 49
mbedDevLondon 0:a5ece7312edc 50 void MainMenu::highlightPrevItem()
mbedDevLondon 0:a5ece7312edc 51 {
mbedDevLondon 0:a5ece7312edc 52 menuItem[highlightedItem].removeHighLight();
mbedDevLondon 0:a5ece7312edc 53
mbedDevLondon 0:a5ece7312edc 54 highlightedItem--;
mbedDevLondon 0:a5ece7312edc 55 if(highlightedItem < 0)highlightedItem = maxitems - 1 ;
mbedDevLondon 0:a5ece7312edc 56
mbedDevLondon 0:a5ece7312edc 57 menuItem[highlightedItem].highlight();
mbedDevLondon 0:a5ece7312edc 58 }
mbedDevLondon 0:a5ece7312edc 59
mbedDevLondon 0:a5ece7312edc 60 int MainMenu::getHighlightedItem()
mbedDevLondon 0:a5ece7312edc 61 {
mbedDevLondon 0:a5ece7312edc 62 return menuItem[highlightedItem].getMenuID();
mbedDevLondon 0:a5ece7312edc 63 }
mbedDevLondon 0:a5ece7312edc 64
mbedDevLondon 0:a5ece7312edc 65 void MainMenu::erase()
mbedDevLondon 0:a5ece7312edc 66 {
mbedDevLondon 0:a5ece7312edc 67 for (int i = 0; i < maxitems; i++) {
mbedDevLondon 0:a5ece7312edc 68 menuItem[i].erase();
mbedDevLondon 0:a5ece7312edc 69 }
mbedDevLondon 0:a5ece7312edc 70 }