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 56aa416..c54ce03 100644 --- a/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.cpp +++ b/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.cpp @@ -255,12 +255,17 @@ void WorldEditorImGui::handleSelection(ox::Size const&paneSz, float fbPaneScale) && inside(fbPos.x, 0, paneSz.width) && inside(fbPos.y, 0, paneSz.height); auto const scaledViewSz = static_cast(m_view.drawSize()) * fbPaneScale; - m_selection.updateCursorPoint(fbPtToTileAddr(fbPos, scaledViewSz), startSel); - if (m_selection.selectionOngoing()) { - m_view.setSelection(m_selection.selection()); + m_selTracker.updateCursorPoint(fbPtToTileAddr(fbPos, scaledViewSz), startSel); + if (m_selTracker.selectionOngoing()) { + m_selection.emplace(m_selTracker.selection()); + m_view.setSelection(*m_selection); } } else if (io.MouseReleased[0]) { - m_selection.finishSelection(); + m_selTracker.finishSelection(); + } + if (io.KeyCtrl && io.KeysDown[ImGuiKey_G]) { + m_selection.reset(); + m_view.clearSelection(); } } @@ -277,7 +282,7 @@ ox::Error WorldEditorImGui::handleDrop(float fbPaneScale) noexcept { if (tileAddr.x < m_doc.columns && tileAddr.y < m_doc.rows) { ox::Vector mods; if (tileSelected(tileAddr)) { - studio::iterateSelection(m_selection.selection(), [&](int32_t x, int32_t y) { + studio::iterateSelection(*m_selection, [&](int32_t x, int32_t y) { mods.emplace_back(ModifyTilesCommand::Mod{ .layer = m_activeLayer, .tileAddr = {x, y}, @@ -342,7 +347,10 @@ ox::Error WorldEditorImGui::undoStackChanged(studio::UndoCommand const*) { } bool WorldEditorImGui::tileSelected(ox::Point const&pt) const noexcept { - auto const sel = m_selection.selection(); + if (!m_selection) { + return false; + } + auto const&sel = *m_selection; return inside(pt.x, sel.a.x, sel.b.x) && inside(pt.y, sel.a.y, sel.b.y); } 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 b1dabbb..6250652 100644 --- a/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.hpp +++ b/src/jasper/modules/world/src/studio/worldeditor/worldeditor-imgui.hpp @@ -19,7 +19,8 @@ namespace jasper::world { class WorldEditorImGui: public studio::Editor { private: - studio::SelectionTracker m_selection; + studio::SelectionTracker m_selTracker; + ox::Optional m_selection; uint8_t m_activeLayer{}; studio::StudioContext &m_sctx; studio::ig::FilePicker m_objSetPicker{ diff --git a/src/jasper/modules/world/src/studio/worldeditor/worldeditorview.cpp b/src/jasper/modules/world/src/studio/worldeditor/worldeditorview.cpp index 616f7fc..447110d 100644 --- a/src/jasper/modules/world/src/studio/worldeditor/worldeditorview.cpp +++ b/src/jasper/modules/world/src/studio/worldeditor/worldeditorview.cpp @@ -37,12 +37,16 @@ void WorldEditorView::draw(ox::Size const&targetSz) noexcept { m_highlighter.draw(); } -void WorldEditorView::setSelection(studio::Selection const&sel) noexcept { +void WorldEditorView::clearSelection() noexcept { if (m_selection) { studio::iterateSelection(*m_selection, [this](int32_t x, int32_t y) { std::ignore = m_highlighter.setTileHighlight({x, y}, false); }); } +} + +void WorldEditorView::setSelection(studio::Selection const&sel) noexcept { + clearSelection(); m_selection.emplace(sel); studio::iterateSelection(*m_selection, [this](int32_t x, int32_t y) { std::ignore = m_highlighter.setTileHighlight({x, y}, true); diff --git a/src/jasper/modules/world/src/studio/worldeditor/worldeditorview.hpp b/src/jasper/modules/world/src/studio/worldeditor/worldeditorview.hpp index f6eb4eb..1f95db0 100644 --- a/src/jasper/modules/world/src/studio/worldeditor/worldeditorview.hpp +++ b/src/jasper/modules/world/src/studio/worldeditor/worldeditorview.hpp @@ -39,6 +39,8 @@ class WorldEditorView { void draw(ox::Size const&targetSz) noexcept; + void clearSelection() noexcept; + void setSelection(studio::Selection const&sel) noexcept; [[nodiscard]]