home *** CD-ROM | disk | FTP | other *** search
/ ST-Computer Leser-CD 2000 January / LCD_01_2000.iso / games / doom / pmdoom / src / st_lib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-12-17  |  5.1 KB  |  295 lines

  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.  
  24.  
  25. static const char
  26. rcsid[] = "$Id: st_lib.c,v 1.4 1997/02/03 16:47:56 b1 Exp $";
  27.  
  28. #include <ctype.h>
  29.  
  30. #include "doomdef.h"
  31.  
  32. #include "z_zone.h"
  33. #include "v_video.h"
  34.  
  35. #include "m_swap.h"
  36.  
  37. #include "i_system.h"
  38.  
  39. #include "w_wad.h"
  40.  
  41. #include "st_stuff.h"
  42. #include "st_lib.h"
  43. #include "r_local.h"
  44.  
  45. #include "i_video.h"
  46.  
  47. /*  in AM_map.c */
  48. extern boolean        automapactive; 
  49.  
  50.  
  51.  
  52.  
  53. /*  */
  54. /*  Hack display negative frags. */
  55. /*   Loads and store the stminus lump. */
  56. /*  */
  57. patch_t*        sttminus;
  58.  
  59. void STlib_init(void)
  60. {
  61.     sttminus = (patch_t *) W_CacheLumpName("STTMINUS", PU_STATIC);
  62. }
  63.  
  64.  
  65. /*  ? */
  66. void
  67. STlib_initNum
  68. ( st_number_t*        n,
  69.   int            x,
  70.   int            y,
  71.   patch_t**        pl,
  72.   int*            num,
  73.   boolean*        on,
  74.   int            width )
  75. {
  76.     n->x    = x;
  77.     n->y    = y;
  78.     n->oldnum    = 0;
  79.     n->width    = width;
  80.     n->num    = num;
  81.     n->on    = on;
  82.     n->p    = pl;
  83. }
  84.  
  85.  
  86. /*   */
  87. /*  A fairly efficient way to draw a number */
  88. /*   based on differences from the old number. */
  89. /*  Note: worth the trouble? */
  90. /*  */
  91. void
  92. STlib_drawNum
  93. ( st_number_t*    n,
  94.   boolean    refresh )
  95. {
  96.  
  97.     int        numdigits = n->width;
  98.     int        num = *n->num;
  99.     
  100.     int        w = SHORT(n->p[0]->width);
  101.     int        h = SHORT(n->p[0]->height);
  102.     int        x = n->x;
  103.     
  104.     int        neg;
  105.  
  106.     n->oldnum = *n->num;
  107.  
  108.     neg = num < 0;
  109.  
  110.     if (neg)
  111.     {
  112.     if (numdigits == 2 && num < -9)
  113.         num = -9;
  114.     else if (numdigits == 3 && num < -99)
  115.         num = -99;
  116.     
  117.     num = -num;
  118.     }
  119.  
  120.     /*  clear the area */
  121.     x = n->x - numdigits*w;
  122.  
  123.     if (n->y - ST_Y < 0)
  124.     I_Error("drawNum: n->y - ST_Y < 0");
  125.  
  126.     V_CopyRect(x, n->y - ST_Y, BG, w*numdigits, h, x, n->y, FG);
  127.  
  128.     /*  if non-number, do not draw it */
  129.     if (num == 1994)
  130.     return;
  131.  
  132.     x = n->x;
  133.  
  134.     /*  in the special case of 0, you draw 0 */
  135.     if (!num)
  136.     V_DrawPatch(x - w, n->y, FG, n->p[ 0 ]);
  137.  
  138.     /*  draw the new number */
  139.     while (num && numdigits--)
  140.     {
  141.     x -= w;
  142.     V_DrawPatch(x, n->y, FG, n->p[ num % 10 ]);
  143.     num /= 10;
  144.     }
  145.  
  146.     /*  draw a minus sign if necessary */
  147.     if (neg)
  148.     V_DrawPatch(x - 8, n->y, FG, sttminus);
  149. }
  150.  
  151.  
  152. /*  */
  153. void
  154. STlib_updateNum
  155. ( st_number_t*        n,
  156.   boolean        refresh )
  157. {
  158.     if (*n->on) STlib_drawNum(n, refresh);
  159. }
  160.  
  161.  
  162. /*  */
  163. void
  164. STlib_initPercent
  165. ( st_percent_t*        p,
  166.   int            x,
  167.   int            y,
  168.   patch_t**        pl,
  169.   int*            num,
  170.   boolean*        on,
  171.   patch_t*        percent )
  172. {
  173.     STlib_initNum(&p->n, x, y, pl, num, on, 3);
  174.     p->p = percent;
  175. }
  176.  
  177.  
  178.  
  179.  
  180. void
  181. STlib_updatePercent
  182. ( st_percent_t*        per,
  183.   int            refresh )
  184. {
  185.     if (refresh && *per->n.on)
  186.     V_DrawPatch(per->n.x, per->n.y, FG, per->p);
  187.     
  188.     STlib_updateNum(&per->n, refresh);
  189. }
  190.  
  191.  
  192.  
  193. void
  194. STlib_initMultIcon
  195. ( st_multicon_t*    i,
  196.   int            x,
  197.   int            y,
  198.   patch_t**        il,
  199.   int*            inum,
  200.   boolean*        on )
  201. {
  202.     i->x    = x;
  203.     i->y    = y;
  204.     i->oldinum     = -1;
  205.     i->inum    = inum;
  206.     i->on    = on;
  207.     i->p    = il;
  208. }
  209.  
  210.  
  211.  
  212. void
  213. STlib_updateMultIcon
  214. ( st_multicon_t*    mi,
  215.   boolean        refresh )
  216. {
  217.     int            w;
  218.     int            h;
  219.     int            x;
  220.     int            y;
  221.  
  222.     if (*mi->on
  223.     && (mi->oldinum != *mi->inum || refresh)
  224.     && (*mi->inum!=-1))
  225.     {
  226.     if (mi->oldinum != -1)
  227.     {
  228.         x = mi->x - SHORT(mi->p[mi->oldinum]->leftoffset);
  229.         y = mi->y - SHORT(mi->p[mi->oldinum]->topoffset);
  230.         w = SHORT(mi->p[mi->oldinum]->width);
  231.         h = SHORT(mi->p[mi->oldinum]->height);
  232.  
  233.         if (y - ST_Y < 0)
  234.         I_Error("updateMultIcon: y - ST_Y < 0");
  235.  
  236.         V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG);
  237.     }
  238.     V_DrawPatch(mi->x, mi->y, FG, mi->p[*mi->inum]);
  239.     mi->oldinum = *mi->inum;
  240.     }
  241. }
  242.  
  243.  
  244.  
  245. void
  246. STlib_initBinIcon
  247. ( st_binicon_t*        b,
  248.   int            x,
  249.   int            y,
  250.   patch_t*        i,
  251.   boolean*        val,
  252.   boolean*        on )
  253. {
  254.     b->x    = x;
  255.     b->y    = y;
  256.     b->oldval    = 0;
  257.     b->val    = val;
  258.     b->on    = on;
  259.     b->p    = i;
  260. }
  261.  
  262.  
  263.  
  264. void
  265. STlib_updateBinIcon
  266. ( st_binicon_t*        bi,
  267.   boolean        refresh )
  268. {
  269.     int            x;
  270.     int            y;
  271.     int            w;
  272.     int            h;
  273.  
  274.     if (*bi->on
  275.     && (bi->oldval != *bi->val || refresh))
  276.     {
  277.     x = bi->x - SHORT(bi->p->leftoffset);
  278.     y = bi->y - SHORT(bi->p->topoffset);
  279.     w = SHORT(bi->p->width);
  280.     h = SHORT(bi->p->height);
  281.  
  282.     if (y - ST_Y < 0)
  283.         I_Error("updateBinIcon: y - ST_Y < 0");
  284.  
  285.     if (*bi->val)
  286.         V_DrawPatch(bi->x, bi->y, FG, bi->p);
  287.     else
  288.         V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG);
  289.  
  290.     bi->oldval = *bi->val;
  291.     }
  292.  
  293. }
  294.  
  295.