From e03297b6fa3c4261f0cbb344812e9d2e0ef4a62a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 1 Jun 2022 18:48:27 +0100 Subject: [PATCH] Use the same preferred size algorithm in wxBitmapBundleImplRC Reuse DoGetPreferredSize() in this implementation in order to ensure that we do the same thing when using bitmaps from disk files with wxBitmapBundleImplSet or bitmaps from MSW resources with this one. --- src/msw/bmpbndl.cpp | 44 +++++--------------------------------------- 1 file changed, 5 insertions(+), 39 deletions(-) diff --git a/src/msw/bmpbndl.cpp b/src/msw/bmpbndl.cpp index f5ec7b25dd..6ecd42a78e 100644 --- a/src/msw/bmpbndl.cpp +++ b/src/msw/bmpbndl.cpp @@ -191,48 +191,14 @@ wxSize wxBitmapBundleImplRC::GetDefaultSize() const wxSize wxBitmapBundleImplRC::GetPreferredBitmapSizeAtScale(double scale) const { - // Optimistically assume we're going to use this exact scale by default. - double scalePreferred = scale; - - for ( size_t i = 0; ; ++i ) + const size_t n = m_resourceInfos.size(); + wxVector scales(n); + for ( size_t i = 0; i < n; ++i ) { - if ( i == m_resourceInfos.size() ) - { - // The requested scale is bigger than anything we have, so use the - // biggest available one. - scalePreferred = m_resourceInfos[i - 1].scale; - break; - } - - const double scaleThis = m_resourceInfos[i].scale; - - // Keep looking for the exact match which we still can hope to find - // while the current scale is smaller. - if ( scaleThis < scale ) - continue; - - // If we've found the exact match, just use it. - if ( scaleThis == scale ) - break; - - // We've found the closest bigger scale. - - // If there is no smaller one, we have no choice but to use this one. - if ( i == 0 ) - break; - - // Decide whether we should use this one or the previous smaller one - // depending on which of them is closer to the target scale, breaking - // the tie in favour of the bigger one. - const double scaleLast = m_resourceInfos[i - 1].scale; - - scalePreferred = scaleThis - scale <= scale - scaleLast - ? scaleThis - : scaleLast; - break; + scales[i] = m_resourceInfos[i].scale; } - return GetDefaultSize()*scalePreferred; + return DoGetPreferredSize(scale, n, &scales[0]); } wxBitmap