[gnome-games/wip/exalm/ds: 2/2] savestate-listbox-row: Use correct aspect ratio



commit f1ad8695c3fc05546a3a92c6af4e2256341e04e3
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Sun Aug 11 16:01:20 2019 +0500

    savestate-listbox-row: Use correct aspect ratio
    
    Try to fetch aspect ratio from savestate. Since older savestates are not
    going to have it, fall back to width/height for them.
    
    Fixes #204

 src/ui/savestate-listbox-row.vala | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)
---
diff --git a/src/ui/savestate-listbox-row.vala b/src/ui/savestate-listbox-row.vala
index 51b1cdb3..d0766b79 100644
--- a/src/ui/savestate-listbox-row.vala
+++ b/src/ui/savestate-listbox-row.vala
@@ -2,6 +2,8 @@
 
 [GtkTemplate (ui = "/org/gnome/Games/ui/savestate-listbox-row.ui")]
 private class Games.SavestateListBoxRow : Gtk.ListBoxRow {
+       public const int THUMBNAIL_SIZE = 64;
+
        [GtkChild]
        private Gtk.Image image;
        [GtkChild]
@@ -17,9 +19,8 @@ private class Games.SavestateListBoxRow : Gtk.ListBoxRow {
 
                        if (savestate.is_automatic ())
                                name_label.label = _("Autosave");
-                       else {
+                       else
                                name_label.label = savestate.get_name ();
-                       }
 
                        var creation_date = savestate.get_creation_date ();
 
@@ -27,8 +28,7 @@ private class Games.SavestateListBoxRow : Gtk.ListBoxRow {
              * by the abbreviated month name followed by the year followed
              * by a time in 24h format i.e. "3 Feb 2015 23:04:00" */
             /* xgettext:no-c-format */
-                       var creation_date_str = creation_date.format (_("%-e %b %Y %X"));
-                       date_label.label = creation_date_str;
+                       date_label.label = creation_date.format (_("%-e %b %Y %X"));
 
                        // Load the savestate thumbnail
                        var screenshot_path = savestate.get_screenshot_path ();
@@ -37,27 +37,31 @@ private class Games.SavestateListBoxRow : Gtk.ListBoxRow {
 
                        Gdk.Pixbuf.get_file_info (screenshot_path, out screenshot_width, out 
screenshot_height);
 
-                       var aspect_ratio = ((double) screenshot_width) / screenshot_height;
+                       var aspect_ratio = (double) savestate.get_screenshot_aspect_ratio ();
+
+                       // A fallback for savestates created during 3.33.90.
+                       if (aspect_ratio == 0)
+                               aspect_ratio = (double) screenshot_width / screenshot_height;
 
                        // Calculate the thumbnail width and height
-                       const int thumbnail_max_width_height = 64;
                        var thumbnail_width = screenshot_width;
-                       var thumbnail_height = screenshot_height;
+                       var thumbnail_height = (int) (screenshot_width / aspect_ratio);
 
-                       if (screenshot_width > screenshot_height && screenshot_width != 
thumbnail_max_width_height) {
-                               thumbnail_width = thumbnail_max_width_height;
-                               thumbnail_height = (int) (thumbnail_max_width_height / aspect_ratio);
+                       if (thumbnail_width > thumbnail_height && thumbnail_width != THUMBNAIL_SIZE) {
+                               thumbnail_width = THUMBNAIL_SIZE;
+                               thumbnail_height = (int) (THUMBNAIL_SIZE / aspect_ratio);
                        }
 
-                       if (screenshot_height > screenshot_width && screenshot_height != 
thumbnail_max_width_height) {
-                               thumbnail_height = thumbnail_max_width_height;
-                               thumbnail_width = (int) (thumbnail_max_width_height * aspect_ratio);
+                       if (thumbnail_height > thumbnail_width && thumbnail_height != THUMBNAIL_SIZE) {
+                               thumbnail_height = THUMBNAIL_SIZE;
+                               thumbnail_width = (int) (THUMBNAIL_SIZE * aspect_ratio);
                        }
 
-                       Gdk.Pixbuf thumbnail = null;
-
                        try {
-                               thumbnail = new Gdk.Pixbuf.from_file_at_scale (screenshot_path, 
thumbnail_width, thumbnail_height, false);
+                               var thumbnail = new Gdk.Pixbuf.from_file_at_scale (screenshot_path,
+                                                                                  thumbnail_width,
+                                                                                  thumbnail_height,
+                                                                                  false);
                                image.set_from_pixbuf (thumbnail);
                        }
                        catch (Error e) {


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