]> git.hungrycats.org Git - xscreensaver/blobdiff - hacks/glx/carousel.c
From https://www.jwz.org/xscreensaver/xscreensaver-6.09.tar.gz
[xscreensaver] / hacks / glx / carousel.c
index 7f7a8da628a267761048e3f9aaecf21a2ea4c06e..a1aa802ea1a704e1e1bb50526dc65291a8efd6a0 100644 (file)
@@ -1,4 +1,4 @@
-/* carousel, Copyright (c) 2005-2015 Jamie Zawinski <jwz@jwz.org>
+/* carousel, Copyright © 2005-2023 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
  * Created: 21-Feb-2005
  */
 
-#define DEF_FONT "-*-helvetica-bold-r-normal-*-*-240-*-*-*-*-*-*"
+#define DEF_FONT \
+  "OCR A 48, OCR A Std 48, Lucida Console 48, Monaco 48, Courier 48, monospace 48"
+#define DEF_TITLE_FONT "sans-serif bold 48"
+
 #define DEFAULTS  "*count:           7         \n" \
                  "*delay:           10000     \n" \
                  "*wireframe:       False     \n" \
                  "*fpsSolid:        True      \n" \
                  "*useSHM:          True      \n" \
                  "*font:          " DEF_FONT "\n" \
+                 "*titleFont:     " DEF_TITLE_FONT "\n" \
                   "*desktopGrabber:  xscreensaver-getimage -no-desktop %s\n" \
                  "*grabDesktopImages:   False \n" \
                  "*chooseRandomImages:  True  \n"
 
-# define refresh_carousel 0
 # define release_carousel 0
 # include "xlockmore.h"
 
-#undef countof
-#define countof(x) (sizeof((x))/sizeof((*x)))
-
 #ifdef USE_GL
 
 # define DEF_SPEED          "1.0"
@@ -101,7 +101,7 @@ typedef struct {
   Bool awaiting_first_images_p;
   int loads_in_progress;
 
-  texture_font_data *texfont;
+  texture_font_data *texfont, *titlefont;
 
   fade_mode mode;
   int mode_tick;
@@ -232,6 +232,11 @@ load_image (ModeInfo *mi, image_frame *frame)
       int h = (MI_HEIGHT(mi) / 2) - 1;
       if (w <= 10) w = 10;
       if (h <= 10) h = 10;
+
+      if (w > h * 5) {   /* tiny window: use 16:9 boxes */
+        h = w * 9/16;
+      }
+
       load_texture_async (mi->xgwa.screen, mi->window, *ss->glx_context, w, h,
                           mipmap_p, frame->loading.texid, 
                           image_loaded_cb, frame);
@@ -399,8 +404,15 @@ ENTRYPOINT void
 reshape_carousel (ModeInfo *mi, int width, int height)
 {
   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, 0, (GLint) width, (GLint) height);
+  glViewport (0, y, (GLint) width, (GLint) height);
 
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
@@ -475,6 +487,7 @@ hack_resources (Display *dpy)
   value.addr = buf2;
   value.size = strlen(buf2);
   XrmPutResource (&db, buf1, "String", &value);
+  free (val);
 # endif /* !HAVE_JWXYZ */
 }
 
@@ -498,7 +511,7 @@ loading_msg (ModeInfo *mi, int n)
     {
       /* only do this once, so that the string doesn't move. */
       XCharStruct e;
-      texture_string_metrics (ss->texfont, text, &e, 0, 0);
+      texture_string_metrics (ss->titlefont, text, &e, 0, 0);
       ss->loading_sw = e.width;
       ss->loading_sh = e.ascent + e.descent;
     }
@@ -526,14 +539,13 @@ loading_msg (ModeInfo *mi, int n)
   }
 */
 
