ui.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. #ifndef _UI_H_
  2. #define _UI_H_
  3. #include "graphics.h"
  4. #define EVENT_UNHANDLED 0
  5. #define EVENT_HANDLED 1
  6. #define SML_FONT 15
  7. #define LGE_FONT 20
  8. #define UIMSG_OK 0
  9. #define UIMSG_YN 1
  10. #define UIMSG_OC 2
  11. #define UI_WIDGET_NULL 0x00
  12. #define UI_WIDGET_LABEL 0x01
  13. #define UI_WIDGET_BUTTON 0x02
  14. #define UI_WIDGET_CONTAINER 0x03
  15. #define UI_WIDGET_TEXT 0x04
  16. #define UI_WIDGET_NUM 0x05
  17. #define UI_WIDGET_CHECK 0x06
  18. #define UI_WIDGET_HEADER 0x07
  19. #define UI_WIDGET_CONSOLE 0x08
  20. #define UI_WIDGET_PBAR 0x09
  21. #define UI_WIDGET_TEXTBOX 0x0A
  22. #define UI_WIDGET_HSLIDE 0x0B
  23. #define UI_WIDGET_LIST 0x0C
  24. #define UI_WIDGET_LISTROW 0x0D
  25. struct widget_s;
  26. #ifndef _HAVE_SPRITE_TYPE
  27. #define _HAVE_SPRITE_TYPE
  28. typedef struct sprite_s {
  29. GLfloat x;
  30. GLfloat y;
  31. GLfloat w;
  32. GLfloat h;
  33. material_t *mat;
  34. } sprite_t;
  35. #endif
  36. #ifndef _HAVE_MSGBOX_DATA_TYPE
  37. #define _HAVE_MSGBOX_DATA_TYPE
  38. typedef struct msgbox_data_s {
  39. struct widget_s *container;
  40. struct widget_s *txt;
  41. struct widget_s *btn1;
  42. struct widget_s *btn2;
  43. int (*btn1_func)(struct widget_s*);
  44. int (*btn2_func)(struct widget_s*);
  45. } msgbox_data_t;
  46. #endif
  47. #ifndef _HAVE_LISTROW_DATA_TYPE
  48. #define _HAVE_LISTROW_DATA_TYPE
  49. typedef struct listrow_data_s {
  50. char** values;
  51. } listrow_data_t;
  52. #endif
  53. #ifndef _HAVE_LISTCOLUMN_TYPE
  54. #define _HAVE_LISTCOLUMN_TYPE
  55. typedef struct list_column_s {
  56. char* name;
  57. int width;
  58. } list_column_t;
  59. #endif
  60. #ifndef _HAVE_LIST_DATA_TYPE
  61. #define _HAVE_LIST_DATA_TYPE
  62. typedef struct list_data_s {
  63. int col_cnt;
  64. int rows;
  65. int offset;
  66. int y;
  67. int (*click)(struct widget_s *);
  68. list_column_t *columns;
  69. } list_data_t;
  70. #endif
  71. #ifndef _HAVE_OPTBOX_BTN_TYPE
  72. #define _HAVE_OPTBOX_BTN_TYPE
  73. typedef struct optbox_btn_s {
  74. struct widget_s *btn;
  75. int (*func)(struct widget_s*);
  76. struct optbox_btn_s *next;
  77. } optbox_btn_t;
  78. #endif
  79. #ifndef _HAVE_OPTBOX_DATA_TYPE
  80. #define _HAVE_OPTBOX_DATA_TYPE
  81. typedef struct optbox_data_s {
  82. struct widget_s *container;
  83. struct widget_s *txt;
  84. optbox_btn_t *buttons;
  85. } optbox_data_t;
  86. #endif
  87. #ifndef _HAVE_OPTION_DATA_TYPE
  88. #define _HAVE_OPTION_DATA_TYPE
  89. typedef struct option_data_s {
  90. char com[100];
  91. } option_data_t;
  92. #endif
  93. #ifndef _HAVE_CHECKBOX_DATA_TYPE
  94. #define _HAVE_CHECKBOX_DATA_TYPE
  95. typedef struct checkbox_data_s {
  96. uint8_t checked;
  97. } check_data_t;
  98. #endif
  99. #ifndef _HAVE_NUMBOX_DATA_TYPE
  100. #define _HAVE_NUMBOX_DATA_TYPE
  101. typedef struct numbox_data_s {
  102. int value;
  103. int min;
  104. int max;
  105. } numbox_data_t;
  106. #endif
  107. #ifndef _HAVE_CONSOLE_LINE_TYPE
  108. #define _HAVE_CONSOLE_LINE_TYPE
  109. typedef struct console_line_s {
  110. struct console_line_s *prev;
  111. struct console_line_s *next;
  112. char str[256];
  113. } console_line_t;
  114. #endif
  115. #ifndef _HAVE_CONSOLE_DATA_TYPE
  116. #define _HAVE_CONSOLE_DATA_TYPE
  117. typedef struct console_data_s {
  118. console_line_t *lines;
  119. char command[256];
  120. int cchar;
  121. } console_data_t;
  122. #endif
  123. #ifndef _HAVE_SLIDE_DATA_TYPE
  124. #define _HAVE_SLIDE_DATA_TYPE
  125. typedef struct slide_data_s {
  126. int value;
  127. int min;
  128. int max;
  129. sprite_t *sld;
  130. } slide_data_t;
  131. #endif
  132. #ifndef _HAVE_PBAR_DATA_TYPE
  133. #define _HAVE_PBAR_DATA_TYPE
  134. typedef struct pbar_data_s {
  135. int max;
  136. int value;
  137. int blind;
  138. colour_t colour;
  139. } pbar_data_t;
  140. #endif
  141. #ifndef _HAVE_WIDGET_DATA_TYPE
  142. #define _HAVE_WIDGET_DATA_TYPE
  143. typedef union widget_data_u {
  144. console_data_t con;
  145. numbox_data_t num;
  146. check_data_t chk;
  147. pbar_data_t pbr;
  148. msgbox_data_t msg;
  149. optbox_data_t opb;
  150. option_data_t opt;
  151. slide_data_t sld;
  152. list_data_t lst;
  153. listrow_data_t row;
  154. } widget_data_t;
  155. #endif
  156. #ifndef _HAVE_WIDGET_EVENTS_TYPE
  157. #define _HAVE_WIDGET_EVENTS_TYPE
  158. typedef struct widget_events_s {
  159. int (*mclick)(struct widget_s *w);
  160. int (*mdown)(struct widget_s *w);
  161. int (*mup)(struct widget_s *w);
  162. int (*sdown)(struct widget_s *w);
  163. int (*sup)(struct widget_s *w);
  164. int (*mmove)(struct widget_s *w);
  165. int (*kdown)(struct widget_s *w);
  166. int (*kup)(struct widget_s *w);
  167. int (*show)(struct widget_s *w);
  168. int (*hide)(struct widget_s *w);
  169. } widget_events_t;
  170. #endif
  171. #ifndef _HAVE_WIDGET_STYLE_TYPE
  172. #define _HAVE_WIDGET_STYLE_TYPE
  173. typedef struct widget_style_s {
  174. int x;
  175. int y;
  176. int w;
  177. int h;
  178. int visible;
  179. int visibility_changed;
  180. sprite_t *bg;
  181. colour_t color;
  182. colour_t border;
  183. int has_border;
  184. int text_align;
  185. int font_face;
  186. int font_size;
  187. colour_t ttcolor;
  188. colour_t ttbg;
  189. int has_ttbg;
  190. colour_t ttborder;
  191. int has_ttborder;
  192. int ttfont_face;
  193. int ttfont_size;
  194. } widget_style_t;
  195. #endif
  196. #ifndef _HAVE_WIDGET_TYPE
  197. #define _HAVE_WIDGET_TYPE
  198. typedef struct widget_s {
  199. struct widget_s *prev;
  200. struct widget_s *next;
  201. uint32_t type;
  202. uint32_t id;
  203. textbuffer_t text;
  204. int hover;
  205. textbuffer_t htext;
  206. struct xml_tag_s *x;
  207. widget_style_t style;
  208. widget_data_t *data;
  209. widget_events_t *events;
  210. struct widget_s *parent;
  211. struct widget_s *child;
  212. } widget_t;
  213. #endif
  214. /* defined in ui.c */
  215. int ui_init(void);
  216. widget_t *ui_widget_container(void);
  217. void ui_render(void);
  218. void ui_loader(char* str);
  219. void ui_msg(uint8_t type, char* txt, int (*func)(), ...);
  220. void ui_opt(char* txt, ...);
  221. #endif