hu_lib.c (4585B)
1 #include <ctype.h> 2 3 #include "doomdef.h" 4 5 #include "v_video.h" 6 #include "hu_lib.h" 7 #include "r_local.h" 8 #include "r_draw.h" 9 10 11 #define noterased viewwindowx 12 13 extern boolean automapactive; 14 15 void HUlib_init(void) 16 { 17 } 18 19 void HUlib_clearTextLine(hu_textline_t* t) 20 { 21 t->len = 0; 22 t->l[0] = 0; 23 t->needsupdate = true; 24 } 25 26 void 27 HUlib_initTextLine 28 ( hu_textline_t* t, 29 int x, 30 int y, 31 patch_t** f, 32 int sc ) 33 { 34 t->x = x; 35 t->y = y; 36 t->f = f; 37 t->sc = sc; 38 HUlib_clearTextLine(t); 39 } 40 41 boolean 42 HUlib_addCharToTextLine 43 ( hu_textline_t* t, 44 char ch ) 45 { 46 47 if (t->len == HU_MAXLINELENGTH) 48 return false; 49 else 50 { 51 t->l[t->len++] = ch; 52 t->l[t->len] = 0; 53 t->needsupdate = 4; 54 return true; 55 } 56 57 } 58 59 boolean HUlib_delCharFromTextLine(hu_textline_t* t) 60 { 61 62 if (!t->len) return false; 63 else 64 { 65 t->l[--t->len] = 0; 66 t->needsupdate = 4; 67 return true; 68 } 69 70 } 71 72 void 73 HUlib_drawTextLine 74 ( hu_textline_t* l, 75 boolean drawcursor ) 76 { 77 78 int i; 79 int w; 80 int x; 81 unsigned char c; 82 83 84 x = l->x; 85 for (i=0;i<l->len;i++) 86 { 87 c = toupper(l->l[i]); 88 if (c != ' ' 89 && c >= l->sc 90 && c <= '_') 91 { 92 w = l->f[c - l->sc]->width; 93 if (x+w > SCREENWIDTH) 94 break; 95 V_DrawPatch(x, l->y, FG, l->f[c - l->sc]); 96 x += w; 97 } 98 else 99 { 100 x += 4; 101 if (x >= SCREENWIDTH) 102 break; 103 } 104 } 105 106 107 if (drawcursor 108 && x + l->f['_' - l->sc]->width <= SCREENWIDTH) 109 { 110 V_DrawPatch(x, l->y, FG, l->f['_' - l->sc]); 111 } 112 } 113 114 115 116 void HUlib_eraseTextLine(hu_textline_t* l) 117 { 118 int lh; 119 int y; 120 int yoffset; 121 122 123 124 125 126 if (!automapactive && 127 viewwindowx && l->needsupdate) 128 { 129 lh = l->f[0]->height + 1; 130 for (y=l->y,yoffset=y*SCREENWIDTH ; y<l->y+lh ; y++,yoffset+=SCREENWIDTH) 131 { 132 if (y < viewwindowy || y >= viewwindowy + viewheight) 133 R_VideoErase(yoffset, SCREENWIDTH); 134 else 135 { 136 R_VideoErase(yoffset, viewwindowx); 137 R_VideoErase(yoffset + viewwindowx + viewwidth, viewwindowx); 138 139 } 140 } 141 } 142 143 if (l->needsupdate) l->needsupdate--; 144 145 } 146 147 void 148 HUlib_initSText 149 ( hu_stext_t* s, 150 int x, 151 int y, 152 int h, 153 patch_t** font, 154 int startchar, 155 boolean* on ) 156 { 157 158 int i; 159 160 s->h = h; 161 s->on = on; 162 s->laston = true; 163 s->cl = 0; 164 for (i=0;i<h;i++) 165 HUlib_initTextLine(&s->l[i], x, y - i*(font[0]->height+1), font, startchar); 166 167 } 168 169 void HUlib_addLineToSText(hu_stext_t* s) 170 { 171 172 int i; 173 174 175 if (++s->cl == s->h) 176 s->cl = 0; 177 HUlib_clearTextLine(&s->l[s->cl]); 178 179 180 for (i=0 ; i<s->h ; i++) 181 s->l[i].needsupdate = 4; 182 183 } 184 185 void 186 HUlib_addMessageToSText 187 ( hu_stext_t* s, 188 char* prefix, 189 char* msg ) 190 { 191 HUlib_addLineToSText(s); 192 if (prefix) 193 while (*prefix) 194 HUlib_addCharToTextLine(&s->l[s->cl], *(prefix++)); 195 196 while (*msg) 197 HUlib_addCharToTextLine(&s->l[s->cl], *(msg++)); 198 } 199 200 void HUlib_drawSText(hu_stext_t* s) 201 { 202 int i, idx; 203 hu_textline_t *l; 204 205 if (!*s->on) 206 return; 207 208 209 for (i=0 ; i<s->h ; i++) 210 { 211 idx = s->cl - i; 212 if (idx < 0) 213 idx += s->h; 214 215 l = &s->l[idx]; 216 217 218 HUlib_drawTextLine(l, false); 219 } 220 221 } 222 223 void HUlib_eraseSText(hu_stext_t* s) 224 { 225 226 int i; 227 228 for (i=0 ; i<s->h ; i++) 229 { 230 if (s->laston && !*s->on) 231 s->l[i].needsupdate = 4; 232 HUlib_eraseTextLine(&s->l[i]); 233 } 234 s->laston = *s->on; 235 236 } 237 238 void 239 HUlib_initIText(hu_itext_t* it, int x, int y, patch_t** font, int startchar, boolean* on) 240 { 241 it->lm = 0; 242 it->on = on; 243 it->laston = true; 244 HUlib_initTextLine(&it->l, x, y, font, startchar); 245 } 246 247 248 249 void HUlib_delCharFromIText(hu_itext_t* it) 250 { 251 if (it->l.len != it->lm) 252 HUlib_delCharFromTextLine(&it->l); 253 } 254 255 void HUlib_eraseLineFromIText(hu_itext_t* it) 256 { 257 while (it->lm != it->l.len) 258 HUlib_delCharFromTextLine(&it->l); 259 } 260 261 262 void HUlib_resetIText(hu_itext_t* it) 263 { 264 it->lm = 0; 265 HUlib_clearTextLine(&it->l); 266 } 267 268 void 269 HUlib_addPrefixToIText 270 ( hu_itext_t* it, 271 char* str ) 272 { 273 while (*str) 274 HUlib_addCharToTextLine(&it->l, *(str++)); 275 it->lm = it->l.len; 276 } 277 278 279 280 boolean 281 HUlib_keyInIText 282 ( hu_itext_t* it, 283 unsigned char ch ) 284 { 285 286 if (ch >= ' ' && ch <= '_') 287 HUlib_addCharToTextLine(&it->l, (char) ch); 288 else 289 if (ch == KEY_BACKSPACE) 290 HUlib_delCharFromIText(it); 291 else 292 if (ch != KEY_ENTER) 293 return false; 294 295 return true; 296 297 } 298 299 void HUlib_drawIText(hu_itext_t* it) 300 { 301 302 hu_textline_t *l = &it->l; 303 304 if (!*it->on) 305 return; 306 HUlib_drawTextLine(l, true); 307 308 } 309 310 void HUlib_eraseIText(hu_itext_t* it) 311 { 312 if (it->laston && !*it->on) 313 it->l.needsupdate = 4; 314 HUlib_eraseTextLine(&it->l); 315 it->laston = *it->on; 316 } 317