Update wxStaticBitmap in wxMSW on DPI change

Use the appropriately sized bitmap when the resolution changes.
This commit is contained in:
Vadim Zeitlin
2021-10-21 19:05:07 +01:00
parent 0a91a2f40b
commit 04828b7225
2 changed files with 13 additions and 0 deletions

View File

@@ -112,7 +112,9 @@ private:
// can we leave it to it) // can we leave it to it)
void DoPaintManually(wxPaintEvent& event); void DoPaintManually(wxPaintEvent& event);
// event handlers
void WXHandleSize(wxSizeEvent& event); void WXHandleSize(wxSizeEvent& event);
void WXHandleDPIChanged(wxDPIChangedEvent& event);
// return the size of m_icon or the appropriate size of m_bitmapBundle at // return the size of m_icon or the appropriate size of m_bitmapBundle at
// the current DPI scaling (may still be invalid of both of them are) // the current DPI scaling (may still be invalid of both of them are)

View File

@@ -45,6 +45,7 @@
wxBEGIN_EVENT_TABLE(wxStaticBitmap, wxStaticBitmapBase) wxBEGIN_EVENT_TABLE(wxStaticBitmap, wxStaticBitmapBase)
EVT_SIZE(wxStaticBitmap::WXHandleSize) EVT_SIZE(wxStaticBitmap::WXHandleSize)
EVT_DPI_CHANGED(wxStaticBitmap::WXHandleDPIChanged)
wxEND_EVENT_TABLE() wxEND_EVENT_TABLE()
// =========================================================================== // ===========================================================================
@@ -190,6 +191,16 @@ void wxStaticBitmap::WXHandleSize(wxSizeEvent& event)
event.Skip(); event.Skip();
} }
void wxStaticBitmap::WXHandleDPIChanged(wxDPIChangedEvent& event)
{
// Icons only exist in a single resolution, so don't bother updating in
// this case.
if ( !m_icon.IsOk() && m_bitmapBundle.IsOk() )
DoUpdateImage(wxSize(), false /* not using an icon */);
event.Skip();
}
void wxStaticBitmap::DoPaintManually(wxPaintEvent& WXUNUSED(event)) void wxStaticBitmap::DoPaintManually(wxPaintEvent& WXUNUSED(event))
{ {
wxPaintDC dc(this); wxPaintDC dc(this);