-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatePattern.cpp
More file actions
62 lines (51 loc) · 858 Bytes
/
StatePattern.cpp
File metadata and controls
62 lines (51 loc) · 858 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "StatePattern.h"
#include <utility>
#include <cstdio>
#include <iostream>
void Pen::mouseUp() const
{
puts("Drawing with a pen!");
}
void Pen::mouseDown() const
{
puts("Pen selected!");
}
std::string Pen::toolType() const
{
return { "Pen" };
}
void Eraser::mouseUp() const
{
puts("Erase something!");
}
void Eraser::mouseDown() const
{
puts("Eraser selected!");
}
std::string Eraser::toolType() const
{
return { "Eraser" };
}
Canvas::Canvas(): current_tool(std::make_unique<Pen>())
{
}
Canvas::Canvas(Tool* tool):current_tool(tool)
{
}
void Canvas::changeTool(Tool* tool)
{
current_tool.reset(tool);
std::cout << "Change tool -> " << tool->toolType() << '\n';
}
void Canvas::mouseUp() const
{
current_tool->mouseUp();
}
void Canvas::mouseDown() const
{
current_tool->mouseDown();
}
Tool::~Tool()
{
puts("Tool released!");
}