Add weapon cycling bindings for mouse and joystick buttons. Add weapon cycling bindi...
[chocolate-doom.git] / src / st_lib.c
blob11299a91976d083fa7ebcf12fb9081dbe099ff5b
1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
3 //
4 // Copyright(C) 1993-1996 Id Software, Inc.
5 // Copyright(C) 2005 Simon Howard
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 // 02111-1307, USA.
22 // DESCRIPTION:
23 // The status bar widget code.
25 //-----------------------------------------------------------------------------
29 #include <ctype.h>
31 #include "deh_main.h"
32 #include "doomdef.h"
34 #include "z_zone.h"
35 #include "v_video.h"
37 #include "i_swap.h"
38 #include "i_system.h"
40 #include "w_wad.h"
42 #include "st_stuff.h"
43 #include "st_lib.h"
44 #include "r_local.h"
47 // in AM_map.c
48 extern boolean automapactive;
54 // Hack display negative frags.
55 // Loads and store the stminus lump.
57 patch_t* sttminus;
59 void STlib_init(void)
61 sttminus = (patch_t *) W_CacheLumpName(DEH_String("STTMINUS"), PU_STATIC);
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 )
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;
86 //
87 // A fairly efficient way to draw a number
88 // based on differences from the old number.
89 // Note: worth the trouble?
91 void
92 STlib_drawNum
93 ( st_number_t* n,
94 boolean refresh )
97 int numdigits = n->width;
98 int num = *n->num;
100 int w = SHORT(n->p[0]->width);
101 int h = SHORT(n->p[0]->height);
102 int x = n->x;
104 int neg;
106 n->oldnum = *n->num;
108 neg = num < 0;
110 if (neg)
112 if (numdigits == 2 && num < -9)
113 num = -9;
114 else if (numdigits == 3 && num < -99)
115 num = -99;
117 num = -num;
120 // clear the area
121 x = n->x - numdigits*w;
123 if (n->y - ST_Y < 0)
124 I_Error("drawNum: n->y - ST_Y < 0");
126 V_CopyRect(x, n->y - ST_Y, BG, w*numdigits, h, x, n->y, FG);
128 // if non-number, do not draw it
129 if (num == 1994)
130 return;
132 x = n->x;
134 // in the special case of 0, you draw 0
135 if (!num)
136 V_DrawPatch(x - w, n->y, FG, n->p[ 0 ]);
138 // draw the new number
139 while (num && numdigits--)
141 x -= w;
142 V_DrawPatch(x, n->y, FG, n->p[ num % 10 ]);
143 num /= 10;
146 // draw a minus sign if necessary
147 if (neg)
148 V_DrawPatch(x - 8, n->y, FG, sttminus);
153 void
154 STlib_updateNum
155 ( st_number_t* n,
156 boolean refresh )
158 if (*n->on) STlib_drawNum(n, refresh);
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 )
173 STlib_initNum(&p->n, x, y, pl, num, on, 3);
174 p->p = percent;
180 void
181 STlib_updatePercent
182 ( st_percent_t* per,
183 int refresh )
185 if (refresh && *per->n.on)
186 V_DrawPatch(per->n.x, per->n.y, FG, per->p);
188 STlib_updateNum(&per->n, refresh);
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 )
202 i->x = x;
203 i->y = y;
204 i->oldinum = -1;
205 i->inum = inum;
206 i->on = on;
207 i->p = il;
212 void
213 STlib_updateMultIcon
214 ( st_multicon_t* mi,
215 boolean refresh )
217 int w;
218 int h;
219 int x;
220 int y;
222 if (*mi->on
223 && (mi->oldinum != *mi->inum || refresh)
224 && (*mi->inum!=-1))
226 if (mi->oldinum != -1)
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);
233 if (y - ST_Y < 0)
234 I_Error("updateMultIcon: y - ST_Y < 0");
236 V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG);
238 V_DrawPatch(mi->x, mi->y, FG, mi->p[*mi->inum]);
239 mi->oldinum = *mi->inum;
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 )
254 b->x = x;
255 b->y = y;
256 b->oldval = false;
257 b->val = val;
258 b->on = on;
259 b->p = i;
264 void
265 STlib_updateBinIcon
266 ( st_binicon_t* bi,
267 boolean refresh )
269 int x;
270 int y;
271 int w;
272 int h;
274 if (*bi->on
275 && (bi->oldval != *bi->val || refresh))
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);
282 if (y - ST_Y < 0)
283 I_Error("updateBinIcon: y - ST_Y < 0");
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);
290 bi->oldval = *bi->val;