From c4f5ced37ca9eff6a5c62c08f1cc7a9e6dc47f7d Mon Sep 17 00:00:00 2001 From: EmptyChaos Date: Mon, 3 Oct 2016 07:19:56 +0000 Subject: [PATCH] WX: Replace SetIcon with SetIcons(wxIconBundle) Setting a single icon at a single resolution doesn't scale well, Windows requires a 16x16 icon for the window and a 32x32/48x48 for the taskbar. Providing all icons produces less pixellated results at HiDPI. --- Source/Core/DolphinWX/Cheats/CheatsWindow.cpp | 1 + Source/Core/DolphinWX/Frame.cpp | 4 +- .../DolphinWX/NetPlay/NetPlaySetupFrame.cpp | 6 +-- Source/Core/DolphinWX/NetPlay/NetWindow.cpp | 1 + Source/Core/DolphinWX/WxUtils.cpp | 48 +++++++++++++++++++ Source/Core/DolphinWX/WxUtils.h | 3 ++ 6 files changed, 55 insertions(+), 8 deletions(-) diff --git a/Source/Core/DolphinWX/Cheats/CheatsWindow.cpp b/Source/Core/DolphinWX/Cheats/CheatsWindow.cpp index a313d4c2a0..af4ec1c177 100644 --- a/Source/Core/DolphinWX/Cheats/CheatsWindow.cpp +++ b/Source/Core/DolphinWX/Cheats/CheatsWindow.cpp @@ -61,6 +61,7 @@ wxCheatsWindow::wxCheatsWindow(wxWindow* const parent) UpdateGUI(); wxTheApp->Bind(DOLPHIN_EVT_LOCAL_INI_CHANGED, &wxCheatsWindow::OnLocalGameIniModified, this); + SetIcons(WxUtils::GetDolphinIconBundle()); SetLayoutAdaptationMode(wxDIALOG_ADAPTATION_MODE_ENABLED); SetLayoutAdaptationLevel(wxDIALOG_ADAPTATION_STANDARD_SIZER); Center(); diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp index 2b3cdb0959..5cfbc79937 100644 --- a/Source/Core/DolphinWX/Frame.cpp +++ b/Source/Core/DolphinWX/Frame.cpp @@ -85,9 +85,7 @@ CRenderFrame::CRenderFrame(wxFrame* parent, wxWindowID id, const wxString& title : wxFrame(parent, id, title, pos, size, style) { // Give it an icon - wxIcon IconTemp; - IconTemp.CopyFromBitmap(WxUtils::LoadScaledResourceBitmap("Dolphin", this)); - SetIcon(IconTemp); + SetIcons(WxUtils::GetDolphinIconBundle()); DragAcceptFiles(true); Bind(wxEVT_DROP_FILES, &CRenderFrame::OnDropFiles, this); diff --git a/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp b/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp index 230f12bbe8..21dbce3217 100644 --- a/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp +++ b/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp @@ -43,11 +43,7 @@ NetPlaySetupFrame::NetPlaySetupFrame(wxWindow* const parent, const CGameListCtrl IniFile::Section& netplay_section = *inifile.GetOrCreateSection("NetPlay"); CreateGUI(); - { - wxIcon icon; - icon.CopyFromBitmap(WxUtils::LoadScaledResourceBitmap("Dolphin", this)); - SetIcon(icon); - } + SetIcons(WxUtils::GetDolphinIconBundle()); { std::string temp; diff --git a/Source/Core/DolphinWX/NetPlay/NetWindow.cpp b/Source/Core/DolphinWX/NetPlay/NetWindow.cpp index 1c7a7dc57f..90f60e3c1b 100644 --- a/Source/Core/DolphinWX/NetPlay/NetWindow.cpp +++ b/Source/Core/DolphinWX/NetPlay/NetWindow.cpp @@ -70,6 +70,7 @@ NetPlayDialog::NetPlayDialog(wxWindow* const parent, const CGameListCtrl* const { Bind(wxEVT_THREAD, &NetPlayDialog::OnThread, this); CreateGUI(); + SetIcons(WxUtils::GetDolphinIconBundle()); Center(); // Remember the window size and position for NetWindow diff --git a/Source/Core/DolphinWX/WxUtils.cpp b/Source/Core/DolphinWX/WxUtils.cpp index 7a7763df48..ef22a09d43 100644 --- a/Source/Core/DolphinWX/WxUtils.cpp +++ b/Source/Core/DolphinWX/WxUtils.cpp @@ -28,6 +28,10 @@ #include "DolphinWX/WxUtils.h" +#ifdef _WIN32 +#include +#endif + namespace WxUtils { // Launch a file according to its mime type @@ -81,6 +85,50 @@ void AddToolbarButton(wxToolBar* toolbar, int toolID, const wxString& label, con wxITEM_NORMAL, shortHelp); } +wxIconBundle GetDolphinIconBundle() +{ + static wxIconBundle s_bundle; + if (!s_bundle.IsEmpty()) + return s_bundle; + +#ifdef _WIN32 + + // Convert the Windows ICO file into a wxIconBundle by tearing it apart into each individual + // sub-icon using the Win32 API. This is necessary because WX uses its own wxIcons internally + // which (unlike QIcon in Qt) only contain 1 image per icon, hence why wxIconBundle exists. + HINSTANCE dolphin = GetModuleHandleW(nullptr); + for (int size : {16, 32, 48, 256}) + { + // Extract resource from embedded DolphinWX.rc + HANDLE win32_icon = + LoadImageW(dolphin, L"\"DOLPHIN\"", IMAGE_ICON, size, size, LR_CREATEDIBSECTION); + if (win32_icon && win32_icon != INVALID_HANDLE_VALUE) + { + wxIcon icon; + icon.CreateFromHICON(reinterpret_cast(win32_icon)); + s_bundle.AddIcon(icon); + } + } + +#else + + for (const char* fname : {"Dolphin.png", "dolphin_logo.png", "dolphin_logo@2x.png"}) + { + wxImage image{StrToWxStr(File::GetSysDirectory() + RESOURCES_DIR DIR_SEP + fname), + wxBITMAP_TYPE_PNG}; + if (image.IsOk()) + { + wxIcon icon; + icon.CopyFromBitmap(image); + s_bundle.AddIcon(icon); + } + } + +#endif + + return s_bundle; +} + wxRect GetVirtualScreenGeometry() { wxRect geometry; diff --git a/Source/Core/DolphinWX/WxUtils.h b/Source/Core/DolphinWX/WxUtils.h index 521979d32c..6cb449ae2d 100644 --- a/Source/Core/DolphinWX/WxUtils.h +++ b/Source/Core/DolphinWX/WxUtils.h @@ -36,6 +36,9 @@ wxBitmap CreateDisabledButtonBitmap(const wxBitmap& original); void AddToolbarButton(wxToolBar* toolbar, int toolID, const wxString& label, const wxBitmap& bitmap, const wxString& shortHelp); +// Gets a complete set of window icons at all relevant sizes, use with wxTopLevelWindow::SetIcons +wxIconBundle GetDolphinIconBundle(); + // Get the dimensions of the virtual desktop that spans all monitors. // Matches GetSystemMetrics(SM_XVIRTUALSCREEN), etc on Windows. wxRect GetVirtualScreenGeometry();