[nostalgia/core/studio] Cleanup to ensure ongoing draw command ending

This commit is contained in:
Gary Talent 2022-02-13 23:34:57 -06:00
parent d792e4c515
commit 95f3c5b62a
2 changed files with 13 additions and 7 deletions

View File

@ -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<DrawCommand*>(cmd);
}
}

View File

@ -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();