X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Frotor.c;h=293b273cb58bfbfc4b108c191d5c6cba5c8ec0dd;hb=4361b69d3178d7fc98d0388f9a223af6c2651aba;hp=135159e36e40f5a5b562a2609d18a4c13602239f;hpb=df7adbee81405e2849728a24b498ad2117784b1f;p=xscreensaver diff --git a/hacks/rotor.c b/hacks/rotor.c index 135159e3..293b273c 100644 --- a/hacks/rotor.c +++ b/hacks/rotor.c @@ -1,9 +1,8 @@ /* -*- Mode: C; tab-width: 4 -*- */ /* rotor --- a swirly rotor */ -#if !defined( lint ) && !defined( SABER ) -static const char sccsid[] = "@(#)rotor.c 4.04 97/07/28 xlockmore"; - +#if 0 +static const char sccsid[] = "@(#)rotor.c 5.00 2000/11/01 xlockmore"; #endif /*- @@ -22,38 +21,52 @@ static const char sccsid[] = "@(#)rotor.c 4.04 97/07/28 xlockmore"; * other special, indirect and consequential damages. * * Revision History: - * 10-May-97: Compatible with xscreensaver - * 08-Mar-95: CAT stuff for ## was tripping up some C compilers. Removed. - * 01-Dec-93: added patch for AIXV3 from Tom McConnell - * - * 11-Nov-90: put into xlock by Steve Zellers - * 16-Oct-90: Received from Tom Lawrence (tcl@cs.brown.edu: 'flight' simulator) + * 01-Nov-2000: Allocation checks + * 10-May-1997: Compatible with xscreensaver + * 08-Mar-1995: CAT stuff for ## was tripping up some C compilers. Removed. + * 01-Dec-1993: added patch for AIXV3 from Tom McConnell + * + * 11-Nov-1990: put into xlock by Steve Zellers + * 16-Oct-1990: Received from Tom Lawrence (tcl@cs.brown.edu: 'flight' + * simulator) */ #ifdef STANDALONE -# define PROGCLASS "Rotor" -# define HACK_INIT init_rotor -# define HACK_DRAW draw_rotor -# define rotor_opts xlockmore_opts -# define DEFAULTS "*delay: 10000 \n" \ - "*count: 4 \n" \ - "*size: -6 \n" \ - "*cycles: 20 \n" \ - "*ncolors: 200 \n" +#define MODE_rotor +#define DEFAULTS "*delay: 10000 \n" \ + "*count: 4 \n" \ + "*cycles: 20 \n" \ + "*size: -6 \n" \ + "*ncolors: 200 \n" \ + "*fpsSolid: true \n" \ + # define SMOOTH_COLORS +# define reshape_rotor 0 +# define rotor_handle_event 0 # include "xlockmore.h" /* in xscreensaver distribution */ #else /* STANDALONE */ -# include "xlock.h" /* in xlockmore distribution */ +# include "xlock.h" /* in xlockmore distribution */ #endif /* STANDALONE */ -ModeSpecOpt rotor_opts = -{0, NULL, 0, NULL, NULL}; +#ifdef MODE_rotor + +ENTRYPOINT ModeSpecOpt rotor_opts = +{0, (XrmOptionDescRec *) NULL, 0, (argtype *) NULL, (OptionStruct *) NULL}; + +#ifdef USE_MODULES +ModStruct rotor_description = +{"rotor", "init_rotor", "draw_rotor", "release_rotor", + "refresh_rotor", "init_rotor", (char *) NULL, &rotor_opts, + 100, 4, 100, -6, 64, 0.3, "", + "Shows Tom's Roto-Rooter", 0, NULL}; + +#endif /*- * A 'batchcount' of 3 or 4 works best! */ -#define MAXANGLE 3000.0 /* irrectangular (jwz: was 10000.0) */ +#define MAXANGLE 3000.0 /* irrectangular (was 10000.0) */ /* How many segments to draw per cycle when redrawing */ #define REDRAWSTEP 3 @@ -88,30 +101,44 @@ typedef struct { elem *elements; XPoint *save; int redrawing, redrawpos; + int linewidth; } rotorstruct; -static rotorstruct *rotors = NULL; +static rotorstruct *rotors = (rotorstruct *) NULL; -void -init_rotor(ModeInfo * mi) +static void +free_rotor(rotorstruct *rp) +{ + if (rp->elements != NULL) { + (void) free((void *) rp->elements); + rp->elements = (elem *) NULL; + } + if (rp->save != NULL) { + (void) free((void *) rp->save); + rp->save = (XPoint *) NULL; + } +} + +ENTRYPOINT void +init_rotor (ModeInfo * mi) { - rotorstruct *rp; int x; elem *pelem; unsigned char wasiconified; + rotorstruct *rp; - if (rotors == NULL) { - if ((rotors = (rotorstruct *) calloc(MI_NUM_SCREENS(mi), - sizeof (rotorstruct))) == NULL) - return; - } + MI_INIT (mi, rotors, 0); rp = &rotors[MI_SCREEN(mi)]; +#ifdef HAVE_JWXYZ + jwxyz_XSetAntiAliasing (MI_DISPLAY(mi), MI_GC(mi), False); +#endif + rp->prevcenterx = rp->centerx; rp->prevcentery = rp->centery; - rp->centerx = MI_WIN_WIDTH(mi) / 2; - rp->centery = MI_WIN_HEIGHT(mi) / 2; + rp->centerx = MI_WIDTH(mi) / 2; + rp->centery = MI_HEIGHT(mi) / 2; rp->redrawing = 0; /* @@ -122,7 +149,7 @@ init_rotor(ModeInfo * mi) */ wasiconified = rp->iconifiedscreen; - rp->iconifiedscreen = MI_WIN_IS_ICONIC(mi); + rp->iconifiedscreen = MI_IS_ICONIC(mi); if (wasiconified && !rp->iconifiedscreen) rp->firsttime = True; @@ -137,21 +164,33 @@ init_rotor(ModeInfo * mi) if (!rp->prevcentery) rp->prevcentery = rp->centery * 12; - rp->num = MI_BATCHCOUNT(mi); + rp->num = MI_COUNT(mi); if (rp->num < 0) { rp->num = NRAND(-rp->num) + 1; if (rp->elements != NULL) { (void) free((void *) rp->elements); - rp->elements = NULL; + rp->elements = (elem *) NULL; } } if (rp->elements == NULL) - rp->elements = (elem *) calloc(rp->num, sizeof (elem)); + if ((rp->elements = (elem *) calloc(rp->num, + sizeof (elem))) == NULL) { + free_rotor(rp); + return; + } rp->nsave = MI_CYCLES(mi); if (rp->nsave <= 1) rp->nsave = 2; if (rp->save == NULL) - rp->save = (XPoint *) calloc(rp->nsave, sizeof (XPoint)); + if ((rp->save = (XPoint *) malloc(rp->nsave * + sizeof (XPoint))) == NULL) { + free_rotor(rp); + return; + } + for (x = 0; x < rp->nsave; x++) { + rp->save[x].x = rp->centerx; + rp->save[x].y = rp->centery; + } pelem = rp->elements; @@ -175,31 +214,34 @@ init_rotor(ModeInfo * mi) rp->angle = (float) NRAND((long) MAXANGLE) / 3.0; rp->forward = rp->firsttime = True; } + rp->linewidth = MI_SIZE(mi); - { - int line_width = MI_SIZE(mi); - if (line_width == 0) - line_width = -5; - if (line_width < 0) - line_width = NRAND(-line_width)+1; - XSetLineAttributes(MI_DISPLAY(mi), MI_GC(mi), line_width, - LineSolid, CapButt, JoinMiter); - } + if (rp->linewidth == 0) + rp->linewidth = 1; + if (rp->linewidth < 0) + rp->linewidth = NRAND(-rp->linewidth) + 1; - XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi)); + MI_CLEARWINDOW(mi); } -void -draw_rotor(ModeInfo * mi) +ENTRYPOINT void +draw_rotor (ModeInfo * mi) { Display *display = MI_DISPLAY(mi); GC gc = MI_GC(mi); - register rotorstruct *rp = &rotors[MI_SCREEN(mi)]; register elem *pelem; int thisx, thisy; int i; int x_1, y_1, x_2, y_2; + rotorstruct *rp; + + if (rotors == NULL) + return; + rp = &rotors[MI_SCREEN(mi)]; + if (rp->elements == NULL) + return; + MI_IS_DRAWN(mi) = True; if (!rp->iconifiedscreen) { thisx = rp->centerx; thisy = rp->centery; @@ -207,6 +249,8 @@ draw_rotor(ModeInfo * mi) thisx = rp->prevcenterx; thisy = rp->prevcentery; } + XSetLineAttributes(MI_DISPLAY(mi), MI_GC(mi), rp->linewidth, + LineSolid, CapButt, JoinMiter); for (i = rp->num, pelem = rp->elements; --i >= 0; pelem++) { if (pelem->radius_drift_max <= pelem->radius_drift_now) { pelem->start_radius = pelem->end_radius; @@ -237,7 +281,7 @@ draw_rotor(ModeInfo * mi) if (rp->firsttime) rp->firsttime = False; else { - XSetForeground(display, gc, MI_WIN_BLACK_PIXEL(mi)); + XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); x_1 = (int) rp->save[rp->rotor].x; y_1 = (int) rp->save[rp->rotor].y; @@ -257,7 +301,7 @@ draw_rotor(ModeInfo * mi) if (++rp->pix >= MI_NPIXELS(mi)) rp->pix = 0; } else - XSetForeground(display, gc, MI_WIN_WHITE_PIXEL(mi)); + XSetForeground(display, gc, MI_WHITE_PIXEL(mi)); x_1 = rp->lastx; y_1 = rp->lasty; @@ -317,32 +361,37 @@ draw_rotor(ModeInfo * mi) } } } + XSetLineAttributes(MI_DISPLAY(mi), MI_GC(mi), 1, + LineSolid, CapButt, JoinMiter); } -void -release_rotor(ModeInfo * mi) +ENTRYPOINT void +release_rotor (ModeInfo * mi) { if (rotors != NULL) { int screen; - for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) { - rotorstruct *rp = &rotors[screen]; - - if (rp->elements != NULL) - (void) free((void *) rp->elements); - if (rp->save != NULL) - (void) free((void *) rp->save); - } + for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) + free_rotor(&rotors[screen]); (void) free((void *) rotors); - rotors = NULL; + rotors = (rotorstruct *) NULL; } } -void -refresh_rotor(ModeInfo * mi) +ENTRYPOINT void +refresh_rotor (ModeInfo * mi) { - rotorstruct *rp = &rotors[MI_SCREEN(mi)]; + rotorstruct *rp; + if (rotors == NULL) + return; + rp = &rotors[MI_SCREEN(mi)]; + + MI_CLEARWINDOW(mi); rp->redrawing = 1; rp->redrawpos = 1; } + +XSCREENSAVER_MODULE ("Rotor", rotor) + +#endif /* MODE_rotor */