Add wxBitmap::GetDIPSize() and use it in wxBitmapBundleImplArt
This fixes the problem with wrong standard bitmaps size when using high DPI for the main monitor with wxMSW, as GetScaledSize() used here since 31f2892200 (Avoid bitmap scaling in wxArtProvider::GetBitmapBundle(), 2021-12-17) was not the right function to use there. Closes #19331.
This commit is contained in:
@@ -186,10 +186,16 @@ public:
|
||||
wxSize GetSize() const
|
||||
{ return wxSize(GetWidth(), GetHeight()); }
|
||||
|
||||
// support for scaled bitmaps
|
||||
// Store or return the scale factor, which determines the ratio between the
|
||||
// bitmap physical size and its DIP size (on all platforms). By default
|
||||
// it's just 1.
|
||||
virtual void SetScaleFactor(double scale);
|
||||
virtual double GetScaleFactor() const;
|
||||
|
||||
// This function returns the size divided by the scale factor, so that a
|
||||
// 64x64 bitmap with a scale factor of 2 has DIP size of 32x32 everywhere.
|
||||
wxSize GetDIPSize() const;
|
||||
|
||||
// These functions return the corresponding metrics divided by the scale
|
||||
// factor on platforms with DPI-independent pixels (e.g. GTK, Mac) and just
|
||||
// the same thing as the non-scaled accessors elsewhere (e.g. MSW).
|
||||
|
||||
@@ -188,6 +188,9 @@ public:
|
||||
virtual void SetScaleFactor(double scale);
|
||||
virtual double GetScaleFactor() const;
|
||||
|
||||
// return the size divided by scale factor
|
||||
wxSize GetDIPSize() const;
|
||||
|
||||
// but scaled metrics accessors return the same thing as non-scaled ones,
|
||||
// just as in all the other ports without wxHAS_DPI_INDEPENDENT_PIXELS.
|
||||
double GetScaledWidth() const;
|
||||
|
||||
@@ -541,6 +541,22 @@ public:
|
||||
*/
|
||||
virtual int GetDepth() const;
|
||||
|
||||
/**
|
||||
Returns the size of bitmap in DPI-independent units.
|
||||
|
||||
This assumes that the bitmap was created using the value of scale
|
||||
factor corresponding to the current DPI (see CreateScaled() and
|
||||
SetScaleFactor()) and returns its physical size divided by this scale
|
||||
factor.
|
||||
|
||||
Unlike GetScaledSize(), this function returns the same value under all
|
||||
platforms and so its result should @e not be used as window or device
|
||||
context coordinates.
|
||||
|
||||
@since 3.1.6
|
||||
*/
|
||||
wxSize GetDIPSize() const;
|
||||
|
||||
/**
|
||||
Returns the static list of bitmap format handlers.
|
||||
|
||||
|
||||
@@ -193,7 +193,7 @@ private:
|
||||
// necessary, so use GetScaledSize() and not GetSize().
|
||||
const wxBitmap bitmap = wxArtProvider::GetBitmap(id, client);
|
||||
if ( bitmap.IsOk() )
|
||||
return bitmap.GetScaledSize();
|
||||
return bitmap.GetDIPSize();
|
||||
|
||||
// We really need some default size, so just return this hardcoded
|
||||
// value if all else fails -- what else can we do.
|
||||
|
||||
@@ -220,6 +220,11 @@ double wxBitmapBase::GetScaleFactor() const
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
wxSize wxBitmapBase::GetDIPSize() const
|
||||
{
|
||||
return GetSize() / GetScaleFactor();
|
||||
}
|
||||
|
||||
#ifdef wxHAS_DPI_INDEPENDENT_PIXELS
|
||||
|
||||
double wxBitmapBase::GetScaledWidth() const
|
||||
|
||||
@@ -1385,6 +1385,11 @@ double wxBitmap::GetScaleFactor() const
|
||||
return GetBitmapData()->m_scaleFactor;
|
||||
}
|
||||
|
||||
wxSize wxBitmap::GetDIPSize() const
|
||||
{
|
||||
return GetSize() / GetScaleFactor();
|
||||
}
|
||||
|
||||
double wxBitmap::GetScaledWidth() const
|
||||
{
|
||||
return GetWidth();
|
||||
|
||||
Reference in New Issue
Block a user