From http://www.jwz.org/xscreensaver/xscreensaver-5.38.tar.gz
[xscreensaver] / hacks / glx / flipflop.c
index 3d35c1e1c277821f26299a3ef66eed4d2bff4b57..c26458c2dc1cb22283514114fe8cefafb38c62a5 100644 (file)
@@ -43,7 +43,7 @@
                        "*showFPS:   False     \n" \
                        "*wireframe: False     \n"
 
-# define refresh_flipflop 0
+# define release_flipflop 0
 # include "xlockmore.h"
 
 #else
@@ -94,8 +94,8 @@ ENTRYPOINT ModeSpecOpt flipflop_opts = {countof(opts), opts, countof(vars), vars
 
 #ifdef USE_MODULES
 ModStruct   flipflop_description =
-    {"flipflop", "init_flipflop", "draw_flipflop", "release_flipflop",
-     "draw_flipflop", "init_flipflop", NULL, &flipflop_opts,
+    {"flipflop", "init_flipflop", "draw_flipflop", NULL,
+     "draw_flipflop", "init_flipflop", "free_flipflop", &flipflop_opts,
      1000, 1, 2, 1, 4, 1.0, "",
      "Flipflop", 0, NULL};
 
@@ -283,12 +283,20 @@ display(ModeInfo *mi)
 ENTRYPOINT void
 reshape_flipflop(ModeInfo *mi, int width, int height)
 {
-    GLfloat h = (GLfloat) height / (GLfloat) width;
-    glViewport(0,0, width, height);
-    glMatrixMode(GL_PROJECTION);
-    glLoadIdentity();
-    gluPerspective(45, 1/h, 1.0, 300.0);
-    glMatrixMode(GL_MODELVIEW);
+  GLfloat h = (GLfloat) height / (GLfloat) width;
+  int y = 0;
+
+  if (width > height * 5) {   /* tiny window: show middle */
+    height = width * 9/16;
+    y = -height/2;
+    h = height / (GLfloat) width;
+  }
+
+  glViewport(0,y, width, height);
+  glMatrixMode(GL_PROJECTION);
+  glLoadIdentity();
+  gluPerspective(45, 1/h, 1.0, 300.0);
+  glMatrixMode(GL_MODELVIEW);
 }
 
 static void
@@ -392,9 +400,7 @@ init_flipflop(ModeInfo *mi)
     screen = MI_SCREEN(mi);
     wire = MI_IS_WIREFRAME(mi);
 
-    if(!qs &&
-       !(qs = (Flipflopcreen *) calloc(MI_NUM_SCREENS(mi), sizeof(Flipflopcreen))))
-        return;
+    MI_INIT(mi, qs);
 
     c = &qs[screen];
     c->window = MI_WINDOW(mi);
@@ -465,27 +471,13 @@ draw_flipflop(ModeInfo *mi)
 }
 
 ENTRYPOINT void
-release_flipflop(ModeInfo *mi)
+free_flipflop(ModeInfo *mi)
 {
-  if(qs) {
-    int screen;
-
-    for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++)
-    {
-      Flipflopcreen *c = &qs[MI_SCREEN(mi)];
-      if (c->glx_context)
-        c->glx_context = 0;
-      if (c->sheet) {
-        randsheet_free(c->sheet);
-        free (c->sheet);
-        c->sheet = 0;
-      }
-    }
-    free(qs);
-    qs = 0;
+  Flipflopcreen *c = &qs[MI_SCREEN(mi)];
+  if (c->sheet) {
+    randsheet_free(c->sheet);
+    free (c->sheet);
   }
-
-  FreeAllGL(mi);
 }
 
 /*** ADDED RANDSHEET FUNCTIONS ***/