wmglobe: Update to version 1.3.

From https://github.com/d-torrance/dockapps/pull/6
This commit is contained in:
Doug Torrance 2018-01-08 08:26:56 -05:00 committed by Carlos R. Mafra
parent 23019d9278
commit cb7b362149
17 changed files with 4948 additions and 4425 deletions

View file

@ -1,4 +1,27 @@
VMGlobe
1.3 released 12/08/01
- solve bug of custom map loading (now all maps are 3 layers RGB)
- default -bord is now 2
- accept a night map of different size than the day map
- new -defnimap option
- a few minor changes
1.2 released 9/04/2000
- WindowMaker 0.62 compliancy
1.1 not released
- another floating point exception bug solved (Alpha)
- little optimizations and rewriting in rend.c
- -sun option
- -moon option
- -mk marker option
1.0 released 30/05/99
- option -stable : latitude never change of sign
- change email to jerome.dumonteil@linuxfr.org
- modify a few typo in doc
0.5 released 6/02/99
- floating point exception bug solved
- many minor bugs solved (earth displaying, mouse, time management)
@ -22,14 +45,14 @@ VMGlobe
- shift+left button : change longitude & latitude
- man page
0.3.1 released 5/02/99
0.3.1 released 5/01/99
- option -austral
- solved bug about colors 24 and 32 bit per pixel
0.3 released 3/02/99
0.3 released 3/01/99
- right button : screen of digital modification of latitude/long.
0.2.1 released 3/02/99
0.2.1 released 3/01/99
- change & enhance mouse operations (longitude/latitude/zoom)
- minor bugs, CPU optimization

View file

