Commit 1f31c334 authored by Adrien Plazas's avatar Adrien Plazas
Browse files

cover-loader: Use the logical size for all but rendering

This doesn't preemplively apply the scale factor to the rendering size
to keep it be the logical size. Only apply the scale when rendering.

This also makes the 256@2x cover cache hold a 512x512 image for the
256x256 logical size, rather than a 256x256 image for the 128x128
logical size, making it more intuitive.
parent dfbd636b
Pipeline #292659 passed with stage
in 132 minutes and 46 seconds
......@@ -157,6 +157,7 @@ public class Highscore.CoverLoader : Object {
int overlay_x, overlay_y;
int width, height, zoom_width, zoom_height;
double aspect_ratio;
int natural_size = size * scale_factor;
bool is_tiny;
assert (file != null);
......@@ -167,27 +168,27 @@ public class Highscore.CoverLoader : Object {
is_tiny = width <= TINY_ICON_SIZE && height <= TINY_ICON_SIZE;
if (height >= width) {
height = size;
width = (int) (size * aspect_ratio);
height = natural_size;
width = (int) (natural_size * aspect_ratio);
zoom_width = size;
zoom_height = (int) (size * height / (double) width);
zoom_width = natural_size;
zoom_height = (int) (natural_size * height / (double) width);
overlay_x = (int) ((height - width) / 2);
overlay_y = 0;
}
else {
width = size;
height = (int) (size / aspect_ratio);
width = natural_size;
height = (int) (natural_size / aspect_ratio);
zoom_height = size;
zoom_width = (int) (size * width / (double) height);
zoom_height = natural_size;
zoom_width = (int) (natural_size * width / (double) height);
overlay_x = 0;
overlay_y = (int) ((width - height) / 2);
}
var image_surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, size, size);
var image_surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, natural_size, natural_size);
var cr = new Cairo.Context (image_surface);
try {
......@@ -216,32 +217,32 @@ public class Highscore.CoverLoader : Object {
if (height > width) {
var blur_y = (int) ((double) (height - width) / 2);
draw_cover_blur_rect (cr, blur_pixbuf, size, scale_factor, false,
0, blur_y, overlay_x, size);
draw_cover_blur_rect (cr, blur_pixbuf, natural_size, scale_factor, false,
0, blur_y, overlay_x, natural_size);
if (height > width)
cr.translate (overlay_x + width, 0);
else
cr.translate (0, blur_y);
draw_cover_blur_rect (cr, blur_pixbuf, size, scale_factor, true,
draw_cover_blur_rect (cr, blur_pixbuf, natural_size, scale_factor, true,
overlay_x + width, blur_y,
size - width - overlay_x, size);
natural_size - width - overlay_x, natural_size);
}
else if (height < width) {
var blur_x = (int) ((double) (width - height) / 2);
draw_cover_blur_rect (cr, blur_pixbuf, size, scale_factor, false,
blur_x, 0, size, overlay_y);
draw_cover_blur_rect (cr, blur_pixbuf, natural_size, scale_factor, false,
blur_x, 0, natural_size, overlay_y);
if (height > width)
cr.translate (blur_x, 0);
else
cr.translate (0, overlay_y + height);
draw_cover_blur_rect (cr, blur_pixbuf, size, scale_factor, true,
draw_cover_blur_rect (cr, blur_pixbuf, natural_size, scale_factor, true,
blur_x, overlay_y + height,
size, size - height - overlay_y);
natural_size, natural_size - height - overlay_y);
}
cr.restore ();
......@@ -249,7 +250,7 @@ public class Highscore.CoverLoader : Object {
Gdk.cairo_set_source_pixbuf (cr, overlay_pixbuf, overlay_x, overlay_y);
cr.paint ();
return Gdk.pixbuf_get_from_surface (image_surface, 0, 0, size, size);
return Gdk.pixbuf_get_from_surface (image_surface, 0, 0, natural_size, natural_size);
}
public void fetch_cover (Game game, int scale_factor, int cover_size, CoverReadyCallback cb) {
......
......@@ -99,7 +99,7 @@ private class Highscore.GameThumbnail : Gtk.Widget {
}
private void get_cover (DrawingContext context, out Gdk.Paintable cover) {
var cover_size = int.min (context.width, context.height) * scale_factor;
var cover_size = int.min (context.width, context.height);
if (cover_size != last_cover_size || scale_factor != last_scale_factor) {
cover_paintable = null;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment