[nostalgia/core/studio] Get Undo/Redo working
This commit is contained in:
@@ -31,9 +31,11 @@ struct DrawCommand: public studio::UndoCommand {
|
||||
NostalgiaGraphic *m_img = nullptr;
|
||||
ox::Vector<Change, 8> m_changes;
|
||||
int m_palIdx = 0;
|
||||
bool *m_modelUpdated = nullptr;
|
||||
|
||||
public:
|
||||
constexpr DrawCommand(NostalgiaGraphic *img, std::size_t idx, int palIdx) noexcept {
|
||||
constexpr DrawCommand(bool *updated, NostalgiaGraphic *img, std::size_t idx, int palIdx) noexcept {
|
||||
m_modelUpdated = updated;
|
||||
m_img = img;
|
||||
m_changes.emplace_back(idx, m_img->getPixel(idx));
|
||||
m_palIdx = palIdx;
|
||||
@@ -55,16 +57,18 @@ struct DrawCommand: public studio::UndoCommand {
|
||||
}
|
||||
|
||||
void redo() noexcept final {
|
||||
for (const auto &c : m_changes) {
|
||||
oxDebugf("{} to {}", c.idx, m_palIdx);
|
||||
for (const auto &c : m_changes
|
||||
) {
|
||||
m_img->setPixel(c.idx, m_palIdx);
|
||||
}
|
||||
*m_modelUpdated = true;
|
||||
}
|
||||
|
||||
void undo() noexcept final {
|
||||
for (const auto &c : m_changes) {
|
||||
m_img->setPixel(c.idx, c.oldPalIdx);
|
||||
}
|
||||
*m_modelUpdated = true;
|
||||
}
|
||||
|
||||
};
|
||||
@@ -146,6 +150,10 @@ class TileSheetEditorModel {
|
||||
|
||||
void ackUpdate() noexcept;
|
||||
|
||||
constexpr studio::UndoStack *undoStack() noexcept {
|
||||
return &m_undoStack;
|
||||
}
|
||||
|
||||
protected:
|
||||
void saveItem();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user