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:
@@ -71,7 +71,7 @@ public:
|
|||||||
#endif // WXWIN_COMPATIBILITY_3_0
|
#endif // WXWIN_COMPATIBILITY_3_0
|
||||||
|
|
||||||
WXHICON GetHICON() const { return (WXHICON)GetHandle(); }
|
WXHICON GetHICON() const { return (WXHICON)GetHandle(); }
|
||||||
bool InitFromHICON(WXHICON icon, int width, int height);
|
bool InitFromHICON(WXHICON icon, int width, int height, double scale = 1.0);
|
||||||
|
|
||||||
// create from bitmap (which should have a mask unless it's monochrome):
|
// create from bitmap (which should have a mask unless it's monochrome):
|
||||||
// there shouldn't be any implicit bitmap -> icon conversion (i.e. no
|
// there shouldn't be any implicit bitmap -> icon conversion (i.e. no
|
||||||
|
|||||||
@@ -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
|
#if wxUSE_PNG_RESOURCE_HANDLER
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ bool wxIcon::CreateFromHICON(WXHICON icon)
|
|||||||
return InitFromHICON(icon, size.GetWidth(), size.GetHeight());
|
return InitFromHICON(icon, size.GetWidth(), size.GetHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxIcon::InitFromHICON(WXHICON icon, int width, int height)
|
bool wxIcon::InitFromHICON(WXHICON icon, int width, int height, double scale)
|
||||||
{
|
{
|
||||||
#if wxDEBUG_LEVEL >= 2
|
#if wxDEBUG_LEVEL >= 2
|
||||||
if ( icon != NULL )
|
if ( icon != NULL )
|
||||||
@@ -170,6 +170,7 @@ bool wxIcon::InitFromHICON(WXHICON icon, int width, int height)
|
|||||||
GetGDIImageData()->m_handle = (WXHANDLE)icon;
|
GetGDIImageData()->m_handle = (WXHANDLE)icon;
|
||||||
GetGDIImageData()->m_width = width;
|
GetGDIImageData()->m_width = width;
|
||||||
GetGDIImageData()->m_height = height;
|
GetGDIImageData()->m_height = height;
|
||||||
|
GetGDIImageData()->m_scaleFactor = scale;
|
||||||
|
|
||||||
return IsOk();
|
return IsOk();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user