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.

186 lines
4.7KB

  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. * Miscellaneous GUI functions.
  10. *
  11. * ---------------------------------------------------------------------------|
  12. */
  13. #include "common.h"
  14. #include "p_player.h"
  15. #include "w_world.h"
  16. /* Extern Functions -------------------------------------------------------- */
  17. void G_Auto(struct gui_state *g, u32 id, i32 x, i32 y, i32 w, i32 h,
  18. bool slide) {
  19. x += g->ox;
  20. y += g->oy;
  21. /* check clip versus cursor (if clipping), then check control
  22. * versus cursor
  23. */
  24. if((!g->useclip ||
  25. aabb_point(g->clpxS, g->clpyS, g->clpxE, g->clpyE, g->cx, g->cy)) &&
  26. aabb_point(x, y, w, h, g->cx, g->cy)) {
  27. g->hot = id;
  28. if(g->active == 0 && g->clicklft)
  29. g->active = id;
  30. }
  31. /* check slide state */
  32. if(slide && g->slide != id && g->active == id) {
  33. g->slide = id;
  34. g->slidetime = 1;
  35. g->slidecount = 0;
  36. }
  37. }
  38. void G_Init(struct gui_state *g, void *state) {
  39. g->state = state;
  40. g->gfxprefix = ":UI:";
  41. }
  42. void G_UpdateState(struct gui_state *g, struct player *p) {
  43. /* Due to ZDoom being ZDoom, GetUserCVar with invertmouse does
  44. * nothing. This breaks network sync so we can only do it in
  45. * single-player.
  46. */
  47. bool inverted = p->getCVarI(sc_player_invertmouse);
  48. Str(invertmouse, s"invertmouse");
  49. if(singleplayer) inverted |= ACS_GetCVar(invertmouse);
  50. g->old = g->cur;
  51. k32 xmul = p->getCVarK(sc_gui_xmul);
  52. k32 ymul = p->getCVarK(sc_gui_ymul);
  53. g->cx -= p->yawv * (800.0lk * xmul);
  54. if(inverted) g->cy += p->pitchv * (800.0lk * ymul);
  55. else g->cy -= p->pitchv * (800.0lk * ymul);
  56. g->cx = minmax(g->cx, 0, g->w);
  57. g->cy = minmax(g->cy, 0, g->h);
  58. g->clicklft = p->buttons & BT_ATTACK;
  59. g->clickrgt = p->buttons & BT_ALTATTACK;
  60. g->clickany = g->clicklft || g->clickrgt;
  61. g->defcr = Draw_GetCr(p->getCVarI(sc_gui_defcr));
  62. if(!g->clickany)
  63. g->slide = 0;
  64. else if(g->slidecount)
  65. g->slidetime++;
  66. }
  67. void G_Begin(struct gui_state *g, i32 w, i32 h) {
  68. if(!w) w = 320;
  69. if(!h) h = 200;
  70. g->hot = 0;
  71. SetSize(g->w = w, g->h = h);
  72. }
  73. void G_End(struct gui_state *g, enum cursor curs) {
  74. str cgfx;
  75. switch(curs) {
  76. default:
  77. case gui_curs_green: cgfx = sp_UI_Cursor; break;
  78. case gui_curs_pink: cgfx = sp_UI_CursorPink; break;
  79. case gui_curs_blue: cgfx = sp_UI_CursorBlue; break;
  80. case gui_curs_orange: cgfx = sp_UI_CursorOrange; break;
  81. case gui_curs_red: cgfx = sp_UI_CursorRed; break;
  82. case gui_curs_white: cgfx = sp_UI_CursorWhite; break;
  83. case gui_curs_outline: cgfx = sp_UI_CursorOutline; break;
  84. case gui_curs_outline2: cgfx = sp_UI_CursorOutline2; break;
  85. case gui_curs_outlineinv: cgfx = sp_UI_CursorOutlineInv; break;
  86. case gui_curs_outline2inv: cgfx = sp_UI_CursorOutline2Inv; break;
  87. }
  88. PrintSprite(cgfx, g->cx,1, g->cy,1);
  89. if(!g->clickany)
  90. g->active = 0;
  91. }
  92. void G_Clip(struct gui_state *g, i32 x, i32 y, i32 w, i32 h, i32 ww) {
  93. g->useclip = true;
  94. g->clpxE = w;
  95. g->clpyE = h;
  96. if(ww == 0) ww = w;
  97. SetClipW(g->clpxS = x, g->clpyS = y, w, h, ww);
  98. }
  99. void G_ClipRelease(struct gui_state *g) {
  100. g->useclip = g->clpxS = g->clpyS = g->clpxE = g->clpyE = 0;
  101. ClearClip();
  102. }
  103. void G_TypeOn(struct gui_state *g, struct gui_typ *typeon, str text) {
  104. typeon->txt = text;
  105. typeon->len = ACS_StrLen(text);
  106. typeon->pos = 0;
  107. }
  108. struct gui_typ const *G_TypeOnUpdate(struct gui_state *g,
  109. struct gui_typ *typeon) {
  110. i32 num = ACS_Random(2, 15);
  111. if((typeon->pos += num) > typeon->len)
  112. typeon->pos = typeon->len;
  113. return typeon;
  114. }
  115. bool G_Filler(i32 x, i32 y, u32 *fill, u32 tics, bool held) {
  116. if(*fill > tics) {
  117. *fill = 0;
  118. return true;
  119. }
  120. if(held) {
  121. *fill += 1;
  122. } else if(*fill && ticks % 4 == 0) {
  123. *fill -= 1;
  124. }
  125. PrintSprite(StrParam(":UI:Filler%i", (*fill * 8) / tics), x,1, y,0);
  126. return false;
  127. }
  128. i32 G_Tabs(struct gui_state *g, u32 *st, char const (*names)[20], size_t num,
  129. i32 x, i32 y, i32 yp) {
  130. i32 xp = 0;
  131. for(i32 i = 0; i < num; i++) {
  132. if(G_Button_HId(g, xp + yp * 6, names[i], gui_p.btntab.w * xp + x,
  133. gui_p.btntab.h * yp + y, i == *st, Pre(btntab))) {
  134. *st = i;
  135. }
  136. if(xp == 5) {
  137. xp = 0;
  138. yp++;
  139. } else {
  140. xp++;
  141. }
  142. }
  143. return yp;
  144. }
  145. /* EOF */