[nostalgia/gfx/studio/tilesheet] Make rotate only available for square subsheets or selections
All checks were successful
Build / build (push) Successful in 3m39s

This commit is contained in:
Gary Talent 2025-02-05 01:54:41 -06:00
parent 3c804bf62a
commit b4798fd2ab
3 changed files with 29 additions and 23 deletions

View File

@ -248,29 +248,22 @@ void TileSheetEditorImGui::draw(studio::StudioContext&) noexcept {
ImGui::EndChild(); ImGui::EndChild();
ImGui::BeginChild("OperationsBox", {0, 35}, ImGuiWindowFlags_NoTitleBar); ImGui::BeginChild("OperationsBox", {0, 35}, ImGuiWindowFlags_NoTitleBar);
{ {
size_t i{}; if (ImGui::BeginCombo("##Operations", "Operations", 0)) {
if (ig::ComboBox("##Operations", ox::SpanView<ox::CStringView>{{ if (ImGui::Selectable("Flip X", false)) {
ox::CStringView{"Operations"}, oxLogError(m_model.flipX());
ox::CStringView{"Flip X"}, }
ox::CStringView{"Flip Y"}, if (ImGui::Selectable("Flip Y", false)) {
ox::CStringView{"Rotate Left"}, oxLogError(m_model.flipY());
ox::CStringView{"Rotate Right"}, }
}}, i)) { ImGui::BeginDisabled(!m_model.rotateEligible());
switch (i) { if (ImGui::Selectable("Rotate Left", false)) {
case 1: oxLogError(m_model.rotateLeft());
oxLogError(m_model.flipX()); }
break; if (ImGui::Selectable("Rotate Right", false)) {
case 2: oxLogError(m_model.rotateRight());
oxLogError(m_model.flipY()); }
break; ImGui::EndDisabled();
case 3: ImGui::EndCombo();
oxLogError(m_model.rotateLeft());
break;
case 4:
oxLogError(m_model.rotateRight());
break;
default:;
}
} }
} }
ImGui::EndChild(); ImGui::EndChild();

View File

@ -352,6 +352,16 @@ ox::Error TileSheetEditorModel::flipY() noexcept {
return pushCommand(ox::make<FlipYCommand>(m_img, m_activeSubsSheetIdx, a, b)); return pushCommand(ox::make<FlipYCommand>(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 { ox::Error TileSheetEditorModel::moveSubSheet(TileSheet::SubSheetIdx src, TileSheet::SubSheetIdx dst) noexcept {
return pushCommand(ox::make<MoveSubSheetCommand>(m_img, std::move(src), std::move(dst))); return pushCommand(ox::make<MoveSubSheetCommand>(m_img, std::move(src), std::move(dst)));
} }

View File

@ -138,6 +138,9 @@ class TileSheetEditorModel: public ox::SignalHandler {
ox::Error flipY() noexcept; ox::Error flipY() noexcept;
[[nodiscard]]
bool rotateEligible() const noexcept;
ox::Error moveSubSheet(TileSheet::SubSheetIdx src, TileSheet::SubSheetIdx dst) noexcept; ox::Error moveSubSheet(TileSheet::SubSheetIdx src, TileSheet::SubSheetIdx dst) noexcept;
private: private: