Ryan Scott / menuSystemMbed

Fork of menuSystemMbed by Brad Smith

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MainMenu.cpp Source File

MainMenu.cpp

00001 //
00002 //  MainMenu.cpp
00003 //  menuSystem
00004 //
00005 //  Created by BradDSmith on 2013-02-26.
00006 //  Copyright (c) 2013 BradDSmith. All rights reserved.
00007 //
00008 
00009 #include "MainMenu.h"
00010 
00011 #include "console.h"
00012 
00013 MainMenu::MainMenu()
00014 {
00015     highlightedItem = 0;
00016     maxitems = MAXITEMS;
00017 }
00018 
00019 void MainMenu::setMaxItems(int max)
00020 {
00021     maxitems = max;
00022 }
00023 
00024 void MainMenu::setMenuItem(int locID, int menuID, const char * menuText, int x, int y)
00025 {
00026     if(locID <maxitems){
00027         menuItem[locID].initialize(menuID, (char *)menuText,x, y);
00028         }
00029 }
00030 
00031 void MainMenu::printMenu()
00032 {
00033     for (int i = 0; i < maxitems; i++) {
00034         menuItem[i].print();
00035     }
00036 
00037    menuItem[highlightedItem].highlight();
00038 }
00039 
00040 void MainMenu::highlightNextItem()
00041 {
00042     menuItem[highlightedItem].removeHighLight();
00043     
00044     highlightedItem++;
00045     if(highlightedItem >= maxitems)highlightedItem = 0;
00046     
00047     menuItem[highlightedItem].highlight();
00048 }
00049 
00050 void MainMenu::highlightPrevItem()
00051 {
00052     menuItem[highlightedItem].removeHighLight();
00053     
00054     highlightedItem--;
00055     if(highlightedItem < 0)highlightedItem = maxitems - 1 ;
00056     
00057     menuItem[highlightedItem].highlight();
00058 }
00059 
00060 int MainMenu::getHighlightedItem()
00061 {
00062     return menuItem[highlightedItem].getMenuID();
00063 }
00064 
00065 void MainMenu::erase()
00066 {
00067        for (int i = 0; i < maxitems; i++) {
00068             menuItem[i].erase();
00069             }
00070 }