Subversion Repositories Kolibri OS

Rev

Rev 298 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 298 Rev 333
1
// Emacs style mode select   -*- C++ -*- 
1
// Emacs style mode select   -*- C++ -*- 
2
//-----------------------------------------------------------------------------
2
//-----------------------------------------------------------------------------
3
//
3
//
4
// $Id:$
4
// $Id:$
5
//
5
//
6
// Copyright (C) 1993-1996 by id Software, Inc.
6
// Copyright (C) 1993-1996 by id Software, Inc.
7
//
7
//
8
// This source is available for distribution and/or modification
8
// This source is available for distribution and/or modification
9
// only under the terms of the DOOM Source Code License as
9
// only under the terms of the DOOM Source Code License as
10
// published by id Software. All rights reserved.
10
// published by id Software. All rights reserved.
11
//
11
//
12
// The source is distributed in the hope that it will be useful,
12
// The source is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
14
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
15
// for more details.
15
// for more details.
16
//
16
//
17
// $Log:$
17
// $Log:$
18
//
18
//
19
// DESCRIPTION:  heads-up text and input code
19
// DESCRIPTION:  heads-up text and input code
20
//
20
//
21
//-----------------------------------------------------------------------------
21
//-----------------------------------------------------------------------------
22
 
22
 
23
static const char
23
static const char
24
rcsid[] = "$Id: hu_lib.c,v 1.3 1997/01/26 07:44:58 b1 Exp $";
24
rcsid[] = "$Id: hu_lib.c,v 1.3 1997/01/26 07:44:58 b1 Exp $";
25
 
25
 
26
#include 
26
#include 
27
 
-
 
28
#include "m_swap.h"
-
 
29
 
27
 
30
#include "doomdef.h"
28
#include "doomdef.h"
31
 
29
 
32
#include "v_video.h"
30
#include "v_video.h"
-
 
31
#include "m_swap.h"
33
 
32
 
34
#include "hu_lib.h"
33
#include "hu_lib.h"
35
#include "r_local.h"
34
#include "r_local.h"
36
#include "r_draw.h"
35
#include "r_draw.h"
37
 
36
 
38
// boolean : whether the screen is always erased
37
// boolean : whether the screen is always erased
39
#define noterased viewwindowx
38
#define noterased viewwindowx
40
 
39
 
41
extern boolean	automapactive;	// in AM_map.c
40
extern boolean	automapactive;	// in AM_map.c
42
 
41
 
43
void HUlib_init(void)
42
void HUlib_init(void)
44
{
43
{
45
}
44
}
46
 
45
 
47
void HUlib_clearTextLine(hu_textline_t* t)
46
void HUlib_clearTextLine(hu_textline_t* t)
48
{
47
{
49
    t->len = 0;
48
    t->len = 0;
50
    t->l[0] = 0;
49
    t->l[0] = 0;
51
    t->needsupdate = true;
50
    t->needsupdate = true;
52
}
51
}
53
 
52
 
54
void
53
void
55
HUlib_initTextLine
54
HUlib_initTextLine
56
( hu_textline_t*	t,
55
( hu_textline_t*	t,
57
  int			x,
56
  int			x,
58
  int			y,
57
  int			y,
59
  patch_t**		f,
58
  patch_t**		f,
60
  int			sc )
59
  int			sc )
61
{
60
{
62
    t->x = x;
61
    t->x = x;
63
    t->y = y;
62
    t->y = y;
64
    t->f = f;
63
    t->f = f;
65
    t->sc = sc;
64
    t->sc = sc;
66
    HUlib_clearTextLine(t);
65
    HUlib_clearTextLine(t);
67
}
66
}
68
 
67
 
69
boolean
68
boolean
70
HUlib_addCharToTextLine
69
HUlib_addCharToTextLine
71
( hu_textline_t*	t,
70
( hu_textline_t*	t,
72
  char			ch )
71
  char			ch )
