-
Notifications
You must be signed in to change notification settings - Fork 1
/
fontbm.c
407 lines (344 loc) · 7.24 KB
/
fontbm.c
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <sys/types.h>
#include <sys/time.h>
#include <assert.h>
#include "netrek.h"
#define fontmessage() fprintf(stderr, "You must do 'xset +fp <netrek-font-directory>' or have it\n\
in your .xinitrc in order for netrek to run.\n");
#define F_LPLANET "netrek_lplanetfont"
#define F_LPLANET_NUM FONTS+1
static F_lplanet_num = F_LPLANET_NUM;
#define F_MPLANET "netrek_mplanetfont"
#define F_MPLANET_NUM FONTS+2
static F_mplanet_num = F_MPLANET_NUM;
#define F_MISC "netrek_miscfont"
#define F_MISC_NUM FONTS+3
static F_misc_num = F_MISC_NUM;
#define F_SHIP1 "netrek_shipfont1"
#define F_SHIP1_NUM FONTS+4
static F_ship1_num = F_SHIP1_NUM;
#define F_SHIP2 "netrek_shipfont2"
#define F_SHIP2_NUM FONTS+5
static F_ship2_num = F_SHIP2_NUM;
#define F_SHIP3 "netrek_shipfont3"
#define F_SHIP3_NUM FONTS+6
static F_ship3_num = F_SHIP3_NUM;
#define F_SMALL "netrek_smallfont"
#define F_SMALL_NUM FONTS+7
static F_small_num = F_SMALL_NUM;
extern Display *W_Display;
extern Window W_Root;
#define W_VoidToGCList(v) ((GC *) v)
void
F_init(fonts, lastused)
W_FontInfo *fonts;
int lastused;
{
XFontStruct *f;
lastused++;
if(!(f = XLoadQueryFont(W_Display, F_LPLANET))){
fprintf(stderr, "netrek: Can't find bitmap font \"%s\"\n", F_LPLANET);
fontmessage();
exit(1);
}
fonts[lastused].baseline = f->max_bounds.ascent;
fonts[lastused].font = (void *)f;
lastused++;
if(!(f = XLoadQueryFont(W_Display, F_MPLANET))){
fprintf(stderr, "netrek: Can't find bitmap font \"%s\"\n", F_MPLANET);
fontmessage();
exit(1);
}
fonts[lastused].baseline = f->max_bounds.ascent;
fonts[lastused].font = (void *)f;
lastused++;
if(!(f = XLoadQueryFont(W_Display, F_MISC))){
fprintf(stderr, "netrek: Can't find bitmap font \"%s\"\n", F_MISC);
fontmessage();
exit(1);
}
fonts[lastused].baseline = f->max_bounds.ascent;
fonts[lastused].font = (void *)f;
lastused++;
if(!(f = XLoadQueryFont(W_Display, F_SHIP1))){
fprintf(stderr, "netrek: Can't find bitmap font \"%s\"\n", F_SHIP1);
fontmessage();
exit(1);
}
fonts[lastused].baseline = f->max_bounds.ascent;
fonts[lastused].font = (void *)f;
lastused++;
if(!(f = XLoadQueryFont(W_Display, F_SHIP2))){
fprintf(stderr, "netrek: Can't find bitmap font \"%s\"\n", F_SHIP2);
fontmessage();
exit(1);
}
fonts[lastused].baseline = f->max_bounds.ascent;
fonts[lastused].font = (void *)f;
lastused++;
if(!(f = XLoadQueryFont(W_Display, F_SHIP3))){
fprintf(stderr, "netrek: Can't find bitmap font \"%s\"\n", F_SHIP3);
fontmessage();
exit(1);
}
fonts[lastused].baseline = f->max_bounds.ascent;
fonts[lastused].font = (void *)f;
lastused++;
if(!(f = XLoadQueryFont(W_Display, F_SMALL))){
fprintf(stderr, "netrek: Can't find bitmap font \"%s\"\n", F_SMALL);
fontmessage();
exit(1);
}
fonts[lastused].baseline = f->max_bounds.ascent;
fonts[lastused].font = (void *)f;
lastused++;
}
void
F_initGC(gclist_v, lastused, fonts)
W_GC *gclist_v;
int lastused;
W_FontInfo *fonts;
{
GC *gclist = W_VoidToGCList(gclist_v);
XGCValues values;
register i;
for(i=0; i < F_NUMFONTS; i++){
lastused++;
values.font = ((XFontStruct *)fonts[lastused].font)->fid;
if(gclist[lastused])
XFreeGC(W_Display, gclist[lastused]);
gclist[lastused] = XCreateGC(W_Display, W_Root, GCFont, &values);
XSetGraphicsExposures(W_Display, gclist[lastused], False);
}
}
/*
planet_width/planet_height 30/30
cloak_width/cloak_height 20/20
shield_width/shield_height 20/20
sbexp_width/sbexp_height 80/80
ex_width/ex_height 64/64
plasmacloud_width/plasmacloud_height 13/13
cloud_width/cloud_height 9/9
eplasmacloud_width/eplasmacloud_height 7/7
mplasmacloud_width/mplasmacloud_height 5/5
mplanet_width/mplanet_height 16/16
*/
/* local planet character */
char *
F_planetChar(l)
struct planet *l;
{
static char r;
if(!(l->pl_info & me->p_team)) return "\015";
switch(showlocal){
case 0: /* owner */
r = remap[l->pl_owner] + 8;
return &r;
case 1: /* resource */
case 3:
r=0;
if(l->pl_armies > 4)
r += 4;
if(l->pl_flags & PLREPAIR)
r += 2;
if(l->pl_flags & PLFUEL)
r += 1;
if(showlocal == 3)
r += '\017';
return &r;
case 2: /* nothing */
#if 0
if(l->pl_armies < 5)
return "\020";
else
#endif
return "\010";
default:
return "";
}
}
W_Font
F_planetFont()
{
return (W_Font) &F_lplanet_num;
}
char *
F_cloakChar()
{
return "\205";
}
W_Font
F_cloakFont()
{
return (W_Font) &F_ship3_num;
}
char *
F_shieldChar(i)
int i;
{
static char r;
r = 128 + i;
return &r;
}
W_Font
F_shieldFont()
{
return (W_Font) &F_ship3_num;
}
#ifdef HOCKEY
char *
F_puckChar(dir)
int dir;
{
static char r;
r = '\206' + rosette(dir);
return &r;
}
#endif
char *
F_shipChar(team, ship, dir)
int team;
int ship;
unsigned char dir;
{
static char r;
r = ship * 16 + rosette(dir);
switch(team){
case FED:
case KLI:
r += 128;
}
return &r;
}
#ifdef HOCKEY
W_Font
F_puckFont()
{
return (W_Font) & F_ship3_num;
}
#endif
W_Font
F_playerFont(team)
int team;
{
switch(team){
case IND:
case FED:
return (W_Font) &F_ship1_num;
case ROM:
case KLI:
return (W_Font) &F_ship2_num;
case ORI:
return (W_Font) &F_ship3_num;
default:
return (W_Font) &F_ship1_num;
}
}
char *
F_expSbChar(frame)
int frame;
{
static char r;
r = frame;
return &r;
}
W_Font
F_explodeFont()
{
return (W_Font) &F_misc_num;
}
char *
F_expChar(frame)
int frame;
{
static char r;
r = 7 + frame;
return &r;
}
W_Font
F_smallFont()
{
return (W_Font) &F_small_num;
}
char *
F_expTorpChar(frame)
int frame;
{
static char r;
r = frame;
return &r;
}
char *
F_expPlasmaTorpChar(frame)
int frame;
{
static char r;
r = 12 + frame;
return &r;
}
char *
F_plasmaTorpEnemyChar()
{
return "\05";
}
char *
F_plasmaTorpChar()
{
return "\06";
}
char *
F_planetMapChar(l)
struct planet *l;
{
static char r;
if(!(l->pl_info & me->p_team)) return "\015";
switch(showgalactic){
case 0: /* owner */
r = remap[l->pl_owner] + 8;
return &r;
case 1: /* resource */
r=0;
if(l->pl_armies > 4)
r += 4;
#ifdef MOOBITMAPS
else if(myPlanetBitmap)
r += 13;
#endif
if(l->pl_flags & PLREPAIR)
r += 2;
if(l->pl_flags & PLFUEL)
r += 1;
#ifdef MOOBITMAPS
if(myPlanetBitmap){
/* NASTY kludge (font bitmaps screwed up)*/
if(r == 13) r = '\025';
}
#endif
return &r;
break;
case 2: /* nothing */
if(l->pl_armies < 5)
return "\025";
else
return "\010";
default:
return "";
}
}
W_Font
F_planetMapFont()
{
return (W_Font) &F_mplanet_num;
}
char *
F_phaserChar()
{
return "\07";
}
W_Font
F_phaserFont()
{
return (W_Font) &F_small_num;
}