[nostalgia/studio] Make UndoCommand undo/redo return ox::Error
This commit is contained in:
parent
0afa2b8cbd
commit
815f23a0b5
@ -14,12 +14,13 @@ int AddPageCommand::commandId() const noexcept {
|
|||||||
return static_cast<int>(PaletteEditorCommandId::AddPage);
|
return static_cast<int>(PaletteEditorCommandId::AddPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddPageCommand::redo() noexcept {
|
ox::Error AddPageCommand::redo() noexcept {
|
||||||
m_pal.pages.emplace_back();
|
m_pal.pages.emplace_back();
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddPageCommand::undo() noexcept {
|
ox::Error AddPageCommand::undo() noexcept {
|
||||||
std::ignore = m_pal.pages.erase(static_cast<std::size_t>(m_pal.pages.size() - 1));
|
return m_pal.pages.erase(static_cast<std::size_t>(m_pal.pages.size() - 1)).error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -37,13 +38,14 @@ int DuplicatePageCommand::commandId() const noexcept {
|
|||||||
return static_cast<int>(PaletteEditorCommandId::DuplicatePage);
|
return static_cast<int>(PaletteEditorCommandId::DuplicatePage);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DuplicatePageCommand::redo() noexcept {
|
ox::Error DuplicatePageCommand::redo() noexcept {
|
||||||
m_pal.pages.emplace(m_dstIdx, std::move(m_page));
|
m_pal.pages.emplace(m_dstIdx, std::move(m_page));
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void DuplicatePageCommand::undo() noexcept {
|
ox::Error DuplicatePageCommand::undo() noexcept {
|
||||||
m_page = std::move(m_pal.pages[m_dstIdx]);
|
m_page = std::move(m_pal.pages[m_dstIdx]);
|
||||||
std::ignore = m_pal.pages.erase(static_cast<std::size_t>(m_dstIdx));
|
return m_pal.pages.erase(static_cast<std::size_t>(m_dstIdx)).error;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t DuplicatePageCommand::insertIdx() const noexcept {
|
size_t DuplicatePageCommand::insertIdx() const noexcept {
|
||||||
@ -60,13 +62,14 @@ int RemovePageCommand::commandId() const noexcept {
|
|||||||
return static_cast<int>(PaletteEditorCommandId::RemovePage);
|
return static_cast<int>(PaletteEditorCommandId::RemovePage);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemovePageCommand::redo() noexcept {
|
ox::Error RemovePageCommand::redo() noexcept {
|
||||||
m_page = std::move(m_pal.pages[m_idx]);
|
m_page = std::move(m_pal.pages[m_idx]);
|
||||||
std::ignore = m_pal.pages.erase(static_cast<std::size_t>(m_idx));
|
return m_pal.pages.erase(static_cast<std::size_t>(m_idx)).error;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemovePageCommand::undo() noexcept {
|
ox::Error RemovePageCommand::undo() noexcept {
|
||||||
m_pal.pages.insert(m_idx, std::move(m_page));
|
m_pal.pages.insert(m_idx, std::move(m_page));
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -81,12 +84,13 @@ int AddColorCommand::commandId() const noexcept {
|
|||||||
return static_cast<int>(PaletteEditorCommandId::AddColor);
|
return static_cast<int>(PaletteEditorCommandId::AddColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddColorCommand::redo() noexcept {
|
ox::Error AddColorCommand::redo() noexcept {
|
||||||
m_pal->pages[m_page].insert(static_cast<std::size_t>(m_idx), m_color);
|
m_pal->pages[m_page].insert(static_cast<std::size_t>(m_idx), m_color);
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddColorCommand::undo() noexcept {
|
ox::Error AddColorCommand::undo() noexcept {
|
||||||
std::ignore = m_pal->pages[m_page].erase(static_cast<std::size_t>(m_idx));
|
return m_pal->pages[m_page].erase(static_cast<std::size_t>(m_idx)).error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -101,12 +105,13 @@ int RemoveColorCommand::commandId() const noexcept {
|
|||||||
return static_cast<int>(PaletteEditorCommandId::RemoveColor);
|
return static_cast<int>(PaletteEditorCommandId::RemoveColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveColorCommand::redo() noexcept {
|
ox::Error RemoveColorCommand::redo() noexcept {
|
||||||
std::ignore = m_pal->pages[m_page].erase(static_cast<std::size_t>(m_idx));
|
return m_pal->pages[m_page].erase(static_cast<std::size_t>(m_idx)).error;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveColorCommand::undo() noexcept {
|
ox::Error RemoveColorCommand::undo() noexcept {
|
||||||
m_pal->pages[m_page].insert(static_cast<std::size_t>(m_idx), m_color);
|
m_pal->pages[m_page].insert(static_cast<std::size_t>(m_idx), m_color);
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -141,12 +146,14 @@ int UpdateColorCommand::commandId() const noexcept {
|
|||||||
return static_cast<int>(PaletteEditorCommandId::UpdateColor);
|
return static_cast<int>(PaletteEditorCommandId::UpdateColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateColorCommand::redo() noexcept {
|
ox::Error UpdateColorCommand::redo() noexcept {
|
||||||
m_pal->pages[m_page][static_cast<std::size_t>(m_idx)] = m_newColor;
|
m_pal->pages[m_page][static_cast<std::size_t>(m_idx)] = m_newColor;
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateColorCommand::undo() noexcept {
|
ox::Error UpdateColorCommand::undo() noexcept {
|
||||||
m_pal->pages[m_page][static_cast<std::size_t>(m_idx)] = m_oldColor;
|
m_pal->pages[m_page][static_cast<std::size_t>(m_idx)] = m_oldColor;
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -161,12 +168,14 @@ int MoveColorCommand::commandId() const noexcept {
|
|||||||
return static_cast<int>(PaletteEditorCommandId::MoveColor);
|
return static_cast<int>(PaletteEditorCommandId::MoveColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MoveColorCommand::redo() noexcept {
|
ox::Error MoveColorCommand::redo() noexcept {
|
||||||
moveColor(static_cast<int>(m_idx), m_offset);
|
moveColor(static_cast<int>(m_idx), m_offset);
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void MoveColorCommand::undo() noexcept {
|
ox::Error MoveColorCommand::undo() noexcept {
|
||||||
moveColor(static_cast<int>(m_idx) + m_offset, -m_offset);
|
moveColor(static_cast<int>(m_idx) + m_offset, -m_offset);
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void MoveColorCommand::moveColor(int idx, int offset) noexcept {
|
void MoveColorCommand::moveColor(int idx, int offset) noexcept {
|
||||||
|
@ -35,9 +35,9 @@ class AddPageCommand: public studio::UndoCommand {
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
int commandId() const noexcept final;
|
int commandId() const noexcept final;
|
||||||
|
|
||||||
void redo() noexcept final;
|
ox::Error redo() noexcept final;
|
||||||
|
|
||||||
void undo() noexcept final;
|
ox::Error undo() noexcept final;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -55,9 +55,9 @@ class DuplicatePageCommand: public studio::UndoCommand {
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
int commandId() const noexcept final;
|
int commandId() const noexcept final;
|
||||||
|
|
||||||
void redo() noexcept final;
|
ox::Error redo() noexcept final;
|
||||||
|
|
||||||
void undo() noexcept final;
|
ox::Error undo() noexcept final;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
size_t insertIdx() const noexcept;
|
size_t insertIdx() const noexcept;
|
||||||
@ -78,9 +78,9 @@ class RemovePageCommand: public studio::UndoCommand {
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
int commandId() const noexcept final;
|
int commandId() const noexcept final;
|
||||||
|
|
||||||
void redo() noexcept final;
|
ox::Error redo() noexcept final;
|
||||||
|
|
||||||
void undo() noexcept final;
|
ox::Error undo() noexcept final;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -99,9 +99,9 @@ class AddColorCommand: public studio::UndoCommand {
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
int commandId() const noexcept override;
|
int commandId() const noexcept override;
|
||||||
|
|
||||||
void redo() noexcept override;
|
ox::Error redo() noexcept override;
|
||||||
|
|
||||||
void undo() noexcept override;
|
ox::Error undo() noexcept override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -120,9 +120,9 @@ class RemoveColorCommand: public studio::UndoCommand {
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
int commandId() const noexcept override;
|
int commandId() const noexcept override;
|
||||||
|
|
||||||
void redo() noexcept override;
|
ox::Error redo() noexcept override;
|
||||||
|
|
||||||
void undo() noexcept override;
|
ox::Error undo() noexcept override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -145,9 +145,9 @@ class UpdateColorCommand: public studio::UndoCommand {
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
int commandId() const noexcept final;
|
int commandId() const noexcept final;
|
||||||
|
|
||||||
void redo() noexcept final;
|
ox::Error redo() noexcept final;
|
||||||
|
|
||||||
void undo() noexcept final;
|
ox::Error undo() noexcept final;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -167,9 +167,9 @@ class MoveColorCommand: public studio::UndoCommand {
|
|||||||
int commandId() const noexcept override;
|
int commandId() const noexcept override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void redo() noexcept override;
|
ox::Error redo() noexcept override;
|
||||||
|
|
||||||
void undo() noexcept override;
|
ox::Error undo() noexcept override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void moveColor(int idx, int offset) noexcept;
|
void moveColor(int idx, int offset) noexcept;
|
||||||
|
@ -24,7 +24,7 @@ AddSubSheetCommand::AddSubSheetCommand(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddSubSheetCommand::redo() noexcept {
|
ox::Error AddSubSheetCommand::redo() noexcept {
|
||||||
auto &parent = getSubSheet(m_img, m_parentIdx);
|
auto &parent = getSubSheet(m_img, m_parentIdx);
|
||||||
if (m_addedSheets.size() < 2) {
|
if (m_addedSheets.size() < 2) {
|
||||||
auto i = parent.subsheets.size();
|
auto i = parent.subsheets.size();
|
||||||
@ -35,9 +35,10 @@ void AddSubSheetCommand::redo() noexcept {
|
|||||||
parent.columns = 0;
|
parent.columns = 0;
|
||||||
parent.subsheets.emplace_back(m_img.idIt++, "Subsheet 1", 1, 1, m_img.bpp);
|
parent.subsheets.emplace_back(m_img.idIt++, "Subsheet 1", 1, 1, m_img.bpp);
|
||||||
}
|
}
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddSubSheetCommand::undo() noexcept {
|
ox::Error AddSubSheetCommand::undo() noexcept {
|
||||||
auto &parent = getSubSheet(m_img, m_parentIdx);
|
auto &parent = getSubSheet(m_img, m_parentIdx);
|
||||||
if (parent.subsheets.size() == 2) {
|
if (parent.subsheets.size() == 2) {
|
||||||
auto s = parent.subsheets[0];
|
auto s = parent.subsheets[0];
|
||||||
@ -47,9 +48,10 @@ void AddSubSheetCommand::undo() noexcept {
|
|||||||
parent.subsheets.clear();
|
parent.subsheets.clear();
|
||||||
} else {
|
} else {
|
||||||
for (auto idx = m_addedSheets.rbegin(); idx != m_addedSheets.rend(); ++idx) {
|
for (auto idx = m_addedSheets.rbegin(); idx != m_addedSheets.rend(); ++idx) {
|
||||||
oxLogError(rmSubSheet(m_img, *idx));
|
oxReturnError(rmSubSheet(m_img, *idx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int AddSubSheetCommand::commandId() const noexcept {
|
int AddSubSheetCommand::commandId() const noexcept {
|
||||||
|
@ -17,9 +17,9 @@ class AddSubSheetCommand: public TileSheetCommand {
|
|||||||
public:
|
public:
|
||||||
AddSubSheetCommand(TileSheet &img, TileSheet::SubSheetIdx parentIdx) noexcept;
|
AddSubSheetCommand(TileSheet &img, TileSheet::SubSheetIdx parentIdx) noexcept;
|
||||||
|
|
||||||
void redo() noexcept final;
|
ox::Error redo() noexcept final;
|
||||||
|
|
||||||
void undo() noexcept final;
|
ox::Error undo() noexcept final;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
int commandId() const noexcept final;
|
int commandId() const noexcept final;
|
||||||
|
@ -41,18 +41,20 @@ CutPasteCommand::CutPasteCommand(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CutPasteCommand::redo() noexcept {
|
ox::Error CutPasteCommand::redo() noexcept {
|
||||||
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
|
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
|
||||||
for (const auto &c : m_changes) {
|
for (const auto &c : m_changes) {
|
||||||
setPixel(subsheet, m_img.bpp, c.idx, static_cast<uint8_t>(c.newPalIdx));
|
setPixel(subsheet, m_img.bpp, c.idx, static_cast<uint8_t>(c.newPalIdx));
|
||||||
}
|
}
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void CutPasteCommand::undo() noexcept {
|
ox::Error CutPasteCommand::undo() noexcept {
|
||||||
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
|
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
|
||||||
for (const auto &c : m_changes) {
|
for (const auto &c : m_changes) {
|
||||||
setPixel(subsheet, m_img.bpp, c.idx, static_cast<uint8_t>(c.oldPalIdx));
|
setPixel(subsheet, m_img.bpp, c.idx, static_cast<uint8_t>(c.oldPalIdx));
|
||||||
}
|
}
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int CutPasteCommand::commandId() const noexcept {
|
int CutPasteCommand::commandId() const noexcept {
|
||||||
|
@ -69,9 +69,9 @@ class CutPasteCommand: public TileSheetCommand {
|
|||||||
ox::Point const&dstEnd,
|
ox::Point const&dstEnd,
|
||||||
TileSheetClipboard const&cb) noexcept;
|
TileSheetClipboard const&cb) noexcept;
|
||||||
|
|
||||||
void redo() noexcept final;
|
ox::Error redo() noexcept final;
|
||||||
|
|
||||||
void undo() noexcept final;
|
ox::Error undo() noexcept final;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
int commandId() const noexcept final;
|
int commandId() const noexcept final;
|
||||||
|
@ -28,7 +28,7 @@ core::DeleteTilesCommand::DeleteTilesCommand(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void core::DeleteTilesCommand::redo() noexcept {
|
ox::Error core::DeleteTilesCommand::redo() noexcept {
|
||||||
auto &s = getSubSheet(m_img, m_idx);
|
auto &s = getSubSheet(m_img, m_idx);
|
||||||
auto &p = s.pixels;
|
auto &p = s.pixels;
|
||||||
auto srcPos = m_deletePos + m_deleteSz;
|
auto srcPos = m_deletePos + m_deleteSz;
|
||||||
@ -37,9 +37,10 @@ void core::DeleteTilesCommand::redo() noexcept {
|
|||||||
const auto dst2 = p.data() + (p.size() - m_deleteSz);
|
const auto dst2 = p.data() + (p.size() - m_deleteSz);
|
||||||
ox::memmove(dst1, src, p.size() - srcPos);
|
ox::memmove(dst1, src, p.size() - srcPos);
|
||||||
ox::memset(dst2, 0, m_deleteSz * sizeof(decltype(p[0])));
|
ox::memset(dst2, 0, m_deleteSz * sizeof(decltype(p[0])));
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeleteTilesCommand::undo() noexcept {
|
ox::Error DeleteTilesCommand::undo() noexcept {
|
||||||
auto &s = getSubSheet(m_img, m_idx);
|
auto &s = getSubSheet(m_img, m_idx);
|
||||||
auto &p = s.pixels;
|
auto &p = s.pixels;
|
||||||
const auto src = p.data() + m_deletePos;
|
const auto src = p.data() + m_deletePos;
|
||||||
@ -48,6 +49,7 @@ void DeleteTilesCommand::undo() noexcept {
|
|||||||
const auto sz = p.size() - m_deletePos - m_deleteSz;
|
const auto sz = p.size() - m_deletePos - m_deleteSz;
|
||||||
ox::memmove(dst1, src, sz);
|
ox::memmove(dst1, src, sz);
|
||||||
ox::memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size());
|
ox::memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size());
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int DeleteTilesCommand::commandId() const noexcept {
|
int DeleteTilesCommand::commandId() const noexcept {
|
||||||
|
@ -23,9 +23,9 @@ class DeleteTilesCommand: public TileSheetCommand {
|
|||||||
std::size_t tileIdx,
|
std::size_t tileIdx,
|
||||||
std::size_t tileCnt) noexcept;
|
std::size_t tileCnt) noexcept;
|
||||||
|
|
||||||
void redo() noexcept final;
|
ox::Error redo() noexcept final;
|
||||||
|
|
||||||
void undo() noexcept final;
|
ox::Error undo() noexcept final;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
int commandId() const noexcept final;
|
int commandId() const noexcept final;
|
||||||
|
@ -56,18 +56,20 @@ bool DrawCommand::append(const ox::Vector<std::size_t> &idxList) noexcept {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawCommand::redo() noexcept {
|
ox::Error DrawCommand::redo() noexcept {
|
||||||
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
|
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
|
||||||
for (const auto &c : m_changes) {
|
for (const auto &c : m_changes) {
|
||||||
setPixel(subsheet, m_img.bpp, c.idx, static_cast<uint8_t>(m_palIdx));
|
setPixel(subsheet, m_img.bpp, c.idx, static_cast<uint8_t>(m_palIdx));
|
||||||
}
|
}
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawCommand::undo() noexcept {
|
ox::Error DrawCommand::undo() noexcept {
|
||||||
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
|
auto &subsheet = getSubSheet(m_img, m_subSheetIdx);
|
||||||
for (const auto &c : m_changes) {
|
for (const auto &c : m_changes) {
|
||||||
setPixel(subsheet, m_img.bpp, c.idx, static_cast<uint8_t>(c.oldPalIdx));
|
setPixel(subsheet, m_img.bpp, c.idx, static_cast<uint8_t>(c.oldPalIdx));
|
||||||
}
|
}
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int DrawCommand::commandId() const noexcept {
|
int DrawCommand::commandId() const noexcept {
|
||||||
|
@ -40,9 +40,9 @@ class DrawCommand: public TileSheetCommand {
|
|||||||
|
|
||||||
bool append(const ox::Vector<std::size_t> &idxList) noexcept;
|
bool append(const ox::Vector<std::size_t> &idxList) noexcept;
|
||||||
|
|
||||||
void redo() noexcept final;
|
ox::Error redo() noexcept final;
|
||||||
|
|
||||||
void undo() noexcept final;
|
ox::Error undo() noexcept final;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
int commandId() const noexcept final;
|
int commandId() const noexcept final;
|
||||||
|
@ -28,7 +28,7 @@ core::InsertTilesCommand::InsertTilesCommand(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InsertTilesCommand::redo() noexcept {
|
ox::Error InsertTilesCommand::redo() noexcept {
|
||||||
auto &s = getSubSheet(m_img, m_idx);
|
auto &s = getSubSheet(m_img, m_idx);
|
||||||
auto &p = s.pixels;
|
auto &p = s.pixels;
|
||||||
auto dstPos = m_insertPos + m_insertCnt;
|
auto dstPos = m_insertPos + m_insertCnt;
|
||||||
@ -36,9 +36,10 @@ void InsertTilesCommand::redo() noexcept {
|
|||||||
const auto src = p.data() + m_insertPos;
|
const auto src = p.data() + m_insertPos;
|
||||||
ox::memmove(dst, src, p.size() - dstPos);
|
ox::memmove(dst, src, p.size() - dstPos);
|
||||||
ox::memset(src, 0, m_insertCnt * sizeof(decltype(p[0])));
|
ox::memset(src, 0, m_insertCnt * sizeof(decltype(p[0])));
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void InsertTilesCommand::undo() noexcept {
|
ox::Error InsertTilesCommand::undo() noexcept {
|
||||||
auto &s = getSubSheet(m_img, m_idx);
|
auto &s = getSubSheet(m_img, m_idx);
|
||||||
auto &p = s.pixels;
|
auto &p = s.pixels;
|
||||||
const auto srcIdx = m_insertPos + m_insertCnt;
|
const auto srcIdx = m_insertPos + m_insertCnt;
|
||||||
@ -48,6 +49,7 @@ void InsertTilesCommand::undo() noexcept {
|
|||||||
const auto sz = p.size() - srcIdx;
|
const auto sz = p.size() - srcIdx;
|
||||||
ox::memmove(dst1, src, sz);
|
ox::memmove(dst1, src, sz);
|
||||||
ox::memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size());
|
ox::memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size());
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int InsertTilesCommand::commandId() const noexcept {
|
int InsertTilesCommand::commandId() const noexcept {
|
||||||
|
@ -23,9 +23,9 @@ class InsertTilesCommand: public TileSheetCommand {
|
|||||||
std::size_t tileIdx,
|
std::size_t tileIdx,
|
||||||
std::size_t tileCnt) noexcept;
|
std::size_t tileCnt) noexcept;
|
||||||
|
|
||||||
void redo() noexcept final;
|
ox::Error redo() noexcept final;
|
||||||
|
|
||||||
void undo() noexcept final;
|
ox::Error undo() noexcept final;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
int commandId() const noexcept final;
|
int commandId() const noexcept final;
|
||||||
|
@ -16,12 +16,14 @@ core::PaletteChangeCommand::PaletteChangeCommand(
|
|||||||
m_newPalette(ox::FileAddress(ox::sfmt<ox::IString<43>>("uuid://{}", newPalette))) {
|
m_newPalette(ox::FileAddress(ox::sfmt<ox::IString<43>>("uuid://{}", newPalette))) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaletteChangeCommand::redo() noexcept {
|
ox::Error PaletteChangeCommand::redo() noexcept {
|
||||||
m_img.defaultPalette = m_newPalette;
|
m_img.defaultPalette = m_newPalette;
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void PaletteChangeCommand::undo() noexcept {
|
ox::Error PaletteChangeCommand::undo() noexcept {
|
||||||
m_img.defaultPalette = m_oldPalette;
|
m_img.defaultPalette = m_oldPalette;
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int PaletteChangeCommand::commandId() const noexcept {
|
int PaletteChangeCommand::commandId() const noexcept {
|
||||||
|
@ -21,9 +21,9 @@ class PaletteChangeCommand: public TileSheetCommand {
|
|||||||
TileSheet &img,
|
TileSheet &img,
|
||||||
ox::CRStringView newPalette) noexcept;
|
ox::CRStringView newPalette) noexcept;
|
||||||
|
|
||||||
void redo() noexcept final;
|
ox::Error redo() noexcept final;
|
||||||
|
|
||||||
void undo() noexcept final;
|
ox::Error undo() noexcept final;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
int commandId() const noexcept final;
|
int commandId() const noexcept final;
|
||||||
|
@ -13,16 +13,18 @@ core::RmSubSheetCommand::RmSubSheetCommand(TileSheet &img, TileSheet::SubSheetId
|
|||||||
m_parentIdx.pop_back();
|
m_parentIdx.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RmSubSheetCommand::redo() noexcept {
|
ox::Error RmSubSheetCommand::redo() noexcept {
|
||||||
auto &parent = getSubSheet(m_img, m_parentIdx);
|
auto &parent = getSubSheet(m_img, m_parentIdx);
|
||||||
m_sheet = std::move(parent.subsheets[*m_idx.back().value]);
|
m_sheet = std::move(parent.subsheets[*m_idx.back().value]);
|
||||||
oxLogError(parent.subsheets.erase(*m_idx.back().value).error);
|
oxReturnError(parent.subsheets.erase(*m_idx.back().value).error);
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void RmSubSheetCommand::undo() noexcept {
|
ox::Error RmSubSheetCommand::undo() noexcept {
|
||||||
auto &parent = getSubSheet(m_img, m_parentIdx);
|
auto &parent = getSubSheet(m_img, m_parentIdx);
|
||||||
auto const i = *m_idx.back().value;
|
auto const i = *m_idx.back().value;
|
||||||
parent.subsheets.insert(i, std::move(m_sheet));
|
parent.subsheets.insert(i, std::move(m_sheet));
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int RmSubSheetCommand::commandId() const noexcept {
|
int RmSubSheetCommand::commandId() const noexcept {
|
||||||
|
@ -18,9 +18,9 @@ class RmSubSheetCommand: public TileSheetCommand {
|
|||||||
public:
|
public:
|
||||||
RmSubSheetCommand(TileSheet &img, TileSheet::SubSheetIdx idx) noexcept;
|
RmSubSheetCommand(TileSheet &img, TileSheet::SubSheetIdx idx) noexcept;
|
||||||
|
|
||||||
void redo() noexcept final;
|
ox::Error redo() noexcept final;
|
||||||
|
|
||||||
void undo() noexcept final;
|
ox::Error undo() noexcept final;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
int commandId() const noexcept final;
|
int commandId() const noexcept final;
|
||||||
|
@ -20,15 +20,17 @@ core::UpdateSubSheetCommand::UpdateSubSheetCommand(
|
|||||||
m_newRows(rows) {
|
m_newRows(rows) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateSubSheetCommand::redo() noexcept {
|
ox::Error UpdateSubSheetCommand::redo() noexcept {
|
||||||
auto &sheet = getSubSheet(m_img, m_idx);
|
auto &sheet = getSubSheet(m_img, m_idx);
|
||||||
sheet.name = m_newName;
|
sheet.name = m_newName;
|
||||||
oxLogError(resizeSubsheet(sheet, m_img.bpp, {m_newCols, m_newRows}));
|
oxLogError(resizeSubsheet(sheet, m_img.bpp, {m_newCols, m_newRows}));
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateSubSheetCommand::undo() noexcept {
|
ox::Error UpdateSubSheetCommand::undo() noexcept {
|
||||||
auto &sheet = getSubSheet(m_img, m_idx);
|
auto &sheet = getSubSheet(m_img, m_idx);
|
||||||
sheet = m_sheet;
|
sheet = m_sheet;
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
int UpdateSubSheetCommand::commandId() const noexcept {
|
int UpdateSubSheetCommand::commandId() const noexcept {
|
||||||
|
@ -25,9 +25,9 @@ class UpdateSubSheetCommand: public TileSheetCommand {
|
|||||||
int cols,
|
int cols,
|
||||||
int rows) noexcept;
|
int rows) noexcept;
|
||||||
|
|
||||||
void redo() noexcept final;
|
ox::Error redo() noexcept final;
|
||||||
|
|
||||||
void undo() noexcept final;
|
ox::Error undo() noexcept final;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
int commandId() const noexcept final;
|
int commandId() const noexcept final;
|
||||||
|
@ -19,8 +19,8 @@ class NoChangesException: public ox::Exception {
|
|||||||
class UndoCommand {
|
class UndoCommand {
|
||||||
public:
|
public:
|
||||||
virtual ~UndoCommand() noexcept = default;
|
virtual ~UndoCommand() noexcept = default;
|
||||||
virtual void redo() noexcept = 0;
|
virtual ox::Error redo() noexcept = 0;
|
||||||
virtual void undo() noexcept = 0;
|
virtual ox::Error undo() noexcept = 0;
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
virtual int commandId() const noexcept = 0;
|
virtual int commandId() const noexcept = 0;
|
||||||
virtual bool mergeWith(UndoCommand const&cmd) noexcept;
|
virtual bool mergeWith(UndoCommand const&cmd) noexcept;
|
||||||
|
@ -10,7 +10,9 @@ void UndoStack::push(ox::UPtr<UndoCommand> &&cmd) noexcept {
|
|||||||
for (auto const i = m_stackIdx; i < m_stack.size();) {
|
for (auto const i = m_stackIdx; i < m_stack.size();) {
|
||||||
std::ignore = m_stack.erase(i);
|
std::ignore = m_stack.erase(i);
|
||||||
}
|
}
|
||||||
cmd->redo();
|
if (cmd->redo()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
redoTriggered.emit(cmd.get());
|
redoTriggered.emit(cmd.get());
|
||||||
changeTriggered.emit(cmd.get());
|
changeTriggered.emit(cmd.get());
|
||||||
if (m_stack.empty() || !(*m_stack.back().value)->mergeWith(*cmd)) {
|
if (m_stack.empty() || !(*m_stack.back().value)->mergeWith(*cmd)) {
|
||||||
@ -21,8 +23,11 @@ void UndoStack::push(ox::UPtr<UndoCommand> &&cmd) noexcept {
|
|||||||
|
|
||||||
void UndoStack::redo() noexcept {
|
void UndoStack::redo() noexcept {
|
||||||
if (m_stackIdx < m_stack.size()) {
|
if (m_stackIdx < m_stack.size()) {
|
||||||
auto &c = m_stack[m_stackIdx++];
|
auto &c = m_stack[m_stackIdx];
|
||||||
c->redo();
|
if (c->redo()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
++m_stackIdx;
|
||||||
redoTriggered.emit(c.get());
|
redoTriggered.emit(c.get());
|
||||||
changeTriggered.emit(c.get());
|
changeTriggered.emit(c.get());
|
||||||
}
|
}
|
||||||
@ -31,7 +36,9 @@ void UndoStack::redo() noexcept {
|
|||||||
void UndoStack::undo() noexcept {
|
void UndoStack::undo() noexcept {
|
||||||
if (m_stackIdx) {
|
if (m_stackIdx) {
|
||||||
auto &c = m_stack[--m_stackIdx];
|
auto &c = m_stack[--m_stackIdx];
|
||||||
c->undo();
|
if (c->undo()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
undoTriggered.emit(c.get());
|
undoTriggered.emit(c.get());
|
||||||
changeTriggered.emit(c.get());
|
changeTriggered.emit(c.get());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user