From 0596f7c1a19473964cfb8be4bde758c148c6138f Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Thu, 21 Sep 2017 19:26:54 +0200 Subject: Correctly center and scale image, even if not rectangular --- source/widgets/textbox.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c index 0fed9d38..4a5a6369 100644 --- a/source/widgets/textbox.c +++ b/source/widgets/textbox.c @@ -430,11 +430,12 @@ static void textbox_draw ( widget *wid, cairo_t *draw ) cairo_save ( draw ); int iconh = cairo_image_surface_get_height ( tb->icon ); - double scale = (double) iconheight / iconh; - - cairo_translate ( draw, x, y ); + int iconw = cairo_image_surface_get_width ( tb->icon ); + int icons = MAX(iconh, iconw); + double scale = (double) iconheight / icons; + cairo_translate ( draw, x+(iconheight-iconw*scale)/2.0, y+(iconheight-iconh*scale)/2.0 ); cairo_scale ( draw, scale, scale ); - cairo_set_source_surface ( draw, tb->icon, 0, 0 ); + cairo_set_source_surface ( draw, tb->icon, 0,0); cairo_paint ( draw ); cairo_restore ( draw ); } -- cgit v1.2.3