From d1c7caec3bf726ac137566ced91d067591a71e7e Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Wed, 2 Dec 2020 14:39:37 +0100 Subject: Improve Fl_Graphics_Driver::cache_size() when GUI is scaled. The change lets this function enlarge the size only when strictly necessary for image tiling. --- src/Fl_Graphics_Driver.cxx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/Fl_Graphics_Driver.cxx') diff --git a/src/Fl_Graphics_Driver.cxx b/src/Fl_Graphics_Driver.cxx index e156ae2c4..5b33f7b2f 100644 --- a/src/Fl_Graphics_Driver.cxx +++ b/src/Fl_Graphics_Driver.cxx @@ -203,14 +203,15 @@ unsigned Fl_Graphics_Driver::font_desc_size() { scale() and in slightly modifying that to help support tiled images. */ void Fl_Graphics_Driver::cache_size(Fl_Image *img, int &width, int &height) { - if ( int(scale()) == scale() ) { - width = width * scale(); - height = height * scale(); - } else { - width = (width+1) * scale(); - height = (height+1) * scale(); - } - img->cache_size_(width, height); + // Image tiling may require to convert the floating value of width * scale() or + // height * scale() to a larger integer value to avoid undrawn space between adjacent images. + float s = scale(), fs = width * s; + width = (fs - int(fs) < 0.001 ? int(fs) : + int((width+1) * s)); + fs = height * s; + height = (fs - int(fs) < 0.001 ? int(fs) : + int((height+1) * s)); + if (img) img->cache_size_(width, height); } /** Draws an Fl_Pixmap object using this graphics driver. -- cgit v1.2.3