1 /*     WMGlobe 1.3  -  All the Earth on a WMaker Icon
2  *     copyright (C) 1998,99,2000,01 Jerome Dumonteil <jerome.dumonteil@linuxfr.org>
3  *
4  *     This program is free software; you can redistribute it and/or modify
5  *     it under the terms of the GNU General Public License as published by
6  *     the Free Software Foundation; either version 2 of the License, or
7  *     (at your option) any later version.
8  *
9  *     This program is distributed in the hope that it will be useful,
10  *     but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *     GNU General Public License for more details.
13  *
14  *     You should have received a copy of the GNU General Public License
15  *     along with this program; if not, write to the Free Software
16  *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  ***************************************************************************/
18 /*
19  * I used many functions  of wmgeneral.c ("openXwindow")
20  * for the main function of wmglobe.c
21  * wmgeneral.c was taken from wmaker applet wmtune-1.0 :
22  * Author: Martijn Pieterse (pieterse@xs4all.nl)
23  *
24  * wmglobe.c uses functions of : Xglobe, Xearth, wmgeneral, wmaker/wrlib
25  ***************************************************************************/
26 
27 #include "wmglobe.h"
28 #include "zapnum.xpm"
29 #include "zaptxt.xpm"
30 #include "zapnum.h"
31 #include "scrpos.xpm"
32 #include "scrtime.xpm"
33 #include "scrdiv.xpm"
34 
35 /*
36  * variables globales
37  */
38 
39 MOUSE_REGION mouse_region[MAX_MOUSE_REGION];
40 MPO *md[4], *mn[4];
41 int solution;
42 char *dayfile, *nightfile, *dpy_name;
43 XpmIcon screenpos, scrdate, scrdiv, numpix, txtpix, wmg;
44 int onlyshape, option_iw;
45 int nb_marker, sun_marker, moon_marker;
46 RColor sun_col, moon_col;
47 double delay, time_multi;
48 int sens, fun, funx, funy, oknimap, mratiox, mratioy, gotoscr;
49 int typecadre, p_type, use_nightmap, use_default_nightmap, use_nmap_ini,
50     firstTime, stoprand, do_something, iop;
51 double v_lat, v_long, old_dvlat, old_dvlong, dv_lat, dv_long;
52 double dlat, dlong, addlat, addlong, ratiox, ratioy, dawn;
53 double sun_lat;
54 double sun_long;
55 double fov;
56 double radius;
57 double proj_dist;		/* distance to projection plane */
58 double ambient_light;
59 double zoom;
60 RColor noir;
61 double minhz;
62 int stable;
63 
64 
65 
66 static void move_earth(double vla, double vlo);
67 static int flush_expose(Window w);
68 static void mqparam();
69 static double getdegre(char *val);
70 static void screen_1();
71 static void screen_2();
72 static void screen_3();
73 static void screen_4();
74 static void screen_5();
75 static void screen_6();
76 static void screen_7();
77 static void write_icon(char *txt, int x, int y);
78 static void chiffre(int ch, int xx, int yy);
79 static int lettre(char c, int xx, int yy);
80 static void display_pos(double la, double lo);
81 static void display_date(double la, double lo);
82 static void release_but(int ckm);
83 static void press_but(int ckm);
84 static void display_zoom();
85 static void display_light();
86 static void display_accel();
87 static void display_dlat();
88 static void display_type();
89 static void move_delay(int factor);
90 static void move_zoom(int factor);
91 static void move_light(int factor);
92 static void move_dawn(int factor);
93 static void move_accel(int factor);
94 static void move_dlat(int factor);
95 static void move_dlong(int factor);
96 
97 /**************************************************************************
98  *       TIME FUNCTIONS
99  *************************************************************************/
100 
diftimev(struct timeval t1,struct timeval t2)101 struct timeval diftimev(struct timeval t1, struct timeval t2)
102 {
103     t1.tv_usec -= t2.tv_usec;
104     if (t1.tv_usec < 0) {
105 	t1.tv_usec += 1000000;
106 	t1.tv_sec--;
107     }
108     t1.tv_sec -= t2.tv_sec;
109     return t1;
110 }
111 
112 
113 
addtimev(struct timeval t1,struct timeval t2)114 struct timeval addtimev(struct timeval t1, struct timeval t2)
115 {
116     t1.tv_usec += t2.tv_usec;
117     if (t1.tv_usec >= 1000000) {
118 	t1.tv_usec -= 1000000;
119 	t1.tv_sec++;
120     }
121     t1.tv_sec += t2.tv_sec;
122     return t1;
123 }
124 
125 
126 
getimev()127 struct timeval getimev()
128 {
129     struct timeval tv;
130     struct timezone tz;
131 
132     gettimeofday(&tv, &tz);
133     return tv;
134 }
135 
136 
137 /***************************************************************************
138  *     INIT FUNCTIONS
139  *
140  *  defaults, commandline
141  *  init of pixmap for screenpos and numbers displaying
142  ***************************************************************************/
143 
loadxpm(Window draw)144 void loadxpm(Window draw)
145 {
146     XpmCreatePixmapFromData(dpy, draw, scrpos_xpm, &(screenpos.pixmap),
147 			    &(screenpos.mask), &(screenpos.attributes));
148     XpmCreatePixmapFromData(dpy, draw, scrtime_xpm, &(scrdate.pixmap),
149 			    &(scrdate.mask), &(scrdate.attributes));
150     XpmCreatePixmapFromData(dpy, draw, zapnum_xpm, &(numpix.pixmap),
151 			    &(numpix.mask), &(numpix.attributes));
152     XpmCreatePixmapFromData(dpy, draw, zaptxt_xpm, &(txtpix.pixmap),
153 			    &(txtpix.mask), &(txtpix.attributes));
154     XpmCreatePixmapFromData(dpy, draw, scrdiv_xpm, &(scrdiv.pixmap),
155 			    &(scrdiv.mask), &(scrdiv.attributes));
156     return;
157 }
158 
159 
160 
161 
162 
163 
164 
set_defaults()165 void set_defaults()
166 {
167     stable = FALSE;
168     firstTime = TRUE;
169     dayfile = NULL;
170     use_nightmap = TRUE;
171     use_default_nightmap = FALSE;
172     nightfile = NULL;
173     oknimap = DEFAULT_NIGHTMAP;
174     p_type = PTSUN;
175     delay = DEFAULT_DELAY;
176     tini = getimev();
177     tbase = tini;
178     tsunpos = 0;
179     tlast.tv_sec = 0;
180     tlast.tv_usec = 0;
181     do_something = TRUE;
182     time_multi = 1.0;
183     v_lat = DEFAULT_V_LAT / 180. * PI;
184     v_long = DEFAULT_V_LONG / 180. * PI;
185     dv_lat = DEFAULT_V_LAT;
186     dv_long = DEFAULT_V_LONG;
187     old_dvlat = DEFAULT_V_LAT;
188     old_dvlong = DEFAULT_V_LONG;
189     iop = 0;
190     dlat = 0.0;
191     dlong = 0.0;
192     addlat = 0.0;
193     addlong = 0.0;
194     radius = 1000.0;
195     sun_long = 0.0;
196     sun_lat = 0.0;
197     fov = 0.5 * PI / 180.;
198     sens = DEFAULT_SENS;
199     zoom = DEFAULT_ZOOM;
200     ambient_light = DEFAULT_LIGHT;
201     dawn = DEFAULT_DAWN;
202     typecadre = DEFAULT_BORDER;
203     fun = FALSE;
204     funx = 0;
205     funy = 0;
206     dpy_name = NULL;
207     onlyshape = TRUE;
208     option_iw = WithdrawnState;
209     stoprand = FALSE;
210     solution = FALSE;
211     proj_dist = DIAMETRE / tan(fov);
212     noir.red = 0;
213     noir.green = 0;
214     noir.blue = 0;
215     noir.alpha = 255;
216 #if WITH_MARKERS
217     nb_marker = 0;
218     sun_marker = -1;
219     moon_marker = -1;
220     sun_col.red = CR_SUN_R;
221     sun_col.green = CR_SUN_G;
222     sun_col.blue = CR_SUN_B;
223     sun_col.alpha = 255;
224     moon_col.red = CR_MOON_R;
225     moon_col.green = CR_MOON_G;
226     moon_col.blue = CR_MOON_B;
227     moon_col.alpha = 255;
228 #endif
229     md[0] = (MPO *) malloc(sizeof(MPO));
230     md[1] = (MPO *) malloc(sizeof(MPO));
231     md[2] = (MPO *) malloc(sizeof(MPO));
232     md[3] = (MPO *) malloc(sizeof(MPO));
233     mn[0] = (MPO *) malloc(sizeof(MPO));
234     mn[1] = (MPO *) malloc(sizeof(MPO));
235     mn[2] = (MPO *) malloc(sizeof(MPO));
236     mn[3] = (MPO *) malloc(sizeof(MPO));
237 #ifdef DEBUG
238     minhz = 1.;
239 #endif
240     return;
241 }
242 
243 
244 
245 
getdegre(char * val)246 static double getdegre(char *val)
247 {
248     double d, m, s;
249     if (strchr(val, '�') != NULL || strchr(val, 'd') != NULL
250 	|| strchr(val, 'D') != NULL || strchr(val, ':') != NULL) {
251 	d = m = s = 0;
252 	sscanf(val, "%lf%*c%lf%*c%lf", &d, &m, &s);
253 	if (d >= 0.)
254 	    return d + m / 60. + s / 3600.;
255 	else
256 	    return d - m / 60. - s / 3600.;
257     } else {
258 	return atof(val);
259     }
260 }
261 
262 
263 
264 
mqparam()265 static void mqparam()
266 {
267     fprintf(stderr, "error in parameters\n");
268     exit(1);
269 }
270 
271 
272 
273 
274 
cmdline(int argc,char * argv[])275 void cmdline(int argc, char *argv[])
276 {
277     int i, j;
278 
279     if (argc > 0) {
280 	for (i = 1; i < argc; i++) {
281 	    j = 0;
282 
283 
284 	    if (strcasecmp(argv[i], "-v") == 0
285 		|| strcasecmp(argv[i], "-version") == 0) {
286 		printf("%s\n", WMGVERSION);
287 		exit(0);
288 	    }
289 
290 	    if (strcasecmp(argv[i], "-w") == 0
291 		|| strcasecmp(argv[i], "-wmaker") == 0) {
292 		option_iw = WithdrawnState;
293 		j = 1;
294 	    }
295 
296 	    if (strcasecmp(argv[i], "-i") == 0
297 		|| strcasecmp(argv[i], "-iconic") == 0) {
298 		option_iw = IconicState;
299 		j = 1;
300 	    }
301 
302 	    if (!j && (strcasecmp(argv[i], "-s") == 0 ||
303 		       strcasecmp(argv[i], "-shape") == 0)) {
304 		onlyshape = TRUE;
305 		j = 1;
306 	    }
307 
308 	    if (!j && (strcasecmp(argv[i], "-d") == 0
309 		       || strcasecmp(argv[i], "-display") == 0)) {
310 		i++;
311 		if (i < argc) {
312 		    j = 1;
313 		    dpy_name = argv[i];
314 		} else {
315 		    mqparam();
316 		    i--;
317 		}
318 	    }
319 
320 	    if (!j && (strcasecmp(argv[i], "-stable") == 0
321 		       || strcasecmp(argv[i], "-stab") == 0)) {
322 		stable = TRUE;
323 		j = 1;
324 	    }
325 
326 	    if (!j && (strcasecmp(argv[i], "-rand") == 0
327 		       || strcasecmp(argv[i], "-random") == 0)) {
328 		p_type = PTRANDOM;
329 		srandom(((int) time(NULL)) + ((int) getpid()));
330 		j = 1;
331 	    }
332 
333 	    if (!j && (strcasecmp(argv[i], "-sun") == 0
334 		       || strcasecmp(argv[i], "-soleil") == 0)) {
335 		p_type = PTSUN;
336 		j = 1;
337 	    }
338 
339 #if WITH_MARKERS
340 	    if (!j && (strcasecmp(argv[i], "-moon") == 0
341 		       || strcasecmp(argv[i], "-lune") == 0)) {
342 		p_type = PTMOON;
343 		j = 1;
344 	    }
345 #endif
346 
347 	    if (!j && (strcasecmp(argv[i], "-oz") == 0
348 		       || strcasecmp(argv[i], "-austral") == 0)) {
349 		sens = -1;
350 		j = 1;
351 	    }
352 
353 	    if (!j && strcasecmp(argv[i], "-map") == 0) {
354 
355 		i++;
356 		if (i < argc) {
357 		    j = 1;
358 		    free(dayfile);
359 		    if ((dayfile = (char *) malloc(strlen(argv[i]) + 1)) ==
360 			NULL) {
361 			fprintf(stderr, "erreur memoire options map\n");
362 			exit(1);
363 		    };
364 		    strcpy(dayfile, argv[i]);
365 		} else {
366 		    mqparam();
367 		    i--;
368 		}
369 	    }
370 
371 	    if (!j && (strcasecmp(argv[i], "-nimap") == 0
372 		       || strcasecmp(argv[i], "-nightmap") == 0
373 		       || strcasecmp(argv[i], "-night") == 0)) {
374 		i++;
375 		if (i < argc) {
376 		    j = 1;
377 		    free(nightfile);
378 		    if ((nightfile = (char *) malloc(strlen(argv[i]) + 1))
379 			== NULL) {
380 			fprintf(stderr, "erreur memoire options nimap\n");
381 			exit(1);
382 		    };
383 		    strcpy(nightfile, argv[i]);
384 		    use_nightmap = TRUE;
385 		} else {
386 		    mqparam();
387 		    i--;
388 		}
389 	    }
390 
391 	    if (!j && (strcasecmp(argv[i], "-accel") == 0
392 		       || strcasecmp(argv[i], "-accell") == 0
393 		       || strcasecmp(argv[i], "-acc") == 0
394 		       || strcasecmp(argv[i], "-multi") == 0)) {
395 		i++;
396 		if (i < argc) {
397 		    j = 1;
398 		    time_multi = atof(argv[i]);
399 		    if (time_multi < 1.0)
400 			time_multi = 1.0;
401 		    if (time_multi > MAX_MULTI_COEF)
402 			time_multi = MAX_MULTI_COEF;
403 		    if (time_multi > 24.0)
404 			time_multi = floor(time_multi);
405 		    else
406 			time_multi = floor(time_multi * 10.0) / 10.0;
407 		} else {
408 		    mqparam();
409 		    i--;
410 		}
411 	    }
412 
413 	    if (!j && (strcasecmp(argv[i], "-nonimap") == 0
414 		       || strcasecmp(argv[i], "-nonightmap") == 0
415 		       || strcasecmp(argv[i], "-nonight") == 0
416 		       || strcasecmp(argv[i], "-nomap") == 0)) {
417 		j = 1;
418 		use_nightmap = FALSE;
419 		oknimap = FALSE;
420 	    }
421 
422 	    if (!j && (strcasecmp(argv[i], "-defnimap") == 0
423 		       || strcasecmp(argv[i], "-defnightmap") == 0
424 		       || strcasecmp(argv[i], "-defnight") == 0)) {
425 		j = 1;
426 		use_default_nightmap = TRUE;
427 	    }
428 
429 	    if (!j && strcasecmp(argv[i], "-zoom") == 0) {
430 		i++;
431 		if (i < argc) {
432 		    j = 1;
433 		    zoom = atof(argv[i]);
434 		    if (zoom < ZOOM_MIN)
435 			zoom = ZOOM_MIN;
436 		    if (zoom > ZOOM_MAX)
437 			zoom = ZOOM_MAX;
438 		} else {
439 		    mqparam();
440 		    i--;
441 		}
442 	    }
443 
444 	    if (!j && strcasecmp(argv[i], "-dawn") == 0) {
445 		i++;
446 		if (i < argc) {
447 		    j = 1;
448 		    dawn = atof(argv[i]);
449 		    dawn = MAX(0.0, dawn);
450 		    dawn = MIN(1.0, dawn);
451 
452 		    dawn = (1.0 - dawn / 2.0);
453 		} else {
454 		    mqparam();
455 		    i--;
456 		}
457 	    }
458 
459 	    if (!j && strcasecmp(argv[i], "-delay") == 0) {
460 		i++;
461 		if (i < argc) {
462 		    j = 1;
463 		    delay = atof(argv[i]);
464 		    if (delay < 0)
465 			delay = 0;
466 		    if (delay > MAX_DELAY_SEC)
467 			delay = MAX_DELAY_SEC;
468 		} else {
469 		    mqparam();
470 		    i--;
471 		}
472 	    }
473 
474 	    if (!j && (strcasecmp(argv[i], "-dlat") == 0
475 		       || strcasecmp(argv[i], "-lat") == 0
476 		       || strcasecmp(argv[i], "-dlatitude") == 0)) {
477 		i++;
478 		if (i < argc) {
479 		    j = 1;
480 		    dlat = getdegre(argv[i]);
481 		    if (dlat < -MAX_DELTA_LONG)
482 			dlat = -MAX_DELTA_LONG;
483 		    if (dlat > MAX_DELTA_LONG)
484 			dlat = MAX_DELTA_LONG;
485 		    p_type = PTFIXED;
486 		} else {
487 		    mqparam();
488 		    i--;
489 		}
490 	    }
491 
492 	    if (!j && (strcasecmp(argv[i], "-dlong") == 0
493 		       || strcasecmp(argv[i], "-long") == 0
494 		       || strcasecmp(argv[i], "-dlongitude") == 0)) {
495 		i++;
496 		if (i < argc) {
497 		    j = 1;
498 		    dlong = getdegre(argv[i]);
499 		    if (dlong < -MAX_DELTA_LONG)
500 			dlong = -MAX_DELTA_LONG;
501 		    if (dlong > MAX_DELTA_LONG)
502 			dlong = MAX_DELTA_LONG;
503 		    p_type = PTFIXED;
504 		} else {
505 		    mqparam();
506 		    i--;
507 		}
508 	    }
509 
510 	    if (!j && strcasecmp(argv[i], "-light") == 0) {
511 		i++;
512 		if (i < argc) {
513 		    j = 1;
514 		    ambient_light = atof(argv[i]);
515 		    if (ambient_light < 0.)
516 			ambient_light = 0.;
517 		    if (ambient_light > 1.)
518 			ambient_light = 1.;
519 		} else {
520 		    mqparam();
521 		    i--;
522 		}
523 	    }
524 
525 	    if (!j && strcasecmp(argv[i], "-time") == 0) {
526 		i++;
527 		if (i < argc) {
528 		    j = 1;
529 		    tbase.tv_sec = atoi(argv[i]);
530 		    tbase.tv_usec = 0;
531 		} else {
532 		    mqparam();
533 		    i--;
534 		}
535 	    }
536 
537 	    if (!j && (strcasecmp(argv[i], "-bord") == 0
538 		       || strcasecmp(argv[i], "-border") == 0)) {
539 		i++;
540 		if (i < argc) {
541 		    j = 1;
542 		    typecadre = atoi(argv[i]);
543 		    if (typecadre < 0)
544 			typecadre = 0;
545 		    if (typecadre > 2)
546 			typecadre = 2;
547 		} else {
548 		    mqparam();
549 		    i--;
550 		}
551 	    }
552 
553 	    if (!j && strcasecmp(argv[i], "-fun") == 0) {
554 		fun = TRUE;
555 		i++;
556 		if (i < argc) {
557 		    funx = atoi(argv[i]);
558 
559 		    i++;
560 		    if (i < argc) {
561 			j = 1;
562 			funy = atoi(argv[i]);
563 		    } else {
564 			mqparam();
565 			i--;
566 		    }
567 		} else {
568 		    mqparam();
569 		    i--;
570 		}
571 	    }
572 
573 	    if (!j && (strcasecmp(argv[i], "-pos") == 0
574 		       || strcasecmp(argv[i], "-position") == 0
575 		       || strcasecmp(argv[i], "-fixed") == 0)) {
576 		p_type = PTFIXED;
577 		i++;
578 		if (i < argc) {
579 		    addlat = getdegre(argv[i]);
580 		    i++;
581 		    if (i < argc) {
582 			j = 1;
583 			addlong = getdegre(argv[i]);
584 		    } else {
585 			mqparam();
586 			i--;
587 		    }
588 		} else {
589 		    mqparam();
590 		    i--;
591 		}
592 	    }
593 
594 #if WITH_MARKERS
595 	    if (!j && (strcasecmp(argv[i], "-mk") == 0
596 		       || strcasecmp(argv[i], "-marker") == 0)) {
597 		if (nb_marker == MAX_MARKERS) {
598 		    fprintf(stderr, "Too many markers, max=%d\n",
599 			    MAX_MARKERS);
600 		    mqparam();
601 		}
602 		i++;
603 		if (i < argc) {
604 		    j = 1;
605 		    if (strcasecmp(argv[i], "sun") == 0) {
606 			sun_marker = nb_marker;
607 			nb_marker++;
608 		    } else if (strcasecmp(argv[i], "moon") == 0) {
609 			moon_marker = nb_marker;
610 			nb_marker++;
611 		    } else {
612 			marker[nb_marker][1] = getdegre(argv[i]);
613 			i++;
614 			if (i < argc) {
615 			    marker[nb_marker][0] = getdegre(argv[i]);
616 			    nb_marker++;
617 			} else {
618 			    mqparam();
619 			    i--;
620 			}
621 		    }
622 		} else {
623 		    mqparam();
624 		    i--;
625 		}
626 	    }
627 #endif
628 
629 
630 	    if (!j && argv[i][0] == '-') {
631 		printf("%s\n", WMGVERSION);
632 		printf("\n");
633 		printf
634 		    ("-v                  : version         -h : this help message !\n");
635 		printf
636 		    ("-zoom   zoom_value  : changing apparent size in icon\n");
637 		printf
638 		    ("-pos latitude long. : fixed initial position (default=follow sun)\n");
639 		printf("-sun                : follow the sun (default)\n");
640 #if WITH_MARKERS
641 		printf("-moon               : follow the moon\n");
642 #endif
643 		printf
644 		    ("-rand               : random position at every refresh\n");
645 		printf
646 		    ("-map    map_file    : use this map for rendering\n");
647 		printf
648 		    ("-nimap  night_file  : and this one for the dark side of earth\n");
649 		printf
650 		    ("-defnimap           : use the default night map (with a custom map)\n");
651 		printf
652 		    ("-nonimap            : don't use the default night map\n");
653 		printf
654 		    ("-delay  seconds     : time between refresh of image\n");
655 		printf
656 		    ("-dlat   delta_lat   : latitude speed of point of view (default=follow sun)\n");
657 		printf("-dlong  delta_long  : the same for longitude\n");
658 		printf
659 		    ("-light  light_value : level of light for dark side of earth, [0..1]\n");
660 		printf
661 		    ("-dawn   dawn_value  : level of continuity for dawn limit\n");
662 		printf
663 		    ("-bord   border_num  : 0 1 or 2 , type of icon border.\n");
664 		printf("-accel  time_multi  : time accelerator\n");
665 		printf
666 		    ("-time   seconds     : time to display in seconds since 01-01-1970\n");
667 		printf
668 		    ("-oz                 : start in \"austral\" mode (for \"down under\" people)\n");
669 		printf
670 		    ("-stable             : keep the globe from going over the poles\n");
671 #if WITH_MARKERS
672 		printf
673 		    ("-mk  latitude long. : position of a marker (or \"sun\", \"moon\")\n");
674 #endif
675 		printf
676 		    ("-fun    dx  dy      : offset of vision... almost useless\n");
677 		printf
678 		    ("-w  -shape          : set by default (WMaker dockable application)\n");
679 		printf
680 		    ("-d      display     : display (WindowMaker not needed on the server side)\n");
681 		printf
682 		    ("left button         : change longitude, with shift key, change latitude too\n");
683 		printf
684 		    ("middle button       : zoom in, shift + middle button : zoom out\n");
685 		printf
686 		    ("right button        : access to a few screens of parameters\n");
687 		exit(0);
688 	    }
689 
690 	}
691     }
692     return;
693 }
694 
695 /****************************************************************************
696  * X functions, mouse selection
697  *
698  ****************************************************************************/
699 
700 
flush_expose(Window w)701 static int flush_expose(Window w)
702 {
703     XEvent dummy;
704     int i = 0;
705 
706     while (XCheckTypedWindowEvent(dpy, w, Expose, &dummy))
707 	i++;
708     return i;
709 }
710 
711 
712 
RedrawWindowXYWH(int x,int y,int w,int h)713 void RedrawWindowXYWH(int x, int y, int w, int h)
714 {
715     flush_expose(iconwin);
716     XCopyArea(dpy, wmg.pixmap, iconwin, NormalGC, x, y, w, h, x, y);
717     flush_expose(win);
718     XCopyArea(dpy, wmg.pixmap, win, NormalGC, x, y, w, h, x, y);
719     return;
720 }
721 
722 
723 
AddMouseRegion(int index,int left,int top,int right,int bottom)724 void AddMouseRegion(int index, int left, int top, int right, int bottom)
725 {
726     if (index < MAX_MOUSE_REGION) {
727 	mouse_region[index].enable = 1;
728 	mouse_region[index].top = top;
729 	mouse_region[index].left = left;
730 	mouse_region[index].bottom = bottom;
731 	mouse_region[index].right = right;
732     }
733     return;
734 }
735 
736 
737 
CheckMouseRegion(int x,int y)738 int CheckMouseRegion(int x, int y)
739 {
740     int i;
741     int found;
742 
743     found = 0;
744 
745     for (i = 0; i < MAX_MOUSE_REGION && !found; i++) {
746 	if (mouse_region[i].enable &&
747 	    x <= mouse_region[i].right &&
748 	    x >= mouse_region[i].left &&
749 	    y <= mouse_region[i].bottom && y >= mouse_region[i].top)
750 	    found = 1;
751     }
752     if (!found)
753 	return -1;
754     return (i - 1);
755 }
756 
757 
758 
759 /****************************************************************************
760  * GRAPHIC : pixmap writing of letters & numbers
761  *
762  ****************************************************************************/
763 
chiffre(int ch,int xx,int yy)764 static void chiffre(int ch, int xx, int yy)
765 {
766     XCopyArea(dpy, numpix.pixmap, wmg.pixmap, NormalGC,
767 	      zapnum[ch][0], zapnum[ch][1], zapnum[ch][2], zapnum[ch][3],
768 	      xx, yy);
769 
770     return;
771 }
772 
773 
lettre(char c,int xx,int yy)774 static int lettre(char c, int xx, int yy)
775 {
776     int i;
777     if (c == '�')
778 	i = 288;
779     else
780 	switch (toupper(c)) {
781 	case '0':
782 	    i = 0;
783 	    break;
784 	case '1':
785 	    i = 6;
786 	    break;
787 	case '2':
788 	    i = 12;
789 	    break;
790 	case '3':
791 	    i = 18;
792 	    break;
793 	case '4':
794 	    i = 24;
795 	    break;
796 	case '5':
797 	    i = 30;
798 	    break;
799 	case '6':
800 	    i = 36;
801 	    break;
802 	case '7':
803 	    i = 42;
804 	    break;
805 	case '8':
806 	    i = 48;
807 	    break;
808 	case '9':
809 	    i = 54;
810 	    break;
811 	case '+':
812 	    i = 60;
813 	    break;
814 	case 'A':
815 	    i = 66;
816 	    break;
817 	case 'B':
818 	    i = 72;
819 	    break;
820 	case 'C':
821 	    i = 78;
822 	    break;
823 	case 'D':
824 	    i = 84;
825 	    break;
826 	case 'E':
827 	    i = 90;
828 	    break;
829 	case 'F':
830 	    i = 96;
831 	    break;
832 	case 'G':
833 	    i = 102;
834 	    break;
835 	case 'H':
836 	    i = 108;
837 	    break;
838 	case 'I':
839 	    i = 114;
840 	    break;
841 	case 'J':
842 	    i = 120;
843 	    break;
844 	case 'K':
845 	    i = 126;
846 	    break;
847 	case 'L':
848 	    i = 132;
849 	    break;
850 	case 'M':
851 	    i = 138;
852 	    break;
853 	case 'N':
854 	    i = 144;
855 	    break;
856 	case 'O':
857 	    i = 150;
858 	    break;
859 	case 'P':
860 	    i = 156;
861 	    break;
862 	case 'Q':
863 	    i = 162;
864 	    break;
865 	case 'R':
866 	    i = 168;
867 	    break;
868 	case 'S':
869 	    i = 174;
870 	    break;
871 	case 'T':
872 	    i = 180;
873 	    break;
874 	case 'U':
875 	    i = 186;
876 	    break;
877 	case 'V':
878 	    i = 192;
879 	    break;
880 	case 'W':
881 	    i = 198;
882 	    break;
883 	case 'X':
884 	    i = 204;
885 	    break;
886 	case 'Y':
887 	    i = 210;
888 	    break;
889 	case 'Z':
890 	    i = 216;
891 	    break;
892 	case ' ':
893 	    i = 222;
894 	    break;
895 	case ':':
896 	    i = 228;
897 	    break;
898 	case '/':
899 	    i = 234;
900 	    break;
901 	case '!':
902 	    i = 240;
903 	    break;
904 	case '*':
905 	    i = 246;
906 	    break;
907 	case '-':
908 	    i = 252;
909 	    break;
910 	case '.':
911 	    i = 258;
912 	    break;
913 	case '=':
914 	    i = 264;
915 	    break;
916 	case '#':
917 	    i = 270;
918 	    break;
919 	case '<':
920 	    i = 276;
921 	    break;
922 	case '>':
923 	    i = 282;
924 	    break;
925 	case '"':
926 	    i = 294;
927 	    break;
928 	case '\'':
929 	    i = 300;
930 	    break;
931 	case ',':
932 	    i = 306;
933 	    break;
934 	case '@':
935 	    i = 312;
936 	    break;
937 	case '(':
938 	    i = 318;
939 	    break;
940 	case ')':
941 	    i = 324;
942 	    break;
943 	case '&':
944 	    i = 330;
945 	    break;
946 	case '~':
947 	    i = 336;
948 	    break;
949 	case '�':
950 	    i = 342;
951 	    break;
952 	case '�':
953 	    i = 348;
954 	    break;
955 	case '{':
956 	    i = 354;
957 	    break;
958 	case '}':
959 	    i = 360;
960 	    break;
961 	case '[':
962 	    i = 366;
963 	    break;
964 	case ']':
965 	    i = 372;
966 	    break;
967 	case '\\':
968 	    i = 378;
969 	    break;
970 	case '|':
971 	    i = 384;
972 	    break;
973 	case '?':
974 	    i = 390;
975 	    break;
976 	case '%':
977 	    i = 396;
978 	    break;
979 	default:
980 	    i = 222;
981 	    break;
982 	}
983 
984     XCopyArea(dpy, txtpix.pixmap, wmg.pixmap, NormalGC,
985 	      i, 0, 6, 10, xx, yy);
986     return xx + 6;
987 }
988 
989 
990 
write_icon(char * txt,int x,int y)991 static void write_icon(char *txt, int x, int y)
992 {
993     int p, ok;
994     p = 0;
995 
996 #ifdef DEBUG
997     fprintf(stdout, "%s_\n", txt);
998 #endif
999     ok = TRUE;
1000     while (ok) {
1001 	if (txt[p] == '\0' || x > DIAMETRE - 5) {
1002 	    ok = FALSE;
1003 	} else {
1004 	    x = lettre(txt[p], x, y);
1005 	    p++;
1006 	}
1007     }
1008     return;
1009 }
1010 
1011 
1012 
press_but(int ckm)1013 static void press_but(int ckm)
1014 {
1015     switch (ckm) {
1016     case 5:
1017 	XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
1018 		  0, 38, 20, 9, 2, 52);
1019 	RedrawWindowXYWH(2, 52, 20, 9);
1020 	break;
1021     case 6:
1022 	XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
1023 		  20, 38, 20, 9, 22, 52);
1024 	RedrawWindowXYWH(22, 52, 20, 9);
1025 	break;
1026     case 7:
1027 	XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
1028 		  40, 38, 20, 9, 42, 52);
1029 	RedrawWindowXYWH(42, 52, 20, 9);
1030 	break;
1031     default:
1032 	break;
1033     }
1034     return;
1035 }
1036 
1037 
1038 
release_but(int ckm)1039 static void release_but(int ckm)
1040 {
1041     switch (ckm) {
1042     case 5:
1043 	XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
1044 		  0, 28, 20, 9, 2, 52);
1045 	RedrawWindowXYWH(2, 52, 20, 9);
1046 	break;
1047     case 6:
1048 	XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
1049 		  20, 28, 20, 9, 22, 52);
1050 	RedrawWindowXYWH(22, 52, 20, 9);
1051 	break;
1052     case 7:
1053 	XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
1054 		  40, 28, 20, 9, 42, 52);
1055 	RedrawWindowXYWH(42, 52, 20, 9);
1056 	break;
1057     default:
1058 	break;
1059     }
1060     return;
1061 }
1062 
1063 
1064 
1065 
1066 /***************************************************************************
1067  * MENU SELECTION & ACTIONS
1068  ***************************************************************************/
1069 
1070 
screen_back()1071 void screen_back()
1072 {
1073     AddMouseRegion(0, 0, 0, 0, 0);
1074     if (p_type == PTRANDOM) {
1075 	stoprand = STOP_RANDOM_FACTOR;
1076 	addlong = dv_long;
1077 	addlat = dv_lat;
1078     }
1079     gotoscr = 1;
1080     while (gotoscr != 0) {
1081 	switch (gotoscr) {
1082 	case 1:
1083 	    screen_1();
1084 	    break;
1085 	case 2:
1086 	    screen_2();
1087 	    break;
1088 	case 3:
1089 	    screen_3();
1090 	    break;
1091 	case 4:
1092 	    screen_4();
1093 	    break;
1094 	case 5:
1095 	    screen_5();
1096 	    break;
1097 	case 6:
1098 	    screen_6();
1099 	    break;
1100 	case 7:
1101 	    screen_7();
1102 	    break;
1103 	default:
1104 	    break;
1105 	}
1106 	XFlush(dpy);
1107     }
1108 /*
1109  * put old environment
1110  */
1111     XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, pixmask, ShapeSet);
1112     XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, pixmask,
1113 		      ShapeSet);
1114 
1115     AddMouseRegion(0, 5, 5, DIAMETRE - 4, DIAMETRE - 4);
1116     stoprand = FALSE;
1117     do_something = TRUE;
1118 
1119     return;
1120 }
1121 
1122 
1123 
display_pos(double la,double lo)1124 static void display_pos(double la, double lo)
1125 {
1126     int c, i, j, k, l, neg;
1127 
1128     if (la > 0) {
1129 	neg = 10;
1130     } else {
1131 	neg = 11;
1132 	la *= -1;
1133     }
1134     i = floor(la / 10.0);
1135     la -= 10 * i;
1136     j = floor(la);
1137     la -= j;
1138     la *= 60;
1139     k = floor(la / 10.0);
1140     la -= 10 * k;
1141     l = floor(la);
1142 
1143     if (i == 0) {
1144 	i = neg;
1145 	neg = 10;
1146     }
1147     chiffre(neg, platd[1][0], platd[1][1]);
1148     chiffre(i, platd[2][0], platd[2][1]);
1149     chiffre(j, platd[3][0], platd[3][1]);
1150     chiffre(k, platm[0][0], platd[0][1]);
1151     chiffre(l, platm[1][0], platd[1][1]);
1152 
1153     if (lo > 0) {
1154 	neg = 12;
1155     } else {
1156 	neg = 11;
1157 	lo *= -1;
1158     }
1159     c = floor(lo / 100.0);
1160     lo -= c * 100;
1161     if (c > 0) {
1162 	if (neg == 11)
1163 	    neg = 13;
1164     } else {
1165 	if (neg == 11) {
1166 	    c = neg;
1167 	} else {
1168 	    c = 10;
1169 	}
1170 	neg = 12;
1171     }
1172     i = floor(lo / 10.0);
1173     lo -= 10 * i;
1174     j = floor(lo);
1175     lo -= j;
1176     lo *= 60;
1177     k = floor(lo / 10.0);
1178     lo -= 10 * k;
1179     l = floor(lo);
1180     if (i == 0 && c > 9) {
1181 	i = c;
1182 	c = 10;
1183     }
1184     chiffre(neg, plongd[0][0], plongd[0][1]);
1185     chiffre(c, plongd[1][0], plongd[1][1]);
1186     chiffre(i, plongd[2][0], plongd[2][1]);
1187     chiffre(j, plongd[3][0], plongd[3][1]);
1188     chiffre(k, plongm[0][0], plongm[0][1]);
1189     chiffre(l, plongm[1][0], plongm[1][1]);
1190 
1191     RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE);
1192     return;
1193 }
1194 
1195 
1196 
rotation_terre(int x,int y,int lat_flag)1197 void rotation_terre(int x, int y, int lat_flag)
1198 {
1199 /*
1200  * earth rotate after (while) a clic
1201  */
1202     double mx, my;
1203     mx =
1204 	(double) ((double) x - DIAMETRE / 2 +
1205 		  0.5) / zoom * cos(v_lat) * sens;
1206     if (lat_flag) {
1207 	my = -(double) ((double) y - DIAMETRE / 2 + 0.5) * sens / zoom;
1208 	if (my > 0.0)
1209 	    my +=
1210 		ABS(sin(v_lat) * ((double) x - DIAMETRE / 2 + 0.5) / zoom);
1211 	else
1212 	    my -=
1213 		ABS(sin(v_lat) * ((double) x - DIAMETRE / 2 + 0.5) / zoom);
1214     } else {
1215 	my = 0;
1216     }
1217     if (p_type == PTRANDOM) {
1218 	stoprand = STOP_RANDOM_FACTOR;
1219 	addlong = dv_long;
1220 	addlat = dv_lat;
1221     }
1222     addlong += mx * RATIO_ROTATE;
1223     addlat += my * RATIO_ROTATE;
1224 
1225     do_something = TRUE;
1226     return;
1227 }
1228 
1229 
1230 
move_earth(double vla,double vlo)1231 static void move_earth(double vla, double vlo)
1232 {
1233     addlat += vla;
1234     addlong += vlo;
1235 
1236 
1237     switch (p_type) {
1238     case PTSUN:
1239 	setViewPos(sun_lat * 180. / PI + addlat,
1240 		   sun_long * 180. / PI + addlong);
1241 	break;
1242 #if WITH_MARKERS
1243     case PTMOON:
1244 	setViewPos(moon_lat * 180. / PI + addlat,
1245 		   moon_long * 180. / PI + addlong);
1246 	break;
1247 #endif
1248     case PTFIXED:
1249     case PTRANDOM:
1250 	setViewPos(addlat, addlong);
1251 	break;
1252     default:
1253 	break;
1254     }
1255     display_pos(dv_lat, dv_long);
1256     return;
1257 }
1258 
1259 
1260 
screen_1()1261 static void screen_1()
1262 {
1263     int ok, ckm, sensadd, waitrel, not3;
1264     struct timeval tin;
1265 
1266 #ifdef DEBUG
1267     fprintf(stdout, "scr 1\n");
1268 #endif
1269     tin = getimev();
1270     waitrel = 0;
1271     ckm = 0;
1272     sensadd = 1;
1273     not3 = TRUE;
1274 
1275     XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, screenpos.mask,
1276 		      ShapeSet);
1277     XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, screenpos.mask,
1278 		      ShapeSet);
1279 
1280     XCopyArea(dpy, screenpos.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE,
1281 	      DIAMETRE, 0, 0);
1282 
1283     AddMouseRegion(1, platd[0][0], platd[0][1], platd[3][0] + 9,
1284 		   platd[3][1] + 12);
1285     AddMouseRegion(2, platm[0][0], platm[0][1], platm[1][0] + 9,
1286 		   platm[1][1] + 12);
1287     AddMouseRegion(3, plongd[0][0], plongd[0][1], plongd[3][0] + 9,
1288 		   plongd[3][1] + 12);
1289     AddMouseRegion(4, plongm[0][0], plongm[0][1], plongm[1][0] + 9,
1290 		   plongm[1][1] + 12);
1291     AddMouseRegion(5, 1, 51, 21, 61);
1292     AddMouseRegion(6, 22, 51, 41, 61);
1293     AddMouseRegion(7, 42, 51, 62, 61);
1294 
1295     display_pos(dv_lat, dv_long);
1296 
1297     ok = TRUE;
1298     while (ok) {
1299 	while (XPending(dpy)) {
1300 	    XNextEvent(dpy, &Event);
1301 	    switch (Event.type) {
1302 	    case Expose:
1303 		RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE);
1304 		break;
1305 	    case DestroyNotify:
1306 		XCloseDisplay(dpy);
1307 		exit(0);
1308 		break;
1309 	    case ButtonPress:
1310 		ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
1311 		waitrel = 1;
1312 		press_but(ckm);
1313 		switch (Event.xbutton.button) {
1314 		case 1:
1315 		    not3 = TRUE;
1316 		    sensadd = 1;
1317 		    break;
1318 		case 2:
1319 		    not3 = TRUE;
1320 		    sensadd = -1;
1321 		    break;
1322 		case 3:
1323 		    not3 = FALSE;
1324 		    if (ckm < 5)
1325 			gotoscr = 0;
1326 		default:
1327 		    break;
1328 		}
1329 		break;
1330 	    case ButtonRelease:
1331 		release_but(ckm);
1332 		waitrel = ckm;
1333 		ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
1334 		if (waitrel == ckm) {
1335 		    switch (ckm) {
1336 		    case 5:
1337 			gotoscr--;
1338 			if (gotoscr == 0)
1339 			    gotoscr = NUM_SCREEN;
1340 			break;
1341 		    case 6:
1342 			gotoscr++;
1343 			if (gotoscr > NUM_SCREEN)
1344 			    gotoscr = 1;
1345 			break;
1346 		    case 7:
1347 			gotoscr = 0;
1348 		    default:
1349 			break;
1350 		    }
1351 		}
1352 		ckm = 0;
1353 		waitrel = 0;
1354 		tin = getimev();
1355 		break;
1356 	    default:
1357 		break;
1358 
1359 	    }
1360 	}
1361 	usleep(VAL_USLEEP_SHORT);
1362 	if (waitrel && not3) {
1363 	    if (ckm == 1) {
1364 		move_earth(sens * sensadd * 1.0, 0.0);
1365 		usleep(VAL_USLEEP);
1366 	    }
1367 	    if (ckm == 2) {
1368 		move_earth(sens * sensadd * 1.0 / 60.0, 0.0);
1369 		usleep(VAL_USLEEP);
1370 	    }
1371 	    if (ckm == 3) {
1372 		move_earth(0.0, sens * sensadd * 1.0);
1373 		usleep(VAL_USLEEP);
1374 	    }
1375 	    if (ckm == 4) {
1376 		move_earth(0.0, sens * sensadd * 1.0 / 60.0);
1377 		usleep(VAL_USLEEP);
1378 	    }
1379 	}
1380 	if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT
1381 	    && gotoscr == 1)
1382 	    gotoscr = 0;
1383 	if (gotoscr != 1)
1384 	    ok = FALSE;
1385     }
1386     return;
1387 }
1388 
1389 
1390 
display_date(double la,double lo)1391 static void display_date(double la, double lo)
1392 {
1393     char datest[32];
1394     time_t t;
1395     int i, j;
1396 
1397     write_icon(" time :", 2, 2);
1398     RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1);
1399 
1400     write_icon(" GMT+long.", 2, 14);
1401     RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1);
1402 
1403     t = trend.tv_sec;
1404     t += (int) (floor((lo + 7.5) / 15.0) * 3600);
1405 /*** pb near 2038 ***/
1406 
1407     strftime(datest, 30, "%x", gmtime(&t));
1408 
1409     i = 10 - strlen(datest);
1410     if (i < 0)
1411 	i = 0;
1412     else
1413 	i = i / 2;
1414 
1415     write_icon(datest, 2 + i * 6, 26);
1416     RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1);
1417 
1418     strftime(datest, 30, "%X", gmtime(&t));
1419 
1420     i = 10 - strlen(datest);
1421     if (i < 0) {
1422 	i = 0;
1423 	while (datest[i] != '\0') {
1424 	    if (datest[i] != ' ') {
1425 		i++;
1426 	    } else {
1427 		j = i;
1428 		do {
1429 		    datest[j] = datest[j + 1];
1430 		    j++;
1431 		}
1432 		while (datest[j - 1] != '\0');
1433 	    }
1434 	}
1435 	i = 0;
1436     } else {
1437 	i = i / 2;
1438     }
1439 
1440     write_icon(datest, 2 + i * 6, 38);
1441     RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1);
1442 
1443     return;
1444 }
1445 
1446 
1447 
screen_2()1448 static void screen_2()
1449 {
1450     int ok, ckm, waitrel;
1451     struct timeval tin;
1452 
1453 #ifdef DEBUG
1454     fprintf(stdout, "scr 2\n");
1455 #endif
1456     tin = getimev();
1457     waitrel = 0;
1458     ckm = 0;
1459 
1460     XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask,
1461 		      ShapeSet);
1462     XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask,
1463 		      ShapeSet);
1464 
1465     XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE,
1466 	      DIAMETRE, 0, 0);
1467 
1468     display_date(dv_lat, dv_long);
1469 
1470     ok = TRUE;
1471     while (ok) {
1472 	while (XPending(dpy)) {
1473 	    XNextEvent(dpy, &Event);
1474 	    switch (Event.type) {
1475 	    case Expose:
1476 		RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE);
1477 		break;
1478 	    case DestroyNotify:
1479 		XCloseDisplay(dpy);
1480 		exit(0);
1481 		break;
1482 	    case ButtonPress:
1483 		ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
1484 		waitrel = 1;
1485 		press_but(ckm);
1486 		switch (Event.xbutton.button) {
1487 		case 1:
1488 		    break;
1489 		case 2:
1490 		    break;
1491 		case 3:
1492 		    if (ckm < 5)
1493 			gotoscr = 0;
1494 		    break;
1495 		default:
1496 		    break;
1497 		}
1498 		break;
1499 	    case ButtonRelease:
1500 		release_but(ckm);
1501 		waitrel = ckm;
1502 		ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
1503 		if (waitrel == ckm) {
1504 		    switch (ckm) {
1505 		    case 5:
1506 			gotoscr--;
1507 			if (gotoscr == 0)
1508 			    gotoscr = NUM_SCREEN;
1509 			break;
1510 		    case 6:
1511 			gotoscr++;
1512 			if (gotoscr > NUM_SCREEN)
1513 			    gotoscr = 1;
1514 			break;
1515 		    case 7:
1516 			gotoscr = 0;
1517 		    default:
1518 			break;
1519 		    }
1520 		}
1521 		ckm = 0;
1522 		waitrel = 0;
1523 		tin = getimev();
1524 		break;
1525 	    default:
1526 		break;
1527 
1528 	    }
1529 	}
1530 	usleep(VAL_USLEEP_SHORT);
1531 
1532 	if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT
1533 	    && gotoscr == 2)
1534 	    gotoscr = 0;
1535 	if (gotoscr != 2)
1536 	    ok = FALSE;
1537     }
1538     return;
1539 }
1540 
1541 
1542 
display_zoom()1543 static void display_zoom()
1544 {
1545     char datest[32], dstr[32];
1546     int i;
1547 
1548     write_icon(" delay :", 2, 2);
1549     RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1);
1550 
1551     sprintf(dstr, "%f", delay);
1552     dstr[8] = '\0';
1553     i = strlen(dstr) - 1;
1554     while (i > 0) {
1555 	if (dstr[i] == '0') {
1556 	    dstr[i] = '\0';
1557 	    i--;
1558 	} else {
1559 	    i = 0;
1560 	}
1561     }
1562     i = strlen(dstr) - 1;
1563     if (dstr[i] == '.')
1564 	dstr[i] = '\0';
1565     sprintf(datest, "%s s", dstr);
1566 
1567     i = 10 - strlen(datest);
1568     if (i < 0)
1569 	i = 0;
1570     else
1571 	i = i / 2;
1572     write_icon(datest, 2 + i * 6, 14);
1573     RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1);
1574 
1575     write_icon(" zoom :", 2, 26);
1576     RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1);
1577 
1578     sprintf(datest, "%.3f", zoom);
1579     i = 10 - strlen(datest);
1580     if (i < 0)
1581 	i = 0;
1582     else
1583 	i = i / 2;
1584     write_icon(datest, 2 + i * 6, 38);
1585     RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1);
1586 
1587     return;
1588 }
1589 
1590 
1591 
move_delay(int factor)1592 static void move_delay(int factor)
1593 {
1594     if (factor == 1) {
1595 	if (delay < (double) VAL_USLEEP / 1000000)
1596 	    delay = (double) VAL_USLEEP / 1000000;
1597 	else if (delay < 0.1) {
1598 	    delay += 0.01;
1599 	    if (delay > 0.1)
1600 		delay = 0.2;
1601 	} else if (delay < 1.) {
1602 	    delay += 0.1;
1603 	    if (delay > 1.0)
1604 		delay = 2.;
1605 	} else if (delay < 60.)
1606 	    delay += 1.;
1607 	else if (delay < 300.)
1608 	    delay += 10.;
1609 	else if (delay < 3600.)
1610 	    delay += 60.;
1611 	else if (delay < MAX_DELAY_SEC)
1612 	    delay += 360.;
1613 
1614 	if (delay > MAX_DELAY_SEC)
1615 	    delay = MAX_DELAY_SEC;
1616     } else {
1617 	if (delay > 3600.)
1618 	    delay -= 360.;
1619 	else if (delay > 300.)
1620 	    delay -= 60.;
1621 	else if (delay > 60.)
1622 	    delay -= 10.;
1623 	else if (delay > 1.)
1624 	    delay -= 1.;
1625 	else if (delay > 0.1)
1626 	    delay -= 0.1;
1627 	else if (delay > (double) VAL_USLEEP / 1000000)
1628 	    delay -= 0.01;
1629 	else
1630 	    delay = 0.0;
1631 
1632 	if (delay < (double) VAL_USLEEP / 1000000)
1633 	    delay = 0.0;
1634     }
1635 
1636     tdelay.tv_sec = (int) floor(delay);
1637     tdelay.tv_usec = (int) ((delay - tdelay.tv_sec) * 1000000);
1638 
1639     XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
1640 	      0, 15, 60, 10, 2, 14);
1641 
1642     display_zoom();
1643     return;
1644 }
1645 
1646 
1647 
zooming(int facto)1648 void zooming(int facto)
1649 {
1650     if (facto)
1651 	zoom /= ZOOM_FACTOR;
1652     else
1653 	zoom *= ZOOM_FACTOR;
1654     zoom = MAX(zoom, ZOOM_MIN);
1655     zoom = MIN(zoom, ZOOM_MAX);
1656     if (p_type == PTRANDOM) {
1657 	addlong = dv_long;
1658 	addlat = dv_lat;
1659 	stoprand = STOP_RANDOM_FACTOR;
1660     }
1661     calcDistance();
1662     do_something = TRUE;
1663     return;
1664 }
1665 
1666 
1667 
move_zoom(int factor)1668 static void move_zoom(int factor)
1669 {
1670     if (factor == -1)
1671 	zooming(1);
1672     else
1673 	zooming(0);
1674     XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
1675 	      0, 15, 60, 10, 2, 38);
1676     display_zoom();
1677     return;
1678 }
1679 
1680 
1681 
screen_3()1682 static void screen_3()
1683 {
1684     int ok, ckm, waitrel, sensadd, not3;
1685     struct timeval tin;
1686 
1687 #ifdef DEBUG
1688     fprintf(stdout, "scr 3\n");
1689 #endif
1690     tin = getimev();
1691     waitrel = 0;
1692     ckm = 0;
1693     sensadd = 0;
1694     not3 = TRUE;
1695     XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask,
1696 		      ShapeSet);
1697     XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask,
1698 		      ShapeSet);
1699 
1700     XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE,
1701 	      DIAMETRE, 0, 0);
1702 
1703     AddMouseRegion(1, 2, 14, DIAMETRE - 2, 25);
1704     AddMouseRegion(2, 2, 38, DIAMETRE - 2, 49);
1705     display_zoom();
1706 
1707     ok = TRUE;
1708     while (ok) {
1709 
1710 	while (XPending(dpy)) {
1711 	    XNextEvent(dpy, &Event);
1712 	    switch (Event.type) {
1713 	    case Expose:
1714 		RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE);
1715 		break;
1716 	    case DestroyNotify:
1717 		XCloseDisplay(dpy);
1718 		exit(0);
1719 		break;
1720 	    case ButtonPress:
1721 		ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
1722 		waitrel = 1;
1723 		press_but(ckm);
1724 		switch (Event.xbutton.button) {
1725 		case 1:
1726 		    not3 = TRUE;
1727 		    sensadd = 1;
1728 		    break;
1729 		case 2:
1730 		    not3 = TRUE;
1731 		    sensadd = -1;
1732 		    break;
1733 		case 3:
1734 		    not3 = FALSE;
1735 		    if (ckm < 5)
1736 			gotoscr = 0;
1737 		    break;
1738 		default:
1739 		    break;
1740 		}
1741 		break;
1742 	    case ButtonRelease:
1743 		release_but(ckm);
1744 		waitrel = ckm;
1745 		ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
1746 		if (waitrel == ckm) {
1747 		    switch (ckm) {
1748 		    case 5:
1749 			gotoscr--;
1750 			if (gotoscr == 0)
1751 			    gotoscr = NUM_SCREEN;
1752 			break;
1753 		    case 6:
1754 			gotoscr++;
1755 			if (gotoscr > NUM_SCREEN)
1756 			    gotoscr = 1;
1757 			break;
1758 		    case 7:
1759 			gotoscr = 0;
1760 		    default:
1761 			break;
1762 		    }
1763 		}
1764 		ckm = 0;
1765 		waitrel = 0;
1766 		tin = getimev();
1767 		break;
1768 	    default:
1769 		break;
1770 
1771 	    }
1772 	}
1773 	usleep(VAL_USLEEP_SHORT);
1774 	if (waitrel && not3) {
1775 	    if (ckm == 1) {
1776 		move_delay(sensadd);
1777 		usleep(2 * VAL_USLEEP);
1778 	    }
1779 	    if (ckm == 2) {
1780 		move_zoom(sensadd);
1781 		usleep(VAL_USLEEP);
1782 	    }
1783 	}
1784 	if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT
1785 	    && gotoscr == 3)
1786 	    gotoscr = 0;
1787 	if (gotoscr != 3)
1788 	    ok = FALSE;
1789     }
1790     return;
1791 }
1792 
1793 
1794 
display_light()1795 static void display_light()
1796 {
1797     char datest[32];
1798     int i;
1799 
1800     write_icon(" light :", 2, 2);
1801     RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1);
1802 
1803     sprintf(datest, "%.2f", ambient_light);
1804     i = 10 - strlen(datest);
1805     if (i < 0)
1806 	i = 0;
1807     else
1808 	i = i / 2;
1809     write_icon(datest, 2 + i * 6, 14);
1810     RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1);
1811 
1812     write_icon(" dawn :", 2, 26);
1813     RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1);
1814 
1815     dawn = (1.0 - dawn) * 2.0;
1816     sprintf(datest, "%.2f", dawn);
1817     dawn = (1.0 - dawn / 2.0);
1818     i = 10 - strlen(datest);
1819     if (i < 0)
1820 	i = 0;
1821     else
1822 	i = i / 2;
1823     write_icon(datest, 2 + i * 6, 38);
1824     RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1);
1825 
1826     return;
1827 }
1828 
1829 
1830 
move_light(int factor)1831 static void move_light(int factor)
1832 {
1833     ambient_light += factor / 20.0;
1834     ambient_light = MAX(0.0, ambient_light);
1835     ambient_light = MIN(1.0, ambient_light);
1836     aml = (int) floor(ambient_light * 256);
1837 
1838     XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
1839 	      0, 15, 60, 10, 2, 14);
1840 
1841     display_light();
1842     return;
1843 }
1844 
1845 
1846 
move_dawn(int factor)1847 static void move_dawn(int factor)
1848 {
1849     dawn = (1.0 - dawn) * 2.0;
1850     dawn += factor / 20.0;
1851     dawn = MAX(0.0, dawn);
1852     dawn = MIN(1.0, dawn);
1853     dawn = (1.0 - dawn / 2.0);
1854     XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
1855 	      0, 15, 60, 10, 2, 38);
1856 
1857     display_light();
1858     return;
1859 }
1860 
1861 
1862 
screen_4()1863 static void screen_4()
1864 {
1865     int ok, ckm, waitrel, sensadd, not3;
1866     struct timeval tin;
1867 
1868 #ifdef DEBUG
1869     fprintf(stdout, "scr 4\n");
1870 #endif
1871     tin = getimev();
1872     waitrel = 0;
1873     ckm = 0;
1874     sensadd = 0;
1875     not3 = TRUE;
1876     XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask,
1877 		      ShapeSet);
1878     XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask,
1879 		      ShapeSet);
1880 
1881     XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE,
1882 	      DIAMETRE, 0, 0);
1883 
1884     AddMouseRegion(1, 2, 14, DIAMETRE - 2, 25);
1885     AddMouseRegion(2, 2, 38, DIAMETRE - 2, 49);
1886     display_light();
1887 
1888     ok = TRUE;
1889     while (ok) {
1890 
1891 	while (XPending(dpy)) {
1892 	    XNextEvent(dpy, &Event);
1893 	    switch (Event.type) {
1894 	    case Expose:
1895 		RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE);
1896 		break;
1897 	    case DestroyNotify:
1898 		XCloseDisplay(dpy);
1899 		exit(0);
1900 		break;
1901 	    case ButtonPress:
1902 		ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
1903 		waitrel = 1;
1904 		press_but(ckm);
1905 		switch (Event.xbutton.button) {
1906 		case 1:
1907 		    not3 = TRUE;
1908 		    sensadd = 1;
1909 		    break;
1910 		case 2:
1911 		    not3 = TRUE;
1912 		    sensadd = -1;
1913 		    break;
1914 		case 3:
1915 		    not3 = FALSE;
1916 		    if (ckm < 5)
1917 			gotoscr = 0;
1918 		    break;
1919 		default:
1920 		    break;
1921 		}
1922 		break;
1923 	    case ButtonRelease:
1924 		release_but(ckm);
1925 		waitrel = ckm;
1926 		ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
1927 		if (waitrel == ckm) {
1928 		    switch (ckm) {
1929 		    case 5:
1930 			gotoscr--;
1931 			if (gotoscr == 0)
1932 			    gotoscr = NUM_SCREEN;
1933 			break;
1934 		    case 6:
1935 			gotoscr++;
1936 			if (gotoscr > NUM_SCREEN)
1937 			    gotoscr = 1;
1938 			break;
1939 		    case 7:
1940 			gotoscr = 0;
1941 		    default:
1942 			break;
1943 		    }
1944 		}
1945 		ckm = 0;
1946 		waitrel = 0;
1947 		tin = getimev();
1948 		break;
1949 	    default:
1950 		break;
1951 	    }
1952 	}
1953 	usleep(VAL_USLEEP_SHORT);
1954 	if (waitrel && not3) {
1955 	    if (ckm == 1) {
1956 		move_light(sensadd);
1957 		usleep(VAL_USLEEP);
1958 	    }
1959 	    if (ckm == 2) {
1960 		move_dawn(sensadd);
1961 		usleep(VAL_USLEEP);
1962 	    }
1963 	}
1964 	if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT
1965 	    && gotoscr == 4)
1966 	    gotoscr = 0;
1967 	if (gotoscr != 4)
1968 	    ok = FALSE;
1969     }
1970     return;
1971 }
1972 
1973 
1974 
display_accel()1975 static void display_accel()
1976 {
1977     char datest[32];
1978     int i;
1979 
1980     write_icon(" accel :", 2, 2);
1981     RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1);
1982 
1983     if (time_multi < 24.0)
1984 	sprintf(datest, "%.1f", time_multi);
1985     else
1986 	sprintf(datest, "%.0f", time_multi);
1987 
1988     i = 10 - strlen(datest);
1989     if (i < 0)
1990 	i = 0;
1991     else
1992 	i = i / 2;
1993     write_icon(datest, 2 + i * 6, 14);
1994     RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1);
1995 
1996     write_icon("night map:", 2, 26);
1997     RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1);
1998 
1999     if (use_nightmap)
2000 	write_icon("    yes   ", 2, 38);
2001     else
2002 	write_icon("    no    ", 2, 38);
2003 
2004     RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1);
2005 
2006     return;
2007 }
2008 
2009 
2010 
move_accel(int factor)2011 static void move_accel(int factor)
2012 {
2013     if (factor == 1) {
2014 	if (time_multi < 1.0)
2015 	    time_multi = 1.0;
2016 	if (time_multi < 24.0)
2017 	    time_multi += 0.2;
2018 	else if (time_multi < 60.0) {
2019 	    time_multi = floor(time_multi);
2020 	    time_multi += 1.0;
2021 	} else if (time_multi < 120.0) {
2022 	    time_multi = floor(time_multi);
2023 	    time_multi += 2.0;
2024 	} else if (time_multi < 240.0) {
2025 	    time_multi = floor(time_multi);
2026 	    time_multi += 4.0;
2027 	} else if (time_multi < 600.0) {
2028 	    time_multi = floor(time_multi);
2029 	    time_multi += 10.0;
2030 	} else if (time_multi < 1200.0) {
2031 	    time_multi = floor(time_multi);
2032 	    time_multi += 20.0;
2033 	} else if (time_multi < 2400.0) {
2034 	    time_multi = floor(time_multi);
2035 	    time_multi += 40.0;
2036 	} else if (time_multi < 6000.0) {
2037 	    time_multi = floor(time_multi);
2038 	    time_multi += 100.0;
2039 	} else if (time_multi < 12000.0) {
2040 	    time_multi = floor(time_multi);
2041 	    time_multi += 200.0;
2042 	} else if (time_multi < 24000.0) {
2043 	    time_multi = floor(time_multi);
2044 	    time_multi += 400.0;
2045 	} else if (time_multi < 60000.0) {
2046 	    time_multi = floor(time_multi);
2047 	    time_multi += 1000.0;
2048 	} else if (time_multi < 120000.0) {
2049 	    time_multi = floor(time_multi);
2050 	    time_multi += 2000.0;
2051 	} else if (time_multi < 240000.0) {
2052 	    time_multi = floor(time_multi);
2053 	    time_multi += 4000.0;
2054 	} else {
2055 	    time_multi = floor(time_multi);
2056 	    time_multi += 8000.0;
2057 	}
2058 	if (time_multi > MAX_MULTI_COEF)
2059 	    time_multi = MAX_MULTI_COEF;
2060     } else {
2061 	if (time_multi < 24.1)
2062 	    time_multi -= 0.2;
2063 	else if (time_multi < 60.2) {
2064 	    time_multi = floor(time_multi);
2065 	    time_multi -= 1.0;
2066 	} else if (time_multi < 121.0) {
2067 	    time_multi = floor(time_multi);
2068 	    time_multi -= 2.0;
2069 	} else if (time_multi < 241.0) {
2070 	    time_multi = floor(time_multi);
2071 	    time_multi -= 4.0;
2072 	} else if (time_multi < 601.0) {
2073 	    time_multi = floor(time_multi);
2074 	    time_multi -= 10.0;
2075 	} else if (time_multi < 1201.0) {
2076 	    time_multi = floor(time_multi);
2077 	    time_multi -= 20.0;
2078 	} else if (time_multi < 2401.0) {
2079 	    time_multi = floor(time_multi);
2080 	    time_multi -= 40.0;
2081 	} else if (time_multi < 6001.0) {
2082 	    time_multi = floor(time_multi);
2083 	    time_multi -= 100.0;
2084 	} else if (time_multi < 12001.0) {
2085 	    time_multi = floor(time_multi);
2086 	    time_multi -= 200.0;
2087 	} else if (time_multi < 24001.0) {
2088 	    time_multi = floor(time_multi);
2089 	    time_multi -= 400.0;
2090 	} else if (time_multi < 60001.0) {
2091 	    time_multi = floor(time_multi);
2092 	    time_multi -= 1000.0;
2093 	} else if (time_multi < 120001.0) {
2094 	    time_multi = floor(time_multi);
2095 	    time_multi -= 2000.0;
2096 	} else if (time_multi < 240001.0) {
2097 	    time_multi = floor(time_multi);
2098 	    time_multi -= 4000.0;
2099 	} else {
2100 	    time_multi = floor(time_multi);
2101 	    time_multi -= 8000.0;
2102 	}
2103 
2104 	if (time_multi > 24.0)
2105 	    time_multi = floor(time_multi);
2106 	if (time_multi < 1.0)
2107 	    time_multi = 1.0;
2108     }
2109 
2110     tini = tlast;
2111     tbase = trend;
2112 
2113     XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
2114 	      0, 15, 60, 10, 2, 14);
2115 
2116     display_accel();
2117     return;
2118 }
2119 
2120 
2121 
screen_5()2122 static void screen_5()
2123 {
2124     int ok, ckm, waitrel, sensadd, not3;
2125     struct timeval tin;
2126 
2127 #ifdef DEBUG
2128     fprintf(stdout, "scr 5\n");
2129 #endif
2130     tin = getimev();
2131     waitrel = 0;
2132     ckm = 0;
2133     sensadd = 0;
2134     not3 = TRUE;
2135     XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask,
2136 		      ShapeSet);
2137     XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask,
2138 		      ShapeSet);
2139 
2140     XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE,
2141 	      DIAMETRE, 0, 0);
2142 
2143     AddMouseRegion(1, 2, 14, DIAMETRE - 2, 25);
2144     AddMouseRegion(2, 2, 38, DIAMETRE - 2, 49);
2145     display_accel();
2146 
2147     ok = TRUE;
2148     while (ok) {
2149 
2150 	while (XPending(dpy)) {
2151 	    XNextEvent(dpy, &Event);
2152 	    switch (Event.type) {
2153 	    case Expose:
2154 		RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE);
2155 		break;
2156 	    case DestroyNotify:
2157 		XCloseDisplay(dpy);
2158 		exit(0);
2159 		break;
2160 	    case ButtonPress:
2161 		ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
2162 		waitrel = 1;
2163 		press_but(ckm);
2164 		switch (Event.xbutton.button) {
2165 		case 1:
2166 		    not3 = TRUE;
2167 		    sensadd = 1;
2168 		    break;
2169 		case 2:
2170 		    not3 = TRUE;
2171 		    sensadd = -1;
2172 		    break;
2173 		case 3:
2174 		    not3 = FALSE;
2175 		    if (ckm < 5)
2176 			gotoscr = 0;
2177 		    break;
2178 		default:
2179 		    break;
2180 		}
2181 		break;
2182 	    case ButtonRelease:
2183 		release_but(ckm);
2184 		waitrel = ckm;
2185 		ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
2186 		if (waitrel == ckm) {
2187 		    switch (ckm) {
2188 		    case 5:
2189 			gotoscr--;
2190 			if (gotoscr == 0)
2191 			    gotoscr = NUM_SCREEN;
2192 			break;
2193 		    case 6:
2194 			gotoscr++;
2195 			if (gotoscr > NUM_SCREEN)
2196 			    gotoscr = 1;
2197 			break;
2198 		    case 7:
2199 			gotoscr = 0;
2200 		    default:
2201 			break;
2202 		    }
2203 		}
2204 		ckm = 0;
2205 		waitrel = 0;
2206 		tin = getimev();
2207 		break;
2208 	    default:
2209 		break;
2210 
2211 	    }
2212 	}
2213 	usleep(VAL_USLEEP_SHORT);
2214 	if (waitrel && not3) {
2215 	    if (ckm == 1) {
2216 		move_accel(sensadd);
2217 		usleep(VAL_USLEEP);
2218 	    }
2219 	    if (ckm == 2) {
2220 		not3 = FALSE;
2221 		if (use_nightmap) {
2222 		    use_nightmap = FALSE;
2223 		    display_accel();
2224 		} else {
2225 		    if (use_nmap_ini) {
2226 			use_nightmap = TRUE;
2227 			display_accel();
2228 		    }
2229 		}
2230 		usleep(VAL_USLEEP);
2231 	    }
2232 	}
2233 	if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT
2234 	    && gotoscr == 5)
2235 	    gotoscr = 0;
2236 	if (gotoscr != 5)
2237 	    ok = FALSE;
2238     }
2239     return;
2240 }
2241 
2242 
2243 
display_dlat()2244 static void display_dlat()
2245 {
2246     char datest[32];
2247     int i, d, m, nega, nego;
2248 
2249     write_icon(" dlat :", 2, 2);
2250     RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1);
2251     if (dlat < 0.0) {
2252 	nega = TRUE;
2253 	dlat *= -1;
2254     } else
2255 	nega = FALSE;
2256 
2257     m = (int) floor((dlat - floor(dlat)) * 60.0);
2258     d = (int) floor(dlat);
2259 
2260     if (nega) {
2261 	sprintf(datest, "-%d�%02d'", d, m);
2262 	dlat *= -1;
2263     } else
2264 	sprintf(datest, "%d�%02d'", d, m);
2265 
2266     i = 10 - strlen(datest);
2267     if (i < 0)
2268 	i = 0;
2269     else
2270 	i = i / 2;
2271     write_icon(datest, 2 + i * 6, 14);
2272     RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1);
2273 
2274     write_icon(" dlong :", 2, 26);
2275     RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1);
2276 
2277 
2278     if (dlong < 0.0) {
2279 	nego = TRUE;
2280 	dlong *= -1;
2281     } else
2282 	nego = FALSE;
2283 
2284     m = (int) floor((dlong - floor(dlong)) * 60.0);
2285     d = (int) floor(dlong);
2286 
2287     if (nego) {
2288 	sprintf(datest, "-%d�%02d'", d, m);
2289 	dlong *= -1;
2290     } else
2291 	sprintf(datest, "%d�%02d'", d, m);
2292 
2293     i = 10 - strlen(datest);
2294     if (i < 0)
2295 	i = 0;
2296     else
2297 	i = i / 2;
2298     write_icon(datest, 2 + i * 6, 38);
2299     RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1);
2300 
2301     return;
2302 }
2303 
2304 
2305 
move_dlat(int factor)2306 static void move_dlat(int factor)
2307 {
2308     dlat += factor / 4.0;
2309     if (dlat > MAX_DELTA_LONG)
2310 	dlat = MAX_DELTA_LONG;
2311     if (dlat < -MAX_DELTA_LONG)
2312 	dlat = -MAX_DELTA_LONG;
2313     if (dlat < 0.25 && dlat > -0.25)
2314 	dlat = 0;
2315     XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
2316 	      0, 15, 60, 10, 2, 14);
2317     if (dlat != 0.)
2318 	p_type = PTFIXED;
2319     display_dlat();
2320     return;
2321 }
2322 
2323 
2324 
move_dlong(int factor)2325 static void move_dlong(int factor)
2326 {
2327     dlong += factor / 4.0;
2328     if (dlong > MAX_DELTA_LONG)
2329 	dlong = MAX_DELTA_LONG;
2330     if (dlong < -MAX_DELTA_LONG)
2331 	dlong = -MAX_DELTA_LONG;
2332     if (dlong < 0.25 && dlong > -0.25)
2333 	dlong = 0;
2334     XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
2335 	      0, 15, 60, 10, 2, 38);
2336     if (dlong != 0.)
2337 	p_type = PTFIXED;
2338     display_dlat();
2339     return;
2340 }
2341 
2342 
2343 
screen_6()2344 static void screen_6()
2345 {
2346     int ok, ckm, waitrel, sensadd, not3;
2347     struct timeval tin;
2348 
2349 #ifdef DEBUG
2350     fprintf(stdout, "scr 6\n");
2351 #endif
2352     tin = getimev();
2353     waitrel = 0;
2354     sensadd = 0;
2355     ckm = 0;
2356     not3 = TRUE;
2357     XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask,
2358 		      ShapeSet);
2359     XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask,
2360 		      ShapeSet);
2361 
2362     XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE,
2363 	      DIAMETRE, 0, 0);
2364     AddMouseRegion(1, 2, 14, DIAMETRE - 2, 25);
2365     AddMouseRegion(2, 2, 38, DIAMETRE - 2, 49);
2366 
2367     display_dlat();
2368 
2369     ok = TRUE;
2370     while (ok) {
2371 
2372 	while (XPending(dpy)) {
2373 	    XNextEvent(dpy, &Event);
2374 	    switch (Event.type) {
2375 	    case Expose:
2376 		RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE);
2377 		break;
2378 	    case DestroyNotify:
2379 		XCloseDisplay(dpy);
2380 		exit(0);
2381 		break;
2382 	    case ButtonPress:
2383 		ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
2384 		waitrel = 1;
2385 		press_but(ckm);
2386 		switch (Event.xbutton.button) {
2387 		case 1:
2388 		    not3 = TRUE;
2389 		    sensadd = 1;
2390 		    break;
2391 		case 2:
2392 		    not3 = TRUE;
2393 		    sensadd = -1;
2394 		    break;
2395 		case 3:
2396 		    not3 = FALSE;;
2397 		    if (ckm < 5)
2398 			gotoscr = 0;
2399 		    break;
2400 		default:
2401 		    break;
2402 		}
2403 		break;
2404 	    case ButtonRelease:
2405 		release_but(ckm);
2406 		waitrel = ckm;
2407 		ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
2408 		if (waitrel == ckm) {
2409 		    switch (ckm) {
2410 		    case 5:
2411 			gotoscr--;
2412 			if (gotoscr == 0)
2413 			    gotoscr = NUM_SCREEN;
2414 			break;
2415 		    case 6:
2416 			gotoscr++;
2417 			if (gotoscr > NUM_SCREEN)
2418 			    gotoscr = 1;
2419 			break;
2420 		    case 7:
2421 			gotoscr = 0;
2422 		    default:
2423 			break;
2424 		    }
2425 		}
2426 		ckm = 0;
2427 		waitrel = 0;
2428 		tin = getimev();
2429 		break;
2430 	    default:
2431 		break;
2432 
2433 	    }
2434 	}
2435 	usleep(VAL_USLEEP_SHORT);
2436 	if (waitrel && not3) {
2437 	    if (ckm == 1 && p_type != PTRANDOM) {
2438 		move_dlat(sensadd);
2439 		usleep(VAL_USLEEP);
2440 	    }
2441 	    if (ckm == 2 && p_type != PTRANDOM) {
2442 		move_dlong(sensadd);
2443 		usleep(VAL_USLEEP);
2444 	    }
2445 	}
2446 	if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT
2447 	    && gotoscr == 6)
2448 	    gotoscr = 0;
2449 	if (gotoscr != 6)
2450 	    ok = FALSE;
2451     }
2452     return;
2453 }
2454 
2455 
2456 
display_type()2457 static void display_type()
2458 {
2459     char c, cc, mess[12];
2460 
2461     write_icon(" view :", 2, 2);
2462     RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1);
2463 
2464     if (p_type == PTFIXED) {
2465 	c = '>';
2466 	cc = '<';
2467     } else {
2468 	c = ' ';
2469 	cc = ' ';
2470     }
2471     sprintf(mess, "%c  move  %c", c, cc);
2472     write_icon(mess, 2, 14);
2473     RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1);
2474     if (p_type == PTSUN) {
2475 	c = '>';
2476 	cc = '<';
2477     } else {
2478 	c = ' ';
2479 	cc = ' ';
2480     }
2481     sprintf(mess, "%c  sun   %c", c, cc);
2482     write_icon(mess, 2, 26);
2483     RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1);
2484 #if WITH_MARKERS
2485     if (p_type == PTMOON) {
2486 	c = '>';
2487 	cc = '<';
2488     } else {
2489 	c = ' ';
2490 	cc = ' ';
2491     }
2492     sprintf(mess, "%c  moon  %c", c, cc);
2493 #else
2494     if (p_type == PTRANDOM) {
2495 	c = '>';
2496 	cc = '<';
2497     } else {
2498 	c = ' ';
2499 	cc = ' ';
2500     }
2501     sprintf(mess, "%c random %c", c, cc);
2502 #endif
2503     write_icon(mess, 2, 38);
2504     RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1);
2505 
2506     return;
2507 }
2508 
2509 
2510 
screen_7()2511 static void screen_7()
2512 {
2513     int ok, ckm, waitrel, sensadd, not3;
2514     struct timeval tin;
2515 
2516 #ifdef DEBUG
2517     fprintf(stdout, "scr 7\n");
2518 #endif
2519     tin = getimev();
2520     waitrel = 0;
2521     sensadd = 0;
2522     ckm = 0;
2523     not3 = TRUE;
2524 
2525     XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask,
2526 		      ShapeSet);
2527     XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask,
2528 		      ShapeSet);
2529 
2530     XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE,
2531 	      DIAMETRE, 0, 0);
2532     AddMouseRegion(1, 2, 14, DIAMETRE - 2, 25);
2533     AddMouseRegion(2, 2, 26, DIAMETRE - 2, 37);
2534     AddMouseRegion(3, 2, 38, DIAMETRE - 2, 49);
2535 
2536     display_type();
2537 
2538     ok = TRUE;
2539     while (ok) {
2540 
2541 	while (XPending(dpy)) {
2542 	    XNextEvent(dpy, &Event);
2543 	    switch (Event.type) {
2544 	    case Expose:
2545 		RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE);
2546 		break;
2547 	    case DestroyNotify:
2548 		XCloseDisplay(dpy);
2549 		exit(0);
2550 		break;
2551 	    case ButtonPress:
2552 		ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
2553 		waitrel = 1;
2554 		press_but(ckm);
2555 		switch (Event.xbutton.button) {
2556 		case 1:
2557 		    not3 = TRUE;
2558 		    if (ckm < 4 && ckm > 0)
2559 			sensadd = ckm;
2560 		    break;
2561 		case 2:
2562 		    not3 = TRUE;
2563 		    break;
2564 		case 3:
2565 		    not3 = FALSE;
2566 		    if (ckm < 5)
2567 			gotoscr = 0;
2568 		    break;
2569 		default:
2570 		    break;
2571 		}
2572 		break;
2573 	    case ButtonRelease:
2574 		release_but(ckm);
2575 		waitrel = ckm;
2576 		ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
2577 		if (waitrel == ckm) {
2578 		    switch (ckm) {
2579 		    case 5:
2580 			gotoscr--;
2581 			if (gotoscr == 0)
2582 			    gotoscr = NUM_SCREEN;
2583 			break;
2584 		    case 6:
2585 			gotoscr++;
2586 			if (gotoscr > NUM_SCREEN)
2587 			    gotoscr = 1;
2588 			break;
2589 		    case 7:
2590 			gotoscr = 0;
2591 		    default:
2592 			break;
2593 		    }
2594 		}
2595 		ckm = 0;
2596 		waitrel = 0;
2597 		tin = getimev();
2598 		break;
2599 	    default:
2600 		break;
2601 	    }
2602 	}
2603 	usleep(VAL_USLEEP_SHORT);
2604 	if (waitrel && not3 && sensadd) {
2605 	    if (sensadd == 2) {
2606 		if (p_type != PTSUN) {
2607 		    p_type = PTSUN;
2608 		    dlat = 0;
2609 		    dlong = 0;
2610 		    display_type();
2611 		}
2612 	    }
2613 	    if (sensadd == 1) {
2614 		if (p_type != PTFIXED) {
2615 		    p_type = PTFIXED;
2616 		    display_type();
2617 		}
2618 	    }
2619 	    if (sensadd == 3) {
2620 #if WITH_MARKERS
2621 		if (p_type != PTMOON) {
2622 		    p_type = PTMOON;
2623 #else
2624 		if (p_type != PTRANDOM) {
2625 		    p_type = PTRANDOM;
2626 #endif
2627 		    dlat = 0;
2628 		    dlong = 0;
2629 		    display_type();
2630 		}
2631 	    }
2632 	}
2633 	sensadd = 0;
2634 	if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT
2635 	    && gotoscr == 7)
2636 	    gotoscr = 0;
2637 	if (gotoscr != 7)
2638 	    ok = FALSE;
2639     }
2640     return;
2641 }
2642