From http://www.jwz.org/xscreensaver/xscreensaver-5.35.tar.gz
[xscreensaver] / hacks / glx / topblock.c
index 6523102a65243d270c62f9f828f8a83b84f7fe1f..eed2fd54f775fa0522bbb19a2fcf54ed88613b02 100644 (file)
@@ -47,7 +47,7 @@ History
 
 #ifdef USE_GL /* whole file */
 
-#ifndef HAVE_COCOA
+#ifndef HAVE_JWXYZ
 # include <GL/glu.h>
 #endif
 
@@ -279,7 +279,7 @@ init_topBlock (ModeInfo *mi)
     tb->eyeY=20;
     tb->eyeZ=0;
   }
-  tb->trackball = gltrackball_init ();
+  tb->trackball = gltrackball_init (False);
 }
 
 /* provides the per frame entertainment */
@@ -327,6 +327,15 @@ draw_topBlock (ModeInfo *mi)
        /* rotate the world */
        glRotatef(tb->rotation, 0.0, 0.0, 1.0);         
 
+# ifdef HAVE_MOBILE    /* Keep it the same relative size when rotated. */
+        {
+          GLfloat h = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
+          int o = (int) current_device_rotation();
+          if (o != 0 && o != 180 && o != -180)
+            glScalef (1/h, 1/h, 1/h);
+        }
+# endif
+
        llCurrent = tb->blockNodeRoot;
        if (drawCarpet) {
                /* center carpet */
@@ -803,7 +812,12 @@ ENTRYPOINT Bool
 topBlock_handle_event (ModeInfo *mi, XEvent *event)
 {
   topBlockSTATE *tb = &tbs[MI_SCREEN(mi)];
-       if (event->xany.type == KeyPress)    {
+
+  if (gltrackball_event_handler (event, tb->trackball,
+                                 MI_WIDTH (mi), MI_HEIGHT (mi),
+                                 &tb->button_down_p))
+    return True;
+  else if (event->xany.type == KeyPress) {
     KeySym keysym;
     char c = 0;
     XLookupString (&event->xkey, &c, 1, &keysym, 0);
@@ -848,40 +862,8 @@ topBlock_handle_event (ModeInfo *mi, XEvent *event)
                        return True;
                }
        }
-  if (event->xany.type == ButtonPress &&
-      event->xbutton.button == Button1)
-    {
-      tb->button_down_p = True;
-      gltrackball_start (tb->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)
-    {
-      tb->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 (tb->trackball, event->xbutton.button, 10,
-                              !!event->xbutton.state);
-      return True;
-    }
-  else if (event->xany.type == MotionNotify &&
-           tb->button_down_p)
-    {
-      gltrackball_track (tb->trackball,
-                         event->xmotion.x, event->xmotion.y,
-                         MI_WIDTH (mi), MI_HEIGHT (mi));
-      return True;
-    }
-       return False;
+
+  return False;
 }
 
 /* this is tha main change for v5 compatability and acompanying ENTRYPOINTS */