Ryan Scott / menuSystemMbedBroken

Dependencies:   ANSITermMenuSystem

Fork of menuSystemMbed by Ryan Scott

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     selecteditem = 0;   //April 9th 2013 Ask Brad about Glitch
00016     highlightedItem = 0;
00017     maxitems = MAXITEMS;
00018     selectionstatus = false;
00019 }
00020 
00021 void MainMenu::setMaxItems(int max)
00022 {
00023     maxitems = max;
00024 }
00025 
00026 void MainMenu::setMenuItem(int locID, int menuID, const char * menuText, int x, int y)
00027 {
00028     if(locID <maxitems){
00029         menuItem[locID].initialize(menuID, (char *)menuText,x, y);
00030         }
00031 }
00032 
00033 void MainMenu::printMenu()
00034 {
00035     const char * msg = Title.c_str();
00036     printXY( (char *)msg, 5, 0);
00037     for (int i = 0; i < maxitems; i++) {
00038         menuItem[i].print();
00039     }
00040 
00041    menuItem[highlightedItem].highlight();
00042    if (selectionstatus == true) 
00043    {
00044    menuItem[selecteditem].showselect();  //April 9th 2013 Ask Brad about Glitch
00045    }
00046 }
00047 
00048 void MainMenu::highlightNextItem()
00049 {
00050     menuItem[highlightedItem].removeHighLight();
00051     
00052     highlightedItem++;
00053     if(highlightedItem >= maxitems)highlightedItem = 0;
00054   //   highlightedItem--;
00055   //   if(highlightedItem < 0)highlightedItem = maxitems - 1 ;
00056     
00057     menuItem[highlightedItem].highlight();
00058 }
00059 
00060 void MainMenu::highlightPrevItem()
00061 {
00062     menuItem[highlightedItem].removeHighLight();
00063     
00064   highlightedItem--;
00065   if(highlightedItem < 0)highlightedItem = maxitems - 1 ;
00066   //  highlightedItem++;
00067  //   if(highlightedItem >= maxitems)highlightedItem = 0;
00068     
00069     menuItem[highlightedItem].highlight();
00070 }
00071 
00072 int MainMenu::getHighlightedItem()
00073 {
00074     return menuItem[highlightedItem].getMenuID();
00075 }
00076 
00077 void MainMenu::erase()
00078 {
00079        for (int i = 0; i < maxitems; i++) {
00080             menuItem[i].erase();
00081             }
00082 }
00083 
00084 void MainMenu::selection()
00085 {
00086     selecteditem = highlightedItem;
00087     menuItem[selecteditem].showselect();
00088 }
00089 
00090 void MainMenu::removeselection()
00091 {
00092     menuItem[selecteditem].removeselect();
00093 }
00094 
00095 string MainMenu::getTitle()
00096 {
00097     return Title;
00098 }
00099 void MainMenu::setTitle(string NewTitle)
00100 {
00101     Title = NewTitle;
00102 }
00103 
00104 void MainMenu::setselectstatus()
00105 {
00106     selectionstatus = true;
00107 }
00108 
00109 int MainMenu::getselecteditem()
00110 {
00111     return selecteditem;
00112 }