[nostalgia/core/studio] Fix TileSheetEditor cut to use undo stack
This commit is contained in:
parent
041e571626
commit
10d2f2c064
@ -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<CommandId CommandId>
|
||||
class CutPasteCommand: public studio::UndoCommand {
|
||||
private:
|
||||
struct Change {
|
||||
uint32_t idx = 0;
|
||||
@ -155,7 +157,7 @@ class PasteCommand: public studio::UndoCommand {
|
||||
ox::Vector<Change> 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<int>(CommandId::Paste);
|
||||
return static_cast<int>(CommandId);
|
||||
}
|
||||
|
||||
};
|
||||
@ -362,20 +364,24 @@ TileSheetEditorModel::TileSheetEditorModel(Context *ctx, const ox::String &path)
|
||||
}
|
||||
|
||||
void TileSheetEditorModel::cut() {
|
||||
auto cb = ox::make_unique<TileSheetClipboard>();;
|
||||
TileSheetClipboard blankCb;
|
||||
auto cb = ox::make_unique<TileSheetClipboard>();
|
||||
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<CommandId::Cut>(&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<CommandId::Paste>(&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:
|
||||
|
Loading…
Reference in New Issue
Block a user