From 3759be86a170a2d96d769c353097500d752f2b23 Mon Sep 17 00:00:00 2001 From: SimoZ64 Date: Tue, 6 May 2025 14:12:35 +0200 Subject: [PATCH] smaller imgui impl improvements --- src/frontend/ImGuiImpl/PopupWindow.hpp | 8 ++++++-- src/frontend/ImGuiImpl/StatusBar.hpp | 2 ++ src/frontend/KaizenGui.cpp | 27 +++++++++++++++----------- src/frontend/KaizenGui.hpp | 3 ++- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/frontend/ImGuiImpl/PopupWindow.hpp b/src/frontend/ImGuiImpl/PopupWindow.hpp index 071b2e70..24654f3c 100644 --- a/src/frontend/ImGuiImpl/PopupWindow.hpp +++ b/src/frontend/ImGuiImpl/PopupWindow.hpp @@ -4,12 +4,16 @@ namespace gui { struct PopupWindow { - PopupWindow(const std::string& title, std::function&& func = nullptr, bool opened = true) : title(title), exec(func), opened(opened) {} + PopupWindow(const std::string& title, std::function&& func = nullptr, bool opened = false) : title(title), exec(func), opened(opened) {} void setFunc(std::function&& func) { exec = func; } + void setOpened(bool v) { opened = true; } + bool render() { + if(!opened) + return false; ImGui::OpenPopup(title.c_str()); ImVec2 center = ImGui::GetMainViewport()->GetCenter(); ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f)); @@ -28,6 +32,6 @@ struct PopupWindow { private: std::function exec; std::string title; - bool opened = true; + bool opened = false; }; } \ No newline at end of file diff --git a/src/frontend/ImGuiImpl/StatusBar.hpp b/src/frontend/ImGuiImpl/StatusBar.hpp index a95b83e3..778fb5ab 100644 --- a/src/frontend/ImGuiImpl/StatusBar.hpp +++ b/src/frontend/ImGuiImpl/StatusBar.hpp @@ -5,6 +5,8 @@ namespace gui { struct StatusBar { StatusBar(std::function&& func = nullptr, bool enabled = true) : exec(func), enabled(enabled) {} + void setFunc(std::function&& func) { exec = func; } + bool render() { float statusWindowHeight = ImGui::GetFrameHeight() * 1.4f; ImGuiViewport* viewport = ImGui::GetMainViewport(); diff --git a/src/frontend/KaizenGui.cpp b/src/frontend/KaizenGui.cpp index 90b6ce94..37cdfe83 100644 --- a/src/frontend/KaizenGui.cpp +++ b/src/frontend/KaizenGui.cpp @@ -12,6 +12,20 @@ KaizenGui::KaizenGui() noexcept : window(SDL_CreateWindow("Kaizen", 1280, 720, S } }; + about.setFunc([&]() { + ImGui::Text("Kaizen is a Nintendo 64 emulator that strives"); + ImGui::Text("to offer a friendly user experience and compatibility."); + ImGui::Text("Kaizen is licensed under the BSD 3-clause license."); + ImGui::Text("Nintendo 64 is a registered trademarks of Nintendo Co., Ltd."); + if(ImGui::Button("OK")) { + about.setOpened(false); + } + }); + + statusBar.setFunc([&]() { + ImGui::Text("GUI FPS: %.2f, Emulation FPS: %.2f", ImGui::GetIO().Framerate, fpsCounter); + }); + menuBar.addMenu({"File", { {"Open", [&]() { @@ -43,12 +57,7 @@ KaizenGui::KaizenGui() noexcept : window(SDL_CreateWindow("Kaizen", 1280, 720, S menuBar.addMenu({"Help", { {"About", [&]() { - gui::PopupWindow about{"About Kaizen", [&]() { - ImGui::Text("Kaizen is a Nintendo 64 emulator that strives"); - ImGui::Text("to offer a friendly user experience and compatibility."); - ImGui::Text("Kaizen is licensed under the BSD 3-clause license."); - ImGui::Text("Nintendo 64 is a registered trademarks of Nintendo Co., Ltd."); - }}; + about.setOpened(true); }}, } }); @@ -81,11 +90,7 @@ int KaizenGui::run() { menuBar.render(); - // TODO VULKAN CANVAS - - gui::StatusBar statusBar{[&]() { - ImGui::Text("GUI FPS: %.2f, Emulation FPS: %.2f", ImGui::GetIO().Framerate, fpsCounter); - }}; + about.render(); statusBar.render(); } diff --git a/src/frontend/KaizenGui.hpp b/src/frontend/KaizenGui.hpp index 8e4691d2..2273acc9 100644 --- a/src/frontend/KaizenGui.hpp +++ b/src/frontend/KaizenGui.hpp @@ -24,6 +24,7 @@ private: bool quit = false; void handleEvents(); std::function emuExitFunc; - + gui::PopupWindow about{"About Kaizen"}; + gui::StatusBar statusBar{}; bool textPauseToggle = false; };