-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCircle.h
68 lines (61 loc) · 2.69 KB
/
Circle.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
#ifndef MY_CIRCLE_H
#define MY_CIRCLE_H
#include "SVGElement.h"
class my_circle : public SVGElement {
private:
double cx, cy, r;
double stroke_width, stroke_opacity, fill_opacity;
string fill;
Color stroke;
string transform;
public:
my_circle(string name, string transform, double cx = 0, double cy = 0,
double r = 1, Color stroke = Color(0, 0, 0),
double stroke_width = 1, double stroke_opacity = 1,
string fill = "rgb(0, 0, 0)", double fill_opacity = 0)
: cx(cx), cy(cy), r(r), stroke(stroke), fill(fill),
stroke_width(stroke_width), stroke_opacity(stroke_opacity),
fill_opacity(fill_opacity), SVGElement(name), transform(transform) {}
void render(Graphics &graphic, 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;
}
}
graphic.FillEllipse(brush, static_cast<REAL>(this->cx - this->r),
static_cast<REAL>(this->cy - this->r),
static_cast<REAL>(this->r * 2),
static_cast<REAL>(this->r * 2));
graphic.DrawEllipse(&pen, static_cast<REAL>(this->cx - this->r),
static_cast<REAL>(this->cy - this->r),
static_cast<REAL>(this->r * 2),
static_cast<REAL>(this->r * 2));
return;
}
Color filll = stoc(this->fill);
Color strokeColor(255 * this->stroke_opacity, this->stroke.GetR(),
this->stroke.GetG(), this->stroke.GetB());
Color fillColor(255 * this->fill_opacity, filll.GetR(), filll.GetG(),
filll.GetB());
Pen pen(strokeColor, this->stroke_width);
SolidBrush brush(fillColor);
graphic.FillEllipse(&brush, static_cast<REAL>(this->cx - this->r),
static_cast<REAL>(this->cy - this->r),
static_cast<REAL>(this->r * 2),
static_cast<REAL>(this->r * 2));
graphic.DrawEllipse(&pen, static_cast<REAL>(this->cx - this->r),
static_cast<REAL>(this->cy - this->r),
static_cast<REAL>(this->r * 2),
static_cast<REAL>(this->r * 2));
}
~my_circle() override {}
string getTransform() override { return transform; }
};
#endif