From 20722ed0fda422a9ca89957acf3a6902e72d336a Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Mon, 20 Jan 2025 02:12:03 -0600 Subject: [PATCH] [jasper/world/studio] Add input filtering for when popup is open --- .../studio/worldeditor/worldeditor-imgui.cpp | 23 ++++++++----------- .../studio/worldeditor/worldeditor-imgui.hpp | 1 + 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.cpp b/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.cpp index 0d6cc70..d025184 100644 --- a/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.cpp +++ b/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.cpp @@ -91,8 +91,8 @@ WorldEditorImGui::WorldEditorImGui(studio::StudioContext &sctx, ox::StringParam void WorldEditorImGui::draw(studio::StudioContext&) noexcept { auto const paneSize = ImGui::GetContentRegionAvail(); - constexpr auto resourcesWidth = 300.f; { + constexpr auto resourcesWidth = 300.f; ig::ChildStackItem const worldView{"WorldView", {paneSize.x - resourcesWidth, 0}}; drawWorldView(); } @@ -315,12 +315,11 @@ void WorldEditorImGui::drawWorldView() noexcept { return handleDrop(fbPaneScale); }); handleMouseSelection(fbPaneScale); - if (!popupOpen()) { - auto const&io = ImGui::GetIO(); - if (io.KeyCtrl) { - if (io.KeysDown[ImGuiKey_G]) { + if (ig::mainWinHasFocus()) { + if (ImGui::IsKeyDown(ImGuiKey_ModCtrl)) { + if (ImGui::IsKeyPressed(ImGuiKey_G)) { clearSelection(); - } else if (io.KeysDown[ImGuiKey_A]) { + } else if (ImGui::IsKeyPressed(ImGuiKey_A)) { m_selection.emplace(ox::Point{0, 0}, ox::Point{m_doc.columns - 1, m_doc.rows - 1}); m_view.setSelection(*m_selection); setCopyEnabled(true); @@ -332,16 +331,15 @@ void WorldEditorImGui::drawWorldView() noexcept { } void WorldEditorImGui::handleMouseSelection(float const fbPaneScale) noexcept { - auto const&io = ImGui::GetIO(); - if (io.MouseDown[0]) { - auto const fbPos = world::fbPos(ox::Vec2{io.MousePos}); - auto const startSel = io.MouseClicked[0] && ImGui::IsItemHovered(); + if (ImGui::IsMouseDown(0)) { + auto const fbPos = world::fbPos(ox::Vec2{ImGui::GetMousePos()}); + auto const startSel = ImGui::IsMouseClicked(0) && ImGui::IsItemHovered(); auto const scaledViewSz = ox::Vec2{m_view.drawSize()} * fbPaneScale; m_selTracker.updateCursorPoint(fbPtToTileAddr(fbPos, scaledViewSz), startSel); if (m_selTracker.selectionOngoing()) { m_view.setSelection(m_selTracker.selection()); } - } else if (io.MouseReleased[0] && m_selTracker.selectionOngoing()) { + } else if (ImGui::IsMouseReleased(0) && m_selTracker.selectionOngoing()) { m_selTracker.finishSelection(); m_selection.emplace(m_selTracker.selection()); setCopyEnabled(true); @@ -352,8 +350,7 @@ void WorldEditorImGui::handleMouseSelection(float const fbPaneScale) noexcept { ox::Error WorldEditorImGui::handleDrop(float const fbPaneScale) noexcept { OX_REQUIRE(objId, ig::getDragDropPayload("WorldTile")); - auto const&io = ImGui::GetIO(); - auto const fbPos = world::fbPos(ox::Vec2{io.MousePos}); + auto const fbPos = world::fbPos(ox::Vec2{ImGui::GetMousePos()}); auto const viewSz = m_view.drawSize(); auto const tileAddr = fbPtToTileAddr( fbPos, diff --git a/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.hpp b/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.hpp index 008f50a..fbdd408 100644 --- a/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.hpp +++ b/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.hpp @@ -100,6 +100,7 @@ class WorldEditorImGui: public studio::Editor { ox::Error addDependency(ox::FileAddress const&fileAddr) noexcept; + [[nodiscard]] constexpr bool popupOpen() const noexcept { return m_sizeEditor.show; }