[gnome-games/wip/theawless/simplify-thumbnail] game-thumbnail: Unify draw call



commit fecc6acf7b8454f32a6fc70942069d37d4f8679b
Author: theawless <theawless gmail com>
Date:   Tue Oct 2 20:44:27 2018 +0530

    game-thumbnail: Unify draw call

 src/ui/game-thumbnail.vala | 65 ++++++++++++++--------------------------------
 1 file changed, 20 insertions(+), 45 deletions(-)
---
diff --git a/src/ui/game-thumbnail.vala b/src/ui/game-thumbnail.vala
index b23e4a69..82d9cf1f 100644
--- a/src/ui/game-thumbnail.vala
+++ b/src/ui/game-thumbnail.vala
@@ -99,58 +99,26 @@ private class Games.GameThumbnail: Gtk.DrawingArea {
                        tried_loading_cover = false;
                }
 
-               var drawn = false;
+               load_cache (context);
 
-               drawn = draw_cover (context);
-
-               if (!drawn)
-                       drawn = draw_icon (context);
-
-               // Draw the default thumbnail if no thumbnail have been drawn
-               if (!drawn)
-                       draw_emblem (context);
-
-               return true;
-       }
-
-       public bool draw_icon (DrawingContext context) {
-               if (icon_cache == null)
-                       load_icon_cache (context);
-               if (icon_cache == null)
-                       return false;
-
-               draw_background (context);
-               draw_pixbuf (context, icon_cache);
                draw_border (context);
+               if (cover_cache != null)
+                       draw_black_background (context);
+               else
+                       draw_background (context);
 
-               return true;
-       }
-
-       public bool draw_cover (DrawingContext context) {
-               if (cover_cache == null)
-                       load_cover_cache (context);
-               if (cover_cache == null)
-                       return false;
-
-               var border_radius = (int) context.style.get_property (Gtk.STYLE_PROPERTY_BORDER_RADIUS, 
context.state);
-
-               context.cr.set_source_rgb (0, 0, 0);
-               rounded_rectangle (context.cr, 0.5, 0.5, context.width - 1, context.height - 1, 
border_radius);
-               context.cr.fill ();
-               draw_pixbuf (context, cover_cache);
-               draw_border (context);
+               var thumbnail = cover_cache ?? icon_cache ?? get_emblem (context);
+               if (thumbnail != null)
+                       draw_pixbuf (context, thumbnail);
 
                return true;
        }
 
-       public void draw_emblem (DrawingContext context) {
-               var pixbuf = get_emblem (context);
-               if (pixbuf == null)
-                       return;
-
-               draw_background (context);
-               draw_pixbuf (context, pixbuf);
-               draw_border (context);
+       private void load_cache (DrawingContext context) {
+               if (cover_cache == null && icon_cache == null)
+                       load_cover_cache (context);
+               if (cover_cache == null && icon_cache == null)
+                       load_icon_cache (context);
        }
 
        private Gdk.Pixbuf? get_emblem (DrawingContext context) {
@@ -308,6 +276,13 @@ private class Games.GameThumbnail: Gtk.DrawingArea {
                return mask;
        }
 
+       private void draw_black_background (DrawingContext context) {
+               var border_radius = (int) context.style.get_property (Gtk.STYLE_PROPERTY_BORDER_RADIUS, 
context.state);
+               context.cr.set_source_rgb (0, 0, 0);
+               rounded_rectangle (context.cr, 0.5, 0.5, context.width - 1, context.height - 1, 
border_radius);
+               context.cr.fill ();
+       }
+
        private void draw_background (DrawingContext context) {
                context.style.render_background (context.cr, 0.0, 0.0, context.width, context.height);
        }


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