From http://www.jwz.org/xscreensaver/xscreensaver-5.37.tar.gz
[xscreensaver] / hacks / glx / carousel.c
index 2a2a0ceeb3f08bdd26f04f07c7902adbdcfd7bd3..7f7a8da628a267761048e3f9aaecf21a2ea4c06e 100644 (file)
@@ -1,4 +1,4 @@
-/* carousel, Copyright (c) 2005-2012 Jamie Zawinski <jwz@jwz.org>
+/* carousel, Copyright (c) 2005-2015 Jamie Zawinski <jwz@jwz.org>
  * Loads a sequence of images and rotates them around.
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
@@ -12,7 +12,7 @@
  * Created: 21-Feb-2005
  */
 
-#define DEF_FONT "-*-helvetica-bold-r-normal-*-240-*"
+#define DEF_FONT "-*-helvetica-bold-r-normal-*-*-240-*-*-*-*-*-*"
 #define DEFAULTS  "*count:           7         \n" \
                  "*delay:           10000     \n" \
                  "*wireframe:       False     \n" \
@@ -46,7 +46,7 @@
 #include "grab-ximage.h"
 #include "texfont.h"
 
-# ifndef HAVE_COCOA
+# ifndef HAVE_JWXYZ
 #  include <X11/Intrinsic.h>     /* for XrmDatabase in -debug mode */
 # endif
 
@@ -426,11 +426,6 @@ carousel_handle_event (ModeInfo *mi, XEvent *event)
     {
       if (! ss->button_down_p)
         ss->button_down_time = time((time_t *) 0);
-      ss->button_down_p = True;
-      gltrackball_start (ss->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)
@@ -446,25 +441,16 @@ carousel_handle_event (ModeInfo *mi, XEvent *event)
           for (i = 0; i < ss->nframes; i++)
             ss->frames[i]->expires += secs;
         }
-      ss->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 (ss->trackball, event->xbutton.button, 5,
-                              !event->xbutton.state);
-      return True;
-    }
-  else if (event->xany.type == MotionNotify &&
-           ss->button_down_p)
+
+  if (gltrackball_event_handler (event, ss->trackball,
+                                 MI_WIDTH (mi), MI_HEIGHT (mi),
+                                 &ss->button_down_p))
+    return True;
+  else if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event))
     {
-      gltrackball_track (ss->trackball,
-                         event->xmotion.x, event->xmotion.y,
-                         MI_WIDTH (mi), MI_HEIGHT (mi));
+      int i = random() % ss->nframes;
+      ss->frames[i]->expires  = 0;
       return True;
     }
 
@@ -477,7 +463,7 @@ carousel_handle_event (ModeInfo *mi, XEvent *event)
 static void
 hack_resources (Display *dpy)
 {
-# ifndef HAVE_COCOA
+# ifndef HAVE_JWXYZ
   char *res = "desktopGrabber";
   char *val = get_string_resource (dpy, res, "DesktopGrabber");
   char buf1[255];
@@ -489,7 +475,7 @@ hack_resources (Display *dpy)
   value.addr = buf2;
   value.size = strlen(buf2);
   XrmPutResource (&db, buf1, "String", &value);
-# endif /* !HAVE_COCOA */
+# endif /* !HAVE_JWXYZ */
 }
 
 
@@ -508,21 +494,48 @@ loading_msg (ModeInfo *mi, int n)
     sprintf (text, "Loading images...  (%d%%)",
              (int) (n * 100 / MI_COUNT(mi)));
 
-  if (ss->loading_sw == 0)    /* only do this once, so that the string doesn't move. */
-    ss->loading_sw = texture_string_width (ss->texfont, text, &ss->loading_sh);
+  if (ss->loading_sw == 0)
+    {
+      /* only do this once, so that the string doesn't move. */
+      XCharStruct e;
+      texture_string_metrics (ss->texfont, text, &e, 0, 0);
+      ss->loading_sw = e.width;
+      ss->loading_sh = e.ascent + e.descent;
+    }
 
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
   glMatrixMode(GL_PROJECTION);
   glPushMatrix();
   glLoadIdentity();
-  glRotatef(current_device_rotation(), 0, 0, 1);
 
   glMatrixMode(GL_MODELVIEW);
   glPushMatrix();
   glLoadIdentity();
-  glOrtho(0, MI_WIDTH(mi), 0, MI_HEIGHT(mi), -1, 1);
 
+/*
+  {
+    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 (s, 1/s, 1);
+      }
+  }
+*/
+
+# ifdef HAVE_MOBILE
+  if (MI_WIDTH(mi) < MI_HEIGHT(mi))  /* portrait orientation */
+    {
+      GLfloat s = (MI_WIDTH(mi) / (GLfloat) MI_HEIGHT(mi));
+      glScalef (s, s, s);
+      glTranslatef(-s/2, 0, 0);
+    }
+# endif
+
+  glOrtho(0, MI_WIDTH(mi), 0, MI_HEIGHT(mi), -1, 1);
   glTranslatef ((MI_WIDTH(mi)  - ss->loading_sw) / 2,
                 (MI_HEIGHT(mi) - ss->loading_sh) / 2,
                 0);
@@ -550,11 +563,7 @@ init_carousel (ModeInfo *mi)
   carousel_state *ss;
   int wire = MI_IS_WIREFRAME(mi);
   
-  if (sss == NULL) {
-    if ((sss = (carousel_state *)
-         calloc (MI_NUM_SCREENS(mi), sizeof(carousel_state))) == NULL)
-      return;
-  }
+  MI_INIT (mi, sss, NULL);
   ss = &sss[screen];
 
   if ((ss->glx_context = init_GL(mi)) != NULL) {
@@ -592,7 +601,7 @@ init_carousel (ModeInfo *mi)
     ss->rot = make_rotator (spin_speed, spin_speed, spin_speed,
                             spin_accel, wander_speed, True);
 
-    ss->trackball = gltrackball_init ();
+    ss->trackball = gltrackball_init (False);
   }
 
   if (strstr ((char *) glGetString(GL_EXTENSIONS),
@@ -770,10 +779,13 @@ draw_frame (ModeInfo *mi, image_frame *frame, time_t now, Bool body_p)
     }
   else                                 /* Draw a title under the image. */
     {
+      XCharStruct e;
       int sw, sh;
       GLfloat scale = 0.05;
       char *title = frame->current.title ? frame->current.title : "(untitled)";
-      sw = texture_string_width (ss->texfont, title, &sh);
+      texture_string_metrics (ss->texfont, title, &e, 0, 0);
+      sw = e.width;
+      sh = e.ascent + e.descent;
 
       glTranslatef (0, -scale, 0);
 
@@ -833,6 +845,8 @@ draw_carousel (ModeInfo *mi)
 
   glPushMatrix();
 
+  glRotatef(current_device_rotation(), 0, 0, 1);
+
 
   /* Run the startup "un-shrink" animation.
    */
@@ -868,7 +882,6 @@ draw_carousel (ModeInfo *mi)
   {
     double x, y, z;
     gltrackball_rotate (ss->trackball);
-    glRotatef(current_device_rotation(), 0, 0, 1);
 
     /* Tilt the tube up or down by up to 30 degrees */
     get_position (ss->rot, &x, &y, &z, !ss->button_down_p);