diff options
author | John Stebbins <[email protected]> | 2016-03-16 22:27:01 -0600 |
---|---|---|
committer | John Stebbins <[email protected]> | 2016-03-16 22:27:01 -0600 |
commit | f25066f750c4cf963b627e4756b6ea8f4ed3f842 (patch) | |
tree | 67dffe765b7fcbb9b6599a9af473b237df1c387f | |
parent | e5fc75086a8aefbde4ebc4867476fff8d86f1efb (diff) |
LinGui: center image in preview window
If the window manager does not size the window correctly (wayland!)
distribute black evenly around the image.
-rw-r--r-- | gtk/src/preview.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/gtk/src/preview.c b/gtk/src/preview.c index a32ca8570..dab2d3701 100644 --- a/gtk/src/preview.c +++ b/gtk/src/preview.c @@ -802,13 +802,24 @@ live_preview_seek_cb(GtkWidget *widget, signal_user_data_t *ud) static void _draw_pixbuf(signal_user_data_t * ud, cairo_t *cr, GdkPixbuf *pix) { - cairo_set_source_rgb(cr, 0, 0, 0); + int pix_width, pix_height, hoff, voff; + + cairo_save(cr); cairo_rectangle(cr, 0, 0, ud->preview->render_width, ud->preview->render_height); + cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); cairo_fill(cr); - cairo_rectangle(cr, 0, 0, ud->preview->render_width, - ud->preview->render_height); - cairo_clip(cr); + cairo_restore(cr); + + pix_width = gdk_pixbuf_get_width(pix); + pix_height = gdk_pixbuf_get_height(pix); + hoff = MAX((ud->preview->render_width - pix_width) / 2, 0); + voff = MAX((ud->preview->render_height - pix_height) / 2, 0); + if (voff > 0 || hoff > 0) + { + cairo_translate(cr, hoff, voff); + } + gdk_cairo_set_source_pixbuf(cr, pix, 0, 0); cairo_paint(cr); } @@ -953,7 +964,7 @@ init_preview_image(signal_user_data_t *ud) return; int pix_width, pix_height; - pix_width = gdk_pixbuf_get_width(ud->preview->pix); + pix_width = gdk_pixbuf_get_width(ud->preview->pix); pix_height = gdk_pixbuf_get_height(ud->preview->pix); preview_set_size(ud, pix_width, pix_height); |