From ecf26ef9ed05722e0ade7d3629572de00e15aa73 Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Wed, 19 Jul 2023 11:25:51 -0400 Subject: [PATCH] Fix viewport selection happening if clicked outside of viewport and dragged in --- Editor/src/Windows/EditorInterface.cpp | 12 ++++++++++-- Editor/src/Windows/EditorInterface.h | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 1731eddf..e174f19b 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -79,6 +79,7 @@ namespace Nuake { { ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); std::string name = ICON_FA_GAMEPAD + std::string(" Scene"); + if (ImGui::Begin(name.c_str())) { ImGui::PopStyleVar(); @@ -242,8 +243,11 @@ namespace Nuake { } } - if (m_IsHoveringViewport && Input::IsMouseButtonPressed(GLFW_MOUSE_BUTTON_1) && !ImGuizmo::IsUsing()) + m_IsViewportFocused = ImGui::IsWindowFocused(); + if (m_IsHoveringViewport && Input::IsMouseButtonPressed(GLFW_MOUSE_BUTTON_2) && !ImGuizmo::IsUsing()) { + ImGui::FocusWindow(ImGui::GetCurrentWindow()); + const auto windowPosNuake = Vector2(windowPos.x, windowPos.y); auto& gbuffer = Engine::GetCurrentScene()->mSceneRenderer->GetGBuffer(); auto pixelPos = Input::GetMousePosition() - windowPosNuake; @@ -1513,7 +1517,11 @@ namespace Nuake { } auto& editorCam = Engine::GetCurrentScene()->m_EditorCamera; - editorCam->Update(ts, m_IsHoveringViewport); + + if (m_IsViewportFocused) + { + editorCam->Update(ts, m_IsHoveringViewport); + } const bool entityIsSelected = Selection.Type == EditorSelectionType::Entity && Selection.Entity.IsValid(); if (entityIsSelected && Input::IsKeyPressed(GLFW_KEY_F)) diff --git a/Editor/src/Windows/EditorInterface.h b/Editor/src/Windows/EditorInterface.h index 57f5ac94..740b3a1b 100644 --- a/Editor/src/Windows/EditorInterface.h +++ b/Editor/src/Windows/EditorInterface.h @@ -26,6 +26,8 @@ namespace Nuake bool m_DebugCollisions = true; bool m_ShowOverlay = true; bool m_IsHoveringViewport = false; + bool m_IsViewportFocused = false; + Vector2 m_ViewportPos = {0, 0}; Vector2 m_ViewportSize = {};