diff --git a/include/wx/bitmap.h b/include/wx/bitmap.h index dabc68f950..67bed4ce30 100644 --- a/include/wx/bitmap.h +++ b/include/wx/bitmap.h @@ -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). diff --git a/include/wx/msw/bitmap.h b/include/wx/msw/bitmap.h index 1f3d143c70..a3c6d1279b 100644 --- a/include/wx/msw/bitmap.h +++ b/include/wx/msw/bitmap.h @@ -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; diff --git a/interface/wx/bitmap.h b/interface/wx/bitmap.h index 3ef0c30b94..c1605c0523 100644 --- a/interface/wx/bitmap.h +++ b/interface/wx/bitmap.h @@ -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. diff --git a/src/common/artprov.cpp b/src/common/artprov.cpp index 0d7aa76e54..4a06f88e96 100644 --- a/src/common/artprov.cpp +++ b/src/common/artprov.cpp @@ -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. diff --git a/src/common/bmpbase.cpp b/src/common/bmpbase.cpp index e3998b862a..3cb1c75471 100644 --- a/src/common/bmpbase.cpp +++ b/src/common/bmpbase.cpp @@ -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 diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index bba052367d..86b936ef3a 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -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();