-
Notifications
You must be signed in to change notification settings - Fork 3
/
st_lib.pas
306 lines (255 loc) · 7.47 KB
/
st_lib.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
//------------------------------------------------------------------------------
//
// DoomXS - A basic Windows source port of Doom
// based on original Linux Doom as published by "id Software"
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 2021-2022 by Jim Valavanis
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
//------------------------------------------------------------------------------
// Site: https://sourceforge.net/projects/doomxs/
//------------------------------------------------------------------------------
unit st_lib;
interface
uses
d_delphi,
// We are referring to patches.
r_defs;
type
//
// Typedefs of widgets
//
// Number widget
st_number_t = record
// upper right-hand corner
// of the number (right-justified)
x: integer;
y: integer;
width: integer; // max # of digits in number
oldnum: integer; // last number value
num: PInteger; // pointer to current value
// pointer to boolean stating
// whether to update number
_on: PBoolean;
p: Ppatch_tPArray; // list of patches for 0-9
data: integer; // user data
end;
Pst_number_t = ^st_number_t;
// Percent widget ("child" of number widget,
// or, more precisely, contains a number widget.)
st_percent_t = record
n: st_number_t; // number information
p: Ppatch_t; // percent sign graphic
end;
Pst_percent_t = ^st_percent_t;
// Multiple Icon widget
st_multicon_t = record
// center-justified location of icons
x: integer;
y: integer;
oldinum: integer; // last icon number
inum: PInteger; // pointer to current icon
// pointer to boolean stating
// whether to update icon
_on: PBoolean;
p: Ppatch_tPArray; // list of icons
data: integer; // user data
end;
Pst_multicon_t = ^st_multicon_t;
// Binary Icon widget
st_binicon_t = record
// center-justified location of icon
x: integer;
y: integer;
oldval: boolean; // last icon value
val: PBoolean; // pointer to current icon status
// pointer to boolean
// stating whether to update icon
_on: PBoolean;
p: Ppatch_t; // icon
data: integer; // user data
end;
Pst_binicon_t = ^st_binicon_t;
//
// Widget creation, access, and update routines
//
// Initializes widget library.
// More precisely, initialize STMINUS,
// everything else is done somewhere else.
procedure STlib_init;
// Number widget routines
procedure STlib_initNum(n: Pst_number_t; x, y: integer; pl: Ppatch_tPArray;
num: PInteger; _on: PBoolean; width: integer);
procedure STlib_updateNum(n: Pst_number_t; refresh: boolean);
// Percent widget routines
procedure STlib_initPercent(p: Pst_percent_t; x, y: integer; pl: Ppatch_tPArray;
num: PInteger; _on: PBoolean; percent: Ppatch_t);
procedure STlib_updatePercent(per: Pst_percent_t; refresh: boolean);
// Multiple Icon widget routines
procedure STlib_initMultIcon(i: Pst_multicon_t; x, y: integer; il: Ppatch_tPArray;
inum: PInteger; _on: PBoolean);
procedure STlib_updateMultIcon(mi: Pst_multicon_t; refresh: boolean);
// Binary Icon widget routines
procedure STlib_initBinIcon(b: Pst_binicon_t; x, y: integer; i: Ppatch_t;
val: PBoolean; _on: PBoolean);
procedure STlib_updateBinIcon(bi: Pst_binicon_t; refresh: boolean);
implementation
uses
z_memory,
v_video,
i_system,
w_wad,
st_stuff; // automapactive
// Hack display negative frags.
// Loads and store the stminus lump.
var
sttminus: Ppatch_t;
procedure STlib_init;
begin
sttminus := W_CacheLumpName('STTMINUS', PU_STATIC);
end;
procedure STlib_initNum(n: Pst_number_t; x, y: integer; pl: Ppatch_tPArray;
num: PInteger; _on: PBoolean; width: integer);
begin
n.x := x;
n.y := y;
n.oldnum := 0;
n.width := width;
n.num := num;
n._on := _on;
n.p := pl;
end;
// A fairly efficient way to draw a number
// based on differences from the old number.
// Note: worth the trouble?
procedure STlib_drawNum(n: Pst_number_t; refresh: boolean);
var
numdigits: integer;
num: integer;
w: integer;
h: integer;
x: integer;
neg: boolean;
begin
numdigits := n.width;
num := n.num^;
w := n.p[0].width;
h := n.p[0].height;
n.oldnum := num;
neg := num < 0;
if neg then
begin
if (numdigits = 2) and (num < -9) then
num := -9
else if (numdigits = 3) and (num < -99) then
num := -99;
num := -num;
end;
// clear the area
x := n.x - numdigits * w;
if n.y - ST_Y < 0 then
I_Error('STlib_drawNum() : n.y - ST_Y < 0');
V_CopyRect(x, n.y - ST_Y, SCN_ST, w * numdigits, h, x, n.y, SCN_FG, True);
// if non-number, do not draw it
if num = 1994 then
Exit;
x := n.x;
// in the special case of 0, you draw 0
if num = 0 then
V_DrawPatch(x - w, n.y - ST_Y, SCN_ST, n.p[0], False);
// draw the new number
while (num <> 0) and (numdigits <> 0) do
begin
x := x - w;
V_DrawPatch(x, n.y - ST_Y, SCN_ST, n.p[num mod 10], False);
num := num div 10;
dec(numdigits);
end;
// draw a minus sign if necessary
if neg then
V_DrawPatch(x - 8, n.y - ST_Y, SCN_ST, sttminus, False);
end;
//
procedure STlib_updateNum(n: Pst_number_t; refresh: boolean);
begin
if n._on^ then
STlib_drawNum(n, refresh);
end;
//
procedure STlib_initPercent(p: Pst_percent_t; x, y: integer; pl: Ppatch_tPArray;
num: PInteger; _on: PBoolean; percent: Ppatch_t);
begin
STlib_initNum(@p.n, x, y, pl, num, _on, 3);
p.p := percent;
end;
procedure STlib_updatePercent(per: Pst_percent_t; refresh: boolean);
begin
if refresh and per.n._on^ then
V_DrawPatch(per.n.x, per.n.y - ST_Y, SCN_ST, per.p, False);
STlib_updateNum(@per.n, refresh);
end;
procedure STlib_initMultIcon(i: Pst_multicon_t; x, y: integer; il: Ppatch_tPArray;
inum: PInteger; _on: PBoolean);
begin
i.x := x;
i.y := y;
i.oldinum := -1;
i.inum := inum;
i._on := _on;
i.p := il;
end;
procedure STlib_updateMultIcon(mi: Pst_multicon_t; refresh: boolean);
var
y: integer;
begin
if mi._on^ and ((mi.oldinum <> mi.inum^) or refresh) and (mi.inum^ <> -1) then
begin
if mi.oldinum <> -1 then
begin
y := mi.y - mi.p[mi.oldinum].topoffset;
if y - ST_Y < 0 then
I_Error('STlib_updateMultIcon(): y - ST_Y < 0');
end;
V_DrawPatch(mi.x, mi.y - ST_Y, SCN_ST, mi.p[mi.inum^], False);
mi.oldinum := mi.inum^;
end;
end;
procedure STlib_initBinIcon(b: Pst_binicon_t; x, y: integer; i: Ppatch_t;
val: PBoolean; _on: PBoolean);
begin
b.x := x;
b.y := y;
b.oldval := False;
b.val := val;
b._on := _on;
b.p := i;
end;
procedure STlib_updateBinIcon(bi: Pst_binicon_t; refresh: boolean);
var
y: integer;
begin
if bi._on^ and ((bi.oldval <> bi.val^) or refresh) then
begin
y := bi.y - bi.p.topoffset;
if y - ST_Y < 0 then
I_Error('STlib_updateBinIcon(): y - ST_Y < 0');
if bi.val^ then
V_DrawPatch(bi.x, bi.y - ST_Y, SCN_ST, bi.p, False);
bi.oldval := bi.val^;
end;
end;
end.