Debian Codegraph @

prboom2/src/st_lib.c

raw
1 /* Emacs style mode select -*- C -*-
2 *-----------------------------------------------------------------------------
3 *
4 *
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
11 * Copyright 2005, 2006 by
12 * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 * 02111-1307, USA.
28 *
29 * DESCRIPTION:
30 * The status bar widget code.
31 *
32 *-----------------------------------------------------------------------------*/
33
34 #include "doomdef.h"
35 #include "doomstat.h"
36 #include "v_video.h"
37 #include "w_wad.h"
38 #include "st_stuff.h"
39 #include "st_lib.h"
40 #include "r_main.h"
41 #include "lprintf.h"
42
43 int sts_colored_numbers; //jff 2/18/98 control to enable status color changes
44 int sts_pct_always_gray; // killough 2/21/98: always gray %'s? bug or feature?
45
46 //
47 // STlib_init()
48 //
49 void STlib_init(void)
50 {
51 // cph - no longer hold STMINUS pointer
52 }
53
54 //
55 // STlib_initNum()
56 //
57 // Initializes an st_number_t widget
58 //
59 // Passed the widget, its position, the patches for the digits, a pointer
60 // to the value displayed, a pointer to the on/off control, and the width
61 // Returns nothing
62 //
63 void STlib_initNum
64 ( st_number_t* n,
65 int x,
66 int y,
67 const patchnum_t* pl,
68 int* num,
69 dboolean* on,
70 int width )
71 {
72 n->x = x;
73 n->y = y;
74 n->oldnum = 0;
75 n->width = width;
76 n->num = num;
77 n->on = on;
78 n->p = pl;
79 }
80
81 /*
82 * STlib_drawNum()
83 *
84 * A fairly efficient way to draw a number based on differences from the
85 * old number.
86 *
87 * Passed a st_number_t widget, a color range for output, and a flag
88 * indicating whether refresh is needed.
89 * Returns nothing
90 *
91 * jff 2/16/98 add color translation to digit output
92 * cphipps 10/99 - const pointer to colour trans table, made function static
93 */
94 static void STlib_drawNum
95 ( st_number_t* n,
96 int cm,
97 dboolean refresh )
98 {
99
100 int numdigits = n->width;
101 int num = *n->num;
102
103 int w = n->p[0].width;
104 int h = n->p[0].height;
105 int x = n->x;
106 int clear_x, clear_y;
107
108 int neg;
109
110 // leban 1/20/99:
111 // strange that somebody went through all the work to draw only the
112 // differences, and then went and constantly redrew all the numbers.
113 // return without drawing if the number didn't change and the bar
114 // isn't refreshing.
115 if(n->oldnum == num && !refresh)
116 return;
117
118 // CPhipps - compact some code, use num instead of *n->num
119 if ((neg = (n->oldnum = num) < 0))
120 {
121 if (numdigits == 2 && num < -9)
122 num = -9;
123 else if (numdigits == 3 && num < -99)
124 num = -99;
125
126 num = -num;
127 }
128
129 // clear the area
130 clear_x = n->x - LittleShort(n->p[0].leftoffset) - numdigits * w;
131 clear_y = n->y - LittleShort(n->p[0].topoffset);
132
133 V_CopyRect(BG, FG, clear_x, clear_y, w * numdigits, h, VPT_STRETCH | VPT_ALIGN_BOTTOM);
134
135 // if non-number, do not draw it
136 if (num == 1994)
137 return;
138
139 //jff 2/16/98 add color translation to digit output
140 // in the special case of 0, you draw 0
141 if (!num)
142 // CPhipps - patch drawing updated, reformatted
143 V_DrawNumPatch(x - w, n->y, FG, n->p[0].lumpnum, cm,
144 (((cm!=CR_DEFAULT) && sts_colored_numbers) ? VPT_TRANS : VPT_NONE) | VPT_ALIGN_BOTTOM);
145
146 // draw the new number
147 //jff 2/16/98 add color translation to digit output
148 while (num && numdigits--) {
149 // CPhipps - patch drawing updated, reformatted
150 x -= w;
151 V_DrawNumPatch(x, n->y, FG, n->p[num % 10].lumpnum, cm,
152 (((cm!=CR_DEFAULT) && sts_colored_numbers) ? VPT_TRANS : VPT_NONE) | VPT_ALIGN_BOTTOM);
153 num /= 10;
154 }
155
156 // draw a minus sign if necessary
157 //jff 2/16/98 add color translation to digit output
158 // cph - patch drawing updated, load by name instead of acquiring pointer earlier
159 if (neg)
160 V_DrawNamePatch(x - w, n->y, FG, "STTMINUS", cm,
161 (((cm!=CR_DEFAULT) && sts_colored_numbers) ? VPT_TRANS : VPT_NONE) | VPT_ALIGN_BOTTOM);
162 }
163
164 /*
165 * STlib_updateNum()
166 *
167 * Draws a number conditionally based on the widget's enable
168 *
169 * Passed a number widget, the output color range, and a refresh flag
170 * Returns nothing
171 *
172 * jff 2/16/98 add color translation to digit output
173 * cphipps 10/99 - make that pointer const
174 */
175 void STlib_updateNum
176 ( st_number_t* n,
177 int cm,
178 dboolean refresh )
179 {
180 if (*n->on) STlib_drawNum(n, cm, refresh);
181 }
182
183 //
184 // STlib_initPercent()
185 //
186 // Initialize a st_percent_t number with percent sign widget
187 //
188 // Passed a st_percent_t widget, the position, the digit patches, a pointer
189 // to the number to display, a pointer to the enable flag, and patch
190 // for the percent sign.
191 // Returns nothing.
192 //
193 void STlib_initPercent
194 ( st_percent_t* p,
195 int x,
196 int y,
197 const patchnum_t* pl,
198 int* num,
199 dboolean* on,
200 const patchnum_t* percent )
201 {
202 STlib_initNum(&p->n, x, y, pl, num, on, 3);
203 p->p = percent;
204 }
205
206 /*
207 * STlib_updatePercent()
208 *
209 * Draws a number/percent conditionally based on the widget's enable
210 *
211 * Passed a precent widget, the output color range, and a refresh flag
212 * Returns nothing
213 *
214 * jff 2/16/98 add color translation to digit output
215 * cphipps - const for pointer to the colour translation table
216 */
217
218 void STlib_updatePercent
219 ( st_percent_t* per,
220 int cm,
221 int refresh )
222 {
223 if (*per->n.on && (refresh || (per->n.oldnum != *per->n.num))) {
224 // killough 2/21/98: fix percents not updated;
225 /* CPhipps - make %'s only be updated if number changed */
226 // CPhipps - patch drawing updated
227 V_DrawNumPatch(per->n.x, per->n.y, FG, per->p->lumpnum,
228 sts_pct_always_gray ? CR_GRAY : cm,
229 (sts_colored_numbers || sts_pct_always_gray ? VPT_TRANS : VPT_NONE) | VPT_ALIGN_BOTTOM);
230 }
231
232 STlib_updateNum(&per->n, cm, refresh);
233 }
234
235 //
236 // STlib_initMultIcon()
237 //
238 // Initialize a st_multicon_t widget, used for a multigraphic display
239 // like the status bar's keys.
240 //
241 // Passed a st_multicon_t widget, the position, the graphic patches, a pointer
242 // to the numbers representing what to display, and pointer to the enable flag
243 // Returns nothing.
244 //
245 void STlib_initMultIcon
246 ( st_multicon_t* i,
247 int x,
248 int y,
249 const patchnum_t* il,
250 int* inum,
251 dboolean* on )
252 {
253 i->x = x;
254 i->y = y;
255 i->oldinum = -1;
256 i->inum = inum;
257 i->on = on;
258 i->p = il;
259 }
260
261 //
262 // STlib_updateMultIcon()
263 //
264 // Draw a st_multicon_t widget, used for a multigraphic display
265 // like the status bar's keys. Displays each when the control
266 // numbers change or refresh is true
267 //
268 // Passed a st_multicon_t widget, and a refresh flag
269 // Returns nothing.
270 //
271 void STlib_updateMultIcon
272 ( st_multicon_t* mi,
273 dboolean refresh )
274 {
275 int w;
276 int h;
277 int x;
278 int y;
279
280 if (*mi->on && (mi->oldinum != *mi->inum || refresh))
281 {
282 if (mi->oldinum != -1)
283 {
284 x = mi->x - mi->p[mi->oldinum].leftoffset;
285 y = mi->y - mi->p[mi->oldinum].topoffset;
286 w = mi->p[mi->oldinum].width;
287 h = mi->p[mi->oldinum].height;
288
289 #ifdef RANGECHECK
290 if (y - ST_Y < 0)
291 I_Error("STlib_updateMultIcon: y - ST_Y < 0");
292 #endif
293
294 V_CopyRect(BG, FG, x, y, w, h, VPT_STRETCH | VPT_ALIGN_BOTTOM);
295 }
296 if (*mi->inum != -1) // killough 2/16/98: redraw only if != -1
297 V_DrawNumPatch(mi->x, mi->y, FG, mi->p[*mi->inum].lumpnum, CR_DEFAULT, VPT_ALIGN_BOTTOM);
298 mi->oldinum = *mi->inum;
299 }
300 }