[gnome-games] ui: Make GameThumbnail draw covers
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] ui: Make GameThumbnail draw covers
- Date: Tue, 12 Jul 2016 13:46:38 +0000 (UTC)
commit 4cb48e1ae6e605cd6f143d1765f42504a6362fac
Author: Adrien Plazas <kekun plazas laposte net>
Date: Wed May 11 07:54:59 2016 +0200
ui: Make GameThumbnail draw covers
Allows to display the cover of games providing one.
src/ui/game-thumbnail.vala | 48 +++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 47 insertions(+), 1 deletions(-)
---
diff --git a/src/ui/game-thumbnail.vala b/src/ui/game-thumbnail.vala
index b02789c..14c8fe4 100644
--- a/src/ui/game-thumbnail.vala
+++ b/src/ui/game-thumbnail.vala
@@ -6,6 +6,7 @@ private class Games.GameThumbnail: Gtk.DrawingArea {
private const Gtk.CornerType[] bottom_corners = { Gtk.CornerType.BOTTOM_LEFT,
Gtk.CornerType.BOTTOM_RIGHT };
private const double ICON_SCALE = 0.75;
+ private const double COVER_MARGIN = 3;
private const double FRAME_RADIUS = 2;
private const int EMBLEM_PADDING = 8;
@@ -74,9 +75,15 @@ private class Games.GameThumbnail: Gtk.DrawingArea {
if (icon == null)
return false;
+ if (cover == null)
+ return false;
+
var drawn = false;
- drawn = draw_icon (context);
+ drawn = draw_cover (context);
+
+ if (!drawn)
+ drawn = draw_icon (context);
// Draw the default thumbnail if no thumbnail have been drawn
if (!drawn)
@@ -101,6 +108,27 @@ private class Games.GameThumbnail: Gtk.DrawingArea {
return true;
}
+ public bool draw_cover (DrawingContext context) {
+ var g_icon = cover.get_cover ();
+ if (g_icon == null)
+ return false;
+
+ var pixbuf = get_scaled_cover (context, g_icon);
+ if (pixbuf == null)
+ return false;
+
+ double width = pixbuf.width + COVER_MARGIN * 2;
+ double height = pixbuf.height + COVER_MARGIN * 2;
+ double offset_x = (context.width - width) / 2.0;
+ double offset_y = (context.height - height) / 2.0;
+
+ context.style.render_background (context.cr, offset_x, offset_y, width, height);
+ draw_pixbuf (context, pixbuf);
+ context.style.render_frame (context.cr, offset_x, offset_y, width, height);
+
+ return true;
+ }
+
public void draw_default (DrawingContext context) {
draw_background (context);
draw_emblem_icon (context, "applications-games-symbolic", center_emblem_size);
@@ -149,6 +177,24 @@ private class Games.GameThumbnail: Gtk.DrawingArea {
}
}
+ private Gdk.Pixbuf? get_scaled_cover (DrawingContext context, GLib.Icon? icon) {
+ if (icon == null)
+ return null;
+
+ var theme = Gtk.IconTheme.get_default ();
+ var lookup_flags = Gtk.IconLookupFlags.FORCE_SIZE | Gtk.IconLookupFlags.FORCE_REGULAR;
+ var size = int.min (context.width, context.height) - COVER_MARGIN * 2;
+ var icon_info = theme.lookup_by_gicon (icon, (int) size, lookup_flags);
+
+ try {
+ return icon_info.load_icon ();
+ }
+ catch (Error e) {
+ warning (@"Couldn't load the icon: $(e.message)\n");
+ return null;
+ }
+ }
+
private void draw_pixbuf (DrawingContext context, Gdk.Pixbuf pixbuf) {
var surface = Gdk.cairo_surface_create_from_pixbuf (pixbuf, 1, context.window);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]