[gimp] app: improve splash screen sizing.



commit f1e2b7c8920b3e6589d7c9eb568a8aee43947ced
Author: Jehan <jehan girinstud io>
Date:   Sun Jan 14 05:48:18 2018 +0100

    app: improve splash screen sizing.
    
    Current code was using the dimension of the screen as a max size. That
    is really too big. 2/3 of the screen size is an acceptable size being
    both well visible and not overwhelming.
    Also the current code was cropping, not rescaling, the splash image,
    which is obviously not an acceptable solution because on a very small
    displays, we would end up with ununderstandable piece of a bigger image.
    
    This new code will allow to ship big size default splash image(s), and
    display it in an acceptable size on both low and high density displays.
    We indeed got a feedback from someone with a 4K display who was saying
    the current dev splash screen was tiny on one's display.
    
    Of course, custom splash can still be at any size; but from now on, we
    will need for the *default upstream splash image(s)* to be of huge
    dimension in order to show up well everywhere (at least Full HD splash,
    which is half of a 4K UHD screen).
    
    Animated splash images are still not resized though and will show up at
    their default dimension. This means we cannot ship animated splash
    screens as a default for the time being (they can still be installed as
    custom splash).

 app/gui/splash.c |  169 ++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 112 insertions(+), 57 deletions(-)
---
diff --git a/app/gui/splash.c b/app/gui/splash.c
index ba282a5..b336e94 100644
--- a/app/gui/splash.c
+++ b/app/gui/splash.c
@@ -63,28 +63,37 @@ typedef struct
 static GimpSplash *splash = NULL;
 
 
-static void        splash_position_layouts    (GimpSplash     *splash,
-                                               const gchar    *text1,
-                                               const gchar    *text2,
-                                               GdkRectangle   *area);
-static gboolean    splash_area_expose         (GtkWidget      *widget,
-                                               GdkEventExpose *event,
-                                               GimpSplash     *splash);
-static void        splash_rectangle_union     (GdkRectangle   *dest,
-                                               PangoRectangle *pango_rect,
-                                               gint            offset_x,
-                                               gint            offset_y);
-static gboolean    splash_average_text_area   (GimpSplash     *splash,
-                                               GdkPixbuf      *pixbuf,
-                                               GdkColor       *color);
+static void        splash_position_layouts     (GimpSplash     *splash,
+                                                const gchar    *text1,
+                                                const gchar    *text2,
+                                                GdkRectangle   *area);
+static gboolean    splash_area_expose          (GtkWidget      *widget,
+                                                GdkEventExpose *event,
+                                                GimpSplash     *splash);
+static void        splash_rectangle_union      (GdkRectangle   *dest,
+                                                PangoRectangle *pango_rect,
+                                                gint            offset_x,
+                                                gint            offset_y);
+static gboolean    splash_average_text_area    (GimpSplash     *splash,
+                                                GdkPixbuf      *pixbuf,
+                                                GdkColor       *color);
 
 static GdkPixbufAnimation *
-                   splash_image_load          (gboolean        be_verbose);
+                   splash_image_load           (gint            max_width,
+                                                gint            max_height,
+                                                gboolean        be_verbose);
 static GdkPixbufAnimation *
-                   splash_image_pick_from_dir (const gchar    *dirname,
-                                               gboolean        be_verbose);
+                   splash_image_load_from_file (const gchar    *filename,
+                                                gint            max_width,
+                                                gint            max_height,
+                                                gboolean        be_verbose);
+static GdkPixbufAnimation *
+                   splash_image_pick_from_dir  (const gchar    *dirname,
+                                                gint            max_width,
+                                                gint            max_height,
+                                                gboolean        be_verbose);
 
-static void        splash_timer_elapsed       (void);
+static void        splash_timer_elapsed        (void);
 
 
 /*  public functions  */
