Something went wrong. Try again.
art software for the rest of us
drawing paint image sdl art
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455#include "HistoryManager.h"#include "../AppLayers/NotifyLayer.h"
void HistoryManager::Clear() { for (int i = 0; i < (int)history.size(); i++) { delete history[i].release(); } history.clear(); cursor = -1;}
json HistoryManager::GetEvents() { json events = json::array(); for (int i = 0; i <= cursor; i++) { json event = history[i]->Serialize(); events.push_back(event); } return events;}
void HistoryManager::Execute(std::unique_ptr<Command> command) { if (history.size() && cursor < (int)history.size() - 1) { for (int i = cursor + 1; i < (int)history.size(); i++) { delete history[i].release(); } history.erase(history.begin() + cursor + 1, history.end()); } command->Execute(); history.push_back(std::move(command)); cursor++;}
void HistoryManager::Undo() { if (CanUndo()) { NotifyAppLayer::SetMessage("Undo: " + history[cursor]->GetTitle()); history[cursor]->Undo(); cursor--; }}
void HistoryManager::Redo() { if (CanRedo()) { cursor++; NotifyAppLayer::SetMessage("Redo: " + history[cursor]->GetTitle()); history[cursor]->Execute(); }}
bool HistoryManager::CanUndo() { return cursor >= 0;}
bool HistoryManager::CanRedo() { return cursor < (int)history.size() - 1;}