73
{
72
{
74
 
73
 
75
    if (t->len == HU_MAXLINELENGTH)
74
    if (t->len == HU_MAXLINELENGTH)
76
	return false;
75
	return false;
77
    else
76
    else
78
    {
77
    {
79
	t->l[t->len++] = ch;
78
	t->l[t->len++] = ch;
80
	t->l[t->len] = 0;
79
	t->l[t->len] = 0;
81
	t->needsupdate = 4;
80
	t->needsupdate = 4;
82
	return true;
81
	return true;
83
    }
82
    }
84
 
83
 
85
}
84
}
86
 
85
 
87
boolean HUlib_delCharFromTextLine(hu_textline_t* t)
86
boolean HUlib_delCharFromTextLine(hu_textline_t* t)
88
{
87
{
89
 
88
 
90
    if (!t->len) return false;
89
    if (!t->len) return false;
91
    else
90
    else
92
    {
91
    {
93
	t->l[--t->len] = 0;
92
	t->l[--t->len] = 0;
94
	t->needsupdate = 4;
93
	t->needsupdate = 4;
95
	return true;
94
	return true;
96
    }
95
    }
97
 
96
 
98
}
97
}
99
 
98
 
100
void
99
void
101
HUlib_drawTextLine
100
HUlib_drawTextLine
102
( hu_textline_t*	l,
101
( hu_textline_t*	l,
103
  boolean		drawcursor )
102
  boolean		drawcursor )
104
{
103
{
105
 
104
 
106
    int			i;
105
    int			i;
107
    int			w;
106
    int			w;
108
    int			x;
107
    int			x;
109
    unsigned char	c;
108
    unsigned char	c;
110
 
109
 
111
    // draw the new stuff
110
    // draw the new stuff
112
    x = l->x;
111
    x = l->x;
113
    for (i=0;ilen;i++)
112
    for (i=0;ilen;i++)
114
    {
113
    {
115
	c = toupper(l->l[i]);
114
	c = toupper(l->l[i]);
116
	if (c != ' '
115
	if (c != ' '
117
	    && c >= l->sc
116
	    && c >= l->sc
118
	    && c <= '_')
117
	    && c <= '_')
119
	{
118
	{
120
	    w = SHORT(l->f[c - l->sc]->width);
119
	    w = SHORT(l->f[c - l->sc]->width);
121
	    if (x+w > SCREENWIDTH)
120
	    if (x+w > SCREENWIDTH)
122
		break;
121
		break;
123
	    V_DrawPatchDirect(x, l->y, FG, l->f[c - l->sc]);
122
	    V_DrawPatchDirect(x, l->y, FG, l->f[c - l->sc]);
124
	    x += w;
123
	    x += w;
125
	}
124
	}
126
	else
125
	else
127
	{
126
	{
128
	    x += 4;
127
	    x += 4;
129
	    if (x >= SCREENWIDTH)
128
	    if (x >= SCREENWIDTH)
130
		break;
129
		break;
131
	}
130
	}
132
    }
131
    }
133
 
132
 
134
    // draw the cursor if requested
133
    // draw the cursor if requested
135
    if (drawcursor
134
    if (drawcursor
136
	&& x + SHORT(l->f['_' - l->sc]->width) <= SCREENWIDTH)
135
	&& x + SHORT(l->f['_' - l->sc]->width) <= SCREENWIDTH)
137
    {
136
    {
138
	V_DrawPatchDirect(x, l->y, FG, l->f['_' - l->sc]);
137
	V_DrawPatchDirect(x, l->y, FG, l->f['_' - l->sc]);
139
    }
138
    }
140
}
139
}
141
 
140
 
142
 
141
 
