1 /* WMGlobe 1.3 - All the Earth on a WMaker Icon
2 * copyright (C) 1998,99,2000,01 Jerome Dumonteil <jerome.dumonteil@linuxfr.org>
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 ***************************************************************************/
32 #include "scrtime.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
);
66 /**************************************************************************
68 *************************************************************************/
70 struct timeval
diftimev(struct timeval t1
, struct timeval t2
)
72 t1
.tv_usec
-= t2
.tv_usec
;
74 t1
.tv_usec
+= 1000000;
77 t1
.tv_sec
-= t2
.tv_sec
;
83 struct timeval
addtimev(struct timeval t1
, struct timeval t2
)
85 t1
.tv_usec
+= t2
.tv_usec
;
86 if (t1
.tv_usec
>= 1000000) {
87 t1
.tv_usec
-= 1000000;
90 t1
.tv_sec
+= t2
.tv_sec
;
96 struct timeval
getimev()
101 gettimeofday(&tv
, &tz
);
106 /***************************************************************************
109 * defaults, commandline
110 * init of pixmap for screenpos and numbers displaying
111 ***************************************************************************/
113 void loadxpm(Window draw
)
115 XpmCreatePixmapFromData(dpy
, draw
, scrpos_xpm
, &(screenpos
.pixmap
),
116 &(screenpos
.mask
), &(screenpos
.attributes
));
117 XpmCreatePixmapFromData(dpy
, draw
, scrtime_xpm
, &(scrdate
.pixmap
),
118 &(scrdate
.mask
), &(scrdate
.attributes
));
119 XpmCreatePixmapFromData(dpy
, draw
, zapnum_xpm
, &(numpix
.pixmap
),
120 &(numpix
.mask
), &(numpix
.attributes
));
121 XpmCreatePixmapFromData(dpy
, draw
, zaptxt_xpm
, &(txtpix
.pixmap
),
122 &(txtpix
.mask
), &(txtpix
.attributes
));
123 XpmCreatePixmapFromData(dpy
, draw
, scrdiv_xpm
, &(scrdiv
.pixmap
),
124 &(scrdiv
.mask
), &(scrdiv
.attributes
));
140 use_default_nightmap
= FALSE
;
142 oknimap
= DEFAULT_NIGHTMAP
;
144 delay
= DEFAULT_DELAY
;
152 v_lat
= DEFAULT_V_LAT
/ 180. * PI
;
153 v_long
= DEFAULT_V_LONG
/ 180. * PI
;
154 dv_lat
= DEFAULT_V_LAT
;
155 dv_long
= DEFAULT_V_LONG
;
156 old_dvlat
= DEFAULT_V_LAT
;
157 old_dvlong
= DEFAULT_V_LONG
;
166 fov
= 0.5 * PI
/ 180.;
169 ambient_light
= DEFAULT_LIGHT
;
171 typecadre
= DEFAULT_BORDER
;
177 option_iw
= WithdrawnState
;
180 proj_dist
= DIAMETRE
/ tan(fov
);
189 sun_col
.red
= CR_SUN_R
;
190 sun_col
.green
= CR_SUN_G
;
191 sun_col
.blue
= CR_SUN_B
;
193 moon_col
.red
= CR_MOON_R
;
194 moon_col
.green
= CR_MOON_G
;
195 moon_col
.blue
= CR_MOON_B
;
196 moon_col
.alpha
= 255;
198 md
[0] = (MPO
*) malloc(sizeof(MPO
));
199 md
[1] = (MPO
*) malloc(sizeof(MPO
));
200 md
[2] = (MPO
*) malloc(sizeof(MPO
));
201 md
[3] = (MPO
*) malloc(sizeof(MPO
));
202 mn
[0] = (MPO
*) malloc(sizeof(MPO
));
203 mn
[1] = (MPO
*) malloc(sizeof(MPO
));
204 mn
[2] = (MPO
*) malloc(sizeof(MPO
));
205 mn
[3] = (MPO
*) malloc(sizeof(MPO
));
215 static double getdegre(char *val
)
218 if (strchr(val
, '°') != NULL
|| strchr(val
, 'd') != NULL
219 || strchr(val
, 'D') != NULL
|| strchr(val
, ':') != NULL
) {
221 sscanf(val
, "%lf%*c%lf%*c%lf", &d
, &m
, &s
);
223 return d
+ m
/ 60. + s
/ 3600.;
225 return d
- m
/ 60. - s
/ 3600.;
234 static void mqparam()
236 fprintf(stderr
, "error in parameters\n");
244 void cmdline(int argc
, char *argv
[])
249 for (i
= 1; i
< argc
; i
++) {
253 if (strcasecmp(argv
[i
], "-v") == 0
254 || strcasecmp(argv
[i
], "-version") == 0) {
255 printf("%s\n", WMGVERSION
);
259 if (strcasecmp(argv
[i
], "-w") == 0
260 || strcasecmp(argv
[i
], "-wmaker") == 0) {
261 option_iw
= WithdrawnState
;
265 if (strcasecmp(argv
[i
], "-i") == 0
266 || strcasecmp(argv
[i
], "-iconic") == 0) {
267 option_iw
= IconicState
;
271 if (!j
&& (strcasecmp(argv
[i
], "-s") == 0 ||
272 strcasecmp(argv
[i
], "-shape") == 0)) {
277 if (!j
&& (strcasecmp(argv
[i
], "-d") == 0
278 || strcasecmp(argv
[i
], "-display") == 0)) {
289 if (!j
&& (strcasecmp(argv
[i
], "-stable") == 0
290 || strcasecmp(argv
[i
], "-stab") == 0)) {
295 if (!j
&& (strcasecmp(argv
[i
], "-rand") == 0
296 || strcasecmp(argv
[i
], "-random") == 0)) {
298 srandom(((int) time(NULL
)) + ((int) getpid()));
302 if (!j
&& (strcasecmp(argv
[i
], "-sun") == 0
303 || strcasecmp(argv
[i
], "-soleil") == 0)) {
309 if (!j
&& (strcasecmp(argv
[i
], "-moon") == 0
310 || strcasecmp(argv
[i
], "-lune") == 0)) {
316 if (!j
&& (strcasecmp(argv
[i
], "-oz") == 0
317 || strcasecmp(argv
[i
], "-austral") == 0)) {
322 if (!j
&& strcasecmp(argv
[i
], "-map") == 0) {
328 if ((dayfile
= (char *) malloc(strlen(argv
[i
]) + 1)) ==
330 fprintf(stderr
, "erreur memoire options map\n");
333 strcpy(dayfile
, argv
[i
]);
340 if (!j
&& (strcasecmp(argv
[i
], "-nimap") == 0
341 || strcasecmp(argv
[i
], "-nightmap") == 0
342 || strcasecmp(argv
[i
], "-night") == 0)) {
347 if ((nightfile
= (char *) malloc(strlen(argv
[i
]) + 1))
349 fprintf(stderr
, "erreur memoire options nimap\n");
352 strcpy(nightfile
, argv
[i
]);
360 if (!j
&& (strcasecmp(argv
[i
], "-accel") == 0
361 || strcasecmp(argv
[i
], "-accell") == 0
362 || strcasecmp(argv
[i
], "-acc") == 0
363 || strcasecmp(argv
[i
], "-multi") == 0)) {
367 time_multi
= atof(argv
[i
]);
368 if (time_multi
< 1.0)
370 if (time_multi
> MAX_MULTI_COEF
)
371 time_multi
= MAX_MULTI_COEF
;
372 if (time_multi
> 24.0)
373 time_multi
= floor(time_multi
);
375 time_multi
= floor(time_multi
* 10.0) / 10.0;
382 if (!j
&& (strcasecmp(argv
[i
], "-nonimap") == 0
383 || strcasecmp(argv
[i
], "-nonightmap") == 0
384 || strcasecmp(argv
[i
], "-nonight") == 0
385 || strcasecmp(argv
[i
], "-nomap") == 0)) {
387 use_nightmap
= FALSE
;
391 if (!j
&& (strcasecmp(argv
[i
], "-defnimap") == 0
392 || strcasecmp(argv
[i
], "-defnightmap") == 0
393 || strcasecmp(argv
[i
], "-defnight") == 0)) {
395 use_default_nightmap
= TRUE
;
398 if (!j
&& strcasecmp(argv
[i
], "-zoom") == 0) {
402 zoom
= atof(argv
[i
]);
413 if (!j
&& strcasecmp(argv
[i
], "-dawn") == 0) {
417 dawn
= atof(argv
[i
]);
418 dawn
= MAX(0.0, dawn
);
419 dawn
= MIN(1.0, dawn
);
421 dawn
= (1.0 - dawn
/ 2.0);
428 if (!j
&& strcasecmp(argv
[i
], "-delay") == 0) {
432 delay
= atof(argv
[i
]);
435 if (delay
> MAX_DELAY_SEC
)
436 delay
= MAX_DELAY_SEC
;
443 if (!j
&& (strcasecmp(argv
[i
], "-dlat") == 0
444 || strcasecmp(argv
[i
], "-lat") == 0
445 || strcasecmp(argv
[i
], "-dlatitude") == 0)) {
449 dlat
= getdegre(argv
[i
]);
450 if (dlat
< -MAX_DELTA_LONG
)
451 dlat
= -MAX_DELTA_LONG
;
452 if (dlat
> MAX_DELTA_LONG
)
453 dlat
= MAX_DELTA_LONG
;
461 if (!j
&& (strcasecmp(argv
[i
], "-dlong") == 0
462 || strcasecmp(argv
[i
], "-long") == 0
463 || strcasecmp(argv
[i
], "-dlongitude") == 0)) {
467 dlong
= getdegre(argv
[i
]);
468 if (dlong
< -MAX_DELTA_LONG
)
469 dlong
= -MAX_DELTA_LONG
;
470 if (dlong
> MAX_DELTA_LONG
)
471 dlong
= MAX_DELTA_LONG
;
479 if (!j
&& strcasecmp(argv
[i
], "-light") == 0) {
483 ambient_light
= atof(argv
[i
]);
484 if (ambient_light
< 0.)
486 if (ambient_light
> 1.)
494 if (!j
&& strcasecmp(argv
[i
], "-time") == 0) {
498 tbase
.tv_sec
= atoi(argv
[i
]);
506 if (!j
&& (strcasecmp(argv
[i
], "-bord") == 0
507 || strcasecmp(argv
[i
], "-border") == 0)) {
511 typecadre
= atoi(argv
[i
]);
522 if (!j
&& strcasecmp(argv
[i
], "-fun") == 0) {
526 funx
= atoi(argv
[i
]);
531 funy
= atoi(argv
[i
]);
542 if (!j
&& (strcasecmp(argv
[i
], "-pos") == 0
543 || strcasecmp(argv
[i
], "-position") == 0
544 || strcasecmp(argv
[i
], "-fixed") == 0)) {
548 addlat
= getdegre(argv
[i
]);
552 addlong
= getdegre(argv
[i
]);
564 if (!j
&& (strcasecmp(argv
[i
], "-mk") == 0
565 || strcasecmp(argv
[i
], "-marker") == 0)) {
566 if (nb_marker
== MAX_MARKERS
) {
567 fprintf(stderr
, "Too many markers, max=%d\n",
574 if (strcasecmp(argv
[i
], "sun") == 0) {
575 sun_marker
= nb_marker
;
577 } else if (strcasecmp(argv
[i
], "moon") == 0) {
578 moon_marker
= nb_marker
;
581 marker
[nb_marker
][1] = getdegre(argv
[i
]);
584 marker
[nb_marker
][0] = getdegre(argv
[i
]);
599 if (!j
&& argv
[i
][0] == '-') {
600 printf("%s\n", WMGVERSION
);
603 ("-v : version -h : this help message !\n");
605 ("-zoom zoom_value : changing apparent size in icon\n");
607 ("-pos latitude long. : fixed initial position (default=follow sun)\n");
608 printf("-sun : follow the sun (default)\n");
610 printf("-moon : follow the moon\n");
613 ("-rand : random position at every refresh\n");
615 ("-map map_file : use this map for rendering\n");
617 ("-nimap night_file : and this one for the dark side of earth\n");
619 ("-defnimap : use the default night map (with a custom map)\n");
621 ("-nonimap : don't use the default night map\n");
623 ("-delay seconds : time between refresh of image\n");
625 ("-dlat delta_lat : latitude speed of point of view (default=follow sun)\n");
626 printf("-dlong delta_long : the same for longitude\n");
628 ("-light light_value : level of light for dark side of earth, [0..1]\n");
630 ("-dawn dawn_value : level of continuity for dawn limit\n");
632 ("-bord border_num : 0 1 or 2 , type of icon border.\n");
633 printf("-accel time_multi : time accelerator\n");
635 ("-time seconds : time to display in seconds since 01-01-1970\n");
637 ("-oz : start in \"austral\" mode (for \"down under\" people)\n");
639 ("-stable : keep the globe from going over the poles\n");
642 ("-mk latitude long. : position of a marker (or \"sun\", \"moon\")\n");
645 ("-fun dx dy : offset of vision... almost useless\n");
647 ("-w -shape : set by default (WMaker dockable application)\n");
649 ("-d display : display (WindowMaker not needed on the server side)\n");
651 ("left button : change longitude, with shift key, change latitude too\n");
653 ("middle button : zoom in, shift + middle button : zoom out\n");
655 ("right button : access to a few screens of parameters\n");
664 /****************************************************************************
665 * X functions, mouse selection
667 ****************************************************************************/
670 static int flush_expose(Window w
)
675 while (XCheckTypedWindowEvent(dpy
, w
, Expose
, &dummy
))
682 void RedrawWindowXYWH(int x
, int y
, int w
, int h
)
684 flush_expose(iconwin
);
685 XCopyArea(dpy
, wmg
.pixmap
, iconwin
, NormalGC
, x
, y
, w
, h
, x
, y
);
687 XCopyArea(dpy
, wmg
.pixmap
, win
, NormalGC
, x
, y
, w
, h
, x
, y
);
693 void AddMouseRegion(unsigned index
, int left
, int top
, int right
, int bottom
)
695 if (index
< MAX_MOUSE_REGION
) {
696 mouse_region
[index
].enable
= 1;
697 mouse_region
[index
].top
= top
;
698 mouse_region
[index
].left
= left
;
699 mouse_region
[index
].bottom
= bottom
;
700 mouse_region
[index
].right
= right
;
707 int CheckMouseRegion(int x
, int y
)
714 for (i
= 0; i
< MAX_MOUSE_REGION
&& !found
; i
++) {
715 if (mouse_region
[i
].enable
&&
716 x
<= mouse_region
[i
].right
&&
717 x
>= mouse_region
[i
].left
&&
718 y
<= mouse_region
[i
].bottom
&& y
>= mouse_region
[i
].top
)
728 /****************************************************************************
729 * GRAPHIC : pixmap writing of letters & numbers
731 ****************************************************************************/
733 static void chiffre(int ch
, int xx
, int yy
)
735 XCopyArea(dpy
, numpix
.pixmap
, wmg
.pixmap
, NormalGC
,
736 zapnum
[ch
][0], zapnum
[ch
][1], zapnum
[ch
][2], zapnum
[ch
][3],
743 static int lettre(char c
, int xx
, int yy
)
749 switch (toupper(c
)) {
953 XCopyArea(dpy
, txtpix
.pixmap
, wmg
.pixmap
, NormalGC
,
954 i
, 0, 6, 10, xx
, yy
);
960 static void write_icon(char *txt
, int x
, int y
)
966 fprintf(stdout
, "%s_\n", txt
);
970 if (txt
[p
] == '\0' || x
> DIAMETRE
- 5) {
973 x
= lettre(txt
[p
], x
, y
);
982 static void press_but(int ckm
)
986 XCopyArea(dpy
, scrdiv
.pixmap
, wmg
.pixmap
, NormalGC
,
987 0, 38, 20, 9, 2, 52);
988 RedrawWindowXYWH(2, 52, 20, 9);
991 XCopyArea(dpy
, scrdiv
.pixmap
, wmg
.pixmap
, NormalGC
,
992 20, 38, 20, 9, 22, 52);
993 RedrawWindowXYWH(22, 52, 20, 9);
996 XCopyArea(dpy
, scrdiv
.pixmap
, wmg
.pixmap
, NormalGC
,
997 40, 38, 20, 9, 42, 52);
998 RedrawWindowXYWH(42, 52, 20, 9);
1008 static void release_but(int ckm
)
1012 XCopyArea(dpy
, scrdiv
.pixmap
, wmg
.pixmap
, NormalGC
,
1013 0, 28, 20, 9, 2, 52);
1014 RedrawWindowXYWH(2, 52, 20, 9);
1017 XCopyArea(dpy
, scrdiv
.pixmap
, wmg
.pixmap
, NormalGC
,
1018 20, 28, 20, 9, 22, 52);
1019 RedrawWindowXYWH(22, 52, 20, 9);
1022 XCopyArea(dpy
, scrdiv
.pixmap
, wmg
.pixmap
, NormalGC
,
1023 40, 28, 20, 9, 42, 52);
1024 RedrawWindowXYWH(42, 52, 20, 9);
1035 /***************************************************************************
1036 * MENU SELECTION & ACTIONS
1037 ***************************************************************************/
1042 AddMouseRegion(0, 0, 0, 0, 0);
1043 if (p_type
== PTRANDOM
) {
1044 stoprand
= STOP_RANDOM_FACTOR
;
1049 while (gotoscr
!= 0) {
1078 * put old environment
1080 XShapeCombineMask(dpy
, win
, ShapeBounding
, 0, 0, pixmask
, ShapeSet
);
1081 XShapeCombineMask(dpy
, iconwin
, ShapeBounding
, 0, 0, pixmask
,
1084 AddMouseRegion(0, 5, 5, DIAMETRE
- 4, DIAMETRE
- 4);
1086 do_something
= TRUE
;
1093 static void display_pos(double la
, double lo
)
1095 int c
, i
, j
, k
, l
, neg
;
1103 i
= floor(la
/ 10.0);
1108 k
= floor(la
/ 10.0);
1116 chiffre(neg
, platd
[1][0], platd
[1][1]);
1117 chiffre(i
, platd
[2][0], platd
[2][1]);
1118 chiffre(j
, platd
[3][0], platd
[3][1]);
1119 chiffre(k
, platm
[0][0], platd
[0][1]);
1120 chiffre(l
, platm
[1][0], platd
[1][1]);
1128 c
= floor(lo
/ 100.0);
1141 i
= floor(lo
/ 10.0);
1146 k
= floor(lo
/ 10.0);
1149 if (i
== 0 && c
> 9) {
1153 chiffre(neg
, plongd
[0][0], plongd
[0][1]);
1154 chiffre(c
, plongd
[1][0], plongd
[1][1]);
1155 chiffre(i
, plongd
[2][0], plongd
[2][1]);
1156 chiffre(j
, plongd
[3][0], plongd
[3][1]);
1157 chiffre(k
, plongm
[0][0], plongm
[0][1]);
1158 chiffre(l
, plongm
[1][0], plongm
[1][1]);
1160 RedrawWindowXYWH(0, 0, DIAMETRE
, DIAMETRE
);
1166 void rotation_terre(int x
, int y
, int lat_flag
)
1169 * earth rotate after (while) a clic
1173 (double) ((double) x
- DIAMETRE
/ 2 +
1174 0.5) / zoom
* cos(v_lat
) * sens
;
1176 my
= -(double) ((double) y
- DIAMETRE
/ 2 + 0.5) * sens
/ zoom
;
1179 ABS(sin(v_lat
) * ((double) x
- DIAMETRE
/ 2 + 0.5) / zoom
);
1182 ABS(sin(v_lat
) * ((double) x
- DIAMETRE
/ 2 + 0.5) / zoom
);
1186 if (p_type
== PTRANDOM
) {
1187 stoprand
= STOP_RANDOM_FACTOR
;
1191 addlong
+= mx
* RATIO_ROTATE
;
1192 addlat
+= my
* RATIO_ROTATE
;
1194 do_something
= TRUE
;
1200 static void move_earth(double vla
, double vlo
)
1208 setViewPos(sun_lat
* 180. / PI
+ addlat
,
1209 sun_long
* 180. / PI
+ addlong
);
1213 setViewPos(moon_lat
* 180. / PI
+ addlat
,
1214 moon_long
* 180. / PI
+ addlong
);
1219 setViewPos(addlat
, addlong
);
1224 display_pos(dv_lat
, dv_long
);
1230 static void screen_1()
1232 int ok
, ckm
, sensadd
, waitrel
, not3
;
1236 fprintf(stdout
, "scr 1\n");
1244 XShapeCombineMask(dpy
, win
, ShapeBounding
, 0, 0, screenpos
.mask
,
1246 XShapeCombineMask(dpy
, iconwin
, ShapeBounding
, 0, 0, screenpos
.mask
,
1249 XCopyArea(dpy
, screenpos
.pixmap
, wmg
.pixmap
, NormalGC
, 0, 0, DIAMETRE
,
1252 AddMouseRegion(1, platd
[0][0], platd
[0][1], platd
[3][0] + 9,
1254 AddMouseRegion(2, platm
[0][0], platm
[0][1], platm
[1][0] + 9,
1256 AddMouseRegion(3, plongd
[0][0], plongd
[0][1], plongd
[3][0] + 9,
1258 AddMouseRegion(4, plongm
[0][0], plongm
[0][1], plongm
[1][0] + 9,
1260 AddMouseRegion(5, 1, 51, 21, 61);
1261 AddMouseRegion(6, 22, 51, 41, 61);
1262 AddMouseRegion(7, 42, 51, 62, 61);
1264 display_pos(dv_lat
, dv_long
);
1268 while (XPending(dpy
)) {
1269 XNextEvent(dpy
, &Event
);
1270 switch (Event
.type
) {
1272 RedrawWindowXYWH(0, 0, DIAMETRE
, DIAMETRE
);
1279 ckm
= CheckMouseRegion(Event
.xbutton
.x
, Event
.xbutton
.y
);
1282 switch (Event
.xbutton
.button
) {
1302 ckm
= CheckMouseRegion(Event
.xbutton
.x
, Event
.xbutton
.y
);
1303 if (waitrel
== ckm
) {
1308 gotoscr
= NUM_SCREEN
;
1312 if (gotoscr
> NUM_SCREEN
)
1330 usleep(VAL_USLEEP_SHORT
);
1331 if (waitrel
&& not3
) {
1333 move_earth(sens
* sensadd
* 1.0, 0.0);
1337 move_earth(sens
* sensadd
* 1.0 / 60.0, 0.0);
1341 move_earth(0.0, sens
* sensadd
* 1.0);
1345 move_earth(0.0, sens
* sensadd
* 1.0 / 60.0);
1349 if (waitrel
== 0 && diftimev(getimev(), tin
).tv_sec
> SCREEN_WAIT
1360 static void display_date(double la
, double lo
)
1366 write_icon(" time :", 2, 2);
1367 RedrawWindowXYWH(2, 2, DIAMETRE
- 1, DIAMETRE
- 1);
1369 write_icon(" GMT+long.", 2, 14);
1370 RedrawWindowXYWH(2, 14, DIAMETRE
- 1, DIAMETRE
- 1);
1373 t
+= (int) (floor((lo
+ 7.5) / 15.0) * 3600);
1374 /*** pb near 2038 ***/
1376 strftime(datest
, 30, "%x", gmtime(&t
));
1378 i
= 10 - strlen(datest
);
1384 write_icon(datest
, 2 + i
* 6, 26);
1385 RedrawWindowXYWH(2, 26, DIAMETRE
- 1, DIAMETRE
- 1);
1387 strftime(datest
, 30, "%X", gmtime(&t
));
1389 i
= 10 - strlen(datest
);
1392 while (datest
[i
] != '\0') {
1393 if (datest
[i
] != ' ') {
1398 datest
[j
] = datest
[j
+ 1];
1401 while (datest
[j
- 1] != '\0');
1409 write_icon(datest
, 2 + i
* 6, 38);
1410 RedrawWindowXYWH(2, 38, DIAMETRE
- 1, DIAMETRE
- 1);
1417 static void screen_2()
1419 int ok
, ckm
, waitrel
;
1423 fprintf(stdout
, "scr 2\n");
1429 XShapeCombineMask(dpy
, win
, ShapeBounding
, 0, 0, scrdate
.mask
,
1431 XShapeCombineMask(dpy
, iconwin
, ShapeBounding
, 0, 0, scrdate
.mask
,
1434 XCopyArea(dpy
, scrdate
.pixmap
, wmg
.pixmap
, NormalGC
, 0, 0, DIAMETRE
,
1437 display_date(dv_lat
, dv_long
);
1441 while (XPending(dpy
)) {
1442 XNextEvent(dpy
, &Event
);
1443 switch (Event
.type
) {
1445 RedrawWindowXYWH(0, 0, DIAMETRE
, DIAMETRE
);
1452 ckm
= CheckMouseRegion(Event
.xbutton
.x
, Event
.xbutton
.y
);
1455 switch (Event
.xbutton
.button
) {
1471 ckm
= CheckMouseRegion(Event
.xbutton
.x
, Event
.xbutton
.y
);
1472 if (waitrel
== ckm
) {
1477 gotoscr
= NUM_SCREEN
;
1481 if (gotoscr
> NUM_SCREEN
)
1499 usleep(VAL_USLEEP_SHORT
);
1501 if (waitrel
== 0 && diftimev(getimev(), tin
).tv_sec
> SCREEN_WAIT
1512 static void display_zoom()
1514 char datest
[32], dstr
[32];
1517 write_icon(" delay :", 2, 2);
1518 RedrawWindowXYWH(2, 2, DIAMETRE
- 1, DIAMETRE
- 1);
1520 sprintf(dstr
, "%f", delay
);
1522 i
= strlen(dstr
) - 1;
1524 if (dstr
[i
] == '0') {
1531 i
= strlen(dstr
) - 1;
1534 sprintf(datest
, "%s s", dstr
);
1536 i
= 10 - strlen(datest
);
1541 write_icon(datest
, 2 + i
* 6, 14);
1542 RedrawWindowXYWH(2, 14, DIAMETRE
- 1, DIAMETRE
- 1);
1544 write_icon(" zoom :", 2, 26);
1545 RedrawWindowXYWH(2, 26, DIAMETRE
- 1, DIAMETRE
- 1);
1547 sprintf(datest
, "%.3f", zoom
);
1548 i
= 10 - strlen(datest
);
1553 write_icon(datest
, 2 + i
* 6, 38);
1554 RedrawWindowXYWH(2, 38, DIAMETRE
- 1, DIAMETRE
- 1);
1561 static void move_delay(int factor
)
1564 if (delay
< (double) VAL_USLEEP
/ 1000000)
1565 delay
= (double) VAL_USLEEP
/ 1000000;
1566 else if (delay
< 0.1) {
1570 } else if (delay
< 1.) {
1574 } else if (delay
< 60.)
1576 else if (delay
< 300.)
1578 else if (delay
< 3600.)
1580 else if (delay
< MAX_DELAY_SEC
)
1583 if (delay
> MAX_DELAY_SEC
)
1584 delay
= MAX_DELAY_SEC
;
1588 else if (delay
> 300.)
1590 else if (delay
> 60.)
1592 else if (delay
> 1.)
1594 else if (delay
> 0.1)
1596 else if (delay
> (double) VAL_USLEEP
/ 1000000)
1601 if (delay
< (double) VAL_USLEEP
/ 1000000)
1605 tdelay
.tv_sec
= (int) floor(delay
);
1606 tdelay
.tv_usec
= (int) ((delay
- tdelay
.tv_sec
) * 1000000);
1608 XCopyArea(dpy
, scrdiv
.pixmap
, wmg
.pixmap
, NormalGC
,
1609 0, 15, 60, 10, 2, 14);
1617 void zooming(int facto
)
1620 zoom
/= ZOOM_FACTOR
;
1622 zoom
*= ZOOM_FACTOR
;
1623 zoom
= MAX(zoom
, ZOOM_MIN
);
1624 zoom
= MIN(zoom
, ZOOM_MAX
);
1625 if (p_type
== PTRANDOM
) {
1628 stoprand
= STOP_RANDOM_FACTOR
;
1631 do_something
= TRUE
;
1637 static void move_zoom(int factor
)
1643 XCopyArea(dpy
, scrdiv
.pixmap
, wmg
.pixmap
, NormalGC
,
1644 0, 15, 60, 10, 2, 38);
1651 static void screen_3()
1653 int ok
, ckm
, waitrel
, sensadd
, not3
;
1657 fprintf(stdout
, "scr 3\n");
1664 XShapeCombineMask(dpy
, win
, ShapeBounding
, 0, 0, scrdate
.mask
,
1666 XShapeCombineMask(dpy
, iconwin
, ShapeBounding
, 0, 0, scrdate
.mask
,
1669 XCopyArea(dpy
, scrdate
.pixmap
, wmg
.pixmap
, NormalGC
, 0, 0, DIAMETRE
,
1672 AddMouseRegion(1, 2, 14, DIAMETRE
- 2, 25);
1673 AddMouseRegion(2, 2, 38, DIAMETRE
- 2, 49);
1679 while (XPending(dpy
)) {
1680 XNextEvent(dpy
, &Event
);
1681 switch (Event
.type
) {
1683 RedrawWindowXYWH(0, 0, DIAMETRE
, DIAMETRE
);
1690 ckm
= CheckMouseRegion(Event
.xbutton
.x
, Event
.xbutton
.y
);
1693 switch (Event
.xbutton
.button
) {
1714 ckm
= CheckMouseRegion(Event
.xbutton
.x
, Event
.xbutton
.y
);
1715 if (waitrel
== ckm
) {
1720 gotoscr
= NUM_SCREEN
;
1724 if (gotoscr
> NUM_SCREEN
)
1742 usleep(VAL_USLEEP_SHORT
);
1743 if (waitrel
&& not3
) {
1745 move_delay(sensadd
);
1746 usleep(2 * VAL_USLEEP
);
1753 if (waitrel
== 0 && diftimev(getimev(), tin
).tv_sec
> SCREEN_WAIT
1764 static void display_light()
1769 write_icon(" light :", 2, 2);
1770 RedrawWindowXYWH(2, 2, DIAMETRE
- 1, DIAMETRE
- 1);
1772 sprintf(datest
, "%.2f", ambient_light
);
1773 i
= 10 - strlen(datest
);
1778 write_icon(datest
, 2 + i
* 6, 14);
1779 RedrawWindowXYWH(2, 14, DIAMETRE
- 1, DIAMETRE
- 1);
1781 write_icon(" dawn :", 2, 26);
1782 RedrawWindowXYWH(2, 26, DIAMETRE
- 1, DIAMETRE
- 1);
1784 dawn
= (1.0 - dawn
) * 2.0;
1785 sprintf(datest
, "%.2f", dawn
);
1786 dawn
= (1.0 - dawn
/ 2.0);
1787 i
= 10 - strlen(datest
);
1792 write_icon(datest
, 2 + i
* 6, 38);
1793 RedrawWindowXYWH(2, 38, DIAMETRE
- 1, DIAMETRE
- 1);
1800 static void move_light(int factor
)
1802 ambient_light
+= factor
/ 20.0;
1803 ambient_light
= MAX(0.0, ambient_light
);
1804 ambient_light
= MIN(1.0, ambient_light
);
1805 aml
= (int) floor(ambient_light
* 256);
1807 XCopyArea(dpy
, scrdiv
.pixmap
, wmg
.pixmap
, NormalGC
,
1808 0, 15, 60, 10, 2, 14);
1816 static void move_dawn(int factor
)
1818 dawn
= (1.0 - dawn
) * 2.0;
1819 dawn
+= factor
/ 20.0;
1820 dawn
= MAX(0.0, dawn
);
1821 dawn
= MIN(1.0, dawn
);
1822 dawn
= (1.0 - dawn
/ 2.0);
1823 XCopyArea(dpy
, scrdiv
.pixmap
, wmg
.pixmap
, NormalGC
,
1824 0, 15, 60, 10, 2, 38);
1832 static void screen_4()
1834 int ok
, ckm
, waitrel
, sensadd
, not3
;
1838 fprintf(stdout
, "scr 4\n");
1845 XShapeCombineMask(dpy
, win
, ShapeBounding
, 0, 0, scrdate
.mask
,
1847 XShapeCombineMask(dpy
, iconwin
, ShapeBounding
, 0, 0, scrdate
.mask
,
1850 XCopyArea(dpy
, scrdate
.pixmap
, wmg
.pixmap
, NormalGC
, 0, 0, DIAMETRE
,
1853 AddMouseRegion(1, 2, 14, DIAMETRE
- 2, 25);
1854 AddMouseRegion(2, 2, 38, DIAMETRE
- 2, 49);
1860 while (XPending(dpy
)) {
1861 XNextEvent(dpy
, &Event
);
1862 switch (Event
.type
) {
1864 RedrawWindowXYWH(0, 0, DIAMETRE
, DIAMETRE
);
1871 ckm
= CheckMouseRegion(Event
.xbutton
.x
, Event
.xbutton
.y
);
1874 switch (Event
.xbutton
.button
) {
1895 ckm
= CheckMouseRegion(Event
.xbutton
.x
, Event
.xbutton
.y
);
1896 if (waitrel
== ckm
) {
1901 gotoscr
= NUM_SCREEN
;
1905 if (gotoscr
> NUM_SCREEN
)
1922 usleep(VAL_USLEEP_SHORT
);
1923 if (waitrel
&& not3
) {
1925 move_light(sensadd
);
1933 if (waitrel
== 0 && diftimev(getimev(), tin
).tv_sec
> SCREEN_WAIT
1944 static void display_accel()
1949 write_icon(" accel :", 2, 2);
1950 RedrawWindowXYWH(2, 2, DIAMETRE
- 1, DIAMETRE
- 1);
1952 if (time_multi
< 24.0)
1953 sprintf(datest
, "%.1f", time_multi
);
1955 sprintf(datest
, "%.0f", time_multi
);
1957 i
= 10 - strlen(datest
);
1962 write_icon(datest
, 2 + i
* 6, 14);
1963 RedrawWindowXYWH(2, 14, DIAMETRE
- 1, DIAMETRE
- 1);
1965 write_icon("night map:", 2, 26);
1966 RedrawWindowXYWH(2, 26, DIAMETRE
- 1, DIAMETRE
- 1);
1969 write_icon(" yes ", 2, 38);
1971 write_icon(" no ", 2, 38);
1973 RedrawWindowXYWH(2, 38, DIAMETRE
- 1, DIAMETRE
- 1);
1980 static void move_accel(int factor
)
1983 if (time_multi
< 1.0)
1985 if (time_multi
< 24.0)
1987 else if (time_multi
< 60.0) {
1988 time_multi
= floor(time_multi
);
1990 } else if (time_multi
< 120.0) {
1991 time_multi
= floor(time_multi
);
1993 } else if (time_multi
< 240.0) {
1994 time_multi
= floor(time_multi
);
1996 } else if (time_multi
< 600.0) {
1997 time_multi
= floor(time_multi
);
1999 } else if (time_multi
< 1200.0) {
2000 time_multi
= floor(time_multi
);
2002 } else if (time_multi
< 2400.0) {
2003 time_multi
= floor(time_multi
);
2005 } else if (time_multi
< 6000.0) {
2006 time_multi
= floor(time_multi
);
2007 time_multi
+= 100.0;
2008 } else if (time_multi
< 12000.0) {
2009 time_multi
= floor(time_multi
);
2010 time_multi
+= 200.0;
2011 } else if (time_multi
< 24000.0) {
2012 time_multi
= floor(time_multi
);
2013 time_multi
+= 400.0;
2014 } else if (time_multi
< 60000.0) {
2015 time_multi
= floor(time_multi
);
2016 time_multi
+= 1000.0;
2017 } else if (time_multi
< 120000.0) {
2018 time_multi
= floor(time_multi
);
2019 time_multi
+= 2000.0;
2020 } else if (time_multi
< 240000.0) {
2021 time_multi
= floor(time_multi
);
2022 time_multi
+= 4000.0;
2024 time_multi
= floor(time_multi
);
2025 time_multi
+= 8000.0;
2027 if (time_multi
> MAX_MULTI_COEF
)
2028 time_multi
= MAX_MULTI_COEF
;
2030 if (time_multi
< 24.1)
2032 else if (time_multi
< 60.2) {
2033 time_multi
= floor(time_multi
);
2035 } else if (time_multi
< 121.0) {
2036 time_multi
= floor(time_multi
);
2038 } else if (time_multi
< 241.0) {
2039 time_multi
= floor(time_multi
);
2041 } else if (time_multi
< 601.0) {
2042 time_multi
= floor(time_multi
);
2044 } else if (time_multi
< 1201.0) {
2045 time_multi
= floor(time_multi
);
2047 } else if (time_multi
< 2401.0) {
2048 time_multi
= floor(time_multi
);
2050 } else if (time_multi
< 6001.0) {
2051 time_multi
= floor(time_multi
);
2052 time_multi
-= 100.0;
2053 } else if (time_multi
< 12001.0) {
2054 time_multi
= floor(time_multi
);
2055 time_multi
-= 200.0;
2056 } else if (time_multi
< 24001.0) {
2057 time_multi
= floor(time_multi
);
2058 time_multi
-= 400.0;
2059 } else if (time_multi
< 60001.0) {
2060 time_multi
= floor(time_multi
);
2061 time_multi
-= 1000.0;
2062 } else if (time_multi
< 120001.0) {
2063 time_multi
= floor(time_multi
);
2064 time_multi
-= 2000.0;
2065 } else if (time_multi
< 240001.0) {
2066 time_multi
= floor(time_multi
);
2067 time_multi
-= 4000.0;
2069 time_multi
= floor(time_multi
);
2070 time_multi
-= 8000.0;
2073 if (time_multi
> 24.0)
2074 time_multi
= floor(time_multi
);
2075 if (time_multi
< 1.0)
2082 XCopyArea(dpy
, scrdiv
.pixmap
, wmg
.pixmap
, NormalGC
,
2083 0, 15, 60, 10, 2, 14);
2091 static void screen_5()
2093 int ok
, ckm
, waitrel
, sensadd
, not3
;
2097 fprintf(stdout
, "scr 5\n");
2104 XShapeCombineMask(dpy
, win
, ShapeBounding
, 0, 0, scrdate
.mask
,
2106 XShapeCombineMask(dpy
, iconwin
, ShapeBounding
, 0, 0, scrdate
.mask
,
2109 XCopyArea(dpy
, scrdate
.pixmap
, wmg
.pixmap
, NormalGC
, 0, 0, DIAMETRE
,
2112 AddMouseRegion(1, 2, 14, DIAMETRE
- 2, 25);
2113 AddMouseRegion(2, 2, 38, DIAMETRE
- 2, 49);
2119 while (XPending(dpy
)) {
2120 XNextEvent(dpy
, &Event
);
2121 switch (Event
.type
) {
2123 RedrawWindowXYWH(0, 0, DIAMETRE
, DIAMETRE
);
2130 ckm
= CheckMouseRegion(Event
.xbutton
.x
, Event
.xbutton
.y
);
2133 switch (Event
.xbutton
.button
) {
2154 ckm
= CheckMouseRegion(Event
.xbutton
.x
, Event
.xbutton
.y
);
2155 if (waitrel
== ckm
) {
2160 gotoscr
= NUM_SCREEN
;
2164 if (gotoscr
> NUM_SCREEN
)
2182 usleep(VAL_USLEEP_SHORT
);
2183 if (waitrel
&& not3
) {
2185 move_accel(sensadd
);
2191 use_nightmap
= FALSE
;
2195 use_nightmap
= TRUE
;
2202 if (waitrel
== 0 && diftimev(getimev(), tin
).tv_sec
> SCREEN_WAIT
2213 static void display_dlat()
2216 int i
, d
, m
, nega
, nego
;
2218 write_icon(" dlat :", 2, 2);
2219 RedrawWindowXYWH(2, 2, DIAMETRE
- 1, DIAMETRE
- 1);
2226 m
= (int) floor((dlat
- floor(dlat
)) * 60.0);
2227 d
= (int) floor(dlat
);
2230 sprintf(datest
, "-%d°%02d'", d
, m
);
2233 sprintf(datest
, "%d°%02d'", d
, m
);
2235 i
= 10 - strlen(datest
);
2240 write_icon(datest
, 2 + i
* 6, 14);
2241 RedrawWindowXYWH(2, 14, DIAMETRE
- 1, DIAMETRE
- 1);
2243 write_icon(" dlong :", 2, 26);
2244 RedrawWindowXYWH(2, 26, DIAMETRE
- 1, DIAMETRE
- 1);
2253 m
= (int) floor((dlong
- floor(dlong
)) * 60.0);
2254 d
= (int) floor(dlong
);
2257 sprintf(datest
, "-%d°%02d'", d
, m
);
2260 sprintf(datest
, "%d°%02d'", d
, m
);
2262 i
= 10 - strlen(datest
);
2267 write_icon(datest
, 2 + i
* 6, 38);
2268 RedrawWindowXYWH(2, 38, DIAMETRE
- 1, DIAMETRE
- 1);
2275 static void move_dlat(int factor
)
2277 dlat
+= factor
/ 4.0;
2278 if (dlat
> MAX_DELTA_LONG
)
2279 dlat
= MAX_DELTA_LONG
;
2280 if (dlat
< -MAX_DELTA_LONG
)
2281 dlat
= -MAX_DELTA_LONG
;
2282 if (dlat
< 0.25 && dlat
> -0.25)
2284 XCopyArea(dpy
, scrdiv
.pixmap
, wmg
.pixmap
, NormalGC
,
2285 0, 15, 60, 10, 2, 14);
2294 static void move_dlong(int factor
)
2296 dlong
+= factor
/ 4.0;
2297 if (dlong
> MAX_DELTA_LONG
)
2298 dlong
= MAX_DELTA_LONG
;
2299 if (dlong
< -MAX_DELTA_LONG
)
2300 dlong
= -MAX_DELTA_LONG
;
2301 if (dlong
< 0.25 && dlong
> -0.25)
2303 XCopyArea(dpy
, scrdiv
.pixmap
, wmg
.pixmap
, NormalGC
,
2304 0, 15, 60, 10, 2, 38);
2313 static void screen_6()
2315 int ok
, ckm
, waitrel
, sensadd
, not3
;
2319 fprintf(stdout
, "scr 6\n");
2326 XShapeCombineMask(dpy
, win
, ShapeBounding
, 0, 0, scrdate
.mask
,
2328 XShapeCombineMask(dpy
, iconwin
, ShapeBounding
, 0, 0, scrdate
.mask
,
2331 XCopyArea(dpy
, scrdate
.pixmap
, wmg
.pixmap
, NormalGC
, 0, 0, DIAMETRE
,
2333 AddMouseRegion(1, 2, 14, DIAMETRE
- 2, 25);
2334 AddMouseRegion(2, 2, 38, DIAMETRE
- 2, 49);
2341 while (XPending(dpy
)) {
2342 XNextEvent(dpy
, &Event
);
2343 switch (Event
.type
) {
2345 RedrawWindowXYWH(0, 0, DIAMETRE
, DIAMETRE
);
2352 ckm
= CheckMouseRegion(Event
.xbutton
.x
, Event
.xbutton
.y
);
2355 switch (Event
.xbutton
.button
) {
2376 ckm
= CheckMouseRegion(Event
.xbutton
.x
, Event
.xbutton
.y
);
2377 if (waitrel
== ckm
) {
2382 gotoscr
= NUM_SCREEN
;
2386 if (gotoscr
> NUM_SCREEN
)
2404 usleep(VAL_USLEEP_SHORT
);
2405 if (waitrel
&& not3
) {
2406 if (ckm
== 1 && p_type
!= PTRANDOM
) {
2410 if (ckm
== 2 && p_type
!= PTRANDOM
) {
2411 move_dlong(sensadd
);
2415 if (waitrel
== 0 && diftimev(getimev(), tin
).tv_sec
> SCREEN_WAIT
2426 static void display_type()
2428 char c
, cc
, mess
[12];
2430 write_icon(" view :", 2, 2);
2431 RedrawWindowXYWH(2, 2, DIAMETRE
- 1, DIAMETRE
- 1);
2433 if (p_type
== PTFIXED
) {
2440 sprintf(mess
, "%c move %c", c
, cc
);
2441 write_icon(mess
, 2, 14);
2442 RedrawWindowXYWH(2, 14, DIAMETRE
- 1, DIAMETRE
- 1);
2443 if (p_type
== PTSUN
) {
2450 sprintf(mess
, "%c sun %c", c
, cc
);
2451 write_icon(mess
, 2, 26);
2452 RedrawWindowXYWH(2, 26, DIAMETRE
- 1, DIAMETRE
- 1);
2454 if (p_type
== PTMOON
) {
2461 sprintf(mess
, "%c moon %c", c
, cc
);
2463 if (p_type
== PTRANDOM
) {
2470 sprintf(mess
, "%c random %c", c
, cc
);
2472 write_icon(mess
, 2, 38);
2473 RedrawWindowXYWH(2, 38, DIAMETRE
- 1, DIAMETRE
- 1);
2480 static void screen_7()
2482 int ok
, ckm
, waitrel
, sensadd
, not3
;
2486 fprintf(stdout
, "scr 7\n");
2494 XShapeCombineMask(dpy
, win
, ShapeBounding
, 0, 0, scrdate
.mask
,
2496 XShapeCombineMask(dpy
, iconwin
, ShapeBounding
, 0, 0, scrdate
.mask
,
2499 XCopyArea(dpy
, scrdate
.pixmap
, wmg
.pixmap
, NormalGC
, 0, 0, DIAMETRE
,
2501 AddMouseRegion(1, 2, 14, DIAMETRE
- 2, 25);
2502 AddMouseRegion(2, 2, 26, DIAMETRE
- 2, 37);
2503 AddMouseRegion(3, 2, 38, DIAMETRE
- 2, 49);
2510 while (XPending(dpy
)) {
2511 XNextEvent(dpy
, &Event
);
2512 switch (Event
.type
) {
2514 RedrawWindowXYWH(0, 0, DIAMETRE
, DIAMETRE
);
2521 ckm
= CheckMouseRegion(Event
.xbutton
.x
, Event
.xbutton
.y
);
2524 switch (Event
.xbutton
.button
) {
2527 if (ckm
< 4 && ckm
> 0)
2545 ckm
= CheckMouseRegion(Event
.xbutton
.x
, Event
.xbutton
.y
);
2546 if (waitrel
== ckm
) {
2551 gotoscr
= NUM_SCREEN
;
2555 if (gotoscr
> NUM_SCREEN
)
2572 usleep(VAL_USLEEP_SHORT
);
2573 if (waitrel
&& not3
&& sensadd
) {
2575 if (p_type
!= PTSUN
) {
2583 if (p_type
!= PTFIXED
) {
2590 if (p_type
!= PTMOON
) {
2593 if (p_type
!= PTRANDOM
) {
2603 if (waitrel
== 0 && diftimev(getimev(), tin
).tv_sec
> SCREEN_WAIT