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
28 * The status bar widget code.
30 *-----------------------------------------------------------------------------*/
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?
49 // cph - no longer hold STMINUS pointer
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
82 * A fairly efficient way to draw a number based on differences from the
85 * Passed a st_number_t widget, a color range for output, and a flag
86 * indicating whether refresh is needed.
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
98 int numdigits
= n
->width
;
101 int w
= SHORT(n
->p
[0].width
);
102 int h
= SHORT(n
->p
[0].height
);
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
112 if(n
->oldnum
== num
&& !refresh
)
115 // CPhipps - compact some code, use num instead of *n->num
116 if ((neg
= (n
->oldnum
= num
) < 0))
118 if (numdigits
== 2 && num
< -9)
120 else if (numdigits
== 3 && num
< -99)
127 x
= n
->x
- numdigits
*w
;
131 I_Error("STlib_drawNum: n->y - ST_Y < 0");
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
142 //jff 2/16/98 add color translation to digit output
143 // in the special case of 0, you draw 0
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
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
);
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
163 V_DrawNamePatch(x
- w
, n
->y
, FG
, "STTMINUS", cm
,
164 (((cm
!=CR_DEFAULT
) && !sts_always_red
) ? VPT_TRANS
: VPT_NONE
) | VPT_STRETCH
);
170 * Draws a number conditionally based on the widget's enable
172 * Passed a number widget, the output color range, and a refresh flag
175 * jff 2/16/98 add color translation to digit output
176 * cphipps 10/99 - make that pointer const
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.
196 void STlib_initPercent
200 const patchnum_t
* pl
,
203 const patchnum_t
* percent
)
205 STlib_initNum(&p
->n
, x
, y
, pl
, num
, on
, 3);
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
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
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
248 void STlib_initMultIcon
252 const patchnum_t
* 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
274 void STlib_updateMultIcon
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
);
294 I_Error("STlib_updateMultIcon: y - ST_Y < 0");
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
315 void STlib_initBinIcon
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
344 void STlib_updateBinIcon
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
);
362 I_Error("STlib_updateBinIcon: y - ST_Y < 0");
366 V_DrawNumPatch(bi
->x
, bi
->y
, FG
, bi
->p
->lumpnum
, CR_DEFAULT
, VPT_STRETCH
);
368 V_CopyRect(x
, y
-ST_Y
, BG
, w
, h
, x
, y
, FG
, VPT_STRETCH
);
370 bi
->oldval
= *bi
->val
;