From http://www.jwz.org/xscreensaver/xscreensaver-5.38.tar.gz
[xscreensaver] / hacks / glx / hexstrut.c
index f2646099cd79f8603ff761228d38e78afb670e08..a547a76ca1fe22c2c74872f8459c3d6f51a35d33 100644 (file)
@@ -1,4 +1,4 @@
-/* hexstrut, Copyright (c) 2016 Jamie Zawinski <jwz@jwz.org>
+/* hexstrut, Copyright (c) 2016-2017 Jamie Zawinski <jwz@jwz.org>
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
@@ -15,7 +15,7 @@
                        "*count:        20          \n" \
                        "*suppressRotationAnimation: True\n" \
 
-# define refresh_hexstrut 0
+# define release_hexstrut 0
 #undef countof
 #define countof(x) (sizeof((x))/sizeof((*x)))
 
@@ -196,7 +196,7 @@ tick_triangles (ModeInfo *mi)
           t->rot += step * (t->rot > 0 ? 1 : -1);
 
           t->ccolor++;
-          if (t->ccolor > bp->ncolors)
+          if (t->ccolor >= bp->ncolors)
             t->ccolor = 0;
 
           if (t->rot > 1 || t->rot < -1)
@@ -332,8 +332,15 @@ ENTRYPOINT void
 reshape_hexstrut (ModeInfo *mi, int width, int height)
 {
   GLfloat h = (GLfloat) height / (GLfloat) width;
+  int y = 0;
 
-  glViewport (0, 0, (GLint) width, (GLint) height);
+  if (width > height * 3) {   /* tiny window: show middle */
+    height = width * 9/16;
+    y = -height/2;
+    h = height / (GLfloat) width;
+  }
+
+  glViewport (0, y, (GLint) width, (GLint) height);
 
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
@@ -390,14 +397,7 @@ init_hexstrut (ModeInfo *mi)
 {
   hexstrut_configuration *bp;
 
-  if (!bps) {
-    bps = (hexstrut_configuration *)
-      calloc (MI_NUM_SCREENS(mi), sizeof (hexstrut_configuration));
-    if (!bps) {
-      fprintf(stderr, "%s: out of memory\n", progname);
-      exit(1);
-    }
-  }
+  MI_INIT (mi, bps);
 
   bp = &bps[MI_SCREEN(mi)];
 
@@ -421,12 +421,9 @@ init_hexstrut (ModeInfo *mi)
 
 
   /* Let's tilt the scene a little. */
-  gltrackball_start (bp->trackball, 500, 500, 1000, 1000);
-  gltrackball_track (bp->trackball,
-                     350 + (random() % 300),
-                     350 + (random() % 300),
-                     1000, 1000);
-
+  gltrackball_reset (bp->trackball,
+                     -0.4 + frand(0.8),
+                     -0.4 + frand(0.8));
 
   if (thickness < 0.05) thickness = 0.05;
   if (thickness < 0.05) MI_IS_WIREFRAME(mi) = True;
@@ -496,7 +493,7 @@ draw_hexstrut (ModeInfo *mi)
 
 
 ENTRYPOINT void
-release_hexstrut (ModeInfo *mi)
+free_hexstrut (ModeInfo *mi)
 {
   hexstrut_configuration *bp = &bps[MI_SCREEN(mi)];
   while (bp->triangles)