menu.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * Copyright (c) 2019 Clementine Computing LLC.
  3. *
  4. * This file is part of PopuFare.
  5. *
  6. * PopuFare is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * PopuFare is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with PopuFare. If not, see <https://www.gnu.org/licenses/>.
  18. *
  19. */
  20. //--------------------------------------- Menu Node related --------------------------------------
  21. typedef enum
  22. {
  23. NODE_ROOT = 0, //this is special, respect its zero-ness
  24. NODE_MENU,
  25. NODE_ACTION,
  26. NODE_WIDGET,
  27. NODE_CLASS,
  28. NUM_NODETYPES
  29. } menunode_type;
  30. extern char *nodetype_words[NUM_NODETYPES];
  31. typedef enum
  32. {
  33. ACTION_RULE,
  34. ACTION_SETVAR,
  35. ACTION_APPEND,
  36. ACTION_BKSPACE,
  37. ACTION_SETMENU,
  38. ACTION_LOGIN,
  39. ACTION_LOGOUT,
  40. ACTION_SETPADDLE,
  41. ACTION_PREVSTOP,
  42. ACTION_NEXTSTOP,
  43. ACTION_SETEQNUM,
  44. ACTION_GETEQNUM,
  45. ACTION_CLRMSGS,
  46. ACTION_SHELLCALL,
  47. NUM_ACTIONS
  48. } action_type;
  49. extern char *action_words[NUM_ACTIONS];
  50. typedef enum
  51. {
  52. WIDGET_MENUINIT = 0, //not a real widget, just a placeholder for actions to take at menu init
  53. WIDGET_BUTTON,
  54. WIDGET_STATUSBAR,
  55. WIDGET_MESSAGES,
  56. WIDGET_INPUT,
  57. WIDGET_TEXT,
  58. WIDGET_BOX,
  59. WIDGET_FILLEDBOX,
  60. WIDGET_LINE,
  61. WIDGET_FULLSTATUS,
  62. NUM_WIDGETS
  63. } widget_type;
  64. extern char *widget_words[NUM_WIDGETS];
  65. typedef enum
  66. {
  67. FONT_SMALL = 0,
  68. FONT_MEDIUM,
  69. FONT_LARGE,
  70. NUM_FONTS
  71. } widget_font;
  72. extern char *font_words[NUM_FONTS];
  73. #define WF_DONTDRAW (0x0001) //Don't draw this widget
  74. #define WF_DISABLED (0x0002) //This widget is not clickabe (applies only to things like buttons that CAN be clickable)
  75. #define WF_PRESSED (0x0004) //This widget is currently pressed (internal use only)
  76. #define WF_SHADOW (0x0008) //This widget casts a shadow
  77. #define WF_PASSWORD (0x0010) //This input widget is a password entry (echo * instead of data)
  78. #define GRID (16)
  79. typedef struct widget_struct
  80. {
  81. int flags;
  82. widget_type type; //What kind of a widget is this...
  83. int x, y, width, height; //Coordinates and size in 16x16 grid units
  84. char *text; //Text and font
  85. widget_font font;
  86. pixel color, bgcolor, textcolor, hotcolor; //colors
  87. } widget;
  88. typedef struct action_struct
  89. {
  90. action_type type; //what kind of action is this
  91. //---------- common action params
  92. char *var;
  93. char *value;
  94. char *name;
  95. int limit;
  96. } action;
  97. typedef struct menu_struct
  98. {
  99. int keys;
  100. char **key;
  101. char **value;
  102. } menu;
  103. typedef struct menunode_struct //generic menu node structure
  104. {
  105. menunode_type type; //widget, action, or menu?
  106. struct menunode_struct *next; //next item in list
  107. struct menunode_struct *subtree; //subtree belonging to this item
  108. int keys; //number of raw parameters
  109. char **key; //raw keys
  110. char **value; //raw values
  111. union //data holders for this item (by type)
  112. {
  113. struct widget_struct wid;
  114. struct action_struct act;
  115. struct menu_struct mnu;
  116. };
  117. } menunode;
  118. //--------------------------------------- Menu Variable related ----------------------------------
  119. #define MENUVAR_IDENTLEN (16)
  120. #define MENUVAR_VALUELEN (32)
  121. typedef struct menuvar_struct
  122. {
  123. char ident[MENUVAR_IDENTLEN];
  124. char value[MENUVAR_VALUELEN];
  125. struct menuvar_struct *next;
  126. } menuvar;
  127. //--------------------------------------- Menu Tree related --------------------------------------
  128. typedef struct menu_stack_struct
  129. {
  130. menunode *n;
  131. menunode *tail;
  132. menunode_type expect;
  133. } menu_stack;
  134. #define PARSE_IN_CLASS_TAG (1)
  135. typedef struct menutree_struct
  136. {
  137. //--------------------------- These variables are used only during parse and initialization...
  138. unsigned int user_error;
  139. unsigned int parse_flags;
  140. unsigned int sp;
  141. XML_Parser parser;
  142. menu_stack stack[MENU_STACK_DEPTH];
  143. //------------------------------ These variables are used duriong operation
  144. //Head node of the menu tree (should contain all menus as children)
  145. struct menunode_struct *head;
  146. //Currently active menu....
  147. struct menunode_struct *current;
  148. //Currently pressed button
  149. struct menunode_struct *pressed;
  150. //And its temporary flags
  151. int pressed_flags;
  152. //And touch state...
  153. int down;
  154. int down_x;
  155. int down_y;
  156. //------------------------------
  157. struct menunode_struct *classlist;
  158. struct menuvar_struct *menuvars;
  159. } menutree;
  160. extern driver_status my_driver_status;
  161. extern int update_driver_status;
  162. extern time_t paddle_req_timeout;
  163. extern set_paddle_req paddle_req;
  164. //-------------------------------------------------------------------------------------
  165. menutree *load_menutree(char *fname);
  166. int init_menutree(menutree *mt);
  167. void free_menutree(menutree *mt);
  168. void print_menu_tree(menutree *mt);
  169. int setmenu(menutree *mt, char *name);
  170. int process_pen(menutree *mt, int x, int y, int down);
  171. int draw_menu(menutree *mt);
  172. void clear_diu_messages();
  173. void add_diu_message(pixel bgcolor, pixel textcolor, char *message);
  174. void replace_diu_message(pixel bgcolor, pixel textcolor, char *message);
  175. int check_paddle_request(menutree *mt);