Import upstream u-boot 1.1.4
[u-boot.git] / board / MAI / menu / menu.c
1 #include "menu.h"
2
3 #define SINGLE_BOX 0
4 #define DOUBLE_BOX 1
5
6 void video_draw_box(int style, int attr, char *title, int separate, int x, int y, int w, int h);
7 void video_draw_text(int x, int y, int attr, char *text);
8 void video_save_rect(int x, int y, int w, int h, void *save_area, int clearchar, int clearattr);
9 void video_restore_rect(int x, int y, int w, int h, void *save_area);
10 int  video_rows(void);
11 int  video_cols(void);
12
13 #define MAX_MENU_OPTIONS 200
14
15 typedef struct
16 {
17     int used;                  /* flag if this entry is used */
18     int entry_x;               /* Character column of the menu entry */
19     int entry_y;               /* Character line of the entry */
20     int option_x;              /* Character colum of the option (entry is same) */
21 } option_data_t;
22
23 option_data_t odata[MAX_MENU_OPTIONS];
24
25 int normal_attr = 0x0F;
26 int select_attr = 0x2F;
27 int disabled_attr = 0x07;
28
29 menu_t *root_menu;
30
31 int menu_init (menu_t *root)
32 {
33     char *s;
34     int i;
35
36     s = getenv("menu_normal");
37     if (s) normal_attr = atoi(s);
38
39     s = getenv("menu_select");
40     if (s) select_attr = atoi(s);
41
42     s = getenv("menu_disabled");
43     if (s) disabled_attr = atoi(s);
44
45     for (i=0; i<MAX_MENU_OPTIONS; i++) odata[i].used = 0;
46
47     root_menu = root;
48 }
49
50 option_data_t *menu_alloc_odata(void)
51 {
52     int i;
53     for (int i=0; i<MAX_MENU_OPTIONS; i++)
54     {
55         if (odata[i].used == 0) return &odata[i];
56     }
57     return NULL;
58 }
59
60 void menu_free_odata(option_data_t *odata)
61 {
62     odata->used = 0;
63 }
64
65 void menu_layout (menu_t *menu)
66 {