diff --git a/wmglobe/CHANGES b/wmglobe/CHANGES index 4f9d4d5..79f8f5f 100644 --- a/wmglobe/CHANGES +++ b/wmglobe/CHANGES @@ -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) @@ -11,7 +34,7 @@ VMGlobe - option selection through parameters screens (right button) - approximation of date & time of view point - new default map (bigger, better) - - display of time uses setlocale() + - display of time uses setlocale() - option -dawn value : enhance dawn borderline - option -time : change date displayed - option -nonimap @@ -20,16 +43,16 @@ VMGlobe - modify comportment of -rand option when zooming - change left button comportment : only change longitude - shift+left button : change longitude & latitude - - man page + - 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 @@ -39,7 +62,7 @@ VMGlobe left click = change longitude middle click = zoom in / zoom out right click = change latitude - - a few hints for compile on *BSD + - a few hints for compile on *BSD 0.1 released 31/12/98 diff --git a/wmglobe/Makefile b/wmglobe/Makefile index 17dd01d..b619240 100644 --- a/wmglobe/Makefile +++ b/wmglobe/Makefile @@ -2,7 +2,7 @@ INC = -I/usr/X11R6/include LIBS = -lXext -lX11 -lm -L/usr/X11R6/lib \ -ltiff -lXpm -lpng -lz -ljpeg -lungif -lwraster OBJS = src/wmglobe.o src/rend.o src/wmgutil.o \ - src/sunpos.o src/myconvert.o src/mycontext.o + src/sunpos.o src/myconvert.o src/mycontext.o .c.o : @@ -12,11 +12,11 @@ all: wmglobe clean: rm -f src/*.o wmglobe - + wmglobe : $(OBJS) gcc -O2 -Wall $(OBJS) -o wmglobe $(LIBS) - strip wmglobe + strip wmglobe -install : +install : install wmglobe /usr/local/bin install wmglobe.1 /usr/local/man/man1 diff --git a/wmglobe/README b/wmglobe/README index 05b883c..03b40d7 100644 --- a/wmglobe/README +++ b/wmglobe/README @@ -1,5 +1,5 @@ -WMGlobe 0.5 - The Whole Earth spinning on you desktop... as a dockable app -Copyright (C) 1998,99 Jerome Dumonteil +WMGlobe 1.3 - The Whole Earth spinning on you desktop... as a dockable app +Copyright (C) 1998,99,2000,01 Jerome Dumonteil This program is licensed under the terms of the GNU GPL, see below. @@ -10,90 +10,98 @@ 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... 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 +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 :-) - - - tar -xvzf wmglobe-0.5.tar.gz - cd wmglobe-0.5 +Warning : this version won't work with WindowMaker < 0.62 + + 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 + + then move wmglobe in /usr/local/bin and man page somewhere or do (as root) : make install -If it doesn't work, look for the graphic libraries. +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 +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 +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. compile time problems : -Xlib.h, Xpm.h ... : -If you compile wmglobe on a computer installed with packages (.rpm), you may +Xlib.h, Xpm.h ... : +If you compile wmglobe on a computer installed with packages (.rpm), you may lack of these header files. Just install the "xxx-dev.rpm" packages for XFree86 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 -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 +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 +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 +graphic libs : +you can use libgif or libungif. If your version of WindowMaker is built without support for some graphic type, you don't need it (just remove it -from the makefile). -This problem may happen with RedHat 5.2, if you get this kind of message, +from the makefile). +This problem may happen with RedHat 5.2, if you get this kind of message, just add a libtiff to your system : /usr/local/lib/libwraster.so: undefined reference to `TIFFReadDirectory' ... make: *** [wmglobe] Error 1 -compile time options : +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 -#define MOUSE_LAT_FULL +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) -Maps + +Maps ---------------------------------------- -Like XGlobe, WMGlobe needs a longitude/latitude map to work. By default, -it uses a low quality built-in map of earth. But you will probably want +Like XGlobe, WMGlobe needs a longitude/latitude map to work. By default, +it uses a low quality built-in map of earth. But you will probably want to use better ones. You can get maps usable with WMGlobe on the net. See the LINKS chapter. @@ -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. @@ -112,37 +119,42 @@ Configuration options ---------------------------------------- Configuration is done through command line options. - + -v version -h short help -zoom zoom_value Value > 1 to magnify the view, value < 1 to lower. - Default : 1.0 + Default : 1.0 -pos latitude long. Initial viewing fixed at this position, don't follow - the sun rotation. Accepted values in the form - 45°12'36 or 45.21 or 45:12:36 + 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 - PNM, TIFF but none BMP +-map map_file Map used for the rendering. Can be JPEG, GIF, XPM + PNM, TIFF but none BMP Default : use internal map of earth. - + -nimap night_file Map used for the dark side of the earth. Must be of - the same width x height as the day side map. + 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. + a default internal night file (see -nonimap option). + +-defnimap Use the default night map (with a custom map). --nonimap Don't use the default night map. +-nonimap Don't use the default night map. --delay seconds Time in seconds between each calculation of a new +-delay seconds Time in seconds between each calculation of a new position. Limited to 0.04 at compile time (25 frames - per second should be enough). The sun position move + per second should be enough). The sun position move only once per minute, so if you use wmglobe without -dlong or -accel option, the CPU cost of WMGlobe is *very* low. The use of very low value for -delay plus @@ -150,29 +162,29 @@ Configuration is done through command line options. Default : 1.0 sec. -dlat delta_latitude Move the point of view by delta_lat degrees per second, - with a value of 6 the earth make a full rotation in + with a value of 6 the earth make a full rotation in one minute. The value can be formated as -pos option. Default : 0°0'0 - --dlong delta_long Move the point of view by delta_long degrees per - second. With a value of -0°0'15" the earth make a full - rotation in 24 hours toward the west. By default, + +-dlong delta_long Move the point of view by delta_long degrees per + second. With a value of -0°0'15" the earth make a full + rotation in 24 hours toward the west. By default, -dlong and -dlat are null. If they are used, the view follow their values. Going back to "follow sun" mode in parameters screen put -dlat and -dlong to zero. -light light_value Level of light of the dark side when there is no - night map, from 0 to 1. - Default : 0.25 + night map, from 0 to 1. + Default : 0.25 -dawn dawn_value Level of continuity for dawn limit, from 0 to 1. With a value of 1, the border line between night and day is at maximum contrast. Default : 0.2 --bord border_num 0 1 or 2. There are 3 different borders for the icon. +-bord border_num 0 1 or 2. There are 3 different borders for the icon. Default : 0 - + -accel time_multi Time warp factor. With -accel 24, the sun make a full rotation in one hour (or the earth, I'm not sure). Default : 1.0 @@ -183,14 +195,22 @@ 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) +-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 +-w -shape Useless, since it is set by default (WMaker dockable application) mouse : @@ -203,13 +223,13 @@ right button Displays 7 screens of parameters. On every screen, just clic with left or right button on the figures to change their value. The TIME screen shows an approximation of date and time of the earth zone currently displayed, - using GMT time + longitude offset, it's close to the - real local time by one or two hours. Others options + using GMT time + longitude offset, it's close to the + real local time by one or two hours. Others options don't need more help. Intuitive they said... + - -Links : Some sites dealing with WindowMaker +Links : Some sites dealing with WindowMaker ------------------------------------------- Official Window Maker Website : @@ -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 : @@ -254,7 +274,7 @@ Livingearth Inc. has some nice (day and night) images on their web pages. With these you can test the -nightmap option of XEarth. Unfortunately they are pretty low-res (400x200). You can find a higher-resolution (but heavily compressed) version of this -day map at the "Earth View" page: +day map at the "Earth View" page: http://www.fourmilab.ch/cgi-bin/uncgi/Earth @@ -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,29 +306,33 @@ 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. - WMGlobe hopes that an overflow of a long integer dont generate an error - and that LONG_MAX +1 = LONG_MIN . This happens with high values of -accel + 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 +Original idea, tests, logos : Sylvestre Taburet + +WindowMaker 0.62 fix : Charles G Waldman 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 @@ -335,15 +361,15 @@ The code in 'sunpos.cpp' is taken from Xearth by Kirk Lauritz Johnson. The rendering engine is taken from XGlobe by Thorsten Scheuermann XGlobe Homepage: http://www.uni-karlsruhe.de/~uddn/xglobe -Raster graphics library by Alfredo K. Kojima, & stuff of Window Maker +Raster graphics library by Alfredo K. Kojima, & stuff of Window Maker by A. K. Kojima, Dan Pascu, Matthew Hawkins & team Feedback ---------------------------------------- -For your questions, bugs, remarks, please contact our representative on -planet Earth : jerome dumonteil +For your questions, bugs, remarks, please contact our representative on +planet Earth : jerome dumonteil diff --git a/wmglobe/puzzle.sh b/wmglobe/puzzle.sh index 2790ae8..c0b4a7b 100755 --- a/wmglobe/puzzle.sh +++ b/wmglobe/puzzle.sh @@ -1,17 +1,17 @@ #!/bin/sh #just for the fun, solve the puzzle and put it on the clip :) -if [ -x ./wmglobe ] +if [ -x ./wmglobe ] then WMG="nice ./wmglobe" 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 & diff --git a/wmglobe/src/mycontext.c b/wmglobe/src/mycontext.c index 8479d34..60068d5 100644 --- a/wmglobe/src/mycontext.c +++ b/wmglobe/src/mycontext.c @@ -1,22 +1,22 @@ -/* 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 : */ /* context.c - X context management * Raster graphics library - * + * * Copyright (c) 1997 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. @@ -31,526 +31,541 @@ * #include * #include * #include - * + * * #include * #include * #include * #include - * + * * #include - * + * * #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; } diff --git a/wmglobe/src/myconvert.c b/wmglobe/src/myconvert.c index d75878a..8a057cf 100644 --- a/wmglobe/src/myconvert.c +++ b/wmglobe/src/myconvert.c @@ -1,4 +1,4 @@ -/* WMGlobe 0.5 - All the Earth on a WMaker Icon +/* WMGlobe 1.3 - All the Earth on a WMaker Icon * myconvert.c - an adaptation of wrlib for use in wmglobe * initial source taken in WindowMaker-0.20.3/wrlib : */ @@ -6,32 +6,29 @@ /* convert.c - convert RImage to Pixmap * Raster graphics library * - * Copyright (c) 1997 Alfredo K. Kojima + * Copyright (c) 1997 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. */ -/* - * #include - */ #include "wmglobe.h" typedef struct RConversionTable { - unsigned short table[256]; - unsigned short index; - struct RConversionTable *next; + unsigned short table[256]; + unsigned short index; + struct RConversionTable *next; } RConversionTable; @@ -43,527 +40,538 @@ static RXImage *ximgok; void initmyconvert() { - pif[0] = (RConversionTable *) malloc(sizeof(RConversionTable)); - pif[1] = (RConversionTable *) malloc(sizeof(RConversionTable)); - pif[2] = (RConversionTable *) malloc(sizeof(RConversionTable)); - re = (short *) malloc((DIAMETRE + 2) * sizeof(short)); - ge = (short *) malloc((DIAMETRE + 2) * sizeof(short)); - be = (short *) malloc((DIAMETRE + 2) * sizeof(short)); - nre = (short *) malloc((DIAMETRE + 2) * sizeof(short)); - nge = (short *) malloc((DIAMETRE + 2) * sizeof(short)); - nbe = (short *) malloc((DIAMETRE + 2) * sizeof(short)); - ximgok = NULL; - return; + pif[0] = (RConversionTable *) malloc(sizeof(RConversionTable)); + pif[1] = (RConversionTable *) malloc(sizeof(RConversionTable)); + pif[2] = (RConversionTable *) malloc(sizeof(RConversionTable)); + re = (short *) malloc((DIAMETRE + 2) * sizeof(short)); + ge = (short *) malloc((DIAMETRE + 2) * sizeof(short)); + be = (short *) malloc((DIAMETRE + 2) * sizeof(short)); + nre = (short *) malloc((DIAMETRE + 2) * sizeof(short)); + nge = (short *) malloc((DIAMETRE + 2) * sizeof(short)); + nbe = (short *) malloc((DIAMETRE + 2) * sizeof(short)); + ximgok = NULL; + return; } -static unsigned short * - computeTable(unsigned short mask, int hop) +static unsigned short *computeTable(unsigned short mask, int hop) { - RConversionTable *tmp = conversionTable; - int i; + RConversionTable *tmp = conversionTable; + int i; - tmp = pif[hop]; + tmp = pif[hop]; - for (i = 0; i < 256; i++) - tmp->table[i] = (i * mask + 0x7f) / 0xff; + for (i = 0; i < 256; i++) + tmp->table[i] = (i * mask + 0x7f) / 0xff; - tmp->index = mask; - return tmp->table; + tmp->index = mask; + return tmp->table; } -static RXImage * - image2TrueColor(RContext * ctx, RImage * image) +static RXImage *image2TrueColor(RContext * ctx, RImage * image) { - RXImage *ximg; - register int x, y, r, g, b; - unsigned char *red, *grn, *blu; - unsigned long pixel; - unsigned short rmask, gmask, bmask; - unsigned short roffs, goffs, boffs; - unsigned short *rtable, *gtable, *btable; - int ofs; + RXImage *ximg; + register int x, y, r, g, b; + unsigned char *red, *grn, *blu; + unsigned long pixel; + unsigned short rmask, gmask, bmask; + unsigned short roffs, goffs, boffs; + unsigned short *rtable, *gtable, *btable; + int ofs; - if (ximgok == NULL) - ximgok = RCreateXImage(ctx, ctx->depth, image->width, image->height); + if (ximgok == NULL) + ximgok = + RCreateXImage(ctx, ctx->depth, image->width, image->height); - ximg = ximgok; - if (!ximg) { - puts("err "); - return NULL; - } - red = image->data[0]; - grn = image->data[1]; - blu = image->data[2]; + ximg = ximgok; + if (!ximg) { + puts("err "); + return NULL; + } + + red = image->data; + grn = image->data + 1; + blu = image->data + 2; + + roffs = ctx->red_offset; + goffs = ctx->green_offset; + boffs = ctx->blue_offset; - roffs = ctx->red_offset; - goffs = ctx->green_offset; - boffs = ctx->blue_offset; - - rmask = ctx->visual->red_mask >> roffs; - gmask = ctx->visual->green_mask >> goffs; - bmask = ctx->visual->blue_mask >> boffs; + rmask = ctx->visual->red_mask >> roffs; + gmask = ctx->visual->green_mask >> goffs; + bmask = ctx->visual->blue_mask >> boffs; - rtable = computeTable(rmask, 0); - gtable = computeTable(gmask, 1); - btable = computeTable(bmask, 2); + rtable = computeTable(rmask, 0); + gtable = computeTable(gmask, 1); + btable = computeTable(bmask, 2); - if (rtable == NULL || gtable == NULL || btable == NULL) { - RErrorCode = RERR_NOMEMORY; - RDestroyXImage(ctx, ximg); - return NULL; - } - if (ctx->attribs->render_mode == RM_MATCH) { - /* fake match */ + if (rtable == NULL || gtable == NULL || btable == NULL) { + RErrorCode = RERR_NOMEMORY; + RDestroyXImage(ctx, ximg); + return NULL; + } + if (ctx->attribs->render_mode == RBestMatchRendering) { + /* fake match */ #ifdef DEBUG - puts("true color match"); + puts("true color match"); #endif - for (y = 0, ofs = 0; y < image->height; y++) { - for (x = 0; x < image->width; x++, ofs++) { - /* reduce pixel */ - r = rtable[red[ofs]]; - g = gtable[grn[ofs]]; - b = btable[blu[ofs]]; - pixel = (r << roffs) | (g << goffs) | (b << boffs); - XPutPixel(ximg->image, x, y, pixel); - } - } - } else { - /* dither */ - short *rerr, *gerr, *berr; - short *nrerr, *ngerr, *nberr; - short *terr; - int rer, ger, ber; - const int dr = 0xff / rmask; - const int dg = 0xff / gmask; - const int db = 0xff / bmask; - -#ifdef DEBUG - puts("true color dither"); -#endif - rerr = re; - gerr = ge; - berr = be; - nrerr = nre; - ngerr = nge; - nberr = nbe; - - if (!rerr || !gerr || !berr || !nrerr || !ngerr || !nberr) { - RErrorCode = RERR_NOMEMORY; - RDestroyXImage(ctx, ximg); - return NULL; - } - for (x = 0; x < image->width; x++) { - - rerr[x] = red[x]; - gerr[x] = grn[x]; - berr[x] = blu[x]; - } - rerr[x] = gerr[x] = berr[x] = 0; - /* convert and dither the image to XImage */ - for (y = 0, ofs = 0; y < image->height; y++) { - if (y < image->height - 1) { - int x1; - for (x = 0, x1 = ofs + image->width; x < image->width; x++, x1++) { - nrerr[x] = red[x1]; - ngerr[x] = grn[x1]; - nberr[x] = blu[x1]; - } - /* last column */ - x1--; - nrerr[x] = red[x1]; - ngerr[x] = grn[x1]; - nberr[x] = blu[x1]; - } - for (x = 0; x < image->width; x++) { - /* reduce pixel */ - if (rerr[x] > 0xff) - rerr[x] = 0xff; - else if (rerr[x] < 0) - rerr[x] = 0; - if (gerr[x] > 0xff) - gerr[x] = 0xff; - else if (gerr[x] < 0) - gerr[x] = 0; - if (berr[x] > 0xff) - berr[x] = 0xff; - else if (berr[x] < 0) - berr[x] = 0; - - r = rtable[rerr[x]]; - g = gtable[gerr[x]]; - b = btable[berr[x]]; - - pixel = (r << roffs) | (g << goffs) | (b << boffs); - XPutPixel(ximg->image, x, y, pixel); - /* calc error */ - rer = rerr[x] - r * dr; - ger = gerr[x] - g * dg; - ber = berr[x] - b * db; - - /* distribute error */ - r = (rer * 3) / 8; - g = (ger * 3) / 8; - b = (ber * 3) / 8; - /* x+1, y */ - rerr[x + 1] += r; - gerr[x + 1] += g; - berr[x + 1] += b; - /* x, y+1 */ - nrerr[x] += r; - ngerr[x] += g; - nberr[x] += b; - /* x+1, y+1 */ - nrerr[x + 1] += rer - 2 * r; - ngerr[x + 1] += ger - 2 * g; - nberr[x + 1] += ber - 2 * b; - } - ofs += image->width; - /* skip to next line */ - terr = rerr; - rerr = nrerr; - nrerr = terr; - - terr = gerr; - gerr = ngerr; - ngerr = terr; - - terr = berr; - berr = nberr; - nberr = terr; - } + for (y = 0, ofs = 0; y < image->height; y++) { + for (x = 0; x < image->width; x++, ofs += 3) { + /* reduce pixel */ + r = rtable[red[ofs]]; + g = gtable[grn[ofs]]; + b = btable[blu[ofs]]; + pixel = (r << roffs) | (g << goffs) | (b << boffs); + XPutPixel(ximg->image, x, y, pixel); + } } - return ximg; + } else { + /* dither */ + short *rerr, *gerr, *berr; + short *nrerr, *ngerr, *nberr; + short *terr; + int rer, ger, ber; + const int dr = 0xff / rmask; + const int dg = 0xff / gmask; + const int db = 0xff / bmask; + register int x1; + +#ifdef DEBUG + puts("true color dither"); +#endif + rerr = re; + gerr = ge; + berr = be; + nrerr = nre; + ngerr = nge; + nberr = nbe; + + if (!rerr || !gerr || !berr || !nrerr || !ngerr || !nberr) { + RErrorCode = RERR_NOMEMORY; + RDestroyXImage(ctx, ximg); + return NULL; + } + for (x = x1 = 0; x < image->width; x++, x1 += 3) { + + rerr[x] = red[x1]; + gerr[x] = grn[x1]; + berr[x] = blu[x1]; + } + rerr[x] = gerr[x] = berr[x] = 0; + /* convert and dither the image to XImage */ + for (y = 0, ofs = 0; y < image->height; y++) { + if (y < image->height - 1) { + + for (x = 0, x1 = 3 * (ofs + image->width); x < + image->width; x++, x1 += 3) { + + nrerr[x] = red[x1]; + ngerr[x] = grn[x1]; + nberr[x] = blu[x1]; + } + /* last column */ + x1-=3; + nrerr[x] = red[x1]; + ngerr[x] = grn[x1]; + nberr[x] = blu[x1]; + } + for (x = 0; x < image->width; x++) { + /* reduce pixel */ + if (rerr[x] > 0xff) + rerr[x] = 0xff; + else if (rerr[x] < 0) + rerr[x] = 0; + if (gerr[x] > 0xff) + gerr[x] = 0xff; + else if (gerr[x] < 0) + gerr[x] = 0; + if (berr[x] > 0xff) + berr[x] = 0xff; + else if (berr[x] < 0) + berr[x] = 0; + + r = rtable[rerr[x]]; + g = gtable[gerr[x]]; + b = btable[berr[x]]; + + pixel = (r << roffs) | (g << goffs) | (b << boffs); + XPutPixel(ximg->image, x, y, pixel); + /* calc error */ + rer = rerr[x] - r * dr; + ger = gerr[x] - g * dg; + ber = berr[x] - b * db; + + /* distribute error */ + r = (rer * 3) / 8; + g = (ger * 3) / 8; + b = (ber * 3) / 8; + /* x+1, y */ + rerr[x + 1] += r; + gerr[x + 1] += g; + berr[x + 1] += b; + /* x, y+1 */ + nrerr[x] += r; + ngerr[x] += g; + nberr[x] += b; + /* x+1, y+1 */ + nrerr[x + 1] += rer - 2 * r; + ngerr[x + 1] += ger - 2 * g; + nberr[x + 1] += ber - 2 * b; + } + ofs += image->width; + /* skip to next line */ + terr = rerr; + rerr = nrerr; + nrerr = terr; + + terr = gerr; + gerr = ngerr; + ngerr = terr; + + terr = berr; + berr = nberr; + nberr = terr; + } + } + return ximg; } -static RXImage * - image2PseudoColor(RContext * ctx, RImage * image) +static RXImage *image2PseudoColor(RContext * ctx, RImage * image) { - RXImage *ximg; - register int x, y, r, g, b; - unsigned char *red, *grn, *blu; - unsigned long pixel; - const int cpc = ctx->attribs->colors_per_channel; - const unsigned short rmask = cpc - 1; /* different sizes could be used */ - const unsigned short gmask = rmask; /* for r,g,b */ - const unsigned short bmask = rmask; - unsigned short *rtable, *gtable, *btable; - const int cpccpc = cpc * cpc; - unsigned char *data; - int ofs; - /*register unsigned char maxrgb = 0xff; */ + RXImage *ximg; + register int x, y, r, g, b; + unsigned char *red, *grn, *blu; + unsigned long pixel; + const int cpc = ctx->attribs->colors_per_channel; + const unsigned short rmask = cpc - 1; /* different sizes could be used */ + const unsigned short gmask = rmask; /* for r,g,b */ + const unsigned short bmask = rmask; + unsigned short *rtable, *gtable, *btable; + const int cpccpc = cpc * cpc; + unsigned char *data; + int ofs; + /*register unsigned char maxrgb = 0xff; */ - if (ximgok == NULL) - ximgok = RCreateXImage(ctx, ctx->depth, image->width, image->height); + if (ximgok == NULL) + ximgok = + RCreateXImage(ctx, ctx->depth, image->width, image->height); - ximg = ximgok; + ximg = ximgok; - if (!ximg) { - puts("err psc"); - return NULL; - } - red = image->data[0]; - grn = image->data[1]; - blu = image->data[2]; + if (!ximg) { + puts("err psc"); + return NULL; + } + red = image->data; + grn = image->data + 1; + blu = image->data + 2; - data = ximg->image->data; + data = ximg->image->data; - /* Tables are same at the moment because rmask==gmask==bmask. */ - rtable = computeTable(rmask, 0); - gtable = computeTable(gmask, 1); - btable = computeTable(bmask, 2); + /* Tables are same at the moment because rmask==gmask==bmask. */ + rtable = computeTable(rmask, 0); + gtable = computeTable(gmask, 1); + btable = computeTable(bmask, 2); - if (rtable == NULL || gtable == NULL || btable == NULL) { - RErrorCode = RERR_NOMEMORY; - RDestroyXImage(ctx, ximg); - return NULL; - } - if (ctx->attribs->render_mode == RM_MATCH) { - /* fake match */ + if (rtable == NULL || gtable == NULL || btable == NULL) { + RErrorCode = RERR_NOMEMORY; + RDestroyXImage(ctx, ximg); + return NULL; + } + if (ctx->attribs->render_mode == RBestMatchRendering) { + /* fake match */ #ifdef DEBUG - printf("pseudo color match with %d colors per channel\n", cpc); + printf("pseudo color match with %d colors per channel\n", cpc); #endif - for (y = 0, ofs = 0; y < image->height; y++) { - for (x = 0; x < image->width; x++, ofs++) { - /* reduce pixel */ - r = rtable[red[ofs]]; - g = gtable[grn[ofs]]; - b = btable[blu[ofs]]; - pixel = r * cpccpc + g * cpc + b; - /*data[ofs] = ctx->colors[pixel].pixel; */ - XPutPixel(ximg->image, x, y, ctx->colors[pixel].pixel); - } - } - } else { - /* dither */ - short *rerr, *gerr, *berr; - short *nrerr, *ngerr, *nberr; - short *terr; - int rer, ger, ber; - const int dr = 0xff / rmask; - const int dg = 0xff / gmask; - const int db = 0xff / bmask; - -#ifdef DEBUG - printf("pseudo color dithering with %d colors per channel\n", cpc); -#endif - rerr = re; - gerr = ge; - berr = be; - nrerr = nre; - ngerr = nge; - nberr = nbe; - if (!rerr || !gerr || !berr || !nrerr || !ngerr || !nberr) { - RErrorCode = RERR_NOMEMORY; - RDestroyXImage(ctx, ximg); - return NULL; - } - for (x = 0; x < image->width; x++) { - rerr[x] = red[x]; - gerr[x] = grn[x]; - berr[x] = blu[x]; - } - rerr[x] = gerr[x] = berr[x] = 0; - /* convert and dither the image to XImage */ - for (y = 0, ofs = 0; y < image->height; y++) { - if (y < image->height - 1) { - int x1; - for (x = 0, x1 = ofs + image->width; x < image->width; x++, x1++) { - nrerr[x] = red[x1]; - ngerr[x] = grn[x1]; - nberr[x] = blu[x1]; - } - /* last column */ - x1--; - nrerr[x] = red[x1]; - ngerr[x] = grn[x1]; - nberr[x] = blu[x1]; - } - for (x = 0; x < image->width; x++, ofs++) { - /* reduce pixel */ - if (rerr[x] > 0xff) - rerr[x] = 0xff; - else if (rerr[x] < 0) - rerr[x] = 0; - if (gerr[x] > 0xff) - gerr[x] = 0xff; - else if (gerr[x] < 0) - gerr[x] = 0; - if (berr[x] > 0xff) - berr[x] = 0xff; - else if (berr[x] < 0) - berr[x] = 0; - - r = rtable[rerr[x]]; - g = gtable[gerr[x]]; - b = btable[berr[x]]; - - pixel = r * cpccpc + g * cpc + b; - /*data[ofs] = ctx->colors[pixel].pixel; */ - XPutPixel(ximg->image, x, y, ctx->colors[pixel].pixel); - - /* calc error */ - rer = rerr[x] - r * dr; - ger = gerr[x] - g * dg; - ber = berr[x] - b * db; - - /* distribute error */ - rerr[x + 1] += (rer * 7) / 16; - gerr[x + 1] += (ger * 7) / 16; - berr[x + 1] += (ber * 7) / 16; - - nrerr[x] += (rer * 5) / 16; - ngerr[x] += (ger * 5) / 16; - nberr[x] += (ber * 5) / 16; - - if (x > 0) { - nrerr[x - 1] += (rer * 3) / 16; - ngerr[x - 1] += (ger * 3) / 16; - nberr[x - 1] += (ber * 3) / 16; - } - nrerr[x + 1] += rer / 16; - ngerr[x + 1] += ger / 16; - nberr[x + 1] += ber / 16; - } - /* skip to next line */ - terr = rerr; - rerr = nrerr; - nrerr = terr; - - terr = gerr; - gerr = ngerr; - ngerr = terr; - - terr = berr; - berr = nberr; - nberr = terr; - } + for (y = 0, ofs = 0; y < image->height; y++) { + for (x = 0; x < image->width; x++, ofs += 3) { + /* reduce pixel */ + r = rtable[red[ofs]]; + g = gtable[grn[ofs]]; + b = btable[blu[ofs]]; + pixel = r * cpccpc + g * cpc + b; + /*data[ofs] = ctx->colors[pixel].pixel; */ + XPutPixel(ximg->image, x, y, ctx->colors[pixel].pixel); + } } - ximg->image->data = (char *) data; + } else { + /* dither */ + short *rerr, *gerr, *berr; + short *nrerr, *ngerr, *nberr; + short *terr; + int rer, ger, ber; + const int dr = 0xff / rmask; + const int dg = 0xff / gmask; + const int db = 0xff / bmask; + register int x1; + +#ifdef DEBUG + printf("pseudo color dithering with %d colors per channel\n", cpc); +#endif + rerr = re; + gerr = ge; + berr = be; + nrerr = nre; + ngerr = nge; + nberr = nbe; + if (!rerr || !gerr || !berr || !nrerr || !ngerr || !nberr) { + RErrorCode = RERR_NOMEMORY; + RDestroyXImage(ctx, ximg); + return NULL; + } + for (x = x1 = 0; x < image->width; x++, x1+=3) { + rerr[x] = red[x1]; + gerr[x] = grn[x1]; + berr[x] = blu[x1]; + } + rerr[x] = gerr[x] = berr[x] = 0; + /* convert and dither the image to XImage */ + for (y = 0, ofs = 0; y < image->height; y++) { + if (y < image->height - 1) { + int x1; + for (x = 0, x1 = 3*(ofs + image->width); x < + image->width; x++, x1 += 3) { + nrerr[x] = red[x1]; + ngerr[x] = grn[x1]; + nberr[x] = blu[x1]; + } + /* last column */ + x1-=3; + nrerr[x] = red[x1]; + ngerr[x] = grn[x1]; + nberr[x] = blu[x1]; + } + for (x = 0; x < image->width; x++, ofs++) { + /* reduce pixel */ + if (rerr[x] > 0xff) + rerr[x] = 0xff; + else if (rerr[x] < 0) + rerr[x] = 0; + if (gerr[x] > 0xff) + gerr[x] = 0xff; + else if (gerr[x] < 0) + gerr[x] = 0; + if (berr[x] > 0xff) + berr[x] = 0xff; + else if (berr[x] < 0) + berr[x] = 0; - return ximg; + r = rtable[rerr[x]]; + g = gtable[gerr[x]]; + b = btable[berr[x]]; + + pixel = r * cpccpc + g * cpc + b; + /*data[ofs] = ctx->colors[pixel].pixel; */ + XPutPixel(ximg->image, x, y, ctx->colors[pixel].pixel); + + /* calc error */ + rer = rerr[x] - r * dr; + ger = gerr[x] - g * dg; + ber = berr[x] - b * db; + + /* distribute error */ + rerr[x + 1] += (rer * 7) / 16; + gerr[x + 1] += (ger * 7) / 16; + berr[x + 1] += (ber * 7) / 16; + + nrerr[x] += (rer * 5) / 16; + ngerr[x] += (ger * 5) / 16; + nberr[x] += (ber * 5) / 16; + + if (x > 0) { + nrerr[x - 1] += (rer * 3) / 16; + ngerr[x - 1] += (ger * 3) / 16; + nberr[x - 1] += (ber * 3) / 16; + } + nrerr[x + 1] += rer / 16; + ngerr[x + 1] += ger / 16; + nberr[x + 1] += ber / 16; + } + /* skip to next line */ + terr = rerr; + rerr = nrerr; + nrerr = terr; + + terr = gerr; + gerr = ngerr; + ngerr = terr; + + terr = berr; + berr = nberr; + nberr = terr; + } + } + ximg->image->data = (char *) data; + + return ximg; } -static RXImage * - image2GrayScale(RContext * ctx, RImage * image) +static RXImage *image2GrayScale(RContext * ctx, RImage * image) { - RXImage *ximg; - register int x, y, g; - unsigned char *red, *grn, *blu; - const int cpc = ctx->attribs->colors_per_channel; - unsigned short gmask; - unsigned short *table; - unsigned char *data; - int ofs; - /*register unsigned char maxrgb = 0xff; */ + RXImage *ximg; + register int x, y, g; + unsigned char *red, *grn, *blu; + const int cpc = ctx->attribs->colors_per_channel; + unsigned short gmask; + unsigned short *table; + unsigned char *data; + int ofs; + /*register unsigned char maxrgb = 0xff; */ - if (ximgok == NULL) - ximgok = RCreateXImage(ctx, ctx->depth, image->width, image->height); + if (ximgok == NULL) + ximgok = + RCreateXImage(ctx, ctx->depth, image->width, image->height); - ximg = ximgok; + ximg = ximgok; - if (!ximg) { - puts("error!"); - return NULL; - } - red = image->data[0]; - grn = image->data[1]; - blu = image->data[2]; + if (!ximg) { + puts("error!"); + return NULL; + } + red = image->data; + grn = image->data + 1; + blu = image->data + 2; - data = ximg->image->data; + data = ximg->image->data; - if (ctx->vclass == StaticGray) - gmask = (1 << ctx->depth) - 1; /* use all grays */ - else - gmask = cpc * cpc * cpc - 1; + if (ctx->vclass == StaticGray) + gmask = (1 << ctx->depth) - 1; /* use all grays */ + else + gmask = cpc * cpc * cpc - 1; - table = computeTable(gmask, 0); + table = computeTable(gmask, 0); - if (table == NULL) { - RErrorCode = RERR_NOMEMORY; - RDestroyXImage(ctx, ximg); - return NULL; - } - if (ctx->attribs->render_mode == RM_MATCH) { - /* fake match */ + if (table == NULL) { + RErrorCode = RERR_NOMEMORY; + RDestroyXImage(ctx, ximg); + return NULL; + } + if (ctx->attribs->render_mode == RBestMatchRendering) { + /* fake match */ #ifdef DEBUG - printf("grayscale match with %d colors per channel\n", cpc); + printf("grayscale match with %d colors per channel\n", cpc); #endif - for (y = 0, ofs = 0; y < image->height; y++) { - for (x = 0; x < image->width; x++, ofs++) { - /* reduce pixel */ - g = table[(red[ofs] * 30 + grn[ofs] * 59 + blu[ofs] * 11) / 100]; + for (y = 0, ofs = 0; y < image->height; y++) { + for (x = 0; x < image->width; x++, ofs++) { + /* reduce pixel */ + g = + table[(red[ofs] * 30 + grn[ofs] * 59 + blu[ofs] * 11) / + 100]; - /*data[ofs] = ctx->colors[g].pixel; */ - XPutPixel(ximg->image, x, y, ctx->colors[g].pixel); - } - } - } else { - /* dither */ - short *gerr; - short *ngerr; - short *terr; - int ger; - const int dg = 0xff / gmask; + /*data[ofs] = ctx->colors[g].pixel; */ + XPutPixel(ximg->image, x, y, ctx->colors[g].pixel); + } + } + } else { + /* dither */ + short *gerr; + short *ngerr; + short *terr; + int ger; + const int dg = 0xff / gmask; #ifdef DEBUG - printf("grayscale dither with %d colors per channel\n", cpc); + printf("grayscale dither with %d colors per channel\n", cpc); #endif - gerr = ge; - ngerr = nge; - if (!gerr || !ngerr) { - RErrorCode = RERR_NOMEMORY; - RDestroyXImage(ctx, ximg); - return NULL; - } - for (x = 0; x < image->width; x++) { - gerr[x] = (red[x] * 30 + grn[x] * 59 + blu[x] * 11) / 100; - } - gerr[x] = 0; - /* convert and dither the image to XImage */ - for (y = 0, ofs = 0; y < image->height; y++) { - if (y < image->height - 1) { - int x1; - for (x = 0, x1 = ofs + image->width; x < image->width; x++, x1++) { - ngerr[x] = (red[x1] * 30 + grn[x1] * 59 + blu[x1] * 11) / 100; - } - /* last column */ - x1--; - ngerr[x] = (red[x1] * 30 + grn[x1] * 59 + blu[x1] * 11) / 100; - } - for (x = 0; x < image->width; x++, ofs++) { - /* reduce pixel */ - if (gerr[x] > 0xff) - gerr[x] = 0xff; - else if (gerr[x] < 0) - gerr[x] = 0; - - g = table[gerr[x]]; - - /*data[ofs] = ctx->colors[g].pixel; */ - XPutPixel(ximg->image, x, y, ctx->colors[g].pixel); - /* calc error */ - ger = gerr[x] - g * dg; - - /* distribute error */ - g = (ger * 3) / 8; - /* x+1, y */ - gerr[x + 1] += g; - /* x, y+1 */ - ngerr[x] += g; - /* x+1, y+1 */ - ngerr[x + 1] += ger - 2 * g; - } - /* skip to next line */ - terr = gerr; - gerr = ngerr; - ngerr = terr; - } + gerr = ge; + ngerr = nge; + if (!gerr || !ngerr) { + RErrorCode = RERR_NOMEMORY; + RDestroyXImage(ctx, ximg); + return NULL; } - ximg->image->data = (char *) data; + for (x = 0; x < image->width; x++) { + gerr[x] = (red[x] * 30 + grn[x] * 59 + blu[x] * 11) / 100; + } + gerr[x] = 0; + /* convert and dither the image to XImage */ + for (y = 0, ofs = 0; y < image->height; y++) { + if (y < image->height - 1) { + int x1; + for (x = 0, x1 = ofs + image->width; x < image->width; + x++, x1++) { + ngerr[x] = + (red[x1] * 30 + grn[x1] * 59 + blu[x1] * 11) / 100; + } + /* last column */ + x1--; + ngerr[x] = + (red[x1] * 30 + grn[x1] * 59 + blu[x1] * 11) / 100; + } + for (x = 0; x < image->width; x++, ofs++) { + /* reduce pixel */ + if (gerr[x] > 0xff) + gerr[x] = 0xff; + else if (gerr[x] < 0) + gerr[x] = 0; - return ximg; + g = table[gerr[x]]; + + /*data[ofs] = ctx->colors[g].pixel; */ + XPutPixel(ximg->image, x, y, ctx->colors[g].pixel); + /* calc error */ + ger = gerr[x] - g * dg; + + /* distribute error */ + g = (ger * 3) / 8; + /* x+1, y */ + gerr[x + 1] += g; + /* x, y+1 */ + ngerr[x] += g; + /* x+1, y+1 */ + ngerr[x + 1] += ger - 2 * g; + } + /* skip to next line */ + terr = gerr; + gerr = ngerr; + ngerr = terr; + } + } + ximg->image->data = (char *) data; + + return ximg; } int myRConvertImage(RContext * context, RImage * image, Pixmap * pixmap) { - RXImage *ximg = NULL; + RXImage *ximg = NULL; - assert(context != NULL); - assert(image != NULL); - assert(pixmap != NULL); + assert(context != NULL); + assert(image != NULL); + assert(pixmap != NULL); - /* clear error message */ - if (context->vclass == TrueColor) - ximg = image2TrueColor(context, image); - else if (context->vclass == PseudoColor || context->vclass == StaticColor) - ximg = image2PseudoColor(context, image); - else if (context->vclass == GrayScale || context->vclass == StaticGray) - ximg = image2GrayScale(context, image); + /* clear error message */ + if (context->vclass == TrueColor) + ximg = image2TrueColor(context, image); + else if (context->vclass == PseudoColor + || context->vclass == StaticColor) ximg = + image2PseudoColor(context, image); + else if (context->vclass == GrayScale || context->vclass == StaticGray) + ximg = image2GrayScale(context, image); - if (!ximg) { + if (!ximg) { #ifdef C_ALLOCA - alloca(0); + alloca(0); #endif - return False; - } + return False; + } /* * *pixmap = XCreatePixmap(context->dpy, context->drawable, image->width, * image->height, context->depth); */ - RPutXImage(context, *pixmap, context->copy_gc, ximg, 0, 0, 0, 0, - image->width, image->height); + RPutXImage(context, *pixmap, context->copy_gc, ximg, 0, 0, 0, 0, + image->width, image->height); /* @@ -572,7 +580,7 @@ int myRConvertImage(RContext * context, RImage * image, Pixmap * pixmap) #ifdef C_ALLOCA - alloca(0); + alloca(0); #endif - return True; + return True; } diff --git a/wmglobe/src/rend.c b/wmglobe/src/rend.c index c11f322..215a9da 100644 --- a/wmglobe/src/rend.c +++ b/wmglobe/src/rend.c @@ -1,25 +1,23 @@ -/* WMGlobe 0.5 - All the Earth on a WMaker Icon - * copyright (C) 1998,99 Jerome Dumonteil - * +/* WMGlobe 1.3 - All the Earth on a WMaker Icon + * copyright (C) 1998,99,2000,01 Jerome Dumonteil + * * 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program 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 General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ***************************************************************************/ -/* this code is based on XGlobe : - +/* this code was based on XGlobe : renderer.cpp - * - * + * * This file is part of XGlobe. See README for details. * * Copyright (C) 1998 Thorsten Scheuermann @@ -27,13 +25,16 @@ * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public Licenses as published by * the Free Software Foundation. - *************************************************************************** */ - + ************************************************************************/ +/* + Some parts of this files should be rewritten to not depend on + WindowMaker version +*/ #include "wmglobe.h" static RColor mygetMapColorLinear - (double longitude, double latitude, double angle); + (double longitude, double latitude, double angle); /* * static RColor getMapColor(double longitude, double latitude, double angle); @@ -42,75 +43,222 @@ static RColor mygetMapColorLinear static void randomPosition(); void setViewPos(double lat, double lon); static void myRPutPixel(int x, int y, RColor * color); -static void getquarter(RImage * image, int x, int y, MPO * m[4], int dx, int dy); +#ifdef WITH_MARKERS +#if (WITH_MARKERS == 1) +static void invertPixel(int x, int y); +static void put_cross(int x, int y); +static void put_dot_cross(int x, int y, RColor * color); +#endif +#endif +static void getquarter(RImage * image, int x, int y, MPO * m[4], int dx, + int dy); static void updateTime(int force); static struct timeval timeaccel(struct timeval t); -/* ------------------------------------------------------------------------ */ + + + + + struct timeval timeaccel(struct timeval t) { - struct timeval at; - double rr; + struct timeval at; + double rr; - t = diftimev(t, tini); - rr = floor((double) t.tv_sec * time_multi + (double) t.tv_usec * time_multi / 1000000.); + t = diftimev(t, tini); + rr = floor((double) t.tv_sec * time_multi + + (double) t.tv_usec * time_multi / 1000000.); /*** something bad may appen if time_multi=max after 41 minutes (overflow) ***/ - while (rr > (double) LONG_MAX) - rr -= (2.0 * (double) LONG_MAX + 1.0); - at.tv_sec = (int) rr; - at.tv_usec = (int) (t.tv_usec * time_multi) % 1000000; - return addtimev(at, tbase); + while (rr > (double) LONG_MAX) + rr -= (2.0 * (double) LONG_MAX + 1.0); + at.tv_sec = (int) rr; + at.tv_usec = (int) (t.tv_usec * time_multi) % 1000000; + return addtimev(at, tbase); } -/* ------------------------------------------------------------------------ */ + + + + + + static void myRPutPixel(int x, int y, RColor * color) { - int ofs; - unsigned char *sr, *sg, *sb; + int ofs; + unsigned char *sr, *sg, *sb; - ofs = y * DIAMETRE + x; - sr = small->data[0] + ofs; - sg = small->data[1] + ofs; - sb = small->data[2] + ofs; + ofs = (y * DIAMETRE + x) * 3; + sr = small->data + (ofs++); + sg = small->data + (ofs++); + sb = small->data + (ofs); - *sr = color->red; - *sg = color->green; - *sb = color->blue; - return; + *sr = color->red; + *sg = color->green; + *sb = color->blue; + return; } -/* ------------------------------------------------------------------------ */ -static void getquarter(RImage * image, int x, int y, MPO * m[4], int dx, int dy) + + + + + + +#if WITH_MARKERS +static void invertPixel(int x, int y) { - int xx; - register int ofs; + int ofs; + unsigned char *sr, *sg, *sb; + + ofs = (y * DIAMETRE + x) * 3; + sr = small->data + (ofs++); + sg = small->data + (ofs++); + sb = small->data + (ofs); + +#if ( CROSS_INVERT == 1 ) + *sr = 255 - *sr; + *sg = 255 - *sg; + *sb = 255 - *sb; +#else + if (*sb > 127 || *sg > 127 || *sr > 127) + *sr = *sg = *sb = 0; + else + *sr = *sg = *sb = 255; +#endif + return; +} + +#define T_CADRE(x,y) ((x) < DIAMETRE && (x) >= 0 \ +&& (y) < DIAMETRE && (y) >= 0 && tabsolu[(x)][(y)]) + + + + + +static void put_cross(int x, int y) +{ + int i, x_cross, y_cross; + + if (T_CADRE(x, y)) { + if (!fun && sens != 1) { + x = DIAMETRE - 1 - x; + y = DIAMETRE - 1 - y; + } + for (i = 2; i <= CROSS_LENGTH; i++) { + x_cross = x + i; + y_cross = y; + if (T_CADRE(x_cross, y_cross)) + invertPixel(x_cross, y_cross); + x_cross = x - i; + + if (T_CADRE(x_cross, y_cross)) + invertPixel(x_cross, y_cross); + x_cross = x; + y_cross = y - i; + if (T_CADRE(x_cross, y_cross)) + invertPixel(x_cross, y_cross); + + y_cross = y + i; + if (T_CADRE(x_cross, y_cross)) + invertPixel(x_cross, y_cross); + } + } +} + + + + + + + + +static void put_dot_cross(int x, int y, RColor * color) +{ + int i, x_cross, y_cross; + + if (T_CADRE(x, y)) { + if (!fun && sens != 1) { + x = DIAMETRE - 1 - x; + y = DIAMETRE - 1 - y; + } + for (i = 2; i <= CROSS_LENGTH; i += 2) { + x_cross = x + i; + y_cross = y; + if (T_CADRE(x_cross, y_cross)) + invertPixel(x_cross, y_cross); + x_cross = x - i; + + if (T_CADRE(x_cross, y_cross)) + invertPixel(x_cross, y_cross); + x_cross = x; + y_cross = y - i; + if (T_CADRE(x_cross, y_cross)) + invertPixel(x_cross, y_cross); + + y_cross = y + i; + if (T_CADRE(x_cross, y_cross)) + invertPixel(x_cross, y_cross); + + x_cross = x + i + 1; + y_cross = y; + if (T_CADRE(x_cross, y_cross)) + myRPutPixel(x_cross, y_cross, color); + x_cross = x - i - 1; + + if (T_CADRE(x_cross, y_cross)) + myRPutPixel(x_cross, y_cross, color); + x_cross = x; + y_cross = y - i - 1; + if (T_CADRE(x_cross, y_cross)) + myRPutPixel(x_cross, y_cross, color); + + y_cross = y + i + 1; + if (T_CADRE(x_cross, y_cross)) + myRPutPixel(x_cross, y_cross, color); + } + } +} +#endif + + + + + + + + +static void getquarter(RImage * image, int x, int y, MPO * m[4], int dx, + int dy) +{ + int xx; + register int ofs; /*** hope this is faster than calculation with floats .... ****/ - x %= image->width; - xx = x; - y %= image->height; - ofs = y * image->width + x; - m[0]->r = image->data[0][ofs]; - m[0]->g = image->data[1][ofs]; - m[0]->b = image->data[2][ofs]; + x %= image->width; + xx = x; + y %= image->height; + ofs = (y * image->width + x) * 3; + m[0]->r = image->data[ofs++]; + m[0]->g = image->data[ofs++]; + m[0]->b = image->data[ofs]; - xx++; - xx %= image->width; - ofs = y * image->width + xx; - m[1]->r = image->data[0][ofs]; - m[1]->g = image->data[1][ofs]; - m[1]->b = image->data[2][ofs]; + xx++; + xx %= image->width; + ofs = (y * image->width + xx) * 3; + m[1]->r = image->data[ofs++]; + m[1]->g = image->data[ofs++]; + m[1]->b = image->data[ofs]; - y++; - y %= image->height; - ofs = y * image->width + x; - m[2]->r = image->data[0][ofs]; - m[2]->g = image->data[1][ofs]; - m[2]->b = image->data[2][ofs]; + y++; + y %= image->height; + ofs = (y * image->width + x) * 3; + m[2]->r = image->data[ofs++]; + m[2]->g = image->data[ofs++]; + m[2]->b = image->data[ofs]; - ofs = y * image->width + xx; - m[3]->r = image->data[0][ofs]; - m[3]->g = image->data[1][ofs]; - m[3]->b = image->data[2][ofs]; + ofs = (y * image->width + xx) * 3; + m[3]->r = image->data[ofs++]; + m[3]->g = image->data[ofs++]; + m[3]->b = image->data[ofs]; /* @@ -128,576 +276,852 @@ static void getquarter(RImage * image, int x, int y, MPO * m[4], int dx, int dy) * (m[3]->b*dx*dy))>>16; */ - if ((ofs = m[1]->r - m[0]->r) != 0) - m[0]->r += (ofs * dx) >> 8; - if ((ofs = m[1]->g - m[0]->g) != 0) - m[0]->g += (ofs * dx) >> 8; - if ((ofs = m[1]->b - m[0]->b) != 0) - m[0]->b += (ofs * dx) >> 8; + if ((ofs = m[1]->r - m[0]->r) != 0) + m[0]->r += (ofs * dx) >> 8; + if ((ofs = m[1]->g - m[0]->g) != 0) + m[0]->g += (ofs * dx) >> 8; + if ((ofs = m[1]->b - m[0]->b) != 0) + m[0]->b += (ofs * dx) >> 8; - if ((ofs = m[3]->r - m[2]->r) != 0) - m[2]->r += (ofs * dx) >> 8; - if ((ofs = m[3]->g - m[2]->g) != 0) - m[2]->g += (ofs * dx) >> 8; - if ((ofs = m[3]->b - m[2]->b) != 0) - m[2]->b += (ofs * dx) >> 8; + if ((ofs = m[3]->r - m[2]->r) != 0) + m[2]->r += (ofs * dx) >> 8; + if ((ofs = m[3]->g - m[2]->g) != 0) + m[2]->g += (ofs * dx) >> 8; + if ((ofs = m[3]->b - m[2]->b) != 0) + m[2]->b += (ofs * dx) >> 8; - if ((ofs = m[2]->r - m[0]->r) != 0) - m[0]->r += (ofs * dy) >> 8; - if ((ofs = m[2]->g - m[0]->g) != 0) - m[0]->g += (ofs * dy) >> 8; - if ((ofs = m[2]->b - m[0]->b) != 0) - m[0]->b += (ofs * dy) >> 8; + if ((ofs = m[2]->r - m[0]->r) != 0) + m[0]->r += (ofs * dy) >> 8; + if ((ofs = m[2]->g - m[0]->g) != 0) + m[0]->g += (ofs * dy) >> 8; + if ((ofs = m[2]->b - m[0]->b) != 0) + m[0]->b += (ofs * dy) >> 8; - return; + return; } -/* ------------------------------------------------------------------------ */ + + + + + + + + + void calcDistance() { - double tan_a; + double tan_a; - tan_a = (zoom * DIAMETRE / 2.0) / proj_dist; + tan_a = (zoom * DIAMETRE / 2.0) / proj_dist; /* * distance of camera to center of earth ( = coordinate origin) */ - center_dist = radius / sin(atan(tan_a)); - c_coef = center_dist * center_dist - radius * radius; - solution = FALSE; - return; + center_dist = radius / sin(atan(tan_a)); + c_coef = center_dist * center_dist - radius * radius; + solution = FALSE; + return; } -/* ------------------------------------------------------------------------ */ + + + + + + + + + void renderFrame() { - int py, px; - RColor teinte; + int py, px; + RColor teinte; - double dir_x, dir_y, dir_z; /* direction of cast ray */ + double dir_x, dir_y, dir_z; /* direction of cast ray */ - double hit_x, hit_y, hit_z; /* hit position on earth surface */ + double hit_x, hit_y, hit_z; /* hit position on earth surface */ - double hit2_x, hit2_y, hit2_z; /* mirrored hit position on earth surface */ + double hit2_x, hit2_y, hit2_z; /* mirrored hit position on earth surface */ - double sp_x, sp_y, sp_z; /* intersection point of globe and ray */ + double sp_x, sp_y, sp_z; /* intersection point of globe and ray */ - double a; /* coeff. of quardatic equation */ + double a; /* coeff. of quardatic equation */ - double radikand; - double wurzel; - double r; /* r' */ + double udroot; /* racine */ + double wurzel; + double r; /* r' */ - double s1, s2, s; /*distance between intersections and + double s1, s2, s; /*distance between intersections and camera position */ - double longitude, latitude; /* coordinates of hit position */ + double longitude, latitude; /* coordinates of hit position */ - double light_angle; /* cosine of angle between sunlight and + double light_angle; /* cosine of angle between sunlight and surface normal */ - int startx, endx; /* the region to be painted */ + int startx, endx; /* the region to be painted */ - int starty, endy; + int starty, endy; - double m11; - double m12; - double m13; - double m21; - double m22; - double m23; - double m31; - double m32; - double m33; + double m11; + double m12; + double m13; + double m21; + double m22; + double m23; + double m31; + double m32; + double m33; - a = dir_x = dir_y = 0; - dir_z = -proj_dist; + a = dir_x = dir_y = 0; + dir_z = -proj_dist; #ifdef DEBUG - fprintf(stdout, "solution : %d\n", solution); + fprintf(stdout, "solution : %d\n", solution); #endif - /* - * clear image - */ - if (solution == FALSE) - RClearImage(small, &noir); + /* + * clear image + */ + if (solution == FALSE) + RClearImage(small, &noir); + /* + * rotation matrix + */ - /* - * rotation matrix - */ + m11 = cos(v_long); + m22 = cos(v_lat); + m23 = sin(v_lat); + m31 = -sin(v_long); + m12 = m23 * m31; + m13 = -m22 * m31; + m21 = 0.; + m32 = -m23 * m11; + m33 = m22 * m11; - m11 = cos(v_long); - m22 = cos(v_lat); - m23 = sin(v_lat); - m31 = -sin(v_long); - m12 = m23 * m31; - m13 = -m22 * m31; - m21 = 0.; - m32 = -m23 * m11; - m33 = m22 * m11; + /* + * calc. radius of projected sphere + */ + if (solution == FALSE) { + b_coef = 2 * center_dist * dir_z; + radius_proj = + (int) sqrt(b_coef * b_coef / (4 * c_coef) - dir_z * dir_z) + 1; + } + + if (fun) { + starty = DIAMETRE / 2 - radius_proj - 3; + endy = DIAMETRE - starty - 1; + if ((double) starty < (double) (-funy)) + starty = -funy; + if ((double) starty > (double) (DIAMETRE - 1 - funy)) + starty = DIAMETRE - 1 - funy; + if ((double) endy < (double) (-funy)) + endy = -funy; + if ((double) endy > (double) (DIAMETRE - 1 - funy)) + endy = DIAMETRE - 1 - funy; - /* - * calc. radius of projected sphere - */ if (solution == FALSE) { - b_coef = 2 * center_dist * dir_z; - radius_proj = (int) sqrt(b_coef * b_coef / (4 * c_coef) - dir_z * dir_z) + 1; + int i, j; + if (starty + funy > 0) + for (j = 0; j < starty + funy; j++) + for (i = 0; i < DIAMETRE; i++) + tabsolu[i][j] = 0; + if (endy + 1 + funy <= DIAMETRE - 1) + for (j = endy + funy + 1; j < DIAMETRE; j++) + for (i = 0; i < DIAMETRE; i++) + tabsolu[i][j] = 0; } -/*-----------------------------------------------------------------------------------------*/ - if (fun) { - starty = DIAMETRE / 2 - radius_proj - 3; - endy = DIAMETRE - starty - 1; - if ((double) starty < (double) (-funy)) - starty = -funy; - if ((double) starty > (double) (DIAMETRE - 1 - funy)) - starty = DIAMETRE - 1 - funy; - if ((double) endy < (double) (-funy)) - endy = -funy; - if ((double) endy > (double) (DIAMETRE - 1 - funy)) - endy = DIAMETRE - 1 - funy; - for (py = starty; py <= endy; py++) { + for (py = starty; py <= endy; py++) { - startx = DIAMETRE / 2 - 6 - - (int) sqrt(radius_proj * radius_proj - - (py - DIAMETRE / 2) * - (py - DIAMETRE / 2)); + startx = DIAMETRE / 2 - 6 - + (int) sqrt(MAX((radius_proj * radius_proj - + (py - DIAMETRE / 2) * + (py - DIAMETRE / 2)), 0.0)); - endx = DIAMETRE - startx - 1; - if ((double) startx < (double) (-funx)) - startx = -funx; + endx = DIAMETRE - startx - 1; + if ((double) startx < (double) (-funx)) + startx = -funx; - if ((double) startx > (double) (DIAMETRE - 1 - funx)) - startx = DIAMETRE - 1 - funx; + if ((double) startx > (double) (DIAMETRE - 1 - funx)) + startx = DIAMETRE - 1 - funx; - if ((double) endx < (double) (-funx)) - endx = -funx; - if ((double) endx > (double) (DIAMETRE - 1 - funx)) - endx = DIAMETRE - 1 - funx; + if ((double) endx < (double) (-funx)) + endx = -funx; + if ((double) endx > (double) (DIAMETRE - 1 - funx)) + endx = DIAMETRE - 1 - funx; - /* - * calculate offset into image data - */ - - for (px = startx; px <= endx; px++) { - - dir_x = (double) px - DIAMETRE / 2 + 0.5; - dir_y = -(double) py + DIAMETRE / 2 - 0.5; - - a = dir_x * dir_x + dir_y * dir_y + dir_z * dir_z; - /* - * c constant, see above - */ - radikand = b_coef * b_coef - 4 * a * c_coef; /*what's under the sq.root when solving the - quadratic equation */ - - if (radikand >= 0.0) { /* solution exists <=> intersection */ - - wurzel = sqrt(radikand); - s1 = (-b_coef + wurzel) / (2. * a); - s2 = (-b_coef - wurzel) / (2. * a); - s = (s1 < s2) ? s1 : s2; /* smaller solution belongs to nearer - * intersection */ + if (solution == FALSE) { + int i; + if (startx + funx > 0) + for (i = 0; i < startx + funx; i++) + tabsolu[i][py + funy] = 0; + if (endx + 1 + funx <= DIAMETRE - 1) + for (i = endx + 1 + funx; i < DIAMETRE; i++) + tabsolu[i][py + funy] = 0; + } - sp_x = s * dir_x; /* sp = camera pos + s*dir */ - sp_y = s * dir_y; - sp_z = center_dist + s * dir_z; + /* + * calculate offset into image data + */ - hit_x = m11 * sp_x + m12 * sp_y + m13 * sp_z; - hit_y = m22 * sp_y + m23 * sp_z; - hit_z = m31 * sp_x + m32 * sp_y + m33 * sp_z; + for (px = startx; px <= endx; px++) { + if (solution == FALSE) { + dir_x = (double) px - DIAMETRE / 2 + 0.5; + dir_y = -(double) py + DIAMETRE / 2 - 0.5; - hit2_x = -m11 * sp_x + m12 * sp_y + m13 * sp_z; - hit2_y = m22 * sp_y + m23 * sp_z; - hit2_z = -m31 * sp_x + m32 * sp_y + m33 * sp_z; + a = dir_x * dir_x + dir_y * dir_y + dir_z * dir_z; + + udroot = b_coef * b_coef - 4 * a * c_coef; /*what's under the + sq.root when solving the quadratic equation */ + if (udroot >= 0) { + tabsolu[px + funx][py + funy] = 1; + wurzel = sqrt(udroot); + s1 = (-b_coef + wurzel) / (2. * a); + s2 = (-b_coef - wurzel) / (2. * a); + s = (s1 < s2) ? s1 : s2; /* smaller solution belongs + to nearer intersection */ + solu[px + funx][py + funy][0] = s * dir_x; + solu[px + funx][py + funy][1] = s * dir_y; + solu[px + funx][py + funy][2] = + center_dist + s * dir_z; + } else { + tabsolu[px + funx][py + funy] = 0; + } + } + + if (tabsolu[px + funx][py + funy]) { /* solution exists <=> + intersection exists */ + sp_x = solu[px + funx][py + funy][0]; /* sp = camera pos + s*dir */ + sp_y = solu[px + funx][py + funy][1]; + sp_z = solu[px + funx][py + funy][2]; + + hit_x = m11 * sp_x + m12 * sp_y + m13 * sp_z; + hit_y = m22 * sp_y + m23 * sp_z; + hit_z = m31 * sp_x + m32 * sp_y + m33 * sp_z; + + hit2_x = -m11 * sp_x + m12 * sp_y + m13 * sp_z; + hit2_y = m22 * sp_y + m23 * sp_z; + hit2_z = -m31 * sp_x + m32 * sp_y + m33 * sp_z; /*** hope hit_z wont get too close to zero *******/ - if (ABS(hit_z) < 0.001) { - if (hit_x * hit_z > 0.) - longitude = PI / 2.; - else - longitude = -PI / 2.; - if (hit_z > 0.) - hit_z = 0.001; - else - hit_z = -0.001; - } else { - longitude = atan(hit_x / hit_z); - } + if (ABS(hit_z) < 0.001) { + if (hit_x * hit_z > 0.) + longitude = PI / 2.; + else + longitude = -PI / 2.; + if (hit_z > 0.) + hit_z = 0.001; + else + hit_z = -0.001; + } else { + longitude = atan(hit_x / hit_z); + } - if (hit_z < 0.) - longitude += PI; + if (hit_z < 0.) + longitude += PI; - r = (double) sqrt(hit_x * hit_x + hit_z * hit_z); + r = (double) sqrt(hit_x * hit_x + hit_z * hit_z); - latitude = atan(-hit_y / r); + latitude = atan(-hit_y / r); - light_angle = - (light_x * hit_x + light_y * hit_y + light_z * hit_z) / radius; + light_angle = + (light_x * hit_x + light_y * hit_y + + light_z * hit_z) / radius; + + /* + * Set pixel in image + */ + + teinte = + mygetMapColorLinear(longitude, latitude, + light_angle); + /* here dont use myRPutPixel since we prefer some + error detection about limits */ + RPutPixel(small, px + funx, py + funy, &teinte); + } + } /*px */ + } /*py */ + + } - /* - * Set pixel in image - */ - teinte = mygetMapColorLinear(longitude, latitude, light_angle); - RPutPixel(small, px + funx, py + funy, &teinte); - } - } /*px */ - } /*py */ - } -/*-----------------------------------------------------------------------------------------*/ /*** not fun : ***/ - else { - starty = DIAMETRE / 2 - radius_proj - 3; - starty = (starty < 0) ? 0 : starty; - endy = DIAMETRE - starty - 1; + else { + starty = DIAMETRE / 2 - radius_proj - 3; + starty = (starty < 0) ? 0 : starty; + endy = DIAMETRE - starty - 1; /* * py 0 to 63 max */ - for (py = starty; py <= endy; py++) { - startx = DIAMETRE / 2 - 6 - - (int) sqrt(radius_proj * radius_proj - - (py - DIAMETRE / 2) * - (py - DIAMETRE / 2)); - startx = (startx < 0) ? 0 : startx; + if (solution == FALSE) { + int i, j; + if (starty > 0) + for (j = 0; j < starty; j++) + for (i = 0; i < DIAMETRE; i++) + tabsolu[i][j] = 0; + if (endy + 1 <= DIAMETRE - 1) + for (j = endy + 1; j < DIAMETRE; j++) + for (i = 0; i < DIAMETRE; i++) + tabsolu[i][j] = 0; + } + + + for (py = starty; py <= endy; py++) { + startx = DIAMETRE / 2 - 6 - + (int) sqrt(MAX((radius_proj * radius_proj - + (py - DIAMETRE / 2) * + (py - DIAMETRE / 2)), 0.0)); + startx = (startx < 0) ? 0 : startx; /* * 0<= startx <=31 */ + if (solution == FALSE) { + int i; + if (startx > 0) + for (i = 0; i < startx; i++) { + tabsolu[i][py] = 0; + tabsolu[DIAMETRE - 1 - i][py] = 0; + } + } - for (px = startx; px < DIAMETRE / 2; px++) { - if (solution == FALSE) { - dir_x = (double) px - DIAMETRE / 2 + 0.5; + for (px = startx; px < DIAMETRE / 2; px++) { + if (solution == FALSE) { + dir_x = (double) px - DIAMETRE / 2 + 0.5; - dir_y = -(double) py + DIAMETRE / 2 - 0.5; + dir_y = -(double) py + DIAMETRE / 2 - 0.5; - a = dir_x * dir_x + dir_y * dir_y + dir_z * dir_z; + a = dir_x * dir_x + dir_y * dir_y + dir_z * dir_z; + /*what's under the sq.root when solving the + quadratic equation */ + udroot = b_coef * b_coef - 4 * a * c_coef; + if (udroot >= 0) { + tabsolu[px][py] = 1; + tabsolu[DIAMETRE - 1 - px][py] = 1; + wurzel = sqrt(udroot); + s1 = (-b_coef + wurzel) / (2. * a); + s2 = (-b_coef - wurzel) / (2. * a); + s = (s1 < s2) ? s1 : s2; /* smaller solution + belongs to nearer + intersection */ + /* sp = camera pos + s*dir */ + solu[px][py][0] = s * dir_x; + solu[px][py][1] = s * dir_y; + solu[px][py][2] = center_dist + s * dir_z; + } else { + tabsolu[px][py] = 0; + tabsolu[DIAMETRE - 1 - px][py] = 0; + } + } + if (tabsolu[px][py]) { /* solution exists <=> + intersection exists */ + sp_x = solu[px][py][0]; + sp_y = solu[px][py][1]; + sp_z = solu[px][py][2]; + hit_x = m11 * sp_x + m12 * sp_y + m13 * sp_z; + hit_y = m22 * sp_y + m23 * sp_z; + hit_z = m31 * sp_x + m32 * sp_y + m33 * sp_z; - soluce[px][py][0] = b_coef * b_coef - 4 * a * c_coef; - /*what's under the sq.root when solving the - quadratic equation */ - - } - if (soluce[px][py][0] >= 0.0) { /* solution exists <=> intersection */ - - if (solution == FALSE) { - wurzel = sqrt(soluce[px][py][0]); - s1 = (-b_coef + wurzel) / (2. * a); - s2 = (-b_coef - wurzel) / (2. * a); - s = (s1 < s2) ? s1 : s2; /* smaller solution belongs to nearer - * intersection */ - - soluce[px][py][1] = s * dir_x; /* sp = camera pos + s*dir */ - soluce[px][py][2] = s * dir_y; - soluce[px][py][3] = center_dist + s * dir_z; - } - sp_x = soluce[px][py][1]; - sp_y = soluce[px][py][2]; - sp_z = soluce[px][py][3]; - hit_x = m11 * sp_x + m12 * sp_y + m13 * sp_z; - hit_y = m22 * sp_y + m23 * sp_z; - hit_z = m31 * sp_x + m32 * sp_y + m33 * sp_z; - - hit2_x = -m11 * sp_x + m12 * sp_y + m13 * sp_z; - hit2_y = m22 * sp_y + m23 * sp_z; - hit2_z = -m31 * sp_x + m32 * sp_y + m33 * sp_z; + hit2_x = -m11 * sp_x + m12 * sp_y + m13 * sp_z; + hit2_y = m22 * sp_y + m23 * sp_z; + hit2_z = -m31 * sp_x + m32 * sp_y + m33 * sp_z; /*** hope hit_z wont get too close to zero *******/ #ifdef DEBUG - if (ABS(hit_z) < ABS(minhz)) { - minhz = hit_z; - fprintf(stdout, "should >>0 : hit_z %f\n", hit_z); - fprintf(stdout, " hit_x %f\n", hit_x); - fprintf(stdout, " ratio %f\n", hit_x / hit_z); - fprintf(stdout, " long %f\n", atan(hit_x / hit_z)); + if (ABS(hit_z) < ABS(minhz)) { + minhz = hit_z; + fprintf(stdout, "should >>0 : hit_z %f\n", hit_z); + fprintf(stdout, " hit_x %f\n", hit_x); + fprintf(stdout, " ratio %f\n", + hit_x / hit_z); + fprintf(stdout, " long %f\n", + atan(hit_x / hit_z)); - sleep(5); - } + sleep(1); + } #endif - if (ABS(hit_z) < 0.001) { - if (hit_x * hit_z > 0.) - longitude = PI / 2.; - else - longitude = -PI / 2.; - if (hit_z > 0.) - hit_z = 0.001; - else - hit_z = -0.001; - } else { - longitude = atan(hit_x / hit_z); - } + if (ABS(hit_z) < 0.001) { + if (hit_x * hit_z > 0.) + longitude = PI / 2.; + else + longitude = -PI / 2.; + if (hit_z > 0.) + hit_z = 0.001; + else + hit_z = -0.001; + } else { + longitude = atan(hit_x / hit_z); + } - if (hit_z < 0.) - longitude += PI; + if (hit_z < 0.) + longitude += PI; - r = (double) sqrt(hit_x * hit_x + hit_z * hit_z); + r = (double) sqrt(hit_x * hit_x + hit_z * hit_z); - latitude = atan(-hit_y / r); + latitude = atan(-hit_y / r); - light_angle = - (light_x * hit_x + light_y * hit_y + light_z * hit_z) / radius; - if (sens == 1) { + light_angle = + (light_x * hit_x + light_y * hit_y + + light_z * hit_z) / radius; + if (sens == 1) { - /* - * Set pixel in image - */ + /* + * Set pixel in image + */ - teinte = mygetMapColorLinear(longitude, latitude, light_angle); - myRPutPixel(px, py, &teinte); + teinte = + mygetMapColorLinear(longitude, latitude, + light_angle); + myRPutPixel(px, py, &teinte); - /* - * mirror the left half-circle of the globe: we need a new position - * and have to recalc. the light intensity - */ + /* + * mirror the left half-circle of the globe: + * we need a new position and have to recalc. the + * light intensity + */ - light_angle = - (light_x * hit2_x + light_y * hit2_y + light_z * hit2_z) / radius; - teinte = mygetMapColorLinear(2 * v_long - longitude, latitude, light_angle); - myRPutPixel(DIAMETRE - px - 1, py, &teinte); - } else { - /* sens==-1 */ - /* - * Set pixel in image - */ + light_angle = + (light_x * hit2_x + light_y * hit2_y + + light_z * hit2_z) / radius; + teinte = + mygetMapColorLinear(2 * v_long - longitude, + latitude, light_angle); + myRPutPixel(DIAMETRE - px - 1, py, &teinte); + } else { + /* sens==-1 */ + /* + * Set pixel in image + */ - teinte = mygetMapColorLinear(longitude, latitude, light_angle); - myRPutPixel(DIAMETRE - px - 1, DIAMETRE - py - 1, &teinte); + teinte = + mygetMapColorLinear(longitude, latitude, + light_angle); + myRPutPixel(DIAMETRE - px - 1, DIAMETRE - py - 1, + &teinte); - /* - * mirror the left half-circle of the globe: we need a new position - * and have to recalc. the light intensity - */ + /* + * mirror the left half-circle of the globe: + * we need a new position and have + * to recalc. the light intensity + */ - light_angle = - (light_x * hit2_x + light_y * hit2_y + light_z * hit2_z) / radius; - teinte = mygetMapColorLinear(2 * v_long - longitude, latitude, light_angle); - myRPutPixel(px, DIAMETRE - py - 1, &teinte); - } - } - } /*px */ - } /*py */ - } /*else fun */ - solution = TRUE; - return; -} -/*------------------------------------------------------------------------ */ -static RColor - mygetMapColorLinear(double longitude, double latitude, double angle) -{ - RColor point; - int x, y, xl, yl, dx, dy, ang; - - if (longitude < 0.) - longitude += 2 * PI; - - latitude += PI / 2; - - longitude += PI; - if (longitude >= 2 * PI) - longitude -= 2 * PI; - - if (angle > 0) - ang = (int) floor((1 - ((1 - angle) * dawn)) * 256); - else - ang = angle * 256; - - xl = (int) (longitude * mratiox); - yl = (int) (latitude * mratioy); - - x = xl >> 8; - y = yl >> 8; - dx = xl - (x << 8); - dy = yl - (y << 8); - - if (use_nightmap) { - if (ang > 0) { - getquarter(map, x, y, md, dx, dy); - getquarter(mapnight, x, y, mn, dx, dy); - - md[0]->r = ((mn[0]->r * (256 - ang) + md[0]->r * ang)) >> 8; - md[0]->g = ((mn[0]->g * (256 - ang) + md[0]->g * ang)) >> 8; - md[0]->b = ((mn[0]->b * (256 - ang) + md[0]->b * ang)) >> 8; - } else { - getquarter(mapnight, x, y, md, dx, dy); + light_angle = + (light_x * hit2_x + light_y * hit2_y + + light_z * hit2_z) / radius; + teinte = + mygetMapColorLinear(2 * v_long - longitude, + latitude, light_angle); + myRPutPixel(px, DIAMETRE - py - 1, &teinte); + } } - } else { - getquarter(map, x, y, md, dx, dy); - if (ang > 0) { - md[0]->r = ((md[0]->r * aml + md[0]->r * ang / 256 * (256 - aml))) >> 8; - md[0]->g = ((md[0]->g * aml + md[0]->g * ang / 256 * (256 - aml))) >> 8; - md[0]->b = ((md[0]->b * aml + md[0]->b * ang / 256 * (256 - aml))) >> 8; + } /*px */ + } /*py */ + + + } /*else fun */ +#if WITH_MARKERS +/* markers */ + if (nb_marker) { + int i; + double mx, my, mz; + + for (i = 0; i < nb_marker; i++) { + + mx = m11 * marker[i][0] + m31 * marker[i][2]; + mz = -m31 * marker[i][0] + m11 * marker[i][2]; + my = m22 * marker[i][1] - m23 * mz; + mz = m23 * marker[i][1] + m22 * mz; + + if (mz > 0) { + if (i == sun_marker) { + put_dot_cross((int) + (mx * radius_proj + DIAMETRE / 2 + funx), + (int) (-my * radius_proj + DIAMETRE / 2 + + funy), &sun_col); + } else if (i == moon_marker) { + put_dot_cross((int) + (mx * radius_proj + DIAMETRE / 2 + funx), + (int) (-my * radius_proj + DIAMETRE / 2 + + funy), &moon_col); } else { - md[0]->r = (md[0]->r * aml) >> 8; - md[0]->g = (md[0]->g * aml) >> 8; - md[0]->b = (md[0]->b * aml) >> 8; + put_cross((int) + (mx * radius_proj + DIAMETRE / 2 + funx), + (int) (-my * radius_proj + DIAMETRE / 2 + + funy)); } + } } - - point.red = (unsigned char) md[0]->r; - point.green = (unsigned char) md[0]->g; - point.blue = (unsigned char) md[0]->b; - point.alpha = 255; - return point; + } +#endif + solution = TRUE; + return; } -/* ------------------------------------------------------------------------ */ + + + + + + + + + + + + + +static RColor +mygetMapColorLinear(double longitude, double latitude, double angle) +{ + RColor point; + int x, y, xl, yl, dx, dy, ang; + + if (longitude < 0.) + longitude += 2 * PI; + + latitude += PI / 2; + + longitude += PI; + if (longitude >= 2 * PI) + longitude -= 2 * PI; + + if (angle > 0) + ang = (int) floor((1 - ((1 - angle) * dawn)) * 256); + else + ang = angle * 256; + + xl = (int) (longitude * mratiox); + yl = (int) (latitude * mratioy); + + x = xl >> 8; + y = yl >> 8; + dx = xl - (x << 8); + dy = yl - (y << 8); + + if (use_nightmap) { + if (ang > 0) { + getquarter(map, x, y, md, dx, dy); + getquarter(mapnight, x, y, mn, dx, dy); + + md[0]->r = ((mn[0]->r * (256 - ang) + md[0]->r * ang)) >> 8; + md[0]->g = ((mn[0]->g * (256 - ang) + md[0]->g * ang)) >> 8; + md[0]->b = ((mn[0]->b * (256 - ang) + md[0]->b * ang)) >> 8; + } else { + getquarter(mapnight, x, y, md, dx, dy); + } + } else { + getquarter(map, x, y, md, dx, dy); + if (ang > 0) { + md[0]->r = + ((md[0]->r * aml + + md[0]->r * ang / 256 * (256 - aml))) >> 8; + md[0]->g = + ((md[0]->g * aml + + md[0]->g * ang / 256 * (256 - aml))) >> 8; + md[0]->b = + ((md[0]->b * aml + + md[0]->b * ang / 256 * (256 - aml))) >> 8; + } else { + md[0]->r = (md[0]->r * aml) >> 8; + md[0]->g = (md[0]->g * aml) >> 8; + md[0]->b = (md[0]->b * aml) >> 8; + } + } + + point.red = (unsigned char) md[0]->r; + point.green = (unsigned char) md[0]->g; + point.blue = (unsigned char) md[0]->b; + point.alpha = 255; /* in fun mode, we use original Rputpixel that need alpha?*/ + return point; +} + + + + + + + static void randomPosition() { - addlat = ((rand() % 30001) / 30000.) * 180. - 90.; - addlong = ((rand() % 30001) / 30000.) * 360. - 180.; - return; + addlat = ((rand() % 30001) / 30000.) * 180. - 90.; + addlong = ((rand() % 30001) / 30000.) * 360. - 180.; + return; } -/* ------------------------------------------------------------------------ */ + + + + + + + + + static void updateTime(int force) { /* calcul of sun position every minute */ - if ((trend.tv_sec - tsunpos) >= 60 || force) { - tsunpos = trend.tv_sec; - GetSunPos(tsunpos, &sun_lat, &sun_long); - light_x = cos(sun_lat) * sin(sun_long); - light_y = sin(sun_lat); - light_z = cos(sun_lat) * cos(sun_long); - do_something = TRUE; + if ((trend.tv_sec - tsunpos) >= 60 || force) { + tsunpos = trend.tv_sec; + sun_position(tsunpos, &sun_lat, &sun_long); + light_x = cos(sun_lat) * sin(sun_long); + light_y = sin(sun_lat); + light_z = cos(sun_lat) * cos(sun_long); + do_something = TRUE; +#if WITH_MARKERS + if (sun_marker >= 0) { + marker[sun_marker][0] = light_x; + marker[sun_marker][1] = light_y; + marker[sun_marker][2] = light_z; } - return; +/* ... and the moon position */ + if (moon_marker >= 0 || p_type == PTMOON || force == STRONG) { + moon_position(tsunpos, &moon_lat, &moon_long); + if (moon_marker >= 0) { + marker[moon_marker][1] = moon_lat; + marker[moon_marker][0] = moon_long; + transform_marker(moon_marker); + } + } +#endif + } + return; } -/* ------------------------------------------------------------------------ */ + + + + + + + + + +void transform_marker(int m) +{ + /* long/lat => rotation matrix */ + double dtmp1, dtmp2; + + dtmp1 = sin(marker[m][0]) * cos(marker[m][1]); + dtmp2 = sin(marker[m][1]); + marker[m][2] = cos(marker[m][0]) * cos(marker[m][1]); + marker[m][0] = dtmp1; + marker[m][1] = dtmp2; +} + + + + + + + + void setViewPos(double lat, double lon) { - double dif; - while (lat >= 360.) - lat -= 360.; - while (lat <= -360.) - lat += 360.; - while (addlat >= 360.) - addlat -= 360.; - while (addlat <= -360.) - addlat += 360.; + double dif; + while (lat >= 360.) + lat -= 360.; + while (lat <= -360.) + lat += 360.; + while (addlat >= 360.) + addlat -= 360.; + while (addlat <= -360.) + addlat += 360.; - if (lat >= 90.) { - dif = lat; - lat = 180. - lat; - addlat += (lat - dif); - dlat *= -1; - if (!fun) { - lon += 180.; - addlong += 180.; - } - sens *= -1; + if (lat >= 90.) { + dif = lat; + lat = 180. - lat; + addlat += (lat - dif); + dlat *= -1; + if (!fun && !stable) { + lon += 180.; + addlong += 180.; } - if (lat <= -90.) { - dif = lat; - lat = -180. - lat; - addlat += (lat - dif); - dlat *= -1; - if (!fun) { - lon += 180.; - addlong += 180.; - } - sens *= -1; + if (!stable) + sens *= -1; + } + if (lat <= -90.) { + dif = lat; + lat = -180. - lat; + addlat += (lat - dif); + dlat *= -1; + if (!fun && !stable) { + lon += 180.; + addlong += 180.; } - if (lat >= 90.) { - dif = lat; - lat = 180. - lat; - addlat += (lat - dif); - dlat *= -1; - if (!fun) { - lon += 180.; - addlong += 180.; - } - sens *= -1; + if (!stable) + sens *= -1; + } + if (lat >= 90.) { + dif = lat; + lat = 180. - lat; + addlat += (lat - dif); + dlat *= -1; + if (!fun && !stable) { + lon += 180.; + addlong += 180.; } - if (lat <= -90.) { - dif = lat; - lat = -180. - lat; - addlat += (lat - dif); - dlat *= -1; - if (!fun) { - lon += 180.; - addlong += 180.; - } - sens *= -1; - } - while (lon >= 180.) { - lon -= 360.; - addlong -= 360.; - } - while (lon <= -180.) { - lon += 360.; - addlong += 360.; + if (!stable) + sens *= -1; + } + if (lat <= -90.) { + dif = lat; + lat = -180. - lat; + addlat += (lat - dif); + dlat *= -1; + if (!fun && !stable) { + lon += 180.; + addlong += 180.; } + if (!stable) + sens *= -1; + } + while (lon >= 180.) { + lon -= 360.; + addlong -= 360.; + } + while (lon <= -180.) { + lon += 360.; + addlong += 360.; + } - v_lat = lat * PI / 180.; - v_long = lon * PI / 180.; - dv_lat = lat; - dv_long = lon; + v_lat = lat * PI / 180.; + v_long = lon * PI / 180.; + dv_lat = lat; + dv_long = lon; - return; + return; } -/* ------------------------------------------------------------------------ */ -void recalc(int calme) + + + + + + + + +void recalc(int force) { - double coeff, va, vo; - struct timeval tv, tnow; + double coeff, va, vo; + struct timeval tv, tnow; - tnow = getimev(); - trend = timeaccel(tnow); - tv = diftimev(tnow, tlast); + tnow = getimev(); + trend = timeaccel(tnow); + tv = diftimev(tnow, tlast); - if (firstTime) { - firstTime = FALSE; - updateTime(TRUE); - } else { - coeff = (double) tv.tv_sec + tv.tv_usec / 1000000.; + if (firstTime) { + firstTime = FALSE; + updateTime(STRONG); + } else { + coeff = (double) tv.tv_sec + tv.tv_usec / 1000000.; - if (!calme) { + if (!force) { /** while !clic button rotate earth **/ - addlat += dlat * coeff; - addlong += dlong * coeff; - } + addlat += dlat * coeff; + addlong += dlong * coeff; } + } - if (addlong != old_dvlong || addlat != old_dvlat || p_type == PTRANDOM) { - old_dvlong = addlong; - old_dvlat = addlat; - do_something = TRUE; + if (addlong != old_dvlong || addlat != old_dvlat || p_type == PTRANDOM) { + old_dvlong = addlong; + old_dvlat = addlat; + do_something = TRUE; + } +#if WITH_MARKERS + if (force) { + if (p_type == PTSUN) { + va = sun_lat * 180. / PI; + vo = sun_long * 180. / PI; + updateTime(TRUE); + addlat -= sun_lat * 180. / PI - va; + addlong -= sun_long * 180. / PI - vo; + } else if (p_type == PTMOON) { + va = moon_lat * 180. / PI; + vo = moon_long * 180. / PI; + updateTime(TRUE); + addlat -= moon_lat * 180. / PI - va; + addlong -= moon_long * 180. / PI - vo; } - if (calme && p_type == PTSUNREL) { - va = sun_lat * 180. / PI; - vo = sun_long * 180. / PI; - updateTime(TRUE); - addlat -= sun_lat * 180. / PI - va; - addlong -= sun_long * 180. / PI - vo; - } else { - updateTime(FALSE); - } - - if (do_something) { - switch (p_type) { - case PTSUNREL: - setViewPos(sun_lat * 180. / PI + addlat, - sun_long * 180. / PI + addlong); - break; - - case PTFIXED: - setViewPos(addlat, addlong); - break; - - case PTRANDOM: - if (stoprand == FALSE) - randomPosition(); - else - stoprand--; - setViewPos(addlat, addlong); - break; - - default: - break; - } -#ifdef DEBUG - fprintf(stdout, "%s render\n", ctime(&trend.tv_sec)); +#else + if (force && p_type == PTSUN) { + va = sun_lat * 180. / PI; + vo = sun_long * 180. / PI; + updateTime(TRUE); + addlat -= sun_lat * 180. / PI - va; + addlong -= sun_long * 180. / PI - vo; #endif - renderFrame(); - } - tlast = tnow; - tnext = addtimev(tnow, tdelay); + } else { + updateTime(FALSE); + } - return; + if (do_something) { + switch (p_type) { + case PTSUN: + setViewPos(sun_lat * 180. / PI + addlat, + sun_long * 180. / PI + addlong); + break; + +#if WITH_MARKERS + case PTMOON: + setViewPos(moon_lat * 180. / PI + addlat, + moon_long * 180. / PI + addlong); + break; +#endif + case PTFIXED: + setViewPos(addlat, addlong); + break; + + case PTRANDOM: + if (stoprand == FALSE) + randomPosition(); + else + stoprand--; + setViewPos(addlat, addlong); + break; + + default: + break; + } +#ifdef DEBUG + fprintf(stdout, "%s render\n", ctime(&trend.tv_sec)); +#endif + renderFrame(); + } + tlast = tnow; + tnext = addtimev(tnow, tdelay); + + return; +} + + + + + + +/* convert a 4 layers RGBA image to a 3 layer one */ +int ripalpha(RImage * image) +{ + int x, y; + unsigned char *d, *s, *old; + + if (image == NULL) + return 0; + if (image->format == RRGBFormat) + return 1; + + d = malloc(image->width * image->height * 3 + 4); + if (!d) { + RErrorCode = RERR_NOMEMORY; + puts("error in ripalpha"); + return 0; + } + + s = image->data; + old = image->data; + image->data = d; + image->format = RRGBFormat; + for (y = 0; y < image->height; y++) { + for (x = 0; x < image->width; x++) { + *d++ = *s++; + *d++ = *s++; + *d++ = *s++; + s++; + } + } + free(old); + return 1; } -/* ------------------------------------------------------------------------ */ diff --git a/wmglobe/src/sunpos.c b/wmglobe/src/sunpos.c index 7405da5..81d36ba 100644 --- a/wmglobe/src/sunpos.c +++ b/wmglobe/src/sunpos.c @@ -1,6 +1,6 @@ -/* WMGlobe 0.5 - All the Earth on a WMaker Icon - * copyright (C) 1998,99 Jerome Dumonteil - * sunpos.c is taken from Xearth : +/* WMGlobe 1.3 - All the Earth on a WMaker Icon + * copyright (C) 1998,99,2000,01 Jerome Dumonteil + * 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,21 +201,22 @@ 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 - * double *alpha; (return) right ascension - * double *delta; (return) declination + * double lambda; ecliptic longitude + * double beta; ecliptic latitude + * double *alpha; (return) right ascension + * 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)); } @@ -183,31 +227,31 @@ static void ecliptic_to_equatorial(double lambda, double beta, double *alpha, do */ static double julian_date(int y, int m, int d) /* - * int y; year (e.g. 19xx) - * int m; month (jan=1, feb=2, ...) - * int d; day of month + * int y; year (e.g. 19xx) + * int m; month (jan=1, feb=2, ...) + * 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; } diff --git a/wmglobe/src/wmglobe.c b/wmglobe/src/wmglobe.c index 13fc49f..2c463e4 100644 --- a/wmglobe/src/wmglobe.c +++ b/wmglobe/src/wmglobe.c @@ -1,27 +1,27 @@ -/* WMGlobe 0.5 - All the Earth on a WMaker Icon - * copyright (C) 1998,99 Jerome Dumonteil - * +/* WMGlobe 1.3 - All the Earth on a WMaker Icon + * copyright (C) 1998,99,2000,01 Jerome Dumonteil + * * 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program 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 General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ***************************************************************************/ -/* +/* * I used many functions of wmgeneral.c ("openXwindow") - * for the main function of wmglobe.c + * for the main function of wmglobe.c * wmgeneral.c was taken from wmaker applet wmtune-1.0 : * Author: Martijn Pieterse (pieterse@xs4all.nl) * - * wmglobe.c uses functions of : Xglobe, Xearth, wmgeneral, wmaker/wrlib + * wmglobe.c uses functions of : Xglobe, Xearth, wmgeneral, wmaker/wrlib ***************************************************************************/ #include "wmglobe.h" @@ -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; } diff --git a/wmglobe/src/wmglobe.h b/wmglobe/src/wmglobe.h index e16f4a7..b2011c4 100644 --- a/wmglobe/src/wmglobe.h +++ b/wmglobe/src/wmglobe.h @@ -1,21 +1,21 @@ -/* WMGlobe 0.5 - All the Earth on a WMaker Icon - * copyright (C) 1998,99 Jerome Dumonteil - * +/* WMGlobe 1.3 - All the Earth on a WMaker Icon + * copyright (C) 1998,99,2000,01 Jerome Dumonteil + * * 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program 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 General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ***************************************************************************/ -/* it uses some functions of : Xglobe, Xearth, wmgeneral, wmaker/wrlib +/* it uses some functions of : Xglobe, Xearth, wmgeneral, wmaker/wrlib ***************************************************************************/ @@ -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,11 +120,18 @@ 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, * vec_tim; - * + * * time_t beg_time, ini_time,t1901; */ struct timeval tlast, tnext, trend, tdelay, tini, tbase; @@ -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 diff --git a/wmglobe/src/wmgoption.h b/wmglobe/src/wmgoption.h index 3bac381..8f012ce 100644 --- a/wmglobe/src/wmgoption.h +++ b/wmglobe/src/wmgoption.h @@ -1,16 +1,16 @@ -/* WMGlobe 0.5 - All the Earth on a WMaker Icon - * copyright (C) 1998,99 Jerome Dumonteil - * +/* WMGlobe 1.3 - All the Earth on a WMaker Icon + * copyright (C) 1998,99,2000,01 Jerome Dumonteil + * * 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program 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 General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. @@ -20,7 +20,7 @@ * #define DEBUG */ -#define WMGVERSION "WMGlobe v.0.5 6 fev 1999 " +#define WMGVERSION "WMGlobe v.1.3 12 aug 2001 " /* * 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 @@ -82,6 +95,6 @@ #define DEFAULT_DAWN 0.9 /* change this if not 64x64 icons (not deep tested) you will need to change - the cadrex.xbm too and a few other things for the parameters menus + the cadrex.xbm too and a few other things for the parameters menus --- DIAMETRE must be a multiple of 2 --- */ #define DIAMETRE 64 diff --git a/wmglobe/src/wmgutil.c b/wmglobe/src/wmgutil.c index 2686c5c..8940762 100644 --- a/wmglobe/src/wmgutil.c +++ b/wmglobe/src/wmgutil.c @@ -1,27 +1,27 @@ -/* WMGlobe 0.5 - All the Earth on a WMaker Icon - * copyright (C) 1998,99 Jerome Dumonteil - * +/* WMGlobe 1.3 - All the Earth on a WMaker Icon + * copyright (C) 1998,99,2000,01 Jerome Dumonteil + * * 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program 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 General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ***************************************************************************/ -/* +/* * I used many functions of wmgeneral.c ("openXwindow") - * for the main function of wmglobe.c + * for the main function of wmglobe.c * wmgeneral.c was taken from wmaker applet wmtune-1.0 : * Author: Martijn Pieterse (pieterse@xs4all.nl) * - * wmglobe.c uses functions of : Xglobe, Xearth, wmgeneral, wmaker/wrlib + * wmglobe.c uses functions of : Xglobe, Xearth, wmgeneral, wmaker/wrlib ***************************************************************************/ #include "wmglobe.h" @@ -62,2296 +62,2549 @@ static void move_dawn(int factor); static void move_accel(int factor); static void move_dlat(int factor); static void move_dlong(int factor); -/* ------------------------------------------------------------------------ */ -/* - * TIME FUNCTIONS - */ -/* ------------------------------------------------------------------------ */ + +/************************************************************************** + * TIME FUNCTIONS + *************************************************************************/ + struct timeval diftimev(struct timeval t1, struct timeval t2) { - t1.tv_usec -= t2.tv_usec; - if (t1.tv_usec < 0) { - t1.tv_usec += 1000000; - t1.tv_sec--; - } - t1.tv_sec -= t2.tv_sec; - return t1; + t1.tv_usec -= t2.tv_usec; + if (t1.tv_usec < 0) { + t1.tv_usec += 1000000; + t1.tv_sec--; + } + t1.tv_sec -= t2.tv_sec; + return t1; } -/* ------------------------------------------------------------------------ */ + + + struct timeval addtimev(struct timeval t1, struct timeval t2) { - t1.tv_usec += t2.tv_usec; - if (t1.tv_usec >= 1000000) { - t1.tv_usec -= 1000000; - t1.tv_sec++; - } - t1.tv_sec += t2.tv_sec; - return t1; + t1.tv_usec += t2.tv_usec; + if (t1.tv_usec >= 1000000) { + t1.tv_usec -= 1000000; + t1.tv_sec++; + } + t1.tv_sec += t2.tv_sec; + return t1; } -/* ------------------------------------------------------------------------ */ + + + struct timeval getimev() { - struct timeval tv; - struct timezone tz; + struct timeval tv; + struct timezone tz; - gettimeofday(&tv, &tz); - return tv; + gettimeofday(&tv, &tz); + return tv; } -/* ------------------------------------------------------------------------ */ -/* + + +/*************************************************************************** * INIT FUNCTIONS * * defaults, commandline * init of pixmap for screenpos and numbers displaying - */ -/* ------------------------------------------------------------------------ */ + ***************************************************************************/ + void loadxpm(Window draw) { - XpmCreatePixmapFromData(dpy, draw, scrpos_xpm, &(screenpos.pixmap), - &(screenpos.mask), &(screenpos.attributes)); - XpmCreatePixmapFromData(dpy, draw, scrtime_xpm, &(scrdate.pixmap), - &(scrdate.mask), &(scrdate.attributes)); - XpmCreatePixmapFromData(dpy, draw, zapnum_xpm, &(numpix.pixmap), - &(numpix.mask), &(numpix.attributes)); - XpmCreatePixmapFromData(dpy, draw, zaptxt_xpm, &(txtpix.pixmap), - &(txtpix.mask), &(txtpix.attributes)); - XpmCreatePixmapFromData(dpy, draw, scrdiv_xpm, &(scrdiv.pixmap), - &(scrdiv.mask), &(scrdiv.attributes)); - return; + XpmCreatePixmapFromData(dpy, draw, scrpos_xpm, &(screenpos.pixmap), + &(screenpos.mask), &(screenpos.attributes)); + XpmCreatePixmapFromData(dpy, draw, scrtime_xpm, &(scrdate.pixmap), + &(scrdate.mask), &(scrdate.attributes)); + XpmCreatePixmapFromData(dpy, draw, zapnum_xpm, &(numpix.pixmap), + &(numpix.mask), &(numpix.attributes)); + XpmCreatePixmapFromData(dpy, draw, zaptxt_xpm, &(txtpix.pixmap), + &(txtpix.mask), &(txtpix.attributes)); + XpmCreatePixmapFromData(dpy, draw, scrdiv_xpm, &(scrdiv.pixmap), + &(scrdiv.mask), &(scrdiv.attributes)); + return; } -/* ------------------------------------------------------------------------ */ + + + + + + + void set_defaults() { - firstTime = TRUE; - dayfile = NULL; - use_nightmap = FALSE; - nightfile = NULL; - oknimap = DEFAULT_NIGHTMAP; - p_type = PTSUNREL; - delay = DEFAULT_DELAY; - tini = getimev(); - tbase = tini; - tsunpos = 0; - tlast.tv_sec = 0; - tlast.tv_usec = 0; - do_something = TRUE; - time_multi = 1.0; - v_lat = DEFAULT_V_LAT / 180. * PI; - v_long = DEFAULT_V_LONG / 180. * PI; - dv_lat = DEFAULT_V_LAT; - dv_long = DEFAULT_V_LONG; - old_dvlat = DEFAULT_V_LAT; - old_dvlong = DEFAULT_V_LONG; - iop = 0; - dlat = 0.0; - dlong = 0.0; - addlat = 0.0; - addlong = 0.0; - radius = 1000.0; - sun_long = 0.0; - sun_lat = 0.0; - fov = 0.5 * PI / 180.; - sens = DEFAULT_SENS; - zoom = DEFAULT_ZOOM; - ambient_light = DEFAULT_LIGHT; - dawn = DEFAULT_DAWN; - typecadre = DEFAULT_BORDER; - fun = FALSE; - funx = 0; - funy = 0; - dpy_name = NULL; - onlyshape = TRUE; - option_iw = WithdrawnState; - stoprand = FALSE; - solution = FALSE; - proj_dist = DIAMETRE / tan(fov); - noir.red = 0; - noir.green = 0; - noir.blue = 0; - noir.alpha = 255; - - md[0] = (MPO *) malloc(sizeof(MPO)); - md[1] = (MPO *) malloc(sizeof(MPO)); - md[2] = (MPO *) malloc(sizeof(MPO)); - md[3] = (MPO *) malloc(sizeof(MPO)); - mn[0] = (MPO *) malloc(sizeof(MPO)); - mn[1] = (MPO *) malloc(sizeof(MPO)); - mn[2] = (MPO *) malloc(sizeof(MPO)); - mn[3] = (MPO *) malloc(sizeof(MPO)); -#ifdef DEBUG - minhz = 1.; + stable = FALSE; + firstTime = TRUE; + dayfile = NULL; + use_nightmap = TRUE; + use_default_nightmap = FALSE; + nightfile = NULL; + oknimap = DEFAULT_NIGHTMAP; + p_type = PTSUN; + delay = DEFAULT_DELAY; + tini = getimev(); + tbase = tini; + tsunpos = 0; + tlast.tv_sec = 0; + tlast.tv_usec = 0; + do_something = TRUE; + time_multi = 1.0; + v_lat = DEFAULT_V_LAT / 180. * PI; + v_long = DEFAULT_V_LONG / 180. * PI; + dv_lat = DEFAULT_V_LAT; + dv_long = DEFAULT_V_LONG; + old_dvlat = DEFAULT_V_LAT; + old_dvlong = DEFAULT_V_LONG; + iop = 0; + dlat = 0.0; + dlong = 0.0; + addlat = 0.0; + addlong = 0.0; + radius = 1000.0; + sun_long = 0.0; + sun_lat = 0.0; + fov = 0.5 * PI / 180.; + sens = DEFAULT_SENS; + zoom = DEFAULT_ZOOM; + ambient_light = DEFAULT_LIGHT; + dawn = DEFAULT_DAWN; + typecadre = DEFAULT_BORDER; + fun = FALSE; + funx = 0; + funy = 0; + dpy_name = NULL; + onlyshape = TRUE; + option_iw = WithdrawnState; + stoprand = FALSE; + solution = FALSE; + proj_dist = DIAMETRE / tan(fov); + noir.red = 0; + noir.green = 0; + noir.blue = 0; + noir.alpha = 255; +#if WITH_MARKERS + nb_marker = 0; + sun_marker = -1; + moon_marker = -1; + sun_col.red = CR_SUN_R; + sun_col.green = CR_SUN_G; + sun_col.blue = CR_SUN_B; + sun_col.alpha = 255; + moon_col.red = CR_MOON_R; + moon_col.green = CR_MOON_G; + moon_col.blue = CR_MOON_B; + moon_col.alpha = 255; #endif - return; + md[0] = (MPO *) malloc(sizeof(MPO)); + md[1] = (MPO *) malloc(sizeof(MPO)); + md[2] = (MPO *) malloc(sizeof(MPO)); + md[3] = (MPO *) malloc(sizeof(MPO)); + mn[0] = (MPO *) malloc(sizeof(MPO)); + mn[1] = (MPO *) malloc(sizeof(MPO)); + mn[2] = (MPO *) malloc(sizeof(MPO)); + mn[3] = (MPO *) malloc(sizeof(MPO)); +#ifdef DEBUG + minhz = 1.; +#endif + return; } -/* ------------------------------------------------------------------------ */ + + + + static double getdegre(char *val) { - double d, m, s; - if (strchr(val, '°') != NULL || strchr(val, 'd') != NULL - || strchr(val, 'D') != NULL || strchr(val, ':') != NULL) { - d = m = s = 0; - sscanf(val, "%lf%*c%lf%*c%lf", &d, &m, &s); - if (d >= 0.) - return d + m / 60. + s / 3600.; - else - return d - m / 60. - s / 3600.; - } else { - return atof(val); - } + double d, m, s; + if (strchr(val, '°') != NULL || strchr(val, 'd') != NULL + || strchr(val, 'D') != NULL || strchr(val, ':') != NULL) { + d = m = s = 0; + sscanf(val, "%lf%*c%lf%*c%lf", &d, &m, &s); + if (d >= 0.) + return d + m / 60. + s / 3600.; + else + return d - m / 60. - s / 3600.; + } else { + return atof(val); + } } -/* ------------------------------------------------------------------------ */ + + + + static void mqparam() { - printf("error in parameters\n"); - exit(1); + fprintf(stderr, "error in parameters\n"); + exit(1); } -/* ------------------------------------------------------------------------ */ + + + + void cmdline(int argc, char *argv[]) { - int i, j; + int i, j; - if (argc > 0) { - for (i = 1; i < argc; i++) { - j = 0; + if (argc > 0) { + for (i = 1; i < argc; i++) { + j = 0; -/* ---------------------------------------------------- */ - if (strcasecmp(argv[i], "-v") == 0 - || strcasecmp(argv[i], "-version") == 0) { - printf("%s\n", WMGVERSION); - exit(0); - } -/* ---------------------------------------------------- */ - if (strcasecmp(argv[i], "-w") == 0 - || strcasecmp(argv[i], "-wmaker") == 0) { - option_iw = WithdrawnState; - j = 1; - } -/* ---------------------------------------------------- */ - if (strcasecmp(argv[i], "-i") == 0 - || strcasecmp(argv[i], "-iconic") == 0) { - option_iw = IconicState; - j = 1; - } -/* ---------------------------------------------------- */ - if (!j && (strcasecmp(argv[i], "-s") == 0 || - strcasecmp(argv[i], "-shape") == 0)) { - onlyshape = TRUE; - j = 1; - } -/* ---------------------------------------------------- */ - if (!j && (strcasecmp(argv[i], "-d") == 0 - || strcasecmp(argv[i], "-display") == 0)) { - i++; - if (i < argc) { - j = 1; - dpy_name = argv[i]; - } else { - mqparam(); - i--; - } - } -/* ---------------------------------------------------- */ - if (!j && (strcasecmp(argv[i], "-rand") == 0 - || strcasecmp(argv[i], "-random") == 0)) { - p_type = PTRANDOM; - srandom(((int) time(NULL)) + ((int) getpid())); - j = 1; - } -/* ---------------------------------------------------- */ - if (!j && (strcasecmp(argv[i], "-oz") == 0 - || strcasecmp(argv[i], "-austral") == 0)) { - sens = -1; - j = 1; - } -/* ---------------------------------------------------- */ - if (!j && strcasecmp(argv[i], "-map") == 0) { - i++; - if (i < argc) { - j = 1; - free(dayfile); - if ((dayfile = (char *) malloc(strlen(argv[i]) + 1)) == NULL) { - fprintf(stderr, "erreur memoire options map\n"); - exit(1); - }; - strcpy(dayfile, argv[i]); - } else { - mqparam(); - i--; - } - } -/* ---------------------------------------------------- */ - if (!j && (strcasecmp(argv[i], "-nimap") == 0 - || strcasecmp(argv[i], "-nightmap") == 0 - || strcasecmp(argv[i], "-night") == 0)) { + if (strcasecmp(argv[i], "-v") == 0 + || strcasecmp(argv[i], "-version") == 0) { + printf("%s\n", WMGVERSION); + exit(0); + } - i++; - if (i < argc) { - j = 1; - free(nightfile); - if ((nightfile = (char *) malloc(strlen(argv[i]) + 1)) == NULL) { - fprintf(stderr, "erreur memoire options nimap\n"); - exit(1); - }; - strcpy(nightfile, argv[i]); - use_nightmap = TRUE; - } else { - mqparam(); - i--; - } - } -/* ---------------------------------------------------- */ - if (!j && (strcasecmp(argv[i], "-accel") == 0 - || strcasecmp(argv[i], "-accell") == 0 - || strcasecmp(argv[i], "-acc") == 0 - || strcasecmp(argv[i], "-multi") == 0)) { - i++; - if (i < argc) { - j = 1; - time_multi = atof(argv[i]); - if (time_multi < 1.0) - time_multi = 1.0; - if (time_multi > MAX_MULTI_COEF) - time_multi = MAX_MULTI_COEF; - if (time_multi > 24.0) - time_multi = floor(time_multi); - else - time_multi = floor(time_multi * 10.0) / 10.0; - } else { - mqparam(); - i--; - } - } -/* ---------------------------------------------------- */ - if (!j && (strcasecmp(argv[i], "-nonimap") == 0 - || strcasecmp(argv[i], "-nonightmap") == 0 - || strcasecmp(argv[i], "-nonight") == 0 - || strcasecmp(argv[i], "-nomap") == 0)) { - j = 1; - use_nightmap = FALSE; - oknimap = FALSE; - } -/* ---------------------------------------------------- */ - if (!j && strcasecmp(argv[i], "-zoom") == 0) { - i++; - if (i < argc) { - j = 1; - zoom = atof(argv[i]); - if (zoom < ZOOM_MIN) - zoom = ZOOM_MIN; - if (zoom > ZOOM_MAX) - zoom = ZOOM_MAX; - } else { - mqparam(); - i--; - } - } -/* ---------------------------------------------------- */ - if (!j && strcasecmp(argv[i], "-dawn") == 0) { - i++; - if (i < argc) { - j = 1; - dawn = atof(argv[i]); - dawn = MAX(0.0, dawn); - dawn = MIN(1.0, dawn); + if (strcasecmp(argv[i], "-w") == 0 + || strcasecmp(argv[i], "-wmaker") == 0) { + option_iw = WithdrawnState; + j = 1; + } - dawn = (1.0 - dawn / 2.0); - } else { - mqparam(); - i--; - } - } -/* ---------------------------------------------------- */ - if (!j && strcasecmp(argv[i], "-delay") == 0) { - i++; - if (i < argc) { - j = 1; - delay = atof(argv[i]); - if (delay < 0) - delay = 0; - if (delay > MAX_DELAY_SEC) - delay = MAX_DELAY_SEC; - } else { - mqparam(); - i--; - } - } -/* ---------------------------------------------------- */ - if (!j && (strcasecmp(argv[i], "-dlat") == 0 - || strcasecmp(argv[i], "-lat") == 0 - || strcasecmp(argv[i], "-dlatitude") == 0)) { - i++; - if (i < argc) { - j = 1; - dlat = getdegre(argv[i]); - if (dlat < -MAX_DELTA_LONG) - dlat = -MAX_DELTA_LONG; - if (dlat > MAX_DELTA_LONG) - dlat = MAX_DELTA_LONG; - p_type = PTFIXED; - } else { - mqparam(); - i--; - } - } -/* ---------------------------------------------------- */ - if (!j && (strcasecmp(argv[i], "-dlong") == 0 - || strcasecmp(argv[i], "-long") == 0 - || strcasecmp(argv[i], "-dlongitude") == 0)) { - i++; - if (i < argc) { - j = 1; - dlong = getdegre(argv[i]); - if (dlong < -MAX_DELTA_LONG) - dlong = -MAX_DELTA_LONG; - if (dlong > MAX_DELTA_LONG) - dlong = MAX_DELTA_LONG; - p_type = PTFIXED; - } else { - mqparam(); - i--; - } - } -/* ---------------------------------------------------- */ - if (!j && strcasecmp(argv[i], "-light") == 0) { - i++; - if (i < argc) { - j = 1; - ambient_light = atof(argv[i]); - if (ambient_light < 0.) - ambient_light = 0.; - if (ambient_light > 1.) - ambient_light = 1.; - } else { - mqparam(); - i--; - } - } -/* ---------------------------------------------------- */ - if (!j && strcasecmp(argv[i], "-time") == 0) { - i++; - if (i < argc) { - j = 1; - tbase.tv_sec = atoi(argv[i]); - tbase.tv_usec = 0; - } else { - mqparam(); - i--; - } - } -/* ---------------------------------------------------- */ - if (!j && (strcasecmp(argv[i], "-bord") == 0 - || strcasecmp(argv[i], "-border") == 0)) { - i++; - if (i < argc) { - j = 1; - typecadre = atoi(argv[i]); - if (typecadre < 0) - typecadre = 0; - if (typecadre > 2) - typecadre = 2; - } else { - mqparam(); - i--; - } - } -/* ---------------------------------------------------- */ - if (!j && strcasecmp(argv[i], "-fun") == 0) { - fun = TRUE; - i++; - if (i < argc) { - funx = atoi(argv[i]); + if (strcasecmp(argv[i], "-i") == 0 + || strcasecmp(argv[i], "-iconic") == 0) { + option_iw = IconicState; + j = 1; + } - i++; - if (i < argc) { - j = 1; - funy = atoi(argv[i]); - } else { - mqparam(); - i--; - } - } else { - mqparam(); - i--; - } - } -/* ---------------------------------------------------- */ - if (!j && (strcasecmp(argv[i], "-pos") == 0 - || strcasecmp(argv[i], "-position") == 0 - || strcasecmp(argv[i], "-fixed") == 0)) { - p_type = PTFIXED; - i++; - if (i < argc) { - addlat = getdegre(argv[i]); - i++; - if (i < argc) { - j = 1; - addlong = getdegre(argv[i]); - } else { - mqparam(); - i--; - } - } else { - mqparam(); - i--; - } - } -/* ---------------------------------------------------- */ + if (!j && (strcasecmp(argv[i], "-s") == 0 || + strcasecmp(argv[i], "-shape") == 0)) { + onlyshape = TRUE; + j = 1; + } - if (!j && argv[i][0] == '-') { - printf("%s\n", WMGVERSION); - printf("\n"); - printf("-v : version -h : this help message !\n"); - printf("-zoom zoom_value : changing apparent size in icon\n"); - printf("-pos latitude long. : fixed initial position (default=follow sun)\n"); - printf("-rand : random position at every refresh\n"); - printf("-map map_file : use this map for rendering\n"); - printf("-nimap night_file : and this one for the dark side of earth\n"); - printf("-nonimap : don't use the default night map\n"); - printf("-delay seconds : time between refresh of image\n"); - printf("-dlat delta_lat : latitude speed of point of view (default=follow sun)\n"); - printf("-dlong delta_long : the same for longitude\n"); - printf("-light light_value : level of light for dark side of earth\n"); - printf("-dawn dawn_value : level of continuity for dawn limit\n"); - printf("-bord border_num : 0 1 or 2 , type of icon border.\n"); - printf("-accel time_multi : time accelerator\n"); - printf("-time seconds : time to display in seconds since 01-01-1970\n"); - printf("-oz : start in \"austral\" mode (for \"down under\" people)\n"); - printf("-fun dx dy : offset of vision... almost useless\n"); - printf("-w -shape : set by default (WMaker dockable application)\n"); - printf("-d display : display (WindowMaker not needed on the server side)\n"); - printf("left button : change longitude, with shift key, change latitude too\n"); - printf("middle button : zoom in, shift + middle button : zoom out\n"); - printf("right button : access to a few screens of parameters\n"); - exit(0); - } -/* ------------------------------------------------------------------------ */ + if (!j && (strcasecmp(argv[i], "-d") == 0 + || strcasecmp(argv[i], "-display") == 0)) { + i++; + if (i < argc) { + j = 1; + dpy_name = argv[i]; + } else { + mqparam(); + i--; } + } + + if (!j && (strcasecmp(argv[i], "-stable") == 0 + || strcasecmp(argv[i], "-stab") == 0)) { + stable = TRUE; + j = 1; + } + + if (!j && (strcasecmp(argv[i], "-rand") == 0 + || strcasecmp(argv[i], "-random") == 0)) { + p_type = PTRANDOM; + srandom(((int) time(NULL)) + ((int) getpid())); + j = 1; + } + + if (!j && (strcasecmp(argv[i], "-sun") == 0 + || strcasecmp(argv[i], "-soleil") == 0)) { + p_type = PTSUN; + j = 1; + } + +#if WITH_MARKERS + if (!j && (strcasecmp(argv[i], "-moon") == 0 + || strcasecmp(argv[i], "-lune") == 0)) { + p_type = PTMOON; + j = 1; + } +#endif + + if (!j && (strcasecmp(argv[i], "-oz") == 0 + || strcasecmp(argv[i], "-austral") == 0)) { + sens = -1; + j = 1; + } + + if (!j && strcasecmp(argv[i], "-map") == 0) { + + i++; + if (i < argc) { + j = 1; + free(dayfile); + if ((dayfile = (char *) malloc(strlen(argv[i]) + 1)) == + NULL) { + fprintf(stderr, "erreur memoire options map\n"); + exit(1); + }; + strcpy(dayfile, argv[i]); + } else { + mqparam(); + i--; + } + } + + if (!j && (strcasecmp(argv[i], "-nimap") == 0 + || strcasecmp(argv[i], "-nightmap") == 0 + || strcasecmp(argv[i], "-night") == 0)) { + i++; + if (i < argc) { + j = 1; + free(nightfile); + if ((nightfile = (char *) malloc(strlen(argv[i]) + 1)) + == NULL) { + fprintf(stderr, "erreur memoire options nimap\n"); + exit(1); + }; + strcpy(nightfile, argv[i]); + use_nightmap = TRUE; + } else { + mqparam(); + i--; + } + } + + if (!j && (strcasecmp(argv[i], "-accel") == 0 + || strcasecmp(argv[i], "-accell") == 0 + || strcasecmp(argv[i], "-acc") == 0 + || strcasecmp(argv[i], "-multi") == 0)) { + i++; + if (i < argc) { + j = 1; + time_multi = atof(argv[i]); + if (time_multi < 1.0) + time_multi = 1.0; + if (time_multi > MAX_MULTI_COEF) + time_multi = MAX_MULTI_COEF; + if (time_multi > 24.0) + time_multi = floor(time_multi); + else + time_multi = floor(time_multi * 10.0) / 10.0; + } else { + mqparam(); + i--; + } + } + + if (!j && (strcasecmp(argv[i], "-nonimap") == 0 + || strcasecmp(argv[i], "-nonightmap") == 0 + || strcasecmp(argv[i], "-nonight") == 0 + || strcasecmp(argv[i], "-nomap") == 0)) { + j = 1; + use_nightmap = FALSE; + oknimap = FALSE; + } + + if (!j && (strcasecmp(argv[i], "-defnimap") == 0 + || strcasecmp(argv[i], "-defnightmap") == 0 + || strcasecmp(argv[i], "-defnight") == 0)) { + j = 1; + use_default_nightmap = TRUE; + } + + if (!j && strcasecmp(argv[i], "-zoom") == 0) { + i++; + if (i < argc) { + j = 1; + zoom = atof(argv[i]); + if (zoom < ZOOM_MIN) + zoom = ZOOM_MIN; + if (zoom > ZOOM_MAX) + zoom = ZOOM_MAX; + } else { + mqparam(); + i--; + } + } + + if (!j && strcasecmp(argv[i], "-dawn") == 0) { + i++; + if (i < argc) { + j = 1; + dawn = atof(argv[i]); + dawn = MAX(0.0, dawn); + dawn = MIN(1.0, dawn); + + dawn = (1.0 - dawn / 2.0); + } else { + mqparam(); + i--; + } + } + + if (!j && strcasecmp(argv[i], "-delay") == 0) { + i++; + if (i < argc) { + j = 1; + delay = atof(argv[i]); + if (delay < 0) + delay = 0; + if (delay > MAX_DELAY_SEC) + delay = MAX_DELAY_SEC; + } else { + mqparam(); + i--; + } + } + + if (!j && (strcasecmp(argv[i], "-dlat") == 0 + || strcasecmp(argv[i], "-lat") == 0 + || strcasecmp(argv[i], "-dlatitude") == 0)) { + i++; + if (i < argc) { + j = 1; + dlat = getdegre(argv[i]); + if (dlat < -MAX_DELTA_LONG) + dlat = -MAX_DELTA_LONG; + if (dlat > MAX_DELTA_LONG) + dlat = MAX_DELTA_LONG; + p_type = PTFIXED; + } else { + mqparam(); + i--; + } + } + + if (!j && (strcasecmp(argv[i], "-dlong") == 0 + || strcasecmp(argv[i], "-long") == 0 + || strcasecmp(argv[i], "-dlongitude") == 0)) { + i++; + if (i < argc) { + j = 1; + dlong = getdegre(argv[i]); + if (dlong < -MAX_DELTA_LONG) + dlong = -MAX_DELTA_LONG; + if (dlong > MAX_DELTA_LONG) + dlong = MAX_DELTA_LONG; + p_type = PTFIXED; + } else { + mqparam(); + i--; + } + } + + if (!j && strcasecmp(argv[i], "-light") == 0) { + i++; + if (i < argc) { + j = 1; + ambient_light = atof(argv[i]); + if (ambient_light < 0.) + ambient_light = 0.; + if (ambient_light > 1.) + ambient_light = 1.; + } else { + mqparam(); + i--; + } + } + + if (!j && strcasecmp(argv[i], "-time") == 0) { + i++; + if (i < argc) { + j = 1; + tbase.tv_sec = atoi(argv[i]); + tbase.tv_usec = 0; + } else { + mqparam(); + i--; + } + } + + if (!j && (strcasecmp(argv[i], "-bord") == 0 + || strcasecmp(argv[i], "-border") == 0)) { + i++; + if (i < argc) { + j = 1; + typecadre = atoi(argv[i]); + if (typecadre < 0) + typecadre = 0; + if (typecadre > 2) + typecadre = 2; + } else { + mqparam(); + i--; + } + } + + if (!j && strcasecmp(argv[i], "-fun") == 0) { + fun = TRUE; + i++; + if (i < argc) { + funx = atoi(argv[i]); + + i++; + if (i < argc) { + j = 1; + funy = atoi(argv[i]); + } else { + mqparam(); + i--; + } + } else { + mqparam(); + i--; + } + } + + if (!j && (strcasecmp(argv[i], "-pos") == 0 + || strcasecmp(argv[i], "-position") == 0 + || strcasecmp(argv[i], "-fixed") == 0)) { + p_type = PTFIXED; + i++; + if (i < argc) { + addlat = getdegre(argv[i]); + i++; + if (i < argc) { + j = 1; + addlong = getdegre(argv[i]); + } else { + mqparam(); + i--; + } + } else { + mqparam(); + i--; + } + } + +#if WITH_MARKERS + if (!j && (strcasecmp(argv[i], "-mk") == 0 + || strcasecmp(argv[i], "-marker") == 0)) { + if (nb_marker == MAX_MARKERS) { + fprintf(stderr, "Too many markers, max=%d\n", + MAX_MARKERS); + mqparam(); + } + i++; + if (i < argc) { + j = 1; + if (strcasecmp(argv[i], "sun") == 0) { + sun_marker = nb_marker; + nb_marker++; + } else if (strcasecmp(argv[i], "moon") == 0) { + moon_marker = nb_marker; + nb_marker++; + } else { + marker[nb_marker][1] = getdegre(argv[i]); + i++; + if (i < argc) { + marker[nb_marker][0] = getdegre(argv[i]); + nb_marker++; + } else { + mqparam(); + i--; + } + } + } else { + mqparam(); + i--; + } + } +#endif + + + if (!j && argv[i][0] == '-') { + printf("%s\n", WMGVERSION); + printf("\n"); + printf + ("-v : version -h : this help message !\n"); + printf + ("-zoom zoom_value : changing apparent size in icon\n"); + printf + ("-pos latitude long. : fixed initial position (default=follow sun)\n"); + printf("-sun : follow the sun (default)\n"); +#if WITH_MARKERS + printf("-moon : follow the moon\n"); +#endif + printf + ("-rand : random position at every refresh\n"); + printf + ("-map map_file : use this map for rendering\n"); + printf + ("-nimap night_file : and this one for the dark side of earth\n"); + printf + ("-defnimap : use the default night map (with a custom map)\n"); + printf + ("-nonimap : don't use the default night map\n"); + printf + ("-delay seconds : time between refresh of image\n"); + printf + ("-dlat delta_lat : latitude speed of point of view (default=follow sun)\n"); + printf("-dlong delta_long : the same for longitude\n"); + printf + ("-light light_value : level of light for dark side of earth, [0..1]\n"); + printf + ("-dawn dawn_value : level of continuity for dawn limit\n"); + printf + ("-bord border_num : 0 1 or 2 , type of icon border.\n"); + printf("-accel time_multi : time accelerator\n"); + printf + ("-time seconds : time to display in seconds since 01-01-1970\n"); + printf + ("-oz : start in \"austral\" mode (for \"down under\" people)\n"); + printf + ("-stable : keep the globe from going over the poles\n"); +#if WITH_MARKERS + printf + ("-mk latitude long. : position of a marker (or \"sun\", \"moon\")\n"); +#endif + printf + ("-fun dx dy : offset of vision... almost useless\n"); + printf + ("-w -shape : set by default (WMaker dockable application)\n"); + printf + ("-d display : display (WindowMaker not needed on the server side)\n"); + printf + ("left button : change longitude, with shift key, change latitude too\n"); + printf + ("middle button : zoom in, shift + middle button : zoom out\n"); + printf + ("right button : access to a few screens of parameters\n"); + exit(0); + } + } - return; + } + return; } /**************************************************************************** * X functions, mouse selection - * - */ + * + ****************************************************************************/ + -/* ------------------------------------------------------------------------ */ static int flush_expose(Window w) { - XEvent dummy; - int i = 0; + XEvent dummy; + int i = 0; - while (XCheckTypedWindowEvent(dpy, w, Expose, &dummy)) - i++; - return i; + while (XCheckTypedWindowEvent(dpy, w, Expose, &dummy)) + i++; + return i; } -/* ------------------------------------------------------------------------ */ + + + void RedrawWindowXYWH(int x, int y, int w, int h) { - flush_expose(iconwin); - XCopyArea(dpy, wmg.pixmap, iconwin, NormalGC, x, y, w, h, x, y); - flush_expose(win); - XCopyArea(dpy, wmg.pixmap, win, NormalGC, x, y, w, h, x, y); - return; + flush_expose(iconwin); + XCopyArea(dpy, wmg.pixmap, iconwin, NormalGC, x, y, w, h, x, y); + flush_expose(win); + XCopyArea(dpy, wmg.pixmap, win, NormalGC, x, y, w, h, x, y); + return; } -/* ------------------------------------------------------------------------ */ + + + void AddMouseRegion(int index, int left, int top, int right, int bottom) { - if (index < MAX_MOUSE_REGION) { - mouse_region[index].enable = 1; - mouse_region[index].top = top; - mouse_region[index].left = left; - mouse_region[index].bottom = bottom; - mouse_region[index].right = right; - } - return; + if (index < MAX_MOUSE_REGION) { + mouse_region[index].enable = 1; + mouse_region[index].top = top; + mouse_region[index].left = left; + mouse_region[index].bottom = bottom; + mouse_region[index].right = right; + } + return; } -/* ------------------------------------------------------------------------ */ + + + int CheckMouseRegion(int x, int y) { - int i; - int found; + int i; + int found; - found = 0; + found = 0; - for (i = 0; i < MAX_MOUSE_REGION && !found; i++) { - if (mouse_region[i].enable && - x <= mouse_region[i].right && - x >= mouse_region[i].left && - y <= mouse_region[i].bottom && - y >= mouse_region[i].top) - found = 1; - } - if (!found) - return -1; - return (i - 1); + for (i = 0; i < MAX_MOUSE_REGION && !found; i++) { + if (mouse_region[i].enable && + x <= mouse_region[i].right && + x >= mouse_region[i].left && + y <= mouse_region[i].bottom && y >= mouse_region[i].top) + found = 1; + } + if (!found) + return -1; + return (i - 1); } -/* ------------------------------------------------------------------------ */ -/* + + + +/**************************************************************************** * GRAPHIC : pixmap writing of letters & numbers - * - */ -/* ------------------------------------------------------------------------ */ + * + ****************************************************************************/ + static void chiffre(int ch, int xx, int yy) { - XCopyArea(dpy, numpix.pixmap, wmg.pixmap, NormalGC, - zapnum[ch][0], zapnum[ch][1], zapnum[ch][2], zapnum[ch][3], xx, yy); + XCopyArea(dpy, numpix.pixmap, wmg.pixmap, NormalGC, + zapnum[ch][0], zapnum[ch][1], zapnum[ch][2], zapnum[ch][3], + xx, yy); - return; + return; } -/* ------------------------------------------------------------------------ */ + + static int lettre(char c, int xx, int yy) { - int i; - if (c == '°') - i = 288; - else - switch (toupper(c)) { - case '0': - i = 0; - break; - case '1': - i = 6; - break; - case '2': - i = 12; - break; - case '3': - i = 18; - break; - case '4': - i = 24; - break; - case '5': - i = 30; - break; - case '6': - i = 36; - break; - case '7': - i = 42; - break; - case '8': - i = 48; - break; - case '9': - i = 54; - break; - case '+': - i = 60; - break; - case 'A': - i = 66; - break; - case 'B': - i = 72; - break; - case 'C': - i = 78; - break; - case 'D': - i = 84; - break; - case 'E': - i = 90; - break; - case 'F': - i = 96; - break; - case 'G': - i = 102; - break; - case 'H': - i = 108; - break; - case 'I': - i = 114; - break; - case 'J': - i = 120; - break; - case 'K': - i = 126; - break; - case 'L': - i = 132; - break; - case 'M': - i = 138; - break; - case 'N': - i = 144; - break; - case 'O': - i = 150; - break; - case 'P': - i = 156; - break; - case 'Q': - i = 162; - break; - case 'R': - i = 168; - break; - case 'S': - i = 174; - break; - case 'T': - i = 180; - break; - case 'U': - i = 186; - break; - case 'V': - i = 192; - break; - case 'W': - i = 198; - break; - case 'X': - i = 204; - break; - case 'Y': - i = 210; - break; - case 'Z': - i = 216; - break; - case ' ': - i = 222; - break; - case ':': - i = 228; - break; - case '/': - i = 234; - break; - case '!': - i = 240; - break; - case '*': - i = 246; - break; - case '-': - i = 252; - break; - case '.': - i = 258; - break; - case '=': - i = 264; - break; - case '#': - i = 270; - break; - case '<': - i = 276; - break; - case '>': - i = 282; - break; - case '"': - i = 294; - break; - case '\'': - i = 300; - break; - case ',': - i = 306; - break; - case '@': - i = 312; - break; - case '(': - i = 318; - break; - case ')': - i = 324; - break; - case '&': - i = 330; - break; - case '~': - i = 336; - break; - case 'Ł': - i = 342; - break; - case 'µ': - i = 348; - break; - case '{': - i = 354; - break; - case '}': - i = 360; - break; - case '[': - i = 366; - break; - case ']': - i = 372; - break; - case '\\': - i = 378; - break; - case '|': - i = 384; - break; - case '?': - i = 390; - break; - case '%': - i = 396; - break; - default: - i = 222; - break; - } + int i; + if (c == '°') + i = 288; + else + switch (toupper(c)) { + case '0': + i = 0; + break; + case '1': + i = 6; + break; + case '2': + i = 12; + break; + case '3': + i = 18; + break; + case '4': + i = 24; + break; + case '5': + i = 30; + break; + case '6': + i = 36; + break; + case '7': + i = 42; + break; + case '8': + i = 48; + break; + case '9': + i = 54; + break; + case '+': + i = 60; + break; + case 'A': + i = 66; + break; + case 'B': + i = 72; + break; + case 'C': + i = 78; + break; + case 'D': + i = 84; + break; + case 'E': + i = 90; + break; + case 'F': + i = 96; + break; + case 'G': + i = 102; + break; + case 'H': + i = 108; + break; + case 'I': + i = 114; + break; + case 'J': + i = 120; + break; + case 'K': + i = 126; + break; + case 'L': + i = 132; + break; + case 'M': + i = 138; + break; + case 'N': + i = 144; + break; + case 'O': + i = 150; + break; + case 'P': + i = 156; + break; + case 'Q': + i = 162; + break; + case 'R': + i = 168; + break; + case 'S': + i = 174; + break; + case 'T': + i = 180; + break; + case 'U': + i = 186; + break; + case 'V': + i = 192; + break; + case 'W': + i = 198; + break; + case 'X': + i = 204; + break; + case 'Y': + i = 210; + break; + case 'Z': + i = 216; + break; + case ' ': + i = 222; + break; + case ':': + i = 228; + break; + case '/': + i = 234; + break; + case '!': + i = 240; + break; + case '*': + i = 246; + break; + case '-': + i = 252; + break; + case '.': + i = 258; + break; + case '=': + i = 264; + break; + case '#': + i = 270; + break; + case '<': + i = 276; + break; + case '>': + i = 282; + break; + case '"': + i = 294; + break; + case '\'': + i = 300; + break; + case ',': + i = 306; + break; + case '@': + i = 312; + break; + case '(': + i = 318; + break; + case ')': + i = 324; + break; + case '&': + i = 330; + break; + case '~': + i = 336; + break; + case 'Ł': + i = 342; + break; + case 'µ': + i = 348; + break; + case '{': + i = 354; + break; + case '}': + i = 360; + break; + case '[': + i = 366; + break; + case ']': + i = 372; + break; + case '\\': + i = 378; + break; + case '|': + i = 384; + break; + case '?': + i = 390; + break; + case '%': + i = 396; + break; + default: + i = 222; + break; + } - XCopyArea(dpy, txtpix.pixmap, wmg.pixmap, NormalGC, - i, 0, 6, 10, xx, yy); - return xx + 6; + XCopyArea(dpy, txtpix.pixmap, wmg.pixmap, NormalGC, + i, 0, 6, 10, xx, yy); + return xx + 6; } -/* ------------------------------------------------------------------------ */ + + + static void write_icon(char *txt, int x, int y) { - int p, ok; - p = 0; + int p, ok; + p = 0; #ifdef DEBUG - fprintf(stdout, "%s_\n", txt); + fprintf(stdout, "%s_\n", txt); #endif - ok = TRUE; - while (ok) { - if (txt[p] == '\0' || x > DIAMETRE - 5) { - ok = FALSE; - } else { - x = lettre(txt[p], x, y); - p++; - } + ok = TRUE; + while (ok) { + if (txt[p] == '\0' || x > DIAMETRE - 5) { + ok = FALSE; + } else { + x = lettre(txt[p], x, y); + p++; } - return; + } + return; } -/* ------------------------------------------------------------------------ */ + + + static void press_but(int ckm) { - switch (ckm) { - case 5: - XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, - 0, 38, 20, 9, 2, 52); - RedrawWindowXYWH(2, 52, 20, 9); - break; - case 6: - XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, - 20, 38, 20, 9, 22, 52); - RedrawWindowXYWH(22, 52, 20, 9); - break; - case 7: - XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, - 40, 38, 20, 9, 42, 52); - RedrawWindowXYWH(42, 52, 20, 9); - break; - default: - break; - } - return; + switch (ckm) { + case 5: + XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, + 0, 38, 20, 9, 2, 52); + RedrawWindowXYWH(2, 52, 20, 9); + break; + case 6: + XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, + 20, 38, 20, 9, 22, 52); + RedrawWindowXYWH(22, 52, 20, 9); + break; + case 7: + XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, + 40, 38, 20, 9, 42, 52); + RedrawWindowXYWH(42, 52, 20, 9); + break; + default: + break; + } + return; } -/* ------------------------------------------------------------------------ */ + + + static void release_but(int ckm) { - switch (ckm) { - case 5: - XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, - 0, 28, 20, 9, 2, 52); - RedrawWindowXYWH(2, 52, 20, 9); - break; - case 6: - XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, - 20, 28, 20, 9, 22, 52); - RedrawWindowXYWH(22, 52, 20, 9); - break; - case 7: - XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, - 40, 28, 20, 9, 42, 52); - RedrawWindowXYWH(42, 52, 20, 9); - break; - default: - break; - } - return; + switch (ckm) { + case 5: + XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, + 0, 28, 20, 9, 2, 52); + RedrawWindowXYWH(2, 52, 20, 9); + break; + case 6: + XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, + 20, 28, 20, 9, 22, 52); + RedrawWindowXYWH(22, 52, 20, 9); + break; + case 7: + XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, + 40, 28, 20, 9, 42, 52); + RedrawWindowXYWH(42, 52, 20, 9); + break; + default: + break; + } + return; } -/* ------------------------------------------------------------------------ */ -/* + + + + +/*************************************************************************** * MENU SELECTION & ACTIONS - */ -/* ------------------------------------------------------------------------ */ + ***************************************************************************/ + + void screen_back() { - AddMouseRegion(0, 0, 0, 0, 0); - if (p_type == PTRANDOM) { - stoprand = STOP_RANDOM_FACTOR; - addlong = dv_long; - addlat = dv_lat; - } - gotoscr = 1; - while (gotoscr != 0) { - switch (gotoscr) { - case 1: - screen_1(); - break; - case 2: - screen_2(); - break; - case 3: - screen_3(); - break; - case 4: - screen_4(); - break; - case 5: - screen_5(); - break; - case 6: - screen_6(); - break; - case 7: - screen_7(); - break; - default: - break; - } - XFlush(dpy); + AddMouseRegion(0, 0, 0, 0, 0); + if (p_type == PTRANDOM) { + stoprand = STOP_RANDOM_FACTOR; + addlong = dv_long; + addlat = dv_lat; + } + gotoscr = 1; + while (gotoscr != 0) { + switch (gotoscr) { + case 1: + screen_1(); + break; + case 2: + screen_2(); + break; + case 3: + screen_3(); + break; + case 4: + screen_4(); + break; + case 5: + screen_5(); + break; + case 6: + screen_6(); + break; + case 7: + screen_7(); + break; + default: + break; } + XFlush(dpy); + } /* * put old environment */ - XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, pixmask, ShapeSet); - XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, pixmask, ShapeSet); + XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, pixmask, ShapeSet); + XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, pixmask, + ShapeSet); - AddMouseRegion(0, 5, 5, DIAMETRE - 4, DIAMETRE - 4); - stoprand = FALSE; - do_something = TRUE; + AddMouseRegion(0, 5, 5, DIAMETRE - 4, DIAMETRE - 4); + stoprand = FALSE; + do_something = TRUE; - return; + return; } -/* ------------------------------------------------------------------------ */ + + + static void display_pos(double la, double lo) { - int c, i, j, k, l, neg; + int c, i, j, k, l, neg; - if (la > 0) { - neg = 10; + if (la > 0) { + neg = 10; + } else { + neg = 11; + la *= -1; + } + i = floor(la / 10.0); + la -= 10 * i; + j = floor(la); + la -= j; + la *= 60; + k = floor(la / 10.0); + la -= 10 * k; + l = floor(la); + + if (i == 0) { + i = neg; + neg = 10; + } + chiffre(neg, platd[1][0], platd[1][1]); + chiffre(i, platd[2][0], platd[2][1]); + chiffre(j, platd[3][0], platd[3][1]); + chiffre(k, platm[0][0], platd[0][1]); + chiffre(l, platm[1][0], platd[1][1]); + + if (lo > 0) { + neg = 12; + } else { + neg = 11; + lo *= -1; + } + c = floor(lo / 100.0); + lo -= c * 100; + if (c > 0) { + if (neg == 11) + neg = 13; + } else { + if (neg == 11) { + c = neg; } else { - neg = 11; - la *= -1; + c = 10; } - i = floor(la / 10.0); - la -= 10 * i; - j = floor(la); - la -= j; - la *= 60; - k = floor(la / 10.0); - la -= 10 * k; - l = floor(la); + neg = 12; + } + i = floor(lo / 10.0); + lo -= 10 * i; + j = floor(lo); + lo -= j; + lo *= 60; + k = floor(lo / 10.0); + lo -= 10 * k; + l = floor(lo); + if (i == 0 && c > 9) { + i = c; + c = 10; + } + chiffre(neg, plongd[0][0], plongd[0][1]); + chiffre(c, plongd[1][0], plongd[1][1]); + chiffre(i, plongd[2][0], plongd[2][1]); + chiffre(j, plongd[3][0], plongd[3][1]); + chiffre(k, plongm[0][0], plongm[0][1]); + chiffre(l, plongm[1][0], plongm[1][1]); - if (i == 0) { - i = neg; - neg = 10; - } - chiffre(neg, platd[1][0], platd[1][1]); - chiffre(i, platd[2][0], platd[2][1]); - chiffre(j, platd[3][0], platd[3][1]); - chiffre(k, platm[0][0], platd[0][1]); - chiffre(l, platm[1][0], platd[1][1]); - - if (lo > 0) { - neg = 12; - } else { - neg = 11; - lo *= -1; - } - c = floor(lo / 100.0); - lo -= c * 100; - if (c > 0) { - if (neg == 11) - neg = 13; - } else { - if (neg == 11) { - c = neg; - } else { - c = 10; - } - neg = 12; - } - i = floor(lo / 10.0); - lo -= 10 * i; - j = floor(lo); - lo -= j; - lo *= 60; - k = floor(lo / 10.0); - lo -= 10 * k; - l = floor(lo); - if (i == 0 && c > 9) { - i = c; - c = 10; - } - chiffre(neg, plongd[0][0], plongd[0][1]); - chiffre(c, plongd[1][0], plongd[1][1]); - chiffre(i, plongd[2][0], plongd[2][1]); - chiffre(j, plongd[3][0], plongd[3][1]); - chiffre(k, plongm[0][0], plongm[0][1]); - chiffre(l, plongm[1][0], plongm[1][1]); - - RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE); - return; + RedrawWindowXYWH(0, 0, DIAMETRE, DIAMETRE); + return; } -/* ------------------------------------------------------------------------ */ + + + void rotation_terre(int x, int y, int lat_flag) { /* - * earth rotate after (while) a clic + * earth rotate after (while) a clic */ - double mx, my; - mx = (double) ((double) x - DIAMETRE / 2 + 0.5) / zoom * cos(v_lat) * sens; - if (lat_flag) { - my = -(double) ((double) y - DIAMETRE / 2 + 0.5) * sens / zoom; - if (my > 0.0) - my += ABS(sin(v_lat) * ((double) x - DIAMETRE / 2 + 0.5) / zoom); - else - my -= ABS(sin(v_lat) * ((double) x - DIAMETRE / 2 + 0.5) / zoom); - } else { - my = 0; - } - if (p_type == PTRANDOM) { - stoprand = STOP_RANDOM_FACTOR; - addlong = dv_long; - addlat = dv_lat; - } - addlong += mx * RATIO_ROTATE; - addlat += my * RATIO_ROTATE; + double mx, my; + mx = + (double) ((double) x - DIAMETRE / 2 + + 0.5) / zoom * cos(v_lat) * sens; + if (lat_flag) { + my = -(double) ((double) y - DIAMETRE / 2 + 0.5) * sens / zoom; + if (my > 0.0) + my += + ABS(sin(v_lat) * ((double) x - DIAMETRE / 2 + 0.5) / zoom); + else + my -= + ABS(sin(v_lat) * ((double) x - DIAMETRE / 2 + 0.5) / zoom); + } else { + my = 0; + } + if (p_type == PTRANDOM) { + stoprand = STOP_RANDOM_FACTOR; + addlong = dv_long; + addlat = dv_lat; + } + addlong += mx * RATIO_ROTATE; + addlat += my * RATIO_ROTATE; - do_something = TRUE; - return; + do_something = TRUE; + return; } -/* ------------------------------------------------------------------------ */ + + + static void move_earth(double vla, double vlo) { - addlat += vla; - addlong += vlo; + addlat += vla; + addlong += vlo; - switch (p_type) { - case PTSUNREL: - setViewPos(sun_lat * 180. / PI + addlat, - sun_long * 180. / PI + addlong); - break; - - case PTFIXED: - case PTRANDOM: - setViewPos(addlat, addlong); - break; - default: - break; - } - display_pos(dv_lat, dv_long); - return; + switch (p_type) { + case PTSUN: + setViewPos(sun_lat * 180. / PI + addlat, + sun_long * 180. / PI + addlong); + break; +#if WITH_MARKERS + case PTMOON: + setViewPos(moon_lat * 180. / PI + addlat, + moon_long * 180. / PI + addlong); + break; +#endif + case PTFIXED: + case PTRANDOM: + setViewPos(addlat, addlong); + break; + default: + break; + } + display_pos(dv_lat, dv_long); + return; } -/* ------------------------------------------------------------------------ */ + + + static void screen_1() { - int ok, ckm, sensadd, waitrel, not3; - struct timeval tin; + int ok, ckm, sensadd, waitrel, not3; + struct timeval tin; #ifdef DEBUG - fprintf(stdout, "scr 1\n"); + fprintf(stdout, "scr 1\n"); #endif - tin = getimev(); - waitrel = 0; - ckm = 0; - sensadd = 1; - not3 = TRUE; + tin = getimev(); + waitrel = 0; + ckm = 0; + sensadd = 1; + not3 = TRUE; - XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, screenpos.mask, ShapeSet); - XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, screenpos.mask, ShapeSet); + XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, screenpos.mask, + ShapeSet); + XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, screenpos.mask, + ShapeSet); - XCopyArea(dpy, screenpos.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE, DIAMETRE, 0, 0); + XCopyArea(dpy, screenpos.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE, + DIAMETRE, 0, 0); - AddMouseRegion(1, platd[0][0], platd[0][1], platd[3][0] + 9, platd[3][1] + 12); - AddMouseRegion(2, platm[0][0], platm[0][1], platm[1][0] + 9, platm[1][1] + 12); - AddMouseRegion(3, plongd[0][0], plongd[0][1], plongd[3][0] + 9, plongd[3][1] + 12); - AddMouseRegion(4, plongm[0][0], plongm[0][1], plongm[1][0] + 9, plongm[1][1] + 12); - AddMouseRegion(5, 1, 51, 21, 61); - AddMouseRegion(6, 22, 51, 41, 61); - AddMouseRegion(7, 42, 51, 62, 61); + AddMouseRegion(1, platd[0][0], platd[0][1], platd[3][0] + 9, + platd[3][1] + 12); + AddMouseRegion(2, platm[0][0], platm[0][1], platm[1][0] + 9, + platm[1][1] + 12); + AddMouseRegion(3, plongd[0][0], plongd[0][1], plongd[3][0] + 9, + plongd[3][1] + 12); + AddMouseRegion(4, plongm[0][0], plongm[0][1], plongm[1][0] + 9, + plongm[1][1] + 12); + AddMouseRegion(5, 1, 51, 21, 61); + AddMouseRegion(6, 22, 51, 41, 61); + AddMouseRegion(7, 42, 51, 62, 61); - display_pos(dv_lat, dv_long); + display_pos(dv_lat, dv_long); - ok = TRUE; - while (ok) { - 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: - ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); - waitrel = 1; - press_but(ckm); - switch (Event.xbutton.button) { - case 1: - not3 = TRUE; - sensadd = 1; - break; - case 2: - not3 = TRUE; - sensadd = -1; - break; - case 3: - not3 = FALSE; - if (ckm < 5) - gotoscr = 0; - default: - break; - } - break; - case ButtonRelease: - release_but(ckm); - waitrel = ckm; - ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); - if (waitrel == ckm) { - switch (ckm) { - case 5: - gotoscr--; - if (gotoscr == 0) - gotoscr = NUM_SCREEN; - break; - case 6: - gotoscr++; - if (gotoscr > NUM_SCREEN) - gotoscr = 1; - break; - case 7: - gotoscr = 0; - default: - break; - } - } - ckm = 0; - waitrel = 0; - tin = getimev(); - break; - default: - break; - - } - } - usleep(VAL_USLEEP_SHORT); - if (waitrel && not3) { - if (ckm == 1) { - move_earth(sens * sensadd * 1.0, 0.0); - usleep(VAL_USLEEP); - } - if (ckm == 2) { - move_earth(sens * sensadd * 1.0 / 60.0, 0.0); - usleep(VAL_USLEEP); - } - if (ckm == 3) { - move_earth(0.0, sens * sensadd * 1.0); - usleep(VAL_USLEEP); - } - if (ckm == 4) { - move_earth(0.0, sens * sensadd * 1.0 / 60.0); - usleep(VAL_USLEEP); - } - } - if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT && gotoscr == 1) + ok = TRUE; + while (ok) { + 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: + ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); + waitrel = 1; + press_but(ckm); + switch (Event.xbutton.button) { + case 1: + not3 = TRUE; + sensadd = 1; + break; + case 2: + not3 = TRUE; + sensadd = -1; + break; + case 3: + not3 = FALSE; + if (ckm < 5) gotoscr = 0; - if (gotoscr != 1) - ok = FALSE; + default: + break; + } + break; + case ButtonRelease: + release_but(ckm); + waitrel = ckm; + ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); + if (waitrel == ckm) { + switch (ckm) { + case 5: + gotoscr--; + if (gotoscr == 0) + gotoscr = NUM_SCREEN; + break; + case 6: + gotoscr++; + if (gotoscr > NUM_SCREEN) + gotoscr = 1; + break; + case 7: + gotoscr = 0; + default: + break; + } + } + ckm = 0; + waitrel = 0; + tin = getimev(); + break; + default: + break; + + } } - return; + usleep(VAL_USLEEP_SHORT); + if (waitrel && not3) { + if (ckm == 1) { + move_earth(sens * sensadd * 1.0, 0.0); + usleep(VAL_USLEEP); + } + if (ckm == 2) { + move_earth(sens * sensadd * 1.0 / 60.0, 0.0); + usleep(VAL_USLEEP); + } + if (ckm == 3) { + move_earth(0.0, sens * sensadd * 1.0); + usleep(VAL_USLEEP); + } + if (ckm == 4) { + move_earth(0.0, sens * sensadd * 1.0 / 60.0); + usleep(VAL_USLEEP); + } + } + if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT + && gotoscr == 1) + gotoscr = 0; + if (gotoscr != 1) + ok = FALSE; + } + return; } -/* ------------------------------------------------------------------------ */ + + + static void display_date(double la, double lo) { - char datest[32]; - time_t t; - int i, j; + char datest[32]; + time_t t; + int i, j; - write_icon(" time :", 2, 2); - RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1); + write_icon(" time :", 2, 2); + RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1); - write_icon(" GMT+long.", 2, 14); - RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1); + write_icon(" GMT+long.", 2, 14); + RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1); - t = trend.tv_sec; - t += (int) (floor((lo + 7.5) / 15.0) * 3600); + t = trend.tv_sec; + t += (int) (floor((lo + 7.5) / 15.0) * 3600); /*** pb near 2038 ***/ - strftime(datest, 30, "%x", gmtime(&t)); + strftime(datest, 30, "%x", gmtime(&t)); - i = 10 - strlen(datest); - if (i < 0) - i = 0; - else - i = i / 2; + i = 10 - strlen(datest); + if (i < 0) + i = 0; + else + i = i / 2; - write_icon(datest, 2 + i * 6, 26); - RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1); + write_icon(datest, 2 + i * 6, 26); + RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1); - strftime(datest, 30, "%X", gmtime(&t)); + strftime(datest, 30, "%X", gmtime(&t)); - i = 10 - strlen(datest); - if (i < 0) { - i = 0; - while (datest[i] != '\0') { - if (datest[i] != ' ') { - i++; - } else { - j = i; - do { - datest[j] = datest[j + 1]; - j++; - } - while (datest[j - 1] != '\0'); - } + i = 10 - strlen(datest); + if (i < 0) { + i = 0; + while (datest[i] != '\0') { + if (datest[i] != ' ') { + i++; + } else { + j = i; + do { + datest[j] = datest[j + 1]; + j++; } - i = 0; - } else { - i = i / 2; + while (datest[j - 1] != '\0'); + } } + i = 0; + } else { + i = i / 2; + } - write_icon(datest, 2 + i * 6, 38); - RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1); + write_icon(datest, 2 + i * 6, 38); + RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1); - return; + return; } -/* ------------------------------------------------------------------------ */ + + + static void screen_2() { - int ok, ckm, waitrel; - struct timeval tin; + int ok, ckm, waitrel; + struct timeval tin; #ifdef DEBUG - fprintf(stdout, "scr 2\n"); + fprintf(stdout, "scr 2\n"); #endif - tin = getimev(); - waitrel = 0; - ckm = 0; + tin = getimev(); + waitrel = 0; + ckm = 0; - XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask, ShapeSet); - XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask, ShapeSet); + XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask, + ShapeSet); + XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask, + ShapeSet); - XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE, DIAMETRE, 0, 0); + XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE, + DIAMETRE, 0, 0); - display_date(dv_lat, dv_long); + display_date(dv_lat, dv_long); - ok = TRUE; - while (ok) { - 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: - ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); - waitrel = 1; - press_but(ckm); - switch (Event.xbutton.button) { - case 1: - break; - case 2: - break; - case 3: - if (ckm < 5) - gotoscr = 0; - break; - default: - break; - } - break; - case ButtonRelease: - release_but(ckm); - waitrel = ckm; - ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); - if (waitrel == ckm) { - switch (ckm) { - case 5: - gotoscr--; - if (gotoscr == 0) - gotoscr = NUM_SCREEN; - break; - case 6: - gotoscr++; - if (gotoscr > NUM_SCREEN) - gotoscr = 1; - break; - case 7: - gotoscr = 0; - default: - break; - } - } - ckm = 0; - waitrel = 0; - tin = getimev(); - break; - default: - break; - - } - } - usleep(VAL_USLEEP_SHORT); - - if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT && gotoscr == 2) + ok = TRUE; + while (ok) { + 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: + ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); + waitrel = 1; + press_but(ckm); + switch (Event.xbutton.button) { + case 1: + break; + case 2: + break; + case 3: + if (ckm < 5) gotoscr = 0; - if (gotoscr != 2) - ok = FALSE; + break; + default: + break; + } + break; + case ButtonRelease: + release_but(ckm); + waitrel = ckm; + ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); + if (waitrel == ckm) { + switch (ckm) { + case 5: + gotoscr--; + if (gotoscr == 0) + gotoscr = NUM_SCREEN; + break; + case 6: + gotoscr++; + if (gotoscr > NUM_SCREEN) + gotoscr = 1; + break; + case 7: + gotoscr = 0; + default: + break; + } + } + ckm = 0; + waitrel = 0; + tin = getimev(); + break; + default: + break; + + } } - return; + usleep(VAL_USLEEP_SHORT); + + if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT + && gotoscr == 2) + gotoscr = 0; + if (gotoscr != 2) + ok = FALSE; + } + return; } -/* ------------------------------------------------------------------------ */ + + + static void display_zoom() { - char datest[32], dstr[32]; - int i; + char datest[32], dstr[32]; + int i; - write_icon(" delay :", 2, 2); - RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1); + write_icon(" delay :", 2, 2); + RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1); - sprintf(dstr, "%f", delay); - dstr[8] = '\0'; - i = strlen(dstr) - 1; - while (i > 0) { - if (dstr[i] == '0') { - dstr[i] = '\0'; - i--; - } else { - i = 0; - } + sprintf(dstr, "%f", delay); + dstr[8] = '\0'; + i = strlen(dstr) - 1; + while (i > 0) { + if (dstr[i] == '0') { + dstr[i] = '\0'; + i--; + } else { + i = 0; } - i = strlen(dstr) - 1; - if (dstr[i] == '.') - dstr[i] = '\0'; - sprintf(datest, "%s s", dstr); + } + i = strlen(dstr) - 1; + if (dstr[i] == '.') + dstr[i] = '\0'; + sprintf(datest, "%s s", dstr); - i = 10 - strlen(datest); - if (i < 0) - i = 0; - else - i = i / 2; - write_icon(datest, 2 + i * 6, 14); - RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1); + i = 10 - strlen(datest); + if (i < 0) + i = 0; + else + i = i / 2; + write_icon(datest, 2 + i * 6, 14); + RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1); - write_icon(" zoom :", 2, 26); - RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1); + write_icon(" zoom :", 2, 26); + RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1); - sprintf(datest, "%.3f", zoom); - i = 10 - strlen(datest); - if (i < 0) - i = 0; - else - i = i / 2; - write_icon(datest, 2 + i * 6, 38); - RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1); + sprintf(datest, "%.3f", zoom); + i = 10 - strlen(datest); + if (i < 0) + i = 0; + else + i = i / 2; + write_icon(datest, 2 + i * 6, 38); + RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1); - return; + return; } -/* ------------------------------------------------------------------------ */ + + + static void move_delay(int factor) { - if (factor == 1) { - if (delay < (double) VAL_USLEEP / 1000000) - delay = (double) VAL_USLEEP / 1000000; - else if (delay < 0.1) { - delay += 0.01; - if (delay > 0.1) - delay = 0.2; - } else if (delay < 1.) { - delay += 0.1; - if (delay > 1.0) - delay = 2.; - } else if (delay < 60.) - delay += 1.; - else if (delay < 300.) - delay += 10.; - else if (delay < 3600.) - delay += 60.; - else if (delay < MAX_DELAY_SEC) - delay += 360.; + if (factor == 1) { + if (delay < (double) VAL_USLEEP / 1000000) + delay = (double) VAL_USLEEP / 1000000; + else if (delay < 0.1) { + delay += 0.01; + if (delay > 0.1) + delay = 0.2; + } else if (delay < 1.) { + delay += 0.1; + if (delay > 1.0) + delay = 2.; + } else if (delay < 60.) + delay += 1.; + else if (delay < 300.) + delay += 10.; + else if (delay < 3600.) + delay += 60.; + else if (delay < MAX_DELAY_SEC) + delay += 360.; - if (delay > MAX_DELAY_SEC) - delay = MAX_DELAY_SEC; - } else { - if (delay > 3600.) - delay -= 360.; - else if (delay > 300.) - delay -= 60.; - else if (delay > 60.) - delay -= 10.; - else if (delay > 1.) - delay -= 1.; - else if (delay > 0.1) - delay -= 0.1; - else if (delay > (double) VAL_USLEEP / 1000000) - delay -= 0.01; - else - delay = 0.0; + if (delay > MAX_DELAY_SEC) + delay = MAX_DELAY_SEC; + } else { + if (delay > 3600.) + delay -= 360.; + else if (delay > 300.) + delay -= 60.; + else if (delay > 60.) + delay -= 10.; + else if (delay > 1.) + delay -= 1.; + else if (delay > 0.1) + delay -= 0.1; + else if (delay > (double) VAL_USLEEP / 1000000) + delay -= 0.01; + else + delay = 0.0; - if (delay < (double) VAL_USLEEP / 1000000) - delay = 0.0; - } + if (delay < (double) VAL_USLEEP / 1000000) + delay = 0.0; + } - tdelay.tv_sec = (int) floor(delay); - tdelay.tv_usec = (int) ((delay - tdelay.tv_sec) * 1000000); + tdelay.tv_sec = (int) floor(delay); + tdelay.tv_usec = (int) ((delay - tdelay.tv_sec) * 1000000); - XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, - 0, 15, 60, 10, 2, 14); + XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, + 0, 15, 60, 10, 2, 14); - display_zoom(); - return; + display_zoom(); + return; } -/* ------------------------------------------------------------------------ */ + + + void zooming(int facto) { - if (facto) - zoom /= ZOOM_FACTOR; - else - zoom *= ZOOM_FACTOR; - zoom = MAX(zoom, ZOOM_MIN); - zoom = MIN(zoom, ZOOM_MAX); - if (p_type == PTRANDOM) { - addlong = dv_long; - addlat = dv_lat; - stoprand = STOP_RANDOM_FACTOR; - } - calcDistance(); - do_something = TRUE; - return; + if (facto) + zoom /= ZOOM_FACTOR; + else + zoom *= ZOOM_FACTOR; + zoom = MAX(zoom, ZOOM_MIN); + zoom = MIN(zoom, ZOOM_MAX); + if (p_type == PTRANDOM) { + addlong = dv_long; + addlat = dv_lat; + stoprand = STOP_RANDOM_FACTOR; + } + calcDistance(); + do_something = TRUE; + return; } -/* ------------------------------------------------------------------------ */ + + + static void move_zoom(int factor) { - if (factor == -1) - zooming(1); - else - zooming(0); - XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, - 0, 15, 60, 10, 2, 38); - display_zoom(); - return; + if (factor == -1) + zooming(1); + else + zooming(0); + XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, + 0, 15, 60, 10, 2, 38); + display_zoom(); + return; } -/* ------------------------------------------------------------------------ */ + + + static void screen_3() { - int ok, ckm, waitrel, sensadd, not3; - struct timeval tin; + int ok, ckm, waitrel, sensadd, not3; + struct timeval tin; #ifdef DEBUG - fprintf(stdout, "scr 3\n"); + fprintf(stdout, "scr 3\n"); #endif - tin = getimev(); - waitrel = 0; - ckm = 0; - sensadd = 0; - not3 = TRUE; - XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask, ShapeSet); - XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask, ShapeSet); + tin = getimev(); + waitrel = 0; + ckm = 0; + sensadd = 0; + not3 = TRUE; + XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask, + ShapeSet); + XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask, + ShapeSet); - XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE, DIAMETRE, 0, 0); + XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE, + DIAMETRE, 0, 0); - AddMouseRegion(1, 2, 14, DIAMETRE - 2, 25); - AddMouseRegion(2, 2, 38, DIAMETRE - 2, 49); - display_zoom(); + AddMouseRegion(1, 2, 14, DIAMETRE - 2, 25); + AddMouseRegion(2, 2, 38, DIAMETRE - 2, 49); + display_zoom(); - ok = TRUE; - while (ok) { + ok = TRUE; + while (ok) { - 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: - ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); - waitrel = 1; - press_but(ckm); - switch (Event.xbutton.button) { - case 1: - not3 = TRUE; - sensadd = 1; - break; - case 2: - not3 = TRUE; - sensadd = -1; - break; - case 3: - not3 = FALSE; - if (ckm < 5) - gotoscr = 0; - break; - default: - break; - } - break; - case ButtonRelease: - release_but(ckm); - waitrel = ckm; - ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); - if (waitrel == ckm) { - switch (ckm) { - case 5: - gotoscr--; - if (gotoscr == 0) - gotoscr = NUM_SCREEN; - break; - case 6: - gotoscr++; - if (gotoscr > NUM_SCREEN) - gotoscr = 1; - break; - case 7: - gotoscr = 0; - default: - break; - } - } - ckm = 0; - waitrel = 0; - tin = getimev(); - break; - default: - break; - - } - } - usleep(VAL_USLEEP_SHORT); - if (waitrel && not3) { - if (ckm == 1) { - move_delay(sensadd); - usleep(2 * VAL_USLEEP); - } - if (ckm == 2) { - move_zoom(sensadd); - usleep(VAL_USLEEP); - } - } - if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT && gotoscr == 3) + 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: + ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); + waitrel = 1; + press_but(ckm); + switch (Event.xbutton.button) { + case 1: + not3 = TRUE; + sensadd = 1; + break; + case 2: + not3 = TRUE; + sensadd = -1; + break; + case 3: + not3 = FALSE; + if (ckm < 5) gotoscr = 0; - if (gotoscr != 3) - ok = FALSE; + break; + default: + break; + } + break; + case ButtonRelease: + release_but(ckm); + waitrel = ckm; + ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); + if (waitrel == ckm) { + switch (ckm) { + case 5: + gotoscr--; + if (gotoscr == 0) + gotoscr = NUM_SCREEN; + break; + case 6: + gotoscr++; + if (gotoscr > NUM_SCREEN) + gotoscr = 1; + break; + case 7: + gotoscr = 0; + default: + break; + } + } + ckm = 0; + waitrel = 0; + tin = getimev(); + break; + default: + break; + + } } - return; + usleep(VAL_USLEEP_SHORT); + if (waitrel && not3) { + if (ckm == 1) { + move_delay(sensadd); + usleep(2 * VAL_USLEEP); + } + if (ckm == 2) { + move_zoom(sensadd); + usleep(VAL_USLEEP); + } + } + if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT + && gotoscr == 3) + gotoscr = 0; + if (gotoscr != 3) + ok = FALSE; + } + return; } -/* ------------------------------------------------------------------------ */ + + + static void display_light() { - char datest[32]; - int i; + char datest[32]; + int i; - write_icon(" light :", 2, 2); - RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1); + write_icon(" light :", 2, 2); + RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1); - sprintf(datest, "%.2f", ambient_light); - i = 10 - strlen(datest); - if (i < 0) - i = 0; - else - i = i / 2; - write_icon(datest, 2 + i * 6, 14); - RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1); + sprintf(datest, "%.2f", ambient_light); + i = 10 - strlen(datest); + if (i < 0) + i = 0; + else + i = i / 2; + write_icon(datest, 2 + i * 6, 14); + RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1); - write_icon(" dawn :", 2, 26); - RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1); + write_icon(" dawn :", 2, 26); + RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1); - dawn = (1.0 - dawn) * 2.0; - sprintf(datest, "%.2f", dawn); - dawn = (1.0 - dawn / 2.0); - i = 10 - strlen(datest); - if (i < 0) - i = 0; - else - i = i / 2; - write_icon(datest, 2 + i * 6, 38); - RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1); + dawn = (1.0 - dawn) * 2.0; + sprintf(datest, "%.2f", dawn); + dawn = (1.0 - dawn / 2.0); + i = 10 - strlen(datest); + if (i < 0) + i = 0; + else + i = i / 2; + write_icon(datest, 2 + i * 6, 38); + RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1); - return; + return; } -/* ------------------------------------------------------------------------ */ + + + static void move_light(int factor) { - ambient_light += factor / 20.0; - ambient_light = MAX(0.0, ambient_light); - ambient_light = MIN(1.0, ambient_light); - aml = (int) floor(ambient_light * 256); + ambient_light += factor / 20.0; + ambient_light = MAX(0.0, ambient_light); + ambient_light = MIN(1.0, ambient_light); + aml = (int) floor(ambient_light * 256); - XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, - 0, 15, 60, 10, 2, 14); + XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, + 0, 15, 60, 10, 2, 14); - display_light(); - return; + display_light(); + return; } -/* ------------------------------------------------------------------------ */ + + + static void move_dawn(int factor) { - dawn = (1.0 - dawn) * 2.0; - dawn += factor / 20.0; - dawn = MAX(0.0, dawn); - dawn = MIN(1.0, dawn); - dawn = (1.0 - dawn / 2.0); - XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, - 0, 15, 60, 10, 2, 38); + dawn = (1.0 - dawn) * 2.0; + dawn += factor / 20.0; + dawn = MAX(0.0, dawn); + dawn = MIN(1.0, dawn); + dawn = (1.0 - dawn / 2.0); + XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, + 0, 15, 60, 10, 2, 38); - display_light(); - return; + display_light(); + return; } -/* ------------------------------------------------------------------------ */ + + + static void screen_4() { - int ok, ckm, waitrel, sensadd, not3; - struct timeval tin; + int ok, ckm, waitrel, sensadd, not3; + struct timeval tin; #ifdef DEBUG - fprintf(stdout, "scr 4\n"); + fprintf(stdout, "scr 4\n"); #endif - tin = getimev(); - waitrel = 0; - ckm = 0; - sensadd = 0; - not3 = TRUE; - XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask, ShapeSet); - XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask, ShapeSet); + tin = getimev(); + waitrel = 0; + ckm = 0; + sensadd = 0; + not3 = TRUE; + XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask, + ShapeSet); + XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask, + ShapeSet); - XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE, DIAMETRE, 0, 0); + XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE, + DIAMETRE, 0, 0); - AddMouseRegion(1, 2, 14, DIAMETRE - 2, 25); - AddMouseRegion(2, 2, 38, DIAMETRE - 2, 49); - display_light(); + AddMouseRegion(1, 2, 14, DIAMETRE - 2, 25); + AddMouseRegion(2, 2, 38, DIAMETRE - 2, 49); + display_light(); - ok = TRUE; - while (ok) { + ok = TRUE; + while (ok) { - 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: - ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); - waitrel = 1; - press_but(ckm); - switch (Event.xbutton.button) { - case 1: - not3 = TRUE; - sensadd = 1; - break; - case 2: - not3 = TRUE; - sensadd = -1; - break; - case 3: - not3 = FALSE; - if (ckm < 5) - gotoscr = 0; - break; - default: - break; - } - break; - case ButtonRelease: - release_but(ckm); - waitrel = ckm; - ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); - if (waitrel == ckm) { - switch (ckm) { - case 5: - gotoscr--; - if (gotoscr == 0) - gotoscr = NUM_SCREEN; - break; - case 6: - gotoscr++; - if (gotoscr > NUM_SCREEN) - gotoscr = 1; - break; - case 7: - gotoscr = 0; - default: - break; - } - } - ckm = 0; - waitrel = 0; - tin = getimev(); - break; - default: - break; - } - } - usleep(VAL_USLEEP_SHORT); - if (waitrel && not3) { - if (ckm == 1) { - move_light(sensadd); - usleep(VAL_USLEEP); - } - if (ckm == 2) { - move_dawn(sensadd); - usleep(VAL_USLEEP); - } - } - if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT && gotoscr == 4) + 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: + ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); + waitrel = 1; + press_but(ckm); + switch (Event.xbutton.button) { + case 1: + not3 = TRUE; + sensadd = 1; + break; + case 2: + not3 = TRUE; + sensadd = -1; + break; + case 3: + not3 = FALSE; + if (ckm < 5) gotoscr = 0; - if (gotoscr != 4) - ok = FALSE; + break; + default: + break; + } + break; + case ButtonRelease: + release_but(ckm); + waitrel = ckm; + ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); + if (waitrel == ckm) { + switch (ckm) { + case 5: + gotoscr--; + if (gotoscr == 0) + gotoscr = NUM_SCREEN; + break; + case 6: + gotoscr++; + if (gotoscr > NUM_SCREEN) + gotoscr = 1; + break; + case 7: + gotoscr = 0; + default: + break; + } + } + ckm = 0; + waitrel = 0; + tin = getimev(); + break; + default: + break; + } } - return; + usleep(VAL_USLEEP_SHORT); + if (waitrel && not3) { + if (ckm == 1) { + move_light(sensadd); + usleep(VAL_USLEEP); + } + if (ckm == 2) { + move_dawn(sensadd); + usleep(VAL_USLEEP); + } + } + if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT + && gotoscr == 4) + gotoscr = 0; + if (gotoscr != 4) + ok = FALSE; + } + return; } -/* ------------------------------------------------------------------------ */ + + + static void display_accel() { - char datest[32]; - int i; + char datest[32]; + int i; - write_icon(" accel :", 2, 2); - RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1); + write_icon(" accel :", 2, 2); + RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1); - if (time_multi < 24.0) - sprintf(datest, "%.1f", time_multi); - else - sprintf(datest, "%.0f", time_multi); + if (time_multi < 24.0) + sprintf(datest, "%.1f", time_multi); + else + sprintf(datest, "%.0f", time_multi); - i = 10 - strlen(datest); - if (i < 0) - i = 0; - else - i = i / 2; - write_icon(datest, 2 + i * 6, 14); - RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1); + i = 10 - strlen(datest); + if (i < 0) + i = 0; + else + i = i / 2; + write_icon(datest, 2 + i * 6, 14); + RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1); - write_icon("night map:", 2, 26); - RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1); + write_icon("night map:", 2, 26); + RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1); - if (use_nightmap) - write_icon(" yes ", 2, 38); - else - write_icon(" no ", 2, 38); + if (use_nightmap) + write_icon(" yes ", 2, 38); + else + write_icon(" no ", 2, 38); - RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1); + RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1); - return; + return; } -/* ------------------------------------------------------------------------ */ + + + static void move_accel(int factor) { - if (factor == 1) { - if (time_multi < 1.0) - time_multi = 1.0; - if (time_multi < 24.0) - time_multi += 0.2; - else if (time_multi < 60.0) { - time_multi = floor(time_multi); - time_multi += 1.0; - } else if (time_multi < 120.0) { - time_multi = floor(time_multi); - time_multi += 2.0; - } else if (time_multi < 240.0) { - time_multi = floor(time_multi); - time_multi += 4.0; - } else if (time_multi < 600.0) { - time_multi = floor(time_multi); - time_multi += 10.0; - } else if (time_multi < 1200.0) { - time_multi = floor(time_multi); - time_multi += 20.0; - } else if (time_multi < 2400.0) { - time_multi = floor(time_multi); - time_multi += 40.0; - } else if (time_multi < 6000.0) { - time_multi = floor(time_multi); - time_multi += 100.0; - } else if (time_multi < 12000.0) { - time_multi = floor(time_multi); - time_multi += 200.0; - } else if (time_multi < 24000.0) { - time_multi = floor(time_multi); - time_multi += 400.0; - } else if (time_multi < 60000.0) { - time_multi = floor(time_multi); - time_multi += 1000.0; - } else if (time_multi < 120000.0) { - time_multi = floor(time_multi); - time_multi += 2000.0; - } else if (time_multi < 240000.0) { - time_multi = floor(time_multi); - time_multi += 4000.0; - } else { - time_multi = floor(time_multi); - time_multi += 8000.0; - } - if (time_multi > MAX_MULTI_COEF) - time_multi = MAX_MULTI_COEF; + if (factor == 1) { + if (time_multi < 1.0) + time_multi = 1.0; + if (time_multi < 24.0) + time_multi += 0.2; + else if (time_multi < 60.0) { + time_multi = floor(time_multi); + time_multi += 1.0; + } else if (time_multi < 120.0) { + time_multi = floor(time_multi); + time_multi += 2.0; + } else if (time_multi < 240.0) { + time_multi = floor(time_multi); + time_multi += 4.0; + } else if (time_multi < 600.0) { + time_multi = floor(time_multi); + time_multi += 10.0; + } else if (time_multi < 1200.0) { + time_multi = floor(time_multi); + time_multi += 20.0; + } else if (time_multi < 2400.0) { + time_multi = floor(time_multi); + time_multi += 40.0; + } else if (time_multi < 6000.0) { + time_multi = floor(time_multi); + time_multi += 100.0; + } else if (time_multi < 12000.0) { + time_multi = floor(time_multi); + time_multi += 200.0; + } else if (time_multi < 24000.0) { + time_multi = floor(time_multi); + time_multi += 400.0; + } else if (time_multi < 60000.0) { + time_multi = floor(time_multi); + time_multi += 1000.0; + } else if (time_multi < 120000.0) { + time_multi = floor(time_multi); + time_multi += 2000.0; + } else if (time_multi < 240000.0) { + time_multi = floor(time_multi); + time_multi += 4000.0; } else { - if (time_multi < 24.1) - time_multi -= 0.2; - else if (time_multi < 60.2) { - time_multi = floor(time_multi); - time_multi -= 1.0; - } else if (time_multi < 121.0) { - time_multi = floor(time_multi); - time_multi -= 2.0; - } else if (time_multi < 241.0) { - time_multi = floor(time_multi); - time_multi -= 4.0; - } else if (time_multi < 601.0) { - time_multi = floor(time_multi); - time_multi -= 10.0; - } else if (time_multi < 1201.0) { - time_multi = floor(time_multi); - time_multi -= 20.0; - } else if (time_multi < 2401.0) { - time_multi = floor(time_multi); - time_multi -= 40.0; - } else if (time_multi < 6001.0) { - time_multi = floor(time_multi); - time_multi -= 100.0; - } else if (time_multi < 12001.0) { - time_multi = floor(time_multi); - time_multi -= 200.0; - } else if (time_multi < 24001.0) { - time_multi = floor(time_multi); - time_multi -= 400.0; - } else if (time_multi < 60001.0) { - time_multi = floor(time_multi); - time_multi -= 1000.0; - } else if (time_multi < 120001.0) { - time_multi = floor(time_multi); - time_multi -= 2000.0; - } else if (time_multi < 240001.0) { - time_multi = floor(time_multi); - time_multi -= 4000.0; - } else { - time_multi = floor(time_multi); - time_multi -= 8000.0; - } - - if (time_multi > 24.0) - time_multi = floor(time_multi); - if (time_multi < 1.0) - time_multi = 1.0; + time_multi = floor(time_multi); + time_multi += 8000.0; + } + if (time_multi > MAX_MULTI_COEF) + time_multi = MAX_MULTI_COEF; + } else { + if (time_multi < 24.1) + time_multi -= 0.2; + else if (time_multi < 60.2) { + time_multi = floor(time_multi); + time_multi -= 1.0; + } else if (time_multi < 121.0) { + time_multi = floor(time_multi); + time_multi -= 2.0; + } else if (time_multi < 241.0) { + time_multi = floor(time_multi); + time_multi -= 4.0; + } else if (time_multi < 601.0) { + time_multi = floor(time_multi); + time_multi -= 10.0; + } else if (time_multi < 1201.0) { + time_multi = floor(time_multi); + time_multi -= 20.0; + } else if (time_multi < 2401.0) { + time_multi = floor(time_multi); + time_multi -= 40.0; + } else if (time_multi < 6001.0) { + time_multi = floor(time_multi); + time_multi -= 100.0; + } else if (time_multi < 12001.0) { + time_multi = floor(time_multi); + time_multi -= 200.0; + } else if (time_multi < 24001.0) { + time_multi = floor(time_multi); + time_multi -= 400.0; + } else if (time_multi < 60001.0) { + time_multi = floor(time_multi); + time_multi -= 1000.0; + } else if (time_multi < 120001.0) { + time_multi = floor(time_multi); + time_multi -= 2000.0; + } else if (time_multi < 240001.0) { + time_multi = floor(time_multi); + time_multi -= 4000.0; + } else { + time_multi = floor(time_multi); + time_multi -= 8000.0; } - tini = tlast; - tbase = trend; + if (time_multi > 24.0) + time_multi = floor(time_multi); + if (time_multi < 1.0) + time_multi = 1.0; + } - XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, - 0, 15, 60, 10, 2, 14); + tini = tlast; + tbase = trend; - display_accel(); - return; + XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, + 0, 15, 60, 10, 2, 14); + + display_accel(); + return; } -/* ------------------------------------------------------------------------ */ + + + static void screen_5() { - int ok, ckm, waitrel, sensadd, not3; - struct timeval tin; + int ok, ckm, waitrel, sensadd, not3; + struct timeval tin; #ifdef DEBUG - fprintf(stdout, "scr 5\n"); + fprintf(stdout, "scr 5\n"); #endif - tin = getimev(); - waitrel = 0; - ckm = 0; - sensadd = 0; - not3 = TRUE; - XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask, ShapeSet); - XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask, ShapeSet); + tin = getimev(); + waitrel = 0; + ckm = 0; + sensadd = 0; + not3 = TRUE; + XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask, + ShapeSet); + XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask, + ShapeSet); - XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE, DIAMETRE, 0, 0); + XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE, + DIAMETRE, 0, 0); - AddMouseRegion(1, 2, 14, DIAMETRE - 2, 25); - AddMouseRegion(2, 2, 38, DIAMETRE - 2, 49); - display_accel(); + AddMouseRegion(1, 2, 14, DIAMETRE - 2, 25); + AddMouseRegion(2, 2, 38, DIAMETRE - 2, 49); + display_accel(); - ok = TRUE; - while (ok) { + ok = TRUE; + while (ok) { - 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: - ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); - waitrel = 1; - press_but(ckm); - switch (Event.xbutton.button) { - case 1: - not3 = TRUE; - sensadd = 1; - break; - case 2: - not3 = TRUE; - sensadd = -1; - break; - case 3: - not3 = FALSE; - if (ckm < 5) - gotoscr = 0; - break; - default: - break; - } - break; - case ButtonRelease: - release_but(ckm); - waitrel = ckm; - ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); - if (waitrel == ckm) { - switch (ckm) { - case 5: - gotoscr--; - if (gotoscr == 0) - gotoscr = NUM_SCREEN; - break; - case 6: - gotoscr++; - if (gotoscr > NUM_SCREEN) - gotoscr = 1; - break; - case 7: - gotoscr = 0; - default: - break; - } - } - ckm = 0; - waitrel = 0; - tin = getimev(); - break; - default: - break; - - } - } - usleep(VAL_USLEEP_SHORT); - if (waitrel && not3) { - if (ckm == 1) { - move_accel(sensadd); - usleep(VAL_USLEEP); - } - if (ckm == 2) { - not3 = FALSE; - if (use_nightmap) { - use_nightmap = FALSE; - display_accel(); - } else { - if (use_nmap_ini) { - use_nightmap = TRUE; - display_accel(); - } - } - usleep(VAL_USLEEP); - } - } - if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT && gotoscr == 5) + 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: + ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); + waitrel = 1; + press_but(ckm); + switch (Event.xbutton.button) { + case 1: + not3 = TRUE; + sensadd = 1; + break; + case 2: + not3 = TRUE; + sensadd = -1; + break; + case 3: + not3 = FALSE; + if (ckm < 5) gotoscr = 0; - if (gotoscr != 5) - ok = FALSE; + break; + default: + break; + } + break; + case ButtonRelease: + release_but(ckm); + waitrel = ckm; + ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); + if (waitrel == ckm) { + switch (ckm) { + case 5: + gotoscr--; + if (gotoscr == 0) + gotoscr = NUM_SCREEN; + break; + case 6: + gotoscr++; + if (gotoscr > NUM_SCREEN) + gotoscr = 1; + break; + case 7: + gotoscr = 0; + default: + break; + } + } + ckm = 0; + waitrel = 0; + tin = getimev(); + break; + default: + break; + + } } - return; + usleep(VAL_USLEEP_SHORT); + if (waitrel && not3) { + if (ckm == 1) { + move_accel(sensadd); + usleep(VAL_USLEEP); + } + if (ckm == 2) { + not3 = FALSE; + if (use_nightmap) { + use_nightmap = FALSE; + display_accel(); + } else { + if (use_nmap_ini) { + use_nightmap = TRUE; + display_accel(); + } + } + usleep(VAL_USLEEP); + } + } + if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT + && gotoscr == 5) + gotoscr = 0; + if (gotoscr != 5) + ok = FALSE; + } + return; } -/* ------------------------------------------------------------------------ */ + + + static void display_dlat() { - char datest[32]; - int i, d, m, nega, nego; + char datest[32]; + int i, d, m, nega, nego; - write_icon(" dlat :", 2, 2); - RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1); - if (dlat < 0.0) { - nega = TRUE; - dlat *= -1; - } else - nega = FALSE; + write_icon(" dlat :", 2, 2); + RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1); + if (dlat < 0.0) { + nega = TRUE; + dlat *= -1; + } else + nega = FALSE; - m = (int) floor((dlat - floor(dlat)) * 60.0); - d = (int) floor(dlat); + m = (int) floor((dlat - floor(dlat)) * 60.0); + d = (int) floor(dlat); - if (nega) { - sprintf(datest, "-%d°%02d'", d, m); - dlat *= -1; - } else - sprintf(datest, "%d°%02d'", d, m); + if (nega) { + sprintf(datest, "-%d°%02d'", d, m); + dlat *= -1; + } else + sprintf(datest, "%d°%02d'", d, m); - i = 10 - strlen(datest); - if (i < 0) - i = 0; - else - i = i / 2; - write_icon(datest, 2 + i * 6, 14); - RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1); + i = 10 - strlen(datest); + if (i < 0) + i = 0; + else + i = i / 2; + write_icon(datest, 2 + i * 6, 14); + RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1); - write_icon(" dlong :", 2, 26); - RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1); + write_icon(" dlong :", 2, 26); + RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1); - if (dlong < 0.0) { - nego = TRUE; - dlong *= -1; - } else - nego = FALSE; + if (dlong < 0.0) { + nego = TRUE; + dlong *= -1; + } else + nego = FALSE; - m = (int) floor((dlong - floor(dlong)) * 60.0); - d = (int) floor(dlong); + m = (int) floor((dlong - floor(dlong)) * 60.0); + d = (int) floor(dlong); - if (nego) { - sprintf(datest, "-%d°%02d'", d, m); - dlong *= -1; - } else - sprintf(datest, "%d°%02d'", d, m); + if (nego) { + sprintf(datest, "-%d°%02d'", d, m); + dlong *= -1; + } else + sprintf(datest, "%d°%02d'", d, m); - i = 10 - strlen(datest); - if (i < 0) - i = 0; - else - i = i / 2; - write_icon(datest, 2 + i * 6, 38); - RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1); + i = 10 - strlen(datest); + if (i < 0) + i = 0; + else + i = i / 2; + write_icon(datest, 2 + i * 6, 38); + RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1); - return; + return; } -/* ------------------------------------------------------------------------ */ + + + static void move_dlat(int factor) { - dlat += factor / 4.0; - if (dlat > MAX_DELTA_LONG) - dlat = MAX_DELTA_LONG; - if (dlat < -MAX_DELTA_LONG) - dlat = -MAX_DELTA_LONG; - if (dlat < 0.25 && dlat > -0.25) - dlat = 0; - XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, - 0, 15, 60, 10, 2, 14); - if (dlat != 0.) - p_type = PTFIXED; - display_dlat(); - return; + dlat += factor / 4.0; + if (dlat > MAX_DELTA_LONG) + dlat = MAX_DELTA_LONG; + if (dlat < -MAX_DELTA_LONG) + dlat = -MAX_DELTA_LONG; + if (dlat < 0.25 && dlat > -0.25) + dlat = 0; + XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, + 0, 15, 60, 10, 2, 14); + if (dlat != 0.) + p_type = PTFIXED; + display_dlat(); + return; } -/* ------------------------------------------------------------------------ */ + + + static void move_dlong(int factor) { - dlong += factor / 4.0; - if (dlong > MAX_DELTA_LONG) - dlong = MAX_DELTA_LONG; - if (dlong < -MAX_DELTA_LONG) - dlong = -MAX_DELTA_LONG; - if (dlong < 0.25 && dlong > -0.25) - dlong = 0; - XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, - 0, 15, 60, 10, 2, 38); - if (dlong != 0.) - p_type = PTFIXED; - display_dlat(); - return; + dlong += factor / 4.0; + if (dlong > MAX_DELTA_LONG) + dlong = MAX_DELTA_LONG; + if (dlong < -MAX_DELTA_LONG) + dlong = -MAX_DELTA_LONG; + if (dlong < 0.25 && dlong > -0.25) + dlong = 0; + XCopyArea(dpy, scrdiv.pixmap, wmg.pixmap, NormalGC, + 0, 15, 60, 10, 2, 38); + if (dlong != 0.) + p_type = PTFIXED; + display_dlat(); + return; } -/* ------------------------------------------------------------------------ */ + + + static void screen_6() { - int ok, ckm, waitrel, sensadd, not3; - struct timeval tin; + int ok, ckm, waitrel, sensadd, not3; + struct timeval tin; #ifdef DEBUG - fprintf(stdout, "scr 6\n"); + fprintf(stdout, "scr 6\n"); #endif - tin = getimev(); - waitrel = 0; - sensadd = 0; - ckm = 0; - not3 = TRUE; - XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask, ShapeSet); - XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask, ShapeSet); + tin = getimev(); + waitrel = 0; + sensadd = 0; + ckm = 0; + not3 = TRUE; + XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask, + ShapeSet); + XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask, + ShapeSet); - XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE, DIAMETRE, 0, 0); - AddMouseRegion(1, 2, 14, DIAMETRE - 2, 25); - AddMouseRegion(2, 2, 38, DIAMETRE - 2, 49); + XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE, + DIAMETRE, 0, 0); + AddMouseRegion(1, 2, 14, DIAMETRE - 2, 25); + AddMouseRegion(2, 2, 38, DIAMETRE - 2, 49); - display_dlat(); + display_dlat(); - ok = TRUE; - while (ok) { + ok = TRUE; + while (ok) { - 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: - ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); - waitrel = 1; - press_but(ckm); - switch (Event.xbutton.button) { - case 1: - not3 = TRUE; - sensadd = 1; - break; - case 2: - not3 = TRUE; - sensadd = -1; - break; - case 3: - not3 = FALSE;; - if (ckm < 5) - gotoscr = 0; - break; - default: - break; - } - break; - case ButtonRelease: - release_but(ckm); - waitrel = ckm; - ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); - if (waitrel == ckm) { - switch (ckm) { - case 5: - gotoscr--; - if (gotoscr == 0) - gotoscr = NUM_SCREEN; - break; - case 6: - gotoscr++; - if (gotoscr > NUM_SCREEN) - gotoscr = 1; - break; - case 7: - gotoscr = 0; - default: - break; - } - } - ckm = 0; - waitrel = 0; - tin = getimev(); - break; - default: - break; - - } - } - usleep(VAL_USLEEP_SHORT); - if (waitrel && not3) { - if (ckm == 1 && p_type != PTRANDOM) { - move_dlat(sensadd); - usleep(VAL_USLEEP); - } - if (ckm == 2 && p_type != PTRANDOM) { - move_dlong(sensadd); - usleep(VAL_USLEEP); - } - } - if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT && gotoscr == 6) + 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: + ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); + waitrel = 1; + press_but(ckm); + switch (Event.xbutton.button) { + case 1: + not3 = TRUE; + sensadd = 1; + break; + case 2: + not3 = TRUE; + sensadd = -1; + break; + case 3: + not3 = FALSE;; + if (ckm < 5) gotoscr = 0; - if (gotoscr != 6) - ok = FALSE; + break; + default: + break; + } + break; + case ButtonRelease: + release_but(ckm); + waitrel = ckm; + ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); + if (waitrel == ckm) { + switch (ckm) { + case 5: + gotoscr--; + if (gotoscr == 0) + gotoscr = NUM_SCREEN; + break; + case 6: + gotoscr++; + if (gotoscr > NUM_SCREEN) + gotoscr = 1; + break; + case 7: + gotoscr = 0; + default: + break; + } + } + ckm = 0; + waitrel = 0; + tin = getimev(); + break; + default: + break; + + } } - return; + usleep(VAL_USLEEP_SHORT); + if (waitrel && not3) { + if (ckm == 1 && p_type != PTRANDOM) { + move_dlat(sensadd); + usleep(VAL_USLEEP); + } + if (ckm == 2 && p_type != PTRANDOM) { + move_dlong(sensadd); + usleep(VAL_USLEEP); + } + } + if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT + && gotoscr == 6) + gotoscr = 0; + if (gotoscr != 6) + ok = FALSE; + } + return; } -/* ------------------------------------------------------------------------ */ + + + static void display_type() { - char c, cc, mess[12]; + char c, cc, mess[12]; - write_icon(" view :", 2, 2); - RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1); + write_icon(" view :", 2, 2); + RedrawWindowXYWH(2, 2, DIAMETRE - 1, DIAMETRE - 1); - if (p_type == PTFIXED) { - c = '>'; - cc = '<'; - } else { - c = ' '; - cc = ' '; - } - sprintf(mess, "%c move %c", c, cc); - write_icon(mess, 2, 14); - RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1); - if (p_type == PTSUNREL) { - c = '>'; - cc = '<'; - } else { - c = ' '; - cc = ' '; - } - sprintf(mess, "%c sun %c", c, cc); - write_icon(mess, 2, 26); - RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1); - if (p_type == PTRANDOM) { - c = '>'; - cc = '<'; - } else { - c = ' '; - cc = ' '; - } - sprintf(mess, "%c random %c", c, cc); - write_icon(mess, 2, 38); - RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1); + if (p_type == PTFIXED) { + c = '>'; + cc = '<'; + } else { + c = ' '; + cc = ' '; + } + sprintf(mess, "%c move %c", c, cc); + write_icon(mess, 2, 14); + RedrawWindowXYWH(2, 14, DIAMETRE - 1, DIAMETRE - 1); + if (p_type == PTSUN) { + c = '>'; + cc = '<'; + } else { + c = ' '; + cc = ' '; + } + sprintf(mess, "%c sun %c", c, cc); + write_icon(mess, 2, 26); + RedrawWindowXYWH(2, 26, DIAMETRE - 1, DIAMETRE - 1); +#if WITH_MARKERS + if (p_type == PTMOON) { + c = '>'; + cc = '<'; + } else { + c = ' '; + cc = ' '; + } + sprintf(mess, "%c moon %c", c, cc); +#else + if (p_type == PTRANDOM) { + c = '>'; + cc = '<'; + } else { + c = ' '; + cc = ' '; + } + sprintf(mess, "%c random %c", c, cc); +#endif + write_icon(mess, 2, 38); + RedrawWindowXYWH(2, 38, DIAMETRE - 1, DIAMETRE - 1); - return; + return; } -/* ------------------------------------------------------------------------ */ + + + static void screen_7() { - int ok, ckm, waitrel, sensadd, not3; - struct timeval tin; + int ok, ckm, waitrel, sensadd, not3; + struct timeval tin; #ifdef DEBUG - fprintf(stdout, "scr 7\n"); + fprintf(stdout, "scr 7\n"); #endif - tin = getimev(); - waitrel = 0; - sensadd = 0; - ckm = 0; - not3 = TRUE; + tin = getimev(); + waitrel = 0; + sensadd = 0; + ckm = 0; + not3 = TRUE; - XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask, ShapeSet); - XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask, ShapeSet); + XShapeCombineMask(dpy, win, ShapeBounding, 0, 0, scrdate.mask, + ShapeSet); + XShapeCombineMask(dpy, iconwin, ShapeBounding, 0, 0, scrdate.mask, + ShapeSet); - XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE, DIAMETRE, 0, 0); - AddMouseRegion(1, 2, 14, DIAMETRE - 2, 25); - AddMouseRegion(2, 2, 26, DIAMETRE - 2, 37); - AddMouseRegion(3, 2, 38, DIAMETRE - 2, 49); + XCopyArea(dpy, scrdate.pixmap, wmg.pixmap, NormalGC, 0, 0, DIAMETRE, + DIAMETRE, 0, 0); + AddMouseRegion(1, 2, 14, DIAMETRE - 2, 25); + AddMouseRegion(2, 2, 26, DIAMETRE - 2, 37); + AddMouseRegion(3, 2, 38, DIAMETRE - 2, 49); - display_type(0); + display_type(); - ok = TRUE; - while (ok) { + ok = TRUE; + while (ok) { - 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: - ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); - waitrel = 1; - press_but(ckm); - switch (Event.xbutton.button) { - case 1: - not3 = TRUE; - if (ckm < 4 && ckm > 0) - sensadd = ckm; - break; - case 2: - not3 = TRUE; - break; - case 3: - not3 = FALSE; - if (ckm < 5) - gotoscr = 0; - break; - default: - break; - } - break; - case ButtonRelease: - release_but(ckm); - waitrel = ckm; - ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); - if (waitrel == ckm) { - switch (ckm) { - case 5: - gotoscr--; - if (gotoscr == 0) - gotoscr = NUM_SCREEN; - break; - case 6: - gotoscr++; - if (gotoscr > NUM_SCREEN) - gotoscr = 1; - break; - case 7: - gotoscr = 0; - default: - break; - } - } - ckm = 0; - waitrel = 0; - tin = getimev(); - break; - default: - break; - } - } - usleep(VAL_USLEEP_SHORT); - if (waitrel && not3 && sensadd) { - if (sensadd == 2) { - if (p_type != PTSUNREL) { - p_type = PTSUNREL; - dlat = 0; - dlong = 0; - display_type(); - } - } - if (sensadd == 1) { - if (p_type != PTFIXED) { - p_type = PTFIXED; - display_type(); - } - } - if (sensadd == 3) { - if (p_type != PTRANDOM) { - p_type = PTRANDOM; - dlat = 0; - dlong = 0; - display_type(); - } - } - } - sensadd = 0; - if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT && gotoscr == 7) + 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: + ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); + waitrel = 1; + press_but(ckm); + switch (Event.xbutton.button) { + case 1: + not3 = TRUE; + if (ckm < 4 && ckm > 0) + sensadd = ckm; + break; + case 2: + not3 = TRUE; + break; + case 3: + not3 = FALSE; + if (ckm < 5) gotoscr = 0; - if (gotoscr != 7) - ok = FALSE; + break; + default: + break; + } + break; + case ButtonRelease: + release_but(ckm); + waitrel = ckm; + ckm = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); + if (waitrel == ckm) { + switch (ckm) { + case 5: + gotoscr--; + if (gotoscr == 0) + gotoscr = NUM_SCREEN; + break; + case 6: + gotoscr++; + if (gotoscr > NUM_SCREEN) + gotoscr = 1; + break; + case 7: + gotoscr = 0; + default: + break; + } + } + ckm = 0; + waitrel = 0; + tin = getimev(); + break; + default: + break; + } } - return; + usleep(VAL_USLEEP_SHORT); + if (waitrel && not3 && sensadd) { + if (sensadd == 2) { + if (p_type != PTSUN) { + p_type = PTSUN; + dlat = 0; + dlong = 0; + display_type(); + } + } + if (sensadd == 1) { + if (p_type != PTFIXED) { + p_type = PTFIXED; + display_type(); + } + } + if (sensadd == 3) { +#if WITH_MARKERS + if (p_type != PTMOON) { + p_type = PTMOON; +#else + if (p_type != PTRANDOM) { + p_type = PTRANDOM; +#endif + dlat = 0; + dlong = 0; + display_type(); + } + } + } + sensadd = 0; + if (waitrel == 0 && diftimev(getimev(), tin).tv_sec > SCREEN_WAIT + && gotoscr == 7) + gotoscr = 0; + if (gotoscr != 7) + ok = FALSE; + } + return; } -/* ------------------------------------------------------------------------ */ diff --git a/wmglobe/src/wraster.h b/wmglobe/src/wraster.h deleted file mode 100644 index 0e42af5..0000000 --- a/wmglobe/src/wraster.h +++ /dev/null @@ -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 // - * 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 -#endif - - -#include -#include - -#ifdef XSHM -#include -#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 diff --git a/wmglobe/src/zapnum.h b/wmglobe/src/zapnum.h index 7c7a388..5ce656a 100644 --- a/wmglobe/src/zapnum.h +++ b/wmglobe/src/zapnum.h @@ -1,37 +1,36 @@ -/* WMGlobe 0.5.pre1 - All the Earth on a WMaker Icon - * copyright (C) 1998,99 Jerome Dumonteil - * +/* WMGlobe 1.3 - All the Earth on a WMaker Icon + * copyright (C) 1998,99,2000,01 Jerome Dumonteil + * * 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program 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 General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * 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} }; diff --git a/wmglobe/wmglobe.1 b/wmglobe/wmglobe.1 index 680ffca..01aa877 100644 --- a/wmglobe/wmglobe.1 +++ b/wmglobe/wmglobe.1 @@ -1,6 +1,6 @@ -.TH WMGlobe 1 "fevrier 1999" +.TH WMGlobe 1.3 "august 2001" .SH NAME -WMGlobe - The Whole Earth spinning on you desktop... +WMGlobe - The Whole Earth spinning on you desktop... as a dockable app for WindowMaker .SH SYNOPSIS .B wmglobe @@ -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 +WMGlobe v.1.3 12 aug 2001 .TP .B \-h short help @@ -23,58 +23,66 @@ short help Value > 1 to magnify the view, value < 1 to lower. Default: 1.0 .TP .B \-pos \fI latitude longitude\fP -Initial viewing fixed at this position, don't follow +Initial viewing fixed at this position, don't follow 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 +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 -PNM, TIFF but none BMP. +Map used for the rendering. Can be JPEG, GIF, XPM +PNM, TIFF but none BMP. Default: use internal map of earth. .TP .B \-nimap \fI night_file\fP Map used for the dark side of the earth. Must be of -the same width x height as the day side map. +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. +a default internal night file (see -nonimap option). +.TP +.B \-defnimap +Use the default night map (with a custom map). .TP .B \-nonimap -Don't use the default night map. +Don't use the default night map. .TP .B \-delay \fI seconds\fP -Time in seconds between each calculation of a new +Time in seconds between each calculation of a new position. Limited to 0.04 at compile time (25 frames -per second should be enough). The sun position move +per second should be enough). The sun position move only once per minute, so if you use wmglobe without -dlong or -accel option, the CPU cost of WMGlobe is *very* low. The use of very low value for -delay plus --dlong and -accel can be CPU costly (but very nice...). +-dlong and -accel can be CPU costly (but very nice...). Default: 1.0 sec. .TP .B \-dlat \fI delta_latitude\fP Move the point of view by delta_lat degrees per second, -with a value of 6 the earth make a full rotation in +with a value of 6 the earth make a full rotation in one minute. The value can be formated as -pos option. Default: 0°0'0 .TP -.B \-dlong \fI delta_long\fP -Move the point of view by delta_long degrees per -second. With a value of -0°0'15" the earth make a full -rotation in 24 hours toward the west. By default, +.B \-dlong \fI delta_long\fP +Move the point of view by delta_long degrees per +second. With a value of -0°0'15" the earth make a full +rotation in 24 hours toward the west. By default, -dlong and -dlat are null. If they are used, the view follow their values. Going back to "follow sun" mode in parameters screen put -dlat and -dlong to zero. .TP .B \-light \fI light_value\fP Level of light of the dark side when there is no -night map, from 0 to 1. -Default: 0.25 +night map, from 0 to 1. +Default: 0.25 .TP .B \-dawn \fI dawn_value\fP Level of continuity for dawn limit, from 0 to 1. With @@ -83,9 +91,9 @@ at maximum contrast. Default: 0.2 .TP .B \-bord \fI border_num\fP -0 1 or 2. There are 3 different borders for the icon. -Default: 0 -.TP +0 1 or 2. There are 3 different borders for the icon. +Default: 2 +.TP .B \-accel \fI time_multi\fP Time warp factor. With -accel 24, the sun make a full rotation in one hour (or the earth, I'm not sure). Default: 1.0 @@ -97,18 +105,28 @@ 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. .TP .B \-oz -Start in "austral" mode (for "down under" people) +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 -.B \-w \-shape -Useless, since it is set by default (WMaker dockable +.B \-w \-shape +Useless, since it is set by default (WMaker dockable application) .SH "MOUSE OPTIONS" .TP @@ -124,30 +142,30 @@ Displays 7 screens of parameters. On every screen, just clic with left or right button on the figures to change their value. The TIME screen shows an approximation of date and time of the earth zone currently displayed, -using GMT time + longitude offset, it's close to the -real local time by one or two hours. Others options +using GMT time + longitude offset, it's close to the +real local time by one or two hours. Others options don't need more help. Intuitive they said... .SH "FILES" .TP .B MAPS -Like XGlobe, WMGlobe needs a longitude/latitude map to work. By default, -it uses a low quality built-in map of earth. But you will probably want +Like XGlobe, WMGlobe needs a longitude/latitude map to work. By default, +it uses a low quality built-in map of earth. But you will probably want to use better ones. You can get maps usable with WMGlobe on the net. See the links below. using custom maps: -For the image to be mapped correctly, position 0°North 0°West must be in +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. .TP .B Links: Where to find maps and similar softs -where to find the sources of wmglobe: +where to find the sources of wmglobe: the web page of WMGlobe (made by Sylvestre Taburet): - + where to find maps and similar softs: @@ -163,7 +181,7 @@ XGlobe Homepage: (many links to map of earth) -Xearth Homepage: +Xearth Homepage: @@ -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,18 +200,20 @@ The Window Maker User Guide The Window Maker FAQ .SH "AUTHOR" -jerome dumonteil +jerome dumonteil Patches, bug reports, and suggestions are welcome. .SH "CREDITS" -WMGlobe is Copyright (C) 1998,99 by Jerome Dumonteil and licensed through -the GNU General Public License. +WMGlobe is Copyright (C) 1998,99 by Jerome Dumonteil and licensed through +the GNU General Public License. Read the COPYING file for the complete GNU license. -Original idea, tests, logos: +Original idea, tests, logos: -Sylvestre Taburet +Sylvestre Taburet + +WindowMaker 0.62 fix : Charles G Waldman The code in 'sunpos.cpp' is taken from Xearth by Kirk Lauritz Johnson. @@ -224,7 +245,7 @@ documentation. The rendering engine is taken from XGlobe by Thorsten Scheuermann XGlobe Homepage: http://www.uni-karlsruhe.de/~uddn/xglobe -Raster graphics library by Alfredo K. Kojima, & stuff of Window Maker +Raster graphics library by Alfredo K. Kojima, & stuff of Window Maker by A. K. Kojima, Dan Pascu, Matthew Hawkins & team @@ -234,9 +255,10 @@ If you use the --enable-single-icon compile time option of WindowMaker, you can not display more than one WMGlobe. WMGlobe hopes that an overflow of a long integer dont generate an error -and that LONG_MAX +1 = LONG_MIN . This happens with high values of -accel +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. diff --git a/wmglobe/wmgmap.gif b/wmglobe/wmgmap.gif deleted file mode 100644 index 759d194..0000000 Binary files a/wmglobe/wmgmap.gif and /dev/null differ diff --git a/wmglobe/wmgmap.jpeg b/wmglobe/wmgmap.jpeg new file mode 100644 index 0000000..06ce41d Binary files /dev/null and b/wmglobe/wmgmap.jpeg differ