diff --git a/src/app/sdl3_app_core.cpp b/src/app/sdl3_app_core.cpp index ba950d1..278bd64 100644 --- a/src/app/sdl3_app_core.cpp +++ b/src/app/sdl3_app_core.cpp @@ -36,7 +36,7 @@ void Sdl3App::InitSDL() { if (!window_) { throw std::runtime_error(std::string("SDL_CreateWindow failed: ") + SDL_GetError()); } - SDL_StartTextInput(); + SDL_StartTextInput(window_); } void Sdl3App::InitVulkan() { @@ -74,11 +74,11 @@ void Sdl3App::MainLoop() { } if (guiHasCommands_) { - int mouseX = 0; - int mouseY = 0; + float mouseX = 0.0f; + float mouseY = 0.0f; SDL_GetMouseState(&mouseX, &mouseY); - guiInputSnapshot_.mouseX = static_cast(mouseX); - guiInputSnapshot_.mouseY = static_cast(mouseY); + guiInputSnapshot_.mouseX = mouseX; + guiInputSnapshot_.mouseY = mouseY; cubeScript_.UpdateGuiInput(guiInputSnapshot_); if (guiRenderer_) { guiCommands_ = cubeScript_.LoadGuiCommands(); @@ -116,7 +116,7 @@ void Sdl3App::Cleanup() { window_ = nullptr; } SDL_Vulkan_UnloadLibrary(); - SDL_StopTextInput(); + SDL_StopTextInput(window_); SDL_Quit(); } diff --git a/src/app/sdl3_app_render.cpp b/src/app/sdl3_app_render.cpp index 8900d8f..7e08d2c 100644 --- a/src/app/sdl3_app_render.cpp +++ b/src/app/sdl3_app_render.cpp @@ -101,7 +101,8 @@ void Sdl3App::ProcessGuiEvent(const SDL_Event& event) { break; case SDL_EVENT_KEY_DOWN: case SDL_EVENT_KEY_UP: { - auto it = kGuiKeyNames.find(event.key.keysym.sym); + SDL_Keycode key = event.key.key; + auto it = kGuiKeyNames.find(key); if (it != kGuiKeyNames.end()) { guiInputSnapshot_.keyStates[it->second] = (event.type == SDL_EVENT_KEY_DOWN); } diff --git a/src/gui/gui_renderer.cpp b/src/gui/gui_renderer.cpp index a1f0f76..38c319b 100644 --- a/src/gui/gui_renderer.cpp +++ b/src/gui/gui_renderer.cpp @@ -13,13 +13,19 @@ #include #include #include +#include #include "../../third_party/font8x8_basic.h" namespace script = sdl3cpp::script; +namespace vulkan = sdl3cpp::app::vulkan; +namespace sdl3cpp::gui { namespace { +using ParsedSvg = sdl3cpp::gui::ParsedSvg; +using SvgCircle = sdl3cpp::gui::SvgCircle; + bool ExtractAttribute(const std::string& source, const char* name, std::string& outValue) { std::string key = name; size_t pos = source.find(key); @@ -155,7 +161,9 @@ int ClampToRange(int value, int minimum, int maximum) { return std::min(std::max(value, minimum), maximum); } -class Canvas { +} // namespace + +class GuiRenderer::Canvas { public: using RectData = script::CubeScript::GuiCommand::RectData; @@ -342,16 +350,13 @@ private: std::vector clipStack_; }; -} // namespace - -namespace sdl3cpp::gui { - GuiRenderer::GuiRenderer(VkDevice device, VkPhysicalDevice physicalDevice, VkFormat swapchainFormat, - const std::filesystem::path& scriptDirectory) - : device_(device), - physicalDevice_(physicalDevice), - swapchainFormat_(swapchainFormat), - scriptDirectory_(scriptDirectory), - canvas_(std::make_unique()) {} +GuiRenderer::GuiRenderer(VkDevice device, VkPhysicalDevice physicalDevice, VkFormat swapchainFormat, + const std::filesystem::path& scriptDirectory) + : device_(device), + physicalDevice_(physicalDevice), + swapchainFormat_(swapchainFormat), + scriptDirectory_(scriptDirectory), + canvas_(std::make_unique()) {} GuiRenderer::~GuiRenderer() { DestroyStagingBuffer(); diff --git a/src/gui/gui_renderer.hpp b/src/gui/gui_renderer.hpp index 844c448..c5c9d4d 100644 --- a/src/gui/gui_renderer.hpp +++ b/src/gui/gui_renderer.hpp @@ -3,11 +3,12 @@ #include #include +#include #include #include -#include script/cube_script.hpp +#include "script/cube_script.hpp" namespace sdl3cpp::gui { diff --git a/src/main.cpp b/src/main.cpp index 3003b19..d08d217 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -144,16 +144,22 @@ AppOptions ParseCommandLine(int argc, char** argv) { app.add_option("-s,--create-seed-json", seedOutputText, "Write a template runtime JSON file"); auto* setDefaultJsonOption = app.add_option( - "--set-default-json [PATH]", setDefaultJsonPath, + "-d,--set-default-json", setDefaultJsonPath, "Persist the runtime JSON to the platform default location (XDG/APPDATA); " - "optionally pass PATH to copy that JSON"); + "provide PATH to copy that JSON instead of using the default contents"); setDefaultJsonOption->type_name("PATH"); - setDefaultJsonOption->type_size(0, 1); + setDefaultJsonOption->type_size(1, 1); + setDefaultJsonOption->expected(0, 1); try { app.parse(argc, argv); - } catch (const CLI::ParseError& e) { + } catch (const CLI::CallForHelp& e) { std::exit(app.exit(e)); + } catch (const CLI::CallForVersion& e) { + std::exit(app.exit(e)); + } catch (const CLI::ParseError& e) { + app.exit(e); + throw; } bool shouldSaveDefault = setDefaultJsonOption->count() > 0; diff --git a/src/script/cube_script.cpp b/src/script/cube_script.cpp index 2b2d621..58ddb28 100644 --- a/src/script/cube_script.cpp +++ b/src/script/cube_script.cpp @@ -495,8 +495,8 @@ std::filesystem::path CubeScript::GetScriptDirectory() const { return scriptDirectory_; } -GuiRect CubeScript::ReadRect(lua_State* L, int index) { - GuiRect rect{}; +CubeScript::GuiCommand::RectData CubeScript::ReadRect(lua_State* L, int index) { + GuiCommand::RectData rect{}; if (!lua_istable(L, index)) { return rect; } diff --git a/src/script/cube_script.hpp b/src/script/cube_script.hpp index 7a0d9e0..b178336 100644 --- a/src/script/cube_script.hpp +++ b/src/script/cube_script.hpp @@ -22,13 +22,6 @@ struct GuiInputSnapshot { std::unordered_map keyStates; }; -struct GuiRect { - float x = 0; - float y = 0; - float width = 0; - float height = 0; -}; - struct GuiColor { float r = 0; float g = 0; @@ -61,8 +54,8 @@ struct GuiCommand { RectData clipRect{}; std::string text; float fontSize = 16.0f; - std::string alignX = \"left\"; - std::string alignY = \"center\"; + std::string alignX = "left"; + std::string alignY = "center"; std::string svgPath; GuiColor svgTint; RectData bounds{}; @@ -70,6 +63,10 @@ struct GuiCommand { }; class CubeScript { +public: + using GuiCommand = ::sdl3cpp::script::GuiCommand; + using GuiColor = ::sdl3cpp::script::GuiColor; + public: explicit CubeScript(const std::filesystem::path& scriptPath); ~CubeScript(); @@ -102,7 +99,7 @@ private: static std::vector ReadIndexArray(lua_State* L, int index); static std::string LuaErrorMessage(lua_State* L); static ShaderPaths ReadShaderPathsTable(lua_State* L, int index); - static GuiRect ReadRect(lua_State* L, int index); + static GuiCommand::RectData ReadRect(lua_State* L, int index); static GuiColor ReadColor(lua_State* L, int index, const GuiColor& defaultColor); static bool ReadStringField(lua_State* L, int index, const char* name, std::string& outString);