Overhaul how window icon loading works

Now most of it has been moved out of the backends.
This commit is contained in:
Clownacy 2020-04-01 21:20:26 +01:00
parent 878cac3b3f
commit f23117bbdc
4 changed files with 54 additions and 50 deletions

View file

@ -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);

View file

@ -12,7 +12,6 @@
#include "../../WindowsWrapper.h"
#include "../../Bitmap.h"
#include "../../KeyControl.h"
#include "../../Main.h"
#include "../../Organya.h"
@ -232,22 +231,23 @@ void PlatformBackend_PostWindowCreation(void)
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);
if (rgb_pixels != NULL)
{
void PlatformBackend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int width, unsigned int height)
{
unsigned char *rgba_pixels = (unsigned char*)malloc(width * height * 4);
unsigned char *rgb_pointer = rgb_pixels;
const unsigned char *rgb_pointer = rgb_pixels;
unsigned char *rgba_pointer = rgba_pixels;
if (rgba_pixels != NULL)
@ -268,21 +268,8 @@ void PlatformBackend_PostWindowCreation(void)
free(rgba_pixels);
}
FreeBitmap(rgb_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)
{

View file

@ -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)

View file

@ -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;