wmmoonclock: Bump to version 1.29.
[dockapps.git] / wmglobe / src / wmgutil.c
blob2686c5cf04b4fcaad352905f090a553194823d12
1 /* WMGlobe 0.5 - All the Earth on a WMaker Icon
2 * copyright (C) 1998,99 Jerome Dumonteil <jerome.dumonteil@capway.com>
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.
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.
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 ***************************************************************************/
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)
24 * wmglobe.c uses functions of : Xglobe, Xearth, wmgeneral, wmaker/wrlib
25 ***************************************************************************/
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"
35 static void move_earth(double vla, double vlo);
36 static int flush_expose(Window w);
37 static void mqparam();
38 static double getdegre(char *val);
39 static void screen_1();
40 static void screen_2();
41 static void screen_3();
42 static void screen_4();
43 static void screen_5();
44 static void screen_6();
45 static void screen_7();
46 static void write_icon(char *txt, int x, int y);
47 static void chiffre(int ch, int xx, int yy);
48 static int lettre(char c, int xx, int yy);
49 static void display_pos(double la, double lo);
50 static void display_date(double la, double lo);
51 static void release_but(int ckm);
52 static void press_but(int ckm);
53 static void display_zoom();
54 static void display_light();
55 static void display_accel();
56 static void display_dlat();
57 static void display_type();
58 static void move_delay(int factor);
59 static void move_zoom(int factor);
60 static void move_light(int factor);
61 static void move_dawn(int factor);
62 static void move_accel(int factor);
63 static void move_dlat(int factor);
64 static void move_dlong(int factor);
65 /* ------------------------------------------------------------------------ */
67 * TIME FUNCTIONS
69 /* ------------------------------------------------------------------------ */
70 struct timeval diftimev(struct timeval t1, struct timeval t2)
72 t1.tv_usec -= t2.tv_usec;
73 if (t1.tv_usec < 0) {
74 t1.tv_usec += 1000000;
75 t1.tv_sec--;
77 t1.tv_sec -= t2.tv_sec;
78 return t1;
80 /* ------------------------------------------------------------------------ */
81 struct timeval addtimev(struct timeval t1, struct timeval t2)
83 t1.tv_usec += t2.tv_usec;
84 if (t1.tv_usec >= 1000000) {
85 t1.tv_usec -= 1000000;
86 t1.tv_sec++;
88 t1.tv_sec += t2.tv_sec;
89 return t1;
91 /* ------------------------------------------------------------------------ */
92 struct timeval getimev()
94 struct timeval tv;
95 struct timezone tz;
97 gettimeofday(&tv, &tz);
98 return tv;
100 /* ------------------------------------------------------------------------ */
102 * INIT FUNCTIONS
104 * defaults, commandline
105 * init of pixmap for screenpos and numbers displaying
107 /* ------------------------------------------------------------------------ */
108 void loadxpm(Window draw)
110 XpmCreatePixmapFromData(dpy, draw, scrpos_xpm, &(screenpos.pixmap),
111 &(screenpos.mask), &(screenpos.attributes));
112 XpmCreatePixmapFromData(dpy, draw, scrtime_xpm, &(scrdate.pixmap),
113 &(scrdate.mask), &(scrdate.attributes));
114 XpmCreatePixmapFromData(dpy, draw, zapnum_xpm, &(numpix.pixmap),
115 &(numpix.mask), &(numpix.attributes));
116 XpmCreatePixmapFromData(dpy, draw, zaptxt_xpm, &(txtpix.pixmap),
117 &(txtpix.mask), &(txtpix.attributes));
118 XpmCreatePixmapFromData(dpy, draw, scrdiv_xpm, &(scrdiv.pixmap),
119 &(scrdiv.mask), &(scrdiv.attributes));
120 return;
122 /* ------------------------------------------------------------------------ */
123 void set_defaults()
125 firstTime = TRUE;
126 dayfile = NULL;
127 use_nightmap = FALSE;
128 nightfile = NULL;
129 oknimap = DEFAULT_NIGHTMAP;
130 p_type = PTSUNREL;
131 delay = DEFAULT_DELAY;
132 tini = getimev();
133 tbase = tini;
134 tsunpos = 0;
135 tlast.tv_sec = 0;
136 tlast.tv_usec = 0;
137 do_something = TRUE;
138 time_multi = 1.0;
139 v_lat = DEFAULT_V_LAT / 180. * PI;
140 v_long = DEFAULT_V_LONG / 180. * PI;
141 dv_lat = DEFAULT_V_LAT;
142 dv_long = DEFAULT_V_LONG;
143 old_dvlat = DEFAULT_V_LAT;
144 old_dvlong = DEFAULT_V_LONG;
145 iop = 0;
146 dlat = 0.0;
147 dlong = 0.0;
148 addlat = 0.0;
149 addlong = 0.0;
150 radius = 1000.0;
151 sun_long = 0.0;
152 sun_lat = 0.0;
153 fov = 0.5 * PI / 180.;
154 sens = DEFAULT_SENS;
155 zoom = DEFAULT_ZOOM;
156 ambient_light = DEFAULT_LIGHT;
157 dawn = DEFAULT_DAWN;
158 typecadre = DEFAULT_BORDER;
159 fun = FALSE;
160 funx = 0;
161 funy = 0;
162 dpy_name = NULL;
163 onlyshape = TRUE;
164 option_iw = WithdrawnState;
165 stoprand = FALSE;
166 solution = FALSE;
167 proj_dist = DIAMETRE / tan(fov);
168 noir.red = 0;
169 noir.green = 0;
170 noir.blue = 0;
171 noir.alpha = 255;
173 md[0] = (MPO *) malloc(sizeof(MPO));
174 md[1] = (MPO *) malloc(sizeof(MPO));
175 md[2] = (MPO *) malloc(sizeof(MPO));
176 md[3] = (MPO *) malloc(sizeof(MPO));
177 mn[0] = (MPO *) malloc(sizeof(MPO));
178 mn[1] = (MPO *) malloc(sizeof(MPO));
179 mn[2] = (MPO *) malloc(sizeof(MPO));
180 mn[3] = (MPO *) malloc(sizeof(MPO));
181 #ifdef DEBUG
182 minhz = 1.;
183 #endif
184 return;
186 /* ------------------------------------------------------------------------ */
187 static double getdegre(char *val)
189 double d, m, s;
190 if (strchr(val, '°') != NULL || strchr(val, 'd') != NULL
191 || strchr(val, 'D') != NULL || strchr(val, ':') != NULL) {
192 d = m = s = 0;
193 sscanf(val, "%lf%*c%lf%*c%lf", &d, &m, &s);
194 if (d >= 0.)
195 return d + m / 60. + s / 3600.;
196 else
197 return d - m / 60. - s / 3600.;
198 } else {
199 return atof(val);
202 /* ------------------------------------------------------------------------ */
203 static void mqparam()
205 printf("error in parameters\n");
206 exit(1);
209 /* ------------------------------------------------------------------------ */
210 void cmdline(int argc, char *argv[])
212 int i, j;
214 if (argc > 0) {
215 for (i = 1; i < argc; i++) {
216 j = 0;
218 /* ---------------------------------------------------- */
219 if (strcasecmp(argv[i], "-v") == 0
220 || strcasecmp(argv[i], "-version") == 0) {
221 printf("%s\n", WMGVERSION);
222 exit(0);
224 /* ---------------------------------------------------- */
225 if (strcasecmp(argv[i], "-w") == 0
226 || strcasecmp(argv[i], "-wmaker") == 0) {
227 option_iw = WithdrawnState;
228 j = 1;
230 /* ---------------------------------------------------- */
231 if (strcasecmp(argv[i], "-i") == 0
232 || strcasecmp(argv[i], "-iconic") == 0) {
233 option_iw = IconicState;
234 j = 1;
236 /* ---------------------------------------------------- */
237 if (!j && (strcasecmp(argv[i], "-s") == 0 ||
238 strcasecmp(argv[i], "-shape") == 0)) {
239 onlyshape = TRUE;
240 j = 1;
242 /* ---------------------------------------------------- */
243 if (!j && (strcasecmp(argv[i], "-d") == 0
244 || strcasecmp(argv[i], "-display") == 0)) {
245 i++;
246 if (i < argc) {
247 j = 1;
248 dpy_name = argv[i];
249 } else {
250 mqparam();
251 i--;
254 /* ---------------------------------------------------- */
255 if (!j && (strcasecmp(argv[i], "-rand") == 0
256 || strcasecmp(argv[i], "-random") == 0)) {
257 p_type = PTRANDOM;
258 srandom(((int) time(NULL)) + ((int) getpid()));
259 j = 1;
261 /* ---------------------------------------------------- */
262 if (!j && (strcasecmp(argv[i], "-oz") == 0
263 || strcasecmp(argv[i], "-austral") == 0)) {
264 sens = -1;
265 j = 1;
267 /* ---------------------------------------------------- */
268 if (!j && strcasecmp(argv[i], "-map") == 0) {
270 i++;
271 if (i < argc) {
272 j = 1;
273 free(dayfile);
274 if ((dayfile = (char *) malloc(strlen(argv[i]) + 1)) == NULL) {
275 fprintf(stderr, "erreur memoire options map\n");
276 exit(1);
278 strcpy(dayfile, argv[i]);
279 } else {
280 mqparam();
281 i--;
284 /* ---------------------------------------------------- */
285 if (!j && (strcasecmp(argv[i], "-nimap") == 0
286 || strcasecmp(argv[i], "-nightmap") == 0
287 || strcasecmp(argv[i], "-night") == 0)) {
289 i++;
290 if (i < argc) {
291 j = 1;
292 free(nightfile);
293 if ((nightfile = (char *) malloc(strlen(argv[i]) + 1)) == NULL) {
294 fprintf(stderr, "erreur memoire options nimap\n");
295 exit(1);
297 strcpy(nightfile, argv[i]);
298 use_nightmap = TRUE;
299 } else {
300 mqparam();
301 i--;
304 /* ---------------------------------------------------- */
305 if (!j && (strcasecmp(argv[i], "-accel") == 0
306 || strcasecmp(argv[i], "-accell") == 0
307 || strcasecmp(argv[i], "-acc") == 0
308 || strcasecmp(argv[i], "-multi") == 0)) {
309 i++;
310 if (i < argc) {
311 j = 1;
312 time_multi = atof(argv[i]);
313 if (time_multi < 1.0)
314 time_multi = 1.0;
315 if (time_multi > MAX_MULTI_COEF)
316 time_multi = MAX_MULTI_COEF;
317 if (time_multi > 24.0)
318 time_multi = floor(time_multi);
319 else
320 time_multi = floor(time_multi * 10.0) / 10.0;
321 } else {
322 mqparam();
323 i--;
326 /* ---------------------------------------------------- */
327 if (!j && (strcasecmp(argv[i], "-nonimap") == 0
328 || strcasecmp(argv[i], "-nonightmap") == 0
329 || strcasecmp(argv[i], "-nonight") == 0
330 || strcasecmp(argv[i], "-nomap") == 0)) {
331 j = 1;
332 use_nightmap = FALSE;
333 oknimap = FALSE;
335 /* ---------------------------------------------------- */
336 if (!j && strcasecmp(argv[i], "-zoom") == 0) {
337 i++;
338 if (i < argc) {
339 j = 1;
340 zoom = atof(argv[i]);
341 if (zoom < ZOOM_MIN)
342 zoom = ZOOM_MIN;
343 if (zoom > ZOOM_MAX)
344 zoom = ZOOM_MAX;
345 } else {
346 mqparam();
347 i--;
350 /* ---------------------------------------------------- */
351 if (!j && strcasecmp(argv[i], "-dawn") == 0) {
352 i++;
353 if (i < argc) {
354 j = 1;
355 dawn = atof(argv[i]);
356 dawn = MAX(0.0, dawn);
357 dawn = MIN(1.0, dawn);
359 dawn = (1.0 - dawn / 2.0);
360 } else {
361 mqparam();
362 i--;
365 /* ---------------------------------------------------- */
366 if (!j && strcasecmp(argv[i], "-delay") == 0) {
367 i++;
368 if (i < argc) {
369 j = 1;
370 delay = atof(argv[i]);
371 if (delay < 0)
372 delay = 0;
373 if (delay > MAX_DELAY_SEC)
374 delay = MAX_DELAY_SEC;
375 } else {
376 mqparam();
377 i--;
380 /* ---------------------------------------------------- */
381 if (!j && (strcasecmp(argv[i], "-dlat") == 0
382 || strcasecmp(argv[i], "-lat") == 0
383 || strcasecmp(argv[i], "-dlatitude") == 0)) {
384 i++;
385 if (i < argc) {
386 j = 1;
387 dlat = getdegre(argv[i]);
388 if (dlat < -MAX_DELTA_LONG)
389 dlat = -MAX_DELTA_LONG;
390 if (dlat > MAX_DELTA_LONG)
391 dlat = MAX_DELTA_LONG;
392 p_type = PTFIXED;
393 } else {
394 mqparam();
395 i--;
398 /* ---------------------------------------------------- */
399 if (!j && (strcasecmp(argv[i], "-dlong") == 0
400 || strcasecmp(argv[i], "-long") == 0
401 || strcasecmp(argv[i], "-dlongitude") == 0)) {
402 i++;
403 if (i < argc) {
404 j = 1;
405 dlong = getdegre(argv[i]);
406 if (dlong < -MAX_DELTA_LONG)
407 dlong = -MAX_DELTA_LONG;
408 if (dlong > MAX_DELTA_LONG)
409 dlong = MAX_DELTA_LONG;
410 p_type = PTFIXED;
411 } else {
412 mqparam();
413 i--;
416 /* ---------------------------------------------------- */
417 if (!j && strcasecmp(argv[i], "-light") == 0) {
418 i++;
419 if (i < argc) {
420 j = 1;
421 ambient_light = atof(argv[i]);
422 if (ambient_light < 0.)
423 ambient_light = 0.;
424 if (ambient_light > 1.)
425 ambient_light = 1.;
426 } else {
427 mqparam();
428 i--;
431 /* ---------------------------------------------------- */
432 if (!j && strcasecmp(argv[i], "-time") == 0) {
433 i++;
434 if (i < argc) {
435 j = 1;
436 tbase.tv_sec = atoi(argv[i]);
437 tbase.tv_usec = 0;
438 } else {
439 mqparam();
440 i--;
443 /* ---------------------------------------------------- */
444 if (!j && (strcasecmp(argv[i], "-bord") == 0
445 || strcasecmp(argv[i], "-border") == 0)) {
446 i++;
447 if (i < argc) {
448 j = 1;
449 typecadre = atoi(argv[i]);
450 if (typecadre < 0)
451 typecadre = 0;
452 if (typecadre > 2)
453 typecadre = 2;
454 } else {
455 mqparam();
456 i--;
459 /* ---------------------------------------------------- */
460 if (!j && strcasecmp(argv[i], "-fun") == 0) {
461 fun = TRUE;
462 i++;
463 if (i < argc) {
464 funx = atoi(argv[i]);
466 i++;
467 if (i < argc) {
468 j = 1;
469 funy = atoi(argv[i]);
470 } else {
471 mqparam();
472 i--;
474 } else {
475 mqparam();
476 i--;
479 /* ---------------------------------------------------- */
480 if (!j && (strcasecmp(argv[i], "-pos") == 0
481 || strcasecmp(argv[i], "-position") == 0
482 || strcasecmp(argv[i], "-fixed") == 0)) {
483 p_type = PTFIXED;
484 i++;
485 if (i < argc) {
486 addlat = getdegre(argv[i]);
487 i++;
488 if (i < argc) {
489 j = 1;
490 addlong = getdegre(argv[i]);
491 } else {
492 mqparam();
493 i--;
495 } else {
496 mqparam();
497 i--;
500 /* ---------------------------------------------------- */
502 if (!j && argv[i][0] == '-') {
503 printf("%s\n", WMGVERSION);
504 printf("\n");
505 printf("-v : version -h : this help message !\n");
506 printf("-zoom zoom_value : changing apparent size in icon\n");
507 printf("-pos latitude long. : fixed initial position (default=follow sun)\n");
508 printf("-rand : random position at every refresh\n");
509 printf("-map map_file : use this map for rendering\n");
510 printf("-nimap night_file : and this one for the dark side of earth\n");
511 printf("-nonimap : don't use the default night map\n");
512 printf("-delay seconds : time between refresh of image\n");
513 printf("-dlat delta_lat : latitude speed of point of view (default=follow sun)\n");
514 printf("-dlong delta_long : the same for longitude\n");
515 printf("-light light_value : level of light for dark side of earth\n");
516 printf("-dawn dawn_value : level of continuity for dawn limit\n");
517 printf("-bord border_num : 0 1 or 2 , type of icon border.\n");
518 printf("-accel time_multi : time accelerator\n");
519 printf("-time seconds : time to display in seconds since 01-01-1970\n");
520 printf("-oz : start in \"austral\" mode (for \"down under\" people)\n");
521 printf("-fun dx dy : offset of vision... almost useless\n");
522 printf("-w -shape : set by default (WMaker dockable application)\n");
523 printf("-d display : display (WindowMaker not needed on the server side)\n");
524 printf("left button : change longitude, with shift key, change latitude too\n");
525 printf("middle button : zoom in, shift + middle button : zoom out\n");
526 printf("right button : access to a few screens of parameters\n");
527 exit(0);
529 /* ------------------------------------------------------------------------ */
532 return;
535 /****************************************************************************
536 * X functions, mouse selection
540 /* ------------------------------------------------------------------------ */
541 static int flush_expose(Window w)
543 XEvent dummy;
544 int i = 0;
546 while (XCheckTypedWindowEvent(dpy, w, Expose, &dummy))
547 i++;
548 return i;
550 /* ------------------------------------------------------------------------ */
551 void RedrawWindowXYWH(int x, int y, int w, int h)
553 flush_expose(iconwin);
554 XCopyArea(dpy, wmg.pixmap, iconwin, NormalGC, x, y, w, h, x, y);
555 flush_expose(win);
556 XCopyArea(dpy, wmg.pixmap, win, NormalGC, x, y, w, h, x, y);
557 return;
559 /* ------------------------------------------------------------------------ */
560 void AddMouseRegion(int index, int left, int top, int right, int bottom)
562 if (index < MAX_MOUSE_REGION) {
563 mouse_region[index].enable = 1;
564 mouse_region[index].top = top;
565 mouse_region[index].left = left;
566 mouse_region[index].bottom = bottom;
567 mouse_region[index].right = right;
569 return;
571 /* ------------------------------------------------------------------------ */
572 int CheckMouseRegion(int x, int y)
574 int i;
575 int found;
577 found = 0;
579 for (i = 0; i < MAX_MOUSE_REGION && !found; i++) {
580 if (mouse_region[i].enable &&
581 x <= mouse_region[i].right &&
582 x >= mouse_region[i].left &&
583 y <= mouse_region[i].bottom &&
584 y >= mouse_region[i].top)
585 found = 1;
587 if (!found)
588 return -1;
589 return (i - 1);
591 /* ------------------------------------------------------------------------ */
593 * GRAPHIC : pixmap writing of letters & numbers
596 /* ------------------------------------------------------------------------ */
597 static void chiffre(int ch, int xx, int yy)
599 XCopyArea(dpy, numpix.pixmap, wmg.pixmap, NormalGC,
600 zapnum[ch][0], zapnum[ch][1], zapnum[ch][2], zapnum[ch][3], xx, yy);
602 return;
604 /* ------------------------------------------------------------------------ */
605 static int lettre(char c, int xx, int yy)
607 int i;
608 if (c == '°')
609 i = 288;
610 else
611 switch (toupper(c)) {
612 case '0':
613 i = 0;
614 break;
615 case '1':
616 i = 6;
617 break;
618 case '2':
619 i = 12;
620 break;
621 case '3':
622 i = 18;
623 break;
624 case '4':
625 i = 24;
626 break;
627 case '5':
628 i = 30;
629 break;
630 case '6':
631 i = 36;
632 break;
633 case '7':
634 i = 42;
635 break;
636 case '8':
637 i = 48;
638 break;
639 case '9':
640 i = 54;
641 break;
642 case '+':
643 i = 60;
644 break;
645 case 'A':
646 i = 66;
647 break;
648 case 'B':
649 i = 72;
650 break;
651 case 'C':
652 i = 78;
653 break;
654 case 'D':
655 i = 84;
656 break;
657 case 'E':
658 i = 90;
659 break;
660 case 'F':
661 i = 96;
662 break;
663 case 'G':
664 i = 102;
665 break;
666 case 'H':
667 i = 108;
668 break;
669 case 'I':
670 i = 114;
671 break;
672 case 'J':
673 i = 120;
674 break;
675 case 'K':
676 i = 126;
677 break;
678 case 'L':
679 i = 132;
680 break;
681 case 'M':
682 i = 138;
683 break;
684 case 'N':
685 i = 144;
686 break;
687 case 'O':
688 i = 150;
689 break;
690 case 'P':
691 i = 156;
692 break;
693 case 'Q':
694 i = 162;
695 break;
696 case 'R':
697 i = 168;
698 break;
699 case 'S':
700 i = 174;
701 break;
702 case 'T':
703 i = 180;
704 break;
705 case 'U':
706 i = 186;
707 break;
708 case 'V':
709 i = 192;
710 break;
711 case 'W':
712 i = 198;
713 break;
714 case 'X':
715 i = 204;
716 break;
717 case 'Y':
718 i = 210;
719 break;
720 case 'Z':
721 i = 216;
722 break;
723 case ' ':
724 i = 222;
725 break;
726 case ':':
727 i = 228;
728 break;
729 case '/':
730 i = 234;
731 break;
732 case '!':
733 i = 240;
734 break;
735 case '*':
736 i = 246;
737 break;
738 case '-':
739 i = 252;
740 break;
741 case '.':
742 i = 258;
743 break;
744 case '=':
745 i = 264;
746 break;
747 case '#':
748 i = 270;
749 break;
750 case '<':
751 i = 276;
752 break;
753 case '>':
754 i = 282;
755 break;
756 case '"':
757 i = 294;
758 break;
759 case '\'':
760 i = 300;
761 break;
762 case ',':
763 i = 306;
764 break;
765 case '@':
766 i = 312;
767 break;
768 case '(':
769 i = 318;
770 break;
771 case ')':
772 i = 324;
773 break;
774 case '&':
775 i = 330;
776 break;
777 case '~':
778 i = 336;
779 break;
780 case '£':
781 i = 342;
782 break;
783 case 'µ':
784 i = 348;
785 break;
786 case '{':
787 i = 354;
788 break;
789 case '}':
790 i = 360;
791 break;
792 case '[':
793 i = 366;
794 break;
795 case ']':
796 i = 372;
797 break;
798 case '\\':
799 i = 378;
800 break;
801 case '|':
802 i = 384;
803 break;
804 case '?':
805 i = 390;
806 break;
807 case '%':
808 i = 396;
809 break;
810 default:
811 i = 222;
812 break;
815 XCopyArea(dpy, txtpix.pixmap, wmg.pixmap, NormalGC,
816 i, 0, 6, 10, xx, yy);
817 return xx + 6;
819 /* ------------------------------------------------------------------------ */
820 static void write_icon(char *txt, int x, int y)
822 int p, ok;
823 p = 0;
825 #ifdef DEBUG
826 fprintf(stdout, "%s_\n", txt);
827 #endif
828 ok = TRUE;
829 while (ok) {
830 if (txt[p] == '\0' || x > DIAMETRE - 5) {
831 ok = FALSE;
832 } else {
833 x = lettre(txt[p], x, y);
834 p++;
837 return;
839 /* ------------------------------------------------------------------------ */
840 static void press_but(int ckm)
842 switch (ckm) {
843 case 5:
844 XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
845 0, 38, 20, 9, 2, 52);
846 RedrawWindowXYWH(2, 52, 20, 9);
847 break;
848 case 6:
849 XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
850 20, 38, 20, 9, 22, 52);
851 RedrawWindowXYWH(22, 52, 20, 9);
852 break;
853 case 7:
854 XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
855 40, 38, 20, 9, 42, 52);
856 RedrawWindowXYWH(42, 52, 20, 9);
857 break;
858 default:
859 break;
861 return;
863 /* ------------------------------------------------------------------------ */
864 static void release_but(int ckm)
866 switch (ckm) {
867 case 5:
868 XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
869 0, 28, 20, 9, 2, 52);
870 RedrawWindowXYWH(2, 52, 20, 9);
871 break;
872 case 6:
873 XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
874 20, 28, 20, 9, 22, 52);
875 RedrawWindowXYWH(22, 52, 20, 9);
876 break;
877 case 7:
878 XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
879 40, 28, 20, 9, 42, 52);
880 RedrawWindowXYWH(42, 52, 20, 9);
881 break;
882 default:
883 break;
885 return;
887 /* ------------------------------------------------------------------------ */
889 * MENU SELECTION & ACTIONS
891 /* ------------------------------------------------------------------------ */
892 void screen_back()
894 AddMouseRegion(0, 0, 0, 0, 0);
895 if (p_type == PTRANDOM) {
896 stoprand = STOP_RANDOM_FACTOR;
897 addlong = dv_long;
898 addlat = dv_lat;
900 gotoscr = 1;
901 while (gotoscr != 0) {
902 switch (gotoscr) {
903 case 1:
904 screen_1();
905 break;
906 case 2:
907 screen_2();
908 break;
909 case 3:
910 screen_3();
911 break;
912 case 4:
913 screen_4();
914 break;
915 case 5:
916 screen_5();
917 break;
918 case 6:
919 screen_6();
920 break;
921 case 7:
922 screen_7();
923 break;
924 default:
925 break;
927 XFlush(dpy);
930 * put old environment
932 XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, pixmask, ShapeSet);
933 XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet);
935 AddMouseRegion(0, 5, 5, DIAMETRE - 4, DIAMETRE - 4);
936 stoprand = FALSE;
937 do_something = TRUE;
939 return;
941 /* ------------------------------------------------------------------------ */
942 static void display_pos(double la, double lo)
944 int c, i, j, k, l, neg;
946 if (la > 0) {
947 neg = 10;
948 } else {
949 neg = 11;
950 la *= -1;
952 i = floor(la / 10.0);
953 la -= 10 * i;
954 j = floor(la);
955 la -= j;
956 la *= 60;
957 k = floor(la / 10.0);
958 la -= 10 * k;
959 l = floor(la);
961 if (i == 0) {
962 i = neg;
963 neg = 10;
965 chiffre(neg, platd[1][0], platd[1][1]);
966 chiffre(i, platd[2][0], platd[2][1]);
967 chiffre(j, platd[3][0], platd[3][1]);
968 chiffre(k, platm[0][0], platd[0][1]);
969 chiffre(l, platm[1][0], platd[1][1]);
971 if (lo > 0) {
972 neg = 12;
973 } else {
974 neg = 11;
975 lo *= -1;
977 c = floor(lo / 100.0);
978 lo -= c * 100;
979 if (c > 0) {
980 if (neg == 11)
981 neg = 13;
982 } else {
983 if (neg == 11) {
984 c = neg;
985 } else {
986 c = 10;
988 neg = 12;
990 i = floor(lo / 10.0);
991 lo -= 10 * i;
992 j = floor(lo);
993 lo -= j;
994 lo *= 60;
995 k = floor(lo / 10.0);
996 lo -= 10 * k;
997 l = floor(lo);
998 if (i == 0 && c > 9) {
999 i = c;
1000 c = 10;
1002 chiffre(neg, plongd[0][0], plongd[0][1]);
1003 chiffre(c, plongd[1][0], plongd[1][1]);
1004 chiffre(i, plongd[2][0], plongd[2][1]);
1005 chiffre(j, plongd[3][0], plongd[3][1]);
1006 chiffre(k, plongm[0][0], plongm[0][1]);
1007 chiffre(l, plongm[1][0], plongm[1][1]);
1009 RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE);
1010 return;
1012 /* ------------------------------------------------------------------------ */
1013 void rotation_terre(int x, int y, int lat_flag)
1016 * earth rotate after (while) a clic
1018 double mx, my;
1019 mx = (double) ((double) x - DIAMETRE / 2 + 0.5) / zoom * cos(v_lat) * sens;
1020 if (lat_flag) {
1021 my = -(double) ((double) y - DIAMETRE / 2 + 0.5) * sens / zoom;
1022 if (my > 0.0)
1023 my += ABS(sin(v_lat) * ((double) x - DIAMETRE / 2 + 0.5) / zoom);
1024 else
1025 my -= ABS(sin(v_lat) * ((double) x - DIAMETRE / 2 + 0.5) / zoom);
1026 } else {
1027 my = 0;
1029 if (p_type == PTRANDOM) {
1030 stoprand = STOP_RANDOM_FACTOR;
1031 addlong = dv_long;
1032 addlat = dv_lat;
1034 addlong += mx * RATIO_ROTATE;
1035 addlat += my * RATIO_ROTATE;
1037 do_something = TRUE;
1038 return;
1040 /* ------------------------------------------------------------------------ */
1041 static void move_earth(double vla, double vlo)
1043 addlat += vla;
1044 addlong += vlo;
1047 switch (p_type) {
1048 case PTSUNREL:
1049 setViewPos(sun_lat * 180. / PI + addlat,
1050 sun_long * 180. / PI + addlong);
1051 break;
1053 case PTFIXED:
1054 case PTRANDOM:
1055 setViewPos(addlat, addlong);
1056 break;
1057 default:
1058 break;
1060 display_pos(dv_lat, dv_long);
1061 return;
1063 /* ------------------------------------------------------------------------ */
1064 static void screen_1()
1066 int ok, ckm, sensadd, waitrel, not3;
1067 struct timeval tin;
1069 #ifdef DEBUG
1070 fprintf(stdout, "scr 1\n");
1071 #endif
1072 tin = getimev();
1073 waitrel = 0;
1074 ckm = 0;
1075 sensadd = 1;
1076 not3 = TRUE;
1078 XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, screenpos.mask, ShapeSet);
1079 XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, screenpos.mask, ShapeSet);
1081 XCopyArea(dpy, screenpos.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE, DIAMETRE, 0, 0);
1083 AddMouseRegion(1, platd[0][0], platd[0][1], platd[3][0] + 9, platd[3][1] + 12);
1084 AddMouseRegion(2, platm[0][0], platm[0][1], platm[1][0] + 9, platm[1][1] + 12);
1085 AddMouseRegion(3, plongd[0][0], plongd[0][1], plongd[3][0] + 9, plongd[3][1] + 12);
1086 AddMouseRegion(4, plongm[0][0], plongm[0][1], plongm[1][0] + 9, plongm[1][1] + 12);
1087 AddMouseRegion(5, 1, 51, 21, 61);
1088 AddMouseRegion(6, 22, 51, 41, 61);
1089 AddMouseRegion(7, 42, 51, 62, 61);
1091 display_pos(dv_lat, dv_long);
1093 ok = TRUE;
1094 while (ok) {
1095 while (XPending(dpy)) {
1096 XNextEvent(dpy, &Event);
1097 switch (Event.type) {
1098 case Expose:
1099 RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE);
1100 break;
1101 case DestroyNotify:
1102 XCloseDisplay(dpy);
1103 exit(0);
1104 break;
1105 case ButtonPress:
1106 ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
1107 waitrel = 1;
1108 press_but(ckm);
1109 switch (Event.xbutton.button) {
1110 case 1:
1111 not3 = TRUE;
1112 sensadd = 1;
1113 break;
1114 case 2:
1115 not3 = TRUE;
1116 sensadd = -1;
1117 break;
1118 case 3:
1119 not3 = FALSE;
1120 if (ckm < 5)
1121 gotoscr = 0;
1122 default:
1123 break;
1125 break;
1126 case ButtonRelease:
1127 release_but(ckm);
1128 waitrel = ckm;
1129 ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
1130 if (waitrel == ckm) {
1131 switch (ckm) {
1132 case 5:
1133 gotoscr--;
1134 if (gotoscr == 0)
1135 gotoscr = NUM_SCREEN;
1136 break;
1137 case 6:
1138 gotoscr++;
1139 if (gotoscr > NUM_SCREEN)
1140 gotoscr = 1;
1141 break;
1142 case 7:
1143 gotoscr = 0;
1144 default:
1145 break;
1148 ckm = 0;
1149 waitrel = 0;
1150 tin = getimev();
1151 break;
1152 default:
1153 break;
1157 usleep(VAL_USLEEP_SHORT);
1158 if (waitrel && not3) {
1159 if (ckm == 1) {
1160 move_earth(sens * sensadd * 1.0, 0.0);
1161 usleep(VAL_USLEEP);
1163 if (ckm == 2) {
1164 move_earth(sens * sensadd * 1.0 / 60.0, 0.0);
1165 usleep(VAL_USLEEP);
1167 if (ckm == 3) {
1168 move_earth(0.0, sens * sensadd * 1.0);
1169 usleep(VAL_USLEEP);
1171 if (ckm == 4) {
1172 move_earth(0.0, sens * sensadd * 1.0 / 60.0);
1173 usleep(VAL_USLEEP);
1176 if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT && gotoscr == 1)
1177 gotoscr = 0;
1178 if (gotoscr != 1)
1179 ok = FALSE;
1181 return;
1183 /* ------------------------------------------------------------------------ */
1184 static void display_date(double la, double lo)
1186 char datest[32];
1187 time_t t;
1188 int i, j;
1190 write_icon(" time :", 2, 2);
1191 RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1);
1193 write_icon(" GMT+long.", 2, 14);
1194 RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1);
1196 t = trend.tv_sec;
1197 t += (int) (floor((lo + 7.5) / 15.0) * 3600);
1198 /*** pb near 2038 ***/
1200 strftime(datest, 30, "%x", gmtime(&t));
1202 i = 10 - strlen(datest);
1203 if (i < 0)
1204 i = 0;
1205 else
1206 i = i / 2;
1208 write_icon(datest, 2 + i * 6, 26);
1209 RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1);
1211 strftime(datest, 30, "%X", gmtime(&t));
1213 i = 10 - strlen(datest);
1214 if (i < 0) {
1215 i = 0;
1216 while (datest[i] != '\0') {
1217 if (datest[i] != ' ') {
1218 i++;
1219 } else {
1220 j = i;
1221 do {
1222 datest[j] = datest[j + 1];
1223 j++;
1225 while (datest[j - 1] != '\0');
1228 i = 0;
1229 } else {
1230 i = i / 2;
1233 write_icon(datest, 2 + i * 6, 38);
1234 RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1);
1236 return;
1238 /* ------------------------------------------------------------------------ */
1239 static void screen_2()
1241 int ok, ckm, waitrel;
1242 struct timeval tin;
1244 #ifdef DEBUG
1245 fprintf(stdout, "scr 2\n");
1246 #endif
1247 tin = getimev();
1248 waitrel = 0;
1249 ckm = 0;
1251 XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask, ShapeSet);
1252 XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask, ShapeSet);
1254 XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE, DIAMETRE, 0, 0);
1256 display_date(dv_lat, dv_long);
1258 ok = TRUE;
1259 while (ok) {
1260 while (XPending(dpy)) {
1261 XNextEvent(dpy, &Event);
1262 switch (Event.type) {
1263 case Expose:
1264 RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE);
1265 break;
1266 case DestroyNotify:
1267 XCloseDisplay(dpy);
1268 exit(0);
1269 break;
1270 case ButtonPress:
1271 ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
1272 waitrel = 1;
1273 press_but(ckm);
1274 switch (Event.xbutton.button) {
1275 case 1:
1276 break;
1277 case 2:
1278 break;
1279 case 3:
1280 if (ckm < 5)
1281 gotoscr = 0;
1282 break;
1283 default:
1284 break;
1286 break;
1287 case ButtonRelease:
1288 release_but(ckm);
1289 waitrel = ckm;
1290 ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
1291 if (waitrel == ckm) {
1292 switch (ckm) {
1293 case 5:
1294 gotoscr--;
1295 if (gotoscr == 0)
1296 gotoscr = NUM_SCREEN;
1297 break;
1298 case 6:
1299 gotoscr++;
1300 if (gotoscr > NUM_SCREEN)
1301 gotoscr = 1;
1302 break;
1303 case 7:
1304 gotoscr = 0;
1305 default:
1306 break;
1309 ckm = 0;
1310 waitrel = 0;
1311 tin = getimev();
1312 break;
1313 default:
1314 break;
1318 usleep(VAL_USLEEP_SHORT);
1320 if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT && gotoscr == 2)
1321 gotoscr = 0;
1322 if (gotoscr != 2)
1323 ok = FALSE;
1325 return;
1327 /* ------------------------------------------------------------------------ */
1328 static void display_zoom()
1330 char datest[32], dstr[32];
1331 int i;
1333 write_icon(" delay :", 2, 2);
1334 RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1);
1336 sprintf(dstr, "%f", delay);
1337 dstr[8] = '\0';
1338 i = strlen(dstr) - 1;
1339 while (i > 0) {
1340 if (dstr[i] == '0') {
1341 dstr[i] = '\0';
1342 i--;
1343 } else {
1344 i = 0;
1347 i = strlen(dstr) - 1;
1348 if (dstr[i] == '.')
1349 dstr[i] = '\0';
1350 sprintf(datest, "%s s", dstr);
1352 i = 10 - strlen(datest);
1353 if (i < 0)
1354 i = 0;
1355 else
1356 i = i / 2;
1357 write_icon(datest, 2 + i * 6, 14);
1358 RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1);
1360 write_icon(" zoom :", 2, 26);
1361 RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1);
1363 sprintf(datest, "%.3f", zoom);
1364 i = 10 - strlen(datest);
1365 if (i < 0)
1366 i = 0;
1367 else
1368 i = i / 2;
1369 write_icon(datest, 2 + i * 6, 38);
1370 RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1);
1372 return;
1374 /* ------------------------------------------------------------------------ */
1375 static void move_delay(int factor)
1377 if (factor == 1) {
1378 if (delay < (double) VAL_USLEEP / 1000000)
1379 delay = (double) VAL_USLEEP / 1000000;
1380 else if (delay < 0.1) {
1381 delay += 0.01;
1382 if (delay > 0.1)
1383 delay = 0.2;
1384 } else if (delay < 1.) {
1385 delay += 0.1;
1386 if (delay > 1.0)
1387 delay = 2.;
1388 } else if (delay < 60.)
1389 delay += 1.;
1390 else if (delay < 300.)
1391 delay += 10.;
1392 else if (delay < 3600.)
1393 delay += 60.;
1394 else if (delay < MAX_DELAY_SEC)
1395 delay += 360.;
1397 if (delay > MAX_DELAY_SEC)
1398 delay = MAX_DELAY_SEC;
1399 } else {
1400 if (delay > 3600.)
1401 delay -= 360.;
1402 else if (delay > 300.)
1403 delay -= 60.;
1404 else if (delay > 60.)
1405 delay -= 10.;
1406 else if (delay > 1.)
1407 delay -= 1.;
1408 else if (delay > 0.1)
1409 delay -= 0.1;
1410 else if (delay > (double) VAL_USLEEP / 1000000)
1411 delay -= 0.01;
1412 else
1413 delay = 0.0;
1415 if (delay < (double) VAL_USLEEP / 1000000)
1416 delay = 0.0;
1419 tdelay.tv_sec = (int) floor(delay);
1420 tdelay.tv_usec = (int) ((delay - tdelay.tv_sec) * 1000000);
1422 XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
1423 0, 15, 60, 10, 2, 14);
1425 display_zoom();
1426 return;
1428 /* ------------------------------------------------------------------------ */
1429 void zooming(int facto)
1431 if (facto)
1432 zoom /= ZOOM_FACTOR;
1433 else
1434 zoom *= ZOOM_FACTOR;
1435 zoom = MAX(zoom, ZOOM_MIN);
1436 zoom = MIN(zoom, ZOOM_MAX);
1437 if (p_type == PTRANDOM) {
1438 addlong = dv_long;
1439 addlat = dv_lat;
1440 stoprand = STOP_RANDOM_FACTOR;
1442 calcDistance();
1443 do_something = TRUE;
1444 return;
1446 /* ------------------------------------------------------------------------ */
1447 static void move_zoom(int factor)
1449 if (factor == -1)
1450 zooming(1);
1451 else
1452 zooming(0);
1453 XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
1454 0, 15, 60, 10, 2, 38);
1455 display_zoom();
1456 return;
1458 /* ------------------------------------------------------------------------ */
1459 static void screen_3()
1461 int ok, ckm, waitrel, sensadd, not3;
1462 struct timeval tin;
1464 #ifdef DEBUG
1465 fprintf(stdout, "scr 3\n");
1466 #endif
1467 tin = getimev();
1468 waitrel = 0;
1469 ckm = 0;
1470 sensadd = 0;
1471 not3 = TRUE;
1472 XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask, ShapeSet);
1473 XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask, ShapeSet);
1475 XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE, DIAMETRE, 0, 0);
1477 AddMouseRegion(1, 2, 14, DIAMETRE - 2, 25);
1478 AddMouseRegion(2, 2, 38, DIAMETRE - 2, 49);
1479 display_zoom();
1481 ok = TRUE;
1482 while (ok) {
1484 while (XPending(dpy)) {
1485 XNextEvent(dpy, &Event);
1486 switch (Event.type) {
1487 case Expose:
1488 RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE);
1489 break;
1490 case DestroyNotify:
1491 XCloseDisplay(dpy);
1492 exit(0);
1493 break;
1494 case ButtonPress:
1495 ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
1496 waitrel = 1;
1497 press_but(ckm);
1498 switch (Event.xbutton.button) {
1499 case 1:
1500 not3 = TRUE;
1501 sensadd = 1;
1502 break;
1503 case 2:
1504 not3 = TRUE;
1505 sensadd = -1;
1506 break;
1507 case 3:
1508 not3 = FALSE;
1509 if (ckm < 5)
1510 gotoscr = 0;
1511 break;
1512 default:
1513 break;
1515 break;
1516 case ButtonRelease:
1517 release_but(ckm);
1518 waitrel = ckm;
1519 ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
1520 if (waitrel == ckm) {
1521 switch (ckm) {
1522 case 5:
1523 gotoscr--;
1524 if (gotoscr == 0)
1525 gotoscr = NUM_SCREEN;
1526 break;
1527 case 6:
1528 gotoscr++;
1529 if (gotoscr > NUM_SCREEN)
1530 gotoscr = 1;
1531 break;
1532 case 7:
1533 gotoscr = 0;
1534 default:
1535 break;
1538 ckm = 0;
1539 waitrel = 0;
1540 tin = getimev();
1541 break;
1542 default:
1543 break;
1547 usleep(VAL_USLEEP_SHORT);
1548 if (waitrel && not3) {
1549 if (ckm == 1) {
1550 move_delay(sensadd);
1551 usleep(2 * VAL_USLEEP);
1553 if (ckm == 2) {
1554 move_zoom(sensadd);
1555 usleep(VAL_USLEEP);
1558 if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT && gotoscr == 3)
1559 gotoscr = 0;
1560 if (gotoscr != 3)
1561 ok = FALSE;
1563 return;
1565 /* ------------------------------------------------------------------------ */
1566 static void display_light()
1568 char datest[32];
1569 int i;
1571 write_icon(" light :", 2, 2);
1572 RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1);
1574 sprintf(datest, "%.2f", ambient_light);
1575 i = 10 - strlen(datest);
1576 if (i < 0)
1577 i = 0;
1578 else
1579 i = i / 2;
1580 write_icon(datest, 2 + i * 6, 14);
1581 RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1);
1583 write_icon(" dawn :", 2, 26);
1584 RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1);
1586 dawn = (1.0 - dawn) * 2.0;
1587 sprintf(datest, "%.2f", dawn);
1588 dawn = (1.0 - dawn / 2.0);
1589 i = 10 - strlen(datest);
1590 if (i < 0)
1591 i = 0;
1592 else
1593 i = i / 2;
1594 write_icon(datest, 2 + i * 6, 38);
1595 RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1);
1597 return;
1599 /* ------------------------------------------------------------------------ */
1600 static void move_light(int factor)
1602 ambient_light += factor / 20.0;
1603 ambient_light = MAX(0.0, ambient_light);
1604 ambient_light = MIN(1.0, ambient_light);
1605 aml = (int) floor(ambient_light * 256);
1607 XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
1608 0, 15, 60, 10, 2, 14);
1610 display_light();
1611 return;
1613 /* ------------------------------------------------------------------------ */
1614 static void move_dawn(int factor)
1616 dawn = (1.0 - dawn) * 2.0;
1617 dawn += factor / 20.0;
1618 dawn = MAX(0.0, dawn);
1619 dawn = MIN(1.0, dawn);
1620 dawn = (1.0 - dawn / 2.0);
1621 XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
1622 0, 15, 60, 10, 2, 38);
1624 display_light();
1625 return;
1627 /* ------------------------------------------------------------------------ */
1628 static void screen_4()
1630 int ok, ckm, waitrel, sensadd, not3;
1631 struct timeval tin;
1633 #ifdef DEBUG
1634 fprintf(stdout, "scr 4\n");
1635 #endif
1636 tin = getimev();
1637 waitrel = 0;
1638 ckm = 0;
1639 sensadd = 0;
1640 not3 = TRUE;
1641 XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask, ShapeSet);
1642 XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask, ShapeSet);
1644 XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE, DIAMETRE, 0, 0);
1646 AddMouseRegion(1, 2, 14, DIAMETRE - 2, 25);
1647 AddMouseRegion(2, 2, 38, DIAMETRE - 2, 49);
1648 display_light();
1650 ok = TRUE;
1651 while (ok) {
1653 while (XPending(dpy)) {
1654 XNextEvent(dpy, &Event);
1655 switch (Event.type) {
1656 case Expose:
1657 RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE);
1658 break;
1659 case DestroyNotify:
1660 XCloseDisplay(dpy);
1661 exit(0);
1662 break;
1663 case ButtonPress:
1664 ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
1665 waitrel = 1;
1666 press_but(ckm);
1667 switch (Event.xbutton.button) {
1668 case 1:
1669 not3 = TRUE;
1670 sensadd = 1;
1671 break;
1672 case 2:
1673 not3 = TRUE;
1674 sensadd = -1;
1675 break;
1676 case 3:
1677 not3 = FALSE;
1678 if (ckm < 5)
1679 gotoscr = 0;
1680 break;
1681 default:
1682 break;
1684 break;
1685 case ButtonRelease:
1686 release_but(ckm);
1687 waitrel = ckm;
1688 ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
1689 if (waitrel == ckm) {
1690 switch (ckm) {
1691 case 5:
1692 gotoscr--;
1693 if (gotoscr == 0)
1694 gotoscr = NUM_SCREEN;
1695 break;
1696 case 6:
1697 gotoscr++;
1698 if (gotoscr > NUM_SCREEN)
1699 gotoscr = 1;
1700 break;
1701 case 7:
1702 gotoscr = 0;
1703 default:
1704 break;
1707 ckm = 0;
1708 waitrel = 0;
1709 tin = getimev();
1710 break;
1711 default:
1712 break;
1715 usleep(VAL_USLEEP_SHORT);
1716 if (waitrel && not3) {
1717 if (ckm == 1) {
1718 move_light(sensadd);
1719 usleep(VAL_USLEEP);
1721 if (ckm == 2) {
1722 move_dawn(sensadd);
1723 usleep(VAL_USLEEP);
1726 if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT && gotoscr == 4)
1727 gotoscr = 0;
1728 if (gotoscr != 4)
1729 ok = FALSE;
1731 return;
1733 /* ------------------------------------------------------------------------ */
1734 static void display_accel()
1736 char datest[32];
1737 int i;
1739 write_icon(" accel :", 2, 2);
1740 RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1);
1742 if (time_multi < 24.0)
1743 sprintf(datest, "%.1f", time_multi);
1744 else
1745 sprintf(datest, "%.0f", time_multi);
1747 i = 10 - strlen(datest);
1748 if (i < 0)
1749 i = 0;
1750 else
1751 i = i / 2;
1752 write_icon(datest, 2 + i * 6, 14);
1753 RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1);
1755 write_icon("night map:", 2, 26);
1756 RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1);
1758 if (use_nightmap)
1759 write_icon(" yes ", 2, 38);
1760 else
1761 write_icon(" no ", 2, 38);
1763 RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1);
1765 return;
1767 /* ------------------------------------------------------------------------ */
1768 static void move_accel(int factor)
1770 if (factor == 1) {
1771 if (time_multi < 1.0)
1772 time_multi = 1.0;
1773 if (time_multi < 24.0)
1774 time_multi += 0.2;
1775 else if (time_multi < 60.0) {
1776 time_multi = floor(time_multi);
1777 time_multi += 1.0;
1778 } else if (time_multi < 120.0) {
1779 time_multi = floor(time_multi);
1780 time_multi += 2.0;
1781 } else if (time_multi < 240.0) {
1782 time_multi = floor(time_multi);
1783 time_multi += 4.0;
1784 } else if (time_multi < 600.0) {
1785 time_multi = floor(time_multi);
1786 time_multi += 10.0;
1787 } else if (time_multi < 1200.0) {
1788 time_multi = floor(time_multi);
1789 time_multi += 20.0;
1790 } else if (time_multi < 2400.0) {
1791 time_multi = floor(time_multi);
1792 time_multi += 40.0;
1793 } else if (time_multi < 6000.0) {
1794 time_multi = floor(time_multi);
1795 time_multi += 100.0;
1796 } else if (time_multi < 12000.0) {
1797 time_multi = floor(time_multi);
1798 time_multi += 200.0;
1799 } else if (time_multi < 24000.0) {
1800 time_multi = floor(time_multi);
1801 time_multi += 400.0;
1802 } else if (time_multi < 60000.0) {
1803 time_multi = floor(time_multi);
1804 time_multi += 1000.0;
1805 } else if (time_multi < 120000.0) {
1806 time_multi = floor(time_multi);
1807 time_multi += 2000.0;
1808 } else if (time_multi < 240000.0) {
1809 time_multi = floor(time_multi);
1810 time_multi += 4000.0;
1811 } else {
1812 time_multi = floor(time_multi);
1813 time_multi += 8000.0;
1815 if (time_multi > MAX_MULTI_COEF)
1816 time_multi = MAX_MULTI_COEF;
1817 } else {
1818 if (time_multi < 24.1)
1819 time_multi -= 0.2;
1820 else if (time_multi < 60.2) {
1821 time_multi = floor(time_multi);
1822 time_multi -= 1.0;
1823 } else if (time_multi < 121.0) {
1824 time_multi = floor(time_multi);
1825 time_multi -= 2.0;
1826 } else if (time_multi < 241.0) {
1827 time_multi = floor(time_multi);
1828 time_multi -= 4.0;
1829 } else if (time_multi < 601.0) {
1830 time_multi = floor(time_multi);
1831 time_multi -= 10.0;
1832 } else if (time_multi < 1201.0) {
1833 time_multi = floor(time_multi);
1834 time_multi -= 20.0;
1835 } else if (time_multi < 2401.0) {
1836 time_multi = floor(time_multi);
1837 time_multi -= 40.0;
1838 } else if (time_multi < 6001.0) {
1839 time_multi = floor(time_multi);
1840 time_multi -= 100.0;
1841 } else if (time_multi < 12001.0) {
1842 time_multi = floor(time_multi);
1843 time_multi -= 200.0;
1844 } else if (time_multi < 24001.0) {
1845 time_multi = floor(time_multi);
1846 time_multi -= 400.0;
1847 } else if (time_multi < 60001.0) {
1848 time_multi = floor(time_multi);
1849 time_multi -= 1000.0;
1850 } else if (time_multi < 120001.0) {
1851 time_multi = floor(time_multi);
1852 time_multi -= 2000.0;
1853 } else if (time_multi < 240001.0) {
1854 time_multi = floor(time_multi);
1855 time_multi -= 4000.0;
1856 } else {
1857 time_multi = floor(time_multi);
1858 time_multi -= 8000.0;
1861 if (time_multi > 24.0)
1862 time_multi = floor(time_multi);
1863 if (time_multi < 1.0)
1864 time_multi = 1.0;
1867 tini = tlast;
1868 tbase = trend;
1870 XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
1871 0, 15, 60, 10, 2, 14);
1873 display_accel();
1874 return;
1876 /* ------------------------------------------------------------------------ */
1877 static void screen_5()
1879 int ok, ckm, waitrel, sensadd, not3;
1880 struct timeval tin;
1882 #ifdef DEBUG
1883 fprintf(stdout, "scr 5\n");
1884 #endif
1885 tin = getimev();
1886 waitrel = 0;
1887 ckm = 0;
1888 sensadd = 0;
1889 not3 = TRUE;
1890 XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask, ShapeSet);
1891 XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask, ShapeSet);
1893 XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE, DIAMETRE, 0, 0);
1895 AddMouseRegion(1, 2, 14, DIAMETRE - 2, 25);
1896 AddMouseRegion(2, 2, 38, DIAMETRE - 2, 49);
1897 display_accel();
1899 ok = TRUE;
1900 while (ok) {
1902 while (XPending(dpy)) {
1903 XNextEvent(dpy, &Event);
1904 switch (Event.type) {
1905 case Expose:
1906 RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE);
1907 break;
1908 case DestroyNotify:
1909 XCloseDisplay(dpy);
1910 exit(0);
1911 break;
1912 case ButtonPress:
1913 ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
1914 waitrel = 1;
1915 press_but(ckm);
1916 switch (Event.xbutton.button) {
1917 case 1:
1918 not3 = TRUE;
1919 sensadd = 1;
1920 break;
1921 case 2:
1922 not3 = TRUE;
1923 sensadd = -1;
1924 break;
1925 case 3:
1926 not3 = FALSE;
1927 if (ckm < 5)
1928 gotoscr = 0;
1929 break;
1930 default:
1931 break;
1933 break;
1934 case ButtonRelease:
1935 release_but(ckm);
1936 waitrel = ckm;
1937 ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
1938 if (waitrel == ckm) {
1939 switch (ckm) {
1940 case 5:
1941 gotoscr--;
1942 if (gotoscr == 0)
1943 gotoscr = NUM_SCREEN;
1944 break;
1945 case 6:
1946 gotoscr++;
1947 if (gotoscr > NUM_SCREEN)
1948 gotoscr = 1;
1949 break;
1950 case 7:
1951 gotoscr = 0;
1952 default:
1953 break;
1956 ckm = 0;
1957 waitrel = 0;
1958 tin = getimev();
1959 break;
1960 default:
1961 break;
1965 usleep(VAL_USLEEP_SHORT);
1966 if (waitrel && not3) {
1967 if (ckm == 1) {
1968 move_accel(sensadd);
1969 usleep(VAL_USLEEP);
1971 if (ckm == 2) {
1972 not3 = FALSE;
1973 if (use_nightmap) {
1974 use_nightmap = FALSE;
1975 display_accel();
1976 } else {
1977 if (use_nmap_ini) {
1978 use_nightmap = TRUE;
1979 display_accel();
1982 usleep(VAL_USLEEP);
1985 if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT && gotoscr == 5)
1986 gotoscr = 0;
1987 if (gotoscr != 5)
1988 ok = FALSE;
1990 return;
1992 /* ------------------------------------------------------------------------ */
1993 static void display_dlat()
1995 char datest[32];
1996 int i, d, m, nega, nego;
1998 write_icon(" dlat :", 2, 2);
1999 RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1);
2000 if (dlat < 0.0) {
2001 nega = TRUE;
2002 dlat *= -1;
2003 } else
2004 nega = FALSE;
2006 m = (int) floor((dlat - floor(dlat)) * 60.0);
2007 d = (int) floor(dlat);
2009 if (nega) {
2010 sprintf(datest, "-%d°%02d'", d, m);
2011 dlat *= -1;
2012 } else
2013 sprintf(datest, "%d°%02d'", d, m);
2015 i = 10 - strlen(datest);
2016 if (i < 0)
2017 i = 0;
2018 else
2019 i = i / 2;
2020 write_icon(datest, 2 + i * 6, 14);
2021 RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1);
2023 write_icon(" dlong :", 2, 26);
2024 RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1);
2027 if (dlong < 0.0) {
2028 nego = TRUE;
2029 dlong *= -1;
2030 } else
2031 nego = FALSE;
2033 m = (int) floor((dlong - floor(dlong)) * 60.0);
2034 d = (int) floor(dlong);
2036 if (nego) {
2037 sprintf(datest, "-%d°%02d'", d, m);
2038 dlong *= -1;
2039 } else
2040 sprintf(datest, "%d°%02d'", d, m);
2042 i = 10 - strlen(datest);
2043 if (i < 0)
2044 i = 0;
2045 else
2046 i = i / 2;
2047 write_icon(datest, 2 + i * 6, 38);
2048 RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1);
2050 return;
2052 /* ------------------------------------------------------------------------ */
2053 static void move_dlat(int factor)
2055 dlat += factor / 4.0;
2056 if (dlat > MAX_DELTA_LONG)
2057 dlat = MAX_DELTA_LONG;
2058 if (dlat < -MAX_DELTA_LONG)
2059 dlat = -MAX_DELTA_LONG;
2060 if (dlat < 0.25 && dlat > -0.25)
2061 dlat = 0;
2062 XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
2063 0, 15, 60, 10, 2, 14);
2064 if (dlat != 0.)
2065 p_type = PTFIXED;
2066 display_dlat();
2067 return;
2069 /* ------------------------------------------------------------------------ */
2070 static void move_dlong(int factor)
2072 dlong += factor / 4.0;
2073 if (dlong > MAX_DELTA_LONG)
2074 dlong = MAX_DELTA_LONG;
2075 if (dlong < -MAX_DELTA_LONG)
2076 dlong = -MAX_DELTA_LONG;
2077 if (dlong < 0.25 && dlong > -0.25)
2078 dlong = 0;
2079 XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC,
2080 0, 15, 60, 10, 2, 38);
2081 if (dlong != 0.)
2082 p_type = PTFIXED;
2083 display_dlat();
2084 return;
2086 /* ------------------------------------------------------------------------ */
2087 static void screen_6()
2089 int ok, ckm, waitrel, sensadd, not3;
2090 struct timeval tin;
2092 #ifdef DEBUG
2093 fprintf(stdout, "scr 6\n");
2094 #endif
2095 tin = getimev();
2096 waitrel = 0;
2097 sensadd = 0;
2098 ckm = 0;
2099 not3 = TRUE;
2100 XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask, ShapeSet);
2101 XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask, ShapeSet);
2103 XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE, DIAMETRE, 0, 0);
2104 AddMouseRegion(1, 2, 14, DIAMETRE - 2, 25);
2105 AddMouseRegion(2, 2, 38, DIAMETRE - 2, 49);
2107 display_dlat();
2109 ok = TRUE;
2110 while (ok) {
2112 while (XPending(dpy)) {
2113 XNextEvent(dpy, &Event);
2114 switch (Event.type) {
2115 case Expose:
2116 RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE);
2117 break;
2118 case DestroyNotify:
2119 XCloseDisplay(dpy);
2120 exit(0);
2121 break;
2122 case ButtonPress:
2123 ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
2124 waitrel = 1;
2125 press_but(ckm);
2126 switch (Event.xbutton.button) {
2127 case 1:
2128 not3 = TRUE;
2129 sensadd = 1;
2130 break;
2131 case 2:
2132 not3 = TRUE;
2133 sensadd = -1;
2134 break;
2135 case 3:
2136 not3 = FALSE;;
2137 if (ckm < 5)
2138 gotoscr = 0;
2139 break;
2140 default:
2141 break;
2143 break;
2144 case ButtonRelease:
2145 release_but(ckm);
2146 waitrel = ckm;
2147 ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
2148 if (waitrel == ckm) {
2149 switch (ckm) {
2150 case 5:
2151 gotoscr--;
2152 if (gotoscr == 0)
2153 gotoscr = NUM_SCREEN;
2154 break;
2155 case 6:
2156 gotoscr++;
2157 if (gotoscr > NUM_SCREEN)
2158 gotoscr = 1;
2159 break;
2160 case 7:
2161 gotoscr = 0;
2162 default:
2163 break;
2166 ckm = 0;
2167 waitrel = 0;
2168 tin = getimev();
2169 break;
2170 default:
2171 break;
2175 usleep(VAL_USLEEP_SHORT);
2176 if (waitrel && not3) {
2177 if (ckm == 1 && p_type != PTRANDOM) {
2178 move_dlat(sensadd);
2179 usleep(VAL_USLEEP);
2181 if (ckm == 2 && p_type != PTRANDOM) {
2182 move_dlong(sensadd);
2183 usleep(VAL_USLEEP);
2186 if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT && gotoscr == 6)
2187 gotoscr = 0;
2188 if (gotoscr != 6)
2189 ok = FALSE;
2191 return;
2193 /* ------------------------------------------------------------------------ */
2194 static void display_type()
2196 char c, cc, mess[12];
2198 write_icon(" view :", 2, 2);
2199 RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1);
2201 if (p_type == PTFIXED) {
2202 c = '>';
2203 cc = '<';
2204 } else {
2205 c = ' ';
2206 cc = ' ';
2208 sprintf(mess, "%c move %c", c, cc);
2209 write_icon(mess, 2, 14);
2210 RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1);
2211 if (p_type == PTSUNREL) {
2212 c = '>';
2213 cc = '<';
2214 } else {
2215 c = ' ';
2216 cc = ' ';
2218 sprintf(mess, "%c sun %c", c, cc);
2219 write_icon(mess, 2, 26);
2220 RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1);
2221 if (p_type == PTRANDOM) {
2222 c = '>';
2223 cc = '<';
2224 } else {
2225 c = ' ';
2226 cc = ' ';
2228 sprintf(mess, "%c random %c", c, cc);
2229 write_icon(mess, 2, 38);
2230 RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1);
2232 return;
2234 /* ------------------------------------------------------------------------ */
2235 static void screen_7()
2237 int ok, ckm, waitrel, sensadd, not3;
2238 struct timeval tin;
2240 #ifdef DEBUG
2241 fprintf(stdout, "scr 7\n");
2242 #endif
2243 tin = getimev();
2244 waitrel = 0;
2245 sensadd = 0;
2246 ckm = 0;
2247 not3 = TRUE;
2249 XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask, ShapeSet);
2250 XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask, ShapeSet);
2252 XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE, DIAMETRE, 0, 0);
2253 AddMouseRegion(1, 2, 14, DIAMETRE - 2, 25);
2254 AddMouseRegion(2, 2, 26, DIAMETRE - 2, 37);
2255 AddMouseRegion(3, 2, 38, DIAMETRE - 2, 49);
2257 display_type(0);
2259 ok = TRUE;
2260 while (ok) {
2262 while (XPending(dpy)) {
2263 XNextEvent(dpy, &Event);
2264 switch (Event.type) {
2265 case Expose:
2266 RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE);
2267 break;
2268 case DestroyNotify:
2269 XCloseDisplay(dpy);
2270 exit(0);
2271 break;
2272 case ButtonPress:
2273 ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
2274 waitrel = 1;
2275 press_but(ckm);
2276 switch (Event.xbutton.button) {
2277 case 1:
2278 not3 = TRUE;
2279 if (ckm < 4 && ckm > 0)
2280 sensadd = ckm;
2281 break;
2282 case 2:
2283 not3 = TRUE;
2284 break;
2285 case 3:
2286 not3 = FALSE;
2287 if (ckm < 5)
2288 gotoscr = 0;
2289 break;
2290 default:
2291 break;
2293 break;
2294 case ButtonRelease:
2295 release_but(ckm);
2296 waitrel = ckm;
2297 ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y);
2298 if (waitrel == ckm) {
2299 switch (ckm) {
2300 case 5:
2301 gotoscr--;
2302 if (gotoscr == 0)
2303 gotoscr = NUM_SCREEN;
2304 break;
2305 case 6:
2306 gotoscr++;
2307 if (gotoscr > NUM_SCREEN)
2308 gotoscr = 1;
2309 break;
2310 case 7:
2311 gotoscr = 0;
2312 default:
2313 break;
2316 ckm = 0;
2317 waitrel = 0;
2318 tin = getimev();
2319 break;
2320 default:
2321 break;
2324 usleep(VAL_USLEEP_SHORT);
2325 if (waitrel && not3 && sensadd) {
2326 if (sensadd == 2) {
2327 if (p_type != PTSUNREL) {
2328 p_type = PTSUNREL;
2329 dlat = 0;
2330 dlong = 0;
2331 display_type();
2334 if (sensadd == 1) {
2335 if (p_type != PTFIXED) {
2336 p_type = PTFIXED;
2337 display_type();
2340 if (sensadd == 3) {
2341 if (p_type != PTRANDOM) {
2342 p_type = PTRANDOM;
2343 dlat = 0;
2344 dlong = 0;
2345 display_type();
2349 sensadd = 0;
2350 if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT && gotoscr == 7)
2351 gotoscr = 0;
2352 if (gotoscr != 7)
2353 ok = FALSE;
2355 return;
2357 /* ------------------------------------------------------------------------ */