ship it squrrel

This commit is contained in:
Richard Ward
2025-12-19 03:29:34 +00:00
parent e771913059
commit c6c7491beb
7 changed files with 45 additions and 35 deletions

View File

@@ -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<float>(mouseX);
guiInputSnapshot_.mouseY = static_cast<float>(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();
}

View File

@@ -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);
}

View File

@@ -13,13 +13,19 @@
#include <stdexcept>
#include <string>
#include <unordered_map>
#include <vector>
#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<RectData> 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<Canvas>()) {}
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<Canvas>()) {}
GuiRenderer::~GuiRenderer() {
DestroyStagingBuffer();

View File

@@ -3,11 +3,12 @@
#include <filesystem>
#include <memory>
#include <unordered_map>
#include <vector>
#include <vulkan/vulkan.h>
#include script/cube_script.hpp
#include "script/cube_script.hpp"
namespace sdl3cpp::gui {

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -22,13 +22,6 @@ struct GuiInputSnapshot {
std::unordered_map<std::string, bool> 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<uint16_t> 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);