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(); } // ----------------------------------------------------------------------------