diff --git a/src/Backends/Platform.h b/src/Backends/Platform.h index a71bff20..b9f198e5 100644 --- a/src/Backends/Platform.h +++ b/src/Backends/Platform.h @@ -9,6 +9,7 @@ void PlatformBackend_Deinit(void); void PlatformBackend_PostWindowCreation(void); BOOL PlatformBackend_GetBasePath(char *string_buffer); void PlatformBackend_HideMouse(void); +void PlatformBackend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int width, unsigned int height); BOOL PlatformBackend_SystemTask(void); void PlatformBackend_ShowMessageBox(const char *title, const char *message); unsigned long PlatformBackend_GetTicks(void); diff --git a/src/Backends/Platform/GLFW3.cpp b/src/Backends/Platform/GLFW3.cpp index b84f1315..e0903c26 100644 --- a/src/Backends/Platform/GLFW3.cpp +++ b/src/Backends/Platform/GLFW3.cpp @@ -12,7 +12,6 @@ #include "../../WindowsWrapper.h" -#include "../../Bitmap.h" #include "../../KeyControl.h" #include "../../Main.h" #include "../../Organya.h" @@ -232,46 +231,6 @@ void PlatformBackend_PostWindowCreation(void) glfwSetKeyCallback(window, KeyCallback); glfwSetWindowFocusCallback(window, WindowFocusCallback); glfwSetWindowSizeCallback(window, WindowSizeCallback); - - // Set up window icon - - // TODO - GLFW_ICON -#ifndef _WIN32 // On Windows, we use native icons instead (so we can give the taskbar and window separate icons, like the original EXE does) - size_t resource_size; - const unsigned char *resource_data = FindResource("ICON_MINI", "ICON", &resource_size); - - unsigned int width, height; - unsigned char *rgb_pixels = DecodeBitmap(resource_data, resource_size, &width, &height); - - if (rgb_pixels != NULL) - { - unsigned char *rgba_pixels = (unsigned char*)malloc(width * height * 4); - - unsigned char *rgb_pointer = rgb_pixels; - unsigned char *rgba_pointer = rgba_pixels; - - if (rgba_pixels != NULL) - { - for (unsigned int y = 0; y < height; ++y) - { - for (unsigned int x = 0; x < width; ++x) - { - *rgba_pointer++ = *rgb_pointer++; - *rgba_pointer++ = *rgb_pointer++; - *rgba_pointer++ = *rgb_pointer++; - *rgba_pointer++ = 0xFF; - } - } - - GLFWimage glfw_image = {(int)width, (int)height, rgba_pixels}; - glfwSetWindowIcon(window, 1, &glfw_image); - - free(rgba_pixels); - } - - FreeBitmap(rgb_pixels); - } -#endif } BOOL PlatformBackend_GetBasePath(char *string_buffer) @@ -284,6 +243,34 @@ void PlatformBackend_HideMouse(void) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); } +void PlatformBackend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int width, unsigned int height) +{ + unsigned char *rgba_pixels = (unsigned char*)malloc(width * height * 4); + + const unsigned char *rgb_pointer = rgb_pixels; + unsigned char *rgba_pointer = rgba_pixels; + + if (rgba_pixels != NULL) + { + for (unsigned int y = 0; y < height; ++y) + { + for (unsigned int x = 0; x < width; ++x) + { + *rgba_pointer++ = *rgb_pointer++; + *rgba_pointer++ = *rgb_pointer++; + *rgba_pointer++ = *rgb_pointer++; + *rgba_pointer++ = 0xFF; + } + } + + GLFWimage glfw_image = {(int)width, (int)height, rgba_pixels}; + glfwSetWindowIcon(window, 1, &glfw_image); + + free(rgba_pixels); + } +} + + BOOL PlatformBackend_SystemTask(void) { if (glfwWindowShouldClose(window)) diff --git a/src/Backends/Platform/SDL2.cpp b/src/Backends/Platform/SDL2.cpp index 0b257b6c..77a64cde 100644 --- a/src/Backends/Platform/SDL2.cpp +++ b/src/Backends/Platform/SDL2.cpp @@ -42,15 +42,7 @@ void PlatformBackend_Deinit(void) void PlatformBackend_PostWindowCreation(void) { - // Set up window icon -#ifndef _WIN32 // On Windows, we use native icons instead (so we can give the taskbar and window separate icons, like the original EXE does) - size_t resource_size; - const unsigned char *resource_data = FindResource("ICON_MINI", "ICON", &resource_size); - SDL_RWops *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 + } BOOL PlatformBackend_GetBasePath(char *string_buffer) @@ -69,6 +61,13 @@ void PlatformBackend_HideMouse(void) SDL_ShowCursor(SDL_DISABLE); } +void PlatformBackend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int width, unsigned int height) +{ + SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormatFrom((void*)rgb_pixels, width, height, 0, width * 3, SDL_PIXELFORMAT_RGB24); + SDL_SetWindowIcon(window, surface); + SDL_FreeSurface(surface); +} + BOOL PlatformBackend_SystemTask(void) { while (SDL_PollEvent(NULL) || !bActive) diff --git a/src/Main.cpp b/src/Main.cpp index fa34e8b0..67c9615f 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -9,6 +9,7 @@ #include "Backends/Platform.h" #include "Backends/Rendering.h" +#include "Bitmap.h" #include "CommonDefines.h" #include "Config.h" #include "Draw.h" @@ -277,6 +278,22 @@ int main(int argc, char *argv[]) #ifdef DEBUG_SAVE //SDL_EventState(SDL_DROPFILE, SDL_ENABLE); #endif + + // Set up window icon + // TODO - GLFW_ICON +#ifndef _WIN32 // On Windows, we use native icons instead (so we can give the taskbar and window separate icons, like the original EXE does) + size_t window_icon_resource_size; + const unsigned char *window_icon_resource_data = FindResource("ICON_MINI", "ICON", &window_icon_resource_size); + + unsigned int width, height; + unsigned char *rgb_pixels = DecodeBitmap(window_icon_resource_data, window_icon_resource_size, &width, &height); + + if (rgb_pixels != NULL) + { + PlatformBackend_SetWindowIcon(rgb_pixels, width, height); + FreeBitmap(rgb_pixels); + } +#endif /* // Set up the cursor size_t resource_size;