Store scale factor in wxMSW bitmaps too

Even though it's not really used by MSW code itself, the scale factor is
still needed to determine the correct default bitmap bundle size, for
example: it should be possible to create a bundle with just a single
64x64 bitmap and use it unscaled in 200% DPI, for example, rather than
scaling it up to 128x128 bitmap.
This commit is contained in:
Vadim Zeitlin
2021-12-16 01:15:17 +00:00
parent 0a8f7233cc
commit a1e4dca067
2 changed files with 25 additions and 9 deletions

View File

@@ -499,6 +499,8 @@ bool wxBitmap::CopyFromIconOrCursor(const wxGDIImage& icon,
int w = icon.GetWidth(),
h = icon.GetHeight();
refData->m_scaleFactor = icon.GetScaleFactor();
if ( iconInfo.hbmColor )
{
refData->m_width = w;
@@ -1366,33 +1368,36 @@ bool wxBitmap::InitFromHBITMAP(WXHBITMAP bmp, int width, int height, int depth)
// scale factor-related functions
// ----------------------------------------------------------------------------
// Note: currently we don't use scale factor at all and don't even store it
// because this seems useless, but we define these functions out of line here
// and not inline in the header to make it possible to change this later
// without breaking ABI if necessary.
// 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 WXUNUSED(scale))
void wxBitmap::SetScaleFactor(double scale)
{
wxCHECK_RET( IsOk(), wxT("invalid bitmap") );
GetBitmapData()->m_scaleFactor = scale;
}
double wxBitmap::GetScaleFactor() const
{
return 1.0;
wxCHECK_MSG( IsOk(), -1, wxT("invalid bitmap") );
return GetBitmapData()->m_scaleFactor;
}
double wxBitmap::GetScaledWidth() const
{
return GetWidth();
return GetWidth() / GetScaleFactor();
}
double wxBitmap::GetScaledHeight() const
{
return GetHeight();
return GetHeight() / GetScaleFactor();
}
wxSize wxBitmap::GetScaledSize() const
{
return GetSize();
return GetSize() / GetScaleFactor();
}
// ----------------------------------------------------------------------------