-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinearGradient.h
38 lines (33 loc) · 1.03 KB
/
LinearGradient.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
#ifndef LINEAR_GRADIENT_H
#define LINEAR_GRADIENT_H
#include "Stop.h"
#include <gdiplus.h>
#include <iostream>
using namespace std;
class LinearGradient {
private:
string id;
double x1, x2, y1, y2;
vector<Stop> stops;
public:
LinearGradient(string id, double x1, double x2, double y1, double y2,
vector<Stop> stops)
: id(id), x1(x1), x2(x2), y1(y1), y2(y2), stops(stops) {}
LinearGradientBrush *&createBrush() {
LinearGradientBrush *brush =
new LinearGradientBrush(PointF(x1, y1), PointF(x2, y2), stops[0].color,
stops[stops.size() - 1].color);
Color *color = new Color[stops.size()];
for (int i = 0; i < stops.size(); i++) {
color[i] = stops[i].color;
}
float *positions = new float[stops.size()];
for (int i = 0; i < stops.size(); i++) {
positions[i] = stops[i].offset / stops[stops.size() - 1].offset;
}
brush->SetInterpolationColors(color, positions, stops.size());
return brush;
}
string getId() { return id; }
};
#endif