-
Notifications
You must be signed in to change notification settings - Fork 0
/
path.js
49 lines (43 loc) · 1.09 KB
/
path.js
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
var Path = function (id, name, settings = null, pathParts = []) {
this.id = id;
this.name = name;
this.pathParts = pathParts;
this.settings = settings;
}
Path.prototype.setPathParts = function(pathParts) {
this.pathParts = pathParts;
};
Path.prototype.addPathPart = function(pathPart) {
this.pathParts.push(pathPart);
};
Path.prototype.setSettings = function(settings) {
this.settings = settings;
};
Path.prototype.render = function(context) {
if (this.settings.strokeStyle != null) {
context.strokeStyle = this.settings.strokeStyle;
}
if (this.settings.fillStyle != null) {
context.fillStyle = this.settings.fillStyle;
}
if (this.settings.lineWidth != null) {
context.lineWidth = this.settings.lineWidth;
}
// ... TODO
context.beginPath();
this.pathParts.forEach(function (pathPart) {
if (pathPart.type == 'move') {
context.moveTo(pathPart.x, pathPart.y);
}
if (pathPart.type == 'line') {
context.lineTo(pathPart.x, pathPart.y);
}
// ... TODO
});
if (this.settings.strokeStyle != null) {
context.stroke();
}
if (this.settings.fillStyle != null) {
context.fill();
}
};