-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRect.h
63 lines (56 loc) · 2.42 KB
/
Rect.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
#ifndef MY_RECT_H
#define MY_RECT_H
#include "SVGElement.h"
class my_rect : public SVGElement {
private:
double x, y, width, height;
Color stroke;
string fill;
double stroke_width, stroke_opacity, fill_opacity;
string transform;
public:
my_rect(string name, string transform, double x = 0, double y = 0,
double width = 1, double height = 1, Color stroke = Color(0, 0, 0),
double stroke_width = 1, double stroke_opacity = 1,
string fill = "rgb(0, 0, 0)", double fill_opacity = 1)
: x(x), y(y), width(width), height(height), 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;
}
}
graphics.FillRectangle(
brush, static_cast<REAL>(this->x), static_cast<REAL>(this->y),
static_cast<REAL>(this->width), static_cast<REAL>(this->height));
graphics.DrawRectangle(
&pen, static_cast<REAL>(this->x), static_cast<REAL>(this->y),
static_cast<REAL>(this->width), static_cast<REAL>(this->height));
return;
}
Color stroke_color(255 * this->stroke_opacity, this->stroke.GetR(),
this->stroke.GetG(), this->stroke.GetB());
Pen pen(stroke_color, this->stroke_width);
Color filll = stoc(fill);
SolidBrush brush(Color(this->fill_opacity * 255, filll.GetR(), filll.GetG(),
filll.GetB()));
graphics.FillRectangle(
&brush, static_cast<REAL>(this->x), static_cast<REAL>(this->y),
static_cast<REAL>(this->width), static_cast<REAL>(this->height));
graphics.DrawRectangle(
&pen, static_cast<REAL>(this->x), static_cast<REAL>(this->y),
static_cast<REAL>(this->width), static_cast<REAL>(this->height));
}
~my_rect() override {}
string getTransform() override { return this->transform; }
};
#endif