[gnome-music/wip/mschraal/cleanup-default-icon: 2/2] albumartcache: Modernize DefaultIcon



commit eaecc5e8ab32131e52f69aaa3107d02a47b097dd
Author: Marinus Schraal <mschraal gnome org>
Date:   Sat Jul 28 23:53:03 2018 +0200

    albumartcache: Modernize DefaultIcon
    
    * Use lookup_icon_for_scale.
    * Simplify composite function and allow adjustable scaling.
    * Code style update.

 gnomemusic/albumartcache.py | 37 +++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 18 deletions(-)
---
diff --git a/gnomemusic/albumartcache.py b/gnomemusic/albumartcache.py
index ac462f2e..88022220 100644
--- a/gnomemusic/albumartcache.py
+++ b/gnomemusic/albumartcache.py
@@ -113,26 +113,27 @@ class DefaultIcon(GObject.GObject):
         width = art_size.width * scale
         height = art_size.height * scale
 
-        icon = Gtk.IconTheme.get_default().load_icon(icon_type.value,
-                                                     max(width, height) / 4,
-                                                     0)
-
-        # create an empty pixbuf with the requested size
-        result = GdkPixbuf.Pixbuf.new(icon.get_colorspace(),
-                                      True,
-                                      icon.get_bits_per_sample(),
-                                      width,
-                                      height)
+        # TODO: Load icon async.
+        default_theme = Gtk.IconTheme.get_default()
+        icon_info = default_theme.lookup_icon_for_scale(
+            icon_type.value, max(art_size.width, art_size.height), scale, 0)
+        icon = icon_info.load_icon()
+
+        result = GdkPixbuf.Pixbuf.new(
+            icon.get_colorspace(), True, icon.get_bits_per_sample(), width,
+            height)
         result.fill(0xffffffff)
 
-        icon.composite(result,
-                       icon.get_width() * 3 / 2,
-                       icon.get_height() * 3 / 2,
-                       icon.get_width(),
-                       icon.get_height(),
-                       icon.get_width() * 3 / 2,
-                       icon.get_height() * 3 / 2,
-                       1, 1, GdkPixbuf.InterpType.HYPER, 0x33)
+        icon_scale = 0.33
+
+        def icon_offset(x):
+            return int((x / 2) - (x * icon_scale * 0.5))
+
+        icon.composite(
+            result, icon_offset(width), icon_offset(height),
+            width * icon_scale, height * icon_scale, icon_offset(width),
+            icon_offset(height), icon_scale, icon_scale,
+            GdkPixbuf.InterpType.HYPER, 0x77)
 
         icon_surface = _make_icon_frame(result, art_size, scale)
 


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