From 2152a73cce84e84a49e52d718d1169c7a93933fb Mon Sep 17 00:00:00 2001 From: irisz64 Date: Fri, 23 May 2025 15:57:49 +0200 Subject: [PATCH] More GUI work --- src/frontend/ImGuiImpl/Menu.hpp | 5 +++++ src/frontend/KaizenGui.cpp | 20 ++++++++++++++++++-- src/frontend/KaizenGui.hpp | 2 +- src/frontend/SettingsWindow.cpp | 3 ++- src/frontend/SettingsWindow.hpp | 2 +- 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/frontend/ImGuiImpl/Menu.hpp b/src/frontend/ImGuiImpl/Menu.hpp index e85d4146..9c68ee84 100644 --- a/src/frontend/ImGuiImpl/Menu.hpp +++ b/src/frontend/ImGuiImpl/Menu.hpp @@ -19,6 +19,11 @@ struct MenuItem { return ret; } + void setLabel(const std::string& label) { this->label = label; } + const std::string& getLabel() { return label; } + + void setFunc(std::function&& func) { exec = func; } + void setEnabled(bool v) { enabled = v; } private: bool enabled = true; diff --git a/src/frontend/KaizenGui.cpp b/src/frontend/KaizenGui.cpp index fc787352..feafbfad 100644 --- a/src/frontend/KaizenGui.cpp +++ b/src/frontend/KaizenGui.cpp @@ -7,6 +7,22 @@ KaizenGui::KaizenGui() noexcept : window("Kaizen", 800, 600), core(std::make_shared()), vulkanWidget(core, window.getHandle()), emuThread(core, fpsCounter, vulkanWidget, settingsWindow) { gui::Initialize(core->parallel.wsi, window.getHandle()); + actionPause.setFunc([&]() { + if(ImGui::IsItemClicked()) { + actionPause.setLabel(actionPause.getLabel() == "Pause" ? "Resume" : "Pause"); + core->TogglePause(); + } + }); + + actionStop.setFunc([&]() { + if(ImGui::IsItemClicked()) { + actionStop.setEnabled(false); + actionPause.setEnabled(false); + actionReset.setEnabled(false); + core->Stop(); + } + }); + emuExitFunc = [&]() { quit = true; if (emuThread.isRunning) { @@ -68,10 +84,10 @@ KaizenGui::KaizenGui() noexcept : window("Kaizen", 800, 600), core(std::make_sha void KaizenGui::RenderUI() { gui::StartFrame(); - menuBar.render(); - about.render(); statusBar.render(); + menuBar.render(); settingsWindow.render(); + about.render(); gui::EndFrame(); if (core->render) { diff --git a/src/frontend/KaizenGui.hpp b/src/frontend/KaizenGui.hpp index 1a8d4a1a..8ded172e 100644 --- a/src/frontend/KaizenGui.hpp +++ b/src/frontend/KaizenGui.hpp @@ -13,7 +13,7 @@ public: explicit KaizenGui() noexcept; double fpsCounter = -1.0; gui::MenuBar menuBar; - gui::MenuItem actionPause{"Pause"}, actionStop{"Stop"}, actionReset{"Reset"}; + gui::MenuItem actionPause{"Pause", nullptr, false}, actionStop{"Stop", nullptr, false}, actionReset{"Reset", nullptr, false}; SettingsWindow settingsWindow; std::shared_ptr core; RenderWidget vulkanWidget; diff --git a/src/frontend/SettingsWindow.cpp b/src/frontend/SettingsWindow.cpp index f7bd3e6f..60d0a3ae 100644 --- a/src/frontend/SettingsWindow.cpp +++ b/src/frontend/SettingsWindow.cpp @@ -68,7 +68,8 @@ SettingsWindow::SettingsWindow() : settings{JSONOpenOrCreate("resources/settings ImGui::SameLine(); - if(cancel.render()) { + if(ImGui::Button("Cancel")) { + popup.setOpened(false); ImGui::CloseCurrentPopup(); } }); diff --git a/src/frontend/SettingsWindow.hpp b/src/frontend/SettingsWindow.hpp index 22dbe12f..e5917416 100644 --- a/src/frontend/SettingsWindow.hpp +++ b/src/frontend/SettingsWindow.hpp @@ -8,7 +8,7 @@ #include class SettingsWindow final { - gui::PushButton cancel{"Cancel"}, apply{"Apply", "", false}, savesFolder{"Open", "Save path: {}"}; + gui::PushButton apply{"Apply", "", false}, savesFolder{"Open", "Save path: {}"}; nlohmann::json settings; CPUSettings cpuSettings{settings}; AudioSettings audioSettings{settings};