-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathxscreen.c
1900 lines (1753 loc) · 51.6 KB
/
xscreen.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
/*
** Astrolog (Version 5.41F) File: xscreen.c
**
** Code changed by Valentin Abramov ([email protected])
**
** IMPORTANT NOTICE: The graphics database and chart display routines
** used in this program are Copyright (C) 1991-1998 by Walter D. Pullen
** ([email protected], http://www.magitech.com/~cruiser1/astrolog.htm).
** Permission is granted to freely use and distribute these routines
** provided one doesn't sell, restrict, or profit from them in any way.
** Modification is allowed provided these notices remain with any
** altered or edited versions of the program.
**
** The main planetary calculation routines used in this program have
** been Copyrighted and the core of this program is basically a
** conversion to C of the routines created by James Neely as listed in
** Michael Erlewine's 'Manual of Computer Programming for Astrologers',
** available from Matrix Software. The copyright gives us permission to
** use the routines for personal use but not to sell them or profit from
** them in any way.
**
** The PostScript code within the core graphics routines are programmed
** and Copyright (C) 1992-1993 by Brian D. Willoughby
** ([email protected]). Conditions are identical to those above.
**
** The extended accurate ephemeris databases and formulas are from the
** calculation routines in the library SWISS EPHEMERIS and are programmed and
** copyright 1998 by Astrodienst AG.
** The use of that source code is subject to
** the Swiss Ephemeris Public License, available at
** http://www.astro.ch/swisseph. This copyright notice must not be
** changed or removed by any user of this program.
**
** Initial programming 8/28,30, 9/10,13,16,20,23, 10/3,6,7, 11/7,10,21/1991.
** X Window graphics initially programmed 10/23-29/1991.
** PostScript graphics initially programmed 11/29-30/1992.
** Last code change made 12/20/1998.
** Modifications from version 5.40 to 5.41 are by Alois Treindl.
*/
#include "astrolog.h"
#ifdef GRAPH
/*
******************************************************************************
** Astrolog Icon.
******************************************************************************
*/
#ifdef X11
/* This information used to define Astrolog's X icon (Rainbow over Third */
/* Eye) is identical to the output format used by the bitmap program. */
/* You could extract this section and run xsetroot -bitmap on it. */
#define icon_width 63
#define icon_height 32
static byte icon_bits[] = {
0x00,0x00,0x00,0xa8,0x0a,0x00,0x00,0x00,0x00,0x00,0x40,0x55,0x55,0x01,0x00,
0x00,0x00,0x00,0xa8,0xaa,0xaa,0x0a,0x00,0x00,0x00,0x00,0x54,0xf5,0x57,0x15,
0x00,0x00,0x00,0x80,0xaa,0xaa,0xaa,0xaa,0x00,0x00,0x00,0x40,0xd5,0xff,0xff,
0x55,0x01,0x00,0x00,0xa0,0xaa,0xaa,0xaa,0xaa,0x02,0x00,0x00,0x50,0xfd,0xff,
0xff,0x5f,0x05,0x00,0x00,0xa8,0xaa,0x2a,0xaa,0xaa,0x0a,0x00,0x00,0xd4,0xff,
0xaf,0xfa,0xff,0x15,0x00,0x00,0xaa,0x2a,0x00,0x00,0xaa,0x2a,0x00,0x00,0xf5,
0xbf,0xaa,0xaa,0xfe,0x57,0x00,0x80,0xaa,0x02,0x00,0x00,0xa0,0xaa,0x00,0x40,
0xfd,0xab,0xfa,0xaf,0xea,0x5f,0x01,0xa0,0xaa,0x80,0xff,0xff,0x80,0xaa,0x02,
0x50,0xff,0xea,0xff,0xff,0xab,0x7f,0x05,0xa0,0x2a,0xf0,0xff,0xff,0x07,0xaa,
0x02,0xd0,0xbf,0xfa,0x0f,0xf8,0xaf,0x7e,0x05,0xa8,0x0a,0xfc,0x01,0xc0,0x1f,
0xa8,0x0a,0xd4,0xaf,0x7e,0x00,0x00,0xbf,0xfa,0x15,0xa8,0x0a,0x3f,0x00,0x00,
0x7e,0xa8,0x0a,0xf4,0xaf,0x1f,0xe0,0x03,0xfc,0xfa,0x15,0xaa,0x82,0x0f,0xdc,
0x1d,0xf8,0xa0,0x2a,0xf4,0xab,0x07,0x23,0x62,0xf0,0xea,0x17,0xaa,0xc2,0x87,
0x91,0xc4,0xf0,0xa1,0x2a,0xf4,0xeb,0xc3,0xd0,0x85,0xe1,0xeb,0x17,0xaa,0xe0,
0x83,0x91,0xc4,0xe0,0x83,0x2a,0xf5,0xeb,0x03,0x23,0x62,0xe0,0xeb,0x57,0xaa,
0xe0,0x01,0xdc,0x1d,0xc0,0x83,0x2a,0xf5,0xeb,0x01,0xe0,0x03,0xc0,0xeb,0x57,
0xaa,0xe0,0x01,0x00,0x00,0xc0,0x83,0x2a,0xfd,0xeb,0x01,0x00,0x00,0xc0,0xeb,
0x5f};
#endif
/*
******************************************************************************
** Interactive Screen Graphics Routines.
******************************************************************************
*/
/* Set up all the colors used by the program, i.e. the foreground and */
/* background colors, and all the colors in the object arrays, based on */
/* whether or not we are in monochrome and/or reverse video mode. */
void InitColorsX()
{
int i;
#ifdef X11
Colormap cmap;
XColor xcol;
if (!gi.fFile) {
cmap = XDefaultColormap(gi.disp, gi.screen);
/* Allocate a color from the present X11 colormap. Given a string like */
/* "violet", allocate this color and return a value specifying it. */
for (i = 0; i < 16; i++) {
XParseColor(gi.disp, cmap, szColorX[i], &xcol);
XAllocColor(gi.disp, cmap, &xcol);
rgbind[i] = xcol.pixel;
}
}
#endif
gi.kiOn = kMainA[!gs.fInverse];
gi.kiOff = kMainA[gs.fInverse];
gi.kiLite = gs.fColor ? kMainA[2+gs.fInverse] : gi.kiOn;
gi.kiGray = gs.fColor ? kMainA[3-gs.fInverse] : gi.kiOn;
for (i = 0; i <= 8; i++)
kMainB[i] = gs.fColor ? kMainA[i] : gi.kiOn;
for (i = 0; i <= 7; i++)
kRainbowB[i] = gs.fColor ? kRainbowA[i] : gi.kiOn;
for (i = 0; i < 4; i++)
kElemB[i] = gs.fColor ? kElemA[i] : gi.kiOn;
for (i = 0; i <= cAspect; i++)
kAspB[i] = gs.fColor ? kAspA[i] : gi.kiOn;
for (i = 0; i <= cObj; i++)
kObjB[i] = gs.fColor ? kObjA[i] : gi.kiOn;
#ifdef X11
if (!gi.fFile) {
XSetBackground(gi.disp, gi.gc, rgbind[gi.kiOff]);
XSetForeground(gi.disp, gi.pmgc, rgbind[gi.kiOff]);
}
#endif
}
#ifdef ISG
/* This routine opens up and initializes a window and prepares it to be */
/* drawn upon, and gets various information about the display, too. */
void BeginX()
{
#ifdef X11
gi.disp = XOpenDisplay(gs.szDisplay);
if (gi.disp == NULL) {
PrintError("Can't open display.");
Terminate(tcFatal);
}
gi.screen = DefaultScreen(gi.disp);
bg = BlackPixel(gi.disp, gi.screen);
fg = WhitePixel(gi.disp, gi.screen);
hint.x = gi.xOffset; hint.y = gi.yOffset;
hint.width = gs.xWin; hint.height = gs.yWin;
hint.min_width = BITMAPX1; hint.min_height = BITMAPY1;
hint.max_width = BITMAPX; hint.max_height = BITMAPY;
hint.flags = PPosition | PSize | PMaxSize | PMinSize;
#if FALSE
wmhint = XGetWMHints(gi.disp, gi.wind);
wmhint->input = True;
XSetWMHints(gi.disp, gi.wind, wmhint);
#endif
gi.depth = DefaultDepth(gi.disp, gi.screen);
if (gi.depth < 5) {
gi.fMono = fTrue; /* Is this a monochrome monitor? */
gs.fColor = fFalse;
}
gi.root = RootWindow(gi.disp, gi.screen);
if (gs.fRoot)
gi.wind = gi.root; /* If -XB in effect, we'll use the root window. */
else
gi.wind = XCreateSimpleWindow(gi.disp, DefaultRootWindow(gi.disp),
hint.x, hint.y, hint.width, hint.height, 5, fg, bg);
gi.pmap = XCreatePixmap(gi.disp, gi.wind, gs.xWin, gs.yWin, gi.depth);
gi.icon = XCreateBitmapFromData(gi.disp, DefaultRootWindow(gi.disp),
icon_bits, icon_width, icon_height);
if (!gs.fRoot)
XSetStandardProperties(gi.disp, gi.wind, szAppName, szAppName, gi.icon,
(byte **)xkey, 0, &hint);
/* We have two graphics workareas. One is what the user currently sees in */
/* the window, and the other is what we are currently drawing on. When */
/* done, we can quickly copy this to the viewport for a smooth look. */
gi.gc = XCreateGC(gi.disp, gi.wind, 0, 0);
XSetGraphicsExposures(gi.disp, gi.gc, 0);
gi.pmgc = XCreateGC(gi.disp, gi.wind, 0, 0);
InitColorsX(); /* Go set up colors. */
if (!gs.fRoot)
XSelectInput(gi.disp, gi.wind, KeyPressMask | StructureNotifyMask |
ExposureMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask);
XMapRaised(gi.disp, gi.wind);
XSync(gi.disp, 0);
XFillRectangle(gi.disp, gi.pmap, gi.pmgc, 0, 0, gs.xWin, gs.yWin);
#endif /* X11 */
#ifdef WIN
if (wi.fChartWindow && (wi.xClient != gs.xWin ||
wi.yClient != gs.yWin) && wi.hdcPrint == hdcNil)
ResizeWindowToChart();
gi.xOffset = NMultDiv(wi.xClient - gs.xWin, wi.xScroll, nScrollDiv);
gi.yOffset = NMultDiv(wi.yClient - gs.yWin, wi.yScroll, nScrollDiv);
SetWindowOrg(wi.hdc, -gi.xOffset, -gi.yOffset);
SetWindowExt(wi.hdc, wi.xClient, wi.yClient);
SetMapMode(wi.hdc, MM_ANISOTROPIC);
SelectObject(wi.hdc, GetStockObject(NULL_PEN));
SelectObject(wi.hdc, GetStockObject(NULL_BRUSH));
if (!gs.fJetTrail || wi.hdcPrint != hdcNil)
PatBlt(wi.hdc, -gi.xOffset, -gi.yOffset, wi.xClient, wi.yClient,
gs.fInverse ? WHITENESS : BLACKNESS);
InitColorsX();
#endif /* WIN */
#ifdef MSG
if (!FValidResmode(gi.nRes)) /* Initialize graphics mode to hi-res. */
gi.nRes = gs.nResHi;
_setvideomode(gi.nRes == -1 ? _VRES16COLOR : gi.nRes);
if (_grstatus()) {
PrintError("Can't enter graphics mode.");
Terminate(tcFatal);
}
_getvideoconfig((struct videoconfig far *) &gi.cfg);
if (gi.cfg.numcolors < 16) {
gi.fMono = fTrue;
gs.fColor = fFalse;
}
_remapallpalette((long FPTR *) rgb);
_setactivepage(0);
_setvisualpage(0);
InitColorsX();
#ifdef MOUSE
MouseInit(xPcScreen, yPcScreen);
#endif
/* Make sure we reset textrows upon restart. */
gs.nTextRows = abs(gs.nTextRows);
#endif /* MSG */
#ifdef BGI
int i;
static struct palettetype pal;
if (!FValidResmode(gi.nRes)) /* Initialize graphics mode to hi-res. */
gi.nRes = gs.nResHi;
if (!gi.fLoaded) {
registerfarbgidriver(ATT_driver_far); /* attf.obj */
registerfarbgidriver(CGA_driver_far); /* cgaf.obj */
registerfarbgidriver(EGAVGA_driver_far); /* egavgaf.obj */
registerfarbgidriver(Herc_driver_far); /* hercf.obj */
registerfarbgidriver(IBM8514_driver_far); /* ibm8514f.obj */
registerfarbgidriver(PC3270_driver_far); /* pc3270f.obj */
gi.nDriver = DETECT;
initgraph(&gi.nDriver, &gi.nGraph, "");
gi.fLoaded = fTrue;
}
if (gi.nRes <= 0) {
switch (gi.nDriver) {
case CGA: gi.nGraph = CGAHI; break;
case MCGA: gi.nGraph = MCGAHI; break;
case EGA: gi.nGraph = EGAHI; break;
case EGA64: gi.nGraph = EGA64HI; break;
case EGAMONO: gi.nGraph = EGAMONOHI; break;
case HERCMONO: gi.nGraph = HERCMONOHI; break;
case ATT400: gi.nGraph = ATT400HI; break;
case VGA: gi.nGraph = VGAHI; break;
case PC3270: gi.nGraph = PC3270HI; break;
case IBM8514: gi.nGraph = IBM8514HI; break;
default: gi.nGraph = 0;
}
} else {
switch (gi.nDriver) {
case CGA: gi.nGraph = CGAHI; break;
case MCGA: gi.nGraph = MCGAHI; break;
case EGA: gi.nGraph = EGAHI; break;
case EGA64: gi.nGraph = EGA64HI; break;
case EGAMONO: gi.nGraph = EGAMONOHI; break;
case HERCMONO: gi.nGraph = HERCMONOHI; break;
case ATT400: gi.nGraph = ATT400HI; break;
case VGA: gi.nGraph = VGAMED; break;
case PC3270: gi.nGraph = PC3270HI; break;
case IBM8514: gi.nGraph = IBM8514LO; break;
default: gi.nGraph = 0;
}
}
setgraphmode(gi.nGraph);
if (graphresult()) {
PrintError("Can't enter graphics mode.");
Terminate(tcFatal);
}
gi.nPages = 1 + (gi.nDriver == HERCMONO ||
(gi.nDriver == VGA && gi.nGraph != VGAHI) || gi.nDriver == EGA);
if (getmaxcolor()+1 < 16) {
gi.fMono = fTrue;
gs.fColor = fFalse;
}
getpalette(&pal);
for (i = 0; i < pal.size; i++)
pal.colors[i] = (byte)rgb[i];
setallpalette(&pal);
setactivepage(0);
setvisualpage(0);
gi.nPageCur = 0;
InitColorsX();
#ifdef MOUSE
MouseInit(xPcScreen, yPcScreen);
#endif
/* Make sure we reset textrows upon restart. */
gs.nTextRows = abs(gs.nTextRows);
#endif /* BGI */
#ifdef MACG
MaxApplZone();
InitGraf(&thePort);
InitFonts();
FlushEvents(everyEvent, 0);
InitWindows();
InitMenus();
TEInit();
InitDialogs(0L);
InitCursor();
gi.rcDrag = screenBits.bounds;
gi.rcBounds.left = 20;
gi.rcBounds.top = 20 + GetMBarHeight();
gi.rcBounds.right = gi.rcBounds.left + gs.xWin;
gi.rcBounds.bottom = gi.rcBounds.top + gs.yWin;
gi.wpAst = NewCWindow(0L, &gi.rcBounds, "\pAstrolog 5.41D with Swiss Ephemeris", true,
noGrowDocProc, (WindowPtr)-1L, true, 0);
SetPort(gi.wpAst);
InitColorsX();
#endif /* MACG */
}
/* Add a certain amount of time to the current hour/day/month/year quantity */
/* defining the present chart. This is used by the chart animation feature. */
/* We can add or subtract anywhere from 1 to 9 seconds, minutes, hours, */
/* days, months, years, decades, centuries, or millenia in any one call. */
/* This is mainly just addition to the appropriate quantity, but we have */
/* to check for overflows, e.g. Dec 30 + 3 days = Jan 2 of Current year + 1 */
void AddTime(mode, toadd)
int mode, toadd;
{
int d;
real h, m;
if (!FBetween(mode, 1, 9))
mode = 4;
h = RFloor(TT);
m = RFract(TT)*100.0;
if (mode == 1)
m += 1.0/60.0*(real)toadd; /* Add seconds. */
else if (mode == 2)
m += (real)toadd; /* add minutes. */
/* Add hours, either naturally or if minute value overflowed. */
if (m < 0.0 || m >= 60.0 || mode == 3) {
if (m >= 60.0) {
m -= 60.0; toadd = NSgn(toadd);
} else if (m < 0.0) {
m += 60.0; toadd = NSgn(toadd);
}
h += (real)toadd;
}
/* Add days, either naturally or if hour value overflowed. */
if (h >= 24.0 || h < 0.0 || mode == 4) {
if (h >= 24.0) {
h -= 24.0; toadd = NSgn(toadd);
} else if (h < 0.0) {
h += 24.0; toadd = NSgn(toadd);
}
DD = AddDay(MM, DD, YY, toadd);
}
/* Add months, either naturally or if day value overflowed. */
if (DD > (d = DayInMonth(MM, YY)) || DD < 1 || mode == 5) {
if (DD > d) {
DD -= d; toadd = NSgn(toadd);
} else if (DD < 1) {
DD += DayInMonth(Mod12(MM - 1), YY);
toadd = NSgn(toadd);
}
MM += toadd;
}
/* Add years, either naturally or if month value overflowed. */
if (MM > 12 || MM < 1 || mode == 6) {
if (MM > 12) {
MM -= 12; toadd = NSgn(toadd);
} else if (MM < 1) {
MM += 12; toadd = NSgn(toadd);
}
YY += toadd;
}
if (mode == 7)
YY += 10 * toadd; /* Add decades. */
else if (mode == 8)
YY += 100 * toadd; /* Add centuries. */
else if (mode == 9)
YY += 1000 * toadd; /* Add millenia. */
TT = h+m/100.0; /* Recalibrate hour time. */
}
/* Animate the current chart based on the given values indicating how much */
/* to update by. We update and recast the current chart info appropriately. */
/* Note animation mode for comparison charts will update the second chart. */
void Animate(mode, toadd)
int mode, toadd;
{
CI ciT;
if (us.fProgress && !us.nRel)
ciT = ciCore;
if (gi.nMode == gWorldMap || gi.nMode == gGlobe || gi.nMode == gPolar) {
gs.nRot += toadd;
if (gs.nRot >= nDegMax) /* For animating globe display, add */
gs.nRot -= nDegMax; /* in appropriate degree value. */
else if (gs.nRot < 0)
gs.nRot += nDegMax;
} else {
if (mode == 10) {
#ifdef TIME
/* For the continuous chart update to present moment */
/* animation mode, go get whatever time it is now. */
FInputData(szNowCore);
#else
if (us.nRel)
ciCore = ciTwin;
else
ciCore = ciMain;
AddTime(1, toadd);
#endif
} else { /* Otherwise add on appropriate time vector to chart info. */
if (us.nRel)
ciCore = ciTwin;
else
ciCore = ciMain;
AddTime(mode, toadd);
}
if (us.nRel) {
ciTwin = ciCore;
ciCore = ciMain;
} else
ciMain = ciCore;
if (us.fProgress && !us.nRel)
ciCore = ciT;
if (us.nRel)
CastRelation();
else
CastChart(fTrue);
}
}
/* This routine exits graphics mode, prompts the user for a set of command */
/* switches, processes them, and returns to the previous graphics with the */
/* new settings in effect, allowing one to change most any setting without */
/* having to lose their graphics state or fall way back to a -Q loop. */
void CommandLineX()
{
byte szCommandLine[cchSzMax], *rgsz[MAXSWITCHES];
int argc, fT, fPause = fFalse;
ciCore = ciMain;
#ifdef MSG
_setvideomode(_DEFAULTMODE);
_settextrows(gs.nTextRows);
#endif
#ifdef BGI
restorecrtmode();
if (gs.nTextRows > 25)
textmode(C4350);
#endif
fT = us.fLoop; us.fLoop = fTrue;
argc = NPromptSwitches(szCommandLine, rgsz);
is.cchRow = 0;
is.fSzInteract = fTrue;
if (!FProcessSwitches(argc, rgsz))
fPause = fTrue;
else {
is.fMult = fFalse;
FPrintTables();
if (is.fMult) {
ClearB((lpbyte)&us.fCredit,
(int)((lpbyte)&us.fLoop - (lpbyte)&us.fCredit));
fPause = fTrue;
}
}
#ifdef PCG
/* Pause for the user if there was either an error processing the */
/* switches, or one of the informational text tables was brought up. */
if (fPause) {
AnsiColor(kDefault);
is.cchRow = 0;
PrintSz("Press any key to return to graphics.\n");
while (!kbhit())
;
getch();
}
#endif
is.fSzInteract = fFalse;
us.fLoop = fT;
ciMain = ciCore;
BeginX();
}
/* Given two chart size values, adjust them such that the chart will look */
/* "square". We round the higher value down and check certain conditions. */
void SquareX(x, y, force)
int *x, *y, force;
{
if (!force && !fSquare) /* Unless we want to force a square, realize */
return; /* that some charts look better rectangular. */
if (*x > *y)
*x = *y;
else
*y = *x;
#ifdef PCG
if (FEgaRes(gi.nRes)) /* Scale horizontal size if we're in a PC */
*x = VgaFromEga(*x); /* graphics mode without "square" pixels. */
else if (FCgaRes(gi.nRes))
*x = VgaFromCga(*x);
#endif
if (fSidebar) /* Take into account chart's sidebar, if any. */
*x += xSideT;
}
#ifndef WIN
/* This routine gets called after graphics are brought up and displayed */
/* on the screen. It loops, processing key presses, mouse clicks, etc, that */
/* the window receives, until the user specifies they want to exit program. */
void InteractX()
{
#ifdef X11
byte sz[cchSzDef];
XEvent xevent;
KeySym keysym;
int fResize = fFalse, fRedraw = fTrue;
#endif
#ifdef PCG
#ifdef MOUSE
int eventx, eventy, eventbtn;
#endif
int fResize = fTrue, fRedraw = fFalse;
#endif /* PCG */
#ifdef MACG
EventRecord erCur;
WindowPtr wpCur;
int wc, fEvent, fResize = fFalse, fRedraw = fTrue;
#endif
int fBreak = fFalse, fPause = fFalse, fCast = fFalse, xcorner = 7,
mousex = -1, mousey = -1, buttonx = -1, buttony = -1, dir = 1,
length, key, i;
bool fT;
KI coldrw = gi.kiLite;
neg(gs.nAnim);
while (!fBreak) {
gi.nScale = gs.nScale/100;
/* Some chart windows, like the world maps and aspect grids, should */
/* always be a certian size, so correct if a resize was attempted. */
if (fMap) {
length = nDegMax*gi.nScale;
if (gs.xWin != length) {
gs.xWin = length;
fResize = fTrue;
}
length = nDegHalf*gi.nScale;
if (gs.yWin != length) {
gs.yWin = length;
fResize = fTrue;
}
} else if (gi.nMode == gGrid) {
if (gs.xWin != (length =
(gs.nGridCell + (us.nRel <= rcDual))*CELLSIZE*gi.nScale+1)) {
gs.xWin = length;
fResize = fTrue;
} if (gs.yWin != length) {
gs.yWin = length;
fResize = fTrue;
}
/* Make sure the window isn't too large or too small. */
} else {
if (gs.xWin < BITMAPX1) {
gs.xWin = BITMAPX1;
fResize = fTrue;
} else if (gs.xWin > BITMAPX) {
gs.xWin = BITMAPX;
fResize = fTrue;
}
if (gs.yWin < BITMAPY1) {
gs.yWin = BITMAPY1;
fResize = fTrue;
} else if (gs.yWin > BITMAPY) {
gs.yWin = BITMAPY;
fResize = fTrue;
}
}
/* If in animation mode, ensure we are in the flicker free resolution. */
if (gs.nAnim < 0) {
neg(gs.nAnim);
#ifdef PCG
if (gi.nRes == gs.nResHi && !gs.fJetTrail) {
gi.nRes = gs.nResLo;
BeginX();
gs.xWin = xPcScreen;
gs.yWin = yPcScreen;
SquareX(&gs.xWin, &gs.yWin, fFalse);
fResize = fTrue;
}
#endif
}
/* Physically resize window if we've changed the size parameters. */
if (fResize) {
fResize = fFalse;
#ifdef X11
XResizeWindow(gi.disp, gi.wind, gs.xWin, gs.yWin);
XFreePixmap(gi.disp, gi.pmap);
gi.pmap = XCreatePixmap(gi.disp, gi.wind, gs.xWin, gs.yWin, gi.depth);
#endif
#ifdef PCG
if (xPcScreen > gs.xWin)
gi.xOffset = (xPcScreen - gs.xWin) / 2;
else {
if (xcorner % 3 == 1)
gi.xOffset = 0;
else if (xcorner % 3 == 0)
gi.xOffset = -gs.xWin + xPcScreen;
else
gi.xOffset = -(gs.xWin - xPcScreen) / 2;
}
if (yPcScreen > gs.yWin)
gi.yOffset = (yPcScreen - gs.yWin) / 2;
else {
if (xcorner > 6)
gi.yOffset = 0;
else if (xcorner < 4)
gi.yOffset = -gs.yWin + yPcScreen;
else
gi.yOffset = -(gs.yWin - yPcScreen) / 2;
}
#endif
#ifdef MACG
SizeWindow(gi.wpAst, gs.xWin, gs.yWin, fTrue);
#endif
fRedraw = fTrue;
}
/* Recast chart if the chart information has changed any. */
if (fCast) {
fCast = fFalse;
ciCore = ciMain;
if (us.nRel)
CastRelation();
else
CastChart(fTrue);
fRedraw = fTrue;
}
if (gs.nAnim && !fPause)
fRedraw = fTrue;
/* Update the screen if anything has changed since last time around. */
if (fRedraw && (!fPause || gs.nAnim)) {
fRedraw = fFalse;
/* If we're in animation mode, change the chart info appropriately. */
if (gs.nAnim && !fPause)
Animate(gs.nAnim, dir);
/* Clear the screen and set up a buffer to draw in. */
#ifdef X11
XFillRectangle(gi.disp, gi.pmap, gi.pmgc, 0, 0, gs.xWin, gs.yWin);
#endif
#ifdef PCG
#ifdef MOUSE
MouseShow(fFalse);
#endif
#ifdef MSG
if (gi.cfg.numvideopages > 1)
_setactivepage(_getactivepage() == gs.fJetTrail);
#else
if (gi.nPages > 1) {
gi.nPageCur = (gi.nPageCur == gs.fJetTrail);
setactivepage(gi.nPageCur);
}
#endif
#endif /* PCG */
#ifdef MACG
SetPort(gi.wpAst);
InvalRect(&gi.wpAst->portRect);
BeginUpdate(gi.wpAst);
EraseRect(&gi.wpAst->portRect);
#endif
DrawChartX();
/* Make the drawn chart visible in the current screen buffer. */
#ifdef X11
XSync(gi.disp, 0);
XCopyArea(gi.disp, gi.pmap, gi.wind, gi.gc,
0, 0, gs.xWin, gs.yWin, 0, 0);
#endif
#ifdef PCG
#ifdef MSG
if (gi.cfg.numvideopages > 1)
_setvisualpage(_getactivepage());
#else
if (gi.nPages > 1)
setvisualpage(gi.nPageCur);
#endif
#ifdef MOUSE
if (!gs.nAnim || fPause)
MouseShow(fTrue);
#endif
#endif /* PCG */
#ifdef MACG
EndUpdate(gi.wpAst);
#endif
} /* if */
/* Now process what's on the event queue, i.e. any keys pressed, etc. */
#ifdef X11
if (XEventsQueued(gi.disp, QueuedAfterFlush /*QueuedAfterReading*/) ||
!gs.nAnim || fPause) {
XNextEvent(gi.disp, &xevent);
/* Restore what's on window if a part of it gets uncovered. */
if (xevent.type == Expose && xevent.xexpose.count == 0) {
XSync(gi.disp, 0);
XCopyArea(gi.disp, gi.pmap, gi.wind, gi.gc,
0, 0, gs.xWin, gs.yWin, 0, 0);
}
switch (xevent.type) {
/* Check for a manual resize of window by user. */
case ConfigureNotify:
gs.xWin = xevent.xconfigure.width;
gs.yWin = xevent.xconfigure.height;
XFreePixmap(gi.disp, gi.pmap);
gi.pmap = XCreatePixmap(gi.disp, gi.wind, gs.xWin, gs.yWin, gi.depth);
fRedraw = fTrue;
break;
case MappingNotify:
XRefreshKeyboardMapping((XMappingEvent *)&xevent);
break;
#ifdef MOUSE
/* Process any mouse buttons the user pressed. */
case ButtonPress:
mousex = xevent.xbutton.x; mousey = xevent.xbutton.y;
if (xevent.xbutton.button == Button1) {
DrawColor(gi.kiLite);
DrawPoint(mousex, mousey);
XSync(gi.disp, 0);
XCopyArea(gi.disp, gi.pmap, gi.wind, gi.gc,
0, 0, gs.xWin, gs.yWin, 0, 0);
} else if (xevent.xbutton.button == Button2 && (gi.nMode ==
gAstroGraph || gi.nMode == gWorldMap) && gs.nRot == 0) {
Lon = DegToDec(rDegHalf -
(real)(xevent.xbutton.x-1)/(real)(gs.xWin-2)*rDegMax);
Lat = DegToDec(rDegQuad -
(real)(xevent.xbutton.y-1)/(real)(gs.yWin-2)*181.0);
sprintf(sz, "Mouse is at %s.", SzLocation(Lon, Lat));
PrintNotice(sz);
} else if (xevent.xbutton.button == Button3)
fBreak = fTrue;
break;
/* Check for user dragging any of the mouse buttons across window. */
case MotionNotify:
DrawColor(coldrw);
DrawLine(mousex, mousey, xevent.xbutton.x, xevent.xbutton.y);
XSync(gi.disp, 0);
XCopyArea(gi.disp, gi.pmap, gi.wind, gi.gc,
0, 0, gs.xWin, gs.yWin, 0, 0);
mousex = xevent.xbutton.x; mousey = xevent.xbutton.y;
break;
#endif
/* Process any keys user pressed in window. */
case KeyPress:
length = XLookupString((XKeyEvent *)&xevent, xkey, 10, &keysym, 0);
if (length == 1) {
key = xkey[0];
#endif /* X11 */
#ifdef PCG
#ifdef MOUSE
if ((!gs.nAnim || fPause) && MouseStatus(&eventx, &eventy, &eventbtn)) {
/* If the left button is down, draw on the screen. */
if (eventbtn == mfLeft && mousex >= 0) {
MouseShow(fFalse);
DrawColor(coldrw);
PcMoveTo(mousex, mousey);
buttonx = eventx; buttony = eventy;
PcLineTo(buttonx, buttony);
/* If the right button is down, change the default location. */
} else if (eventbtn == mfRight) {
if (fMap && gs.nRot == 0 && !gs.fConstel && !gs.fMollewide) {
Lon = DegToDec(rDegHalf-(real)(eventx-gi.xOffset)/
(real)gs.xWin*rDegMax);
if (Lon < -rDegHalf)
Lon = -rDegHalf;
else if (Lon > rDegHalf)
Lon = rDegHalf;
Lat = DegToDec(rDegQuad-(real)(eventy-gi.yOffset)/
(real)gs.yWin*181.0);
if (Lat < -rDegQuad)
Lat = -rDegQuad;
else if (Lat > rDegQuad)
Lat = rDegQuad;
fCast = fTrue;
/* Right button means draw lines if not in a world map mode. */
} else if (buttonx >= 0) {
MouseShow(fFalse);
DrawColor(coldrw);
PcMoveTo(buttonx, buttony);
PcLineTo(eventx, eventy);
}
/* Middle button (which most PC's don't have) means exit program. */
} else if (eventbtn == mfMiddle)
fBreak = fTrue;
mousex = eventx; mousey = eventy;
MouseShow(fTrue);
} else
#endif /* MOUSE */
if (kbhit()) {
key = getch();
#endif /* PCG */
#ifdef MACG
HiliteMenu(0);
SystemTask();
fEvent = GetNextEvent(everyEvent, &erCur);
if (fEvent) {
switch (erCur.what) {
case mouseDown:
wc = FindWindow(erCur.where, &wpCur);
switch (wc) {
case inSysWindow:
SystemClick(&erCur, wpCur);
break;
case inMenuBar:
MenuSelect(erCur.where);
break;
case inDrag:
if (wpCur == gi.wpAst)
DragWindow(gi.wpAst, erCur.where, &gi.rcDrag);
break;
case inContent:
if (wpCur == gi.wpAst && wpCur != FrontWindow())
SelectWindow(gi.wpAst);
break;
case inGoAway:
if (wpCur == gi.wpAst && TrackGoAway(gi.wpAst, erCur.where))
HideWindow(gi.wpAst);
break;
}
break;
case updateEvt:
/*fRedraw = fTrue;*/
break;
case keyDown:
case autoKey:
key = (byte)(erCur.message & charCodeMask);
#endif /* MACG */
LSwitch:
switch (key) {
#ifdef PCG
case chNull:
key = NFromAltN(getch());
goto LSwitch;
#endif
case ' ':
fRedraw = fTrue;
break;
case 'p':
not(fPause);
break;
case 'r':
neg(dir);
break;
case 'x':
not(gs.fInverse);
InitColorsX();
fRedraw = fTrue;
break;
case 'm':
if (!gi.fMono) {
not(gs.fColor);
#ifdef MSG
_getvideoconfig((struct videoconfig far *) &gi.cfg);
#endif
InitColorsX();
fRedraw = fTrue;
}
break;
case 'B':
#ifdef X11
XSetWindowBackgroundPixmap(gi.disp, gi.root, gi.pmap);
XClearWindow(gi.disp, gi.root);
#endif
#ifdef PCG
gs.xWin = xPcScreen;
gs.yWin = yPcScreen;
SquareX(&gs.xWin, &gs.yWin, fFalse);
fResize = fTrue;
#endif
break;
case 't':
not(gs.fText);
fRedraw = fTrue;
break;
case 'i':
not(gs.fAlt);
fRedraw = fTrue;
break;
case 'I':
not(InfoFlag);
fRedraw = fTrue;
break;
case 'b':
not(gs.fBorder);
fRedraw = fTrue;
break;
case 'l':
not(gs.fLabel);
fRedraw = fTrue;
break;
case 'j':
not(gs.fJetTrail);
break;
case '<':
if (gs.nScale > 100) {
gs.nScale -= 100;
fResize = fTrue;
}
break;
case '>':
if (gs.nScale < MAXSCALE) {
gs.nScale += 100;
fResize = fTrue;
}
break;
case '[':
if (gi.nMode == gGlobe && gs.rTilt > -rDegQuad) {
gs.rTilt = gs.rTilt > -rDegQuad ? gs.rTilt-TILTSTEP : -rDegQuad;
fRedraw = fTrue;
}
break;
case ']':
if (gi.nMode == gGlobe && gs.rTilt < rDegQuad) {
gs.rTilt = gs.rTilt < rDegQuad ? gs.rTilt+TILTSTEP : rDegQuad;
fRedraw = fTrue;
}
break;
case 'Q':
SquareX(&gs.xWin, &gs.yWin, fTrue);
fResize = fTrue;
break;
case 'R':
for (i = oChi; i <= oVes; i++)
not(ignore[i]);
for (i = oLil; i <= oEP; i++)