fix remapping behavior. Remapping is only necessary if we are rendering on the workbe...
[AROS-Contrib.git] / Games / Doom / hu_lib.c
blobaee73be0a92d809f72271e258fae362e515c2fc7
1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
3 //
4 // $Id$
5 //
6 // Copyright (C) 1993-1996 by id Software, Inc.
7 //
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
15 // for more details.
17 // $Log$
18 // Revision 1.1 2000/02/29 18:21:04 stegerg
19 // Doom port based on ADoomPPC. Read README.AROS!
22 // DESCRIPTION: heads-up text and input code
24 //-----------------------------------------------------------------------------
26 static const char
27 rcsid[] = "$Id$";
29 #include <ctype.h>
31 #include "doomdef.h"
32 #include "doomstat.h"
34 #include "v_video.h"
35 #include "m_swap.h"
37 #include "hu_lib.h"
38 #include "r_local.h"
39 #include "r_draw.h"
41 // boolean : whether the screen is always erased
42 #define noterased viewwindowx
44 extern boolean automapactive; // in AM_map.c
45 extern int maponhu; // checkparm of -maponhu
47 void HUlib_init(void)
51 void HUlib_clearTextLine(hu_textline_t* t)
53 t->len = 0;
54 t->l[0] = 0;
55 t->needsupdate = true;
58 void
59 HUlib_initTextLine
60 ( hu_textline_t* t,
61 int x,
62 int y,
63 patch_t** f,
64 int sc )
66 t->x = x;
67 t->y = y;
68 t->f = f;
69 t->sc = sc;
70 HUlib_clearTextLine(t);
73 boolean
74 HUlib_addCharToTextLine
75 ( hu_textline_t* t,
76 char ch )
79 if (t->len == HU_MAXLINELENGTH)
80 return false;
81 else
83 t->l[t->len++] = ch;
84 t->l[t->len] = 0;
85 t->needsupdate = 4;
86 return true;
91 boolean HUlib_delCharFromTextLine(hu_textline_t* t)
94 if (!t->len) return false;
95 else
97 t->l[--t->len] = 0;
98 t->needsupdate = 4;
99 return true;
104 void
105 HUlib_drawTextLine
106 ( hu_textline_t* l,
107 boolean drawcursor )
110 int i;
111 int w;
112 int x;
113 unsigned char c;
115 // draw the new stuff
116 x = l->x;
117 for (i=0;i<l->len;i++)
119 c = toupper(l->l[i]);
120 if (c != ' '
121 && c >= l->sc
122 && c <= '_')
124 w = SWAPSHORT(l->f[c - l->sc]->width);
125 if (x+w > SCREENWIDTH)
126 break;
127 V_DrawPatchDirect(x, l->y, FG, l->f[c - l->sc]);
128 x += w;
130 else
132 x += 4;
133 if (x >= SCREENWIDTH)
134 break;
138 // draw the cursor if requested
139 if (drawcursor
140 && x + SWAPSHORT(l->f['_' - l->sc]->width) <= SCREENWIDTH)
142 V_DrawPatchDirect(x, l->y, FG, l->f['_' - l->sc]);
147 // sorta called by HU_Erase and just better darn get things straight
148 void HUlib_eraseTextLine(hu_textline_t* l)
150 int lh;
151 int y;
152 int yoffset;
153 static boolean lastautomapactive = true;
155 // Only erases when NOT in automap and the screen is reduced,
156 // and the text must either need updating or refreshing
157 // (because of a recent change back from the automap)
159 if ((!automapactive || maponhu) &&
160 viewwindowx && l->needsupdate)
162 lh = SWAPSHORT(l->f[0]->height) + 1;
163 for (y=l->y,yoffset=y*SCREENWIDTH ; y<l->y+lh ; y++,yoffset+=SCREENWIDTH)
165 if (y < viewwindowy || y >= viewwindowy + viewheight)
166 R_VideoErase(yoffset, SCREENWIDTH); // erase entire line
167 else
169 R_VideoErase(yoffset, viewwindowx); // erase left border
170 R_VideoErase(yoffset + viewwindowx + viewwidth, viewwindowx);
171 // erase right border
176 lastautomapactive = automapactive;
177 if (l->needsupdate) l->needsupdate--;
181 void
182 HUlib_initSText
183 ( hu_stext_t* s,
184 int x,
185 int y,
186 int h,
187 patch_t** font,
188 int startchar,
189 boolean* on )
192 int i;
194 s->h = h;
195 s->on = on;
196 s->laston = true;
197 s->cl = 0;
198 for (i=0;i<h;i++)
199 HUlib_initTextLine(&s->l[i],
200 x, y - i*(SWAPSHORT(font[0]->height)+1),
201 font, startchar);
205 void HUlib_addLineToSText(hu_stext_t* s)
208 int i;
210 // add a clear line
211 if (++s->cl == s->h)
212 s->cl = 0;
213 HUlib_clearTextLine(&s->l[s->cl]);
215 // everything needs updating
216 for (i=0 ; i<s->h ; i++)
217 s->l[i].needsupdate = 4;
221 void
222 HUlib_addMessageToSText
223 ( hu_stext_t* s,
224 char* prefix,
225 char* msg )
227 HUlib_addLineToSText(s);
228 if (prefix)
229 while (*prefix)
230 HUlib_addCharToTextLine(&s->l[s->cl], *(prefix++));
232 while (*msg)
233 HUlib_addCharToTextLine(&s->l[s->cl], *(msg++));
236 void HUlib_drawSText(hu_stext_t* s)
238 int i, idx;
239 hu_textline_t *l;
241 if (!*s->on)
242 return; // if not on, don't draw
244 // draw everything
245 for (i=0 ; i<s->h ; i++)
247 idx = s->cl - i;
248 if (idx < 0)
249 idx += s->h; // handle queue of lines
251 l = &s->l[idx];
253 // need a decision made here on whether to skip the draw
254 HUlib_drawTextLine(l, false); // no cursor, please
259 void HUlib_eraseSText(hu_stext_t* s)
262 int i;
264 for (i=0 ; i<s->h ; i++)
266 if (s->laston && !*s->on)
267 s->l[i].needsupdate = 4;
268 HUlib_eraseTextLine(&s->l[i]);
270 s->laston = *s->on;
274 void
275 HUlib_initIText
276 ( hu_itext_t* it,
277 int x,
278 int y,
279 patch_t** font,
280 int startchar,
281 boolean* on )
283 it->lm = 0; // default left margin is start of text
284 it->on = on;
285 it->laston = true;
286 HUlib_initTextLine(&it->l, x, y, font, startchar);
290 // The following deletion routines adhere to the left margin restriction
291 void HUlib_delCharFromIText(hu_itext_t* it)
293 if (it->l.len != it->lm)
294 HUlib_delCharFromTextLine(&it->l);
297 void HUlib_eraseLineFromIText(hu_itext_t* it)
299 while (it->lm != it->l.len)
300 HUlib_delCharFromTextLine(&it->l);
303 // Resets left margin as well
304 void HUlib_resetIText(hu_itext_t* it)
306 it->lm = 0;
307 HUlib_clearTextLine(&it->l);
310 void
311 HUlib_addPrefixToIText
312 ( hu_itext_t* it,
313 char* str )
315 while (*str)
316 HUlib_addCharToTextLine(&it->l, *(str++));
317 it->lm = it->l.len;
320 // wrapper function for handling general keyed input.
321 // returns true if it ate the key
322 boolean
323 HUlib_keyInIText
324 ( hu_itext_t* it,
325 unsigned char ch )
328 if (ch >= ' ' && ch <= '_')
329 HUlib_addCharToTextLine(&it->l, (char) ch);
330 else
331 if (ch == KEY_BACKSPACE)
332 HUlib_delCharFromIText(it);
333 else
334 if (ch != KEY_ENTER)
335 return false; // did not eat key
337 return true; // ate the key
341 void HUlib_drawIText(hu_itext_t* it)
344 hu_textline_t *l = &it->l;
346 if (!*it->on)
347 return;
348 HUlib_drawTextLine(l, true); // draw the line w/ cursor
352 void HUlib_eraseIText(hu_itext_t* it)
354 if (it->laston && !*it->on)
355 it->l.needsupdate = 4;
356 HUlib_eraseTextLine(&it->l);
357 it->laston = *it->on;