From c175d58f03d9e5ff0012075e92f2e2d46b8d9645 Mon Sep 17 00:00:00 2001 From: SimoZ64 Date: Wed, 7 May 2025 16:11:46 +0200 Subject: [PATCH] start infrastructure for SDL window --- src/frontend/CMakeLists.txt | 1 + src/frontend/KaizenGui.cpp | 2 +- src/frontend/KaizenGui.hpp | 4 +++- src/frontend/NativeWindow.hpp | 18 ++++++++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 src/frontend/NativeWindow.hpp diff --git a/src/frontend/CMakeLists.txt b/src/frontend/CMakeLists.txt index 2e84a4f2..e4994391 100644 --- a/src/frontend/CMakeLists.txt +++ b/src/frontend/CMakeLists.txt @@ -129,6 +129,7 @@ add_executable(kaizen JSONUtils.hpp AudioSettings.hpp AudioSettings.cpp + NativeWindow.hpp InputSettings.hpp InputSettings.cpp Debugger.hpp diff --git a/src/frontend/KaizenGui.cpp b/src/frontend/KaizenGui.cpp index 37cdfe83..3cfae399 100644 --- a/src/frontend/KaizenGui.cpp +++ b/src/frontend/KaizenGui.cpp @@ -3,7 +3,7 @@ #include #include -KaizenGui::KaizenGui() noexcept : window(SDL_CreateWindow("Kaizen", 1280, 720, SDL_WINDOW_HIGH_PIXEL_DENSITY | SDL_WINDOW_RESIZABLE | SDL_WINDOW_VULKAN)), core(std::make_shared()), vulkanWidget(core, window), emuThread(core, fpsCounter, vulkanWidget, settingsWindow) { +KaizenGui::KaizenGui() noexcept : window("Kaizen", 1280, 720), core(std::make_shared()), vulkanWidget(core, window.getHandle()), emuThread(core, fpsCounter, vulkanWidget, settingsWindow) { emuExitFunc = [&]() { quit = true; if (emuThread.isRunning) { diff --git a/src/frontend/KaizenGui.hpp b/src/frontend/KaizenGui.hpp index 2273acc9..adc22054 100644 --- a/src/frontend/KaizenGui.hpp +++ b/src/frontend/KaizenGui.hpp @@ -2,11 +2,13 @@ #include #include #include +#include +#include #include #include class KaizenGui final { - std::shared_ptr window; + gui::NativeWindow window; public: explicit KaizenGui() noexcept; double fpsCounter; diff --git a/src/frontend/NativeWindow.hpp b/src/frontend/NativeWindow.hpp new file mode 100644 index 00000000..09684b4d --- /dev/null +++ b/src/frontend/NativeWindow.hpp @@ -0,0 +1,18 @@ +#pragma once +#include +#include +#include + +namespace gui { +struct NativeWindow { + NativeWindow(const std::string& title, int w, int h, int posX = SDL_WINDOWPOS_CENTERED, int posY = SDL_WINDOWPOS_CENTERED) { + SDL_Init(SDL_INIT_VIDEO); + window = std::make_shared(SDL_CreateWindow(title.c_str(), w, h, SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY)); + } + void setTitle(const std::string& v) { title = v; } + const std::shared_ptr& getHandle() { return window; } +private: + std::shared_ptr window; + std::string title; +}; +} \ No newline at end of file