From d8b469ef9cb76c76579e40e5383b51703003cada Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Tue, 24 Oct 2023 02:14:13 -0400 Subject: [PATCH] Added pause button --- Editor/src/Windows/EditorInterface.cpp | 56 +++++++++++++++++++++++--- Nuake/src/Core/Input.cpp | 8 +--- 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 4d321b16..0fdae187 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -111,15 +111,30 @@ namespace Nuake { float needed = half - used; ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(2, 2)); - if (ImGui::Button(ICON_FA_PLAY, ImVec2(30, 30)) || (Input::IsKeyPressed(GLFW_KEY_F5) && !Engine::IsPlayMode())) + ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(0, 0, 0, 0)); + + if (Engine::IsPlayMode()) { - SceneSnapshot = Engine::GetCurrentScene()->Copy(); - Engine::EnterPlayMode(); + if (ImGui::Button(ICON_FA_PAUSE, ImVec2(30, 30)) || (Input::IsKeyReleased(GLFW_KEY_F5))) + { + Engine::ExitPlayMode(); + + Engine::LoadScene(SceneSnapshot); + Selection = EditorSelection(); + } + } + else + { + if (ImGui::Button(ICON_FA_PLAY, ImVec2(30, 30)) || (Input::IsKeyReleased(GLFW_KEY_F5))) + { + Engine::LoadScene(SceneSnapshot); + Selection = EditorSelection(); + } } ImGui::SameLine(); - if ((ImGui::Button(ICON_FA_STOP, ImVec2(30, 30)) || Input::IsKeyPressed(GLFW_KEY_F8)) && Engine::IsPlayMode()) + if ((ImGui::Button(ICON_FA_STOP, ImVec2(30, 30)) || Input::IsKeyReleased(GLFW_KEY_F8)) && Engine::IsPlayMode()) { Engine::ExitPlayMode(); @@ -127,9 +142,40 @@ namespace Nuake { Selection = EditorSelection(); } + + //if (ImGui::Button(ICON_FA_PLAY, ImVec2(30, 30)) || (Input::IsKeyPressed(GLFW_KEY_F5) && !Engine::IsPlayMode())) + //{ + // SceneSnapshot = Engine::GetCurrentScene()->Copy(); + // Engine::EnterPlayMode(); + //} + // + //ImGui::SameLine(); + // + //if ((ImGui::Button(ICON_FA_STOP, ImVec2(30, 30)) || Input::IsKeyPressed(GLFW_KEY_F8)) && Engine::IsPlayMode()) + //{ + // Engine::ExitPlayMode(); + // + // Engine::LoadScene(SceneSnapshot); + // Selection = EditorSelection(); + //} ImGui::SameLine(); - ImGui::Dummy(ImVec2(ImGui::GetContentRegionAvail().x - 120, 30)); + ImGui::PopStyleColor(); + + float lineHeight = 130.0f; + float separatorHeight = lineHeight * 8.0f; + float separatorThickness = 1.0f; + + ImVec2 curPos = ImGui::GetCursorPos(); + ImVec2 min = ImVec2(curPos.x - separatorThickness, curPos.y - separatorHeight); + ImVec2 max = ImVec2(curPos.x + separatorThickness, curPos.y - separatorHeight); + ImGui::GetWindowDrawList()->AddRectFilled(min, max, IM_COL32(255, 255, 255, 32), 2.0f); + + ImGui::SameLine(); + + const int sizeofRightPart = 160; + + ImGui::Dummy(ImVec2(ImGui::GetContentRegionAvail().x - sizeofRightPart, 30)); ImGui::SameLine(); diff --git a/Nuake/src/Core/Input.cpp b/Nuake/src/Core/Input.cpp index a01e7a1c..a007acc5 100644 --- a/Nuake/src/Core/Input.cpp +++ b/Nuake/src/Core/Input.cpp @@ -60,15 +60,11 @@ namespace Nuake bool result = state == GLFW_RELEASE; // First time pressed? - if (m_Keys.find(keycode) == m_Keys.end()) - return result; - - if (result && m_Keys[keycode] == true) + if (m_Keys.find(keycode) != m_Keys.end()) { - return true; + return result && m_Keys[keycode] == true; } - return false; } #pragma endregion