Correctly center and scale image, even if not rectangular

This commit is contained in:
Dave Davenport 2017-09-21 19:26:54 +02:00
parent 87d9caec60
commit 0596f7c1a1

View file

@ -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 );
}