From ac2da6ed4968a60d5004f9d31f3a313212436f97 Mon Sep 17 00:00:00 2001 From: Xphalnos Date: Fri, 20 Jun 2025 22:54:31 +0200 Subject: [PATCH] Configurable Window Size --- core/Base/Config.cpp | 17 +++++++++++++++++ core/Base/Config.h | 4 ++++ core/main.cpp | 5 +++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/core/Base/Config.cpp b/core/Base/Config.cpp index 8d917d5..b9b37ee 100644 --- a/core/Base/Config.cpp +++ b/core/Base/Config.cpp @@ -7,10 +7,22 @@ namespace Config { +static int widthWindow = 640; + +static int heightWindow = 480; + static bool logAdvanced = false; static std::string typeLog = "async"; +int windowWidth() { + return widthWindow; +} + +int windowHeight() { + return heightWindow; +} + bool isLogAdvanced() { return logAdvanced; } @@ -38,6 +50,9 @@ void Load(const std::filesystem::path& path) { if (data.contains("General")) { const toml::value& general = data.at("General"); + widthWindow = toml::find_or(general, "Window Width", 640); + heightWindow = toml::find_or(general, "Window Height", 480); + logAdvanced = toml::find_or(general, "Advanced Log", false); typeLog = toml::find_or(general, "Log Type", "async"); } @@ -61,6 +76,8 @@ void Save(const std::filesystem::path& path) { fmt::print("Saving new configuration file {}\n", path.string()); } + data["General"]["Window Width"] = widthWindow; + data["General"]["Window Height"] = heightWindow; data["General"]["Advanced Log"] = logAdvanced; data["General"]["Log Type"] = typeLog; diff --git a/core/Base/Config.h b/core/Base/Config.h index d6b2bed..624b4e1 100644 --- a/core/Base/Config.h +++ b/core/Base/Config.h @@ -9,6 +9,10 @@ namespace Config { void Load(const std::filesystem::path& path); void Save(const std::filesystem::path& path); +int windowWidth(); + +int windowHeight(); + bool isLogAdvanced(); std::string logType(); diff --git a/core/main.cpp b/core/main.cpp index 060501f..c51a881 100644 --- a/core/main.cpp +++ b/core/main.cpp @@ -7,6 +7,7 @@ #include #include "ARM/cpu.h" +#include "Base/Config.h" #include "JIT/jit.h" SDL_Window *Window{}; @@ -22,8 +23,8 @@ void initSDL3() { SDL_SetStringProperty(props, SDL_PROP_WINDOW_CREATE_TITLE_STRING, "Pound Emulator"); SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_X_NUMBER, SDL_WINDOWPOS_CENTERED); SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_Y_NUMBER, SDL_WINDOWPOS_CENTERED); - SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, /*Config::windowWidth()*/ 800); - SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, /*Config::windowHeight()*/ 600); + SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, Config::windowWidth()); + SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, Config::windowHeight()); // For a new Vulkan support, don't forget to change 'SDL_WINDOW_OPENGL' by 'SDL_WINDOW_VULKAN'. SDL_SetNumberProperty(props, "flags", SDL_WINDOW_OPENGL); SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_RESIZABLE_BOOLEAN, true);