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



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

    game-thumbnail: Unify draw call

 src/ui/game-thumbnail.vala | 66 ++++++++++++++++------------------------------
 1 file changed, 22 insertions(+), 44 deletions(-)
---
diff --git a/src/ui/game-thumbnail.vala b/src/ui/game-thumbnail.vala
index 2e8ea454..c5b32862 100644
--- a/src/ui/game-thumbnail.vala
+++ b/src/ui/game-thumbnail.vala
@@ -100,59 +100,30 @@ private class Games.GameThumbnail: Gtk.DrawingArea {
                        cover_cache = null;
                }
 
-               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 ?? emblem_cache;
+               if (thumbnail != null)
+                       draw_pixbuf (context, thumbnail);
 
                return true;
        }
 
-       public void draw_emblem (DrawingContext 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);
+               }
                if (emblem_cache == null)
                        load_emblem_cache (context);
-               if (emblem_cache == null)
-                       return;
-
-               draw_background (context);
-               draw_pixbuf (context, emblem_cache);
-               draw_border (context);
        }
 
        private void load_emblem_cache (DrawingContext context) {
@@ -309,6 +280,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]