[gnome-music/wip/mschraal/gtk4-v3: 177/187] coverpaintable: Fix aspect ratio handling




commit 6b373d1900da2e12f5682cda807c1eaf557dcf06
Author: Marinus Schraal <mschraal gnome org>
Date:   Sun Feb 6 23:03:47 2022 +0100

    coverpaintable: Fix aspect ratio handling

 gnomemusic/coverpaintable.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
---
diff --git a/gnomemusic/coverpaintable.py b/gnomemusic/coverpaintable.py
index 299c15870..540f2371d 100644
--- a/gnomemusic/coverpaintable.py
+++ b/gnomemusic/coverpaintable.py
@@ -71,14 +71,22 @@ class CoverPaintable(GObject.GObject, Gdk.Paintable):
         else:
             radius = 9.0
 
-        rect = Graphene.Rect().init(0, 0, w, h)
+        w_s = w
+        h_s = h
+        if self._texture is not None:
+            ratio = self._texture.get_height() / self._texture.get_width()
+            # Scale down the image according to the biggest axis
+            if ratio > 1:
+                w = int(w / ratio)
+            else:
+                h = int(h * ratio)
+
+        rect = Graphene.Rect().init((w_s - w) / 2, (h_s - h) / 2, w, h)
         rounded_rect = Gsk.RoundedRect()
         rounded_rect.init_from_rect(rect, radius)
         snapshot.push_rounded_clip(rounded_rect)
 
         if self._texture is not None:
-            snapshot.translate(Graphene.Point().init(w / 2, h / 2))
-            rect = Graphene.Rect().init(-(w / 2), -(h / 2), w, h)
             snapshot.append_texture(self._texture, rect)
         else:
             i_s = 1 / 3  # Icon scale


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