Add wxBitmapBundle::GetBitmapFor() helper

This can be used to get the bitmap of the size appropriate for the DPI
scaling used for the given window.
This commit is contained in:
Vadim Zeitlin 2021-10-21 02:42:13 +01:00
parent e5a7e9ccbd
commit 9326aa3b6c
3 changed files with 23 additions and 0 deletions

View File

@ -109,6 +109,11 @@ public:
// If size == wxDefaultSize, GetDefaultSize() is used for it instead.
wxBitmap GetBitmap(const wxSize& size) const;
// Helper combining GetBitmap() and GetPreferredSizeFor(): returns the
// bitmap of the size appropriate for the current DPI scaling of the given
// window.
wxBitmap GetBitmapFor(const wxWindow* window) const;
// Access implementation
wxBitmapBundleImpl* GetImpl() const { return m_impl.get(); }

View File

@ -288,6 +288,19 @@ public:
consume resources until the application termination.
*/
wxBitmap GetBitmap(const wxSize& size) const;
/**
Get bitmap of the size appropriate for the DPI scaling used by the
given window.
This helper function simply combines GetBitmap() and
GetPreferredSizeFor(), i.e. it returns a (normally unscaled) bitmap
from the bundle of the closest size to the size that should be used at
the DPI scaling of the provided window.
@param window Non-null and fully created window.
*/
wxBitmap GetBitmapFor(const wxWindow* window) const;
};
/**

View File

@ -407,6 +407,11 @@ wxBitmap wxBitmapBundle::GetBitmap(const wxSize& size) const
return bmp;
}
wxBitmap wxBitmapBundle::GetBitmapFor(const wxWindow* window) const
{
return GetBitmap(GetPreferredSizeFor(window));
}
// ============================================================================
// wxBitmapBundleImpl implementation
// ============================================================================