doom

a minimalistic implementation of doom
git clone git://ssnf.xyz/doom
Log | Files | Refs

st_lib.c (3620B)


      1 #include <ctype.h>
      2 
      3 #include "doomdef.h"
      4 
      5 #include "z_zone.h"
      6 #include "v_video.h"
      7 #include "m_swap.h"
      8 
      9 #include "i_system.h"
     10 
     11 #include "w_wad.h"
     12 
     13 #include "st_stuff.h"
     14 #include "st_lib.h"
     15 #include "r_local.h"
     16 
     17 
     18 
     19 extern boolean		automapactive; 
     20 
     21 
     22 
     23 
     24 
     25 
     26 
     27 
     28 patch_t*		sttminus;
     29 
     30 void STlib_init(void)
     31 {
     32     sttminus = (patch_t *) W_CacheLumpName("STTMINUS", PU_STATIC);
     33 }
     34 
     35 
     36 
     37 void
     38 STlib_initNum
     39 ( st_number_t*		n,
     40   int			x,
     41   int			y,
     42   patch_t**		pl,
     43   int*			num,
     44   boolean*		on,
     45   int			width )
     46 {
     47     n->x	= x;
     48     n->y	= y;
     49     n->oldnum	= 0;
     50     n->width	= width;
     51     n->num	= num;
     52     n->on	= on;
     53     n->p	= pl;
     54 }
     55 
     56 
     57 
     58 
     59 
     60 
     61 
     62 void
     63 STlib_drawNum
     64 ( st_number_t*	n,
     65   boolean	refresh )
     66 {
     67 
     68     int		numdigits = n->width;
     69     int		num = *n->num;
     70     
     71     int		w = SHORT(n->p[0]->width);
     72     int		h = SHORT(n->p[0]->height);
     73     int		x = n->x;
     74     
     75     int		neg;
     76 
     77     n->oldnum = *n->num;
     78 
     79     neg = num < 0;
     80 
     81     if (neg)
     82     {
     83 	if (numdigits == 2 && num < -9)
     84 	    num = -9;
     85 	else if (numdigits == 3 && num < -99)
     86 	    num = -99;
     87 	
     88 	num = -num;
     89     }
     90 
     91     
     92     x = n->x - numdigits*w;
     93 
     94     if (n->y - ST_Y < 0)
     95 	I_Error("drawNum: n->y - ST_Y < 0");
     96 
     97     V_CopyRect(x, n->y - ST_Y, BG, w*numdigits, h, x, n->y, FG);
     98 
     99     
    100     if (num == 1994)
    101 	return;
    102 
    103     x = n->x;
    104 
    105     
    106     if (!num)
    107 	V_DrawPatch(x - w, n->y, FG, n->p[ 0 ]);
    108 
    109     
    110     while (num && numdigits--)
    111     {
    112 	x -= w;
    113 	V_DrawPatch(x, n->y, FG, n->p[ num % 10 ]);
    114 	num /= 10;
    115     }
    116 
    117     
    118     if (neg)
    119 	V_DrawPatch(x - 8, n->y, FG, sttminus);
    120 }
    121 
    122 
    123 
    124 void
    125 STlib_updateNum
    126 ( st_number_t*		n,
    127   boolean		refresh )
    128 {
    129     if (*n->on) STlib_drawNum(n, refresh);
    130 }
    131 
    132 
    133 
    134 void
    135 STlib_initPercent
    136 ( st_percent_t*		p,
    137   int			x,
    138   int			y,
    139   patch_t**		pl,
    140   int*			num,
    141   boolean*		on,
    142   patch_t*		percent )
    143 {
    144     STlib_initNum(&p->n, x, y, pl, num, on, 3);
    145     p->p = percent;
    146 }
    147 
    148 
    149 
    150 
    151 void
    152 STlib_updatePercent
    153 ( st_percent_t*		per,
    154   int			refresh )
    155 {
    156     if (refresh && *per->n.on)
    157 	V_DrawPatch(per->n.x, per->n.y, FG, per->p);
    158     
    159     STlib_updateNum(&per->n, refresh);
    160 }
    161 
    162 
    163 
    164 void
    165 STlib_initMultIcon
    166 ( st_multicon_t*	i,
    167   int			x,
    168   int			y,
    169   patch_t**		il,
    170   int*			inum,
    171   boolean*		on )
    172 {
    173     i->x	= x;
    174     i->y	= y;
    175     i->oldinum 	= -1;
    176     i->inum	= inum;
    177     i->on	= on;
    178     i->p	= il;
    179 }
    180 
    181 
    182 
    183 void
    184 STlib_updateMultIcon
    185 ( st_multicon_t*	mi,
    186   boolean		refresh )
    187 {
    188     int			w;
    189     int			h;
    190     int			x;
    191     int			y;
    192 
    193     if (*mi->on
    194 	&& (mi->oldinum != *mi->inum || refresh)
    195 	&& (*mi->inum!=-1))
    196     {
    197 	if (mi->oldinum != -1)
    198 	{
    199 	    x = mi->x - SHORT(mi->p[mi->oldinum]->leftoffset);
    200 	    y = mi->y - SHORT(mi->p[mi->oldinum]->topoffset);
    201 	    w = SHORT(mi->p[mi->oldinum]->width);
    202 	    h = SHORT(mi->p[mi->oldinum]->height);
    203 
    204 	    if (y - ST_Y < 0)
    205 		I_Error("updateMultIcon: y - ST_Y < 0");
    206 
    207 	    V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG);
    208 	}
    209 	V_DrawPatch(mi->x, mi->y, FG, mi->p[*mi->inum]);
    210 	mi->oldinum = *mi->inum;
    211     }
    212 }
    213 
    214 
    215 
    216 void
    217 STlib_initBinIcon
    218 ( st_binicon_t*		b,
    219   int			x,
    220   int			y,
    221   patch_t*		i,
    222   boolean*		val,
    223   boolean*		on )
    224 {
    225     b->x	= x;
    226     b->y	= y;
    227     b->oldval	= 0;
    228     b->val	= val;
    229     b->on	= on;
    230     b->p	= i;
    231 }
    232 
    233 
    234 
    235 void
    236 STlib_updateBinIcon
    237 ( st_binicon_t*		bi,
    238   boolean		refresh )
    239 {
    240     int			x;
    241     int			y;
    242     int			w;
    243     int			h;
    244 
    245     if (*bi->on
    246 	&& (bi->oldval != *bi->val || refresh))
    247     {
    248 	x = bi->x - SHORT(bi->p->leftoffset);
    249 	y = bi->y - SHORT(bi->p->topoffset);
    250 	w = SHORT(bi->p->width);
    251 	h = SHORT(bi->p->height);
    252 
    253 	if (y - ST_Y < 0)
    254 	    I_Error("updateBinIcon: y - ST_Y < 0");
    255 
    256 	if (*bi->val)
    257 	    V_DrawPatch(bi->x, bi->y, FG, bi->p);
    258 	else
    259 	    V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG);
    260 
    261 	bi->oldval = *bi->val;
    262     }
    263 
    264 }
    265