[gnome-music/wip/jfelder/gtk4-v3: 181/181] coverpaintable: Fix aspect ratio handling




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

    coverpaintable: Fix aspect ratio handling

 gnomemusic/coverpaintable.py | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/gnomemusic/coverpaintable.py b/gnomemusic/coverpaintable.py
index 299c15870..e2f84c61e 100644
--- a/gnomemusic/coverpaintable.py
+++ b/gnomemusic/coverpaintable.py
@@ -71,14 +71,23 @@ 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()
+            print(ratio)
+            # 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]