diff --git a/src/nostalgia/core/studio/tilesheeteditormodel.cpp b/src/nostalgia/core/studio/tilesheeteditormodel.cpp index 11afdc845..44545206e 100644 --- a/src/nostalgia/core/studio/tilesheeteditormodel.cpp +++ b/src/nostalgia/core/studio/tilesheeteditormodel.cpp @@ -56,8 +56,9 @@ enum class CommandId { AddSubSheet = 2, RmSubSheet = 3, UpdateSubSheet = 4, - Paste = 5, - PaletteChange = 6, + Cut = 5, + Paste = 6, + PaletteChange = 7, }; constexpr bool operator==(CommandId c, int i) noexcept { @@ -143,7 +144,8 @@ class DrawCommand: public studio::UndoCommand { }; -class PasteCommand: public studio::UndoCommand { +template +class CutPasteCommand: public studio::UndoCommand { private: struct Change { uint32_t idx = 0; @@ -155,7 +157,7 @@ class PasteCommand: public studio::UndoCommand { ox::Vector m_changes; public: - constexpr PasteCommand(TileSheet *img, const TileSheet::SubSheetIdx &subSheetIdx, const geo::Point &dstStart, const geo::Point &dstEnd, const TileSheetClipboard &cb) noexcept { + constexpr CutPasteCommand(TileSheet *img, const TileSheet::SubSheetIdx &subSheetIdx, const geo::Point &dstStart, const geo::Point &dstEnd, const TileSheetClipboard &cb) noexcept { m_img = img; m_subSheetIdx = subSheetIdx; const auto &subsheet = m_img->getSubSheet(subSheetIdx); @@ -184,7 +186,7 @@ class PasteCommand: public studio::UndoCommand { [[nodiscard]] int commandId() const noexcept final { - return static_cast(CommandId::Paste); + return static_cast(CommandId); } }; @@ -362,20 +364,24 @@ TileSheetEditorModel::TileSheetEditorModel(Context *ctx, const ox::String &path) } void TileSheetEditorModel::cut() { - auto cb = ox::make_unique();; + TileSheetClipboard blankCb; + auto cb = ox::make_unique(); + const auto s = activeSubSheet(); for (int y = m_selectionBounds.y; y <= m_selectionBounds.y2(); ++y) { for (int x = m_selectionBounds.x; x <= m_selectionBounds.x2(); ++x) { auto pt = geo::Point(x, y); - const auto s = activeSubSheet(); const auto idx = s->idx(pt); const auto c = s->getPixel(m_img.bpp, idx); - s->setPixel(m_img.bpp, idx, 0); pt.x -= m_selectionBounds.x; pt.y -= m_selectionBounds.y; cb->addPixel(pt, c); + blankCb.addPixel(pt, 0); } } + const auto pt1 = m_selectionOrigin == geo::Point(-1, -1) ? geo::Point(0, 0) : m_selectionOrigin; + const auto pt2 = geo::Point(s->columns * TileWidth, s->rows * TileHeight); setClipboardObject(m_ctx, std::move(cb)); + pushCommand(new CutPasteCommand(&m_img, m_activeSubsSheetIdx, pt1, pt2, blankCb)); } void TileSheetEditorModel::copy() { @@ -404,7 +410,7 @@ void TileSheetEditorModel::paste() { const auto s = activeSubSheet(); const auto pt1 = m_selectionOrigin == geo::Point(-1, -1) ? geo::Point(0, 0) : m_selectionOrigin; const auto pt2 = geo::Point(s->columns * TileWidth, s->rows * TileHeight); - pushCommand(new PasteCommand(&m_img, m_activeSubsSheetIdx, pt1, pt2, *cb)); + pushCommand(new CutPasteCommand(&m_img, m_activeSubsSheetIdx, pt1, pt2, *cb)); } const ox::FileAddress &TileSheetEditorModel::palPath() const noexcept { @@ -519,6 +525,7 @@ ox::Error TileSheetEditorModel::markUpdated(int cmdId) noexcept { } break; } + case CommandId::Cut: case CommandId::Draw: case CommandId::Paste: case CommandId::UpdateSubSheet: