From http://www.jwz.org/xscreensaver/xscreensaver-5.35.tar.gz
[xscreensaver] / hacks / celtic.c
index a6094a42f55187639a0a185b9f57af6894333e78..890b3982a96d6a2b98c5c0d6bf3665e64b425802 100644 (file)
  */
 
 #include <math.h>
-#include <assert.h>
 #include "screenhack.h"
 #include "erase.h"
 
 #define SQRT_3 1.73205080756887729352
+#undef assert
+#define assert(EXP) do { if (!((EXP))) abort(); } while(0)
 
 /*-----------------------------------------*/
 
@@ -85,7 +86,7 @@ struct state {
   Graph graph;
   XWindowAttributes xgwa;
   int delay2;
-  int reset;
+  int reset, force_reset;
   double t;
 
   struct params params;
@@ -718,13 +719,11 @@ static int pattern_next_unfilled_couple(Pattern p, Edge *e, Direction *d)
 
 static void pattern_make_curves(Pattern p)
 {
-  int i;
   Edge current_edge, first_edge, next_edge;
   Node current_node, first_node;
   Direction current_direction, first_direction;
   Spline s;
 
-  i=0;
   while (pattern_next_unfilled_couple(p, &first_edge, &first_direction)) {
     /* start a new loop */
     s=spline_new(random()%(p->ncolors-2)+2);
@@ -840,6 +839,9 @@ static const char *celtic_defaults[] = {
     "*delay: 10000",
     "*delay2: 5",
     "*showGraph: False",
+#ifdef HAVE_MOBILE
+    "*ignoreRotation: True",
+#endif
     0
 };
 
@@ -921,10 +923,10 @@ celtic_init (Display *d_arg, Window w_arg)
   else
     {
 #if 0
-      make_random_colormap (st->dpy, st->xgwa.visual, st->xgwa.colormap,
+      make_random_colormap (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap,
                             st->colors, &st->ncolors, True, True, 0, True);
 #else
-      make_smooth_colormap (st->dpy, st->xgwa.visual, st->xgwa.colormap,
+      make_smooth_colormap (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap,
                             st->colors, &st->ncolors, True, 0, True);
 #endif
       if (st->ncolors < 2)
@@ -971,21 +973,26 @@ celtic_draw (Display *dpy, Window window, void *closure)
     return 10000;
   }
 
-  if (st->reset) {
+  if (st->reset || st->force_reset) {
+    int delay = (st->force_reset ? 0 : st->delay2);
     st->reset = 0;
+    st->force_reset = 0;
+    st->t = 1;
 
-    pattern_del(st->pattern);
+    if (st->pattern != NULL) {
+      pattern_del(st->pattern);
+    }
     st->pattern = NULL;
     graph_del(st->graph);
 
     /* recolor each time */
     st->ncolors = get_integer_resource (st->dpy, "ncolors", "Integer");
     if (st->ncolors > 2)
-      make_smooth_colormap (st->dpy, st->xgwa.visual, st->xgwa.colormap,
+      make_smooth_colormap (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap,
                             st->colors, &st->ncolors, True, 0, True);
 
     st->eraser = erase_window (st->dpy, st->window, st->eraser);
-    return st->delay2;
+    return (delay);
   }
 
   if (st->pattern == NULL) {
@@ -1104,6 +1111,12 @@ celtic_reshape (Display *dpy, Window window, void *closure,
 static Bool
 celtic_event (Display *dpy, Window window, void *closure, XEvent *event)
 {
+  struct state *st = (struct state *) closure;
+  if (screenhack_event_helper (dpy, window, event))
+    {
+      st->force_reset = 1;
+      return True;
+    }
   return False;
 }