diff --git a/src/nostalgia/core/studio/tilesheeteditormodel.cpp b/src/nostalgia/core/studio/tilesheeteditormodel.cpp index 5d73d964..91261b1e 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 43dd2788..04cedeca 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();