You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

315 line
7.0KB

  1. /* ---------------------------------------------------------------------------|
  2. *
  3. * Distributed under the CC0 public domain license.
  4. * By Alison G. Watson. Attribution is encouraged, though not required.
  5. * See licenses/cc0.txt for more information.
  6. *
  7. * ---------------------------------------------------------------------------|
  8. *
  9. * GUI functions and data.
  10. *
  11. * ---------------------------------------------------------------------------|
  12. */
  13. #ifndef gui_h
  14. #define gui_h
  15. #include "m_cps.h"
  16. #define Pre(name) .preset = &gui_p.name
  17. /* Fixed ID */
  18. #define G_Args(ty, ...) &(struct gui_arg_##ty const){__VA_ARGS__}
  19. #define G_Button_FId(g, id, ...) G_Button_Imp(g, id, G_Args(btn, __VA_ARGS__))
  20. #define G_ChkBox_FId(g, id, ...) G_ChkBox_Imp(g, id, G_Args(cbx, __VA_ARGS__))
  21. #define G_ScrBeg_FId(g, id, ...) G_ScrBeg_Imp(g, id, G_Args(scr, __VA_ARGS__))
  22. #define G_Slider_FId(g, id, ...) G_Slider_Imp(g, id, G_Args(sld, __VA_ARGS__))
  23. #define G_TxtBox_FId(g, id, ...) G_TxtBox_Imp(g, id, G_Args(txt, __VA_ARGS__))
  24. #define G_WinBeg_FId(g, id, ...) G_WinBeg_Imp(g, id, G_Args(win, __VA_ARGS__))
  25. /* Hashed ID */
  26. #define G_HId(id) (id) + LineHash
  27. #define G_Button_HId(g, id, ...) G_Button_FId(g, G_HId(id), __VA_ARGS__)
  28. #define G_ChkBox_HId(g, id, ...) G_ChkBox_FId(g, G_HId(id), __VA_ARGS__)
  29. #define G_ScrBeg_HId(g, id, ...) G_ScrBeg_FId(g, G_HId(id), __VA_ARGS__)
  30. #define G_Slider_HId(g, id, ...) G_Slider_FId(g, G_HId(id), __VA_ARGS__)
  31. #define G_TxtBox_HId(g, id, ...) G_TxtBox_FId(g, G_HId(id), __VA_ARGS__)
  32. #define G_WinBeg_HId(g, id, ...) G_WinBeg_FId(g, G_HId(id), __VA_ARGS__)
  33. /* Hashed */
  34. #define G_Button(g, ...) G_Button_HId(g, 0, __VA_ARGS__)
  35. #define G_ChkBox(g, ...) G_ChkBox_HId(g, 0, __VA_ARGS__)
  36. #define G_ScrBeg(g, ...) G_ScrBeg_HId(g, 0, __VA_ARGS__)
  37. #define G_Slider(g, ...) G_Slider_HId(g, 0, __VA_ARGS__)
  38. #define G_TxtBox(g, ...) G_TxtBox_HId(g, 0, __VA_ARGS__)
  39. #define G_WinBeg(g, ...) G_WinBeg_HId(g, 0, __VA_ARGS__)
  40. #define G_GenPreset(type, def) \
  41. type pre; \
  42. if(a->preset) pre = *a->preset; \
  43. else pre = def
  44. #define G_Prefix(g, gfx, pre, mem) \
  45. do { \
  46. if(!(pre)->mem) (gfx)[0] = '\0'; \
  47. else if((pre)->external) strcpy(gfx, (pre)->mem); \
  48. else lstrcpy2(gfx, (g)->gfxprefix, (pre)->mem); \
  49. } while(0)
  50. #define G_ScrollReset(g, st) \
  51. (*(st) = (struct gui_scr){})
  52. #define G_TxtBoxRes(st) ((st)->tbptr = 0)
  53. #define G_TxtBoxEvt(st) \
  54. __with(cstr txt_buf = Cps_Expand(st->txtbuf, 0, st->tbptr);) \
  55. ifauto(cstr, _c, strchr(txt_buf, '\n')) \
  56. __with(size_t txt_len = _c - txt_buf; G_TxtBoxRes(st);)
  57. /* Types ------------------------------------------------------------------- */
  58. struct gui_scr {
  59. i32 ox;
  60. i32 oy;
  61. i32 occludeS;
  62. i32 occludeE;
  63. k64 y;
  64. k64 grabpos;
  65. bool grabbed;
  66. i32 nextsnd;
  67. };
  68. struct gui_typ {
  69. str txt;
  70. i32 len;
  71. i32 pos;
  72. };
  73. struct gui_txt {
  74. Cps_Decl(txtbuf, 128);
  75. i32 tbptr;
  76. };
  77. struct gui_fil {
  78. u32 *ptr;
  79. u32 tic;
  80. };
  81. struct gui_delta {
  82. k64 cx, cy;
  83. bool clicklft;
  84. bool clickrgt;
  85. bool clickany;
  86. };
  87. struct gui_state {
  88. anonymous
  89. struct gui_delta cur;
  90. struct gui_delta old;
  91. i32 defcr;
  92. i32 ox, oy;
  93. i32 w, h;
  94. u32 active, hot;
  95. u32 slide;
  96. i32 slidecount, slidetime;
  97. u32 dbl;
  98. i32 dbltime;
  99. bool useclip;
  100. i32 clpxS, clpyS, clpxE, clpyE;
  101. void *state;
  102. cstr gfxprefix;
  103. };
  104. struct gui_pre_btn {
  105. cstr gfx;
  106. cstr hot;
  107. cstr cdef;
  108. cstr cact;
  109. cstr chot;
  110. cstr cdis;
  111. str font;
  112. str snd;
  113. i32 ax;
  114. i32 ay;
  115. i32 w;
  116. i32 h;
  117. bool external;
  118. };
  119. struct gui_arg_btn {
  120. cstr label;
  121. i32 x, y;
  122. bool disabled;
  123. cstr color;
  124. bool slide;
  125. struct gui_fil const fill;
  126. struct gui_pre_btn const *preset;
  127. };
  128. struct gui_pre_cbx {
  129. cstr gfx;
  130. cstr hot;
  131. cstr dis;
  132. cstr chkgfx;
  133. cstr chkhot;
  134. cstr chkact;
  135. cstr chkdis;
  136. str sndup;
  137. str snddn;
  138. bool external;
  139. i32 w;
  140. i32 h;
  141. i32 cx;
  142. i32 cy;
  143. };
  144. struct gui_arg_cbx {
  145. bool on;
  146. i32 x, y;
  147. bool disabled;
  148. struct gui_pre_cbx const *preset;
  149. };
  150. struct gui_pre_scr {
  151. cstr capS;
  152. cstr capE;
  153. cstr scrl;
  154. cstr notchgfx;
  155. cstr notchhot;
  156. bool external;
  157. i32 scrlw;
  158. i32 scrlh;
  159. };
  160. struct gui_arg_scr {
  161. struct gui_scr *st;
  162. i32 x;
  163. i32 y;
  164. i32 w;
  165. i32 h;
  166. i32 contenth;
  167. i32 ww;
  168. struct gui_pre_scr const *preset;
  169. };
  170. struct gui_pre_sld {
  171. cstr gfx;
  172. cstr notch;
  173. cstr notchhot;
  174. str snd;
  175. str font;
  176. bool external;
  177. i32 pad;
  178. i32 w;
  179. i32 h;
  180. };
  181. struct gui_arg_sld {
  182. i32 x;
  183. i32 y;
  184. k64 minima;
  185. k64 maxima;
  186. k64 val;
  187. bool integ;
  188. cstr suf;
  189. struct gui_pre_sld const *preset;
  190. };
  191. struct gui_arg_txt {
  192. struct gui_txt *st;
  193. i32 x, y;
  194. struct player *p;
  195. };
  196. struct gui_presets {
  197. struct gui_pre_btn btndef;
  198. struct gui_pre_btn btntab;
  199. struct gui_pre_btn btnexit;
  200. struct gui_pre_btn btnnext;
  201. struct gui_pre_btn btnprev;
  202. struct gui_pre_btn btnnexts;
  203. struct gui_pre_btn btnprevs;
  204. struct gui_pre_btn btnlist;
  205. struct gui_pre_btn btnlistsel;
  206. struct gui_pre_btn btnlistactive;
  207. struct gui_pre_btn btnlistactivated;
  208. struct gui_pre_btn btnbipmain;
  209. struct gui_pre_btn btnbipback;
  210. struct gui_pre_btn btndlgsel;
  211. struct gui_pre_btn btnclear;
  212. struct gui_pre_btn btnnote;
  213. struct gui_pre_cbx cbxdef;
  214. struct gui_pre_cbx cbxsmall;
  215. struct gui_pre_scr scrdef;
  216. struct gui_pre_sld slddef;
  217. };
  218. enum cursor {
  219. gui_curs_green,
  220. gui_curs_pink,
  221. gui_curs_blue,
  222. gui_curs_orange,
  223. gui_curs_red,
  224. gui_curs_white,
  225. gui_curs_outline,
  226. gui_curs_outline2,
  227. gui_curs_outlineinv,
  228. gui_curs_outline2inv,
  229. gui_curs_max,
  230. };
  231. /* Extern Objects ---------------------------------------------------------- */
  232. extern struct gui_presets const gui_p;
  233. /* Extern Functions -------------------------------------------------------- */
  234. optargs(1)
  235. void G_Auto(struct gui_state *g, u32 id, i32 x, i32 y, i32 w, i32 h, bool slide);
  236. optargs(1)
  237. void G_Init(struct gui_state *g, void *state);
  238. void G_UpdateState(struct gui_state *g, struct player *p);
  239. optargs(2)
  240. void G_Begin(struct gui_state *g, i32 w, i32 h);
  241. void G_End(struct gui_state *g, enum cursor curs);
  242. optargs(1)
  243. void G_Clip(struct gui_state *g, i32 x, i32 y, i32 w, i32 h, i32 ww);
  244. void G_ClipRelease(struct gui_state *g);
  245. void G_TypeOn(struct gui_state *g, struct gui_typ *typeon, str text);
  246. struct gui_typ const *G_TypeOnUpdate(struct gui_state *g, struct gui_typ *typeon);
  247. bool G_Filler(i32 x, i32 y, u32 *fill, u32 tics, bool held);
  248. i32 G_Tabs(struct gui_state *g, u32 *st, char const (*names)[20], size_t num,
  249. i32 x, i32 y, i32 yp);
  250. void G_ScrEnd(struct gui_state *g, struct gui_scr *scr);
  251. optargs(1)
  252. bool G_ScrOcc(struct gui_state *g, struct gui_scr const *scr, i32 y, i32 h);
  253. #define G_ImpArgs(ty) struct gui_state *g, u32 id, struct gui_arg_##ty const *a
  254. bool G_Button_Imp(G_ImpArgs(btn));
  255. bool G_ChkBox_Imp(G_ImpArgs(cbx));
  256. void G_ScrBeg_Imp(G_ImpArgs(scr));
  257. k64 G_Slider_Imp(G_ImpArgs(sld));
  258. struct gui_txt *G_TxtBox_Imp(G_ImpArgs(txt));
  259. #if 0
  260. void G_WinBeg_Imp(G_ImpArgs(win));
  261. #endif
  262. #endif