[gnome-games] game-thumbnail: Support HiDPI
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] game-thumbnail: Support HiDPI
- Date: Sat, 17 Aug 2019 10:23:55 +0000 (UTC)
commit 2c694894772cc35cbb2fe1241c9a082bf9fdceeb
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date: Sat Aug 17 15:20:48 2019 +0500
game-thumbnail: Support HiDPI
Load larger covers, and draw them downscaled, ensuring they are as crisp
as possible.
src/ui/game-thumbnail.vala | 28 ++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)
---
diff --git a/src/ui/game-thumbnail.vala b/src/ui/game-thumbnail.vala
index 05f8776f..b7238735 100644
--- a/src/ui/game-thumbnail.vala
+++ b/src/ui/game-thumbnail.vala
@@ -196,14 +196,14 @@ private class Games.GameThumbnail : Gtk.DrawingArea {
}
private Gdk.Pixbuf? get_scaled_cover (DrawingContext context) {
- if (previous_cover_width != context.width) {
- previous_cover_width = context.width;
+ if (previous_cover_width != context.width * scale_factor) {
+ previous_cover_width = context.width * scale_factor;
cover_cache = null;
tried_loading_cover = false;
}
- if (previous_cover_height != context.height) {
- previous_cover_height = context.height;
+ if (previous_cover_height != context.height * scale_factor) {
+ previous_cover_height = context.height * scale_factor;
cover_cache = null;
tried_loading_cover = false;
}
@@ -211,7 +211,7 @@ private class Games.GameThumbnail : Gtk.DrawingArea {
if (cover_cache != null)
return cover_cache;
- var size = int.min (context.width, context.height);
+ var size = int.min (context.width, context.height) * scale_factor;
load_cover_cache_from_disk (context, size);
if (cover_cache != null)
@@ -253,8 +253,10 @@ private class Games.GameThumbnail : Gtk.DrawingArea {
}
try {
- cover_cache = new Gdk.Pixbuf.from_file_at_scale (cover_cache_path, context.width,
- context.height, true);
+ cover_cache = new Gdk.Pixbuf.from_file_at_scale (cover_cache_path,
+ context.width * scale_factor,
+ context.height * scale_factor,
+ true);
}
catch (Error e) {
debug (e.message);
@@ -300,22 +302,28 @@ private class Games.GameThumbnail : Gtk.DrawingArea {
private void draw_pixbuf (DrawingContext context, Gdk.Pixbuf pixbuf) {
var surface = Gdk.cairo_surface_create_from_pixbuf (pixbuf, 1, context.window);
+ context.cr.save ();
+ context.cr.scale (1.0 / scale_factor, 1.0 / scale_factor);
+
var mask = get_mask (context);
- var x_offset = (context.width - pixbuf.width) / 2;
- var y_offset = (context.height - pixbuf.height) / 2;
+ var x_offset = (context.width * scale_factor - pixbuf.width) / 2;
+ var y_offset = (context.height * scale_factor - pixbuf.height) / 2;
context.cr.set_source_surface (surface, x_offset, y_offset);
context.cr.mask_surface (mask, 0, 0);
+
+ context.cr.restore ();
}
private Cairo.Surface get_mask (DrawingContext context) {
- var mask = new Cairo.ImageSurface (Cairo.Format.A8, context.width, context.height);
+ var mask = new Cairo.ImageSurface (Cairo.Format.A8, context.width * scale_factor,
context.height * scale_factor);
var border_radius = (int) context.style.get_property (Gtk.STYLE_PROPERTY_BORDER_RADIUS,
context.state);
border_radius = border_radius.clamp (0, int.max (context.width / 2, context.height / 2));
var cr = new Cairo.Context (mask);
+ cr.scale (scale_factor, scale_factor);
cr.set_source_rgb (0, 0, 0);
rounded_rectangle (cr, 0.5, 0.5, context.width - 1, context.height - 1, border_radius);
cr.fill ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]