-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHistory.cpp
More file actions
31 lines (24 loc) · 873 Bytes
/
History.cpp
File metadata and controls
31 lines (24 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "History.h"
History::History(std::size_t maxDepth) : m_max(maxDepth) {}
void History::clear() { m_undo.clear(); m_redo.clear(); }
void History::push(const sf::Image& img) {
m_undo.push_back(img); // <-- áîëüøå ÍÅ ôèëüòðóåì ïî "imagesEqual"
if (m_undo.size() > m_max) m_undo.erase(m_undo.begin());
m_redo.clear();
}
bool History::canUndo() const { return !m_undo.empty(); }
bool History::canRedo() const { return !m_redo.empty(); }
bool History::undo(const sf::Image& current, sf::Image& out) {
if (m_undo.empty()) return false;
out = m_undo.back();
m_undo.pop_back();
m_redo.push_back(current);
return true;
}
bool History::redo(const sf::Image& current, sf::Image& out) {
if (m_redo.empty()) return false;
out = m_redo.back();
m_redo.pop_back();
m_undo.push_back(current);
return true;
}