-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCanvas.cpp
82 lines (69 loc) · 2.75 KB
/
Canvas.cpp
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "Canvas.h"
Canvas::Canvas()
{
_board = new cimg_library::CImg<unsigned char>(700, 700, 1, 3, 1);
_disp = new cimg_library::CImgDisplay(*_board, "Super Paint");
}
Canvas::~Canvas()
{
_disp->close();
delete _board;
delete _disp;
}
void Canvas::draw_circle(const Point & center, double radius, Color color) const
{
_board->draw_circle(center.getX(), center.getY(), radius, get_color(color).data(), 100.0f).display(*_disp);
}
void Canvas::draw_arrow(const Point & first_point, const Point & second_point, Color color) const
{
_board->draw_arrow(first_point.getX(), first_point.getY(),
second_point.getX(), second_point.getY(), get_color(color).data(), 100.0f).display(*_disp);
}
void Canvas::draw_rectangle(const Point & first_point, const Point & second_point, Color color) const
{
_board->draw_rectangle(first_point.getX(), first_point.getY(),
second_point.getX(), second_point.getY(), get_color(color).data(), 100.0f).display(*_disp);
}
void Canvas::draw_triangle(const Point & first_point, const Point & second_point, const Point & third_point, Color color) const
{
_board->draw_triangle(first_point.getX(), first_point.getY(),
second_point.getX(), second_point.getY(),
third_point.getX(), third_point.getY(), get_color(color).data(), 100.0f).display(*_disp);
}
void Canvas::clear_circle(const Point & center, double radius) const
{
unsigned char BLACK[] = { 0, 0, 0 };
_board->draw_circle(center.getX(), center.getY(), radius, get_color(Color::black).data(), 100.0f).display(*_disp);
}
void Canvas::clear_arrow(const Point & first_point, const Point & second_point) const
{
_board->draw_arrow(first_point.getX(), first_point.getY(),
second_point.getX(), second_point.getY(), get_color(Color::black).data(), 100.0f).display(*_disp);
}
void Canvas::clear_rectangle(const Point & first_point, const Point & second_point) const
{
_board->draw_rectangle(first_point.getX(), first_point.getY(),
second_point.getX(), second_point.getY(), get_color(Color::black).data(), 100.0f).display(*_disp);
}
void Canvas::clear_triangle(const Point & first_point, const Point & second_point, const Point & third_point) const
{
_board->draw_triangle(first_point.getX(), first_point.getY(),
second_point.getX(), second_point.getY(),
third_point.getX(), third_point.getY(), get_color(Color::black).data(), 100.0f).display(*_disp);
}
std::vector<unsigned char> Canvas::get_color(Color color) const
{
switch (color)
{
case Color::red:
return std::vector<unsigned char>{ 255, 0, 0 };
case Color::blue:
return std::vector<unsigned char>{ 0, 0, 255 };
case Color::green:
return std::vector<unsigned char>{ 0, 255, 0 };
case Color::white:
return std::vector<unsigned char>{ 255, 255, 255 };
default: //Color::black
return std::vector<unsigned char>{ 0, 0, 0 };
}
}