[gnome-games/wip/theawless/simplify-thumbnail: 15/17] game-thumbnail: Allow caching icons



commit 9b8624a1b47d01ba9a868c0439d000d7f271c214
Author: theawless <theawless gmail com>
Date:   Sat Oct 6 17:29:31 2018 +0530

    game-thumbnail: Allow caching icons

 src/ui/game-thumbnail.vala | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)
---
diff --git a/src/ui/game-thumbnail.vala b/src/ui/game-thumbnail.vala
index ec499c97..759cbc16 100644
--- a/src/ui/game-thumbnail.vala
+++ b/src/ui/game-thumbnail.vala
@@ -13,7 +13,8 @@ private class Games.GameThumbnail: Gtk.DrawingArea {
 
                        _uid = value;
 
-                       queue_draw ();
+                       icon_cache = null;
+                       invalidate_cover ();
                }
        }
 
@@ -26,6 +27,7 @@ private class Games.GameThumbnail: Gtk.DrawingArea {
 
                        _icon = value;
 
+                       icon_cache = null;
                        queue_draw ();
                }
        }
@@ -51,9 +53,10 @@ private class Games.GameThumbnail: Gtk.DrawingArea {
        }
 
        private bool tried_loading_cover;
+       private Gdk.Pixbuf? icon_cache;
        private Gdk.Pixbuf? cover_cache;
-       private int previous_cover_width;
-       private int previous_cover_height;
+       private int cache_width;
+       private int cache_height;
 
        public struct DrawingContext {
                Cairo.Context cr;
@@ -87,6 +90,14 @@ private class Games.GameThumbnail: Gtk.DrawingArea {
                        cr, window, style, state, width, height
                };
 
+               if (cache_height != context.height || cache_width != context.width) {
+                       cache_height = context.height;
+                       cache_width = context.width;
+                       icon_cache = null;
+                       cover_cache = null;
+                       tried_loading_cover = false;
+               }
+
                var drawn = false;
 
                drawn = draw_cover (context);
@@ -114,18 +125,6 @@ private class Games.GameThumbnail: Gtk.DrawingArea {
        }
 
        public bool draw_cover (DrawingContext context) {
-               if (previous_cover_width != context.width) {
-                       previous_cover_width = context.width;
-                       cover_cache = null;
-                       tried_loading_cover = false;
-               }
-
-               if (previous_cover_height != context.height) {
-                       previous_cover_height = context.height;
-                       cover_cache = null;
-                       tried_loading_cover = false;
-               }
-
                var pixbuf = get_cover_cache (context.width, context.height);
                if (pixbuf == null)
                        return false;


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