From http://www.jwz.org/xscreensaver/xscreensaver-5.40.tar.gz
[xscreensaver] / hacks / glx / quasicrystal.c
index be2e0c164c8ac6f1fb86a30dc09ec33ebcb4c1c3..b82f470e847f51aa68a2de7c306ba9392dbc9967 100644 (file)
@@ -22,8 +22,9 @@
                        "*contrast:     30          \n" \
                        "*showFPS:      False       \n" \
                        "*wireframe:    False       \n" \
+                       "*suppressRotationAnimation: True\n" \
 
-# define refresh_quasicrystal 0
+# define free_quasicrystal 0
 # define release_quasicrystal 0
 #undef countof
 #define countof(x) (sizeof((x))/sizeof((*x)))
@@ -65,7 +66,9 @@ static XrmOptionDescRec opts[] = {
   { "-wander",       ".wander",    XrmoptionNoArg, "True"  },
   { "+wander",       ".wander",    XrmoptionNoArg, "False" },
   { "-symmetry",     ".symmetric", XrmoptionNoArg, "True"   },
+  { "-symmetric",    ".symmetric", XrmoptionNoArg, "True"   },
   { "-no-symmetry",  ".symmetric", XrmoptionNoArg, "False"  },
+  { "-nonsymmetric", ".symmetric", XrmoptionNoArg, "False"  },
   { "-speed",        ".speed",     XrmoptionSepArg, 0 },
   { "-contrast",     ".contrast",  XrmoptionSepArg, 0 },
 };
@@ -121,6 +124,24 @@ quasicrystal_handle_event (ModeInfo *mi, XEvent *event)
       bp->button_down_p = False;
       return True;
     }
+  else if (event->xany.type == ButtonPress &&  /* wheel up or right */
+           (event->xbutton.button == Button4 ||
+            event->xbutton.button == Button7))
+    {
+    UP:
+      if (bp->contrast <= 0) return False;
+      bp->contrast--;
+      return True;
+    }
+  else if (event->xany.type == ButtonPress &&  /* wheel down or left */
+           (event->xbutton.button == Button5 ||
+            event->xbutton.button == Button6))
+    {
+    DOWN:
+      if (bp->contrast >= 100) return False;
+      bp->contrast++;
+      return True;
+    }
   else if (event->xany.type == MotionNotify &&
            bp->button_down_p)
     {
@@ -140,6 +161,24 @@ quasicrystal_handle_event (ModeInfo *mi, XEvent *event)
       bp->mousey = event->xmotion.y;
       return True;
     }
+  else
+    {
+      if (event->xany.type == KeyPress)
+        {
+          KeySym keysym;
+          char c = 0;
+          XLookupString (&event->xkey, &c, 1, &keysym, 0);
+          if (c == '<' || c == ',' || c == '-' || c == '_' ||
+              keysym == XK_Left || keysym == XK_Up || keysym == XK_Prior)
+            goto UP;
+          else if (c == '>' || c == '.' || c == '=' || c == '+' ||
+                   keysym == XK_Right || keysym == XK_Down ||
+                   keysym == XK_Next)
+            goto DOWN;
+        }
+
+      return screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event);
+    }
 
   return False;
 }
@@ -155,14 +194,7 @@ init_quasicrystal (ModeInfo *mi)
   int tex_width;
   int i;
 
-  if (!bps) {
-    bps = (quasicrystal_configuration *)
-      calloc (MI_NUM_SCREENS(mi), sizeof (quasicrystal_configuration));
-    if (!bps) {
-      fprintf(stderr, "%s: out of memory\n", progname);
-      exit(1);
-    }
-  }
+  MI_INIT (mi, bps);
 
   bp = &bps[MI_SCREEN(mi)];
 
@@ -197,7 +229,7 @@ init_quasicrystal (ModeInfo *mi)
     }
 
   bp->symmetric_p =
-    get_boolean_resource (MI_DISPLAY (mi), "symmetry", "Symmetry");
+    get_boolean_resource (MI_DISPLAY (mi), "symmetric", "Symmetric");
 
   bp->contrast = get_float_resource (MI_DISPLAY (mi), "contrast", "Contrast");
   if (bp->contrast < 0 || bp->contrast > 100) 
@@ -243,10 +275,7 @@ init_quasicrystal (ModeInfo *mi)
             glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
             glTexImage1D (GL_TEXTURE_1D, 0, GL_RGBA,
                           tex_width, 0,
-                          GL_RGBA,
-                          /* GL_UNSIGNED_BYTE, */
-                          GL_UNSIGNED_INT_8_8_8_8_REV,
-                          tex_data);
+                          GL_RGBA, GL_UNSIGNED_BYTE, tex_data);
             check_gl_error("texture");
 
             glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@@ -289,6 +318,13 @@ draw_quasicrystal (ModeInfo *mi)
   glDisable(GL_DEPTH_TEST);
   glDisable(GL_CULL_FACE);
   glDisable (GL_LIGHTING);
+  if (!wire)
+    {
+      glEnable (GL_TEXTURE_1D);
+# ifdef HAVE_JWZGLES
+      glEnable (GL_TEXTURE_2D);  /* jwzgles needs this, bleh. */
+# endif
+    }
 
   glEnable (GL_BLEND);
   glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -346,10 +382,7 @@ draw_quasicrystal (ModeInfo *mi)
       glColor4f (1, 1, 1, (wire ? 0.5 : 1.0 / bp->count));
 
       if (!wire)
-        {
-          glEnable (GL_TEXTURE_1D);
-          glBindTexture (GL_TEXTURE_1D, p->texid);
-        }
+        glBindTexture (GL_TEXTURE_1D, p->texid);
 
       glBegin (wire ? GL_LINE_LOOP : GL_QUADS);
       glNormal3f (0, 0, 1);