Update window icon dynamically for Werehog

This commit is contained in:
Hyper
2024-11-10 22:47:11 +00:00
parent f1d633c8a5
commit 4d9e835c88
11 changed files with 58 additions and 780 deletions
+7
View File
@@ -106,6 +106,13 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
break;
}
case SDL_USER_EVILSONIC:
{
Window::s_isIconNight = event->user.code;
Window::SetIcon(Window::s_isIconNight);
break;
}
}
for (auto listener : Window::s_eventListeners)
+18 -4
View File
@@ -1,6 +1,7 @@
#pragma once
#include "res/icon.h"
#include "res/icon_night.h"
#include "ui/window_events.h"
#include "config.h"
@@ -21,12 +22,13 @@ public:
inline static int s_height = DEFAULT_HEIGHT;
inline static bool s_isFocused;
inline static bool s_isIconNight;
inline static std::vector<SDLEventListener*> s_eventListeners;
static SDL_Surface* GetIconSurface(void* pIconBmp = nullptr, size_t iconSize = 0)
static SDL_Surface* GetIconSurface(void* pIconBmp, size_t iconSize)
{
auto rw = SDL_RWFromMem(pIconBmp ? pIconBmp : (void*)g_icon, pIconBmp ? iconSize : g_icon_size);
auto rw = SDL_RWFromMem(pIconBmp, iconSize);
auto surface = SDL_LoadBMP_RW(rw, 1);
if (!surface)
@@ -35,7 +37,7 @@ public:
return surface;
}
static void SetIcon(void* pIconBmp = nullptr, size_t iconSize = 0)
static void SetIcon(void* pIconBmp, size_t iconSize)
{
if (auto icon = GetIconSurface(pIconBmp, iconSize))
{
@@ -44,6 +46,18 @@ public:
}
}
static void SetIcon(bool isNight = false)
{
if (isNight)
{
SetIcon((void*)g_iconNight, g_iconNight_size);
}
else
{
SetIcon((void*)g_icon, g_icon_size);
}
}
static void SetTitle(const char* title = nullptr)
{
if (!title)
@@ -72,7 +86,7 @@ public:
{
SDL_SetWindowFullscreen(s_pWindow, 0);
SDL_ShowCursor(SDL_ENABLE);
SetIcon();
SetIcon(Window::s_isIconNight);
}
return isEnabled;
+11
View File
@@ -3,6 +3,8 @@
#include <SDL.h>
#include "ui/window.h"
#define SDL_USER_EVILSONIC (SDL_USEREVENT + 1)
inline static void SDL_ResizeEvent(SDL_Window* pWindow, int width, int height)
{
SDL_Event event{};
@@ -26,3 +28,12 @@ inline static void SDL_MoveEvent(SDL_Window* pWindow, int x, int y)
SDL_PushEvent(&event);
}
inline static void SDL_User_EvilSonic(SDL_Window* pWindow, bool isCtor)
{
SDL_Event event{};
event.type = SDL_USER_EVILSONIC;
event.user.code = isCtor;
SDL_PushEvent(&event);
}