From http://www.jwz.org/xscreensaver/xscreensaver-5.37.tar.gz
[xscreensaver] / hacks / hopalong.c
index fd64722eac65e17683bb10e2d3a90ced6e0890f7..f0093a3952e212fe8f49369fe5093949ee212989 100644 (file)
@@ -52,20 +52,20 @@ static const char sccsid[] = "@(#)hop.c     5.00 2000/11/01 xlockmore";
 
 #ifdef STANDALONE
 #define MODE_hop
-#define PROGCLASS "Hop"
-#define HACK_INIT init_hop
-#define HACK_DRAW draw_hop
-#define hop_opts xlockmore_opts
-#define DEFAULTS "*delay: 10000 \n" \
- "*count: 1000 \n" \
- "*cycles: 2500 \n" \
- "*ncolors: 200 \n"
-#define SMOOTH_COLORS
-#include "xlockmore.h"         /* in xscreensaver distribution */
-#include "erase.h"
+#define DEFAULTS       "*delay: 10000 \n" \
+                                       "*count: 1000 \n" \
+                                       "*cycles: 2500 \n" \
+                                       "*ncolors: 200 \n" \
+                                       "*fpsSolid: true \n" \
+                                       "*ignoreRotation: True \n" \
+
+# define SMOOTH_COLORS
+# define reshape_hop 0
+# define release_hop 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 */
 
 #ifdef MODE_hop
@@ -148,12 +148,12 @@ static OptionStruct desc[] =
        {"-/+sine", "turn on/off sine format"}
 };
 
-ModeSpecOpt hop_opts =
+ENTRYPOINT ModeSpecOpt hop_opts =
 {sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc};
 
 #ifdef USE_MODULES
 ModStruct   hop_description =
-{"hop", "init_hop", "draw_hop", "release_hop",
+{"hop", "init_hop", "draw_hop", (char *) NULL,
  "refresh_hop", "init_hop", (char *) NULL, &hop_opts,
  10000, 1000, 2500, 1, 64, 1.0, "",
  "Shows real plane iterated fractals", 0, NULL};
@@ -187,11 +187,16 @@ typedef struct {
        int         count;
        int         bufsize;
        XPoint     *pointBuffer;        /* pointer for XDrawPoints */
+#ifdef STANDALONE
+  eraser_state *eraser;
+#endif
 } hopstruct;
 
 static hopstruct *hops = (hopstruct *) NULL;
 
-void
+static void free_hop(ModeInfo * mi);
+
+ENTRYPOINT void
 init_hop(ModeInfo * mi)
 {
        Display    *display = MI_DISPLAY(mi);
@@ -199,11 +204,7 @@ init_hop(ModeInfo * mi)
        double      range;
        hopstruct  *hp;
 
-       if (hops == NULL) {
-               if ((hops = (hopstruct *) calloc(MI_NUM_SCREENS(mi),
-                                                sizeof (hopstruct))) == NULL)
-                       return;
-       }
+       MI_INIT (mi, hops, free_hop);
        hp = &hops[MI_SCREEN(mi)];
 
        hp->centerx = MI_WIDTH(mi) / 2;
@@ -386,14 +387,16 @@ init_hop(ModeInfo * mi)
                        return;
        }
 
+#ifndef STANDALONE
        MI_CLEARWINDOW(mi);
+#endif
 
        XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
        hp->count = 0;
 }
 
 
-void
+ENTRYPOINT void
 draw_hop(ModeInfo * mi)
 {
        double      oldj, oldi;
@@ -404,6 +407,17 @@ draw_hop(ModeInfo * mi)
        if (hops == NULL)
                return;
        hp = &hops[MI_SCREEN(mi)];
+
+#ifdef STANDALONE
+    if (hp->eraser) {
+      hp->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), hp->eraser);
+      if (!hp->eraser)
+        init_hop(mi);
+      return;
+    }
+#endif
+
+
        if (hp->pointBuffer == NULL)
                return;
        xp = hp->pointBuffer;
@@ -532,33 +546,42 @@ draw_hop(ModeInfo * mi)
                    hp->pointBuffer, hp->bufsize, CoordModeOrigin);
        if (++hp->count > MI_CYCLES(mi)) {
 #ifdef STANDALONE
-           erase_full_window(MI_DISPLAY(mi), MI_WINDOW(mi));
-#endif /* STANDALONE */
+      hp->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), hp->eraser);
+#else /* !STANDALONE */
                init_hop(mi);
+#endif
        }
 }
 
-void
-release_hop(ModeInfo * mi)
+static void
+free_hop(ModeInfo * mi)
 {
-       if (hops != NULL) {
-               int         screen;
-
-               for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
-                       hopstruct  *hp = &hops[screen];
+       hopstruct  *hp = &hops[MI_SCREEN(mi)];
 
-                       if (hp->pointBuffer != NULL)
-                               (void) free((void *) hp->pointBuffer);
-               }
-               (void) free((void *) hops);
-               hops = (hopstruct *) NULL;
-       }
+       if (hp->pointBuffer != NULL)
+               (void) free((void *) hp->pointBuffer);
 }
 
-void
+ENTRYPOINT void
 refresh_hop(ModeInfo * mi)
 {
        MI_CLEARWINDOW(mi);
 }
 
+ENTRYPOINT Bool
+hop_handle_event (ModeInfo *mi, XEvent *event)
+{
+  if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event))
+    {
+      MI_CLEARWINDOW(mi);
+      init_hop (mi);
+      return True;
+    }
+  return False;
+}
+
+
+
+XSCREENSAVER_MODULE_2 ("Hopalong", hopalong, hop)
+
 #endif /* MODE_hop */