Move scale factor-related functions to wxGDIImage from wxBitmap

This makes them available in wxIcon (and, less importantly, wxCursor)
too which is needed in order to use icons correctly in high DPI.

This is also more consistent with the other platforms, where wxIcon does
have these methods.

Document these methods in wxIcon now that they're available there under
all platforms and also document wxIcon::GetSize() which had been
available even before, but wasn't documented.
This commit is contained in:
Vadim Zeitlin
2022-01-22 22:54:39 +00:00
parent c1d91d5566
commit b4946c2fe3
5 changed files with 101 additions and 62 deletions

View File

@@ -191,19 +191,6 @@ public:
void UseAlpha(bool use = true);
void ResetAlpha() { UseAlpha(false); }
// allow setting and storing the scale factor
virtual void SetScaleFactor(double scale);
virtual double GetScaleFactor() const;
// return the size divided by scale factor
wxSize GetDIPSize() const;
// logical metrics accessors return the same thing as physical ones, just
// as in all the other ports without wxHAS_DPI_INDEPENDENT_PIXELS.
double GetLogicalWidth() const;
double GetLogicalHeight() const;
wxSize GetLogicalSize() const;
// old synonyms for CreateWithLogicalSize() and GetLogicalXXX() functions
bool CreateScaled(int w, int h, int d, double logicalScale)
{ return CreateWithLogicalSize(wxSize(w, h), logicalScale, d); }

View File

@@ -118,10 +118,19 @@ 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;
}
// allow setting and storing the scale factor
void SetScaleFactor(double scale);
double GetScaleFactor() const;
// return the size divided by scale factor
wxSize GetDIPSize() const;
// logical metrics accessors return the same thing as physical ones, just
// as in all the other ports without wxHAS_DPI_INDEPENDENT_PIXELS.
double GetLogicalWidth() const;
double GetLogicalHeight() const;
wxSize GetLogicalSize() const;
wxSize GetSize() const
{

View File

@@ -222,16 +222,59 @@ public:
int GetDepth() const;
/**
Gets the height of the icon in pixels.
Gets the height of the icon in physical pixels.
@see GetWidth()
@see GetWidth(), GetLogicalHeight()
*/
int GetHeight() const;
/**
Gets the width of the icon in pixels.
Gets the height of the icon in logical pixels.
@see GetHeight()
See wxBitmap::GetLogicalHeight().
@since 3.1.6
*/
double GetLogicalHeight() const;
/**
Gets the size of the icon in logical pixels.
See wxBitmap::GetLogicalSize().
@since 3.1.6
*/
double GetLogicalSize() const;
/**
Gets the width of the icon in logical pixels.
See wxBitmap::GetLogicalWidth().
@since 3.1.6
*/
double GetLogicalWidth() const;
/**
Gets the scale factor of this icon.
See wxBitmap::GetScaleFactor().
@since 3.1.6
*/
double GetScaleFactor() const;
/**
Gets the size of the icon in physical pixels.
@see GetLogicalSize()
*/
wxSize GetSize() const;
/**
Gets the width of the icon in physical pixels.
@see GetHeight(), GetLogicalWidth()
*/
int GetWidth() const;

View File

@@ -1364,47 +1364,6 @@ bool wxBitmap::InitFromHBITMAP(WXHBITMAP bmp, int width, int height, int depth)
return IsOk();
}
// ----------------------------------------------------------------------------
// scale factor-related functions
// ----------------------------------------------------------------------------
// 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 scale)
{
wxCHECK_RET( IsOk(), wxT("invalid bitmap") );
GetBitmapData()->m_scaleFactor = scale;
}
double wxBitmap::GetScaleFactor() const
{
wxCHECK_MSG( IsOk(), -1, wxT("invalid bitmap") );
return GetBitmapData()->m_scaleFactor;
}
wxSize wxBitmap::GetDIPSize() const
{
return GetSize() / GetScaleFactor();
}
double wxBitmap::GetLogicalWidth() const
{
return GetWidth();
}
double wxBitmap::GetLogicalHeight() const
{
return GetHeight();
}
wxSize wxBitmap::GetLogicalSize() const
{
return GetSize();
}
// ----------------------------------------------------------------------------
// raw bitmap access support
// ----------------------------------------------------------------------------

View File

@@ -335,6 +335,47 @@ void wxGDIImage::InitStandardHandlers()
#endif // wxUSE_PNG_RESOURCE_HANDLER
}
// ----------------------------------------------------------------------------
// scale factor-related functions
// ----------------------------------------------------------------------------
// 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 wxGDIImage::SetScaleFactor(double scale)
{
wxCHECK_RET( IsOk(), wxT("invalid bitmap") );
GetGDIImageData()->m_scaleFactor = scale;
}
double wxGDIImage::GetScaleFactor() const
{
wxCHECK_MSG( IsOk(), -1, wxT("invalid bitmap") );
return GetGDIImageData()->m_scaleFactor;
}
wxSize wxGDIImage::GetDIPSize() const
{
return GetSize() / GetScaleFactor();
}
double wxGDIImage::GetLogicalWidth() const
{
return GetWidth();
}
double wxGDIImage::GetLogicalHeight() const
{
return GetHeight();
}
wxSize wxGDIImage::GetLogicalSize() const
{
return GetSize();
}
// ----------------------------------------------------------------------------
// wxBitmap handlers
// ----------------------------------------------------------------------------