From http://www.jwz.org/xscreensaver/xscreensaver-5.37.tar.gz
[xscreensaver] / hacks / flow.c
index 2461cb288fe3c4eec014bc5d8d3c6a953342b4e1..df9aadc366efc82d5866e3e75c18a3d0b2e849fc 100644 (file)
@@ -2,10 +2,8 @@
 /* flow --- flow of strange bees */
 
 #if 0
-#if !defined( lint ) && !defined( SABER )
 static const char sccsid[] = "@(#)flow.c       5.00 2000/11/01 xlockmore";
 #endif
-#endif
 
 /*-
  * Copyright (c) 1996 by Tim Auckland <tda10.geo@yahoo.com>
@@ -103,8 +101,8 @@ static const char sccsid[] = "@(#)flow.c    5.00 2000/11/01 xlockmore";
                                        "*size:        -10   \n" \
                                        "*cycles:      10000 \n" \
                                        "*ncolors:     200   \n"
-# define reshape_flow 0
-# define flow_handle_event 0
+
+# define release_flow 0
 # include "xlockmore.h"                /* in xscreensaver distribution */
 #else /* STANDALONE */
 # include "xlock.h"            /* in xlockmore distribution */
@@ -388,11 +386,12 @@ Iterate(dvector *p, dvector(*ODE)(Par par, double x, double y, double z),
 
 #define deallocate(p,t) if (p!=NULL) {free(p); p=(t*)NULL; }
 #define allocate(p,t,s) if ((p=(t*)malloc(sizeof(t)*s))==NULL)\
-{free_flow(sp);return;}
+{free_flow(mi);return;}
 
 static void
-free_flow(flowstruct *sp)
+free_flow(ModeInfo * mi)
 {
+       flowstruct *sp = &flows[MI_SCREEN(mi)];
        deallocate(sp->csegs, XSegment);
        deallocate(sp->cnsegs, int);
        deallocate(sp->old_segs, XSegment);
@@ -627,11 +626,7 @@ init_flow (ModeInfo * mi)
        flowstruct *sp;
        char       *name;
        
-       if (flows == NULL) {
-               if ((flows = (flowstruct *) calloc(MI_NUM_SCREENS(mi),
-                                                                                  sizeof (flowstruct))) == NULL)
-                       return;
-       }
+       MI_INIT (mi, flows, free_flow);
        sp = &flows[MI_SCREEN(mi)];
 
        sp->count2 = 0;
@@ -773,13 +768,14 @@ init_flow (ModeInfo * mi)
 
        sp->count2 = 0; /* Reset search */
 
-       free_flow(sp);
        sp->beecount = MI_COUNT(mi);
-       if (sp->beecount < 0) { /* random variations */
+       if (!sp->beecount) {
+               sp->beecount = 1; /* The camera requires 1 or more */
+       } else if (sp->beecount < 0) {  /* random variations */
                sp->beecount = NRAND(-sp->beecount) + 1; /* Minimum 1 */
        }
 
-# ifdef HAVE_COCOA     /* Don't second-guess Quartz's double-buffering */
+# ifdef HAVE_JWXYZ     /* Don't second-guess Quartz's double-buffering */
   dbufp = False;
 # endif
 
@@ -806,7 +802,7 @@ init_flow (ModeInfo * mi)
                allocate(sp->csegs, XSegment,
                                 (sp->beecount + BOX_L) * MI_NPIXELS(mi) * sp->taillen);
                allocate(sp->cnsegs, int, MI_NPIXELS(mi));
-               allocate(sp->old_segs, XSegment, sp->beecount * sp->taillen);
+               allocate(sp->old_segs, XSegment, (sp->beecount + BOX_L) * sp->taillen);
                allocate(sp->p, dvector, sp->beecount * sp->taillen);
        }
 
@@ -835,7 +831,7 @@ draw_flow (ModeInfo * mi)
        if (sp->csegs == NULL)
                return;
 
-#ifdef HAVE_COCOA      /* Don't second-guess Quartz's double-buffering */
+#ifdef HAVE_JWXYZ      /* Don't second-guess Quartz's double-buffering */
     XClearWindow (MI_DISPLAY(mi), MI_WINDOW(mi));
 #endif
 
@@ -1110,7 +1106,7 @@ draw_flow (ModeInfo * mi)
                                   are ok, they help to outline the Poincare'
                                   slice. */
                                for(j = i; j < end; j++) Y(j,b) = Y(i,b);
-                               begin = i + 1;
+                               /*begin = i + 1;*/
                                break;
                        }
                        
@@ -1201,24 +1197,30 @@ draw_flow (ModeInfo * mi)
 }
 
 ENTRYPOINT void
-release_flow (ModeInfo * mi)
+reshape_flow(ModeInfo * mi, int width, int height)
 {
-       if (flows != NULL) {
-               int         screen;
-
-               for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++)
-                       free_flow(&flows[screen]);
-               free(flows);
-               flows = (flowstruct *) NULL;
-       }
+  init_flow (mi);
 }
 
+
 ENTRYPOINT void
 refresh_flow (ModeInfo * mi)
 {
        if(!dbufp) MI_CLEARWINDOW(mi);
 }
 
+ENTRYPOINT Bool
+flow_handle_event (ModeInfo *mi, XEvent *event)
+{
+  if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event))
+    {
+      init_flow (mi);
+      return True;
+    }
+  return False;
+}
+
+
 XSCREENSAVER_MODULE ("Flow", flow)
 
 #endif /* MODE_flow */