From http://www.jwz.org/xscreensaver/xscreensaver-5.30.tar.gz
[xscreensaver] / hacks / glx / boing.c
index 21b1958054bdaf10f9b7561488e4b55ceb877e9c..91fd6383fbcdf0694a2c5f362e3f5c1d6c43ceeb 100644 (file)
@@ -1,4 +1,4 @@
-/* boing, Copyright (c) 2005-2008 Jamie Zawinski <jwz@jwz.org>
+/* boing, Copyright (c) 2005-2014 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
@@ -378,7 +378,7 @@ draw_scanlines (ModeInfo *mi)
       int lh, ls;
       int y;
       glLoadIdentity();
-      gluOrtho2D (0, w, 0, h);
+      glOrtho (0, w, 0, h, -1, 1);
 
       if      (h > 500) lh = 4, ls = 4;
       else if (h > 300) lh = 2, ls = 1;
@@ -461,6 +461,13 @@ reshape_boing (ModeInfo *mi, int width, int height)
 
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
+
+  if (height > width)
+    {
+      GLfloat s = width / (GLfloat) height;
+      glScalef (s, s, s);
+    }
+
   gluPerspective (8.0, 1/h, 1.0, 10.0);
 
   glMatrixMode(GL_MODELVIEW);
@@ -478,39 +485,10 @@ boing_handle_event (ModeInfo *mi, XEvent *event)
 {
   boing_configuration *bp = &bps[MI_SCREEN(mi)];
 
-  if (event->xany.type == ButtonPress &&
-      event->xbutton.button == Button1)
-    {
-      bp->button_down_p = True;
-      gltrackball_start (bp->trackball,
-                         event->xbutton.x, event->xbutton.y,
-                         MI_WIDTH (mi), MI_HEIGHT (mi));
-      return True;
-    }
-  else if (event->xany.type == ButtonRelease &&
-           event->xbutton.button == Button1)
-    {
-      bp->button_down_p = False;
-      return True;
-    }
-  else if (event->xany.type == ButtonPress &&
-           (event->xbutton.button == Button4 ||
-            event->xbutton.button == Button5 ||
-            event->xbutton.button == Button6 ||
-            event->xbutton.button == Button7))
-    {
-      gltrackball_mousewheel (bp->trackball, event->xbutton.button, 10,
-                              !!event->xbutton.state);
-      return True;
-    }
-  else if (event->xany.type == MotionNotify &&
-           bp->button_down_p)
-    {
-      gltrackball_track (bp->trackball,
-                         event->xmotion.x, event->xmotion.y,
-                         MI_WIDTH (mi), MI_HEIGHT (mi));
-      return True;
-    }
+  if (gltrackball_event_handler (event, bp->trackball,
+                                 MI_WIDTH (mi), MI_HEIGHT (mi),
+                                 &bp->button_down_p))
+    return True;
 
   return False;
 }
@@ -601,7 +579,7 @@ init_boing (ModeInfo *mi)
 
   bp->ball_dz  = speed * 6 + frand(speed);
 
-  bp->trackball = gltrackball_init ();
+  bp->trackball = gltrackball_init (False);
 }
 
 
@@ -629,6 +607,18 @@ draw_boing (ModeInfo *mi)
     tick_physics (mi);
 
   glPushMatrix ();
+
+  {
+    double rot = current_device_rotation();
+    glRotatef(rot, 0, 0, 1);
+    if ((rot >  45 && rot <  135) ||
+        (rot < -45 && rot > -135))
+      {
+        GLfloat s = MI_WIDTH(mi) / (GLfloat) MI_HEIGHT(mi);
+        glScalef (1/s, s, 1);
+      }
+  }
+
   gltrackball_rotate (bp->trackball);
 
   glLightfv (GL_LIGHT0, GL_POSITION, bp->lightpos);