summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2017-09-21 19:26:54 +0200
committerDave Davenport <qball@gmpclient.org>2017-09-21 19:27:04 +0200
commit0596f7c1a19473964cfb8be4bde758c148c6138f (patch)
tree2f4b4c364bc0fe4c8701b9ad14eaa0b2d8cc1976
parent87d9caec6009b304d97042474219c4a72a445554 (diff)
Correctly center and scale image, even if not rectangular
-rw-r--r--source/widgets/textbox.c9
1 files 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 );
}