@ -1,5 +1,5 @@
WMGlobe 0.5 - The Whole Earth spinning on you desktop... as a dockable app
Copyright (C) 1998,99 Jerome Dumonteil <jerome.dumonteil@capway.com>
WMGlobe 1.3 - The Whole Earth spinning on you desktop... as a dockable app
Copyright (C) 1998,99,2000,01 Jerome Dumonteil <jerome.dumonteil@linuxfr.org>
This program is licensed under the terms of the GNU GPL, see below.
@ -10,7 +10,6 @@ WMGlobe is a WindowMaker dock.app that displays the earth on an icon. It's
an adaptation of XGlobe to WMaker environnement. WMGlobe uses a map which is
rendered on a sphere by raytracing. Yes, for a 64x64 pixel result :-)
It's still a beta version...
@ -19,10 +18,10 @@ Installation
You need WindowMaker to build WMGlobe. WMGlobe needs libwraster to compile,
this lib is built by WindowMaker. No more need at run time if statically
linked, but then, you need WindowMaker to get the full magic :-)
Warning : this version won't work with WindowMaker < 0.62
tar -xvzf wmglobe-0.5.tar.gz
cd wmglobe-0.5
tar -xvzf wmglobe-1.3.tar.gz
cd wmglobe-1.3
make
then move wmglobe in /usr/local/bin and man page somewhere or do
@ -34,20 +33,23 @@ If it doesn't work, look for the graphic libraries.
The Makefile is quite crude...
WMGlobe is developped on Linux (WMaker 0.51.0 and linux 2.0.36/ix86).
WMGlobe is developped on Linux (WMaker 0.65.1 and linux 2.4.x/ix86).
If you are successful on other platforms, please tell me so.
platforms with successfull built reported :
platforms with successfull built reported (wmglobe 1.0 for older WMaker):
NetBSD 1.3.2 / SPARC (wmaker 0.20.3) , with Makefile adaptations for libs
Linux 2.0.36 / RedHat 5.1
Linux 2.0.36 / SuSE 5.3 (wmaker 0.20.3) , -lungif -> -lgif
Linux 2.0.36 / RedHat 5.2 (wmaker 0.53)
Linux 2.2.0-pre4 / Debian :-)
FreeBSD-3.0 with -ltiff -> -ltiff34 and -lungif -> -lgif
Solaris 2.6 / Sun Sparc (wmaker 0.20.3) , with Makefile adaptations for libs
AIX 4.2.1 / IBM RS/6000-250 (wmaker 0.50.2)
Linux 2.3.14 / Mandrake (wmaker but also blackbox !)
LinuxPPC 1999
Linux 2.2.10 / Alpha (wmglobe 1.1+)
RPM & DEBIAN linux packages coming soon. Or you can directly use the binary.
@ -62,10 +64,14 @@ and graphics libs, or install a rpm version of wmglobe.
libwraster :
WindowMaker 0.20.3 uses a libwraster.a , so if you use it, you can execute
the binary on a computer without WindowMaker on it, and displaying on a
remote computer (this one using WindowMaker). WM 0.51.0 creates a dynamic
remote computer (this one using WindowMaker). WM > 0.51.0 creates a dynamic
libwraster.so, so it's necessary to have it on the computer running wmglobe
if you buit WMGlobe with this one. Both versions of WMGlobe run on WM 0.20.3
and 0.51.0
For wmglobe 1.2+, you need WMaker 0.62 or more recent. And wmglobe 1.0 won't
run on these recent versions of WindowMaker. You need to have wraster.h
in the include path to compile wmglobe.
For wmglobe 1.3+, you probably need WMaker 0.64 or more recent.
graphic libs :
you can use libgif or libungif. If your version of WindowMaker is built
@ -81,12 +87,14 @@ make: *** [wmglobe] Error 1
compile time options :
You can modify the file wmgoption.h where many options are set up in defines :
To disable the builtin default map, just comment out the line in wmgoptions.h :
To disable the builtin default map, just comment out the line in wmgoptions.h
#define DEFMAPOK
to supprim the shift+left/left method of rotate earth, uncomment the lines
to remove the shift+left/left method of rotate earth, uncomment the lines
#define MOUSE_LAT_FULL
you can also suppress some options screen in wmgoption.h
you can also suppress some options screen in wmgoption.h (or even suppress
new features of wmglobe 1.2)
@ -101,8 +109,7 @@ You can get maps usable with WMGlobe on the net. See the LINKS chapter.
using custom maps :
- For the image to be mapped correctly, position 0°North 0°West must be in
the center of the image and the latitude must be linear from 90°N to 90°S.
- When using a night map, make sure that day and night map have the same
dimensions.
- You can safely use a night map of different size than the day map.
By the way, you can use maps of Mars, Luna ... and text.
@ -123,11 +130,16 @@ Configuration is done through command line options.
the sun rotation. Accepted values in the form
45°12'36 or 45.21 or 45:12:36
Default : the initial position is "under" the sun, and
the point of view follows the sun
the point of view follows the sun.
-sun The point of view follows the Sun (default).
-moon The point of view follows the Moon (i.e. you see the
Earth as you were on the Moon).
-rand New random position at every refresh of screen
-map map_file Map used for the rendering. Can be JPEG, GIG, XPM
-map map_file Map used for the rendering. Can be JPEG, GIF, XPM
PNM, TIFF but none BMP
Default : use internal map of earth.
@ -135,8 +147,8 @@ Configuration is done through command line options.
the same width x height as the day side map.
Default : if the default internal day map is used, use
a default internal night file (see -nonimap option).
If a custom day map is provided, and no night map, the
dark side is computed via the -light option.
-defnimap Use the default night map (with a custom map).
-nonimap Don't use the default night map.
@ -183,11 +195,19 @@ Configuration is done through command line options.
Negative values for dates before 1970 accepted.
Default : not set, use current time.
-mk latitude long. Put a fixed marker at latitude/longitude.
-mk sun : put a marker under the Sun position.
-mk moon : put a marker under the Moon.
5 markers can be defined simultaneously, so you can
use wmglobe to predict when Moon will meet the Sun :-)
-fun dx dy Move the earth image by dx dy pixels in the icon. See
puzzle.sh to understand why.
-oz Start in "austral" mode (for "down under" people)
-stable Keep the globe from going over the poles.
-d display Select another display
-w -shape Useless, since it is set by default (WMaker dockable
@ -223,10 +243,10 @@ http://www.bensinclair.com/dockapp/
Links : Where to find maps and similar softs
--------------------------------------------
where to find the sources of wmglobe :
http://www.capway.com/dumonte1/wm/wmglobe-0.5.tar.gz
http://perso.linuxfr.org/jdumont/wmg/wmglobe-1.0.tar.gz
the web page of WMGlobe (made by Sylvestre Taburet) :
http://www.capway.com/dumonte1/wm/wmg.html
http://perso.linuxfr.org/jdumont/wmg/
where to find maps and similar softs :
@ -272,9 +292,11 @@ interesting. It also has a rather high resolution.
Todo
----------------------------------------
- add interface module to allow plugins
- test on different platforms, better makefile
- changing map "on the fly", map generator, clouds generator...
- must work on every current WindowMaker platform
- must work on every current WindowMaker platform (hug...)
- rewrite some ugly things in the code
- see how to minimize CPU load
- feature : load a local detailed map of some part of the globe when zooming
(country maps, city maps)
@ -284,6 +306,7 @@ Todo
Bugs
----------------------------------------
- Wmglobe depends on WindowMaker version
- The Makefile
- if you use the --enable-single-icon compile time option of WindowMaker,
you can not display more than one WMGlobe.
@ -291,22 +314,25 @@ Bugs
and that LONG_MAX +1 = LONG_MIN . This happens with high values of -accel
when the date go over year 2038. The expected result is wmglobe
continuing smoothly from 1901.
- Using WMGlobe at high speed through a LAN may induce some load on the net.
License
----------------------------------------
WMGlobe is Copyright (C) 1998,99 by Jerome Dumonteil and licensed through
the GNU General Public License.
WMGlobe is Copyright (C) 1998,99,2000,2001 by Jerome Dumonteil and licensed
through the GNU General Public License.
Read the COPYING file for the complete GNU license.
Credits
----------------------------------------
Original idea, tests, logos : Sylvestre Taburet <staburet@consort.fr>
Original idea, tests, logos : Sylvestre Taburet <Sylvestre.Taburet@free.fr>
WindowMaker 0.62 fix : Charles G Waldman <cgw@fnal.gov>
The code in 'sunpos.cpp' is taken from Xearth by Kirk Lauritz Johnson.
(Actually, it uses now the 1.1 version of Xearth)
/*
* sunpos.c
@ -343,7 +369,7 @@ Raster graphics library by Alfredo K. Kojima, & stuff of Window Maker
Feedback
----------------------------------------
For your questions, bugs, remarks, please contact our representative on
planet Earth : jerome dumonteil <jerome.dumonteil@capway.com>
planet Earth : jerome dumonteil <jerome.dumonteil@linuxfr.org>

View file

@ -8,10 +8,10 @@ else
WMG="nice wmglobe"
fi
HOP=" -delay 0.1 -pos -25 10 -dlat 0.5 -dlong -5 -zoom 1.8 -accel 240"
HOP=" -bord 0 -delay 0.1 -pos -25 10 -dlat 0.5 -dlong -5 -zoom 1.8 -accel 240 -stable"
$WMG $HOP -fun 32 32 &
$WMG $HOP -fun -32 32 &
$WMG $HOP -fun 32 -32 &
$WMG $HOP -fun -32 -32 &
$WMG -map ./wmgmap.gif -delay 0.05 -dlong 25 -pos 0 0 -accel 10000&
[ -f wmgmap.jpeg ] && $WMG -nimap ./wmgmap.jpeg -delay 0.05 -dlat 2 -dlong -20 -pos 0 -20 -accel 21600 -zoom 0.85 -dawn 0 -stable &

View file

@ -1,4 +1,4 @@
/* WMGlobe 0.5 - All the Earth on a WMaker Icon
/* WMGlobe 1.3 - All the Earth on a WMaker Icon
* mycontext.c - an adaptation of wrlib for use in wmglobe
* initial source taken in WindowMaker-0.20.3/wrlib :
*/
@ -42,515 +42,530 @@
* #include "wraster.h"
*/
static Bool bestContext(Display * dpy, int screen_number, RContext * context);
static Bool bestContext(Display * dpy, int screen_number,
RContext * context);
static RContextAttributes DEFAULT_CONTEXT_ATTRIBS =
{
RC_DefaultVisual, /* flags */
0, /* render_mode */
0, /* colors_per_channel */
0,
0,
0,
0,
0 /* NO use_shared_memory */
static RContextAttributes DEFAULT_CONTEXT_ATTRIBS = {
RC_DefaultVisual, /* flags */
0, /* render_mode */
3, /* colors_per_channel */
0,
0,
0,
0,
0 /* NO use_shared_memory */
};
static XColor *
allocatePseudoColor(RContext * ctx)
static XColor *allocatePseudoColor(RContext * ctx)
{
XColor *colors;
XColor avcolors[256];
int avncolors;
int i, ncolors, r, g, b;
int retries;
int cpc = ctx->attribs->colors_per_channel;
XColor *colors;
XColor avcolors[256];
int avncolors;
int i, ncolors, r, g, b;
int retries;
int cpc = ctx->attribs->colors_per_channel;
ncolors = cpc * cpc * cpc;
if (ncolors > (1 << ctx->depth)) {
/* reduce colormap size */
cpc = ctx->attribs->colors_per_channel =
1 << ((int) ctx->depth / 3);
ncolors = cpc * cpc * cpc;
}
assert(cpc >= 2 && ncolors <= (1 << ctx->depth));
colors = malloc(sizeof(XColor) * ncolors);
if (!colors) {
RErrorCode = RERR_NOMEMORY;
return NULL;
}
i = 0;
if ((ctx->attribs->flags & RC_GammaCorrection)
&& ctx->attribs->rgamma > 0 && ctx->attribs->ggamma > 0
&& ctx->attribs->bgamma > 0) {
double rg, gg, bg;
double tmp;
/* do gamma correction */
rg = 1.0 / ctx->attribs->rgamma;
gg = 1.0 / ctx->attribs->ggamma;
bg = 1.0 / ctx->attribs->bgamma;
for (r = 0; r < cpc; r++) {
for (g = 0; g < cpc; g++) {
for (b = 0; b < cpc; b++) {
colors[i].red = (r * 0xffff) / (cpc - 1);
colors[i].green = (g * 0xffff) / (cpc - 1);
colors[i].blue = (b * 0xffff) / (cpc - 1);
colors[i].flags = DoRed | DoGreen | DoBlue;
tmp = (double) colors[i].red / 65536.0;
colors[i].red =
(unsigned short) (65536.0 * pow(tmp, rg));
tmp = (double) colors[i].green / 65536.0;
colors[i].green =
(unsigned short) (65536.0 * pow(tmp, gg));
tmp = (double) colors[i].blue / 65536.0;
colors[i].blue =
(unsigned short) (65536.0 * pow(tmp, bg));
i++;
}
}
}
} else {
for (r = 0; r < cpc; r++) {
for (g = 0; g < cpc; g++) {
for (b = 0; b < cpc; b++) {
colors[i].red = (r * 0xffff) / (cpc - 1);
colors[i].green = (g * 0xffff) / (cpc - 1);
colors[i].blue = (b * 0xffff) / (cpc - 1);
colors[i].flags = DoRed | DoGreen | DoBlue;
i++;
}
}
}
}
/* try to allocate the colors */
for (i = 0; i < ncolors; i++) {
if (!XAllocColor(ctx->dpy, ctx->cmap, &(colors[i]))) {
colors[i].flags = 0; /* failed */
} else {
colors[i].flags = DoRed | DoGreen | DoBlue;
}
}
/* try to allocate close values for the colors that couldn't
* be allocated before */
avncolors = (1 << ctx->depth > 256 ? 256 : 1 << ctx->depth);
for (i = 0; i < avncolors; i++)
avcolors[i].pixel = i;
XQueryColors(ctx->dpy, ctx->cmap, avcolors, avncolors);
for (i = 0; i < ncolors; i++) {
if (colors[i].flags == 0) {
int j;
unsigned long cdiff = 0xffffffff, diff;
unsigned long closest = 0;
retries = 2;
while (retries--) {
/* find closest color */
for (j = 0; j < avncolors; j++) {
r = (colors[i].red - avcolors[i].red) >> 8;
g = (colors[i].green - avcolors[i].green) >> 8;
b = (colors[i].blue - avcolors[i].blue) >> 8;
diff = r * r + g * g + b * b;
if (diff < cdiff) {
cdiff = diff;
closest = j;
}
}
/* allocate closest color found */
colors[i].red = avcolors[closest].red;
colors[i].green = avcolors[closest].green;
colors[i].blue = avcolors[closest].blue;
if (XAllocColor(ctx->dpy, ctx->cmap, &colors[i])) {
colors[i].flags = DoRed | DoGreen | DoBlue;
break; /* succeeded, don't need to retry */
}
#ifdef DEBUG
printf("close color allocation failed. Retrying...\n");
#endif
}
}
}
return colors;
}
static XColor *allocateGrayScale(RContext * ctx)
{
XColor *colors;
XColor avcolors[256];
int avncolors;
int i, ncolors, r, g, b;
int retries;
int cpc = ctx->attribs->colors_per_channel;
ncolors = cpc * cpc * cpc;
if (ctx->vclass == StaticGray) {
/* we might as well use all grays */
ncolors = 1 << ctx->depth;
} else {
if (ncolors > (1 << ctx->depth)) {
/* reduce colormap size */
cpc = ctx->attribs->colors_per_channel = 1 << ((int) ctx->depth / 3);
ncolors = cpc * cpc * cpc;
/* reduce colormap size */
cpc = ctx->attribs->colors_per_channel =
1 << ((int) ctx->depth / 3);
ncolors = cpc * cpc * cpc;
}
assert(cpc >= 2 && ncolors <= (1 << ctx->depth));
}
colors = malloc(sizeof(XColor) * ncolors);
if (!colors) {
RErrorCode = RERR_NOMEMORY;
return NULL;
}
i = 0;
if ((ctx->attribs->flags & RC_GammaCorrection) && ctx->attribs->rgamma > 0
&& ctx->attribs->ggamma > 0 && ctx->attribs->bgamma > 0) {
double rg, gg, bg;
double tmp;
/* do gamma correction */
rg = 1.0 / ctx->attribs->rgamma;
gg = 1.0 / ctx->attribs->ggamma;
bg = 1.0 / ctx->attribs->bgamma;
for (r = 0; r < cpc; r++) {
for (g = 0; g < cpc; g++) {
for (b = 0; b < cpc; b++) {
colors[i].red = (r * 0xffff) / (cpc - 1);
colors[i].green = (g * 0xffff) / (cpc - 1);
colors[i].blue = (b * 0xffff) / (cpc - 1);
colors[i].flags = DoRed | DoGreen | DoBlue;
tmp = (double) colors[i].red / 65536.0;
colors[i].red = (unsigned short) (65536.0 * pow(tmp, rg));
tmp = (double) colors[i].green / 65536.0;
colors[i].green = (unsigned short) (65536.0 * pow(tmp, gg));
tmp = (double) colors[i].blue / 65536.0;
colors[i].blue = (unsigned short) (65536.0 * pow(tmp, bg));
i++;
}
}
}
} else {
for (r = 0; r < cpc; r++) {
for (g = 0; g < cpc; g++) {
for (b = 0; b < cpc; b++) {
colors[i].red = (r * 0xffff) / (cpc - 1);
colors[i].green = (g * 0xffff) / (cpc - 1);
colors[i].blue = (b * 0xffff) / (cpc - 1);
colors[i].flags = DoRed | DoGreen | DoBlue;
i++;
}
}
}
}
/* try to allocate the colors */
for (i = 0; i < ncolors; i++) {
if (!XAllocColor(ctx->dpy, ctx->cmap, &(colors[i]))) {
colors[i].flags = 0; /* failed */
} else {
colors[i].flags = DoRed | DoGreen | DoBlue;
}
}
/* try to allocate close values for the colors that couldn't
* be allocated before */
avncolors = (1 << ctx->depth > 256 ? 256 : 1 << ctx->depth);
for (i = 0; i < avncolors; i++)
avcolors[i].pixel = i;
XQueryColors(ctx->dpy, ctx->cmap, avcolors, avncolors);
for (i = 0; i < ncolors; i++) {
if (colors[i].flags == 0) {
int j;
unsigned long cdiff = 0xffffffff, diff;
unsigned long closest = 0;
retries = 2;
while (retries--) {
/* find closest color */
for (j = 0; j < avncolors; j++) {
r = (colors[i].red - avcolors[i].red) >> 8;
g = (colors[i].green - avcolors[i].green) >> 8;
b = (colors[i].blue - avcolors[i].blue) >> 8;
diff = r * r + g * g + b * b;
if (diff < cdiff) {
cdiff = diff;
closest = j;
}
}
/* allocate closest color found */
colors[i].red = avcolors[closest].red;
colors[i].green = avcolors[closest].green;
colors[i].blue = avcolors[closest].blue;
if (XAllocColor(ctx->dpy, ctx->cmap, &colors[i])) {
colors[i].flags = DoRed | DoGreen | DoBlue;
break; /* succeeded, don't need to retry */
}
if (ncolors >= 256 && ctx->vclass == StaticGray) {
/* don't need dithering for 256 levels of gray in StaticGray visual */
ctx->attribs->render_mode = RBestMatchRendering;
}
colors = malloc(sizeof(XColor) * ncolors);
if (!colors) {
RErrorCode = RERR_NOMEMORY;
return False;
}
for (i = 0; i < ncolors; i++) {
colors[i].red = (i * 0xffff) / (ncolors - 1);
colors[i].green = (i * 0xffff) / (ncolors - 1);
colors[i].blue = (i * 0xffff) / (ncolors - 1);
colors[i].flags = DoRed | DoGreen | DoBlue;
}
/* try to allocate the colors */
for (i = 0; i < ncolors; i++) {
#ifdef DEBUG
printf("close color allocation failed. Retrying...\n");
printf("trying:%x,%x,%x\n", colors[i].red, colors[i].green,
colors[i].blue);
#endif
if (!XAllocColor(ctx->dpy, ctx->cmap, &(colors[i]))) {
colors[i].flags = 0; /* failed */
#ifdef DEBUG
printf("failed:%x,%x,%x\n", colors[i].red, colors[i].green,
colors[i].blue);
#endif
} else {
colors[i].flags = DoRed | DoGreen | DoBlue;
#ifdef DEBUG
printf("success:%x,%x,%x\n", colors[i].red, colors[i].green,
colors[i].blue);
#endif
}
}
}
return colors;
}
/* try to allocate close values for the colors that couldn't
* be allocated before */
avncolors = (1 << ctx->depth > 256 ? 256 : 1 << ctx->depth);
for (i = 0; i < avncolors; i++)
avcolors[i].pixel = i;
XQueryColors(ctx->dpy, ctx->cmap, avcolors, avncolors);
for (i = 0; i < ncolors; i++) {
if (colors[i].flags == 0) {
int j;
unsigned long cdiff = 0xffffffff, diff;
unsigned long closest = 0;
retries = 2;
while (retries--) {
/* find closest color */
for (j = 0; j < avncolors; j++) {
r = (colors[i].red - avcolors[i].red) >> 8;
g = (colors[i].green - avcolors[i].green) >> 8;
b = (colors[i].blue - avcolors[i].blue) >> 8;
diff = r * r + g * g + b * b;
if (diff < cdiff) {
cdiff = diff;
closest = j;
}
}
/* allocate closest color found */
#ifdef DEBUG
printf("best match:%x,%x,%x => %x,%x,%x\n", colors[i].red,
colors[i].green, colors[i].blue,
avcolors[closest].red, avcolors[closest].green,
avcolors[closest].blue);
#endif
colors[i].red = avcolors[closest].red;
colors[i].green = avcolors[closest].green;
colors[i].blue = avcolors[closest].blue;
if (XAllocColor(ctx->dpy, ctx->cmap, &colors[i])) {
colors[i].flags = DoRed | DoGreen | DoBlue;
break; /* succeeded, don't need to retry */
}
#ifdef DEBUG
printf("close color allocation failed. Retrying...\n");
#endif
}
}
}
return colors;
}
static XColor *
allocateGrayScale(RContext * ctx)
static char *mygetenv(char *var, int scr)
{
XColor *colors;
XColor avcolors[256];
int avncolors;
int i, ncolors, r, g, b;
int retries;
int cpc = ctx->attribs->colors_per_channel;
char *p;
char varname[64];
ncolors = cpc * cpc * cpc;
if (ctx->vclass == StaticGray) {
/* we might as well use all grays */
ncolors = 1 << ctx->depth;
} else {
if (ncolors > (1 << ctx->depth)) {
/* reduce colormap size */
cpc = ctx->attribs->colors_per_channel = 1 << ((int) ctx->depth / 3);
ncolors = cpc * cpc * cpc;
}
assert(cpc >= 2 && ncolors <= (1 << ctx->depth));
}
if (ncolors >= 256 && ctx->vclass == StaticGray) {
/* don't need dithering for 256 levels of gray in StaticGray visual */
ctx->attribs->render_mode = RM_MATCH;
}
colors = malloc(sizeof(XColor) * ncolors);
if (!colors) {
RErrorCode = RERR_NOMEMORY;
return False;
}
for (i = 0; i < ncolors; i++) {
colors[i].red = (i * 0xffff) / (ncolors - 1);
colors[i].green = (i * 0xffff) / (ncolors - 1);
colors[i].blue = (i * 0xffff) / (ncolors - 1);
colors[i].flags = DoRed | DoGreen | DoBlue;
}
/* try to allocate the colors */
for (i = 0; i < ncolors; i++) {
#ifdef DEBUG
printf("trying:%x,%x,%x\n", colors[i].red, colors[i].green, colors[i].blue);
#endif
if (!XAllocColor(ctx->dpy, ctx->cmap, &(colors[i]))) {
colors[i].flags = 0; /* failed */
#ifdef DEBUG
printf("failed:%x,%x,%x\n", colors[i].red, colors[i].green, colors[i].blue);
#endif
} else {
colors[i].flags = DoRed | DoGreen | DoBlue;
#ifdef DEBUG
printf("success:%x,%x,%x\n", colors[i].red, colors[i].green, colors[i].blue);
#endif
}
}
/* try to allocate close values for the colors that couldn't
* be allocated before */
avncolors = (1 << ctx->depth > 256 ? 256 : 1 << ctx->depth);
for (i = 0; i < avncolors; i++)
avcolors[i].pixel = i;
XQueryColors(ctx->dpy, ctx->cmap, avcolors, avncolors);
for (i = 0; i < ncolors; i++) {
if (colors[i].flags == 0) {
int j;
unsigned long cdiff = 0xffffffff, diff;
unsigned long closest = 0;
retries = 2;
while (retries--) {
/* find closest color */
for (j = 0; j < avncolors; j++) {
r = (colors[i].red - avcolors[i].red) >> 8;
g = (colors[i].green - avcolors[i].green) >> 8;
b = (colors[i].blue - avcolors[i].blue) >> 8;
diff = r * r + g * g + b * b;
if (diff < cdiff) {
cdiff = diff;
closest = j;
}
}
/* allocate closest color found */
#ifdef DEBUG
printf("best match:%x,%x,%x => %x,%x,%x\n", colors[i].red, colors[i].green, colors[i].blue, avcolors[closest].red, avcolors[closest].green, avcolors[closest].blue);
#endif
colors[i].red = avcolors[closest].red;
colors[i].green = avcolors[closest].green;
colors[i].blue = avcolors[closest].blue;
if (XAllocColor(ctx->dpy, ctx->cmap, &colors[i])) {
colors[i].flags = DoRed | DoGreen | DoBlue;
break; /* succeeded, don't need to retry */
}
#ifdef DEBUG
printf("close color allocation failed. Retrying...\n");
#endif
}
}
}
return colors;
}
static char *
mygetenv(char *var, int scr)
{
char *p;
char varname[64];
sprintf(varname, "%s%i", var, scr);
p = getenv(varname);
if (!p) {
p = getenv(var);
}
return p;
sprintf(varname, "%s%i", var, scr);
p = getenv(varname);
if (!p) {
p = getenv(var);
}
return p;
}
static void gatherconfig(RContext * context, int screen_n)
{
char *ptr;
char *ptr;
ptr = mygetenv("WRASTER_GAMMA", screen_n);
if (ptr) {
float g1, g2, g3;
if (sscanf(ptr, "%f/%f/%f", &g1, &g2, &g3) != 3
|| g1 <= 0.0 || g2 <= 0.0 || g3 <= 0.0) {
printf("wrlib: invalid value(s) for gamma correction \"%s\"\n",
ptr);
} else {
context->attribs->flags |= RC_GammaCorrection;
context->attribs->rgamma = g1;
context->attribs->ggamma = g2;
context->attribs->bgamma = g3;
}
ptr = mygetenv("WRASTER_GAMMA", screen_n);
if (ptr) {
float g1, g2, g3;
if (sscanf(ptr, "%f/%f/%f", &g1, &g2, &g3) != 3
|| g1 <= 0.0 || g2 <= 0.0 || g3 <= 0.0) {
printf("wrlib: invalid value(s) for gamma correction \"%s\"\n",
ptr);
} else {
context->attribs->flags |= RC_GammaCorrection;
context->attribs->rgamma = g1;
context->attribs->ggamma = g2;
context->attribs->bgamma = g3;
}
ptr = mygetenv("WRASTER_COLOR_RESOLUTION", screen_n);
if (ptr) {
int i;
if (sscanf(ptr, "%d", &i) != 1 || i < 2 || i > 6) {
printf("wrlib: invalid value for color resolution \"%s\"\n", ptr);
} else {
context->attribs->flags |= RC_ColorsPerChannel;
context->attribs->colors_per_channel = i;
}
}
ptr = mygetenv("WRASTER_COLOR_RESOLUTION", screen_n);
if (ptr) {
int i;
if (sscanf(ptr, "%d", &i) != 1 || i < 2 || i > 6) {
printf("wrlib: invalid value for color resolution \"%s\"\n",
ptr);
} else {
context->attribs->flags |= RC_ColorsPerChannel;
context->attribs->colors_per_channel = i;
}
}
}
static void getColormap(RContext * context, int screen_number)
{
Colormap cmap = None;
XStandardColormap *cmaps;
int ncmaps, i;
Colormap cmap = None;
XStandardColormap *cmaps;
int ncmaps, i;
if (XGetRGBColormaps(context->dpy,
RootWindow(context->dpy, screen_number),
&cmaps, &ncmaps, XA_RGB_DEFAULT_MAP)) {
for (i = 0; i < ncmaps; ++i) {
if (cmaps[i].visualid == context->visual->visualid) {
puts("ACHOU");
cmap = cmaps[i].colormap;
break;
}
}
XFree(cmaps);
if (XGetRGBColormaps(context->dpy,
RootWindow(context->dpy, screen_number),
&cmaps, &ncmaps, XA_RGB_DEFAULT_MAP)) {
for (i = 0; i < ncmaps; ++i) {
if (cmaps[i].visualid == context->visual->visualid) {
puts("ACHOU");
cmap = cmaps[i].colormap;
break;
}
}
if (cmap == None) {
XColor color;
XFree(cmaps);
}
if (cmap == None) {
XColor color;
cmap = XCreateColormap(context->dpy,
RootWindow(context->dpy, screen_number),
context->visual, AllocNone);
cmap = XCreateColormap(context->dpy,
RootWindow(context->dpy, screen_number),
context->visual, AllocNone);
color.red = color.green = color.blue = 0;
XAllocColor(context->dpy, cmap, &color);
context->black = color.pixel;
color.red = color.green = color.blue = 0;
XAllocColor(context->dpy, cmap, &color);
context->black = color.pixel;
color.red = color.green = color.blue = 0xffff;
XAllocColor(context->dpy, cmap, &color);
context->white = color.pixel;
color.red = color.green = color.blue = 0xffff;
XAllocColor(context->dpy, cmap, &color);
context->white = color.pixel;
}
context->cmap = cmap;
}
context->cmap = cmap;
}
static int count_offset(unsigned long mask)
{
int i;
int i;
i = 0;
while ((mask & 1) == 0) {
i++;
mask = mask >> 1;
}
return i;
i = 0;
while ((mask & 1) == 0) {
i++;
mask = mask >> 1;
}
return i;
}
RContext *
myRCreateContext(Display * dpy, int screen_number, RContextAttributes * attribs)
RContext *myRCreateContext(Display * dpy, int screen_number,
RContextAttributes * attribs)
{
RContext *context;
XGCValues gcv;
RContext *context;
XGCValues gcv;
context = malloc(sizeof(RContext));
if (!context) {
RErrorCode = RERR_NOMEMORY;
return NULL;
context = malloc(sizeof(RContext));
if (!context) {
RErrorCode = RERR_NOMEMORY;
return NULL;
}
memset(context, 0, sizeof(RContext));
context->dpy = dpy;
context->screen_number = screen_number;
context->attribs = malloc(sizeof(RContextAttributes));
if (!context->attribs) {
free(context);
RErrorCode = RERR_NOMEMORY;
return NULL;
}
if (!attribs)
*context->attribs = DEFAULT_CONTEXT_ATTRIBS;
else
*context->attribs = *attribs;
/* get configuration from environment variables */
gatherconfig(context, screen_number);
if ((context->attribs->flags & RC_VisualID)) {
XVisualInfo *vinfo, templ;
int nret;
templ.screen = screen_number;
templ.visualid = context->attribs->visualid;
vinfo =
XGetVisualInfo(context->dpy, VisualIDMask | VisualScreenMask,
&templ, &nret);
if (!vinfo || nret == 0) {
free(context);
RErrorCode = RERR_BADVISUALID;
return NULL;
}
memset(context, 0, sizeof(RContext));
if (vinfo[0].visual == DefaultVisual(dpy, screen_number)) {
context->attribs->flags |= RC_DefaultVisual;
} else {
XSetWindowAttributes attr;
unsigned long mask;
context->dpy = dpy;
context->screen_number = screen_number;
context->attribs = malloc(sizeof(RContextAttributes));
if (!context->attribs) {
free(context);
RErrorCode = RERR_NOMEMORY;
return NULL;
context->visual = vinfo[0].visual;
context->depth = vinfo[0].depth;
context->vclass = vinfo[0].class;
getColormap(context, screen_number);
attr.colormap = context->cmap;
attr.override_redirect = True;
attr.border_pixel = 0;
attr.background_pixel = 0;
mask =
CWBorderPixel | CWColormap | CWOverrideRedirect |
CWBackPixel;
context->drawable =
XCreateWindow(dpy, RootWindow(dpy, screen_number), 1, 1, 1,
1, 0, context->depth, CopyFromParent,
context->visual, mask, &attr);
/* XSetWindowColormap(dpy, context->drawable, attr.colormap); */
}
if (!attribs)
*context->attribs = DEFAULT_CONTEXT_ATTRIBS;
else
*context->attribs = *attribs;
/* get configuration from environment variables */
gatherconfig(context, screen_number);
if ((context->attribs->flags & RC_VisualID)) {
XVisualInfo *vinfo, templ;
int nret;
templ.screen = screen_number;
templ.visualid = context->attribs->visualid;
vinfo = XGetVisualInfo(context->dpy, VisualIDMask | VisualScreenMask,
&templ, &nret);
if (!vinfo || nret == 0) {
free(context);
RErrorCode = RERR_BADVISUALID;
return NULL;
}
if (vinfo[0].visual == DefaultVisual(dpy, screen_number)) {
context->attribs->flags |= RC_DefaultVisual;
} else {
XSetWindowAttributes attr;
unsigned long mask;
context->visual = vinfo[0].visual;
context->depth = vinfo[0].depth;
context->vclass = vinfo[0].class;
getColormap(context, screen_number);
attr.colormap = context->cmap;
attr.override_redirect = True;
attr.border_pixel = 0;
attr.background_pixel = 0;
mask = CWBorderPixel | CWColormap | CWOverrideRedirect | CWBackPixel;
context->drawable =
XCreateWindow(dpy, RootWindow(dpy, screen_number), 1, 1,
1, 1, 0, context->depth, CopyFromParent,
context->visual, mask, &attr);
/* XSetWindowColormap(dpy, context->drawable, attr.colormap); */
}
XFree(vinfo);
XFree(vinfo);
}
/* use default */
if (!context->visual) {
if ((context->attribs->flags & RC_DefaultVisual)
|| !bestContext(dpy, screen_number, context)) {
context->visual = DefaultVisual(dpy, screen_number);
context->depth = DefaultDepth(dpy, screen_number);
context->cmap = DefaultColormap(dpy, screen_number);
context->drawable = RootWindow(dpy, screen_number);
context->black = BlackPixel(dpy, screen_number);
context->white = WhitePixel(dpy, screen_number);
context->vclass = context->visual->class;
}
/* use default */
if (!context->visual) {
if ((context->attribs->flags & RC_DefaultVisual)
|| !bestContext(dpy, screen_number, context)) {
context->visual = DefaultVisual(dpy, screen_number);
context->depth = DefaultDepth(dpy, screen_number);
context->cmap = DefaultColormap(dpy, screen_number);
context->drawable = RootWindow(dpy, screen_number);
context->black = BlackPixel(dpy, screen_number);
context->white = WhitePixel(dpy, screen_number);
context->vclass = context->visual->class;
}
}
gcv.function = GXcopy;
gcv.graphics_exposures = False;
context->copy_gc = XCreateGC(dpy, context->drawable, GCFunction
| GCGraphicsExposures, &gcv);
}
gcv.function = GXcopy;
gcv.graphics_exposures = False;
context->copy_gc = XCreateGC(dpy, context->drawable, GCFunction
| GCGraphicsExposures, &gcv);
if (context->vclass == PseudoColor || context->vclass == StaticColor) {
context->colors = allocatePseudoColor(context);
if (!context->colors) {
return NULL;
}
} else if (context->vclass == GrayScale || context->vclass == StaticGray) {
context->colors = allocateGrayScale(context);
if (!context->colors) {
return NULL;
}
} else if (context->vclass == TrueColor) {
/* calc offsets to create a TrueColor pixel */
context->red_offset = count_offset(context->visual->red_mask);
context->green_offset = count_offset(context->visual->green_mask);
context->blue_offset = count_offset(context->visual->blue_mask);
/* disable dithering on 24 bits visuals */
if (context->depth >= 24)
context->attribs->render_mode = RM_MATCH;
if (context->vclass == PseudoColor || context->vclass == StaticColor) {
context->colors = allocatePseudoColor(context);
if (!context->colors) {
return NULL;
}
/* check avaiability of MIT-SHM */
} else if (context->vclass == GrayScale
|| context->vclass == StaticGray) {
context->colors = allocateGrayScale(context);
if (!context->colors) {
return NULL;
}
} else if (context->vclass == TrueColor) {
/* calc offsets to create a TrueColor pixel */
context->red_offset = count_offset(context->visual->red_mask);
context->green_offset = count_offset(context->visual->green_mask);
context->blue_offset = count_offset(context->visual->blue_mask);
/* disable dithering on 24 bits visuals */
if (context->depth >= 24)
context->attribs->render_mode = RBestMatchRendering;
}
/* check avaiability of MIT-SHM */
return context;
return context;
}
static Bool
bestContext(Display * dpy, int screen_number, RContext * context)
bestContext(Display * dpy, int screen_number, RContext * context)
{
XVisualInfo *vinfo = NULL, rvinfo;
int best = -1, numvis, i;
long flags;
XSetWindowAttributes attr;
XVisualInfo *vinfo = NULL, rvinfo;
int best = -1, numvis, i;
long flags;
XSetWindowAttributes attr;
rvinfo.class = TrueColor;
rvinfo.screen = screen_number;
flags = VisualClassMask | VisualScreenMask;
rvinfo.class = TrueColor;
rvinfo.screen = screen_number;
flags = VisualClassMask | VisualScreenMask;
vinfo = XGetVisualInfo(dpy, flags, &rvinfo, &numvis);
if (vinfo) { /* look for a TrueColor, 24-bit or more (pref 24) */
for (i = numvis - 1, best = -1; i >= 0; i--) {
if (vinfo[i].depth == 24)
best = i;
else if (vinfo[i].depth > 24 && best < 0)
best = i;
}
vinfo = XGetVisualInfo(dpy, flags, &rvinfo, &numvis);
if (vinfo) { /* look for a TrueColor, 24-bit or more (pref 24) */
for (i = numvis - 1, best = -1; i >= 0; i--) {
if (vinfo[i].depth == 24)
best = i;
else if (vinfo[i].depth > 24 && best < 0)
best = i;
}
}
#if 0
if (best == -1) { /* look for a DirectColor, 24-bit or more (pref 24) */
rvinfo.class = DirectColor;
if (vinfo)
XFree((char *) vinfo);
vinfo = XGetVisualInfo(dpy, flags, &rvinfo, &numvis);
if (vinfo) {
for (i = 0, best = -1; i < numvis; i++) {
if (vinfo[i].depth == 24)
best = i;
else if (vinfo[i].depth > 24 && best < 0)
best = i;
}
}
}
#endif
if (best > -1) {
context->visual = vinfo[best].visual;
context->depth = vinfo[best].depth;
context->vclass = vinfo[best].class;
getColormap(context, screen_number);
attr.colormap = context->cmap;
attr.override_redirect = True;
attr.border_pixel = 0;
context->drawable =
XCreateWindow(dpy, RootWindow(dpy, screen_number),
1, 1, 1, 1, 0, context->depth,
CopyFromParent, context->visual,
CWBorderPixel | CWColormap | CWOverrideRedirect, &attr);
/* XSetWindowColormap(dpy, context->drawable, context->cmap); */
}
if (best == -1) { /* look for a DirectColor, 24-bit or more (pref 24) */
rvinfo.class = DirectColor;
if (vinfo)
XFree((char *) vinfo);
XFree((char *) vinfo);
vinfo = XGetVisualInfo(dpy, flags, &rvinfo, &numvis);
if (vinfo) {
for (i = 0, best = -1; i < numvis; i++) {
if (vinfo[i].depth == 24)
best = i;
else if (vinfo[i].depth > 24 && best < 0)
best = i;
}
}
}
#endif
if (best > -1) {
context->visual = vinfo[best].visual;
context->depth = vinfo[best].depth;
context->vclass = vinfo[best].class;
getColormap(context, screen_number);
attr.colormap = context->cmap;
attr.override_redirect = True;
attr.border_pixel = 0;
context->drawable =
XCreateWindow(dpy, RootWindow(dpy, screen_number),
1, 1, 1, 1, 0, context->depth,
CopyFromParent, context->visual,
CWBorderPixel | CWColormap | CWOverrideRedirect,
&attr);
/* XSetWindowColormap(dpy, context->drawable, context->cmap); */
}
if (vinfo)
XFree((char *) vinfo);
if (best < 0)
return False;
else
return True;
if (best < 0)
return False;
else
return True;
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
/* WMGlobe 0.5 - All the Earth on a WMaker Icon
* copyright (C) 1998,99 Jerome Dumonteil <jerome.dumonteil@capway.com>
* sunpos.c is taken from Xearth :
/* WMGlobe 1.3 - All the Earth on a WMaker Icon
* copyright (C) 1998,99,2000,01 Jerome Dumonteil <jerome.dumonteil@linuxfr.org>
* sunpos.c is taken from Xearth 1.0 (and part of 1.1):
*/
/*
* sunpos.c
@ -62,6 +62,7 @@
#define PI 3.141592653
#endif
#define TWOPI (2*PI)
#define DegsToRads(x) ((x)*(TWOPI/360))
/*
* the epoch upon which these astronomical calculations are based is
@ -93,8 +94,8 @@
* Eccentricity (eccentricity of orbit) 0.016713
*/
#define Epsilon_g (279.403303*(TWOPI/360))
#define OmegaBar_g (282.768422*(TWOPI/360))
#define Epsilon_g (DegsToRads(279.403303))
#define OmegaBar_g (DegsToRads(282.768422))
#define Eccentricity (0.016713)
/*
@ -102,7 +103,36 @@
* 1990.0 (computed as 23.440592 degrees according to the method given
* in duffett-smith, section 27)
*/
#define MeanObliquity (23.440592*(TWOPI/360))
#define MeanObliquity (DegsToRads(23.440592))
/*
* Lunar parameters, epoch January 0, 1990.0 (from Xearth 1.1)
*/
#define MoonMeanLongitude DegsToRads(318.351648)
#define MoonMeanLongitudePerigee DegsToRads( 36.340410)
#define MoonMeanLongitudeNode DegsToRads(318.510107)
#define MoonInclination DegsToRads( 5.145396)
#define SideralMonth (27.3217)
/*
* Force an angular value into the range [-PI, +PI]
*/
#define Normalize(x) \
do { \
if ((x) < -PI) \
do (x) += TWOPI; while ((x) < -PI); \
else if ((x) > PI) \
do (x) -= TWOPI; while ((x) > PI); \
} while (0)
static double solve_keplers_equation(double M);
static double mean_sun(double D);
static double sun_ecliptic_longitude(time_t ssue);
static void ecliptic_to_equatorial(double lambda, double beta,
double *alpha, double *delta);
static double julian_date(int y, int m, int d);
static double GST(time_t ssue);
/*
* solve Kepler's equation via Newton's method
@ -110,20 +140,39 @@
*/
static double solve_keplers_equation(double M)
{
double E;
double delta;
double E;
double delta;
E = M;
while (1) {
delta = E - Eccentricity * sin(E) - M;
if (fabs(delta) <= 1e-10)
break;
E -= delta / (1 - Eccentricity * cos(E));
}
return E;
E = M;
while (1) {
delta = E - Eccentricity * sin(E) - M;
if (fabs(delta) <= 1e-10)
break;
E -= delta / (1 - Eccentricity * cos(E));
}
return E;
}
/*
* Calculate the position of the mean sun: where the sun would
* be if the earth's orbit were circular instead of ellipictal.
*/
static double mean_sun(double D)
/* double D; days since ephemeris epoch */
{
double N, M;
N = RadsPerDay * D;
N = fmod(N, TWOPI);
if (N < 0)
N += TWOPI;
M = N + Epsilon_g - OmegaBar_g;
if (M < 0)
M += TWOPI;
return M;
}
/*
* compute ecliptic longitude of sun (in radians)
@ -132,25 +181,19 @@ static double solve_keplers_equation(double M)
static double sun_ecliptic_longitude(time_t ssue)
/* seconds since unix epoch */
{
double D, N;
double M_sun, E;
double v;
double D, N;
double M_sun, E;
double v;
D = DaysSinceEpoch(ssue);
D = DaysSinceEpoch(ssue);
N = RadsPerDay * D;
N = fmod(N, TWOPI);
if (N < 0)
N += TWOPI;
N = RadsPerDay * D;
M_sun = mean_sun(D);
E = solve_keplers_equation(M_sun);
v = 2 * atan(sqrt((1 + Eccentricity) / (1 - Eccentricity)) *
tan(E / 2));
M_sun = N + Epsilon_g - OmegaBar_g;
if (M_sun < 0)
M_sun += TWOPI;
E = solve_keplers_equation(M_sun);
v = 2 * atan(sqrt((1 + Eccentricity) / (1 - Eccentricity)) * tan(E / 2));
return (v + OmegaBar_g);
return (v + OmegaBar_g);
}
@ -158,7 +201,8 @@ static double sun_ecliptic_longitude(time_t ssue)
* convert from ecliptic to equatorial coordinates
* (after duffett-smith, section 27)
*/
static void ecliptic_to_equatorial(double lambda, double beta, double *alpha, double *delta)
static void ecliptic_to_equatorial(double lambda, double beta,
double *alpha, double *delta)
/*
* double lambda; ecliptic longitude
* double beta; ecliptic latitude
@ -166,13 +210,13 @@ static void ecliptic_to_equatorial(double lambda, double beta, double *alpha, do
* double *delta; (return) declination
*/
{
double sin_e, cos_e;
double sin_e, cos_e;
sin_e = sin(MeanObliquity);
cos_e = cos(MeanObliquity);
sin_e = sin(MeanObliquity);
cos_e = cos(MeanObliquity);
*alpha = atan2(sin(lambda) * cos_e - tan(beta) * sin_e, cos(lambda));
*delta = asin(sin(beta) * cos_e + cos(beta) * sin_e * sin(lambda));
*alpha = atan2(sin(lambda) * cos_e - tan(beta) * sin_e, cos(lambda));
*delta = asin(sin(beta) * cos_e + cos(beta) * sin_e * sin(lambda));
}
@ -188,26 +232,26 @@ static double julian_date(int y, int m, int d)
* int d; day of month
*/
{
int A, B, C, D;
double JD;
int A, B, C, D;
double JD;
/* lazy test to ensure gregorian calendar */
/* lazy test to ensure gregorian calendar */
/*
* ASSERT(y >= 1583);
*/
if ((m == 1) || (m == 2)) {
y -= 1;
m += 12;
}
A = y / 100;
B = 2 - A + (A / 4);
C = (int) (365.25 * y);
D = (int) (30.6001 * (m + 1));
if ((m == 1) || (m == 2)) {
y -= 1;
m += 12;
}
A = y / 100;
B = 2 - A + (A / 4);
C = (int) (365.25 * y);
D = (int) (30.6001 * (m + 1));
JD = B + C + D + d + 1720994.5;
JD = B + C + D + d + 1720994.5;
return JD;
return JD;
}
@ -219,30 +263,30 @@ static double julian_date(int y, int m, int d)
static double GST(time_t ssue)
/*time_t ssue; seconds since unix epoch */
{
double JD;
double T, T0;
double UT;
struct tm *tm;
double JD;
double T, T0;
double UT;
struct tm *tm;
tm = gmtime(&ssue);
tm = gmtime(&ssue);
JD = julian_date(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday);
T = (JD - 2451545) / 36525;
JD = julian_date(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday);
T = (JD - 2451545) / 36525;
T0 = ((T + 2.5862e-5) * T + 2400.051336) * T + 6.697374558;
T0 = ((T + 2.5862e-5) * T + 2400.051336) * T + 6.697374558;
T0 = fmod(T0, 24.0);
if (T0 < 0)
T0 += 24;
T0 = fmod(T0, 24.0);
if (T0 < 0)
T0 += 24;
UT = tm->tm_hour + (tm->tm_min + tm->tm_sec / 60.0) / 60.0;
UT = tm->tm_hour + (tm->tm_min + tm->tm_sec / 60.0) / 60.0;
T0 += UT * 1.002737909;
T0 = fmod(T0, 24.0);
if (T0 < 0)
T0 += 24;
T0 += UT * 1.002737909;
T0 = fmod(T0, 24.0);
if (T0 < 0)
T0 += 24;
return T0;
return T0;
}
@ -251,28 +295,67 @@ static double GST(time_t ssue)
* epoch), compute position on the earth (lat, lon) such that sun is
* directly overhead.
*/
void GetSunPos(time_t ssue, double *lat, double *lon)
/* time_t ssue; seconds since unix epoch */
/* double *lat; (return) latitude */
/* double *lon; (return) longitude */
void sun_position(time_t ssue, double *lat, double *lon)
/* time_t ssue; seconds since unix epoch */
/* double *lat; (return) latitude in rad */
/* double *lon; (return) longitude in rad */
{
double lambda;
double alpha, delta;
double tmp;
double lambda;
double alpha, delta;
double tmp;
lambda = sun_ecliptic_longitude(ssue);
ecliptic_to_equatorial(lambda, 0.0, &alpha, &delta);
lambda = sun_ecliptic_longitude(ssue);
ecliptic_to_equatorial(lambda, 0.0, &alpha, &delta);
tmp = alpha - (TWOPI / 24) * GST(ssue);
if (tmp < -PI) {
do
tmp += TWOPI;
while (tmp < -PI);
} else if (tmp > PI) {
do
tmp -= TWOPI;
while (tmp < -PI);
}
*lon = tmp;
*lat = delta;
tmp = alpha - (TWOPI / 24) * GST(ssue);
Normalize(tmp);
*lon = tmp;
*lat = delta;
}
/*
* given a particular time (expressed in seconds since the unix
* epoch), compute position on the earth (lat, lon) such that the
* moon is directly overhead.
*
* Based on duffett-smith **2nd ed** section 61; combines some steps
* into single expressions to reduce the number of extra variables.
*/
void moon_position(time_t ssue, double *lat, double *lon)
/* time_t ssue; seconds since unix epoch */
/* double *lat; (return) latitude in ra */
/* double *lon; (return) longitude in ra */
{
double lambda, beta;
double D, L, Ms, Mm, N, Ev, Ae, Ec, alpha, delta;
D = DaysSinceEpoch(ssue);
lambda = sun_ecliptic_longitude(ssue);
Ms = mean_sun(D);
L = fmod(D / SideralMonth, 1.0) * TWOPI + MoonMeanLongitude;
Normalize(L);
Mm = L - DegsToRads(0.1114041 * D) - MoonMeanLongitudePerigee;
Normalize(Mm);
N = MoonMeanLongitudeNode - DegsToRads(0.0529539 * D);
Normalize(N);
Ev = DegsToRads(1.2739) * sin(2.0 * (L - lambda) - Mm);
Ae = DegsToRads(0.1858) * sin(Ms);
Mm += Ev - Ae - DegsToRads(0.37) * sin(Ms);
Ec = DegsToRads(6.2886) * sin(Mm);
L += Ev + Ec - Ae + DegsToRads(0.214) * sin(2.0 * Mm);
L += DegsToRads(0.6583) * sin(2.0 * (L - lambda));
N -= DegsToRads(0.16) * sin(Ms);
L -= N;
lambda = (fabs(cos(L)) < 1e-12) ?
(N + sin(L) * cos(MoonInclination) * PI / 2) :
(N + atan2(sin(L) * cos(MoonInclination), cos(L)));
Normalize(lambda);
beta = asin(sin(L) * sin(MoonInclination));
ecliptic_to_equatorial(lambda, beta, &alpha, &delta);
alpha -= (TWOPI / 24) * GST(ssue);
Normalize(alpha);
*lon = alpha;
*lat = delta;
}

View file

@ -1,5 +1,5 @@
/* WMGlobe 0.5 - All the Earth on a WMaker Icon
* copyright (C) 1998,99 Jerome Dumonteil <jerome.dumonteil@capway.com>
/* WMGlobe 1.3 - All the Earth on a WMaker Icon
* copyright (C) 1998,99,2000,01 Jerome Dumonteil <jerome.dumonteil@linuxfr.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -35,353 +35,398 @@
#include "defnimap.xpm"
#endif
/***************************************************************************/
int main(int argc, char *argv[])
{
unsigned int borderwidth = 1;
XClassHint classHint;
char *wname = argv[0];
XTextProperty name;
unsigned int borderwidth = 1;
XClassHint classHint;
char *wname = argv[0];
XTextProperty name;
XGCValues gcv;
unsigned long gcm;
XWindowAttributes attributes;
XColor color;
XGCValues gcv;
unsigned long gcm;
XWindowAttributes attributes;
XColor color;
RContext *ctx;
RContext *ctx;
XSizeHints mysizehints;
XWMHints mywmhints;
Pixel back_pix, fore_pix;
char Geometry[256];
XSizeHints mysizehints;
XWMHints mywmhints;
Pixel back_pix, fore_pix;
char Geometry[256];
char *rond_bits;
char *rond_bits;
int dummy = 0;
int ok, redoaction, wait_release, move_lat_flag;
int xx, yy;
int dummy = 0;
int ok, redoaction, wait_release, move_lat_flag;
int xx, yy;
/** initialisation *********************/
xx = 0;
yy = 0;
ok = FALSE;
move_lat_flag = FALSE;
redoaction = 0;
wait_release = 0;
xx = 0;
yy = 0;
ok = FALSE;
move_lat_flag = FALSE;
redoaction = 0;
wait_release = 0;
setlocale(LC_TIME, "");
setlocale(LC_TIME, "");
#ifdef DEBUG
fprintf(stdout, "%s\n", setlocale(LC_TIME, ""));
fprintf(stdout, "%s\n", setlocale(LC_TIME, ""));
#endif
set_defaults();
set_defaults();
cmdline(argc, argv);
cmdline(argc, argv);
switch (typecadre) {
case 1:
rond_bits = cadre1_bits;
break;
case 2:
rond_bits = cadre2_bits;
break;
default:
rond_bits = cadre0_bits;
}
if (p_type == PTRANDOM) {
dlat = 0;
dlong = 0;
}
initmyconvert();
tdelay.tv_sec = (int) floor(delay);
tdelay.tv_usec = (int) ((delay - tdelay.tv_sec) * 1000000);
aml = (int) floor(ambient_light * 256);
/****************************************************************************/
if (!(dpy = XOpenDisplay(dpy_name))) {
fprintf(stderr, "%s: can't open display \"%s\"\n",
wname, XDisplayName(dpy_name));
exit(1);
}
ctx = myRCreateContext(dpy, DefaultScreen(dpy), NULL);
if (ctx->attribs->use_shared_memory) {
#ifdef DEBUG
fprintf(stdout, "enleve les flags use_shared_memory\n");
#if WITH_MARKERS
if (nb_marker) {
int i;
for (i = 0; i < nb_marker; i++)
if (i != moon_marker && i != sun_marker) {
marker[i][0] = marker[i][0] * PI / 180.;
marker[i][1] = marker[i][1] * PI / 180.;
transform_marker(i);
}
}
#endif
ctx->attribs->flags ^= RC_UseSharedMemory;
ctx->attribs->use_shared_memory = FALSE;
ctx->flags.use_shared_pixmap = 0;
}
switch (typecadre) {
case 1:
rond_bits = cadre1_bits;
break;
case 2:
rond_bits = cadre2_bits;
break;
default:
rond_bits = cadre0_bits;
}
if (p_type == PTRANDOM) {
dlat = 0;
dlong = 0;
}
/* setup long term mem allocation */
initmyconvert();
tdelay.tv_sec = (int) floor(delay);
tdelay.tv_usec = (int) ((delay - tdelay.tv_sec) * 1000000);
aml = (int) floor(ambient_light * 256);
/* ctx initialization */
if (!(dpy = XOpenDisplay(dpy_name))) {
fprintf(stderr, "%s: can't open display \"%s\"\n",
wname, XDisplayName(dpy_name));
exit(1);
}
ctx = myRCreateContext(dpy, DefaultScreen(dpy), NULL);
if (ctx->attribs->use_shared_memory) {
#ifdef DEBUG
fprintf(stdout, "depth %d\n", ctx->depth);
fflush(stdout);
fprintf(stdout, "remove flags use_shared_memory\n");
#endif
ctx->attribs->flags ^= RC_UseSharedMemory;
ctx->attribs->use_shared_memory = FALSE;
ctx->flags.use_shared_pixmap = 0;
}
#ifdef DEBUG
fprintf(stdout, "depth %d\n", ctx->depth);
fflush(stdout);
#endif
/*
* loading maps .............
*
*/
if (dayfile != NULL) {
map = RLoadImage(ctx, dayfile, 0);
if (!map) {
fprintf(stdout, "pb map ! file not found ?\n");
exit(1);
}
if (dayfile != NULL) {
map = RLoadImage(ctx, dayfile, 0);
if (!use_default_nightmap)
use_nightmap = FALSE;
ripalpha(map);
if (!map) {
fprintf(stdout, "pb map ! file not found ?\n");
exit(1);
}
} else {
#ifdef DEFMAPOK
map = RGetImageFromXPMData(ctx, defmap_xpm);
use_default_nightmap = TRUE;
ripalpha(map);
if (!map) {
fprintf(stdout, "pb def map ! file not found ?\n");
exit(1);
}
}
#else
fprintf(stdout, "need a map !\n");
exit(1);
}
#endif
if (!oknimap) {
use_nightmap = FALSE;
use_default_nightmap = FALSE;
}
if (use_nightmap) {
if (nightfile != NULL) {
mapnight = RLoadImage(ctx, nightfile, 0);
ripalpha(mapnight);
if (!mapnight) {
fprintf(stdout, "pb map night! file not found ?\n");
exit(1);
}
} else {
#ifdef DEFMAPOK
map = RGetImageFromXPMData(ctx, defmap_xpm);
if (!map) {
fprintf(stdout, "pb def map ! file not found ?\n");
exit(1);
if (use_default_nightmap) {
mapnight = RGetImageFromXPMData(ctx, defnimap_xpm);
ripalpha(mapnight);
if (!mapnight) {
fprintf(stdout,
"pb def map night ! file not found ?\n");
exit(1);
}
nightfile = NULL;
use_nightmap = TRUE;
}
}
#else
fprintf(stdout, "need a map !\n");
exit(1);
use_nightmap = FALSE;
}
#endif
}
if (use_nightmap) {
if (nightfile != NULL) {
mapnight = RLoadImage(ctx, nightfile, 0);
if (!mapnight) {
fprintf(stdout, "pb map night! file not found ?\n");
exit(1);
}
} else {
#ifdef DEFMAPOK
mapnight = RGetImageFromXPMData(ctx, defnimap_xpm);
if (!mapnight) {
fprintf(stdout, "pb def map night ! file not found ?\n");
exit(1);
}
}
#else
/* not very useful... */
use_nightmap = FALSE;
}
#endif
use_nmap_ini = use_nightmap;
/* we need a night map of same size as day map */
if (mapnight) {
if ((mapnight->width != map->width)
|| (mapnight->height != map->height)) {
RImage *tmp;
tmp = mapnight;
mapnight = RScaleImage(tmp, map->width, map->height);
RReleaseImage(tmp);
ripalpha(mapnight);
}
use_nmap_ini = use_nightmap;
if (!oknimap)
use_nightmap = FALSE;
}
/* some other init ..................................... */
ratiox = (double) map->width / (2 * PI);
ratioy = (double) map->height / PI;
mratiox = (int) floor(ratiox * 256);
mratioy = (int) floor(ratioy * 256);
loadxpm(ctx->drawable);
ratiox = (double) map->width / (2 * PI);
ratioy = (double) map->height / PI;
mratiox = (int) floor(ratiox * 256);
mratioy = (int) floor(ratioy * 256);
loadxpm(ctx->drawable);
small = RCreateImage(DIAMETRE, DIAMETRE, 1);
small = RCreateImage(DIAMETRE, DIAMETRE, 0);
calcDistance();
/*...................................................... */
calcDistance();
/*
* first rendering of the earth
*/
recalc(0);
do_something = FALSE;
rotation_terre(DIAMETRE / 2, DIAMETRE / 2, 0);
recalc(0);
do_something = FALSE;
/*************************************************************************
* well, here the problems begin : this code is a merge from wmgeneral and
* some stuff of wmaker, should be rewritten ...
************************************************************************/
/* wmg */
XGetWindowAttributes(dpy, ctx->drawable, &attributes);
XGetWindowAttributes(dpy, ctx->drawable, &attributes);
if (!RConvertImage(ctx, small, &pix)) {
fprintf(stdout, "error small->&pix\n");
puts(RMessageForError(RErrorCode));
exit(1);
}
wmg.pixmap = pix;
wmg.mask = pix;
if (!RConvertImage(ctx, small, &pix)) {
fprintf(stdout, "error small->&pix\n");
puts(RMessageForError(RErrorCode));
exit(1);
}
wmg.pixmap = pix;
wmg.mask = pix;
mysizehints.flags = USSize | USPosition;
mysizehints.x = 0;
mysizehints.y = 0;
mysizehints.flags = USSize | USPosition;
mysizehints.x = 0;
mysizehints.y = 0;
color.pixel = 0;
if (!XParseColor(dpy, attributes.colormap, "white", &color)) {
fprintf(stdout, "wmglobe: can't parse white\n");
} else if (!XAllocColor(dpy, attributes.colormap, &color)) {
fprintf(stdout, "wmglobe: can't allocate white\n");
}
back_pix = color.pixel;
color.pixel = 0;
if (!XParseColor(dpy, attributes.colormap, "white", &color)) {
fprintf(stdout, "wmglobe: can't parse white\n");
} else if (!XAllocColor(dpy, attributes.colormap, &color)) {
fprintf(stdout, "wmglobe: can't allocate white\n");
}
back_pix = color.pixel;
XGetWindowAttributes(dpy, ctx->drawable, &attributes);
XGetWindowAttributes(dpy, ctx->drawable, &attributes);
color.pixel = 0;
if (!XParseColor(dpy, attributes.colormap, "black", &color)) {
fprintf(stdout, "wmglobe: can't parse black\n");
} else if (!XAllocColor(dpy, attributes.colormap, &color)) {
fprintf(stdout, "wmglobe: can't allocate black\n");
}
fore_pix = color.pixel;
color.pixel = 0;
if (!XParseColor(dpy, attributes.colormap, "black", &color)) {
fprintf(stdout, "wmglobe: can't parse black\n");
} else if (!XAllocColor(dpy, attributes.colormap, &color)) {
fprintf(stdout, "wmglobe: can't allocate black\n");
}
fore_pix = color.pixel;
XWMGeometry(dpy, ctx->screen_number, Geometry, NULL, borderwidth, &mysizehints,
&mysizehints.x, &mysizehints.y, &mysizehints.width, &mysizehints.height, &dummy);
mysizehints.width = DIAMETRE;
mysizehints.height = DIAMETRE;
XWMGeometry(dpy, ctx->screen_number, Geometry, NULL, borderwidth,
&mysizehints, &mysizehints.x, &mysizehints.y,
&mysizehints.width, &mysizehints.height, &dummy);
mysizehints.width = DIAMETRE;
mysizehints.height = DIAMETRE;
win = XCreateSimpleWindow(dpy, ctx->drawable, mysizehints.x, mysizehints.y,
mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix);
win =
XCreateSimpleWindow(dpy, ctx->drawable, mysizehints.x,
mysizehints.y, mysizehints.width,
mysizehints.height, borderwidth, fore_pix,
back_pix);
iconwin = XCreateSimpleWindow(dpy, win, mysizehints.x, mysizehints.y,
mysizehints.width, mysizehints.height, borderwidth, fore_pix, back_pix);
iconwin = XCreateSimpleWindow(dpy, win, mysizehints.x, mysizehints.y,
mysizehints.width, mysizehints.height,
borderwidth, fore_pix, back_pix);
/* Activate hints */
XSetWMNormalHints(dpy, win, &mysizehints);
classHint.res_name = wname;
classHint.res_class = wname;
XSetClassHint(dpy, win, &classHint);
/* Activate hints */
XSetWMNormalHints(dpy, win, &mysizehints);
classHint.res_name = wname;
classHint.res_class = wname;
XSetClassHint(dpy, win, &classHint);
XSelectInput(dpy, win, ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask);
XSelectInput(dpy, iconwin, ButtonPressMask | ExposureMask | ButtonReleaseMask | PointerMotionMask | StructureNotifyMask);
XSelectInput(dpy, win,
ButtonPressMask | ExposureMask | ButtonReleaseMask |
PointerMotionMask | StructureNotifyMask);
XSelectInput(dpy, iconwin,
ButtonPressMask | ExposureMask | ButtonReleaseMask |
PointerMotionMask | StructureNotifyMask);
if (XStringListToTextProperty(&wname, 1, &name) == 0) {
fprintf(stdout, "%s: can't allocate window name\n", wname);
exit(1);
}
XSetWMName(dpy, win, &name);
if (XStringListToTextProperty(&wname, 1, &name) == 0) {
fprintf(stdout, "%s: can't allocate window name\n", wname);
exit(1);
}
XSetWMName(dpy, win, &name);
/* Create GC for drawing */
/* Create GC for drawing */
gcm = GCForeground | GCBackground | GCGraphicsExposures;
gcv.foreground = fore_pix;
gcv.background = back_pix;
gcv.graphics_exposures = 0;
NormalGC = XCreateGC(dpy, ctx->drawable, gcm, &gcv);
gcm = GCForeground | GCBackground | GCGraphicsExposures;
gcv.foreground = fore_pix;
gcv.background = back_pix;
gcv.graphics_exposures = 0;
NormalGC = XCreateGC(dpy, ctx->drawable, gcm, &gcv);
/* ONLYSHAPE ON */
if (onlyshape) {
pixmask = XCreateBitmapFromData(dpy, win, rond_bits, DIAMETRE, DIAMETRE);
XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, pixmask, ShapeSet);
XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet);
}
/* ONLYSHAPE OFF */
/* ONLYSHAPE ON */
if (onlyshape) {
pixmask =
XCreateBitmapFromData(dpy, win, rond_bits, DIAMETRE, DIAMETRE);
XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, pixmask,
ShapeSet);
XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, pixmask,
ShapeSet);
}
/* ONLYSHAPE OFF */
mywmhints.initial_state = option_iw;
mywmhints.icon_window = iconwin;
mywmhints.icon_x = mysizehints.x;
mywmhints.icon_y = mysizehints.y;
mywmhints.window_group = win;
mywmhints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint;
mywmhints.initial_state = option_iw;
mywmhints.icon_window = iconwin;
mywmhints.icon_x = mysizehints.x;
mywmhints.icon_y = mysizehints.y;
mywmhints.window_group = win;
mywmhints.flags =
StateHint | IconWindowHint | IconPositionHint | WindowGroupHint;
XSetWMHints(dpy, win, &mywmhints);
XSetWMHints(dpy, win, &mywmhints);
XSetCommand(dpy, win, argv, argc);
XMapWindow(dpy, win);
/****************************************************************************/
XSetCommand(dpy, win, argv, argc);
XMapWindow(dpy, win);
XCopyArea(dpy, wmg.pixmap, win, NormalGC, 0, 0, DIAMETRE, DIAMETRE, 0, 0);
XCopyArea(dpy, wmg.pixmap, win, NormalGC, 0, 0, DIAMETRE, DIAMETRE, 0,
0);
RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE);
RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE);
/*
* ================= MAIN LOOP ==================
*/
while (1) {
while (XPending(dpy)) {
XNextEvent(dpy, &Event);
switch (Event.type) {
case Expose:
RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE);
break;
case DestroyNotify:
XCloseDisplay(dpy);
exit(0);
break;
case ButtonPress:
while (1) {
while (XPending(dpy)) {
XNextEvent(dpy, &Event);
switch (Event.type) {
case Expose:
RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE);
break;
case DestroyNotify:
XCloseDisplay(dpy);
exit(0);
break;
case ButtonPress:
/*
* earth rotate when clic left (1) , zooming when middle (2)
* change screen to longitude / latitude when (3)
*/
switch (Event.xbutton.button) {
case 1:
switch (Event.xbutton.button) {
case 1:
#ifdef MOUSE_LAT_NO_SHIFT
move_lat_flag = TRUE;
move_lat_flag = TRUE;
#else
if (Event.xbutton.state & ShiftMask)
move_lat_flag = TRUE;
else
move_lat_flag = FALSE;
if (Event.xbutton.state & ShiftMask)
move_lat_flag = TRUE;
else
move_lat_flag = FALSE;
#endif
redoaction = 1;
wait_release = 1;
break;
case 2:
if (Event.xbutton.state & ShiftMask)
redoaction = 2;
else
redoaction = 3;
wait_release = 1;
break;
case 3:
wait_release = 0;
redoaction = 0;
screen_back();
ok = TRUE;
break;
default:
break;
}
break;
case ButtonRelease:
wait_release = 0;
redoaction = 0;
break;
default:
break;
}
redoaction = 1;
wait_release = 1;
break;
case 2:
if (Event.xbutton.state & ShiftMask)
redoaction = 2;
else
redoaction = 3;
wait_release = 1;
break;
case 3:
wait_release = 0;
redoaction = 0;
screen_back();
ok = TRUE;
break;
default:
break;
}
if (wait_release) {
usleep(2 * VAL_USLEEP_SHORT);
if (redoaction == 1)
rotation_terre(Event.xbutton.x, Event.xbutton.y, move_lat_flag);
else
zooming(Event.xbutton.state & ShiftMask);
ok = TRUE;
}
if (diftimev(tnext, getimev()).tv_sec < 0 || ok) {
ok = FALSE;
recalc(redoaction == 1);
if (do_something) {
if (!myRConvertImage(ctx, small, &pix)) {
fprintf(stdout, "plante !?\n");
fprintf(stdout, RMessageForError(RErrorCode));
exit(1);
}
wmg.pixmap = pix;
wmg.mask = pix;
RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE);
#ifdef DEBUG
fprintf(stdout, "draw\n");
#endif
do_something = FALSE;
}
}
usleep(VAL_USLEEP);
break;
case ButtonRelease:
wait_release = 0;
redoaction = 0;
break;
default:
break;
}
}
/*
* Still wonder about freeing some memory for X
*/
return 0;
if (wait_release) {
usleep(2 * VAL_USLEEP_SHORT);
if (redoaction == 1)
rotation_terre(Event.xbutton.x, Event.xbutton.y,
move_lat_flag);
else
zooming(Event.xbutton.state & ShiftMask);
ok = TRUE;
}
if (diftimev(tnext, getimev()).tv_sec < 0 || ok) {
ok = FALSE;
recalc(redoaction == 1);
if (do_something) {
if (!myRConvertImage(ctx, small, &pix)) {
fprintf(stderr, "crash !?\n");
fprintf(stderr, RMessageForError(RErrorCode));
exit(1);
}
wmg.pixmap = pix;
wmg.mask = pix;
RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE);
#ifdef DEBUG
fprintf(stdout, "draw\n");
#endif
do_something = FALSE;
}
}
usleep(VAL_USLEEP);
}
return 0;
}

View file

@ -1,5 +1,5 @@
/* WMGlobe 0.5 - All the Earth on a WMaker Icon
* copyright (C) 1998,99 Jerome Dumonteil <jerome.dumonteil@capway.com>
/* WMGlobe 1.3 - All the Earth on a WMaker Icon
* copyright (C) 1998,99,2000,01 Jerome Dumonteil <jerome.dumonteil@linuxfr.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -51,13 +51,15 @@
#define FALSE 0
#define TRUE 1
#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))
#define STRONG 2
#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define PTFIXED 1
#define PTSUNREL 2
#define PTRANDOM 3
#define PTFIXED 1
#define PTSUN 2
#define PTRANDOM 3
#define PTMOON 4
#ifndef PI
#define PI 3.141592653
@ -74,34 +76,31 @@
#define MAX_MOUSE_REGION (8)
typedef struct {
int enable;
int top;
int bottom;
int left;
int right;
int enable;
int top;
int bottom;
int left;
int right;
} MOUSE_REGION;
MOUSE_REGION mouse_region[MAX_MOUSE_REGION];
typedef struct MPO {
int r, g, b;
int r, g, b;
} MPO;
MPO *md[4], *mn[4];
double soluce[DIAMETRE / 2][DIAMETRE][4];
double solu[DIAMETRE][DIAMETRE][3];
int tabsolu[DIAMETRE][DIAMETRE];
int solution;
/************/
typedef struct {
Pixmap pixmap;
Pixmap mask;
XpmAttributes attributes;
Pixmap pixmap;
Pixmap mask;
XpmAttributes attributes;
} XpmIcon;
/************/
Display *dpy;
@ -121,6 +120,13 @@ GC NormalGC;
/********* rendering********/
#if WITH_MARKERS
double marker[MAX_MARKERS][3];
int nb_marker, sun_marker, moon_marker;
RColor sun_col, moon_col;
double moon_lat,moon_long;
#endif
double delay, time_multi;
/*
* struct timeval delta_tim, last_tim, next_tim, render_tim, base_tim,
@ -133,8 +139,8 @@ time_t tsunpos;
int sens, fun, funx, funy, oknimap, mratiox, mratioy, gotoscr;
int typecadre, p_type, use_nightmap, use_nmap_ini, firstTime, stoprand,
do_something, iop;
int typecadre, p_type, use_nightmap, use_default_nightmap, use_nmap_ini,
firstTime, stoprand, do_something, iop;
double v_lat, v_long, old_dvlat, old_dvlong, dv_lat, dv_long;
double dlat, dlong, addlat, addlong, ratiox, ratioy, dawn;
@ -161,11 +167,14 @@ RColor noir;
double minhz;
#endif
int stable;
/****************************************************************/
/* Function Prototypes */
/****************************************************************/
int main(int argc, char *argv[]);
/****************************************************************/
void AddMouseRegion(int index, int left, int top, int right, int bottom);
int CheckMouseRegion(int x, int y);
void RedrawWindowXYWH(int x, int y, int w, int h);
@ -179,19 +188,24 @@ struct timeval diftimev(struct timeval t1, struct timeval t2);
struct timeval addtimev(struct timeval t1, struct timeval t2);
struct timeval getimev();
/***************************************************************/
void setZoom(double z);
void calcDistance();
void renderFrame();
void initmyconvert();
int myRConvertImage(RContext * context, RImage * image, Pixmap * pixmap);
RContext *myRCreateContext
(Display * dpy, int screen_number, RContextAttributes * attribs);
(Display * dpy, int screen_number, RContextAttributes * attribs);
void setTime(struct timeval t);
void recalc(int calme);
void GetSunPos(time_t ssue, double *lat, double *lon);
void sun_position(time_t ssue, double *lat, double *lon);
void moon_position(time_t ssue, double *lat, double *lon);
void transform_marker(int m);
void setViewPos(double lat, double lon);
/***************************************************************/
int ripalpha(RImage * image);
RImage*
RScaleImage(RImage *image, unsigned new_width, unsigned new_height);
void
RReleaseImage(RImage *image);
#endif

View file

@ -1,5 +1,5 @@
/* WMGlobe 0.5 - All the Earth on a WMaker Icon
* copyright (C) 1998,99 Jerome Dumonteil <jerome.dumonteil@capway.com>
/* WMGlobe 1.3 - All the Earth on a WMaker Icon
* copyright (C) 1998,99,2000,01 Jerome Dumonteil <jerome.dumonteil@linuxfr.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -20,7 +20,7 @@
* #define DEBUG
*/
#define WMGVERSION "WMGlobe v.0.5 6 fev 1999 <jerome.dumonteil@capway.com>"
#define WMGVERSION "WMGlobe v.1.3 12 aug 2001 <jerome.dumonteil@linuxfr.org>"
/*
* comment DEFMAPOK to not install the built-in default maps,
@ -64,14 +64,27 @@
#define STOP_RANDOM_FACTOR 1
#define RATIO_ROTATE 0.5
/* Markers */
#define WITH_MARKERS 1 /* put to 0 to remove markers code */
#define CROSS_LENGTH 8 /* min 2 */
#define CROSS_INVERT 0 /* 0: black/white, 1: inv. color */
#define MAX_MARKERS 5
#define CR_SUN_R 255 /* sun cross color */
#define CR_SUN_G 255
#define CR_SUN_B 127
#define CR_MOON_R 0 /* moon cross color */
#define CR_MOON_G 200
#define CR_MOON_B 255
/* some default values*/
#define DEFAULT_DELAY 1.0
#define DEFAULT_V_LAT 0.0
#define DEFAULT_V_LONG 0.0
#define DEFAULT_SENS 1
#define DEFAULT_ZOOM 1.0
#define DEFAULT_LIGHT 0.25
#define DEFAULT_BORDER 0
#define DEFAULT_BORDER 2
#define DEFAULT_NIGHTMAP 1 /* 1 or 0 */
#define MAX_DELAY_SEC 86400.0

File diff suppressed because it is too large Load diff

View file

@ -1,398 +0,0 @@
/*
* Raster graphics library
*
* Copyright (c) 1997, 1998 Alfredo K. Kojima
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* Environment variables:
*
* WRASTER_GAMMA <rgamma>/<ggamma>/<bgamma>
* gamma correction value. Must be greater than 0
* Only for PseudoColor visuals.
*
* Default:
* WRASTER_GAMMA 1/1/1
*
*
* If you want a specific value for a screen, append the screen number
* preceded by a hash to the variable name as in
* WRASTER_GAMMA#1
* for screen number 1
*/
#ifndef RLRASTER_H_
#define RLRASTER_H_
/* version of the header for the library: 0.11 */
#define WRASTER_HEADER_VERSION 11
#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#endif
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#ifdef XSHM
#include <X11/extensions/XShm.h>
#endif
/* RM_MATCH or RM_DITHER */
#define RC_RenderMode (1<<0)
/* number of colors per channel for colormap in PseudoColor mode */
#define RC_ColorsPerChannel (1<<1)
/* do gamma correction */
#define RC_GammaCorrection (1<<2)
/* visual id to use */
#define RC_VisualID (1<<3)
/* shared memory usage */
#define RC_UseSharedMemory (1<<4)
/* use default instead of best visual */
#define RC_DefaultVisual (1<<5)
typedef struct RContextAttributes {
int flags;
int render_mode;
int colors_per_channel; /* for PseudoColor */
float rgamma; /* gamma correction for red, */
float ggamma; /* green, */
float bgamma; /* and blue */
VisualID visualid; /* visual ID to use */
int use_shared_memory; /* True of False */
} RContextAttributes;
/*
* describes a screen in terms of depth, visual, number of colors
* we can use, if we should do dithering, and what colors to use for
* dithering.
*/
typedef struct RContext {
Display *dpy;
int screen_number;
Colormap cmap;
RContextAttributes *attribs;
GC copy_gc;
Visual *visual;
int depth;
Window drawable; /* window to pass for XCreatePixmap(). */
/* generally = root */
int vclass;
unsigned long black;
unsigned long white;
int red_offset; /* only used in 24bpp */
int green_offset;
int blue_offset;
/* only used for pseudocolor and grayscale */
XStandardColormap *std_rgb_map; /* standard RGB colormap */
XStandardColormap *std_gray_map; /* standard grayscale colormap */
int ncolors; /* total number of colors we can use */
XColor *colors; /* internal colormap */
struct {
unsigned int use_shared_pixmap:1;
} flags;
} RContext;
typedef struct RColor {
unsigned char red;
unsigned char green;
unsigned char blue;
unsigned char alpha;
} RColor;
typedef struct RHSVColor {
unsigned short hue; /* 0-359 */
unsigned char saturation; /* 0-255 */
unsigned char value; /* 0-255 */
} RHSVColor;
typedef struct RPoint {
int x, y;
} RPoint;
typedef struct RSegment {
int x1, y1, x2, y2;
} RSegment;
/*
* internal 24bit+alpha image representation
*/
typedef struct RImage {
unsigned width, height; /* size of the image */
RColor background; /* background color */
unsigned char *data[4]; /* image data (R,G,B,A) */
} RImage;
/*
* internal wrapper for XImage. Used for shm abstraction
*/
typedef struct RXImage {
XImage *image;
/* Private data. Do not access */
#ifdef XSHM
XShmSegmentInfo info;
char is_shared;
#endif
} RXImage;
/* note that not all operations are supported in all functions */
enum {
RClearOperation, /* clear with 0 */
RCopyOperation,
RNormalOperation, /* same as combine */
RAddOperation,
RSubtractOperation
};
/* image display modes */
enum {
RDitheredRendering = 0,
RBestMatchRendering = 1
};
/* bw compat */
#define RM_DITHER RDitheredRendering
#define RM_MATCH RBestMatchRendering
enum {
RAbsoluteCoordinates = 0,
RRelativeCoordinates = 1
};
enum {
RSunkenBevel = -1,
RRaisedBevel = 1
};
/* bw compat */
#define RBEV_SUNKEN RSunkenBevel
/* 1 pixel wide */
#define RBEV_RAISED RRaisedBevel
/* 1 pixel wide on top/left 2 on bottom/right */
#define RBEV_RAISED2 2
/* 2 pixel width */
#define RBEV_RAISED3 3
enum {
RHorizontalGradient = 2,
RVerticalGradient = 3,
RDiagonalGradient = 4
};
/* for backwards compatibility */
#define RGRD_HORIZONTAL RHorizontalGradient
#define RGRD_VERTICAL RVerticalGradient
#define RGRD_DIAGONAL RDiagonalGradient
/* error codes */
#define RERR_NONE 0
#define RERR_OPEN 1 /* cant open file */
#define RERR_READ 2 /* error reading from file */
#define RERR_WRITE 3 /* error writing to file */
#define RERR_NOMEMORY 4 /* out of memory */
#define RERR_NOCOLOR 5 /* out of color cells */
#define RERR_BADIMAGEFILE 6 /* image file is corrupted or invalid */
#define RERR_BADFORMAT 7 /* image file format is unknown */
#define RERR_BADINDEX 8 /* no such image index in file */
#define RERR_BADVISUALID 16 /* invalid visual ID requested for context */
#define RERR_XERROR 127 /* internal X error */
#define RERR_INTERNAL 128 /* should not happen */
/*
* Returns a NULL terminated array of strings containing the
* supported formats, such as: TIFF, XPM, PNG, JPEG, PPM, GIF
*/
char **RSupportedFileFormats(void);
void RFreeStringList(char **list);
/*
* Xlib contexts
*/
RContext *RCreateContext(Display * dpy, int screen_number,
RContextAttributes * attribs);
void RDestroyContext(RContext * context);
Bool RGetClosestXColor(RContext * context, RColor * color, XColor * retColor);
/*
* RImage creation
*/
RImage *RCreateImage(unsigned width, unsigned height, int alpha);
RImage *RCreateImageFromXImage(RContext * context, XImage * image, XImage * mask);
RImage *RCreateImageFromDrawable(RContext * context, Drawable drawable,
Pixmap mask);
RImage *RLoadImage(RContext * context, char *file, int index);
void RDestroyImage(RImage * image);
RImage *RGetImageFromXPMData(RContext * context, char **data);
/*
* RImage storing
*/
Bool RSaveImage(RImage * image, char *filename, char *format);
/*
* Area manipulation
*/
RImage *RCloneImage(RImage * image);
RImage *RGetSubImage(RImage * image, int x, int y, unsigned width,
unsigned height);
void RCombineImageWithColor(RImage * image, RColor * color);
void RCombineImages(RImage * image, RImage * src);
void RCombineArea(RImage * image, RImage * src, int sx, int sy, unsigned width,
unsigned height, int dx, int dy);
void RCombineImagesWithOpaqueness(RImage * image, RImage * src, int opaqueness);
void RCombineAreaWithOpaqueness(RImage * image, RImage * src, int sx, int sy,
unsigned width, unsigned height, int dx, int dy,
int opaqueness);
RImage *RScaleImage(RImage * image, unsigned new_width, unsigned new_height);
RImage *RMakeTiledImage(RImage * tile, unsigned width, unsigned height);
RImage *RMakeCenteredImage(RImage * image, unsigned width, unsigned height,
RColor * color);
/*
* Drawing
*/
Bool RGetPixel(RImage * image, int x, int y, RColor * color);
void RPutPixel(RImage * image, int x, int y, RColor * color);
void ROperatePixel(RImage * image, int operation, int x, int y, RColor * color);
void RPutPixels(RImage * image, RPoint * points, int npoints, int mode,
RColor * color);
void ROperatePixels(RImage * image, int operation, RPoint * points,
int npoints, int mode, RColor * color);
int RDrawLine(RImage * image, int x0, int y0, int x1, int y1, RColor * color);
int ROperateLine(RImage * image, int operation, int x0, int y0, int x1, int y1,
RColor * color);
void RDrawLines(RImage * image, RPoint * points, int npoints, int mode,
RColor * color);
void ROperateLines(RImage * image, int operation, RPoint * points, int npoints,
int mode, RColor * color);
void RDrawSegments(RImage * image, RSegment * segs, int nsegs, RColor * color);
void ROperateSegments(RImage * image, int operation, RSegment * segs, int nsegs,
RColor * color);
/*
* Color convertion
*/
void RRGBtoHSV(RColor * color, RHSVColor * hsv);
void RHSVtoRGB(RHSVColor * hsv, RColor * rgb);
/*
* Painting
*/
void RClearImage(RImage * image, RColor * color);
void RBevelImage(RImage * image, int bevel_type);
RImage *RRenderGradient(unsigned width, unsigned height, RColor * from,
RColor * to, int style);
RImage *RRenderMultiGradient(unsigned width, unsigned height, RColor ** colors,
int style);
/*
* Convertion into X Pixmaps
*/
int RConvertImage(RContext * context, RImage * image, Pixmap * pixmap);
int RConvertImageMask(RContext * context, RImage * image, Pixmap * pixmap,
Pixmap * mask, int threshold);
/*
* misc. utilities
*/
RXImage *RCreateXImage(RContext * context, int depth,
unsigned width, unsigned height);
void RDestroyXImage(RContext * context, RXImage * ximage);
void RPutXImage(RContext * context, Drawable d, GC gc, RXImage * ximage,
int src_x, int src_y, int dest_x, int dest_y,
unsigned width, unsigned height);
/* do not free the returned string! */
const char *RMessageForError(int errorCode);
int RBlurImage(RImage * image);
/****** Global Variables *******/
extern int RErrorCode;
#endif

View file

@ -1,5 +1,5 @@
/* WMGlobe 0.5.pre1 - All the Earth on a WMaker Icon
* copyright (C) 1998,99 Jerome Dumonteil <jerome.dumonteil@capway.com>
/* WMGlobe 1.3 - All the Earth on a WMaker Icon
* copyright (C) 1998,99,2000,01 Jerome Dumonteil <jerome.dumonteil@linuxfr.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,22 +16,21 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
***************************************************************************/
int zapnum[14][4] =
{
{90, 0, 10, 13},
{0, 0, 10, 13},
{10, 0, 10, 13},
{20, 0, 10, 13},
{30, 0, 10, 13},
{40, 0, 10, 13},
{50, 0, 10, 13},
{60, 0, 10, 13},
{70, 0, 10, 13},
{80, 0, 10, 13},
{100, 0, 10, 13},
{110, 0, 10, 13},
{100, 0, 5, 13},
{114, 0, 5, 13}
int zapnum[14][4] = {
{90, 0, 10, 13},
{0, 0, 10, 13},
{10, 0, 10, 13},
{20, 0, 10, 13},
{30, 0, 10, 13},
{40, 0, 10, 13},
{50, 0, 10, 13},
{60, 0, 10, 13},
{70, 0, 10, 13},
{80, 0, 10, 13},
{100, 0, 10, 13},
{110, 0, 10, 13},
{100, 0, 5, 13},
{114, 0, 5, 13}
};
/*
@ -54,27 +53,23 @@ int zapnum[14][4] =
* };
*/
int platd[4][2] =
{
{2, 12},
{6, 12},
{16, 12},
{26, 12}
int platd[4][2] = {
{2, 12},
{6, 12},
{16, 12},
{26, 12}
};
int platm[2][2] =
{
{42, 12},
{52, 12}
int platm[2][2] = {
{42, 12},
{52, 12}
};
int plongd[4][2] =
{
{2, 36},
{6, 36},
{16, 36},
{26, 36}
int plongd[4][2] = {
{2, 36},
{6, 36},
{16, 36},
{26, 36}
};
int plongm[2][2] =
{
{42, 36},
{52, 36}
int plongm[2][2] = {
{42, 36},
{52, 36}
};

View file

@ -1,4 +1,4 @@
.TH WMGlobe 1 "fevrier 1999"
.TH WMGlobe 1.3 "august 2001"
.SH NAME
WMGlobe - The Whole Earth spinning on you desktop...
as a dockable app for WindowMaker
@ -14,7 +14,7 @@ rendered on a sphere by raytracing. Yes, for a 64x64 pixel result:-)
.B \-v
version. Currently, this should display :
WMGlobe v.0.5 6 fev 1999 <jerome.dumonteil@capway.com>
WMGlobe v.1.3 12 aug 2001 <jerome.dumonteil@linuxfr.org>
.TP
.B \-h
short help
@ -28,11 +28,18 @@ the sun rotation. Accepted values in the form 45
Default: the initial position is "under" the sun, and
the point of view follows the sun.
.TP
.B \-sun
The point of view follows the Sun (default).
.TP
.B \-moon
The point of view follows the Moon (i.e. you see the Earth as you
were on the Moon).
.TP
.B \-rand
New random position at every refresh of screen.
.TP
.B \-map \fI map_file\fP
Map used for the rendering. Can be JPEG, GIG, XPM
Map used for the rendering. Can be JPEG, GIF, XPM
PNM, TIFF but none BMP.
Default: use internal map of earth.
.TP
@ -41,8 +48,9 @@ Map used for the dark side of the earth. Must be of
the same width x height as the day side map.
Default: if the default internal day map is used, use
a default internal night file (see -nonimap option).
If a custom day map is provided, and no night map, the
dark side is computed via the -light option.
.TP
.B \-defnimap
Use the default night map (with a custom map).
.TP
.B \-nonimap
Don't use the default night map.
@ -84,7 +92,7 @@ Default: 0.2
.TP
.B \-bord \fI border_num\fP
0 1 or 2. There are 3 different borders for the icon.
Default: 0
Default: 2
.TP
.B \-accel \fI time_multi\fP
Time warp factor. With -accel 24, the sun make a full
@ -97,6 +105,13 @@ WMGlobe is Y2K compliant without changing system time.
Negative values for dates before 1970 accepted.
Default: not set, use current time.
.TP
.B \-mk \fI latitude longitude\fP
Put a fixed marker at latitude/longitude.
-mk sun : put a marker under the Sun position.
-mk moon : put a marker under the Moon.
5 markers can be defined simultaneously, so you can
use wmglobe to predict when Moon will meet the Sun :-)
.TP
.B \-fun \fI dx dy\fP
Move the earth image by dx dy pixels in the icon. See
puzzle.sh to understand why.
@ -104,6 +119,9 @@ puzzle.sh to understand why.
.B \-oz
Start in "austral" mode (for "down under" people)
.TP
.B \-stable
Keep the globe from going over the poles.
.TP
.B \-d \fI display\fP
Select another display
.TP
@ -147,7 +165,7 @@ dimensions.
where to find the sources of wmglobe:
the web page of WMGlobe (made by Sylvestre Taburet):
<http://www.capway.com/dumonte1/wm/wmg.html>
<http://perso.linuxfr.org/jdumont/wmg/>
where to find maps and similar softs:
@ -173,7 +191,8 @@ By the way, you can use maps of Mars, Luna ... and text.
.LP
WMGlobe uses the setlocale(3) function, so you LANG environment need to be ok.
You need WindowMaker 0.20.3 or 0.51.0 installed to use WMGlobe.
You need WindowMaker 0.62 or higher to use WMGlobe. (use WMGlobe 1.0 for
older versions of WindowMaker).
.SH "SEE ALSO"
.LP
The Window Maker User Guide
@ -181,7 +200,7 @@ The Window Maker User Guide
The Window Maker FAQ
.SH "AUTHOR"
jerome dumonteil <jerome.dumonteil@capway.com>
jerome dumonteil <jerome.dumonteil@linuxfr.org>
Patches, bug reports, and suggestions are welcome.
@ -192,7 +211,9 @@ Read the COPYING file for the complete GNU license.
Original idea, tests, logos:
Sylvestre Taburet <staburet@consort.fr>
Sylvestre Taburet <Sylvestre.Taburet@free.fr>
WindowMaker 0.62 fix : Charles G Waldman <cgw@fnal.gov>
The code in 'sunpos.cpp' is taken from Xearth by Kirk Lauritz Johnson.
@ -238,5 +259,6 @@ and that LONG_MAX +1 = LONG_MIN . This happens with high values of -accel
when the date go over year 2038. The expected result is wmglobe
continuing smoothly from 1901.
Using WMGlobe at high speed through a LAN may induce some load on the net.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 202 B

BIN
wmglobe/wmgmap.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB