From eaecc5e8ab32131e52f69aaa3107d02a47b097dd Mon Sep 17 00:00:00 2001 From: Marinus Schraal Date: Sat, 28 Jul 2018 23:53:03 +0200 Subject: [PATCH] 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 ac462f2ee..880222209 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) -- GitLab