ref: 976e2425fc40f05e5e4424a46ad565ffc77bd233
parent: ad9e3c3e3bb922832474fce41efce772e3aabcb1
author: Clownacy <Clownacy@users.noreply.github.com>
date: Tue Jan 21 06:27:32 EST 2020
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.
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -221,7 +221,6 @@
BITMAP/Credit18.bmp
CURSOR/CURSOR_IKA.bmp
CURSOR/CURSOR_NORMAL.bmp
- ICON/ICON_MINI.bmp
ORG/Access.org
ORG/Anzen.org
ORG/Balcony.org
@@ -275,6 +274,10 @@
else()
set(DATA_DIRECTORY "${ASSETS_DIRECTORY}/data_en")
list(APPEND RESOURCES "BITMAP/pixel.bmp" "FONT/LiberationMono.ttf")
+endif()
+
+if(NOT WIN32)
+ list(APPEND RESOURCES "ICON/ICON_MINI.bmp")
endif()
if(FIX_BUGS)
--- a/assets/resources/CSE2.rc
+++ b/assets/resources/CSE2.rc
@@ -58,8 +58,16 @@
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
/////////////////////////////////////////////////////////////////////////////
--- a/src/Main.cpp
+++ b/src/Main.cpp
@@ -193,6 +193,11 @@
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 @@
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);
--- 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 @@
#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)},
--
⑨