| 1 | #include "menu.h" |
|---|
| 2 | |
|---|
| 3 | ///////////////////////////////////////// |
|---|
| 4 | // THIS IS NOT READY YET! |
|---|
| 5 | ///////////////////////////////////////// |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | ///////////////////////////////////////////////////////// |
|---|
| 9 | // Read menu.h to find out how this works. |
|---|
| 10 | // |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | // Internal record of all important menu info... |
|---|
| 16 | typedef struct MenuInfo |
|---|
| 17 | { |
|---|
| 18 | MenuItem *menu; // User-specified menu information |
|---|
| 19 | struct MenuInfo *parent; // NULL if root-level |
|---|
| 20 | int items; // number of items in the menu |
|---|
| 21 | int sel; // selected item |
|---|
| 22 | } MenuInfo; |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | // Main menu function... |
|---|
| 27 | int do_menu(MenuItem *menu, MenuInfo *parent); |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | void FillMenuInfo(MenuInfo *m, MenuItem *menu, MenuInfo *parent); |
|---|
| 31 | |
|---|
| 32 | void DrawMenu(MenuInfo *m); |
|---|
| 33 | void DrawMenuItem(MenuInfo *m, int item); |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | /////////////////////////////////////////////////////////////////// |
|---|
| 37 | // User-callable function... |
|---|
| 38 | // |
|---|
| 39 | int menu(MenuItem *menu) |
|---|
| 40 | { |
|---|
| 41 | int ret; |
|---|
| 42 | |
|---|
| 43 | CreateArrows(); // Set custom characters for menu use... |
|---|
| 44 | |
|---|
| 45 | ret = do_menu(menu, NULL); |
|---|
| 46 | |
|---|
| 47 | return ret; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | int do_menu(MenuItem *menu, MenuInfo *parent) |
|---|
| 53 | { |
|---|
| 54 | int current; |
|---|
| 55 | int uparrow; |
|---|
| 56 | int downarrow; |
|---|
| 57 | |
|---|
| 58 | int key; |
|---|
| 59 | int err=0; |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | while(! err) |
|---|
| 63 | { |
|---|
| 64 | // Draw the menu... |
|---|
| 65 | |
|---|
| 66 | // Wait for input |
|---|
| 67 | |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | } |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | int do_menu(MenuItem *menu, MenuInfo *parent) |
|---|
| 74 | { |
|---|
| 75 | int i; |
|---|
| 76 | int items; |
|---|
| 77 | MenuInfo ThisMenu; |
|---|
| 78 | int old_sel; |
|---|
| 79 | int redraw=1; |
|---|
| 80 | int ret=0; |
|---|
| 81 | |
|---|
| 82 | FillMenuInfo(&ThisMenu, menu, parent); |
|---|
| 83 | |
|---|
| 84 | //FIXME: Get input here... Move the selection thingy |
|---|
| 85 | |
|---|
| 86 | DrawMenu(&ThisMenu); |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | do{ |
|---|
| 90 | //FIXME: Get input here... Move the selection thingy |
|---|
| 91 | |
|---|
| 92 | // Figure out which button should be highlighted... |
|---|
| 93 | |
|---|
| 94 | // And... if the "execute" button was pressed... |
|---|
| 95 | if() |
|---|
| 96 | { |
|---|
| 97 | ThisMenu.sel = i; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | DrawMenu(&ThisMenu); |
|---|
| 101 | redraw = 0; |
|---|
| 102 | |
|---|
| 103 | // Dismiss menu? |
|---|
| 104 | if( // cancel was pressed... |
|---|
| 105 | ) |
|---|
| 106 | ret = GUI_CONT; |
|---|
| 107 | |
|---|
| 108 | // pop up another menu? |
|---|
| 109 | if( // execute was pressed... |
|---|
| 110 | &&ThisMenu.sel >= 0 |
|---|
| 111 | &&ThisMenu.menu[ThisMenu.sel].child) |
|---|
| 112 | { |
|---|
| 113 | i = do_menu(ThisMenu.menu[ThisMenu.sel].child, &ThisMenu); |
|---|
| 114 | if(i == GUI_OK) ret = GUI_OK; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | // Or call a function? |
|---|
| 118 | else if( // execute was pressed... |
|---|
| 119 | &&ThisMenu.sel >= 0 |
|---|
| 120 | &&ThisMenu.menu[ThisMenu.sel].func) |
|---|
| 121 | { |
|---|
| 122 | ret = ThisMenu.menu[ThisMenu.sel].func(); |
|---|
| 123 | //ret = GUI_OK; |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | } while(! ret); |
|---|
| 127 | |
|---|
| 128 | return ret; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | ////////////////////////////////////////////////////////////////////// |
|---|
| 134 | // Initializes a menu... |
|---|
| 135 | // |
|---|
| 136 | void FillMenuInfo(MenuInfo *m, MenuItem *menu, MenuInfo * parent) |
|---|
| 137 | { |
|---|
| 138 | m->menu = menu; |
|---|
| 139 | m->parent = parent; |
|---|
| 140 | m->sel = 0; |
|---|
| 141 | |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | void DrawMenu(MenuInfo *m) |
|---|
| 146 | { |
|---|
| 147 | int i; |
|---|
| 148 | |
|---|
| 149 | for(i=0; i<m->items; i++) |
|---|
| 150 | DrawMenuItem(m, i); |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | void DrawMenuItem(MenuInfo *m, int item) |
|---|
| 154 | { |
|---|
| 155 | // Figure out how much to scroll down... |
|---|
| 156 | // Write each menu item... |
|---|
| 157 | // Put arrows where needed (next to current item, and up/down arrow) |
|---|
| 158 | // m->menu[item].text holds the text string... |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | |
|---|