From 976e2425fc40f05e5e4424a46ad565ffc77bd233 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 21 Jan 2020 11:27:32 +0000 Subject: [PATCH] Use native window/taskbar icons on Windows This used to be a feature before the accurate-portable split, I'm just restoring it. Previously, while the EXE itself had a unique icon, the window and taskbar both used the generic 'small' icon, which the original EXE only used for the window. SDL2 gives us a way to assign separate icons to each, but it's a little clunky: it's Windows-only, requires the icons be in .ico format, and needs them to be embedded in the EXE as resource files. Also, for some reason, SDL2 doesn't let us refer to them by name - we have to use their numerical ID. --- CMakeLists.txt | 5 ++++- assets/resources/CSE2.rc | 10 +++++++++- src/Main.cpp | 7 +++++++ src/Resource.cpp | 4 ++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ccde17ca..731861ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -221,7 +221,6 @@ set(RESOURCES BITMAP/Credit18.bmp CURSOR/CURSOR_IKA.bmp CURSOR/CURSOR_NORMAL.bmp - ICON/ICON_MINI.bmp ORG/Access.org ORG/Anzen.org ORG/Balcony.org @@ -277,6 +276,10 @@ else() list(APPEND RESOURCES "BITMAP/pixel.bmp" "FONT/LiberationMono.ttf") endif() +if(NOT WIN32) + list(APPEND RESOURCES "ICON/ICON_MINI.bmp") +endif() + if(FIX_BUGS) target_compile_definitions(CSE2 PRIVATE FIX_BUGS) endif() diff --git a/assets/resources/CSE2.rc b/assets/resources/CSE2.rc index 84e36811..b905e897 100644 --- a/assets/resources/CSE2.rc +++ b/assets/resources/CSE2.rc @@ -58,8 +58,16 @@ BEGIN END END -0 ICON "ICON/0.ico" +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +0 ICON "ICON/0.ico" +1 ICON "ICON/ICON_MINI.ico" #endif // Japanese resources ///////////////////////////////////////////////////////////////////////////// diff --git a/src/Main.cpp b/src/Main.cpp index b03cedcf..37df0900 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -193,6 +193,11 @@ int main(int argc, char *argv[]) RECT unused_rect = {0, 0, WINDOW_WIDTH, WINDOW_HEIGHT}; +#ifdef _WIN32 + SDL_SetHint(SDL_HINT_WINDOWS_INTRESOURCE_ICON, "0"); + SDL_SetHint(SDL_HINT_WINDOWS_INTRESOURCE_ICON_SMALL, "1"); +#endif + SDL_InitSubSystem(SDL_INIT_VIDEO); SDL_Window *window; @@ -274,11 +279,13 @@ int main(int argc, char *argv[]) size_t resource_size; SDL_RWops *rwops; +#ifndef _WIN32 // On Windows, we use native icons instead (so we can give the taskbar and window separate icons, like the original EXE does) resource_data = FindResource("ICON_MINI", "ICON", &resource_size); rwops = SDL_RWFromConstMem(resource_data, resource_size); SDL_Surface *icon_surface = SDL_LoadBMP_RW(rwops, 1); SDL_SetWindowIcon(window, icon_surface); SDL_FreeSurface(icon_surface); +#endif resource_data = FindResource("CURSOR_NORMAL", "CURSOR", &resource_size); rwops = SDL_RWFromConstMem(resource_data, resource_size); diff --git a/src/Resource.cpp b/src/Resource.cpp index 58d1e4be..134c04e0 100644 --- a/src/Resource.cpp +++ b/src/Resource.cpp @@ -32,7 +32,9 @@ #else #include "Resource/FONT/LiberationMono.ttf.h" #endif +#ifndef _WIN32 #include "Resource/ICON/ICON_MINI.bmp.h" +#endif #include "Resource/ORG/Access.org.h" #include "Resource/ORG/Anzen.org.h" #include "Resource/ORG/Balcony.org.h" @@ -113,7 +115,9 @@ static const struct #else {"FONT", "FONT", rLiberationMono, sizeof(rLiberationMono)}, #endif +#ifndef _WIN32 {"ICON", "ICON_MINI", rICON_MINI, sizeof(rICON_MINI)}, +#endif {"ORG", "ACCESS", rAccess, sizeof(rAccess)}, {"ORG", "ANZEN", rAnzen, sizeof(rAnzen)}, {"ORG", "BALCONY", rBalcony, sizeof(rBalcony)},