143
// sorta called by HU_Erase and just better darn get things straight
142
// sorta called by HU_Erase and just better darn get things straight
144
void HUlib_eraseTextLine(hu_textline_t* l)
143
void HUlib_eraseTextLine(hu_textline_t* l)
145
{
144
{
146
    int			lh;
145
    int			lh;
147
    int			y;
146
    int			y;
148
    int			yoffset;
147
    int			yoffset;
149
    static boolean	lastautomapactive = true;
148
    static boolean	lastautomapactive = true;
150
 
149
 
151
    // Only erases when NOT in automap and the screen is reduced,
150
    // Only erases when NOT in automap and the screen is reduced,
152
    // and the text must either need updating or refreshing
151
    // and the text must either need updating or refreshing
153
    // (because of a recent change back from the automap)
152
    // (because of a recent change back from the automap)
154
 
153
 
155
    if (!automapactive &&
154
    if (!automapactive &&
156
	viewwindowx && l->needsupdate)
155
	viewwindowx && l->needsupdate)
157
    {
156
    {
158
	lh = SHORT(l->f[0]->height) + 1;
157
	lh = SHORT(l->f[0]->height) + 1;
159
	for (y=l->y,yoffset=y*SCREENWIDTH ; yy+lh ; y++,yoffset+=SCREENWIDTH)
158
	for (y=l->y,yoffset=y*SCREENWIDTH ; yy+lh ; y++,yoffset+=SCREENWIDTH)
160
	{
159
	{
161
	    if (y < viewwindowy || y >= viewwindowy + viewheight)
160
	    if (y < viewwindowy || y >= viewwindowy + viewheight)
162
		R_VideoErase(yoffset, SCREENWIDTH); // erase entire line
161
		R_VideoErase(yoffset, SCREENWIDTH); // erase entire line
163
	    else
162
	    else
164
	    {
163
	    {
165
		R_VideoErase(yoffset, viewwindowx); // erase left border
164
		R_VideoErase(yoffset, viewwindowx); // erase left border
166
		R_VideoErase(yoffset + viewwindowx + viewwidth, viewwindowx);
165
		R_VideoErase(yoffset + viewwindowx + viewwidth, viewwindowx);
167
		// erase right border
166
		// erase right border
168
	    }
167
	    }
169
	}
168
	}
170
    }
169
    }
171
 
170
 
172
    lastautomapactive = automapactive;
171
    lastautomapactive = automapactive;
173
    if (l->needsupdate) l->needsupdate--;
172
    if (l->needsupdate) l->needsupdate--;
174
 
173
 
175
}
174
}
176
 
175
 
177
void
176
void
178
HUlib_initSText
177
HUlib_initSText
179
( hu_stext_t*	s,
178
( hu_stext_t*	s,
180
  int		x,
179
  int		x,
181
  int		y,
180
  int		y,
182
  int		h,
181
  int		h,
183
  patch_t**	font,
182
  patch_t**	font,
184
  int		startchar,
183
  int		startchar,
185
  boolean*	on )
184
  boolean*	on )
