st_lib.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. // Emacs style mode select -*- C++ -*-
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. // $Log:$
  18. //
  19. // DESCRIPTION:
  20. // The status bar widget code.
  21. //
  22. //-----------------------------------------------------------------------------
  23. static const char
  24. rcsid[] = "$Id: st_lib.c,v 1.4 1997/02/03 16:47:56 b1 Exp $";
  25. #include <ctype.h>
  26. #include "doomdef.h"
  27. #include "z_zone.h"
  28. #include "v_video.h"
  29. #include "m_swap.h"
  30. #include "i_system.h"
  31. #include "w_wad.h"
  32. #include "st_stuff.h"
  33. #include "st_lib.h"
  34. #include "r_local.h"
  35. // in AM_map.c
  36. extern boolean automapactive;
  37. //
  38. // Hack display negative frags.
  39. // Loads and store the stminus lump.
  40. //
  41. patch_t* sttminus;
  42. void STlib_init(void)
  43. {
  44. sttminus = (patch_t *) W_CacheLumpName("STTMINUS", PU_STATIC);
  45. }
  46. // ?
  47. void
  48. STlib_initNum
  49. ( st_number_t* n,
  50. int x,
  51. int y,
  52. patch_t** pl,
  53. int* num,
  54. boolean* on,
  55. int width )
  56. {
  57. n->x = x;
  58. n->y = y;
  59. n->oldnum = 0;
  60. n->width = width;
  61. n->num = num;
  62. n->on = on;
  63. n->p = pl;
  64. }
  65. //
  66. // A fairly efficient way to draw a number
  67. // based on differences from the old number.
  68. // Note: worth the trouble?
  69. //
  70. void
  71. STlib_drawNum
  72. ( st_number_t* n,
  73. boolean refresh )
  74. {
  75. int numdigits = n->width;
  76. int num = *n->num;
  77. int w = SHORT(n->p[0]->width);
  78. int h = SHORT(n->p[0]->height);
  79. int x = n->x;
  80. int neg;
  81. n->oldnum = *n->num;
  82. neg = num < 0;
  83. if (neg)
  84. {
  85. if (numdigits == 2 && num < -9)
  86. num = -9;
  87. else if (numdigits == 3 && num < -99)
  88. num = -99;
  89. num = -num;
  90. }
  91. // clear the area
  92. x = n->x - numdigits*w;
  93. if (n->y - ST_Y < 0)
  94. I_Error("drawNum: n->y - ST_Y < 0");
  95. V_CopyRect(x, n->y - ST_Y, BG, w*numdigits, h, x, n->y, FG);
  96. // if non-number, do not draw it
  97. if (num == 1994)
  98. return;
  99. x = n->x;
  100. // in the special case of 0, you draw 0
  101. if (!num)
  102. V_DrawPatch(x - w, n->y, FG, n->p[ 0 ]);
  103. // draw the new number
  104. while (num && numdigits--)
  105. {
  106. x -= w;
  107. V_DrawPatch(x, n->y, FG, n->p[ num % 10 ]);
  108. num /= 10;
  109. }
  110. // draw a minus sign if necessary
  111. if (neg)
  112. V_DrawPatch(x - 8, n->y, FG, sttminus);
  113. }
  114. //
  115. void
  116. STlib_updateNum
  117. ( st_number_t* n,
  118. boolean refresh )
  119. {
  120. if (*n->on) STlib_drawNum(n, refresh);
  121. }
  122. //
  123. void
  124. STlib_initPercent
  125. ( st_percent_t* p,
  126. int x,
  127. int y,
  128. patch_t** pl,
  129. int* num,
  130. boolean* on,
  131. patch_t* percent )
  132. {
  133. STlib_initNum(&p->n, x, y, pl, num, on, 3);
  134. p->p = percent;
  135. }
  136. void
  137. STlib_updatePercent
  138. ( st_percent_t* per,
  139. int refresh )
  140. {
  141. if (refresh && *per->n.on)
  142. V_DrawPatch(per->n.x, per->n.y, FG, per->p);
  143. STlib_updateNum(&per->n, refresh);
  144. }
  145. void
  146. STlib_initMultIcon
  147. ( st_multicon_t* i,
  148. int x,
  149. int y,
  150. patch_t** il,
  151. int* inum,
  152. boolean* on )
  153. {
  154. i->x = x;
  155. i->y = y;
  156. i->oldinum = -1;
  157. i->inum = inum;
  158. i->on = on;
  159. i->p = il;
  160. }
  161. void
  162. STlib_updateMultIcon
  163. ( st_multicon_t* mi,
  164. boolean refresh )
  165. {
  166. int w;
  167. int h;
  168. int x;
  169. int y;
  170. if (*mi->on
  171. && (mi->oldinum != *mi->inum || refresh)
  172. && (*mi->inum!=-1))
  173. {
  174. if (mi->oldinum != -1)
  175. {
  176. x = mi->x - SHORT(mi->p[mi->oldinum]->leftoffset);
  177. y = mi->y - SHORT(mi->p[mi->oldinum]->topoffset);
  178. w = SHORT(mi->p[mi->oldinum]->width);
  179. h = SHORT(mi->p[mi->oldinum]->height);
  180. if (y - ST_Y < 0)
  181. I_Error("updateMultIcon: y - ST_Y < 0");
  182. V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG);
  183. }
  184. V_DrawPatch(mi->x, mi->y, FG, mi->p[*mi->inum]);
  185. mi->oldinum = *mi->inum;
  186. }
  187. }
  188. void
  189. STlib_initBinIcon
  190. ( st_binicon_t* b,
  191. int x,
  192. int y,
  193. patch_t* i,
  194. boolean* val,
  195. boolean* on )
  196. {
  197. b->x = x;
  198. b->y = y;
  199. b->oldval = 0;
  200. b->val = val;
  201. b->on = on;
  202. b->p = i;
  203. }
  204. void
  205. STlib_updateBinIcon
  206. ( st_binicon_t* bi,
  207. boolean refresh )
  208. {
  209. int x;
  210. int y;
  211. int w;
  212. int h;
  213. if (*bi->on
  214. && (bi->oldval != *bi->val || refresh))
  215. {
  216. x = bi->x - SHORT(bi->p->leftoffset);
  217. y = bi->y - SHORT(bi->p->topoffset);
  218. w = SHORT(bi->p->width);
  219. h = SHORT(bi->p->height);
  220. if (y - ST_Y < 0)
  221. I_Error("updateBinIcon: y - ST_Y < 0");
  222. if (*bi->val)
  223. V_DrawPatch(bi->x, bi->y, FG, bi->p);
  224. else
  225. V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG);
  226. bi->oldval = *bi->val;
  227. }
  228. }