From b4946c2fe34e6e24950caeff5576d5afc0fd1ecb Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 22 Jan 2022 22:54:39 +0000 Subject: [PATCH] Move scale factor-related functions to wxGDIImage from wxBitmap This makes them available in wxIcon (and, less importantly, wxCursor) too which is needed in order to use icons correctly in high DPI. This is also more consistent with the other platforms, where wxIcon does have these methods. Document these methods in wxIcon now that they're available there under all platforms and also document wxIcon::GetSize() which had been available even before, but wasn't documented. --- include/wx/msw/bitmap.h | 13 ---------- include/wx/msw/gdiimage.h | 17 ++++++++++--- interface/wx/icon.h | 51 ++++++++++++++++++++++++++++++++++++--- src/msw/bitmap.cpp | 41 ------------------------------- src/msw/gdiimage.cpp | 41 +++++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+), 62 deletions(-) diff --git a/include/wx/msw/bitmap.h b/include/wx/msw/bitmap.h index 4c0eb8e341..81f981848f 100644 --- a/include/wx/msw/bitmap.h +++ b/include/wx/msw/bitmap.h @@ -191,19 +191,6 @@ public: void UseAlpha(bool use = true); void ResetAlpha() { UseAlpha(false); } - // allow setting and storing the scale factor - virtual void SetScaleFactor(double scale); - virtual double GetScaleFactor() const; - - // return the size divided by scale factor - wxSize GetDIPSize() const; - - // logical metrics accessors return the same thing as physical ones, just - // as in all the other ports without wxHAS_DPI_INDEPENDENT_PIXELS. - double GetLogicalWidth() const; - double GetLogicalHeight() const; - wxSize GetLogicalSize() const; - // old synonyms for CreateWithLogicalSize() and GetLogicalXXX() functions bool CreateScaled(int w, int h, int d, double logicalScale) { return CreateWithLogicalSize(wxSize(w, h), logicalScale, d); } diff --git a/include/wx/msw/gdiimage.h b/include/wx/msw/gdiimage.h index 39f8af2979..2424b93324 100644 --- a/include/wx/msw/gdiimage.h +++ b/include/wx/msw/gdiimage.h @@ -118,10 +118,19 @@ public: int GetWidth() const { return IsNull() ? 0 : GetGDIImageData()->m_width; } int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_height; } int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_depth; } - double GetScaleFactor() const - { - return IsNull() ? 1.0 : GetGDIImageData()->m_scaleFactor; - } + + // allow setting and storing the scale factor + void SetScaleFactor(double scale); + double GetScaleFactor() const; + + // return the size divided by scale factor + wxSize GetDIPSize() const; + + // logical metrics accessors return the same thing as physical ones, just + // as in all the other ports without wxHAS_DPI_INDEPENDENT_PIXELS. + double GetLogicalWidth() const; + double GetLogicalHeight() const; + wxSize GetLogicalSize() const; wxSize GetSize() const { diff --git a/interface/wx/icon.h b/interface/wx/icon.h index 7c41aa63a9..f396caed44 100644 --- a/interface/wx/icon.h +++ b/interface/wx/icon.h @@ -222,16 +222,59 @@ public: int GetDepth() const; /** - Gets the height of the icon in pixels. + Gets the height of the icon in physical pixels. - @see GetWidth() + @see GetWidth(), GetLogicalHeight() */ int GetHeight() const; /** - Gets the width of the icon in pixels. + Gets the height of the icon in logical pixels. - @see GetHeight() + See wxBitmap::GetLogicalHeight(). + + @since 3.1.6 + */ + double GetLogicalHeight() const; + + /** + Gets the size of the icon in logical pixels. + + See wxBitmap::GetLogicalSize(). + + @since 3.1.6 + */ + double GetLogicalSize() const; + + /** + Gets the width of the icon in logical pixels. + + See wxBitmap::GetLogicalWidth(). + + @since 3.1.6 + */ + double GetLogicalWidth() const; + + /** + Gets the scale factor of this icon. + + See wxBitmap::GetScaleFactor(). + + @since 3.1.6 + */ + double GetScaleFactor() const; + + /** + Gets the size of the icon in physical pixels. + + @see GetLogicalSize() + */ + wxSize GetSize() const; + + /** + Gets the width of the icon in physical pixels. + + @see GetHeight(), GetLogicalWidth() */ int GetWidth() const; diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index 2f7b045450..d490d88922 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -1364,47 +1364,6 @@ bool wxBitmap::InitFromHBITMAP(WXHBITMAP bmp, int width, int height, int depth) return IsOk(); } -// ---------------------------------------------------------------------------- -// scale factor-related functions -// ---------------------------------------------------------------------------- - -// wxMSW doesn't really use scale factor, but we must still store it to use the -// correct sizes in the code which uses it to decide on the bitmap size to use. - -void wxBitmap::SetScaleFactor(double scale) -{ - wxCHECK_RET( IsOk(), wxT("invalid bitmap") ); - - GetBitmapData()->m_scaleFactor = scale; -} - -double wxBitmap::GetScaleFactor() const -{ - wxCHECK_MSG( IsOk(), -1, wxT("invalid bitmap") ); - - return GetBitmapData()->m_scaleFactor; -} - -wxSize wxBitmap::GetDIPSize() const -{ - return GetSize() / GetScaleFactor(); -} - -double wxBitmap::GetLogicalWidth() const -{ - return GetWidth(); -} - -double wxBitmap::GetLogicalHeight() const -{ - return GetHeight(); -} - -wxSize wxBitmap::GetLogicalSize() const -{ - return GetSize(); -} - // ---------------------------------------------------------------------------- // raw bitmap access support // ---------------------------------------------------------------------------- diff --git a/src/msw/gdiimage.cpp b/src/msw/gdiimage.cpp index fe2d3b2b52..7a26e3036d 100644 --- a/src/msw/gdiimage.cpp +++ b/src/msw/gdiimage.cpp @@ -335,6 +335,47 @@ void wxGDIImage::InitStandardHandlers() #endif // wxUSE_PNG_RESOURCE_HANDLER } +// ---------------------------------------------------------------------------- +// scale factor-related functions +// ---------------------------------------------------------------------------- + +// wxMSW doesn't really use scale factor, but we must still store it to use the +// correct sizes in the code which uses it to decide on the bitmap size to use. + +void wxGDIImage::SetScaleFactor(double scale) +{ + wxCHECK_RET( IsOk(), wxT("invalid bitmap") ); + + GetGDIImageData()->m_scaleFactor = scale; +} + +double wxGDIImage::GetScaleFactor() const +{ + wxCHECK_MSG( IsOk(), -1, wxT("invalid bitmap") ); + + return GetGDIImageData()->m_scaleFactor; +} + +wxSize wxGDIImage::GetDIPSize() const +{ + return GetSize() / GetScaleFactor(); +} + +double wxGDIImage::GetLogicalWidth() const +{ + return GetWidth(); +} + +double wxGDIImage::GetLogicalHeight() const +{ + return GetHeight(); +} + +wxSize wxGDIImage::GetLogicalSize() const +{ + return GetSize(); +} + // ---------------------------------------------------------------------------- // wxBitmap handlers // ----------------------------------------------------------------------------