From http://www.jwz.org/xscreensaver/xscreensaver-5.37.tar.gz
[xscreensaver] / hacks / glx / glslideshow.c
index 386b4d8ff8a0b9b84bb6e59c472ff3e8dffc0780..a6a56905e597d975d00eb63e43615c947d6cf912 100644 (file)
@@ -1,4 +1,4 @@
-/* glslideshow, Copyright (c) 2003-2008 Jamie Zawinski <jwz@jwz.org>
+/* glslideshow, Copyright (c) 2003-2014 Jamie Zawinski <jwz@jwz.org>
  * Loads a sequence of images and smoothly pans around them; crossfades
  * when loading new images.
  *
@@ -73,7 +73,7 @@
                   "*showFPS:         False                \n" \
                  "*fpsSolid:        True                 \n" \
                  "*useSHM:          True                 \n" \
-                 "*titleFont:       -*-helvetica-medium-r-normal-*-180-*\n" \
+            "*titleFont: -*-helvetica-medium-r-normal-*-*-180-*-*-*-*-*-*\n" \
                   "*desktopGrabber:  xscreensaver-getimage -no-desktop %s\n" \
                  "*grabDesktopImages:   False \n" \
                  "*chooseRandomImages:  True  \n"
@@ -99,7 +99,7 @@
 # define DEF_MIPMAP         "True"
 
 #include "grab-ximage.h"
-#include "glxfonts.h"
+#include "texfont.h"
 
 typedef struct {
   double x, y, w, h;
@@ -160,8 +160,7 @@ typedef struct {
   Bool checked_fps_p;          /* Whether we have checked for a low
                                    frame rate. */
 
-  XFontStruct *xfont;          /* for printing image file names */
-  GLuint font_dlist;
+  texture_font_data *font_data;        /* for printing image file names */
 
   int sprite_id, image_id;      /* debugging id counters */
 
@@ -227,7 +226,7 @@ ENTRYPOINT ModeSpecOpt slideshow_opts = {countof(opts), opts, countof(vars), var
 static const char *
 blurb (void)
 {
-# ifdef HAVE_COCOA
+# ifdef HAVE_JWXYZ
   return "GLSlideshow";
 # else
   static char buf[255];
@@ -358,8 +357,12 @@ image_loaded_cb (const char *filename, XRectangle *geom,
       img->geom.height *= scale;
     }
 
-  if (img->title)  /* strip filename to part between last "/" and last ".". */
+  /* xscreensaver-getimage returns paths relative to the image directory
+     now, so leave the sub-directory part in.  Unless it's an absolute path.
+  */
+  if (img->title && img->title[0] == '/')
     {
+      /* strip filename to part between last "/" and last ".". */
       char *s = strrchr (img->title, '/');
       if (s) strcpy (img->title, s+1);
       s = strrchr (img->title, '.');
@@ -803,19 +806,13 @@ draw_sprite (ModeInfo *mi, sprite *sp)
 
 
     if (do_titles &&
-        img->title && *img->title)
+        img->title && *img->title &&
+        (sp->state == IN || sp->state == FULL))
       {
-        int x = 10;
-        int y = mi->xgwa.height - 10;
-        glColor4f (0, 0, 0, sp->opacity);   /* cheap-assed dropshadow */
-        print_gl_string (mi->dpy, ss->xfont, ss->font_dlist,
-                         mi->xgwa.width, mi->xgwa.height, x, y,
-                         img->title, False);
-        x++; y++;
         glColor4f (1, 1, 1, sp->opacity);
-        print_gl_string (mi->dpy, ss->xfont, ss->font_dlist,
-                         mi->xgwa.width, mi->xgwa.height, x, y,
-                         img->title, False);
+        print_texture_label (mi->dpy, ss->font_data,
+                             mi->xgwa.width, mi->xgwa.height,
+                             1, img->title);
       }
   }
   glPopMatrix();
@@ -869,6 +866,22 @@ draw_sprites (ModeInfo *mi)
   glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
   glPushMatrix();
+
+/*
+  {
+    GLfloat rot = current_device_rotation();
+    glTranslatef (0.5, 0.5, 0);
+    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);
+      }
+    glTranslatef (-0.5, -0.5, 0);
+  }
+*/
+
   for (i = 0; i < ss->nsprites; i++)
     draw_sprite (mi, ss->sprites[i]);
   glPopMatrix();
@@ -900,6 +913,7 @@ reshape_slideshow (ModeInfo *mi, int width, int height)
   glViewport (0, 0, width, height);
   glMatrixMode (GL_PROJECTION);
   glLoadIdentity();
+  glRotatef (current_device_rotation(), 0, 0, 1);
   glMatrixMode (GL_MODELVIEW);
   glLoadIdentity();
 
@@ -925,24 +939,7 @@ slideshow_handle_event (ModeInfo *mi, XEvent *event)
 {
   slideshow_state *ss = &sss[MI_SCREEN(mi)];
 
-  if (event->xany.type == ButtonPress &&
-      event->xbutton.button == Button1)
-    {
-      ss->change_now_p = True;
-      return True;
-    }
-  else if (event->xany.type == KeyPress)
-    {
-      KeySym keysym;
-      char c = 0;
-      XLookupString (&event->xkey, &c, 1, &keysym, 0);
-      if (c == ' ' || c == '\r' || c == '\n' || c == '\t')
-        {
-          ss->change_now_p = True;
-          return True;
-        }
-    }
-  else if (event->xany.type == Expose ||
+  if (event->xany.type == Expose ||
            event->xany.type == GraphicsExpose ||
            event->xany.type == VisibilityNotify)
     {
@@ -951,6 +948,11 @@ slideshow_handle_event (ModeInfo *mi, XEvent *event)
         fprintf (stderr, "%s: exposure\n", blurb());
       return False;
     }
+  else if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event))
+    {
+      ss->change_now_p = True;
+      return True;
+    }
 
   return False;
 }
