Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
298 serge 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.
11
//
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.
16
//
17
// $Log:$
18
//
19
// DESCRIPTION:
20
//	The status bar widget code.
21
//
22
//-----------------------------------------------------------------------------
23
 
24
 
25
static const char
26
rcsid[] = "$Id: st_lib.c,v 1.4 1997/02/03 16:47:56 b1 Exp $";
27
 
28
#include 
29
 
30
#include "doomdef.h"
31
 
32
#include "z_zone.h"
33
#include "v_video.h"
34
 
35
#include "i_system.h"
36
 
37
#include "w_wad.h"
38
 
39
#include "st_stuff.h"
40
#include "st_lib.h"
41
#include "r_local.h"
42
 
43
 
44
// in AM_map.c
45
extern boolean		automapactive;
46
 
47
 
48
 
49
 
50
//
51
// Hack display negative frags.
52
//  Loads and store the stminus lump.
53
//
54
patch_t*		sttminus;
55
 
56
void STlib_init(void)
57
{
58
    sttminus = (patch_t *) W_CacheLumpName("STTMINUS", PU_STATIC);
59
}
60
 
61
 
62
// ?
63
void
64
STlib_initNum
65
( st_number_t*		n,
66
  int			x,
67
  int			y,
68
  patch_t**		pl,
69
  int*			num,
70
  boolean*		on,
71
  int			width )
72
{
73
    n->x	= x;
74
    n->y	= y;
75
    n->oldnum	= 0;
76
    n->width	= width;
77
    n->num	= num;
78
    n->on	= on;
79
    n->p	= pl;
80
}
81
 
82
 
83
//
84
// A fairly efficient way to draw a number
85
//  based on differences from the old number.
86
// Note: worth the trouble?
87
//
88
void
89
STlib_drawNum
90
( st_number_t*	n,
91
  boolean	refresh )
92
{
93
 
94
    int		numdigits = n->width;
95
    int		num = *n->num;
96
 
97
    int		w = (n->p[0]->width);
98
    int		h = (n->p[0]->height);
99
    int		x = n->x;
100
 
101
    int		neg;
102
 
103
    n->oldnum = *n->num;
104
 
105
    neg = num < 0;
106
 
107
    if (neg)
108
    {
109
	if (numdigits == 2 && num < -9)
110
	    num = -9;
111
	else if (numdigits == 3 && num < -99)
112
	    num = -99;
113
 
114
	num = -num;
115
    }
116
 
117
    // clear the area
118
    x = n->x - numdigits*w;
119
 
120
    if (n->y - ST_Y < 0)
121
	I_Error("drawNum: n->y - ST_Y < 0");
122
 
123
    V_CopyRect(x, n->y - ST_Y, BG, w*numdigits, h, x, n->y, FG);
124
 
125
    // if non-number, do not draw it
126
    if (num == 1994)
127
	return;
128
 
129
    x = n->x;
130
 
131
    // in the special case of 0, you draw 0
132
    if (!num)
133
	V_DrawPatch(x - w, n->y, FG, n->p[ 0 ]);
134
 
135
    // draw the new number
136
    while (num && numdigits--)
137
    {
138
	x -= w;
139
	V_DrawPatch(x, n->y, FG, n->p[ num % 10 ]);
140
	num /= 10;
141
    }
142
 
143
    // draw a minus sign if necessary
144
    if (neg)
145
	V_DrawPatch(x - 8, n->y, FG, sttminus);
146
}
147
 
148
 
149
//
150
void
151
STlib_updateNum
152
( st_number_t*		n,
153
  boolean		refresh )
154
{
155
    if (*n->on) STlib_drawNum(n, refresh);
156
}
157
 
158
 
159
//
160
void
161
STlib_initPercent
162
( st_percent_t*		p,
163
  int			x,
164
  int			y,
165
  patch_t**		pl,
166
  int*			num,
167
  boolean*		on,
168
  patch_t*		percent )
169
{
170
    STlib_initNum(&p->n, x, y, pl, num, on, 3);
171
    p->p = percent;
172
}
173
 
174
 
175
 
176
 
177
void
178
STlib_updatePercent
179
( st_percent_t*		per,
180
  int			refresh )
181
{
182
    if (refresh && *per->n.on)
183
	V_DrawPatch(per->n.x, per->n.y, FG, per->p);
184
 
185
    STlib_updateNum(&per->n, refresh);
186
}
187
 
188
 
189
 
190
void
191
STlib_initMultIcon
192
( st_multicon_t*	i,
193
  int			x,
194
  int			y,
195
  patch_t**		il,
196
  int*			inum,
197
  boolean*		on )
198
{
199
    i->x	= x;
200
    i->y	= y;
201
    i->oldinum 	= -1;
202
    i->inum	= inum;
203
    i->on	= on;
204
    i->p	= il;
205
}
206
 
207
 
208
 
209
void
210
STlib_updateMultIcon
211
( st_multicon_t*	mi,
212
  boolean		refresh )
213
{
214
    int			w;
215
    int			h;
216
    int			x;
217
    int			y;
218
 
219
    if (*mi->on
220
	&& (mi->oldinum != *mi->inum || refresh)
221
	&& (*mi->inum!=-1))
222
    {
223
	if (mi->oldinum != -1)
224
	{
225
	    x = mi->x - (mi->p[mi->oldinum]->leftoffset);
226
	    y = mi->y - (mi->p[mi->oldinum]->topoffset);
227
	    w = (mi->p[mi->oldinum]->width);
228
	    h = (mi->p[mi->oldinum]->height);
229
 
230
	    if (y - ST_Y < 0)
231
		I_Error("updateMultIcon: y - ST_Y < 0");
232
 
233
	    V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG);
234
	}
235
	V_DrawPatch(mi->x, mi->y, FG, mi->p[*mi->inum]);
236
	mi->oldinum = *mi->inum;
237
    }
238
}
239
 
240
 
241
 
242
void
243
STlib_initBinIcon
244
( st_binicon_t*		b,
245
  int			x,
246
  int			y,
247
  patch_t*		i,
248
  boolean*		val,
249
  boolean*		on )
250
{
251
    b->x	= x;
252
    b->y	= y;
253
    b->oldval	= 0;
254
    b->val	= val;
255
    b->on	= on;
256
    b->p	= i;
257
}
258
 
259
 
260
 
261
void
262
STlib_updateBinIcon
263
( st_binicon_t*		bi,
264
  boolean		refresh )
265
{
266
    int			x;
267
    int			y;
268
    int			w;
269
    int			h;
270
 
271
    if (*bi->on
272
	&& (bi->oldval != *bi->val || refresh))
273
    {
274
	x = bi->x - (bi->p->leftoffset);
275
	y = bi->y - (bi->p->topoffset);
276
	w = (bi->p->width);
277
	h = (bi->p->height);
278
 
279
	if (y - ST_Y < 0)
280
	    I_Error("updateBinIcon: y - ST_Y < 0");
281
 
282
	if (*bi->val)
283
	    V_DrawPatch(bi->x, bi->y, FG, bi->p);
284
	else
285
	    V_CopyRect(x, y-ST_Y, BG, w, h, x, y, FG);
286
 
287
	bi->oldval = *bi->val;
288
    }
289
 
290
}
291