From ddcc878424ebb8879ace2bd8238b7bd92d7143cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?= Date: Thu, 16 Sep 2021 19:58:34 +0200 Subject: 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. --- fastiv-view.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'fastiv-view.c') diff --git a/fastiv-view.c b/fastiv-view.c index a692285..d06dc57 100644 --- a/fastiv-view.c +++ b/fastiv-view.c @@ -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; } -- cgit v1.2.3