From 7ac29585d69646d3ab3b94f95341241a0b97dbb5 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 31 May 2024 02:23:36 -0500 Subject: [PATCH] [jasper/world/studio] Fix world tile selection to properly release when out of bounds --- .../studio/worldeditor/worldeditor-imgui.cpp | 20 ++++--------------- .../studio/worldeditor/worldeditor-imgui.hpp | 2 +- 2 files changed, 5 insertions(+), 17 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 18aec95..cfb57de 100644 --- a/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.cpp +++ b/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.cpp @@ -72,12 +72,6 @@ constexpr ox::Point fbPtToTileAddr( }; } -[[nodiscard]] -constexpr bool inside(auto const val, int const min, int const max) noexcept { - auto const v = static_cast(val); - return v <= max && v >= min; -}; - WorldEditorImGui::WorldEditorImGui(studio::StudioContext &sctx, ox::StringView path): Editor(path), m_sctx(sctx), @@ -301,7 +295,7 @@ void WorldEditorImGui::drawWorldView() noexcept { std::ignore = ig::dragDropTarget([this, fbPaneScale] { return handleDrop(fbPaneScale); }); - handleMouseSelection(static_cast(ox::Vec2(paneSize)), fbPaneScale); + handleMouseSelection(fbPaneScale); auto const&io = ImGui::GetIO(); if (io.KeyCtrl) { if (io.KeysDown[ImGuiKey_G]) { @@ -316,13 +310,11 @@ void WorldEditorImGui::drawWorldView() noexcept { } } -void WorldEditorImGui::handleMouseSelection(ox::Size const&paneSz, float fbPaneScale) noexcept { +void WorldEditorImGui::handleMouseSelection(float 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] - && inside(fbPos.x, 0, paneSz.width) - && inside(fbPos.y, 0, paneSz.height); + auto const startSel = io.MouseClicked[0] && ImGui::IsItemHovered(); auto const scaledViewSz = static_cast(m_view.drawSize()) * fbPaneScale; m_selTracker.updateCursorPoint(fbPtToTileAddr(fbPos, scaledViewSz), startSel); if (m_selTracker.selectionOngoing()) { @@ -428,11 +420,7 @@ ox::Error WorldEditorImGui::undoStackChanged(studio::UndoCommand const*) { } bool WorldEditorImGui::tileSelected(ox::Point const&pt) const noexcept { - if (!m_selection) { - return false; - } - auto const&sel = *m_selection; - return sel.contains(pt); + return m_selection && m_selection->contains(pt); } void WorldEditorImGui::clearSelection() noexcept { 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 a18af6d..275898c 100644 --- a/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.hpp +++ b/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.hpp @@ -81,7 +81,7 @@ class WorldEditorImGui: public studio::Editor { void drawWorldView() noexcept; - void handleMouseSelection(ox::Size const&paneSz, float fbPaneScale) noexcept; + void handleMouseSelection(float fbPaneScale) noexcept; ox::Error handleDrop(float fbPaneScale) noexcept;