A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 372 lines 9.8 kB view 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 * 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. 16 * 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. 21 * 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. 26 * 27 * DESCRIPTION: 28 * The status bar widget code. 29 * 30 *-----------------------------------------------------------------------------*/ 31 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" 40 41int sts_always_red; //jff 2/18/98 control to disable status color changes 42int sts_pct_always_gray; // killough 2/21/98: always gray %'s? bug or feature? 43 44// 45// STlib_init() 46// 47void STlib_init(void) 48{ 49 // cph - no longer hold STMINUS pointer 50} 51 52// 53// STlib_initNum() 54// 55// Initializes an st_number_t widget 56// 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 60// 61void 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 ) 69{ 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; 77} 78 79/* 80 * STlib_drawNum() 81 * 82 * A fairly efficient way to draw a number based on differences from the 83 * old number. 84 * 85 * Passed a st_number_t widget, a color range for output, and a flag 86 * indicating whether refresh is needed. 87 * Returns nothing 88 * 89 * jff 2/16/98 add color translation to digit output 90 * cphipps 10/99 - const pointer to colour trans table, made function static 91 */ 92static void STlib_drawNum 93( st_number_t* n, 94 int cm, 95 boolean refresh ) 96{ 97 98 int numdigits = n->width; 99 int num = *n->num; 100 101 int w = SHORT(n->p[0].width); 102 int h = SHORT(n->p[0].height); 103 int x = n->x; 104 105 int neg; 106 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; 114 115 // CPhipps - compact some code, use num instead of *n->num 116 if ((neg = (n->oldnum = num) < 0)) 117 { 118 if (numdigits == 2 && num < -9) 119 num = -9; 120 else if (numdigits == 3 && num < -99) 121 num = -99; 122 123 num = -num; 124 } 125 126 // clear the area 127 x = n->x - numdigits*w; 128 129#ifdef RANGECHECK 130 if (n->y - ST_Y < 0) 131 I_Error("STlib_drawNum: n->y - ST_Y < 0"); 132#endif 133 134 V_CopyRect(x, n->y - ST_Y, BG, w*numdigits, h, x, n->y, FG, VPT_STRETCH); 135 136 // if non-number, do not draw it 137 if (num == 1994) 138 return; 139 140 x = n->x; 141 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); 148 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; 157 } 158 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); 165} 166 167/* 168 * STlib_updateNum() 169 * 170 * Draws a number conditionally based on the widget's enable 171 * 172 * Passed a number widget, the output color range, and a refresh flag 173 * Returns nothing 174 * 175 * jff 2/16/98 add color translation to digit output 176 * cphipps 10/99 - make that pointer const 177 */ 178void STlib_updateNum 179( st_number_t* n, 180 int cm, 181 boolean refresh ) 182{ 183 if (*n->on) STlib_drawNum(n, cm, refresh); 184} 185 186// 187// STlib_initPercent() 188// 189// Initialize a st_percent_t number with percent sign widget 190// 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. 195// 196void 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 ) 204{ 205 STlib_initNum(&p->n, x, y, pl, num, on, 3); 206 p->p = percent; 207} 208 209/* 210 * STlib_updatePercent() 211 * 212 * Draws a number/percent conditionally based on the widget's enable 213 * 214 * Passed a precent widget, the output color range, and a refresh flag 215 * Returns nothing 216 * 217 * jff 2/16/98 add color translation to digit output 218 * cphipps - const for pointer to the colour translation table 219 */ 220 221void STlib_updatePercent 222( st_percent_t* per, 223 int cm, 224 int refresh ) 225{ 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); 233 } 234 235 STlib_updateNum(&per->n, cm, refresh); 236} 237 238// 239// STlib_initMultIcon() 240// 241// Initialize a st_multicon_t widget, used for a multigraphic display 242// like the status bar's keys. 243// 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. 247// 248void STlib_initMultIcon 249( st_multicon_t* i, 250 int x, 251 int y, 252 const patchnum_t* il, 253 int* inum, 254 boolean* on ) 255{ 256 i->x = x; 257 i->y = y; 258 i->oldinum = -1; 259 i->inum = inum; 260 i->on = on; 261 i->p = il; 262} 263 264// 265// STlib_updateMultIcon() 266// 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 270// 271// Passed a st_multicon_t widget, and a refresh flag 272// Returns nothing. 273// 274void STlib_updateMultIcon 275( st_multicon_t* mi, 276 boolean refresh ) 277{ 278 int w; 279 int h; 280 int x; 281 int y; 282 283 if (*mi->on && (mi->oldinum != *mi->inum || refresh)) 284 { 285 if (mi->oldinum != -1) 286 { 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); 291 292#ifdef RANGECHECK 293 if (y - ST_Y < 0) 294 I_Error("STlib_updateMultIcon: y - ST_Y < 0"); 295#endif 296 297 V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG, VPT_STRETCH); 298 } 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; 302 } 303} 304 305// 306// STlib_initBinIcon() 307// 308// Initialize a st_binicon_t widget, used for a multinumber display 309// like the status bar's weapons, that are present or not. 310// 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. 314// 315void STlib_initBinIcon 316( st_binicon_t* b, 317 int x, 318 int y, 319 const patchnum_t* i, 320 boolean* val, 321 boolean* on ) 322{ 323 b->x = x; 324 b->y = y; 325 b->oldval = 0; 326 b->val = val; 327 b->on = on; 328 b->p = i; 329} 330 331// 332// STlib_updateBinIcon() 333// 334// DInitialize a st_binicon_t widget, used for a multinumber display 335// like the status bar's weapons, that are present or not. 336// 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 340// 341// Passed a st_binicon_t widget, and a refresh flag 342// Returns nothing. 343// 344void STlib_updateBinIcon 345( st_binicon_t* bi, 346 boolean refresh ) 347{ 348 int x; 349 int y; 350 int w; 351 int h; 352 353 if (*bi->on && (bi->oldval != (signed)*bi->val || refresh)) 354 { 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); 359 360#ifdef RANGECHECK 361 if (y - ST_Y < 0) 362 I_Error("STlib_updateBinIcon: y - ST_Y < 0"); 363#endif 364 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); 369 370 bi->oldval = *bi->val; 371 } 372}