[gnome-games/wip/exalm/collection: 143/143] cover-loader: Center and crop covers



commit 590838ca5a0a8f3997ffef44cf13483338485ea8
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Tue Nov 19 23:03:26 2019 +0500

    cover-loader: Center and crop covers

 src/core/cover-loader.vala | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/src/core/cover-loader.vala b/src/core/cover-loader.vala
index e8e0bb00..10828868 100644
--- a/src/core/cover-loader.vala
+++ b/src/core/cover-loader.vala
@@ -24,7 +24,7 @@ public class Games.CoverLoader : Object {
                });
        }
 
-       private void get_dimensions (File file, int size, out int width, out int height) {
+       private void get_dimensions (File file, int size, out int width, out int height, out int x, out int 
y) {
                int w, h;
                Gdk.Pixbuf.get_file_info (file.get_path (), out w, out h);
 
@@ -32,14 +32,18 @@ public class Games.CoverLoader : Object {
 
                width = w;
                height = (int) (w / aspect_ratio);
+               x = 0;
+               y = 0;
 
-               if (width > h) {
+               if (h > w) {
                        width = size;
                        height = (int) (size / aspect_ratio);
+                       y = (height - size) / 2;
                }
                else {
                        height = size;
                        width = (int) (size * aspect_ratio);
+                       x = (width - size) / 2;
                }
        }
 
@@ -61,11 +65,12 @@ public class Games.CoverLoader : Object {
                                continue;
                        }
 
-                       int width, height;
-                       get_dimensions (file, size, out width, out height);
+                       int x, y, width, height;
+                       get_dimensions (file, size, out width, out height, out x, out y);
 
                        try {
                                pixbuf = new Gdk.Pixbuf.from_file_at_scale (file.get_path (), width, height, 
false);
+                               pixbuf = new Gdk.Pixbuf.subpixbuf (pixbuf, x, y, size, size);
                                save_cover_cache_to_disk (game, pixbuf, size);
                        }
                        catch (Error e) {


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