X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Floop.c;h=fd27fd167c63c84a96f66e9efde8c593d461ae8d;hb=4361b69d3178d7fc98d0388f9a223af6c2651aba;hp=f492ee44c4d92cf4224666e5d9591fd4b8125896;hpb=96a411663168b0ba5432b407a83be55f3df0c802;p=xscreensaver diff --git a/hacks/loop.c b/hacks/loop.c index f492ee44..fd27fd16 100644 --- a/hacks/loop.c +++ b/hacks/loop.c @@ -79,22 +79,24 @@ static const char sccsid[] = "@(#)loop.c 5.01 2000/03/15 xlockmore"; there is handedness at both the initial condition and the transition rule. */ +#ifndef HAVE_JWXYZ +# define DO_STIPPLE +#endif + #ifdef STANDALONE -#define MODE_loop -#define PROGCLASS "loop" -#define HACK_INIT init_loop -#define HACK_DRAW draw_loop -#define loop_opts xlockmore_opts -#define DEFAULTS "*delay: 100000 \n" \ - "*count: -5 \n" \ - "*cycles: 1600 \n" \ - "*size: -12 \n" \ - "*ncolors: 15 \n" \ - "*neighbors: 0 \n" -#define UNIFORM_COLORS -#include "xlockmore.h" /* in xscreensaver distribution */ +# define MODE_loop +# define DEFAULTS "*delay: 100000 \n" \ + "*count: -5 \n" \ + "*cycles: 1600 \n" \ + "*size: -12 \n" \ + "*ncolors: 15 \n" \ + "*fpsSolid: true \n" \ + "*ignoreRotation: True \n" \ + +# define UNIFORM_COLORS +# include "xlockmore.h" /* in xscreensaver distribution */ #else /* STANDALONE */ -#include "xlock.h" /* in xlockmore distribution */ +# include "xlock.h" /* in xlockmore distribution */ #endif /* STANDALONE */ #include "automata.h" @@ -109,20 +111,20 @@ static int neighbors; static XrmOptionDescRec opts[] = { - {(char *) "-neighbors", (char *) ".loop.neighbors", XrmoptionSepArg, (caddr_t) NULL} + {"-neighbors", ".loop.neighbors", XrmoptionSepArg, 0} }; static argtype vars[] = { - {(caddr_t *) & neighbors, (char *) "neighbors", (char *) "Neighbors", (char *) DEF_NEIGHBORS, t_Int} + {&neighbors, "neighbors", "Neighbors", DEF_NEIGHBORS, t_Int} }; static OptionStruct desc[] = { - {(char *) "-neighbors num", (char *) "squares 4 or hexagons 6"} + {"-neighbors num", "squares 4 or hexagons 6"} }; -ModeSpecOpt loop_opts = +ENTRYPOINT ModeSpecOpt loop_opts = {sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc}; @@ -137,8 +139,8 @@ ModStruct loop_description = #define LOOPBITS(n,w,h)\ if ((lp->pixmaps[lp->init_bits]=\ - XCreatePixmapFromBitmapData(display,window,(char *)n,w,h,1,0,1))==None){\ - free_loop(display,lp); return;} else {lp->init_bits++;} + XCreatePixmapFromBitmapData(MI_DISPLAY(mi),window,(char *)n,w,h,1,0,1))==None){\ + free_loop(mi); return;} else {lp->init_bits++;} static int local_neighbors = 0; @@ -858,11 +860,16 @@ drawcell(ModeInfo * mi, int col, int row, int state) gc = MI_GC(mi); XSetForeground(MI_DISPLAY(mi), gc, lp->colors[state]); } else { +#ifdef DO_STIPPLE gcv.stipple = lp->pixmaps[state]; +#endif /* DO_STIPPLE */ gcv.foreground = MI_WHITE_PIXEL(mi); gcv.background = MI_BLACK_PIXEL(mi); XChangeGC(MI_DISPLAY(mi), lp->stippledGC, - GCStipple | GCForeground | GCBackground, &gcv); +#ifdef DO_STIPPLE + GCStipple | +#endif /* DO_STIPPLE */ + GCForeground | GCBackground, &gcv); gc = lp->stippledGC; } fillcell(mi, gc, col, row); @@ -910,8 +917,10 @@ free_list(loopstruct * lp) } static void -free_loop(Display *display, loopstruct * lp) +free_loop(ModeInfo * mi) { + Display *display = MI_DISPLAY(mi); + loopstruct *lp = &loops[MI_SCREEN(mi)]; int shade; for (shade = 0; shade < lp->init_bits; shade++) @@ -943,7 +952,7 @@ addtolist(ModeInfo * mi, int col, int row, unsigned char state) if ((lp->cellList[state] = (CellList *) malloc(sizeof (CellList))) == NULL) { lp->cellList[state] = current; - free_loop(MI_DISPLAY(mi), lp); + free_loop(mi); return False; } lp->cellList[state]->pt.x = col; @@ -966,11 +975,16 @@ draw_state(ModeInfo * mi, int state) gc = MI_GC(mi); XSetForeground(display, gc, lp->colors[state]); } else { +#ifdef DO_STIPPLE gcv.stipple = lp->pixmaps[state]; +#endif /* DO_STIPPLE */ gcv.foreground = MI_WHITE_PIXEL(mi); gcv.background = MI_BLACK_PIXEL(mi); XChangeGC(display, lp->stippledGC, - GCStipple | GCForeground | GCBackground, &gcv); +#ifdef DO_STIPPLE + GCStipple | +#endif /* DO_STIPPLE */ + GCForeground | GCBackground, &gcv); gc = lp->stippledGC; } @@ -1016,7 +1030,6 @@ draw_state(ModeInfo * mi, int state) (void) free((void *) rects); } free_state(lp, state); - XFlush(display); return True; } @@ -1140,7 +1153,7 @@ static void init_adam(ModeInfo * mi) { loopstruct *lp = &loops[MI_SCREEN(mi)]; - XPoint start, dirx, diry; + XPoint start = { 0, 0 }, dirx = { 0, 0 }, diry = { 0, 0 }; int i, j, dir; #ifdef DELAYDEBUGLOOP @@ -1408,47 +1421,40 @@ do_gen(loopstruct * lp) } } -void -release_loop(ModeInfo * mi) +ENTRYPOINT void +release_loop (ModeInfo * mi) { - if (loops != NULL) { - int screen; - - for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) - free_loop(MI_DISPLAY(mi), &loops[screen]); - (void) free((void *) loops); - loops = (loopstruct *) NULL; - } if (table != NULL) { (void) free((void *) table); table = (unsigned int *) NULL; } } -void -init_loop(ModeInfo * mi) +static void *stop_warning_about_triangleUnit_already; + + +ENTRYPOINT void +init_loop (ModeInfo * mi) { - Display *display = MI_DISPLAY(mi); - Window window = MI_WINDOW(mi); int i, size = MI_SIZE(mi); loopstruct *lp; - XGCValues gcv; - if (loops == NULL) { - if ((loops = (loopstruct *) calloc(MI_NUM_SCREENS(mi), - sizeof (loopstruct))) == NULL) - return; - } + stop_warning_about_triangleUnit_already = (void *) &triangleUnit; + + MI_INIT (mi, loops, free_loop); lp = &loops[MI_SCREEN(mi)]; lp->redrawing = 0; +#ifdef DO_STIPPLE if ((MI_NPIXELS(mi) < COLORS) && (lp->init_bits == 0)) { - if (lp->stippledGC == None) { + Window window = MI_WINDOW(mi); + XGCValues gcv; + if (lp->stippledGC == None) { gcv.fill_style = FillOpaqueStippled; - if ((lp->stippledGC = XCreateGC(display, window, + if ((lp->stippledGC = XCreateGC(MI_DISPLAY(mi), window, GCFillStyle, &gcv)) == None) { - free_loop(display, lp); + free_loop(mi); return; } } @@ -1461,6 +1467,7 @@ init_loop(ModeInfo * mi) LOOPBITS(stipples[8], STIPPLESIZE, STIPPLESIZE); LOOPBITS(stipples[10], STIPPLESIZE, STIPPLESIZE); } +#endif /* DO_STIPPLE */ if (MI_NPIXELS(mi) >= COLORS) { /* Maybe these colors should be randomized */ lp->colors[0] = MI_BLACK_PIXEL(mi); @@ -1556,7 +1563,7 @@ init_loop(ModeInfo * mi) } if ((lp->oldcells = (unsigned char *) calloc(lp->bncols * lp->bnrows, sizeof (unsigned char))) == NULL) { - free_loop(display, lp); + free_loop(mi); return; } if (lp->newcells != NULL) { @@ -1565,7 +1572,7 @@ init_loop(ModeInfo * mi) } if ((lp->newcells = (unsigned char *) calloc(lp->bncols * lp->bnrows, sizeof (unsigned char))) == NULL) { - free_loop(display, lp); + free_loop(mi); return; } if (!init_table()) { @@ -1591,8 +1598,8 @@ init_loop(ModeInfo * mi) init_adam(mi); } -void -draw_loop(ModeInfo * mi) +ENTRYPOINT void +draw_loop (ModeInfo * mi) { int offset, i, j; unsigned char *z, *znew; @@ -1635,7 +1642,7 @@ draw_loop(ModeInfo * mi) } for (i = 0; i < COLORS; i++) if (!draw_state(mi, i)) { - free_loop(MI_DISPLAY(mi), lp); + free_loop(mi); return; } if (++lp->generation > MI_CYCLES(mi) || lp->dead) { @@ -1659,8 +1666,15 @@ draw_loop(ModeInfo * mi) } } -void -refresh_loop(ModeInfo * mi) +ENTRYPOINT void +reshape_loop(ModeInfo * mi, int width, int height) +{ + XClearWindow (MI_DISPLAY (mi), MI_WINDOW(mi)); + init_loop (mi); +} + +ENTRYPOINT void +refresh_loop (ModeInfo * mi) { loopstruct *lp; @@ -1673,4 +1687,17 @@ refresh_loop(ModeInfo * mi) lp->redrawpos = lp->by * lp->ncols + lp->bx; } +ENTRYPOINT Bool +loop_handle_event (ModeInfo *mi, XEvent *event) +{ + if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event)) + { + reshape_loop (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); + return True; + } + return False; +} + +XSCREENSAVER_MODULE ("Loop", loop) + #endif /* MODE_loop */