[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::BeginChild("OperationsBox", {0, 35}, ImGuiWindowFlags_NoTitleBar);
{
size_t i{};
if (ig::ComboBox("##Operations", ox::SpanView<ox::CStringView>{{
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();

View File

@ -352,6 +352,16 @@ ox::Error TileSheetEditorModel::flipY() noexcept {
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 {
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;
[[nodiscard]]
bool rotateEligible() const noexcept;
ox::Error moveSubSheet(TileSheet::SubSheetIdx src, TileSheet::SubSheetIdx dst) noexcept;
private: