st_lib.cpp (5593B)
1 /* 2 =========================================================================== 3 4 Doom 3 BFG Edition GPL Source Code 5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 6 7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). 8 9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation, either version 3 of the License, or 12 (at your option) any later version. 13 14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>. 21 22 In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below. 23 24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. 25 26 =========================================================================== 27 */ 28 29 #include "Precompiled.h" 30 #include "globaldata.h" 31 32 #include <ctype.h> 33 34 #include "doomdef.h" 35 36 #include "z_zone.h" 37 #include "v_video.h" 38 39 #include "m_swap.h" 40 41 #include "i_system.h" 42 43 #include "w_wad.h" 44 45 #include "st_stuff.h" 46 #include "st_lib.h" 47 #include "r_local.h" 48 49 50 // in AM_map.c 51 52 53 54 55 // 56 // Hack display negative frags. 57 // Loads and store the stminus lump. 58 // 59 60 void STlib_init(void) 61 { 62 ::g->sttminus = (patch_t *) W_CacheLumpName("STTMINUS", PU_STATIC_SHARED); 63 } 64 65 66 // ? 67 void 68 STlib_initNum 69 ( st_number_t* n, 70 int x, 71 int y, 72 patch_t** pl, 73 int* num, 74 qboolean* on, 75 int width ) 76 { 77 n->x = x; 78 n->y = y; 79 n->oldnum = 0; 80 n->width = width; 81 n->num = num; 82 n->on = on; 83 n->p = pl; 84 } 85 86 87 // 88 // A fairly efficient way to draw a number 89 // based on differences from the old number. 90 // Note: worth the trouble? 91 // 92 void 93 STlib_drawNum 94 ( st_number_t* n, 95 qboolean 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 n->oldnum = *n->num; 108 109 neg = num < 0; 110 111 if (neg) 112 { 113 if (numdigits == 2 && num < -9) 114 num = -9; 115 else if (numdigits == 3 && num < -99) 116 num = -99; 117 118 num = -num; 119 } 120 121 // clear the area 122 x = n->x - numdigits*w; 123 124 if (n->y - ST_Y < 0) 125 I_Error("drawNum: n->y - ST_Y < 0"); 126 127 V_CopyRect(x, n->y - ST_Y, BG, w*numdigits, h, x, n->y, FG); 128 129 // if non-number, do not draw it 130 if (num == 1994) 131 return; 132 133 x = n->x; 134 135 // in the special case of 0, you draw 0 136 if (!num) 137 V_DrawPatch(x - w, n->y, FG, n->p[ 0 ]); 138 139 // draw the new number 140 while (num && numdigits--) 141 { 142 x -= w; 143 V_DrawPatch(x, n->y, FG, n->p[ num % 10 ]); 144 num /= 10; 145 } 146 147 // draw a minus sign if necessary 148 if (neg) 149 V_DrawPatch(x - 8, n->y, FG, ::g->sttminus); 150 } 151 152 153 // 154 void 155 STlib_updateNum 156 ( st_number_t* n, 157 qboolean refresh ) 158 { 159 if (*n->on) STlib_drawNum(n, refresh); 160 } 161 162 163 // 164 void 165 STlib_initPercent 166 ( st_percent_t* p, 167 int x, 168 int y, 169 patch_t** pl, 170 int* num, 171 qboolean* on, 172 patch_t* percent ) 173 { 174 STlib_initNum(&p->n, x, y, pl, num, on, 3); 175 p->p = percent; 176 } 177 178 179 180 181 void 182 STlib_updatePercent 183 ( st_percent_t* per, 184 int refresh ) 185 { 186 if (refresh && *per->n.on) 187 V_DrawPatch(per->n.x, per->n.y, FG, per->p); 188 189 STlib_updateNum(&per->n, refresh); 190 } 191 192 193 194 void 195 STlib_initMultIcon 196 ( st_multicon_t* i, 197 int x, 198 int y, 199 patch_t** il, 200 int* inum, 201 qboolean* on ) 202 { 203 i->x = x; 204 i->y = y; 205 i->oldinum = -1; 206 i->inum = inum; 207 i->on = on; 208 i->p = il; 209 } 210 211 212 213 void 214 STlib_updateMultIcon 215 ( st_multicon_t* mi, 216 qboolean refresh ) 217 { 218 int w; 219 int h; 220 int x; 221 int y; 222 223 if (*mi->on 224 && (mi->oldinum != *mi->inum || refresh) 225 && (*mi->inum!=-1)) 226 { 227 if (mi->oldinum != -1) 228 { 229 x = mi->x - SHORT(mi->p[mi->oldinum]->leftoffset); 230 y = mi->y - SHORT(mi->p[mi->oldinum]->topoffset); 231 w = SHORT(mi->p[mi->oldinum]->width); 232 h = SHORT(mi->p[mi->oldinum]->height); 233 234 if (y - ST_Y < 0) 235 I_Error("updateMultIcon: y - ST_Y < 0"); 236 237 V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG); 238 } 239 V_DrawPatch(mi->x, mi->y, FG, mi->p[*mi->inum]); 240 mi->oldinum = *mi->inum; 241 } 242 } 243 244 245 246 void 247 STlib_initBinIcon 248 ( st_binicon_t* b, 249 int x, 250 int y, 251 patch_t* i, 252 qboolean* val, 253 qboolean* on ) 254 { 255 b->x = x; 256 b->y = y; 257 b->oldval = 0; 258 b->val = val; 259 b->on = on; 260 b->p = i; 261 } 262 263 264 265 void 266 STlib_updateBinIcon 267 ( st_binicon_t* bi, 268 qboolean refresh ) 269 { 270 int x; 271 int y; 272 int w; 273 int h; 274 275 if (*bi->on 276 && (bi->oldval != *bi->val || refresh)) 277 { 278 x = bi->x - SHORT(bi->p->leftoffset); 279 y = bi->y - SHORT(bi->p->topoffset); 280 w = SHORT(bi->p->width); 281 h = SHORT(bi->p->height); 282 283 if (y - ST_Y < 0) 284 I_Error("updateBinIcon: y - ST_Y < 0"); 285 286 if (*bi->val) 287 V_DrawPatch(bi->x, bi->y, FG, bi->p); 288 else 289 V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG); 290 291 bi->oldval = *bi->val; 292 } 293 294 } 295 296