Project Submission (late)

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers OptionsMenu.h Source File

OptionsMenu.h

00001 #ifndef OPTIONSMENU_H
00002 #define OPTIONSMENU_H
00003 
00004 #include "Menus.h"
00005 
00006 // Button class that can modify brightness
00007 
00008 /** BrightnessButton Class
00009  * @brief Derived from Button. Can incremement or decremement the lcd brightness.
00010  * @brief Can only do so in incremements of 5% and can be volatile due to inputs firing twice.
00011  */
00012 class BrightnessButton : public Button {
00013     public:
00014     N5110* lcd;
00015     BrightnessButton(N5110* screenPtr) : lcd(screenPtr) {
00016       x = 25;
00017       y = 16;
00018     }
00019     void virtual run() {
00020       if (brightnessVal < 0.97)
00021         brightnessVal += 0.05;
00022       lcd->setBrightness(brightnessVal);
00023       printf("Brightness increasing\n");
00024     }
00025     void virtual runBack() {
00026       if (brightnessVal > 0.03)
00027         brightnessVal -= 0.05; 
00028       lcd->setBrightness(brightnessVal);
00029       printf("Brightness decreasing\n");
00030     }
00031 };
00032 
00033 // Button class that can modify contrast
00034 /** ContrastButton Class
00035  * @brief Derived from Button. Can incremement or decremement the lcd contrast.
00036  * @brief Can only do so in incremements of 5% and can be volatile due to inputs firing twice.
00037  */
00038 class ContrastButton : public Button {
00039     public:
00040     N5110* lcd;
00041     ContrastButton(N5110* screenPtr) : lcd(screenPtr) {
00042       x = 25;
00043       y = 32;
00044     }
00045     void virtual run() {
00046       if (contrastVal < 0.97)
00047         contrastVal += 0.05;
00048       lcd->setContrast(contrastVal);
00049       printf("Contrast increasing\n");
00050     }
00051     void virtual runBack() {
00052       if (contrastVal > 0.03)
00053         contrastVal -= 0.05; 
00054       lcd->setContrast(contrastVal);
00055       printf("Contrast decreasing\n");
00056     }
00057 };
00058 
00059 // OptionsMenu lets the player modify the brightness and contrast
00060 // of the lcd screen. can only increment in 5% steps.
00061 
00062 /** OptionsMenu Class
00063  * @brief Derived from Menu. Displays the options to change brightness and contrast.
00064  */
00065 class OptionsMenu : public Menu {
00066     public:
00067     OptionsMenu(N5110* screenPtr) : Menu(screenPtr) {
00068         buttons[0] = new BrightnessButton(lcd);
00069         buttons[1] = new ContrastButton(lcd);
00070         currentButton = buttons[0];
00071         numOfButtons = 2;
00072         buttonIndex = 0;
00073     }
00074     void virtual draw() {
00075       std::stringstream ssb;
00076       std::stringstream ssc;
00077       ssc << (contrastVal*100) << "%";
00078       ssb << (brightnessVal*100) << "%";
00079       lcd->printString("Options:",10,0);
00080       lcd->printString("Brightness:",10,1);
00081       lcd->printString(ssb.str().c_str(),30,2);
00082       lcd->printString("Contrast:",10,3);
00083       lcd->printString(ssc.str().c_str(),30,4);
00084     }
00085     /** Destructor
00086     */
00087     ~OptionsMenu() {
00088         delete buttons[0];
00089         delete buttons[1];
00090     }   
00091 };
00092 
00093 #endif // OPTIONSMENU_H