-# 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
+  {
+    GLfloat s = (MI_WIDTH(mi) < MI_HEIGHT(mi)
+                 ? (MI_WIDTH(mi) / (GLfloat) MI_HEIGHT(mi))
+                 : 1);
+    glRotatef (current_device_rotation(), 0, 0, 1);
+    glScalef (s, s, s);
+  }
 
   glOrtho(0, MI_WIDTH(mi), 0, MI_HEIGHT(mi), -1, 1);
   glTranslatef ((MI_WIDTH(mi)  - ss->loading_sw) / 2,
@@ -542,7 +554,9 @@ loading_msg (ModeInfo *mi, int n)
   glColor3f (1, 1, 0);
   glEnable (GL_TEXTURE_2D);
   glDisable (GL_DEPTH_TEST);
-  print_texture_string (ss->texfont, text);
+# ifndef HAVE_ANDROID   /* Doesn't work -- photo displays as static */
+  print_texture_string (ss->titlefont, text);
+# endif
   glEnable (GL_DEPTH_TEST);
   glPopMatrix();
 
@@ -563,7 +577,7 @@ init_carousel (ModeInfo *mi)
   carousel_state *ss;
   int wire = MI_IS_WIREFRAME(mi);
   
-  MI_INIT (mi, sss, NULL);
+  MI_INIT (mi, sss);
   ss = &sss[screen];
 
   if ((ss->glx_context = init_GL(mi)) != NULL) {
@@ -631,6 +645,7 @@ init_carousel (ModeInfo *mi)
     }
 
   ss->texfont = load_texture_font (MI_DISPLAY(mi), "font");
+  ss->titlefont = load_texture_font (MI_DISPLAY(mi), "titleFont");
 
   if (debug_p)
     hack_resources (MI_DISPLAY (mi));
@@ -777,8 +792,8 @@ draw_frame (ModeInfo *mi, image_frame *frame, time_t now, Bool body_p)
       glEnd();
 
     }
-  else                                 /* Draw a title under the image. */
-    {
+  else if (frame->current.title && *frame->current.title)
+    {                                  /* Draw a title under the image. */
       XCharStruct e;
       int sw, sh;
       GLfloat scale = 0.05;
@@ -798,7 +813,9 @@ draw_frame (ModeInfo *mi, image_frame *frame, time_t now, Bool body_p)
       if (!wire)
         {
           glEnable (GL_TEXTURE_2D);
+# ifndef HAVE_ANDROID   /* Doesn't work -- photo displays as static */
           print_texture_string (ss->texfont, title);
+# endif
         }
       else
         {
@@ -824,7 +841,7 @@ draw_carousel (ModeInfo *mi)
   if (!ss->glx_context)
     return;
 
-  glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(ss->glx_context));
+  glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *ss->glx_context);
 
   if (ss->awaiting_first_images_p)
     if (!load_initial_images (mi))
@@ -913,6 +930,29 @@ draw_carousel (ModeInfo *mi)
   glXSwapBuffers (MI_DISPLAY (mi), MI_WINDOW(mi));
 }
 
+
+ENTRYPOINT void
+free_carousel (ModeInfo *mi)
+{
+  carousel_state *ss = &sss[MI_SCREEN(mi)];
+  int i;
+  if (!ss->glx_context) return;
+  glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *ss->glx_context);
+  if (ss->rot) free_rotator (ss->rot);
+  if (ss->trackball) gltrackball_free (ss->trackball);
+  if (ss->texfont) free_texture_font (ss->texfont);
+  if (ss->titlefont) free_texture_font (ss->titlefont);
+  for (i = 0; i < ss->nframes; i++) {
+    if (ss->frames[i]->current.title) free (ss->frames[i]->current.title);
+    if (ss->frames[i]->loading.title) free (ss->frames[i]->loading.title);
+    if (ss->frames[i]->rot) free_rotator (ss->frames[i]->rot);
+    if (ss->frames[i]->current.texid)
+      glDeleteTextures (1, &ss->frames[i]->current.texid);
+    if (ss->frames[i]->loading.texid)
+      glDeleteTextures (1, &ss->frames[i]->loading.texid);
+  }
+}
+
 XSCREENSAVER_MODULE ("Carousel", carousel)
 
 #endif /* USE_GL */