diff --git a/include/wx/msw/gdiimage.h b/include/wx/msw/gdiimage.h index 94b6f01091..39f8af2979 100644 --- a/include/wx/msw/gdiimage.h +++ b/include/wx/msw/gdiimage.h @@ -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 { diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index c63dd61089..c7ed47429a 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -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(); } // ----------------------------------------------------------------------------