From http://www.jwz.org/xscreensaver/xscreensaver-5.37.tar.gz
[xscreensaver] / hacks / thornbird.c
index 44a2a59f294e7cb96eacac744f37ccfc07989c79..2ebbf17297db01dcda1ee404c6c6cb4e4af0e437 100644 (file)
@@ -6,7 +6,7 @@ static const char sccsid[] = "@(#)thornbird.c   5.00 2000/11/01 xlockmore";
 #endif
 
 /*-
- * Copyright (c) 1996 by Tim Auckland <Tim.Auckland@Procket.com>
+ * Copyright (c) 1996 by Tim Auckland <tda10.geo@yahoo.com>
  *
  * Permission to use, copy, modify, and distribute this software and its
  * documentation for any purpose and without fee is hereby granted,
@@ -30,29 +30,30 @@ static const char sccsid[] = "@(#)thornbird.c       5.00 2000/11/01 xlockmore";
  */
 
 #ifdef STANDALONE
-#define MODE_thornbird
-#define PROGCLASS "Thornbird"
-#define HACK_INIT init_thornbird
-#define HACK_DRAW draw_thornbird
-#define thornbird_opts xlockmore_opts
-#define DEFAULTS "*delay: 10000 \n" \
- "*count: 800 \n" \
- "*cycles: 16 \n" \
- "*ncolors: 64 \n"
-#define SMOOTH_COLORS
-#include "xlockmore.h"         /* in xscreensaver distribution */
+# define MODE_thornbird
+#define DEFAULTS       "*delay:    10000 \n" \
+                                       "*count:    100   \n" \
+                                        "*cycles:  400   \n" \
+                                        "*ncolors: 64    \n" \
+                                        "*fpsSolid: true    \n" \
+                                       "*ignoreRotation: True \n" \
+
+# define BRIGHT_COLORS
+# define release_thornbird 0
+# define thornbird_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 */
 
 #ifdef MODE_thornbird
 
-ModeSpecOpt thornbird_opts =
+ENTRYPOINT ModeSpecOpt thornbird_opts =
 {0, (XrmOptionDescRec *) NULL, 0, (argtype *) NULL, (OptionStruct *) NULL};
 
 #ifdef USE_MODULES
 ModStruct   thornbird_description =
-{"thornbird", "init_thornbird", "draw_thornbird", "release_thornbird",
+{"thornbird", "init_thornbird", "draw_thornbird", (char *) NULL,
  "refresh_thornbird", "init_thornbird", (char *) NULL, &thornbird_opts,
  1000, 800, 16, 1, 64, 1.0, "",
  "Shows an animated Bird in a Thorn Bush fractal map", 0, NULL};
@@ -91,8 +92,9 @@ typedef struct {
 static thornbirdstruct *thornbirds = (thornbirdstruct *) NULL;
 
 static void
-free_thornbird(thornbirdstruct *hp)
+free_thornbird(ModeInfo * mi)
 {
+       thornbirdstruct *hp = &thornbirds[MI_SCREEN(mi)];
        if (hp->pointBuffer != NULL) {
                int         buffer;
 
@@ -104,17 +106,12 @@ free_thornbird(thornbirdstruct *hp)
        }
 }
 
-void
-init_thornbird(ModeInfo * mi)
+ENTRYPOINT void
+init_thornbird (ModeInfo * mi)
 {
        thornbirdstruct *hp;
 
-       if (thornbirds == NULL) {
-               if ((thornbirds =
-                    (thornbirdstruct *) calloc(MI_NUM_SCREENS(mi),
-                                         sizeof (thornbirdstruct))) == NULL)
-                       return;
-       }
+       MI_INIT (mi, thornbirds, free_thornbird);
        hp = &thornbirds[MI_SCREEN(mi)];
 
 
@@ -132,14 +129,14 @@ init_thornbird(ModeInfo * mi)
        if (hp->pointBuffer == NULL)
                if ((hp->pointBuffer = (XPoint **) calloc(MI_CYCLES(mi),
                                sizeof (XPoint *))) == NULL) {
-                       free_thornbird(hp);
+                       free_thornbird(mi);
                        return;
                }
 
        if (hp->pointBuffer[0] == NULL)
                if ((hp->pointBuffer[0] = (XPoint *) malloc(MI_COUNT(mi) *
                                sizeof (XPoint))) == NULL) {
-                       free_thornbird(hp);
+                       free_thornbird(mi);
                        return;
                }
 
@@ -160,7 +157,7 @@ init_thornbird(ModeInfo * mi)
 }
 
 
-void
+ENTRYPOINT void
 draw_thornbird(ModeInfo * mi)
 {
        Display    *dsp = MI_DISPLAY(mi);
@@ -222,10 +219,11 @@ draw_thornbird(ModeInfo * mi)
 
        MI_IS_DRAWN(mi) = True;
 
+    if (MI_COUNT(mi) < 1) MI_COUNT(mi) = 1;
        if (hp->pointBuffer[erase] == NULL) {
                if ((hp->pointBuffer[erase] = (XPoint *) malloc(MI_COUNT(mi) *
                                sizeof (XPoint))) == NULL) {
-                       free_thornbird(hp);
+                       free_thornbird(mi);
                        return;
                }
        } else {
@@ -235,7 +233,11 @@ draw_thornbird(ModeInfo * mi)
        }
        if (MI_NPIXELS(mi) > 2) {
                XSetForeground(dsp, gc, MI_PIXEL(mi, hp->pix));
+#if 0
                if (erase == 0) /* change colours after "cycles" cycles */
+#else
+        if (!((hp->inc + 1) % (1 + (MI_CYCLES(mi) / 3)))) /* jwz: sooner */
+#endif
                        if (++hp->pix >= MI_NPIXELS(mi))
                                hp->pix = 0;
        } else
@@ -244,26 +246,22 @@ draw_thornbird(ModeInfo * mi)
        XDrawPoints(dsp, win, gc, hp->pointBuffer[current],
                    batchcount, CoordModeOrigin);
        hp->inc++;
-
 }
 
-void
-release_thornbird(ModeInfo * mi)
+ENTRYPOINT void
+reshape_thornbird(ModeInfo * mi, int width, int height)
 {
-       if (thornbirds != NULL) {
-               int         screen;
-
-               for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++)
-                       free_thornbird(&thornbirds[screen]);
-               (void) free((void *) thornbirds);
-               thornbirds = (thornbirdstruct *) NULL;
-       }
+  XClearWindow (MI_DISPLAY (mi), MI_WINDOW(mi));
+  init_thornbird (mi);
 }
 
-void
-refresh_thornbird(ModeInfo * mi)
+ENTRYPOINT void
+refresh_thornbird (ModeInfo * mi)
 {
        MI_CLEARWINDOW(mi);
 }
 
+
+XSCREENSAVER_MODULE ("Thornbird", thornbird)
+
 #endif /* MODE_thornbird */