From 2f0c9ad012fa733caa450ce2b1840a2cfa7e7c0e Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Sat, 29 Mar 2025 16:46:57 +0100 Subject: [PATCH] make quit button useful --- include/PhGui.h | 2 +- src/PhGui.cpp | 17 ++++++++++++----- src/main.cpp | 5 ++++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/include/PhGui.h b/include/PhGui.h index 5a9bd3d..e3aa1e4 100644 --- a/include/PhGui.h +++ b/include/PhGui.h @@ -3,7 +3,7 @@ namespace ph { namespace gui { -void Render(); +bool Render(); void Init(); } // namespace gui diff --git a/src/PhGui.cpp b/src/PhGui.cpp index c088c07..a093212 100644 --- a/src/PhGui.cpp +++ b/src/PhGui.cpp @@ -107,24 +107,29 @@ static void RenderGameWindow() { }) } -static void RenderMainWindow() { +static bool RenderMainWindow() { if (ImGui::Button("Nouvelle Partie")) { InGame = true; Right = true; } if (ImGui::Button("Quitter")) { - // TODO + return false; } + return true; } -void Render() { +bool Render() { ImGuiIO& io = ImGui::GetIO(); ImGui::SetNextWindowPos(ImVec2(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f), ImGuiCond_Always, ImVec2(0.5f, 0.5f)); ImGui::Begin("MainWindow", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoDecoration); if (InGame) RenderGameWindow(); - else - RenderMainWindow(); + else { + if (!RenderMainWindow()) { + ImGui::End(); + return false; + } + } if (Cooldown > 0.0f) { ImGui::NewLine(); @@ -139,6 +144,8 @@ void Render() { #ifndef NDEBUG ImGui::ShowDemoWindow(); #endif + + return true; } void Init() {} diff --git a/src/main.cpp b/src/main.cpp index 2114d79..c0cc0e4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -146,7 +146,10 @@ int main(int, char**) { ImGui_ImplSDL2_NewFrame(); ImGui::NewFrame(); - ph::gui::Render(); + if (!done && !ph::gui::Render()) { + done = true; + } + // Rendering ImGui::Render();