1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
6 // Copyright (C) 1993-1996 by id Software, Inc.
8 // This source is available for distribution and/or modification
9 // only under the terms of the DOOM Source Code License as
10 // published by id Software. All rights reserved.
12 // The source is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
19 // DESCRIPTION: heads-up text and input code
21 //-----------------------------------------------------------------------------
24 rcsid[] = "$Id: hu_lib.c,v 1.3 1997/01/26 07:44:58 b1 Exp $";
37 // boolean : whether the screen is always erased
38 #define noterased viewwindowx
40 extern boolean automapactive; // in AM_map.c
46 void HUlib_clearTextLine(hu_textline_t* t)
50 t->needsupdate = true;
65 HUlib_clearTextLine(t);
69 HUlib_addCharToTextLine
74 if (t->len == HU_MAXLINELENGTH)
86 boolean HUlib_delCharFromTextLine(hu_textline_t* t)
89 if (!t->len) return false;
110 // draw the new stuff
112 for (i=0;i<l->len;i++)
114 c = toupper(l->l[i]);
119 w = SHORT(l->f[c - l->sc]->width);
120 if (x+w > SCREENWIDTH)
122 V_DrawPatchDirect(x, l->y, FG, l->f[c - l->sc]);
128 if (x >= SCREENWIDTH)
133 // draw the cursor if requested
135 && x + SHORT(l->f['_' - l->sc]->width) <= SCREENWIDTH)
137 V_DrawPatchDirect(x, l->y, FG, l->f['_' - l->sc]);
142 // sorta called by HU_Erase and just better darn get things straight
143 void HUlib_eraseTextLine(hu_textline_t* l)
148 static boolean lastautomapactive = true;
150 // Only erases when NOT in automap and the screen is reduced,
151 // and the text must either need updating or refreshing
152 // (because of a recent change back from the automap)
154 if (!automapactive &&
155 viewwindowx && l->needsupdate)
157 lh = SHORT(l->f[0]->height) + 1;
158 for (y=l->y,yoffset=y*SCREENWIDTH ; y<l->y+lh ; y++,yoffset+=SCREENWIDTH)
160 if (y < viewwindowy || y >= viewwindowy + viewheight)
161 R_VideoErase(yoffset, SCREENWIDTH); // erase entire line
164 R_VideoErase(yoffset, viewwindowx); // erase left border
165 R_VideoErase(yoffset + viewwindowx + viewwidth, viewwindowx);
166 // erase right border
171 lastautomapactive = automapactive;
172 if (l->needsupdate) l->needsupdate--;
194 HUlib_initTextLine(&s->l[i],
195 x, y - i*(SHORT(font[0]->height)+1),
200 void HUlib_addLineToSText(hu_stext_t* s)
208 HUlib_clearTextLine(&s->l[s->cl]);
210 // everything needs updating
211 for (i=0 ; i<s->h ; i++)
212 s->l[i].needsupdate = 4;
217 HUlib_addMessageToSText
222 HUlib_addLineToSText(s);
225 HUlib_addCharToTextLine(&s->l[s->cl], *(prefix++));
228 HUlib_addCharToTextLine(&s->l[s->cl], *(msg++));
231 void HUlib_drawSText(hu_stext_t* s)
237 return; // if not on, don't draw
240 for (i=0 ; i<s->h ; i++)
244 idx += s->h; // handle queue of lines
248 // need a decision made here on whether to skip the draw
249 HUlib_drawTextLine(l, false); // no cursor, please
254 void HUlib_eraseSText(hu_stext_t* s)
259 for (i=0 ; i<s->h ; i++)
261 if (s->laston && !*s->on)
262 s->l[i].needsupdate = 4;
263 HUlib_eraseTextLine(&s->l[i]);
278 it->lm = 0; // default left margin is start of text
281 HUlib_initTextLine(&it->l, x, y, font, startchar);
285 // The following deletion routines adhere to the left margin restriction
286 void HUlib_delCharFromIText(hu_itext_t* it)
288 if (it->l.len != it->lm)
289 HUlib_delCharFromTextLine(&it->l);
292 void HUlib_eraseLineFromIText(hu_itext_t* it)
294 while (it->lm != it->l.len)
295 HUlib_delCharFromTextLine(&it->l);
298 // Resets left margin as well
299 void HUlib_resetIText(hu_itext_t* it)
302 HUlib_clearTextLine(&it->l);
306 HUlib_addPrefixToIText
311 HUlib_addCharToTextLine(&it->l, *(str++));
315 // wrapper function for handling general keyed input.
316 // returns true if it ate the key
323 if (ch >= ' ' && ch <= '_')
324 HUlib_addCharToTextLine(&it->l, (char) ch);
326 if (ch == KEY_BACKSPACE)
327 HUlib_delCharFromIText(it);
330 return false; // did not eat key
332 return true; // ate the key
336 void HUlib_drawIText(hu_itext_t* it)
339 hu_textline_t *l = &it->l;
343 HUlib_drawTextLine(l, true); // draw the line w/ cursor
347 void HUlib_eraseIText(hu_itext_t* it)
349 if (it->laston && !*it->on)
350 it->l.needsupdate = 4;
351 HUlib_eraseTextLine(&it->l);
352 it->laston = *it->on;