From 51dc85c72da7b60c46275ced5cdc9ea07ce857f1 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 22 Jan 2022 21:26:39 +0000 Subject: [PATCH] Round physical bitmap size in wxGTK wxBitmap::CreateScaled() Round the result of the multiplication by possibly non-integer scaling factor rather than truncating it. This is more consistent with wxMSW and other ports not using DIPs (wxOSX doesn't matter, as the scale factor can only be an integer there anyhow) and seems to be more useful. E.g. previously creating a bitmap of logical size 5 at 150% DPI scaling would create a 7px bitmap, for which GetLogicalWidth() would return 4.66 that would be truncated to 4, and not 5, when assigning it to an int, while now a 8px bitmap will be created and both rounding or truncating its GetLogicalWidth() value of 5.33 results in the more expected 5. --- src/gtk/bitmap.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index 5728f236b9..f929e78dc2 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -18,6 +18,7 @@ #include "wx/cursor.h" #endif +#include "wx/math.h" #include "wx/rawbmp.h" #include "wx/gtk/private/object.h" @@ -991,7 +992,7 @@ void wxBitmap::SetMask( wxMask *mask ) #ifdef __WXGTK3__ bool wxBitmap::CreateScaled(int w, int h, int depth, double scale) { - Create(int(w * scale), int(h * scale), depth); + Create(wxRound(w * scale), wxRound(h * scale), depth); M_BMPDATA->m_scaleFactor = scale; return true; }