X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Ft3d.c;h=8b7ee7ed6f64b3cfad0a012f5fc552eeb2bad99a;hb=40eacb5812ef7c0e3374fb139afbb4f5bc8bbfb5;hp=ae0396e514ae94222b364dfbc7cbc9940ffae1c6;hpb=f54438ea00f152166e68073e98000fd3a00f65cd;p=xscreensaver diff --git a/hacks/t3d.c b/hacks/t3d.c index ae0396e5..8b7ee7ed 100644 --- a/hacks/t3d.c +++ b/hacks/t3d.c @@ -13,15 +13,13 @@ of the command-line options provided by screenhack.c. */ -#undef FASTDRAW +#define FASTDRAW +#define FASTCOPY #undef USE_POLYGON -#ifdef FASTDRAW -# define FASTCOPY -#endif - #include #include +#include /* for localtime() and gettimeofday() */ #include "screenhack.h" @@ -61,7 +59,8 @@ int timewait=40000; #define frac(argument) argument-floor(argument) -#define abs(x) ((x)<0.0 ? -(x) : (x)) +#undef ABS +#define ABS(x) ((x)<0.0 ? -(x) : (x)) static Colormap cmap; /* static XColor gray1; */ @@ -136,11 +135,17 @@ static double gettime (void) { struct timeval time1; - struct timezone zone1; struct tm *zeit; - + time_t lt; + +#ifdef GETTIMEOFDAY_TWO_ARGS + struct timezone zone1; gettimeofday(&time1,&zone1); - zeit=localtime(&time1.tv_sec); +#else + gettimeofday(&time1); +#endif + lt = time1.tv_sec; /* avoid type cast lossage */ + zeit=localtime(<); return (zeit->tm_sec+60*(zeit->tm_min+60*(zeit->tm_hour)) + time1.tv_usec*1.0E-6); @@ -205,7 +210,7 @@ initColor (double r, double g, double b) { int n,n1; unsigned long pixels[12]; - long dummy; + unsigned long dummy; cmap = xgwa.colormap; @@ -251,9 +256,13 @@ initialize (void) scrnWidth = xgwa.width; scrnHeight = xgwa.height; - cycle = 60.0 / get_float_resource ("cycle", "Float"); - movef = get_float_resource ("move", "Float") / 2; - wobber *= get_float_resource ("wobble", "Float"); + { + float f = get_float_resource ("cycle", "Float"); + if (f <= 0 || f > 60) f = 6.0; + cycle = 60.0 / f; + } + movef = get_float_resource ("move", "Float"); + wobber = get_float_resource ("wobble", "Float"); { double magfac = get_float_resource ("mag", "Float"); @@ -265,7 +274,7 @@ initialize (void) minutes=1; maxk+=60-24; } - timewait = get_integer_resource ("wait", "Integer"); + timewait = get_integer_resource ("delay", "Integer"); fastch = get_integer_resource ("fast", "Integer"); cycl = get_boolean_resource ("colcycle", "Integer"); hsvcycl = get_float_resource ("hsvcycle", "Integer"); @@ -285,7 +294,7 @@ initialize (void) if (s && *s) { double hh, ss, vv; - if (3 == sscanf (s, "%lf %lf %lf", &hh, &ss, &vv, &dummy)) { + if (3 == sscanf (s, "%lf %lf %lf %c", &hh, &ss, &vv, &dummy)) { hue = hh, sat = ss, val = vv; hsv2rgb(hue,sat,val,&r,&g,&b); } @@ -296,13 +305,6 @@ initialize (void) if (fastch>maxfast) fastch=maxfast; -#ifdef PRTDBX - printf("Set options:\ndisplay: '%s'\ngeometry: '%s'\n",display,geometry); - printf("move\t%.2f\nwobber\t%.2f\nmag\t%.2f\ncycle\t%.4f\n", - movef,wobber,mag/10,cycle); - printf("nice\t%i\nfast\t%i\nmarks\t%i\nwait\t%i\n",niced,fastch,maxk,timewait); -#endif - xgc=( XGCValues *) malloc(sizeof(XGCValues) ); xorgc=( XGCValues *) malloc(sizeof(XGCValues) ); xandgc=( XGCValues *) malloc(sizeof(XGCValues) ); @@ -348,6 +350,13 @@ initialize (void) XFillRectangle (dpy, fastmask , gc, 0, 0, fastcw, fastch+1); #endif + +#ifdef PRTDBX + printf("move\t%.2f\nwobber\t%.2f\nmag\t%.2f\ncycle\t%.4f\n", + movef,wobber,mag/10,cycle); + printf("fast\t%i\nmarks\t%i\nwait\t%i\n",fastch,maxk,timewait); +#endif + } static void fill_kugel(int i, Pixmap buf, int setcol); @@ -504,7 +513,7 @@ fill_kugel(int i, Pixmap buf, int setcol) { double ra; int m,col,inc=1,inr=3,d; - d=(int)((abs(kugeln[i].r1)*2)); + d=(int)((ABS(kugeln[i].r1)*2)); if (d==0) d=1; #ifdef FASTDRAW @@ -521,11 +530,11 @@ fill_kugel(int i, Pixmap buf, int setcol) XPutImage(dpy, buf, orgc, fastcircles[d-1], 0, 0, (int)(kugeln[i].x1)-d/2, (int)(kugeln[i].y1)-d/2, d, d); # endif - } + } else #endif { - if(abs(kugeln[i].r1)<6.0) inr=9; + if(ABS(kugeln[i].r1)<6.0) inr=9; for (m=0;m<=28;m+=inr) { @@ -715,23 +724,46 @@ event_handler(void) starty=scrnHeight/2; scrnH2=startx; scrnW2=starty; - }; break; + }; + break; + case KeyPress: { KeySym kpr=XKeycodeToKeysym(dpy,event.xkey.keycode,0); - if (kpr=='s') /* s */ - vspeed=0.5; - if (kpr=='a') - vspeed=-0.3; - if (kpr=='q') - { - speed=0;vspeed=0; - } - /* printf("%i\n",event.xkey.keycode);*/ - if (kpr=='z') mag*=1.02; - if (kpr=='x') mag/=1.02; - } + + switch (kpr) + { + case 's': case 'S': + vspeed = 0.5; + break; + case 'a': case 'A': + vspeed = -0.3; + break; + + case '0': + speed = 0; + vspeed = 0; + break; + + case 'z': case 'Z': + mag *= 1.02; + break; + + case 'x': case 'X': + mag /= 1.02; + break; + + default: + screenhack_handle_event (dpy, &event); + break; + } + } + + case ButtonPress: case ButtonRelease: + break; + default: + screenhack_handle_event (dpy, &event); break; } } @@ -754,10 +786,10 @@ char *defaults [] = { ".foreground: white", "*move: 0.5", "*wobble: 2.0", - "*cycle: 6.0", + "*cycle: 10.0", "*mag: 1", "*minutes: False", - "*timewait: 40000", + "*delay: 40000", "*fast: 50", "*ccycle: False", "*hsvcycle: 0.0", @@ -769,8 +801,9 @@ XrmOptionDescRec options [] = { { "-wobble", ".wobble", XrmoptionSepArg, 0 }, { "-cycle", ".cycle", XrmoptionSepArg, 0 }, { "-mag", ".mag", XrmoptionSepArg, 0 }, - { "-minutes", ".minutes", XrmoptionSepArg, 0 }, - { "-timewait", ".timewait", XrmoptionSepArg, 0 }, + { "-minutes", ".minutes", XrmoptionNoArg, "True" }, + { "-no-minutes", ".minutes", XrmoptionNoArg, "False" }, + { "-delay", ".delay", XrmoptionSepArg, 0 }, { "-fast", ".fast", XrmoptionSepArg, 0 }, { "-colcycle", ".colcycle", XrmoptionSepArg, 0 }, { "-hsvcycle", ".hsvcycle", XrmoptionSepArg, 0 }, @@ -785,7 +818,8 @@ screenhack (Display *d, Window w) { Window junk_win,in_win; - int px,py,junk,kb/*,wai*/; + int px,py,junk/*,wai*/; + unsigned int kb; /* int act,act1,tc;*/ double vnorm; /* double var=0.0; */