Overhaul how window icon loading works
Now most of it has been moved out of the backends.
This commit is contained in:
parent
878cac3b3f
commit
f23117bbdc
4 changed files with 54 additions and 50 deletions
|
@ -9,6 +9,7 @@ void PlatformBackend_Deinit(void);
|
||||||
void PlatformBackend_PostWindowCreation(void);
|
void PlatformBackend_PostWindowCreation(void);
|
||||||
BOOL PlatformBackend_GetBasePath(char *string_buffer);
|
BOOL PlatformBackend_GetBasePath(char *string_buffer);
|
||||||
void PlatformBackend_HideMouse(void);
|
void PlatformBackend_HideMouse(void);
|
||||||
|
void PlatformBackend_SetWindowIcon(const unsigned char *rgb_pixels, unsigned int width, unsigned int height);
|
||||||
BOOL PlatformBackend_SystemTask(void);
|
BOOL PlatformBackend_SystemTask(void);
|
||||||
void PlatformBackend_ShowMessageBox(const char *title, const char *message);
|
void PlatformBackend_ShowMessageBox(const char *title, const char *message);
|
||||||
unsigned long PlatformBackend_GetTicks(void);
|
unsigned long PlatformBackend_GetTicks(void);
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
|
|
||||||
#include "../../WindowsWrapper.h"
|
#include "../../WindowsWrapper.h"
|
||||||
|
|
||||||
#include "../../Bitmap.h"
|
|
||||||
#include "../../KeyControl.h"
|
#include "../../KeyControl.h"
|
||||||
#include "../../Main.h"
|
#include "../../Main.h"
|
||||||
#include "../../Organya.h"
|
#include "../../Organya.h"
|
||||||
|
@ -232,46 +231,6 @@ void PlatformBackend_PostWindowCreation(void)
|
||||||
glfwSetKeyCallback(window, KeyCallback);
|
glfwSetKeyCallback(window, KeyCallback);
|
||||||
glfwSetWindowFocusCallback(window, WindowFocusCallback);
|
glfwSetWindowFocusCallback(window, WindowFocusCallback);
|
||||||
glfwSetWindowSizeCallback(window, WindowSizeCallback);
|
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)
|
BOOL PlatformBackend_GetBasePath(char *string_buffer)
|
||||||
|
@ -284,6 +243,34 @@ void PlatformBackend_HideMouse(void)
|
||||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
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)
|
BOOL PlatformBackend_SystemTask(void)
|
||||||
{
|
{
|
||||||
if (glfwWindowShouldClose(window))
|
if (glfwWindowShouldClose(window))
|
||||||
|
|
|
@ -42,15 +42,7 @@ void PlatformBackend_Deinit(void)
|
||||||
|
|
||||||
void PlatformBackend_PostWindowCreation(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)
|
BOOL PlatformBackend_GetBasePath(char *string_buffer)
|
||||||
|
@ -69,6 +61,13 @@ void PlatformBackend_HideMouse(void)
|
||||||
SDL_ShowCursor(SDL_DISABLE);
|
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)
|
BOOL PlatformBackend_SystemTask(void)
|
||||||
{
|
{
|
||||||
while (SDL_PollEvent(NULL) || !bActive)
|
while (SDL_PollEvent(NULL) || !bActive)
|
||||||
|
|
17
src/Main.cpp
17
src/Main.cpp
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include "Backends/Platform.h"
|
#include "Backends/Platform.h"
|
||||||
#include "Backends/Rendering.h"
|
#include "Backends/Rendering.h"
|
||||||
|
#include "Bitmap.h"
|
||||||
#include "CommonDefines.h"
|
#include "CommonDefines.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "Draw.h"
|
#include "Draw.h"
|
||||||
|
@ -277,6 +278,22 @@ int main(int argc, char *argv[])
|
||||||
#ifdef DEBUG_SAVE
|
#ifdef DEBUG_SAVE
|
||||||
//SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
|
//SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
|
||||||
#endif
|
#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
|
// Set up the cursor
|
||||||
size_t resource_size;
|
size_t resource_size;
|
||||||
|
|
Loading…
Add table
Reference in a new issue