From f6fbc97c7be8db9c83c1694fd4e596fc42a06ea6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 6 Jan 2022 18:54:39 +0000 Subject: [PATCH] Only return really scaled bitmap size under platforms using DIPs wxBitmap::GetScaledXXX() functions are useful for obtaining the coordinates in logical pixels, so they should only divide by the scaling factor on the platforms where logical pixels are actually different from the physical ones, i.e. those using DPI-independent pixels. This ensures that their behaviour under MSW remains unchanged even after a1e4dca067 (Store scale factor in wxMSW bitmaps too, 2021-12-16), which is the correct way to avoid breaking wxAUI (and other) drawing. --- include/wx/bitmap.h | 3 +++ include/wx/msw/bitmap.h | 4 +++- interface/wx/bitmap.h | 16 +++++++++++----- src/common/bmpbase.cpp | 21 +++++++++++++++++++++ src/msw/bitmap.cpp | 6 +++--- 5 files changed, 41 insertions(+), 9 deletions(-) diff --git a/include/wx/bitmap.h b/include/wx/bitmap.h index ae0bd262c5..dabc68f950 100644 --- a/include/wx/bitmap.h +++ b/include/wx/bitmap.h @@ -190,6 +190,9 @@ public: virtual void SetScaleFactor(double scale); virtual double GetScaleFactor() const; + // These functions return the corresponding metrics divided by the scale + // factor on platforms with DPI-independent pixels (e.g. GTK, Mac) and just + // the same thing as the non-scaled accessors elsewhere (e.g. MSW). double GetScaledWidth() const; double GetScaledHeight() const; wxSize GetScaledSize() const; diff --git a/include/wx/msw/bitmap.h b/include/wx/msw/bitmap.h index 34132fd0ab..1f3d143c70 100644 --- a/include/wx/msw/bitmap.h +++ b/include/wx/msw/bitmap.h @@ -184,10 +184,12 @@ public: void UseAlpha(bool use = true); void ResetAlpha() { UseAlpha(false); } - // provide stabs of scaled bitmaps functions, they are trivial here + // allow setting and storing the scale factor virtual void SetScaleFactor(double scale); virtual double GetScaleFactor() const; + // but scaled metrics accessors return the same thing as non-scaled ones, + // just as in all the other ports without wxHAS_DPI_INDEPENDENT_PIXELS. double GetScaledWidth() const; double GetScaledHeight() const; wxSize GetScaledSize() const; diff --git a/interface/wx/bitmap.h b/interface/wx/bitmap.h index c2fb3b1643..8299dd6f5c 100644 --- a/interface/wx/bitmap.h +++ b/interface/wx/bitmap.h @@ -609,12 +609,18 @@ public: /** Returns the scaled size of the bitmap. - The scaled size of the bitmap is its size in pixels, as returned by + For the platforms using DPI-independent pixels, i.e. those where @c + wxHAS_DPI_INDEPENDENT_PIXELS is defined, such as wxOSX or wxGTK 3, + this function returns the physical size of the bitmap, as returned by GetSize(), divided by its scale factor, as returned by - GetScaleFactor(), and so is the same as the normal size for bitmaps - with the default scale factor of 1 and always less than the physical - size for the higher resolution bitmaps supposed to be used on high DPI - screens. + GetScaleFactor(), while for the other platforms, it simply returns the + same thing as GetSize(). + + This ensures that the result of this function is always expressed in + the pixel coordinates appropriate for the current platform, i.e. its + return value is always in logical pixels, used for window and wxDC + coordinates, whether these pixels are the same as physical pixels, + which are returned by GetSize(), or not. @see GetScaledWidth(), GetScaledHeight(), GetSize() diff --git a/src/common/bmpbase.cpp b/src/common/bmpbase.cpp index 1b76bc3a1a..e3998b862a 100644 --- a/src/common/bmpbase.cpp +++ b/src/common/bmpbase.cpp @@ -220,6 +220,8 @@ double wxBitmapBase::GetScaleFactor() const return 1.0; } +#ifdef wxHAS_DPI_INDEPENDENT_PIXELS + double wxBitmapBase::GetScaledWidth() const { return GetWidth() / GetScaleFactor(); @@ -235,6 +237,25 @@ wxSize wxBitmapBase::GetScaledSize() const return wxSize(wxRound(GetScaledWidth()), wxRound(GetScaledHeight())); } +#else // !wxHAS_DPI_INDEPENDENT_PIXELS + +double wxBitmapBase::GetScaledWidth() const +{ + return GetWidth(); +} + +double wxBitmapBase::GetScaledHeight() const +{ + return GetHeight(); +} + +wxSize wxBitmapBase::GetScaledSize() const +{ + return GetSize(); +} + +#endif // wxHAS_DPI_INDEPENDENT_PIXELS/!wxHAS_DPI_INDEPENDENT_PIXELS + #endif // wxUSE_BITMAP_BASE // ---------------------------------------------------------------------------- diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index c7ed47429a..bba052367d 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -1387,17 +1387,17 @@ double wxBitmap::GetScaleFactor() const double wxBitmap::GetScaledWidth() const { - return GetWidth() / GetScaleFactor(); + return GetWidth(); } double wxBitmap::GetScaledHeight() const { - return GetHeight() / GetScaleFactor(); + return GetHeight(); } wxSize wxBitmap::GetScaledSize() const { - return GetSize() / GetScaleFactor(); + return GetSize(); } // ----------------------------------------------------------------------------