Set scale factor correctly for icons loaded from resources

::LoadIcon() selects the icon of scaled size in the DPI-aware programs,
which is nice, but only works right if we actually set the scale factor
for the icon correctly.
This commit is contained in:
Vadim Zeitlin
2021-12-16 01:17:35 +00:00
parent a1e4dca067
commit d78696243b
3 changed files with 23 additions and 3 deletions

View File

@@ -586,7 +586,26 @@ bool wxICOResourceHandler::LoadIcon(wxIcon *icon,
}
}
return icon->CreateFromHICON((WXHICON)hicon);
if ( !hicon )
return false;
wxSize size;
double scale = 1.0;
if ( hasSize )
{
size.x = desiredWidth;
size.y = desiredHeight;
}
else // We loaded an icon of default size.
{
// LoadIcon() returns icons of scaled size, so we must use the correct
// scaling factor of them.
size = wxGetHiconSize(hicon);
if ( const wxWindow* win = wxApp::GetMainTopWindow() )
scale = win->GetDPIScaleFactor();
}
return icon->InitFromHICON((WXHICON)hicon, size.x, size.y, scale);
}
#if wxUSE_PNG_RESOURCE_HANDLER