Remove unneeded include from screens.c
[kugel-rb.git] / apps / plugins / doom / st_lib.c
blobadcd0e66885b9c6494b9332ad1c1bf588e2a4aa4
1 /* Emacs style mode select -*- C++ -*-
2 *-----------------------------------------------------------------------------
5 * PrBoom a Doom port merged with LxDoom and LSDLDoom
6 * based on BOOM, a modified and improved DOOM engine
7 * Copyright (C) 1999 by
8 * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
9 * Copyright (C) 1999-2000 by
10 * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 * 02111-1307, USA.
27 * DESCRIPTION:
28 * The status bar widget code.
30 *-----------------------------------------------------------------------------*/
32 #include "doomdef.h"
33 #include "doomstat.h"
34 #include "v_video.h"
35 #include "w_wad.h"
36 #include "m_swap.h"
37 #include "st_stuff.h"
38 #include "st_lib.h"
39 #include "r_main.h"
41 int sts_always_red; //jff 2/18/98 control to disable status color changes
42 int sts_pct_always_gray; // killough 2/21/98: always gray %'s? bug or feature?
45 // STlib_init()
47 void STlib_init(void)
49 // cph - no longer hold STMINUS pointer
53 // STlib_initNum()
55 // Initializes an st_number_t widget
57 // Passed the widget, its position, the patches for the digits, a pointer
58 // to the value displayed, a pointer to the on/off control, and the width
59 // Returns nothing
61 void STlib_initNum
62 ( st_number_t* n,
63 int x,
64 int y,
65 const patchnum_t* pl,
66 int* num,
67 boolean* on,
68 int width )
70 n->x = x;
71 n->y = y;
72 n->oldnum = 0;
73 n->width = width;
74 n->num = num;
75 n->on = on;
76 n->p = pl;
80 * STlib_drawNum()
82 * A fairly efficient way to draw a number based on differences from the
83 * old number.
85 * Passed a st_number_t widget, a color range for output, and a flag
86 * indicating whether refresh is needed.
87 * Returns nothing
89 * jff 2/16/98 add color translation to digit output
90 * cphipps 10/99 - const pointer to colour trans table, made function static
92 static void STlib_drawNum
93 ( st_number_t* n,
94 int cm,
95 boolean refresh )
98 int numdigits = n->width;
99 int num = *n->num;
101 int w = SHORT(n->p[0].width);
102 int h = SHORT(n->p[0].height);
103 int x = n->x;
105 int neg;
107 // leban 1/20/99:
108 // strange that somebody went through all the work to draw only the
109 // differences, and then went and constantly redrew all the numbers.
110 // return without drawing if the number didn't change and the bar
111 // isn't refreshing.
112 if(n->oldnum == num && !refresh)
113 return;
115 // CPhipps - compact some code, use num instead of *n->num
116 if ((neg = (n->oldnum = num) < 0))
118 if (numdigits == 2 && num < -9)
119 num = -9;
120 else if (numdigits == 3 && num < -99)
121 num = -99;
123 num = -num;
126 // clear the area
127 x = n->x - numdigits*w;
129 #ifdef RANGECHECK
130 if (n->y - ST_Y < 0)
131 I_Error("STlib_drawNum: n->y - ST_Y < 0");
132 #endif
134 V_CopyRect(x, n->y - ST_Y, BG, w*numdigits, h, x, n->y, FG, VPT_STRETCH);
136 // if non-number, do not draw it
137 if (num == 1994)
138 return;
140 x = n->x;
142 //jff 2/16/98 add color translation to digit output
143 // in the special case of 0, you draw 0
144 if (!num)
145 // CPhipps - patch drawing updated, reformatted
146 V_DrawNumPatch(x - w, n->y, FG, n->p[0].lumpnum, cm,
147 (((cm!=CR_DEFAULT) && !sts_always_red) ? VPT_TRANS : VPT_NONE) | VPT_STRETCH);
149 // draw the new number
150 //jff 2/16/98 add color translation to digit output
151 while (num && numdigits--) {
152 // CPhipps - patch drawing updated, reformatted
153 x -= w;
154 V_DrawNumPatch(x, n->y, FG, n->p[num % 10].lumpnum, cm,
155 (((cm!=CR_DEFAULT) && !sts_always_red) ? VPT_TRANS : VPT_NONE) | VPT_STRETCH);
156 num /= 10;
159 // draw a minus sign if necessary
160 //jff 2/16/98 add color translation to digit output
161 // cph - patch drawing updated, load by name instead of acquiring pointer earlier
162 if (neg)
163 V_DrawNamePatch(x - w, n->y, FG, "STTMINUS", cm,
164 (((cm!=CR_DEFAULT) && !sts_always_red) ? VPT_TRANS : VPT_NONE) | VPT_STRETCH);
168 * STlib_updateNum()
170 * Draws a number conditionally based on the widget's enable
172 * Passed a number widget, the output color range, and a refresh flag
173 * Returns nothing
175 * jff 2/16/98 add color translation to digit output
176 * cphipps 10/99 - make that pointer const
178 void STlib_updateNum
179 ( st_number_t* n,
180 int cm,
181 boolean refresh )
183 if (*n->on) STlib_drawNum(n, cm, refresh);
187 // STlib_initPercent()
189 // Initialize a st_percent_t number with percent sign widget
191 // Passed a st_percent_t widget, the position, the digit patches, a pointer
192 // to the number to display, a pointer to the enable flag, and patch
193 // for the percent sign.
194 // Returns nothing.
196 void STlib_initPercent
197 ( st_percent_t* p,
198 int x,
199 int y,
200 const patchnum_t* pl,
201 int* num,
202 boolean* on,
203 const patchnum_t* percent )
205 STlib_initNum(&p->n, x, y, pl, num, on, 3);
206 p->p = percent;
210 * STlib_updatePercent()
212 * Draws a number/percent conditionally based on the widget's enable
214 * Passed a precent widget, the output color range, and a refresh flag
215 * Returns nothing
217 * jff 2/16/98 add color translation to digit output
218 * cphipps - const for pointer to the colour translation table
221 void STlib_updatePercent
222 ( st_percent_t* per,
223 int cm,
224 int refresh )
226 if (*per->n.on && (refresh || (per->n.oldnum != *per->n.num))) {
227 // killough 2/21/98: fix percents not updated;
228 /* CPhipps - make %'s only be updated if number changed */
229 // CPhipps - patch drawing updated
230 V_DrawNumPatch(per->n.x, per->n.y, FG, per->p->lumpnum,
231 sts_pct_always_gray ? CR_GRAY : cm,
232 (sts_always_red ? VPT_NONE : VPT_TRANS) | VPT_STRETCH);
235 STlib_updateNum(&per->n, cm, refresh);
239 // STlib_initMultIcon()
241 // Initialize a st_multicon_t widget, used for a multigraphic display
242 // like the status bar's keys.
244 // Passed a st_multicon_t widget, the position, the graphic patches, a pointer
245 // to the numbers representing what to display, and pointer to the enable flag
246 // Returns nothing.
248 void STlib_initMultIcon
249 ( st_multicon_t* i,
250 int x,
251 int y,
252 const patchnum_t* il,
253 int* inum,
254 boolean* on )
256 i->x = x;
257 i->y = y;
258 i->oldinum = -1;
259 i->inum = inum;
260 i->on = on;
261 i->p = il;
265 // STlib_updateMultIcon()
267 // Draw a st_multicon_t widget, used for a multigraphic display
268 // like the status bar's keys. Displays each when the control
269 // numbers change or refresh is true
271 // Passed a st_multicon_t widget, and a refresh flag
272 // Returns nothing.
274 void STlib_updateMultIcon
275 ( st_multicon_t* mi,
276 boolean refresh )
278 int w;
279 int h;
280 int x;
281 int y;
283 if (*mi->on && (mi->oldinum != *mi->inum || refresh))
285 if (mi->oldinum != -1)
287 x = mi->x - SHORT(mi->p[mi->oldinum].leftoffset);
288 y = mi->y - SHORT(mi->p[mi->oldinum].topoffset);
289 w = SHORT(mi->p[mi->oldinum].width);
290 h = SHORT(mi->p[mi->oldinum].height);
292 #ifdef RANGECHECK
293 if (y - ST_Y < 0)
294 I_Error("STlib_updateMultIcon: y - ST_Y < 0");
295 #endif
297 V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG, VPT_STRETCH);
299 if (*mi->inum != -1) // killough 2/16/98: redraw only if != -1
300 V_DrawNumPatch(mi->x, mi->y, FG, mi->p[*mi->inum].lumpnum, CR_DEFAULT, VPT_STRETCH);
301 mi->oldinum = *mi->inum;
306 // STlib_initBinIcon()
308 // Initialize a st_binicon_t widget, used for a multinumber display
309 // like the status bar's weapons, that are present or not.
311 // Passed a st_binicon_t widget, the position, the digit patches, a pointer
312 // to the flags representing what is displayed, and pointer to the enable flag
313 // Returns nothing.
315 void STlib_initBinIcon
316 ( st_binicon_t* b,
317 int x,
318 int y,
319 const patchnum_t* i,
320 boolean* val,
321 boolean* on )
323 b->x = x;
324 b->y = y;
325 b->oldval = 0;
326 b->val = val;
327 b->on = on;
328 b->p = i;
332 // STlib_updateBinIcon()
334 // DInitialize a st_binicon_t widget, used for a multinumber display
335 // like the status bar's weapons, that are present or not.
337 // Draw a st_binicon_t widget, used for a multinumber display
338 // like the status bar's weapons that are present or not. Displays each
339 // when the control flag changes or refresh is true
341 // Passed a st_binicon_t widget, and a refresh flag
342 // Returns nothing.
344 void STlib_updateBinIcon
345 ( st_binicon_t* bi,
346 boolean refresh )
348 int x;
349 int y;
350 int w;
351 int h;
353 if (*bi->on && (bi->oldval != (signed)*bi->val || refresh))
355 x = bi->x - SHORT(bi->p->leftoffset);
356 y = bi->y - SHORT(bi->p->topoffset);
357 w = SHORT(bi->p->width);
358 h = SHORT(bi->p->height);
360 #ifdef RANGECHECK
361 if (y - ST_Y < 0)
362 I_Error("STlib_updateBinIcon: y - ST_Y < 0");
363 #endif
365 if (*bi->val)
366 V_DrawNumPatch(bi->x, bi->y, FG, bi->p->lumpnum, CR_DEFAULT, VPT_STRETCH);
367 else
368 V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG, VPT_STRETCH);
370 bi->oldval = *bi->val;