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

@ -36,6 +36,8 @@ public:
{
m_width = m_height = m_depth = 0;
m_scaleFactor = 1.0;
m_handle = NULL;
}
@ -45,6 +47,8 @@ public:
m_height = data.m_height;
m_depth = data.m_depth;
m_scaleFactor = data.m_scaleFactor;
// can't copy handles like this, derived class copy ctor must do it!
m_handle = NULL;
}
@ -65,6 +69,9 @@ public:
// the depth of the image
int m_depth;
// scale factor of the image
double m_scaleFactor;
// the handle to it
union
{
@ -111,6 +118,10 @@ 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;
}
wxSize GetSize() const
{

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();
}
// ----------------------------------------------------------------------------