/
x11window.c
3374 lines (2912 loc) · 83.5 KB
/
x11window.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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* x11window.c
*
* Kevin P. Smith 6/11/89 Much modified by Jerry Frain and Joe Young
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/cursorfont.h>
#include <sys/types.h>
#include <sys/time.h>
#ifdef SETTCPNODELAY
#include <netinet/in.h>
#include <netinet/tcp.h>
#endif
#include <assert.h>
#include "netrek.h"
#define MAX_TEXT_WIDTH 90
#ifdef FONT_BITMAPS
# define MAXFONTS FONTS+F_NUMFONTS+1
#else
# define MAXFONTS FONTS+1
#endif
/* XFIX speedup */
#define MAXCACHE 128
/* changes too good to risk leaving out, by Richard Caley (rjc@cstr.ed.ac.uk) */
#define RJC
#define FOURPLANEFIX
#define NORMAL_FONT "6x10"
#define MESG_FONT "6x10"
#define BOLD_FONT "-*-clean-bold-r-normal--10-100-75-75-c-60-*"
#define ITALIC_FONT "-*-clean-bold-r-normal--10-100-75-75-c-60-*"
#define BIG_FONT "-*-lucidatypewriter-*-*-*-*-40-*-*-*-*-*-*-*"
#define IND_FONT "-*-clean-bold-r-normal--10-100-75-75-c-60-*"
#ifdef TTS
#define TTS_FONT "-misc-fixed-bold-r-normal--15-*"
#endif
#define PtInBox(px, py, xl, yt, xr, yb) \
\
( \
((int)px >= (int)xl) && \
((int)px <= (int)xr) && \
((int)py >= (int)yt) && \
((int)py <= (int)yb))
static char *_nfonts[] =
{
NORMAL_FONT,
"-*-clean-medium-r-normal--10-100-75-75-c-60-*",
"6x10",
NULL,
};
static char *_bfonts[] =
{
BOLD_FONT,
"-*-clean-bold-r-normal--10-100-75-75-c-60-*",
"6x10",
NULL,
};
static char *_ifonts[] =
{
ITALIC_FONT,
"-*-clean-bold-r-normal--10-100-75-75-c-60-*",
"6x10",
NULL,
};
static char *_bgfonts[] =
{
BIG_FONT,
"6x10",
"6x10",
NULL,
};
#define BITGC 4
#define WHITE 0
#define BLACK 1
#define RED 2
#define GREEN 3
#define YELLOW 4
#define CYAN 5
#define GREY 6
#define MAX_COLOR 7
static int zero = 0;
static int one = 1;
static int two = 2;
static int three = 3;
static int four = 4; /* not used */
static int five = 5;
int W_FastClear = 0;
Display *W_Display;
Window W_Root;
Colormap W_Colormap;
int W_Screen;
#ifdef FOURPLANEFIX
Visual *W_Visual;
#endif
W_Font W_BigFont = (W_Font) & zero, W_RegularFont = (W_Font) & one;
W_Font W_HighlightFont = (W_Font) & two, W_UnderlineFont = (W_Font) & three;
W_Font W_MesgFont = (W_Font) &five;
W_Color W_White = WHITE, W_Black = BLACK, W_Red = RED, W_Green = GREEN;
W_Color W_Yellow = YELLOW, W_Cyan = CYAN, W_Grey = GREY;
int W_Textwidth, W_Textheight,
W_MesgTextwidth, W_MesgTextheight;
int W_in_message = 0; /* jfy -- for Jerry's warp message */
/* TTS: moved this out so we can use the 8th color */
static unsigned long planes[3];
#define SCROLL_THUMB_WIDTH 5
static int scrollbar = 1;
static int scroll_thumb_width = SCROLL_THUMB_WIDTH;
static GC scroll_thumb_gc;
static Pixmap scroll_thumb_pixmap;
static int scroll_lines = 100; /* save 100 lines */
/* Setup for ICCCM delete window. */
Atom wm_protocols,
wm_delete_window;
#ifdef RJC
extern W_Window baseWin;
static XClassHint class_hint =
{
"netrek", "Netrek",
};
static XWMHints wm_hint =
{
InputHint | StateHint,
True,
NormalState,
None,
None,
0, 0,
None,
None,
};
static XSizeHints wm_size_hint;
#endif /* RJC */
static W_Event W_myevent;
static int W_isEvent = 0;
struct colors {
char *name;
GC contexts[MAXFONTS];
Pixmap pixmap;
int pixelValue;
};
struct icon {
Window window;
Pixmap bitmap;
int width, height;
Pixmap pixmap;
};
#define WIN_GRAPH 1
#define WIN_TEXT 2
#define WIN_MENU 3
#define WIN_SCROLL 4
struct window {
Window window;
int type;
char *data;
int mapped;
int width, height;
char *name;
};
struct scrollingWindow {
int lines;
int updated;
int topline;
struct stringList *head;
struct stringList *tail;
struct stringList *index;
};
struct stringList {
char string[MAX_TEXT_WIDTH];
W_Color color;
W_Font font;
struct stringList *next, *prev;
};
struct menuItem {
int column;
char *string;
W_Color color;
};
static
struct colors colortable[] =
{
{"white"},
{"black"},
{"red"},
{"green"},
{"yellow"},
{"cyan"},
{"light grey"},
{"dummy"} /* extensions */
};
struct windowlist {
struct window *window;
struct windowlist *next;
};
#define HASHSIZE 29
#define hash(x) (((int) (x)) % HASHSIZE)
static struct windowlist *hashtable[HASHSIZE];
static struct fontInfo fonts[MAXFONTS];
static struct window myroot;
/* Last entry reserved for extensions */
#define NCOLORS (sizeof(colortable)/sizeof(colortable[0]))-1
#define W_Void2Window(win) ((win) ? (struct window *) (win) : &myroot)
#define W_Window2Void(window) ((W_Window) (window))
#define W_Void2Icon(bit) ((struct icon *) (bit))
#define W_Icon2Void(bit) ((W_Icon) (bit))
#define W_GCListToVoid(gcl) ((W_GC *) (gcl))
#define fontNum(font) (*((int *) font))
#define TILESIDE 16
#define WIN_EDGE 5 /* border on l/r edges of text windows */
#define MENU_PAD 5 /* border on t/b edges of text windows */
#define MENU_BAR 2 /* width of menu bar */
static char gray[] =
{
0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55,
0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55,
0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55,
0xaa, 0xaa, 0x55, 0x55, 0xaa, 0xaa, 0x55, 0x55
};
static char striped[] =
{
0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,
0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f,
0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00,
0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0, 0x0f, 0xf0
};
static char solid[] =
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
#if __STDC__ || defined(__cplusplus)
#define P_(s) s
#else
#define P_(s) ()
#endif
/* x11window.c */
static long WMXYHintMode_default P_((void));
static void scrollUp P_((struct window *win, int y));
static void scrollDown P_((struct window *win, int y));
static void scrollPosition P_((struct window *win, int y));
static void scrollTo P_((struct window *win, struct scrollingWindow *sw, int topline));
static void scrollScrolling P_((W_Event *wevent));
static void configureScrolling P_((struct window *win, int x, int y, int width, int height));
static int checkGeometry P_((char *name, int *x, int *y, int *width, int *height));
static void checkFont P_((XFontStruct *fontinfo, char *fontname));
static void setFontValues P_((W_Font font, XFontStruct *f_info));
static void GetFonts P_((void));
static XFontStruct *find_font P_((char *oldf, char **fonts, char **newfontname));
static void GetColors P_((void));
static void FlushClearAreaCache P_((Window win, int in));
static void FlushLineCache P_((Window win, int color));
static struct window *newWindow P_((Window window, int type));
static struct window *findWindow P_((Window window));
static void addToHash P_((struct window *win));
static void AddToScrolling P_((struct window *win, W_Color color, W_Font font, char *str, int len));
static void drawThumb P_((struct window *win, struct scrollingWindow *sw));
static void redrawScrolling P_((struct window *win));
static void redrawMenu P_((struct window *win));
static void redrawMenuItem P_((struct window *win, int n));
static void changeMenuItem P_((struct window *win, int col, int n, char *str, int len, W_Color color));
static void deleteWindow P_((struct window *window));
static void checkParent P_((char *name, W_Window *parent));
static void UpdateBackground P_((W_Window window));
static void UpdateBorder P_((W_Window window));
static void UpdateGeometry P_((W_Window window));
#undef P_
#define XDEBUG 0
#if XDEBUG
/* X debugging */
int
_myerror(d, e)
Display *d;
XErrorEvent *e;
{
abort();
}
#endif
static long
WMXYHintMode_default() /* BRM2.0pl18 */
{
static int fetched = 0;
static long WMXYHM_default;
char *hm_default_string;
if(!fetched)
{ hm_default_string = getdefault("WMXYHintMode");
if(!hm_default_string || strcmp(hm_default_string,"USPosition") == 0)
WMXYHM_default = USPosition;
else WMXYHM_default = PPosition;
fetched = 1;
}
return WMXYHM_default;
}
static void
scrollUp(win, y)
struct window *win;
int y;
{
struct scrollingWindow *sw = (struct scrollingWindow *) win->data;
int savedlines = sw->lines - win->height;
if(savedlines < 0) savedlines = 0;
if(sw->topline + savedlines > 0){
if(!sw->index) {
fprintf(stderr, "scroll error, NULL index (scrollUp).\n");
return;
}
sw->index = sw->index->next;
sw->topline --;
redrawScrolling(win);
}
}
static void
scrollDown(win, y)
struct window *win;
int y;
{
struct scrollingWindow *sw = (struct scrollingWindow *) win->data;
if(sw->topline < 0){
if(!sw->index) {
fprintf(stderr, "scroll error, NULL index (scrollDown).\n");
return;
}
sw->index = sw->index->prev;
sw->topline ++;
redrawScrolling(win);
}
}
static void
scrollPosition(win, y)
struct window *win;
int y;
{
struct scrollingWindow *sw = (struct scrollingWindow *) win->data;
int savedlines, maxrow, winheight,
newtop;
savedlines = sw->lines - win->height;
if(savedlines < 0) savedlines = 0;
maxrow = sw->lines < win->height ? sw->lines : win->height;
winheight = win->height * W_MesgTextheight + MENU_PAD * 2;
newtop = (y * (savedlines + maxrow + 1))/ winheight - savedlines;
if(newtop < -savedlines)
newtop = -savedlines;
else if(newtop > 0)
newtop = 0;
scrollTo(win, sw, newtop);
}
static void
scrollTo(win, sw, topline)
struct window *win;
struct scrollingWindow *sw;
int topline;
{
while(topline < sw->topline){
if(!sw->index) {
fprintf(stderr, "scroll error, NULL index (1).\n");
break;
}
sw->index = sw->index->next;
sw->topline --;
}
while(topline > sw->topline){
if(!sw->index) {
fprintf(stderr, "scroll error, NULL index (2).\n");
break;
}
sw->index = sw->index->prev;
sw->topline ++;
}
redrawScrolling(win);
}
static void
scrollScrolling(wevent)
W_Event *wevent;
{
switch(wevent->key){
case W_RBUTTON:
scrollUp(W_Void2Window(wevent->Window), wevent->y);
break;
case W_LBUTTON:
scrollDown(W_Void2Window(wevent->Window), wevent->y);
break;
case W_MBUTTON:
scrollPosition(W_Void2Window(wevent->Window), wevent->y);
break;
default:
break;
}
}
/* BRM2.00pl18 */
static void
configureScrolling(win, x, y, width, height)
struct window *win;
int x, y; /* TODO */
int width, height;
{
int new_text_width, new_text_height;
int new_real_width,new_real_height;
XWindowAttributes wa;
int sw = scrollbar ? scroll_thumb_width : 0;
#if 0
/* XXX: can't shrink window */
if(width <= win->width*W_MesgTextwidth+ WIN_EDGE*2 &&
height <= win->height*W_MesgTextheight + MENU_PAD*2)
return;
#endif
XGetWindowAttributes(W_Display, win->window, &wa);
new_text_width = (wa.width - WIN_EDGE*2 - sw)/W_MesgTextwidth;
new_text_height = (wa.height - MENU_PAD*2)/W_MesgTextheight;
if(new_text_width <= 0) new_text_width = 1;
if(new_text_height <= 0) new_text_height = 1;
if(new_text_width >= MAX_TEXT_WIDTH) new_text_width = MAX_TEXT_WIDTH-1;
new_real_width = new_text_width*W_MesgTextwidth + WIN_EDGE*2 + sw;
new_real_height = new_text_height*W_MesgTextheight + MENU_PAD*2;
if(new_real_height != wa.height || new_real_width != wa.width){
XResizeWindow(W_Display, win->window,new_real_width,new_real_height);
}
win->width = new_text_width;
win->height = new_text_height;
/* an expose event will follow a resize request, triggering
redrawScrolling */
}
/* BRM2.00pl18 */
/*****************************************************************************/
/* Looks up any default geometry specified in the defaults file and */
/* returns the values found there. Geometry should be of the form */
/* [=][<width>x<height>][{+-}<xoffset>{+-}<yoffset>] */
/* */
/* The result returned indicates which values were set. */
/* XValue, YValue, WidthValue, HeightValue */
/* */
/*****************************************************************************/
static int
checkGeometry(name, x, y, width, height)
char *name;
int *x, *y, *width, *height;
{
char buf[160], *geom_default;
register i;
int mask;
sprintf(buf,"%s.geometry",name);
geom_default = getdefault(buf);
#ifdef SHOW_DEFAULTS
{
char df[80], desc[80];
sprintf(df, "%dx%d%s%d%s%d", *width, *height,(*x<0?"":"+"),*x,
(*y<0?"":"+"),*y);
show_defaults("windows", buf, df,
"Default window geometry (use 'xwininfo -tree' on the netrek window \n\
to get names.)");
}
#endif
if(!geom_default) return 0; /* nothing set */
strcpy(buf, geom_default);
/* Eat trailing spaces */
for (i = strlen(buf) - 1; i && isspace(buf [i]); i--)
buf [i] = '\0';
mask = XParseGeometry(buf, x, y, (unsigned int *)width,
(unsigned int *)height);
if(!mask) {
fprintf(stderr, "netrek: Geometry parse error on \"%s.geometry: %s\"\n",
name, buf);
}
return mask;
}
#ifdef SETTCPNODELAY
void
set_tcp_nodelay(v)
int v;
{
int mi = v;
if(setsockopt(ConnectionNumber(W_Display), IPPROTO_TCP,
TCP_NODELAY, (char *)&mi, sizeof(int)) < 0){
/* harmless error
perror("X socket tcp_nodelay failed.");
*/
}
}
#endif
void
W_Initialize(str)
char *str;
{
int i;
static int init = 0;
#ifdef DEBUG
printf("Initializing...\n");
#endif
if(!init){
for (i = 0; i < HASHSIZE; i++) {
hashtable[i] = NULL;
}
if ((W_Display = XOpenDisplay(str)) == NULL) {
extern char *getenv();
if(str)
fprintf(stderr, "netrek: Can't open display %s.\n", str);
else
fprintf(stderr, "netrek: Can't open display %s.\n",
(getenv("DISPLAY")!=NULL)?getenv("DISPLAY"):"(none)");
exit(1);
}
#ifdef SETTCPNODELAY
set_tcp_nodelay(1);
#endif
}
/* Setup for ICCCM delete window. */
wm_protocols = XInternAtom(W_Display, "WM_PROTOCOLS", False);
wm_delete_window = XInternAtom(W_Display, "WM_DELETE_WINDOW", False);
#ifdef SHOW_DEFAULTS
show_defaults("display", "scrollbar", scrollbar?"on":"off",
"Scrollbars displayed on scrollable text windows.");
show_defaults("display", "scrollSaveLines", "100",
"Maximum lines saved in each text window.");
#endif
/* display scroll thumb */
scrollbar = booleanDefault("ScrollBar", scrollbar);
scroll_lines = intDefault("ScrollSaveLines", scroll_lines);
#ifdef SHOW_DEFAULTS
{
char buf[10];
sprintf(buf, "%d", scroll_thumb_width);
show_defaults("display", "scrollbarWidth", buf,
"Scrollbars width. (Note that scroll control is allowed anywhere in the window.)");
}
#endif
scroll_thumb_width = intDefault("ScrollBarWidth", scroll_thumb_width);
#if XDEBUG
XSynchronize(W_Display, True);
XSetErrorHandler(_myerror);
#endif
W_Root = DefaultRootWindow(W_Display);
#ifdef FOURPLANEFIX
W_Visual = DefaultVisual(W_Display, DefaultScreen(W_Display));
#endif
W_Screen = DefaultScreen(W_Display);
W_Colormap = DefaultColormap(W_Display, W_Screen);
myroot.window = W_Root;
myroot.type = WIN_GRAPH;
GetFonts();
GetColors();
getColorDefs();
#ifdef TTS
init_tts();
#endif
init = 1;
}
void
W_CloseDisplay()
{
if(W_Display) XCloseDisplay(W_Display);
}
/* after fork */
void
W_ChildCloseDisplay()
{
close(ConnectionNumber(W_Display));
}
/*
* Make sure the font will work, ie: that it fits in the 6x10 character
* cell that we expect. (BRM)
*/
static void
checkFont (fontinfo, fontname)
XFontStruct *fontinfo;
char *fontname;
{
if (fontinfo->max_bounds.width != 6 ||
fontinfo->min_bounds.width != 6 ||
fontinfo->descent + fontinfo->ascent != 10 ||
fontinfo->min_bounds.lbearing < 0 ||
fontinfo->max_bounds.rbearing > 6 ||
fontinfo->max_bounds.ascent > 8 ||
fontinfo->max_bounds.descent > 2) {
fprintf (stderr,
"netrek: Font '%s' \n", fontname);
fprintf(stderr,
"\tdoes not conform to 6x10 character cell rules.\n");
}
}
static void
setFontValues(font, f_info)
W_Font font;
XFontStruct *f_info;
{
struct fontInfo *f;
f = &fonts[fontNum(font)];
f->baseline = f_info->max_bounds.ascent;
f->width = f_info->max_bounds.width;
f->height = f_info->max_bounds.descent + f_info->max_bounds.ascent;
f->font = (void *) f_info;
}
static void
GetFonts()
{
Font regular, italic, bold, big, mesg;
int i;
XGCValues values;
XFontStruct *fontinfo;
char *fontname, *newfontname;
#ifdef FONT_BITMAPS
F_init(fonts, FONTS);
#endif
fontname = getdefault("font");
if (fontname == NULL)
fontname = NORMAL_FONT;
#ifdef SHOW_DEFAULTS
show_defaults("fonts", "font", fontname,
"Default font.");
#endif
fontinfo = XLoadQueryFont(W_Display, fontname);
if (fontinfo == NULL) {
fontinfo = find_font(fontname, _nfonts, &newfontname);
fontname = newfontname;
}
if (fontinfo == NULL) {
fprintf(stderr, "netrek: Can't find any fonts!\n");
exit(1);
}
checkFont(fontinfo, fontname);
regular = fontinfo->fid;
W_Textwidth = fontinfo->max_bounds.width;
W_Textheight = fontinfo->max_bounds.descent + fontinfo->max_bounds.ascent;
setFontValues(W_RegularFont, fontinfo);
fontname = getdefault("boldfont");
if (fontname == NULL)
fontname = BOLD_FONT;
#ifdef SHOW_DEFAULTS
show_defaults("fonts", "boldfont", fontname,
"Bold font -- used for highlighting.");
#endif
fontinfo = XLoadQueryFont(W_Display, fontname);
if (fontinfo == NULL) {
fontinfo = find_font(fontname, _bfonts, &newfontname);
fontname = newfontname;
}
if (fontinfo == NULL) {
bold = regular;
setFontValues(W_HighlightFont,
(XFontStruct *)fonts[fontNum(W_RegularFont)].font);
} else {
checkFont(fontinfo, fontname);
bold = fontinfo->fid;
setFontValues(W_HighlightFont, fontinfo);
if (fontinfo->max_bounds.width > W_Textwidth)
W_Textwidth = fontinfo->max_bounds.width;
if (fontinfo->max_bounds.descent + fontinfo->max_bounds.ascent > W_Textheight)
W_Textheight = fontinfo->max_bounds.descent + fontinfo->max_bounds.ascent;
}
fontname = getdefault("italicfont");
if (fontname == NULL)
fontname = ITALIC_FONT;
#ifdef SHOW_DEFAULTS
show_defaults("fonts", "italicfont", fontname,
"Italic font.");
#endif
fontinfo = XLoadQueryFont(W_Display, fontname);
if (fontinfo == NULL) {
fontinfo = find_font(fontname, _ifonts, &newfontname);
fontname = newfontname;
}
if (fontinfo == NULL) {
italic = regular;
setFontValues(W_UnderlineFont,
(XFontStruct *)fonts[fontNum(W_RegularFont)].font);
} else {
checkFont(fontinfo, fontname);
italic = fontinfo->fid;
setFontValues(W_UnderlineFont, fontinfo);
if (fontinfo->max_bounds.width > W_Textwidth)
W_Textwidth = fontinfo->max_bounds.width;
if (fontinfo->max_bounds.descent + fontinfo->max_bounds.ascent > W_Textheight)
W_Textheight = fontinfo->max_bounds.descent + fontinfo->max_bounds.ascent;
}
fontname = getdefault("bigfont");
if (fontname == NULL)
fontname = BIG_FONT;
#ifdef SHOW_DEFAULTS
show_defaults("fonts", "bigfont", fontname,
"Large font -- used to display number of players per team.");
#endif
fontinfo = XLoadQueryFont(W_Display, fontname);
if (fontinfo == NULL) {
fontinfo = find_font(fontname, _bgfonts, &newfontname);
fontname = newfontname;
}
if (fontinfo == NULL) {
big = regular;
setFontValues(W_BigFont,
(XFontStruct *)fonts[fontNum(W_RegularFont)].font);
} else {
big = fontinfo->fid;
setFontValues(W_BigFont, fontinfo);
}
fontname = getdefault("mesgfont");
if (fontname == NULL)
fontname = MESG_FONT;
#ifdef SHOW_DEFAULTS
show_defaults("fonts", "mesgfont", fontname,
"Message and menu font.");
#endif
fontinfo = XLoadQueryFont(W_Display, fontname);
if (fontinfo == NULL) {
fontinfo = find_font(fontname, _nfonts, &newfontname);
fontname = newfontname;
}
if (fontinfo == NULL) {
mesg = regular;
setFontValues(W_MesgFont,
(XFontStruct *)fonts[fontNum(W_RegularFont)].font);
} else {
#if 0
checkFont(fontinfo, fontname);
#endif
mesg = fontinfo->fid;
setFontValues(W_MesgFont, fontinfo);
W_MesgTextwidth = fontinfo->max_bounds.width;
W_MesgTextheight = fontinfo->max_bounds.descent +
fontinfo->max_bounds.ascent;
}
for (i = 0; i < NCOLORS; i++) {
values.font = big;
if(colortable[i].contexts[0])
XFreeGC(W_Display, colortable[i].contexts[0]);
colortable[i].contexts[0] = XCreateGC(W_Display, W_Root, GCFont, &values);
XSetGraphicsExposures(W_Display, colortable[i].contexts[0], False);
values.font = regular;
if(colortable[i].contexts[1])
XFreeGC(W_Display, colortable[i].contexts[1]);
colortable[i].contexts[1] = XCreateGC(W_Display, W_Root, GCFont, &values);
XSetGraphicsExposures(W_Display, colortable[i].contexts[1], False);
XSetLineAttributes(W_Display, colortable[i].contexts[1],
2, LineSolid, CapNotLast, JoinMiter);
values.font = bold;
if(colortable[i].contexts[2])
XFreeGC(W_Display, colortable[i].contexts[2]);
colortable[i].contexts[2] = XCreateGC(W_Display, W_Root, GCFont, &values);
XSetGraphicsExposures(W_Display, colortable[i].contexts[2], False);
values.font = italic;
if(colortable[i].contexts[3])
XFreeGC(W_Display, colortable[i].contexts[3]);
colortable[i].contexts[3] = XCreateGC(W_Display, W_Root, GCFont, &values);
XSetGraphicsExposures(W_Display, colortable[i].contexts[3], False);
if(i == W_Black)
values.function = GXcopy;
else
values.function = GXor;
if(colortable[i].contexts[BITGC])
XFreeGC(W_Display, colortable[i].contexts[BITGC]);
colortable[i].contexts[BITGC] = XCreateGC(W_Display, W_Root, GCFunction,
&values);
XSetGraphicsExposures(W_Display, colortable[i].contexts[BITGC], False);
{
static char dl[] =
{1, 8};
/* was 3 */
XSetLineAttributes(W_Display, colortable[i].contexts[BITGC],
0, LineOnOffDash, CapButt, JoinMiter);
XSetDashes(W_Display, colortable[i].contexts[BITGC], 0, dl, 2);
}
values.font = mesg;
if(colortable[i].contexts[5])
XFreeGC(W_Display, colortable[i].contexts[5]);
colortable[i].contexts[5] = XCreateGC(W_Display, W_Root, GCFont, &values);
XSetGraphicsExposures(W_Display, colortable[i].contexts[5], False);
#ifdef FONT_BITMAPS
F_initGC(W_GCListToVoid(colortable[i].contexts), 5, fonts);
#endif
}
}
static XFontStruct *
find_font(oldf, fonts, newfontname)
char *oldf, **fonts, **newfontname;
{
XFontStruct *fi;
char **f;
fprintf(stderr, "netrek: Can't find font %s. Trying others...\n",
oldf);
for (f = fonts; *f; f++) {
if (strcmp(*f, oldf) != 0) {
if ((fi = XLoadQueryFont(W_Display, *f))){
*newfontname = *f;
return fi;
}
}
}
return NULL;
}
#ifdef FOURPLANEFIX
static unsigned short extrared[8] =
{0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xb0, 0xc0};
static unsigned short extragreen[8] =
{0x40, 0x60, 0x80, 0xa0, 0xb0, 0xc0, 0x00, 0x20};
static unsigned short extrablue[8] =
{0x80, 0xa0, 0xb0, 0xc0, 0x00, 0x20, 0x40, 0x60};
#endif
int bw = 0;
int forceMono = 0;
static void
GetColors()
{
XGCValues values;
int i, j;
XColor foo;
int white, black;
unsigned long pixel;
static long prev_pixel;
char defaultstring[100];
char *defaults;
#ifdef FOURPLANEFIX
unsigned long extracolors[8];
XColor colordef;
#endif
#ifdef SHOW_DEFAULTS
show_defaults("display", "forceMono", forceMono?"on":"off",
"Force black&white even if color supported.");
#endif
forceMono = booleanDefault("forcemono", forceMono); /* 11/14/91 TC */
bw = 0;
if (DisplayCells(W_Display, W_Screen) <= 2 || forceMono) {
bw = 1;
white = WhitePixel(W_Display, W_Screen);
black = BlackPixel(W_Display, W_Screen);
for (i = 0; i < NCOLORS; i++) {
if (i != W_Black) {
colortable[i].pixelValue = white;
} else {
colortable[i].pixelValue = black;
}
/*
* We assume white is 0 or 1, and black is 0 or 1. We adjust
* graphics function based upon who is who.
*/
if (white == 0 && i != W_Black) { /* Black is 1 */
XSetFunction(W_Display, colortable[i].contexts[BITGC],
GXand);
}
}
} else if (DefaultVisual(W_Display, W_Screen)->class == TrueColor) {
/* Stuff added by sheldon@iastate.edu 5/28/93
* This is supposed to detect a TrueColor display, and then do a lookup of
* the colors in default colormap, instead of creating new colormap
*/
for (i=0; i<NCOLORS; i++) {
sprintf(defaultstring, "color.%s", colortable[i].name);
defaults=getdefault(defaultstring);
if (defaults==NULL) defaults=colortable[i].name;
#ifdef SHOW_DEFAULTS
show_defaults("display", defaultstring, defaults,
"Color remapping.\n\
Format: color.<color name>: <color-spec>\n\
Color-spec can be a name [red] or #rgb [#f00, #ff0000]");
#endif
if(!XParseColor(W_Display, W_Colormap, defaults, &foo)){
fprintf(stderr, "netrek: Unknown color \"%s\"\n", defaults);
}
/* allow re-entry */
if(colortable[i].pixmap) continue;
XAllocColor(W_Display, W_Colormap, &foo);
colortable[i].pixelValue = foo.pixel;
}
} else {