From b4798fd2ab628804fd7798c1e36e425f2aa33806 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 5 Feb 2025 01:54:41 -0600 Subject: [PATCH] [nostalgia/gfx/studio/tilesheet] Make rotate only available for square subsheets or selections --- .../tilesheeteditor/tilesheeteditor-imgui.cpp | 39 ++++++++----------- .../tilesheeteditor/tilesheeteditormodel.cpp | 10 +++++ .../tilesheeteditor/tilesheeteditormodel.hpp | 3 ++ 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp index 48c7583b..8b79ae42 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditor-imgui.cpp @@ -248,29 +248,22 @@ void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept { ImGui::EndChild(); ImGui::BeginChild("OperationsBox", {0, 35}, ImGuiWindowFlags_NoTitleBar); { - size_t i{}; - if (ig::ComboBox("##Operations", ox::SpanView{{ - ox::CStringView{"Operations"}, - ox::CStringView{"Flip X"}, - ox::CStringView{"Flip Y"}, - ox::CStringView{"Rotate Left"}, - ox::CStringView{"Rotate Right"}, - }}, i)) { - switch (i) { - case 1: - oxLogError(m_model.flipX()); - break; - case 2: - oxLogError(m_model.flipY()); - break; - case 3: - oxLogError(m_model.rotateLeft()); - break; - case 4: - oxLogError(m_model.rotateRight()); - break; - default:; - } + if (ImGui::BeginCombo("##Operations", "Operations", 0)) { + if (ImGui::Selectable("Flip X", false)) { + oxLogError(m_model.flipX()); + } + if (ImGui::Selectable("Flip Y", false)) { + oxLogError(m_model.flipY()); + } + ImGui::BeginDisabled(!m_model.rotateEligible()); + if (ImGui::Selectable("Rotate Left", false)) { + oxLogError(m_model.rotateLeft()); + } + if (ImGui::Selectable("Rotate Right", false)) { + oxLogError(m_model.rotateRight()); + } + ImGui::EndDisabled(); + ImGui::EndCombo(); } } ImGui::EndChild(); diff --git a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.cpp b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.cpp index 127b5209..52b91f40 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.cpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.cpp @@ -352,6 +352,16 @@ ox::Error TileSheetEditorModel::flipY() noexcept { return pushCommand(ox::make(m_img, m_activeSubsSheetIdx, a, b)); } +bool TileSheetEditorModel::rotateEligible() const noexcept { + if (m_selection) { + auto const w = m_selection->b.x - m_selection->a.x; + auto const h = m_selection->b.y - m_selection->a.y; + return w == h; + } + auto const &ss = activeSubSheet(); + return ss.rows == ss.columns; +} + ox::Error TileSheetEditorModel::moveSubSheet(TileSheet::SubSheetIdx src, TileSheet::SubSheetIdx dst) noexcept { return pushCommand(ox::make(m_img, std::move(src), std::move(dst))); } diff --git a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.hpp b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.hpp index 390c9aef..f1c60a56 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.hpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.hpp @@ -138,6 +138,9 @@ class TileSheetEditorModel: public ox::SignalHandler { ox::Error flipY() noexcept; + [[nodiscard]] + bool rotateEligible() const noexcept; + ox::Error moveSubSheet(TileSheet::SubSheetIdx src, TileSheet::SubSheetIdx dst) noexcept; private: