-
Notifications
You must be signed in to change notification settings - Fork 0
/
CanvasActions.h
53 lines (46 loc) · 1.2 KB
/
CanvasActions.h
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#pragma once
#include <cinttypes>
#include <vector>
#include <functional>
#include "ComponentTypes.hpp"
class CanvasAction {
public:
virtual void run(pixels_t& pixels, bool forward) = 0;
};
class CanvasPaintAction : public CanvasAction {
private:
int x;
int y;
uint8_t old_color;
uint8_t new_color;
public:
CanvasPaintAction(int _x, int _y, uint8_t oc, uint8_t nc) :
x(_x), y(_y), old_color(oc), new_color(nc) {}
virtual void run(pixels_t& pixels, bool forward);
};
class CanvasFillAction : public CanvasAction {
private:
std::vector<CanvasPaintAction*> data;
public:
CanvasFillAction() {}
~CanvasFillAction();
virtual void run(pixels_t& pixels, bool forward);
void add(CanvasPaintAction* action) { data.push_back(action); }
};
class CanvasActions {
private:
std::vector<CanvasAction*> queue;
std::vector<CanvasAction*>::iterator curr_action;
public:
std::function<void(bool)> onUndo;
std::function<void(bool)> onRedo;
std::function<void(void)> onActionRecorded;
std::function<void(void)> onActionsForget;
std::function<void(void)> onChangesMade;
CanvasActions();
~CanvasActions();
void undo(pixels_t& pixels);
void redo(pixels_t& pixels);
void record(CanvasAction* action);
void forget(void);
};