Only return really scaled bitmap size under platforms using DIPs
wxBitmap::GetScaledXXX() functions are useful for obtaining the
coordinates in logical pixels, so they should only divide by the scaling
factor on the platforms where logical pixels are actually different from
the physical ones, i.e. those using DPI-independent pixels.
This ensures that their behaviour under MSW remains unchanged even after
a1e4dca067 (Store scale factor in wxMSW bitmaps too, 2021-12-16), which
is the correct way to avoid breaking wxAUI (and other) drawing.
This commit is contained in:
@@ -190,6 +190,9 @@ public:
|
||||
virtual void SetScaleFactor(double scale);
|
||||
virtual double GetScaleFactor() 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).
|
||||
double GetScaledWidth() const;
|
||||
double GetScaledHeight() const;
|
||||
wxSize GetScaledSize() const;
|
||||
|
||||
@@ -184,10 +184,12 @@ public:
|
||||
void UseAlpha(bool use = true);
|
||||
void ResetAlpha() { UseAlpha(false); }
|
||||
|
||||
// provide stabs of scaled bitmaps functions, they are trivial here
|
||||
// allow setting and storing the scale factor
|
||||
virtual void SetScaleFactor(double scale);
|
||||
virtual double GetScaleFactor() 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;
|
||||
double GetScaledHeight() const;
|
||||
wxSize GetScaledSize() const;
|
||||
|
||||
@@ -609,12 +609,18 @@ public:
|
||||
/**
|
||||
Returns the scaled size of the bitmap.
|
||||
|
||||
The scaled size of the bitmap is its size in pixels, as returned by
|
||||
For the platforms using DPI-independent pixels, i.e. those where @c
|
||||
wxHAS_DPI_INDEPENDENT_PIXELS is defined, such as wxOSX or wxGTK 3,
|
||||
this function returns the physical size of the bitmap, as returned by
|
||||
GetSize(), divided by its scale factor, as returned by
|
||||
GetScaleFactor(), and so is the same as the normal size for bitmaps
|
||||
with the default scale factor of 1 and always less than the physical
|
||||
size for the higher resolution bitmaps supposed to be used on high DPI
|
||||
screens.
|
||||
GetScaleFactor(), while for the other platforms, it simply returns the
|
||||
same thing as GetSize().
|
||||
|
||||
This ensures that the result of this function is always expressed in
|
||||
the pixel coordinates appropriate for the current platform, i.e. its
|
||||
return value is always in logical pixels, used for window and wxDC
|
||||
coordinates, whether these pixels are the same as physical pixels,
|
||||
which are returned by GetSize(), or not.
|
||||
|
||||
@see GetScaledWidth(), GetScaledHeight(), GetSize()
|
||||
|
||||
|
||||
@@ -220,6 +220,8 @@ double wxBitmapBase::GetScaleFactor() const
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
#ifdef wxHAS_DPI_INDEPENDENT_PIXELS
|
||||
|
||||
double wxBitmapBase::GetScaledWidth() const
|
||||
{
|
||||
return GetWidth() / GetScaleFactor();
|
||||
@@ -235,6 +237,25 @@ wxSize wxBitmapBase::GetScaledSize() const
|
||||
return wxSize(wxRound(GetScaledWidth()), wxRound(GetScaledHeight()));
|
||||
}
|
||||
|
||||
#else // !wxHAS_DPI_INDEPENDENT_PIXELS
|
||||
|
||||
double wxBitmapBase::GetScaledWidth() const
|
||||
{
|
||||
return GetWidth();
|
||||
}
|
||||
|
||||
double wxBitmapBase::GetScaledHeight() const
|
||||
{
|
||||
return GetHeight();
|
||||
}
|
||||
|
||||
wxSize wxBitmapBase::GetScaledSize() const
|
||||
{
|
||||
return GetSize();
|
||||
}
|
||||
|
||||
#endif // wxHAS_DPI_INDEPENDENT_PIXELS/!wxHAS_DPI_INDEPENDENT_PIXELS
|
||||
|
||||
#endif // wxUSE_BITMAP_BASE
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -1387,17 +1387,17 @@ double wxBitmap::GetScaleFactor() const
|
||||
|
||||
double wxBitmap::GetScaledWidth() const
|
||||
{
|
||||
return GetWidth() / GetScaleFactor();
|
||||
return GetWidth();
|
||||
}
|
||||
|
||||
double wxBitmap::GetScaledHeight() const
|
||||
{
|
||||
return GetHeight() / GetScaleFactor();
|
||||
return GetHeight();
|
||||
}
|
||||
|
||||
wxSize wxBitmap::GetScaledSize() const
|
||||
{
|
||||
return GetSize() / GetScaleFactor();
|
||||
return GetSize();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user