From 1f8af4d5a2cfd4f09b147277b43e701e09a7a683 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 19 Oct 2021 01:41:36 +0100 Subject: [PATCH] Use preferred size for the button bitmaps in wxMSW Avoid scaling the bitmaps by using the preferred size for them. This results in significantly better appearance without any real drawbacks in practice at 125% and 175% DPI scaling in the common case when just a single and double-sized bitmaps are available, and still seems to be acceptable at 150% scaling in this case. --- src/msw/anybutton.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/msw/anybutton.cpp b/src/msw/anybutton.cpp index 0364d24ee5..b62d516aa0 100644 --- a/src/msw/anybutton.cpp +++ b/src/msw/anybutton.cpp @@ -107,7 +107,7 @@ class wxButtonImageData: public wxObject public: wxButtonImageData(wxWindow* btn, const wxBitmapBundle& normalBundle) { - m_bitmapSize = normalBundle.GetDefaultSize() * btn->GetDPIScaleFactor(); + m_bitmapSize = normalBundle.GetPreferredSizeFor(btn); m_bitmapBundles[wxAnyButton::State_Normal] = normalBundle; } @@ -254,7 +254,7 @@ public: // the image list wxXPButtonImageData(wxAnyButton *btn, const wxBitmapBundle& bitmapBundle) : wxButtonImageData(btn, bitmapBundle), - m_hwndBtn(GetHwndOf(btn)) + m_btn(btn) { InitImageList(); @@ -403,7 +403,7 @@ private: void UpdateImageInfo() { - if ( !::SendMessage(m_hwndBtn, BCM_SETIMAGELIST, 0, (LPARAM)&m_data) ) + if ( !::SendMessage(GetHwndOf(m_btn), BCM_SETIMAGELIST, 0, (LPARAM)&m_data) ) { wxLogDebug("SendMessage(BCM_SETIMAGELIST) failed"); } @@ -415,7 +415,7 @@ private: // We need to recreate the image list using the new size and re-add all // bitmaps to it. - m_bitmapSize = event.Scale(m_bitmapSize); + m_bitmapSize = m_bitmapBundles[wxAnyButton::State_Normal].GetPreferredSizeFor(m_btn); m_iml.Destroy(); InitImageList(); @@ -431,7 +431,7 @@ private: BUTTON_IMAGELIST m_data; // the button we're associated with - const HWND m_hwndBtn; + wxWindow* const m_btn; wxDECLARE_NO_COPY_CLASS(wxXPButtonImageData);