@@ -97,11 +106,15 @@ splash_create (gboolean   be_verbose,
   GtkWidget          *frame;
   GtkWidget          *vbox;
   GdkPixbufAnimation *pixbuf;
+  gint                max_width;
+  gint                max_height;
 
   g_return_if_fail (splash == NULL);
   g_return_if_fail (GDK_IS_SCREEN (screen));
 
-  pixbuf = splash_image_load (be_verbose);
+  max_width  = gdk_screen_get_width (screen) * 2 / 3;
+  max_height = gdk_screen_get_height (screen) * 2 / 3;
+  pixbuf = splash_image_load (max_width, max_height, be_verbose);
 
   if (! pixbuf)
     return;
@@ -403,60 +416,107 @@ splash_average_text_area (GimpSplash *splash,
 }
 
 static GdkPixbufAnimation *
-splash_image_load (gboolean be_verbose)
+splash_image_load (gint     max_width,
+                   gint     max_height,
+                   gboolean be_verbose)
 {
-  GdkPixbufAnimation *pixbuf;
+  GdkPixbufAnimation *animation = NULL;
   gchar              *filename;
 
+  /* File "gimp-splash.png" in personal configuration directory. */
   filename = gimp_personal_rc_file ("gimp-splash.png");
-
-  if (be_verbose)
-    g_printerr ("Trying splash '%s' ... ", filename);
-
-  pixbuf = gdk_pixbuf_animation_new_from_file (filename, NULL);
+  animation = splash_image_load_from_file (filename,
+                                           max_width, max_height,
+                                           be_verbose);
   g_free (filename);
+  if (animation)
+    return animation;
 
-  if (be_verbose)
-    g_printerr (pixbuf ? "OK\n" : "failed\n");
-
-  if (pixbuf)
-    return pixbuf;
-
+  /* Random image under splashes/ directory in personal config dir. */
   filename = gimp_personal_rc_file ("splashes");
-  pixbuf = splash_image_pick_from_dir (filename, be_verbose);
+  animation = splash_image_pick_from_dir (filename,
+                                          max_width, max_height,
+                                          be_verbose);
   g_free (filename);
+  if (animation)
+    return animation;
 
-  if (pixbuf)
-    return pixbuf;
-
+  /* Release splash image. */
   filename = g_build_filename (gimp_data_directory (),
                                "images", "gimp-splash.png", NULL);
+  animation = splash_image_load_from_file (filename,
+                                           max_width, max_height,
+                                           be_verbose);
+  g_free (filename);
+  if (animation)
+    return animation;
+
+  /* Random release image in installed splashes/ directory. */
+  filename = g_build_filename (gimp_data_directory (), "splashes", NULL);
+  animation = splash_image_pick_from_dir (filename,
+                                          max_width, max_height,
+                                          be_verbose);
+  g_free (filename);
+
+  return animation;
+}
 
+static GdkPixbufAnimation *
+splash_image_load_from_file (const gchar *filename,
+                             gint         max_width,
+                             gint         max_height,
+                             gboolean     be_verbose)
+{
+  GdkPixbufAnimation *animation;
   if (be_verbose)
     g_printerr ("Trying splash '%s' ... ", filename);
 
-  pixbuf = gdk_pixbuf_animation_new_from_file (filename, NULL);
-  g_free (filename);
+  animation = gdk_pixbuf_animation_new_from_file (filename, NULL);
 
-  if (be_verbose)
-    g_printerr (pixbuf ? "OK\n" : "failed\n");
+  /* FIXME Right now, we only try to scale static images.
+   * Animated images may end up bigger than the expected max dimensions.
+   */
+  if (animation && gdk_pixbuf_animation_is_static_image (animation) &&
+      (gdk_pixbuf_animation_get_width (animation) > max_width        ||
+       gdk_pixbuf_animation_get_height (animation) > max_height))
+    {
+      GdkPixbuf *pixbuf;
 
-  if (pixbuf)
-    return pixbuf;
+      pixbuf = gdk_pixbuf_new_from_file_at_size (filename,
+                                                 max_width, max_height,
+                                                 NULL);
+      if (pixbuf)
+        {
+          GdkPixbufSimpleAnim *simple_anim = NULL;
 
-  filename = g_build_filename (gimp_data_directory (), "splashes", NULL);
-  pixbuf = splash_image_pick_from_dir (filename, be_verbose);
-  g_free (filename);
+          simple_anim = gdk_pixbuf_simple_anim_new (gdk_pixbuf_get_width (pixbuf),
+                                                    gdk_pixbuf_get_height (pixbuf),
+                                                    1.0);
+          if (simple_anim)
+            {
+              gdk_pixbuf_simple_anim_add_frame (simple_anim, pixbuf);
 
-  return pixbuf;
+              g_object_unref (animation);
+              animation = GDK_PIXBUF_ANIMATION (simple_anim);
+            }
+          g_object_unref (pixbuf);
+        }
+    }
+
+  if (be_verbose)
+    g_printerr (animation ? "OK\n" : "failed\n");
+
+  return animation;
 }
 
 static GdkPixbufAnimation *
 splash_image_pick_from_dir (const gchar *dirname,
+                            gint         max_width,
+                            gint         max_height,
                             gboolean     be_verbose)
 {
-  GdkPixbufAnimation *pixbuf = NULL;
-  GDir               *dir    = g_dir_open (dirname, 0, NULL);
+  GdkPixbufAnimation *animation = NULL;
+  GDir               *dir       = g_dir_open (dirname, 0, NULL);
 
   if (dir)
     {
@@ -475,20 +535,15 @@ splash_image_pick_from_dir (const gchar *dirname,
                                                g_list_nth_data (splashes, i),
                                                NULL);
 
-          if (be_verbose)
-            g_printerr ("Trying splash '%s' ... ", filename);
-
-          pixbuf = gdk_pixbuf_animation_new_from_file (filename, NULL);
+          animation = splash_image_load_from_file (filename,
+                                                   max_width, max_height,
+                                                   be_verbose);
           g_free (filename);
-
-          if (be_verbose)
-            g_printerr (pixbuf ? "OK\n" : "failed\n");
-
           g_list_free_full (splashes, (GDestroyNotify) g_free);
         }
     }
 
-  return pixbuf;
+  return animation;
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]