[gnome-games/wip/theawless/simplify-thumbnail: 77/77] game-thumbnail: Unify draw call
- From: Abhinav Singh <abhinavsingh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/theawless/simplify-thumbnail: 77/77] game-thumbnail: Unify draw call
- Date: Sun, 2 Dec 2018 10:16:42 +0000 (UTC)
commit c041ce0df9a84f23fbf3e08f38031e3e6ee3dfc2
Author: theawless <theawless gmail com>
Date: Tue Oct 2 20:44:27 2018 +0530
game-thumbnail: Unify draw call
This will help create an async flow in a subsequent commmit.
src/ui/game-thumbnail.vala | 63 +++++++++++++++-------------------------------
1 file changed, 20 insertions(+), 43 deletions(-)
---
diff --git a/src/ui/game-thumbnail.vala b/src/ui/game-thumbnail.vala
index 76094e47..9f384354 100644
--- a/src/ui/game-thumbnail.vala
+++ b/src/ui/game-thumbnail.vala
@@ -98,56 +98,26 @@ private class Games.GameThumbnail: Gtk.DrawingArea {
tried_loading_cover = false;
}
- var drawn = false;
+ load_cache (context.width, context.height);
- 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) {
- var pixbuf = get_icon_cache (context.width, context.height);
- if (pixbuf == null)
- return false;
-
- draw_background (context);
- draw_pixbuf (context, pixbuf);
draw_border (context);
+ if (cover_cache != null)
+ draw_black_background (context);
+ else
+ draw_background (context);
- return true;
- }
-
- public bool draw_cover (DrawingContext context) {
- var pixbuf = get_cover_cache (context.width, context.height);
- if (pixbuf == 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, pixbuf);
- 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 (int width, int height) {
+ if (cover_cache == null && icon_cache == null)
+ cover_cache = get_cover_cache (width, height);
+ if (cover_cache == null && icon_cache == null)
+ icon_cache = get_icon_cache (width, height);
}
private Gdk.Pixbuf? get_emblem (DrawingContext context) {
@@ -309,6 +279,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]