Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2024-03-14 21:17:05 +1100
committerKae <80987908+Novaenia@users.noreply.github.com>2024-03-14 21:17:05 +1100
commit8164e5ae6fa33c9ec2a14f107585a7cbe7fbf813 (patch)
tree07506664de68caa581dd55b8d65b6ee22887373f
parent353406780181feffaa4836d387db4f7337ce6cce (diff)
Game window respects Windows theme setting
-rw-r--r--source/application/StarMainApplication_sdl.cpp26
-rw-r--r--source/rendering/StarWorldCamera.hpp8
2 files changed, 29 insertions, 5 deletions
diff --git a/source/application/StarMainApplication_sdl.cpp b/source/application/StarMainApplication_sdl.cpp
index 2130968..7b1601f 100644
--- a/source/application/StarMainApplication_sdl.cpp
+++ b/source/application/StarMainApplication_sdl.cpp
@@ -10,6 +10,11 @@
#include "SDL2/SDL.h"
#include "StarPlatformServices_pc.hpp"
+#ifdef STAR_SYSTEM_WINDOWS
+#include "SDL2/SDL_syswm.h"
+#include <dwmapi.h>
+#endif
+
namespace Star {
Maybe<Key> keyFromSdlKeyCode(SDL_Keycode sym) {
@@ -268,11 +273,30 @@ public:
m_sdlWindow = SDL_CreateWindow(m_windowTitle.utf8Ptr(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
m_windowSize[0], m_windowSize[1], SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
if (!m_sdlWindow)
- throw ApplicationException::format("Application: Could not create SDL window: {}", SDL_GetError());
+ throw ApplicationException::format("Application: Could not create SDL Window: {}", SDL_GetError());
SDL_ShowWindow(m_sdlWindow);
SDL_RaiseWindow(m_sdlWindow);
+// Makes the window border black. From https://github.com/libsdl-org/SDL/commit/89948787#diff-f2ae5c36a8afc0a9a343a6664ab306da2963213e180af8cd97b12397dcbb9ae7R1478
+#ifdef STAR_SYSTEM_WINDOWS
+ if (void* handle = SDL_LoadObject("dwmapi.dll")) {
+ if (auto DwmSetWindowAttributeFunc = (decltype(&DwmSetWindowAttribute))SDL_LoadFunction(handle, "DwmSetWindowAttribute")) {
+ SDL_SysWMinfo wmInfo{};
+ SDL_VERSION(&wmInfo.version);
+ SDL_GetWindowWMInfo(m_sdlWindow, &wmInfo);
+ DWORD type{}, value{}, count = sizeof(value);
+ LSTATUS status = RegGetValue(HKEY_CURRENT_USER,
+ TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"),
+ TEXT("AppsUseLightTheme"),
+ RRF_RT_REG_DWORD, &type, &value, &count);
+ BOOL enabled = status == ERROR_SUCCESS && type == REG_DWORD && value == 0;
+ DwmSetWindowAttributeFunc(wmInfo.info.win.window, DWMWA_USE_IMMERSIVE_DARK_MODE, &enabled, sizeof(enabled));
+ }
+ SDL_UnloadObject(handle);
+ }
+#endif
+
int width;
int height;
SDL_GetWindowSize(m_sdlWindow, &width, &height);
diff --git a/source/rendering/StarWorldCamera.hpp b/source/rendering/StarWorldCamera.hpp
index d83a31a..e022560 100644
--- a/source/rendering/StarWorldCamera.hpp
+++ b/source/rendering/StarWorldCamera.hpp
@@ -88,15 +88,15 @@ inline Vec2F WorldCamera::centerWorldPosition() const {
inline Vec2F WorldCamera::worldToScreen(Vec2F const& worldCoord) const {
Vec2F wrappedCoord = m_worldGeometry.nearestTo(Vec2F(m_worldCenter), worldCoord);
return Vec2F(
- (wrappedCoord[0] - m_worldCenter[0]) * (TilePixels * m_pixelRatio) + m_screenSize[0] / 2.0,
- (wrappedCoord[1] - m_worldCenter[1]) * (TilePixels * m_pixelRatio) + m_screenSize[1] / 2.0
+ (wrappedCoord[0] - m_worldCenter[0]) * (TilePixels * m_pixelRatio) + (float)m_screenSize[0] / 2.0,
+ (wrappedCoord[1] - m_worldCenter[1]) * (TilePixels * m_pixelRatio) + (float)m_screenSize[1] / 2.0
);
}
inline Vec2F WorldCamera::screenToWorld(Vec2F const& screen) const {
return Vec2F(
- (screen[0] - m_screenSize[0] / 2.0) / (TilePixels * m_pixelRatio) + m_worldCenter[0],
- (screen[1] - m_screenSize[1] / 2.0) / (TilePixels * m_pixelRatio) + m_worldCenter[1]
+ (screen[0] - (float)m_screenSize[0] / 2.0) / (TilePixels * m_pixelRatio) + m_worldCenter[0],
+ (screen[1] - (float)m_screenSize[1] / 2.0) / (TilePixels * m_pixelRatio) + m_worldCenter[1]
);
}