FLTK logo

[master] d1c7cae - Improve Fl_Graphics_Driver::cache_size() when GUI is scaled.

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] d1c7cae - Improve Fl_Graphics_Driver::cache_size() when GUI is scaled. "ManoloFLTK" Dec 02, 2020  
 
commit d1c7caec3bf726ac137566ced91d067591a71e7e
Author:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
AuthorDate: Wed Dec 2 14:39:37 2020 +0100
Commit:     ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>
CommitDate: Wed Dec 2 14:39:49 2020 +0100

    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 +++++++++--------
 src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx |  2 +-
 src/drivers/X11/Fl_X11_Screen_Driver.cxx       |  2 +-
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git src/Fl_Graphics_Driver.cxx src/Fl_Graphics_Driver.cxx
index e156ae2..5b33f7b 100644
--- src/Fl_Graphics_Driver.cxx
+++ 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.
diff --git src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx
index 659113c..998d4f9 100644
--- src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx
+++ src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.cxx
@@ -503,7 +503,7 @@ Fl_WinAPI_Screen_Driver::read_win_rectangle(
   int ws, hs;
   if (int(s) == s) { ws = w * s; hs = h * s;}
   else {
-    ws = (w+1)*s; // matches what Fl_Graphics_Driver::cache_size() does
+    ws = (w+1)*s; // approximates what Fl_Graphics_Driver::cache_size() does
     hs = (h+1)*s;
     if (ws < 1) ws = 1;
     if (hs < 1) hs = 1;
diff --git src/drivers/X11/Fl_X11_Screen_Driver.cxx src/drivers/X11/Fl_X11_Screen_Driver.cxx
index 539fdfd..ec3a6e0 100644
--- src/drivers/X11/Fl_X11_Screen_Driver.cxx
+++ src/drivers/X11/Fl_X11_Screen_Driver.cxx
@@ -800,7 +800,7 @@ Fl_RGB_Image *Fl_X11_Screen_Driver::read_win_rectangle(int X, int Y, int w, int
       sh = screens[ns].height;
     }
     if (win && !allow_outside && int(s) != s) {
-      ws = (w+1) * s; // matches what Fl_Graphics_Driver::cache_size() does
+      ws = (w+1) * s; // approximates what Fl_Graphics_Driver::cache_size() does
       hs = (h+1) * s;
       if (Xs + ws >= int(win->w()*s)) ws = win->w()*s - Xs -1;
       if (Ys + hs >= int(win->h()*s)) hs = win->h()*s - Ys -1;
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.