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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
#include<math.h>
#include"seeed_graphics_base.h"
std::vector<color_t> classic_colors {
yellow,
red,
green,
black,
blue,
darkcyan,
magenta,
};
constexpr double pi = 3.14159265358979323846;
extern TFT_eSprite spr;
namespace detail {
void draw(void * poly, bool gen){
detail::poly<polygen> & p = *(detail::poly<polygen> *)poly;
auto default_color = black;
auto default_thickness = pan_thickness;
auto & value = p.value();
auto & color = p.color();
auto & thickness = p.thickness();
if (value.size() <= 1) {
return;
}
for (size_t i = 1; i < value.size() + gen; i++){
auto ai = (i - 1) % value.size();
auto bi = (i) % value.size();
auto a = value[ai];
auto b = value[bi];
if (i - 1 < color.size()){
default_color = color[i - 1];
}
if (i - 1 < thickness.size()){
default_thickness = thickness[i - 1];
}
line(a, b)
.color(default_color)
.thickness(default_thickness)
.draw();
}
}
}
void dot::draw() {
spr.drawPixel(_x, _y, _color);
}
void line::draw() {
spr.drawLine(_x0, _y0, _x1, _y1, _color);
}
void dash_line::draw() {
point origin(_x, _y);
point solid_offset;
point empty_offset;
point end;
if (_orientation == horizon) {
solid_offset = point(_solid, 0);
empty_offset = point(_empty, 0);
end = origin(_length - 1, 0);
}
else {
solid_offset = point(0, _solid);
empty_offset = point(0, _empty);
end = origin(0, _length - 1);
}
for (bool loop = true; loop;) {
auto next = origin(solid_offset);
if (next.x > end.x) {
next.x = end.x;
loop = false;
}
if (next.y > end.y) {
next.y = end.y;
loop = false;
}
line(origin, next)
.color(_color)
.thickness(_thickness)
.draw();
origin = next(empty_offset);
}
}
void rectangle::draw() {
auto origin = adjust(_width, _height);
auto left_top = origin;
auto left_bottom = origin(0, -(pos_t)_height + 1);
auto right_top = left_top(_width - 1, 0);
auto right_bottom = left_bottom(_width - 1, 0);
spr.drawRect(left_top.x, left_top.y, _width, _height, _color);
if (_fill != transparent) {
spr.fillRect(left_top.x + 1, left_top.y + 1, _width - 2, _height - 2, _fill);
}
}
void ellipse::draw() {
auto p = adjust(_width, _height);
if (_fill != transparent) {
spr.fillEllipse(_x, _y, _width / 2, _height / 2, _fill);
}
spr.drawEllipse(_x, _y, _width / 2, _height / 2, _color);
}
text & text::font(font_t value){
_font = value;
spr.setTextFont(uint8_t(value));
return this[0];
}
text & text::thickness(pix_t value){
_thickness = value;
spr.setTextSize(uint8_t(value));
return this[0];
}
text & text::font_height(pix_t * value) {
font(font());
thickness(thickness());
value[0] = spr.fontHeight();
return this[0];
}
text & text::content_width(pix_t * value) {
font(font());
thickness(thickness());
value[0] = spr.textWidth(_value);
return this[0];
}
void text::draw(){
pix_t height = font_height();
pix_t width = content_width();
point p = adjust(width, height);
if (_align == center){
p.x += (_width - width) / 2;
}
else if (_align == right){
p.x += _width - width;
}
if (_valign == vcenter){
p.y += (_height - height) / 2;
}
else if (_valign == bottom){
p.y += _height - height;
}
spr.setTextColor(_color);
spr.drawString(_value, p.x, p.y);
}
void polyline::draw() {
detail::draw(this, false);
}
void polygen::draw() {
detail::draw(this, true);
}
|