menu.c 1.5 KB

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