From da056ee45f5a920fbcb819e43b2931070f223aea Mon Sep 17 00:00:00 2001 From: AllMeatball <181806857+AllMeatball@users.noreply.github.com> Date: Wed, 14 May 2025 23:18:41 +0000 Subject: [PATCH] isleapp: Add icon upon window creation (#85) * isleapp/res: Add icon.h * isleapp: Set icon on non-windows systems * isleapp: Fix formating to match with .clang-format * isleapp: Remove _WIN32 ifdefs This is closer to the original code. I thought it would let Windows set the icon itself not set the icon upon window creation. * isleapp: Load internal .BMP instead of raw pixels This should fix the endianess problem I mentioned in the PR. * isleapp: Only load icon from IOStream if it's valid * isleapp: Disable format checking in ISLE/res/ * ISLE/res/resource.h: Prevent recursive inclusion * ISLE: Remove isle.h from resource.h also rename isle.h to isle_bmp.h * isleapp: Fix formatting --- ISLE/isleapp.cpp | 18 +++ ISLE/res/.clang-format | 1 + ISLE/res/isle.bmp | Bin 0 -> 4166 bytes ISLE/res/isle_bmp.h | 351 +++++++++++++++++++++++++++++++++++++++++ ISLE/res/resource.h | 1 + 5 files changed, 371 insertions(+) create mode 100644 ISLE/res/.clang-format create mode 100644 ISLE/res/isle.bmp create mode 100644 ISLE/res/isle_bmp.h diff --git a/ISLE/isleapp.cpp b/ISLE/isleapp.cpp index 8350cab6..9fe2e774 100644 --- a/ISLE/isleapp.cpp +++ b/ISLE/isleapp.cpp @@ -25,6 +25,7 @@ #include "mxtransitionmanager.h" #include "mxutilities.h" #include "mxvariabletable.h" +#include "res/isle_bmp.h" #include "res/resource.h" #include "roi/legoroi.h" #include "viewmanager/viewmanager.h" @@ -486,6 +487,23 @@ MxResult IsleApp::SetupWindow() return FAILURE; } + SDL_IOStream* icon_stream = SDL_IOFromMem(isle_bmp, isle_bmp_len); + + if (icon_stream) { + SDL_Surface* icon = SDL_LoadBMP_IO(icon_stream, true); + + if (icon) { + SDL_SetWindowIcon(m_windowHandle, icon); + SDL_DestroySurface(icon); + } + else { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to load icon: %s", SDL_GetError()); + } + } + else { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to open SDL_IOStream for icon: %s", SDL_GetError()); + } + if (!SetupLegoOmni()) { return FAILURE; } diff --git a/ISLE/res/.clang-format b/ISLE/res/.clang-format new file mode 100644 index 00000000..e3845288 --- /dev/null +++ b/ISLE/res/.clang-format @@ -0,0 +1 @@ +DisableFormat: true diff --git a/ISLE/res/isle.bmp b/ISLE/res/isle.bmp new file mode 100644 index 0000000000000000000000000000000000000000..07a0b2a29059f19fcdaa5cba3fecf48e60313249 GIT binary patch literal 4166 zcmeH`OA^8`2!`XhbmNQ{@EERLxbyzUiO}|^v>_C$aePG)0-+y}dcI!vsaqHNJ&_y- z*^sp*J5l_w>xH-d$|?0<-jelSZ#RKV_tN4MZL|fOpBY`h&QF>Dp@wubw*xvk|{D=AI+0!lgn0?Fs z#~ao(vV-^U O|D=wB%X