186
{
185
{
187
 
186
 
188
    int i;
187
    int i;
189
 
188
 
190
    s->h = h;
189
    s->h = h;
191
    s->on = on;
190
    s->on = on;
192
    s->laston = true;
191
    s->laston = true;
193
    s->cl = 0;
192
    s->cl = 0;
194
    for (i=0;i
193
    for (i=0;i
195
	HUlib_initTextLine(&s->l[i],
194
	HUlib_initTextLine(&s->l[i],
196
			   x, y - i*(SHORT(font[0]->height)+1),
195
			   x, y - i*(SHORT(font[0]->height)+1),
197
			   font, startchar);
196
			   font, startchar);
198
 
197
 
199
}
198
}
200
 
199
 
201
void HUlib_addLineToSText(hu_stext_t* s)
200
void HUlib_addLineToSText(hu_stext_t* s)
202
{
201
{
203
 
202
 
204
    int i;
203
    int i;
205
 
204
 
206
    // add a clear line
205
    // add a clear line
207
    if (++s->cl == s->h)
206
    if (++s->cl == s->h)
208
	s->cl = 0;
207
	s->cl = 0;
209
    HUlib_clearTextLine(&s->l[s->cl]);
208
    HUlib_clearTextLine(&s->l[s->cl]);
210
 
209
 
211
    // everything needs updating
210
    // everything needs updating
212
    for (i=0 ; ih ; i++)
211
    for (i=0 ; ih ; i++)
213
	s->l[i].needsupdate = 4;
212
	s->l[i].needsupdate = 4;
214
 
213
 
215
}
214
}
216
 
215
 
217
void
216
void
218
HUlib_addMessageToSText
217
HUlib_addMessageToSText
219
( hu_stext_t*	s,
218
( hu_stext_t*	s,
220
  char*		prefix,
219
  char*		prefix,
221
  char*		msg )
220
  char*		msg )
222
{
221
{
223
    HUlib_addLineToSText(s);
222
    HUlib_addLineToSText(s);
224
    if (prefix)
223
    if (prefix)
225
	while (*prefix)
224
	while (*prefix)
226
	    HUlib_addCharToTextLine(&s->l[s->cl], *(prefix++));
225
	    HUlib_addCharToTextLine(&s->l[s->cl], *(prefix++));
227
 
226
 
228
    while (*msg)
227
    while (*msg)
229
	HUlib_addCharToTextLine(&s->l[s->cl], *(msg++));
228
	HUlib_addCharToTextLine(&s->l[s->cl], *(msg++));
230
}
229
}
231
 
230
 
232
void HUlib_drawSText(hu_stext_t* s)
231
void HUlib_drawSText(hu_stext_t* s)
233
{
232
{
234
    int i, idx;
233
    int i, idx;
235
    hu_textline_t *l;
234
    hu_textline_t *l;
236
 
235
 
237
    if (!*s->on)
236
    if (!*s->on)
238
	return; // if not on, don't draw
237
	return; // if not on, don't draw
239
 
238
 
240
    // draw everything
239
    // draw everything
241
    for (i=0 ; ih ; i++)
240
    for (i=0 ; ih ; i++)
242
    {
241
    {
243
	idx = s->cl - i;
242
	idx = s->cl - i;
244
	if (idx < 0)
243
	if (idx < 0)
245
	    idx += s->h; // handle queue of lines
244
	    idx += s->h; // handle queue of lines
246
	
245
	
247
	l = &s->l[idx];
246
	l = &s->l[idx];
248
 
247
 
249
	// need a decision made here on whether to skip the draw
248
	// need a decision made here on whether to skip the draw
250
	HUlib_drawTextLine(l, false); // no cursor, please
249
	HUlib_drawTextLine(l, false); // no cursor, please
251
    }
250
    }
252
 
251
 
253
}
252
}
254
 
253
 
255
void HUlib_eraseSText(hu_stext_t* s)
254
void HUlib_eraseSText(hu_stext_t* s)
256
{
255
{
257
 
256
 
258
    int i;
257
    int i;
259
 
258
 
260
    for (i=0 ; ih ; i++)
259
    for (i=0 ; ih ; i++)
261
    {
260
    {
262
	if (s->laston && !*s->on)
261
	if (s->laston && !*s->on)
263
	    s->l[i].needsupdate = 4;
262
	    s->l[i].needsupdate = 4;
264
	HUlib_eraseTextLine(&s->l[i]);
263
	HUlib_eraseTextLine(&s->l[i]);
265
    }
264
    }
266
    s->laston = *s->on;
265
    s->laston = *s->on;
267
 
266
 
268
}
267
}
269
 
268
 
270
void
269
void
271
HUlib_initIText
270
HUlib_initIText
272
( hu_itext_t*	it,
271
( hu_itext_t*	it,
273
  int		x,
272
  int		x,
274
  int		y,
273
  int		y,
275
  patch_t**	font,
274
  patch_t**	font,
276
  int		startchar,
275
  int		startchar,
277
  boolean*	on )
276
  boolean*	on )
278
{
277
{
279
    it->lm = 0; // default left margin is start of text
278
    it->lm = 0; // default left margin is start of text
280
    it->on = on;
279
    it->on = on;
281
    it->laston = true;
280
    it->laston = true;
282
    HUlib_initTextLine(&it->l, x, y, font, startchar);
281
    HUlib_initTextLine(&it->l, x, y, font, startchar);
283
}
282
}
284
 
283
 
285
 
284
 
286
// The following deletion routines adhere to the left margin restriction
285
// The following deletion routines adhere to the left margin restriction
287
void HUlib_delCharFromIText(hu_itext_t* it)
286
void HUlib_delCharFromIText(hu_itext_t* it)
288
{
287
{
289
    if (it->l.len != it->lm)
288
    if (it->l.len != it->lm)
290
	HUlib_delCharFromTextLine(&it->l);
289
	HUlib_delCharFromTextLine(&it->l);
291
}
290
}
292
 
291
 
293
void HUlib_eraseLineFromIText(hu_itext_t* it)
292
void HUlib_eraseLineFromIText(hu_itext_t* it)
294
{
293
{
295
    while (it->lm != it->l.len)
294
    while (it->lm != it->l.len)
296
	HUlib_delCharFromTextLine(&it->l);
295
	HUlib_delCharFromTextLine(&it->l);
297
}
296
}
298
 
297
 
299
// Resets left margin as well
298
// Resets left margin as well
300
void HUlib_resetIText(hu_itext_t* it)
299
void HUlib_resetIText(hu_itext_t* it)
301
{
300
{
302
    it->lm = 0;
301
    it->lm = 0;
303
    HUlib_clearTextLine(&it->l);
302
    HUlib_clearTextLine(&it->l);
304
}
303
}
305
 
304
 
306
void
305
void
307
HUlib_addPrefixToIText
306
HUlib_addPrefixToIText
308
( hu_itext_t*	it,
307
( hu_itext_t*	it,
309
  char*		str )
308
  char*		str )
310
{
309
{
311
    while (*str)
310
    while (*str)
312
	HUlib_addCharToTextLine(&it->l, *(str++));
311
	HUlib_addCharToTextLine(&it->l, *(str++));
313
    it->lm = it->l.len;
312
    it->lm = it->l.len;
314
}
313
}
315
 
314
 
316
// wrapper function for handling general keyed input.
315
// wrapper function for handling general keyed input.
317
// returns true if it ate the key
316
// returns true if it ate the key
318
boolean
317
boolean
319
HUlib_keyInIText
318
HUlib_keyInIText
320
( hu_itext_t*	it,
319
( hu_itext_t*	it,
321
  unsigned char ch )
320
  unsigned char ch )
322
{
321
{
323
 
322
 
324
    if (ch >= ' ' && ch <= '_') 
323
    if (ch >= ' ' && ch <= '_') 
325
  	HUlib_addCharToTextLine(&it->l, (char) ch);
324
  	HUlib_addCharToTextLine(&it->l, (char) ch);
326
    else 
325
    else 
327
	if (ch == KEY_BACKSPACE) 
326
	if (ch == KEY_BACKSPACE) 
328
	    HUlib_delCharFromIText(it);
327
	    HUlib_delCharFromIText(it);
329
	else 
328
	else 
330
	    if (ch != KEY_ENTER) 
329
	    if (ch != KEY_ENTER) 
331
		return false; // did not eat key
330
		return false; // did not eat key
332
 
331
 
333
    return true; // ate the key
332
    return true; // ate the key
334
 
333
 
335
}
334
}
336
 
335
 
337
void HUlib_drawIText(hu_itext_t* it)
336
void HUlib_drawIText(hu_itext_t* it)
338
{
337
{
339
 
338
 
340
    hu_textline_t *l = &it->l;
339
    hu_textline_t *l = &it->l;
341
 
340
 
342
    if (!*it->on)
341
    if (!*it->on)
343
	return;
342
	return;
344
    HUlib_drawTextLine(l, true); // draw the line w/ cursor
343
    HUlib_drawTextLine(l, true); // draw the line w/ cursor
345
 
344
 
346
}
345
}
347
 
346
 
348
void HUlib_eraseIText(hu_itext_t* it)
347
void HUlib_eraseIText(hu_itext_t* it)
349
{
348
{
350
    if (it->laston && !*it->on)
349
    if (it->laston && !*it->on)
351
	it->l.needsupdate = 4;
350
	it->l.needsupdate = 4;
352
    HUlib_eraseTextLine(&it->l);
351
    HUlib_eraseTextLine(&it->l);
353
    it->laston = *it->on;
352
    it->laston = *it->on;
354
}
353
}
355
>
354
>