st_lib.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU 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. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #include "Precompiled.h"
  21. #include "globaldata.h"
  22. #include <ctype.h>
  23. #include "doomdef.h"
  24. #include "z_zone.h"
  25. #include "v_video.h"
  26. #include "m_swap.h"
  27. #include "i_system.h"
  28. #include "w_wad.h"
  29. #include "st_stuff.h"
  30. #include "st_lib.h"
  31. #include "r_local.h"
  32. // in AM_map.c
  33. //
  34. // Hack display negative frags.
  35. // Loads and store the stminus lump.
  36. //
  37. void STlib_init(void)
  38. {
  39. ::g->sttminus = (patch_t *) W_CacheLumpName("STTMINUS", PU_STATIC_SHARED);
  40. }
  41. // ?
  42. void
  43. STlib_initNum
  44. ( st_number_t* n,
  45. int x,
  46. int y,
  47. patch_t** pl,
  48. int* num,
  49. qboolean* on,
  50. int width )
  51. {
  52. n->x = x;
  53. n->y = y;
  54. n->oldnum = 0;
  55. n->width = width;
  56. n->num = num;
  57. n->on = on;
  58. n->p = pl;
  59. }
  60. //
  61. // A fairly efficient way to draw a number
  62. // based on differences from the old number.
  63. // Note: worth the trouble?
  64. //
  65. void
  66. STlib_drawNum
  67. ( st_number_t* n,
  68. qboolean refresh )
  69. {
  70. int numdigits = n->width;
  71. int num = *n->num;
  72. int w = SHORT(n->p[0]->width);
  73. int h = SHORT(n->p[0]->height);
  74. int x = n->x;
  75. int neg;
  76. n->oldnum = *n->num;
  77. neg = num < 0;
  78. if (neg)
  79. {
  80. if (numdigits == 2 && num < -9)
  81. num = -9;
  82. else if (numdigits == 3 && num < -99)
  83. num = -99;
  84. num = -num;
  85. }
  86. // clear the area
  87. x = n->x - numdigits*w;
  88. if (n->y - ST_Y < 0)
  89. I_Error("drawNum: n->y - ST_Y < 0");
  90. V_CopyRect(x, n->y - ST_Y, BG, w*numdigits, h, x, n->y, FG);
  91. // if non-number, do not draw it
  92. if (num == 1994)
  93. return;
  94. x = n->x;
  95. // in the special case of 0, you draw 0
  96. if (!num)
  97. V_DrawPatch(x - w, n->y, FG, n->p[ 0 ]);
  98. // draw the new number
  99. while (num && numdigits--)
  100. {
  101. x -= w;
  102. V_DrawPatch(x, n->y, FG, n->p[ num % 10 ]);
  103. num /= 10;
  104. }
  105. // draw a minus sign if necessary
  106. if (neg)
  107. V_DrawPatch(x - 8, n->y, FG, ::g->sttminus);
  108. }
  109. //
  110. void
  111. STlib_updateNum
  112. ( st_number_t* n,
  113. qboolean refresh )
  114. {
  115. if (*n->on) STlib_drawNum(n, refresh);
  116. }
  117. //
  118. void
  119. STlib_initPercent
  120. ( st_percent_t* p,
  121. int x,
  122. int y,
  123. patch_t** pl,
  124. int* num,
  125. qboolean* on,
  126. patch_t* percent )
  127. {
  128. STlib_initNum(&p->n, x, y, pl, num, on, 3);
  129. p->p = percent;
  130. }
  131. void
  132. STlib_updatePercent
  133. ( st_percent_t* per,
  134. int refresh )
  135. {
  136. if (refresh && *per->n.on)
  137. V_DrawPatch(per->n.x, per->n.y, FG, per->p);
  138. STlib_updateNum(&per->n, refresh);
  139. }
  140. void
  141. STlib_initMultIcon
  142. ( st_multicon_t* i,
  143. int x,
  144. int y,
  145. patch_t** il,
  146. int* inum,
  147. qboolean* on )
  148. {
  149. i->x = x;
  150. i->y = y;
  151. i->oldinum = -1;
  152. i->inum = inum;
  153. i->on = on;
  154. i->p = il;
  155. }
  156. void
  157. STlib_updateMultIcon
  158. ( st_multicon_t* mi,
  159. qboolean refresh )
  160. {
  161. int w;
  162. int h;
  163. int x;
  164. int y;
  165. if (*mi->on
  166. && (mi->oldinum != *mi->inum || refresh)
  167. && (*mi->inum!=-1))
  168. {
  169. if (mi->oldinum != -1)
  170. {
  171. x = mi->x - SHORT(mi->p[mi->oldinum]->leftoffset);
  172. y = mi->y - SHORT(mi->p[mi->oldinum]->topoffset);
  173. w = SHORT(mi->p[mi->oldinum]->width);
  174. h = SHORT(mi->p[mi->oldinum]->height);
  175. if (y - ST_Y < 0)
  176. I_Error("updateMultIcon: y - ST_Y < 0");
  177. V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG);
  178. }
  179. V_DrawPatch(mi->x, mi->y, FG, mi->p[*mi->inum]);
  180. mi->oldinum = *mi->inum;
  181. }
  182. }
  183. void
  184. STlib_initBinIcon
  185. ( st_binicon_t* b,
  186. int x,
  187. int y,
  188. patch_t* i,
  189. qboolean* val,
  190. qboolean* on )
  191. {
  192. b->x = x;
  193. b->y = y;
  194. b->oldval = 0;
  195. b->val = val;
  196. b->on = on;
  197. b->p = i;
  198. }
  199. void
  200. STlib_updateBinIcon
  201. ( st_binicon_t* bi,
  202. qboolean refresh )
  203. {
  204. int x;
  205. int y;
  206. int w;
  207. int h;
  208. if (*bi->on
  209. && (bi->oldval != *bi->val || refresh))
  210. {
  211. x = bi->x - SHORT(bi->p->leftoffset);
  212. y = bi->y - SHORT(bi->p->topoffset);
  213. w = SHORT(bi->p->width);
  214. h = SHORT(bi->p->height);
  215. if (y - ST_Y < 0)
  216. I_Error("updateBinIcon: y - ST_Y < 0");
  217. if (*bi->val)
  218. V_DrawPatch(bi->x, bi->y, FG, bi->p);
  219. else
  220. V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG);
  221. bi->oldval = *bi->val;
  222. }
  223. }