TRC Library for FTC (2011) 2011
TRC Library Code Project

C:/Users/Michael/Ftc/2011/code/trclib/menu.h

Go to the documentation of this file.
00001 #if 0
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 #endif
00016 
00017 #ifndef _MENU_H
00018 #define _MENU_H
00019 
00020 #pragma systemFile
00021 
00022 #ifdef MOD_ID
00023     #undef MOD_ID
00024 #endif
00025 #define MOD_ID                  MOD_MENU
00026 
00027 //
00028 // Constants
00029 //
00030 #define MAX_NUM_CHOICES         6
00031 
00032 //
00033 // Type definitions.
00034 //
00035 typedef struct
00036 {
00037     string titleText;
00038     int    startLine;
00039     int    userChoice;
00040     string choices[MAX_NUM_CHOICES];
00041     int    numChoices;
00042 } MENU;
00043 
00052 void
00053 MenuInit(
00054     __out MENU &menu,
00055     __in  string titleText,
00056     __in  int startLine,
00057     __in  int defChoice
00058     )
00059 {
00060     TFuncName("MenuInit");
00061     TLevel(INIT);
00062     TEnter();
00063 
00064     strcpy(menu.titleText, titleText);
00065     menu.startLine = startLine;
00066     menu.userChoice = defChoice;
00067     menu.numChoices = 0;
00068 
00069     TExit();
00070     return;
00071 }   //MenuInit
00072 
00082 bool
00083 MenuAddChoice(
00084     __inout MENU &menu,
00085     __in    string choiceText
00086     )
00087 {
00088     bool fSuccess = false;
00089 
00090     TFuncName("MenuAddChoice");
00091     TLevel(API);
00092     TEnter();
00093 
00094     if (menu.numChoices < MAX_NUM_CHOICES)
00095     {
00096         strcpy(menu.choices[menu.numChoices], choiceText);
00097         menu.numChoices++;
00098         fSuccess = true;
00099     }
00100 
00101     TExit();
00102     return fSuccess;
00103 }   //MenuAddChoice
00104 
00112 int
00113 MenuGetChoice(
00114     __inout MENU &menu
00115     )
00116 {
00117     int choice;
00118     TButtons prevNxtBtn;
00119     TButtons currNxtBtn;
00120 
00121     TFuncName("MenuGetChoice");
00122     TLevel(API);
00123     TEnter();
00124 
00125     eraseDisplay();
00126     nxtDisplayTextLine(menu.startLine, menu.titleText);
00127     for (choice = 0; choice < menu.numChoices; choice++)
00128     {
00129         nxtDisplayTextLine(menu.startLine + 1 + choice,
00130                            "%d: %s", choice, menu.choices[choice]);
00131     }
00132 
00133     prevNxtBtn = nNxtButtonPressed;
00134     while (true)
00135     {
00136         currNxtBtn = nNxtButtonPressed;
00137         if (currNxtBtn != prevNxtBtn)
00138         {
00139             if (currNxtBtn == kLeftButton)
00140             {
00141                 menu.userChoice--;
00142                 if (menu.userChoice < 0)
00143                 {
00144                     menu.userChoice = menu.numChoices - 1;
00145                 }
00146             }
00147             else if (currNxtBtn == kRightButton)
00148             {
00149                 menu.userChoice++;
00150                 if (menu.userChoice >= menu.numChoices)
00151                 {
00152                     menu.userChoice = 0;
00153                 }
00154             }
00155             else if (currNxtBtn == kEnterButton)
00156             {
00157                 break;
00158             }
00159             prevNxtBtn = currNxtBtn;
00160         }
00161         nxtDisplayTextLine(menu.startLine + menu.numChoices + 1,
00162                            "Choice? %d", menu.userChoice);
00163         wait1Msec(100);
00164     }
00165 
00166     TExit();
00167     return menu.userChoice;
00168 }   //MenuGetChoice
00169 
00174 void
00175 MenuWaitStart()
00176 {
00177     TButtons prevNxtBtn;
00178     TButtons currNxtBtn;
00179 
00180     TFuncName("MenuWaitStart");
00181     TLevel(API);
00182     TEnter();
00183 
00184     prevNxtBtn = nNxtButtonPressed;
00185     while (true)
00186     {
00187         getJoystickSettings(joystick);
00188         currNxtBtn = nNxtButtonPressed;
00189         if (!joystick.StopPgm ||
00190             (currNxtBtn != prevNxtBtn) && (currNxtBtn != kEnterButton))
00191         {
00192             break;
00193         }
00194         prevNxtBtn = currNxtBtn;
00195     }
00196 
00197     TExit();
00198     return;
00199 }   //MenuWaitStart
00200 
00201 #endif  //ifndef _MENU_H
 All Data Structures Files Functions Variables Defines