-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolyline.h
72 lines (65 loc) · 2.87 KB
/
polyline.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef MY_POLYLINE_H
#define MY_POLYLINE_H
#include "SVGElement.h"
//<polyline stroke = "rgb(255, 0, 0)" stroke - width = "2" stroke - opacity =
//"0.7" fill = "rgb(0, 255, 255)" fill - opacity = "0.5" points = "5,37 15,37
// 15,32 25,32 25,37 35,37 35,25 45,25 45,37 55,37 55,17 65,17 65,37 75,37 75,10
// 85,10 85,37 95,37 95,2 105,2 105,37 115,37" / > <polyline points = "0,40
// 40,40 40,80 80,80 80,120 120,120 120,140" fill - opacity = "0.5" / >
class my_polyline : public SVGElement {
private:
double *points;
int num_points;
Color stroke;
string fill;
double stroke_width, stroke_opacity, fill_opacity;
string transform;
public:
my_polyline(string name, string transform, double *points = nullptr,
double num_points = 0, Color stroke = Color(0, 0, 0),
double stroke_width = 1, double stroke_opacity = 1,
string fill = "rgb(0, 0, 0)", double fill_opacity = 1)
: points(points), num_points(num_points), stroke(stroke), fill(fill),
stroke_width(stroke_width), stroke_opacity(stroke_opacity),
fill_opacity(fill_opacity), SVGElement(name), transform(transform) {}
void render(Graphics &graphics, vector<LinearGradient> gradients) override {
if (fill[0] == 'u' && fill[1] == 'r' && fill[2] == 'l') {
Color strokeColor(255 * this->stroke_opacity, this->stroke.GetR(),
this->stroke.GetG(), this->stroke.GetB());
Pen pen(strokeColor, this->stroke_width);
string id = extractID(fill);
LinearGradientBrush *brush = nullptr;
for (auto gradient : gradients) {
if (gradient.getId() == id) {
brush = gradient.createBrush();
break;
}
}
Point *point_array = new Point[this->num_points / 2];
for (int i = 0; i < this->num_points; i += 2) {
point_array[i / 2].X = this->points[i];
point_array[i / 2].Y = this->points[i + 1];
}
graphics.DrawLines(&pen, point_array, this->num_points / 2);
graphics.FillPolygon(brush, point_array, this->num_points / 2);
delete[] point_array;
return;
}
Color filll = stoc(fill);
Color stroke_color(255 * this->stroke_opacity, this->stroke.GetR(),
this->stroke.GetG(), this->stroke.GetB());
Pen pen(stroke_color, this->stroke_width);
SolidBrush brush(Color(this->fill_opacity * 255, filll.GetR(), filll.GetG(),
filll.GetB()));
Point *point_array = new Point[this->num_points / 2];
for (int i = 0; i < this->num_points; i += 2) {
point_array[i / 2].X = this->points[i];
point_array[i / 2].Y = this->points[i + 1];
}
graphics.DrawLines(&pen, point_array, this->num_points / 2);
graphics.FillPolygon(&brush, point_array, this->num_points / 2);
}
~my_polyline() override { delete[] this->points; }
string getTransform() override { return this->transform; }
};
#endif