From 95f3c5b62aff880b6827a8cf39fa66d2dde32d08 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 13 Feb 2022 23:34:57 -0600 Subject: [PATCH] [nostalgia/core/studio] Cleanup to ensure ongoing draw command ending --- .../core/studio/tilesheeteditormodel.cpp | 16 ++++++++++------ .../core/studio/tilesheeteditormodel.hpp | 4 +++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/nostalgia/core/studio/tilesheeteditormodel.cpp b/src/nostalgia/core/studio/tilesheeteditormodel.cpp index 5d73d9641..91261b1e5 100644 --- a/src/nostalgia/core/studio/tilesheeteditormodel.cpp +++ b/src/nostalgia/core/studio/tilesheeteditormodel.cpp @@ -15,12 +15,11 @@ TileSheetEditorModel::TileSheetEditorModel(Context *ctx, const ox::String &path) } void TileSheetEditorModel::draw(const geo::Point &pt, std::size_t palIdx) noexcept { - if (!m_ongoingDrawCommand) { - m_ongoingDrawCommand = new DrawCommand(&m_img, ptToIdx(pt, m_img.columns), palIdx); - m_undoStack.push(m_ongoingDrawCommand); - m_updated = true; - } else { + if (m_ongoingDrawCommand) { m_updated = m_ongoingDrawCommand->append(ptToIdx(pt, m_img.columns)); + } else { + pushCommand(new DrawCommand(&m_img, ptToIdx(pt, m_img.columns), palIdx)); + m_updated = true; } } @@ -36,7 +35,7 @@ void TileSheetEditorModel::ackUpdate() noexcept { m_updated = false; } -void TileSheetEditorModel::getFillPixels(bool *pixels, geo::Point pt, int oldColor) const noexcept { +void TileSheetEditorModel::getFillPixels(bool *pixels, const geo::Point &pt, int oldColor) const noexcept { const auto tileIdx = [this](const geo::Point &pt) noexcept { return ptToIdx(pt, img().columns) / PixelsPerTile; }; @@ -68,4 +67,9 @@ void TileSheetEditorModel::getFillPixels(bool *pixels, geo::Point pt, int oldCol } } +void TileSheetEditorModel::pushCommand(studio::UndoCommand *cmd) noexcept { + m_undoStack.push(cmd); + m_ongoingDrawCommand = dynamic_cast(cmd); +} + } \ No newline at end of file diff --git a/src/nostalgia/core/studio/tilesheeteditormodel.hpp b/src/nostalgia/core/studio/tilesheeteditormodel.hpp index 43dd27885..04cedeca2 100644 --- a/src/nostalgia/core/studio/tilesheeteditormodel.hpp +++ b/src/nostalgia/core/studio/tilesheeteditormodel.hpp @@ -174,9 +174,11 @@ class TileSheetEditorModel { protected: void saveItem(); - void getFillPixels(bool *pixels, geo::Point pt, int oldColor) const noexcept; + void getFillPixels(bool *pixels, const geo::Point &pt, int oldColor) const noexcept; private: + void pushCommand(studio::UndoCommand *cmd) noexcept; + void setPalette(); void saveState();