X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fant.c;h=ac7555a66d0049bd7dd5831e4f416ad9ff42b31a;hb=aa75c7476aeaa84cf3abc192b376a8b03c325213;hp=463c4e048b38c35a218ae23ede85f65aab99b046;hpb=ffd8c0873576a9e3065696a624dce6b766b77062;p=xscreensaver diff --git a/hacks/ant.c b/hacks/ant.c index 463c4e04..ac7555a6 100644 --- a/hacks/ant.c +++ b/hacks/ant.c @@ -52,23 +52,25 @@ static const char sccsid[] = "@(#)ant.c 5.00 2000/11/01 xlockmore"; Neighbors 6 and neighbors 3 produce the same Turk ants. */ +#ifndef HAVE_JWXYZ +/*# define DO_STIPPLE*/ +#endif + #ifdef STANDALONE -#define MODE_ant -#define PROGCLASS "Ant" -#define HACK_INIT init_ant -#define HACK_DRAW draw_ant -#define ant_opts xlockmore_opts -#define DEFAULTS "*delay: 1000 \n" \ - "*count: -3 \n" \ - "*cycles: 40000 \n" \ - "*size: -12 \n" \ - "*ncolors: 64 \n" \ - "*neighbors: 0 \n" \ - "*sharpturn: False \n" -#include "xlockmore.h" /* in xscreensaver distribution */ -#include "erase.h" +# define MODE_ant +# define DEFAULTS "*delay: 20000 \n" \ + "*count: -3 \n" \ + "*cycles: 40000 \n" \ + "*size: -12 \n" \ + "*ncolors: 64 \n" \ + "*fpsSolid: true \n" \ + +# define reshape_ant 0 +# define ant_handle_event 0 +# include "xlockmore.h" /* in xscreensaver distribution */ +# include "erase.h" #else /* STANDALONE */ -#include "xlock.h" /* in xlockmore distribution */ +# include "xlock.h" /* in xlockmore distribution */ #endif /* STANDALONE */ #include "automata.h" @@ -90,15 +92,13 @@ static Bool sharpturn; static XrmOptionDescRec opts[] = { - {"-neighbors", ".ant.neighbors", XrmoptionSepArg, NULL}, + {"-neighbors", ".ant.neighbors", XrmoptionSepArg, 0}, {"-truchet", ".ant.truchet", XrmoptionNoArg, "on"}, {"+truchet", ".ant.truchet", XrmoptionNoArg, "off"}, {"-eyes", ".ant.eyes", XrmoptionNoArg, "on"}, {"+eyes", ".ant.eyes", XrmoptionNoArg, "off"}, {"-sharpturn", ".ant.sharpturn", XrmoptionNoArg, "on"}, {"+sharpturn", ".ant.sharpturn", XrmoptionNoArg, "off"}, - {"-neighbors", ".ant.neighbors", XrmoptionSepArg, 0}, - {"+neighbors", ".ant.neighbors", XrmoptionSepArg, 0} }; static argtype vars[] = { @@ -106,7 +106,6 @@ static argtype vars[] = {&truchet, "truchet", "Truchet", DEF_TRUCHET, t_Bool}, {&eyes, "eyes", "Eyes", DEF_EYES, t_Bool}, {&sharpturn, "sharpturn", "SharpTurn", DEF_SHARPTURN, t_Bool}, - {&neighbors, "neighbors", "Neighbors", DEF_NEIGHBORS, t_Int} }; static OptionStruct desc[] = { @@ -116,7 +115,7 @@ static OptionStruct desc[] = {"-/+sharpturn", "turn on/off sharp turns (6, 8 or 12 neighbors only)"} }; -ModeSpecOpt ant_opts = +ENTRYPOINT ModeSpecOpt ant_opts = {sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc}; #ifdef USE_MODULES @@ -176,12 +175,17 @@ typedef struct { antstruct *ants; int init_bits; unsigned char colors[NUMSTIPPLES - 1]; +# ifdef DO_STIPPLE GC stippledGC; +# endif /* DO_STIPPLE */ Pixmap pixmaps[NUMSTIPPLES - 1]; union { XPoint hexagon[7]; /* Need more than 6 for truchet */ XPoint triangle[2][4]; /* Need more than 3 for truchet */ } shape; +#ifdef STANDALONE + eraser_state *eraser; +#endif } antfarmstruct; static char plots[] = @@ -641,19 +645,20 @@ drawcell(ModeInfo * mi, int col, int row, unsigned char color) if (!color) { XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_BLACK_PIXEL(mi)); gc = MI_GC(mi); - } else if (MI_NPIXELS(mi) > 2) { - XSetForeground(MI_DISPLAY(mi), MI_GC(mi), - MI_PIXEL(mi, ap->colors[color - 1])); - gc = MI_GC(mi); - } else { +# ifdef DO_STIPPLE + } else if (MI_NPIXELS(mi) <= 2) { XGCValues gcv; - - gcv.stipple = ap->pixmaps[color - 1]; gcv.foreground = MI_WHITE_PIXEL(mi); gcv.background = MI_BLACK_PIXEL(mi); + gcv.stipple = ap->pixmaps[color - 1]; XChangeGC(MI_DISPLAY(mi), ap->stippledGC, GCStipple | GCForeground | GCBackground, &gcv); gc = ap->stippledGC; +# endif /* !DO_STIPPLE */ + } else { + XSetForeground(MI_DISPLAY(mi), MI_GC(mi), + MI_PIXEL(mi, ap->colors[color - 1])); + gc = MI_GC(mi); } fillcell(mi, gc, col, row); } @@ -975,10 +980,12 @@ free_ant(Display *display, antfarmstruct *ap) { int shade; +#ifdef DO_STIPPLE if (ap->stippledGC != None) { XFreeGC(display, ap->stippledGC); ap->stippledGC = None; } +#endif /* DO_STIPPLE */ for (shade = 0; shade < ap->init_bits; shade++) { XFreePixmap(display, ap->pixmaps[shade]); } @@ -997,11 +1004,10 @@ free_ant(Display *display, antfarmstruct *ap) } } -void +ENTRYPOINT void init_ant(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); - Window window = MI_WINDOW(mi); int size = MI_SIZE(mi); antfarmstruct *ap; int col, row, dir; @@ -1015,12 +1021,15 @@ init_ant(ModeInfo * mi) ap = &antfarms[MI_SCREEN(mi)]; ap->redrawing = 0; +#ifdef DO_STIPPLE if (MI_NPIXELS(mi) <= 2) { - if (ap->stippledGC == None) { + Window window = MI_WINDOW(mi); + if (ap->stippledGC == None) { XGCValues gcv; gcv.fill_style = FillOpaqueStippled; - if ((ap->stippledGC = XCreateGC(display, window, GCFillStyle, + if ((ap->stippledGC = XCreateGC(display, window, + GCFillStyle, &gcv)) == None) { free_ant(display, ap); return; @@ -1032,6 +1041,7 @@ init_ant(ModeInfo * mi) } } } +#endif /* DO_STIPPLE */ ap->generation = 0; ap->n = MI_COUNT(mi); if (ap->n < -MINANTS) { @@ -1220,7 +1230,7 @@ init_ant(ModeInfo * mi) draw_anant(mi, dir, col, row); } -void +ENTRYPOINT void draw_ant(ModeInfo * mi) { antstruct *anant; @@ -1236,6 +1246,13 @@ draw_ant(ModeInfo * mi) if (ap->ants == NULL) return; +#ifdef STANDALONE + if (ap->eraser) { + ap->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), ap->eraser); + return; + } +#endif + MI_IS_DRAWN(mi) = True; ap->painted = True; for (i = 0; i < ap->n; i++) { @@ -1297,7 +1314,7 @@ draw_ant(ModeInfo * mi) } if (++ap->generation > MI_CYCLES(mi)) { #ifdef STANDALONE - erase_full_window(MI_DISPLAY(mi), MI_WINDOW(mi)); + ap->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), ap->eraser); #endif init_ant(mi); } @@ -1320,7 +1337,7 @@ draw_ant(ModeInfo * mi) } } -void +ENTRYPOINT void release_ant(ModeInfo * mi) { if (antfarms != NULL) { @@ -1333,7 +1350,7 @@ release_ant(ModeInfo * mi) } } -void +ENTRYPOINT void refresh_ant(ModeInfo * mi) { antfarmstruct *ap; @@ -1349,4 +1366,6 @@ refresh_ant(ModeInfo * mi) } } +XSCREENSAVER_MODULE ("Ant", ant) + #endif /* MODE_ant */