Make the background black, center the image

It might be a good idea to make the colour adjustable, at least being
able to switch to white, for certain partly-transparent pictures.
This commit is contained in:
Přemysl Eric Janouch 2021-09-16 19:58:34 +02:00
parent a6982bcc3b
commit ddcc878424
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 18 additions and 1 deletions

View File

@ -88,8 +88,25 @@ fastiv_view_draw(GtkWidget *widget, cairo_t *cr)
if (!self->surface)
return TRUE;
// TODO(p): Make this adjustable later.
cairo_set_source_rgb(cr, 0, 0, 0);
cairo_paint(cr);
GtkAllocation allocation;
gtk_widget_get_allocation(widget, &allocation);
int w = cairo_image_surface_get_width(self->surface);
int h = cairo_image_surface_get_height(self->surface);
double x = 0;
double y = 0;
if (w < allocation.width)
x = (allocation.width - w) / 2;
if (h < allocation.height)
y = (allocation.height - h) / 2;
// TODO(p): Times the zoom.
cairo_set_source_surface(cr, self->surface, 0, 0);
cairo_set_source_surface(cr, self->surface, x, y);
cairo_paint(cr);
return TRUE;
}