@@ -994,7 +996,7 @@ sanity_check (ModeInfo *mi)
 static void
 check_fps (ModeInfo *mi)
 {
-#ifndef HAVE_COCOA  /* always assume Cocoa is fast enough */
+#ifndef HAVE_JWXYZ  /* always assume Cocoa and mobile are fast enough */
 
   slideshow_state *ss = &sss[MI_SCREEN(mi)];
 
@@ -1046,7 +1048,7 @@ check_fps (ModeInfo *mi)
 
   /* Need this in case zoom changed. */
   reshape_slideshow (mi, mi->xgwa.width, mi->xgwa.height);
-#endif /* HAVE_COCOA */
+#endif /* HAVE_JWXYZ */
 }
 
 
@@ -1077,11 +1079,7 @@ init_slideshow (ModeInfo *mi)
   slideshow_state *ss;
   int wire = MI_IS_WIREFRAME(mi);
   
-  if (sss == NULL) {
-    if ((sss = (slideshow_state *)
-         calloc (MI_NUM_SCREENS(mi), sizeof(slideshow_state))) == NULL)
-      return;
-  }
+  MI_INIT (mi, sss, NULL);
   ss = &sss[screen];
 
   if ((ss->glx_context = init_GL(mi)) != NULL) {
@@ -1116,7 +1114,7 @@ init_slideshow (ModeInfo *mi)
 
   if (debug_p) glLineWidth (3);
 
-  load_font (mi->dpy, "titleFont", &ss->xfont, &ss->font_dlist);
+  ss->font_data = load_texture_font (mi->dpy, "titleFont");
 
   if (debug_p)
     hack_resources();
@@ -1210,7 +1208,6 @@ draw_slideshow (ModeInfo *mi)
 
   draw_sprites (mi);
 
-  ss->fps = fps_compute (mi->fpst, 0);
   if (mi->fps_p) do_fps (mi);
 
   glFinish();