ref: f23117bbdc25c0ce7431eccedd2e39aee4ca6659
parent: 878cac3b3fbad72266bb2b6e89409ea656ff2d6a
author: Clownacy <[email protected]>
date: Wed Apr 1 17:20:26 EDT 2020
Overhaul how window icon loading works Now most of it has been moved out of the backends.
--- a/src/Backends/Platform.h
+++ b/src/Backends/Platform.h
@@ -9,6 +9,7 @@
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);
--- 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,57 +231,45 @@
glfwSetKeyCallback(window, KeyCallback);
glfwSetWindowFocusCallback(window, WindowFocusCallback);
glfwSetWindowSizeCallback(window, WindowSizeCallback);
+}
- // Set up window icon
+BOOL PlatformBackend_GetBasePath(char *string_buffer)
+{
+ return FALSE;
+}
- // 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);
+void PlatformBackend_HideMouse(void)
+{
+ glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
+}
- unsigned int width, height;
- unsigned char *rgb_pixels = DecodeBitmap(resource_data, resource_size, &width, &height);
+void PlatformBackend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int width, unsigned int height)
+{
+ unsigned char *rgba_pixels = (unsigned char*)malloc(width * height * 4);
- if (rgb_pixels != NULL)
- {
- unsigned char *rgba_pixels = (unsigned char*)malloc(width * height * 4);
+ const unsigned char *rgb_pointer = rgb_pixels;
+ unsigned char *rgba_pointer = rgba_pixels;
- unsigned char *rgb_pointer = rgb_pixels;
- unsigned char *rgba_pointer = rgba_pixels;
-
- if (rgba_pixels != NULL)
+ if (rgba_pixels != NULL)
+ {
+ for (unsigned int y = 0; y < height; ++y)
{
- for (unsigned int y = 0; y < height; ++y)
+ for (unsigned int x = 0; x < width; ++x)
{
- for (unsigned int x = 0; x < width; ++x)
- {
- *rgba_pointer++ = *rgb_pointer++;
- *rgba_pointer++ = *rgb_pointer++;
- *rgba_pointer++ = *rgb_pointer++;
- *rgba_pointer++ = 0xFF;
- }
+ *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);
+ GLFWimage glfw_image = {(int)width, (int)height, rgba_pixels};
+ glfwSetWindowIcon(window, 1, &glfw_image);
+
+ free(rgba_pixels);
}
-#endif
}
-BOOL PlatformBackend_GetBasePath(char *string_buffer)
-{
- return FALSE;
-}
-
-void PlatformBackend_HideMouse(void)
-{
- glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
-}
BOOL PlatformBackend_SystemTask(void)
{
--- a/src/Backends/Platform/SDL2.cpp
+++ b/src/Backends/Platform/SDL2.cpp
@@ -42,15 +42,7 @@
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)
@@ -67,6 +59,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)
--- 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"
@@ -276,6 +277,22 @@
#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