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.
This commit is contained in:
@@ -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<double> 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
|
||||
|
||||
Reference in New Issue
Block a user