-
Notifications
You must be signed in to change notification settings - Fork 1
/
CornerBox.js
50 lines (41 loc) · 1.36 KB
/
CornerBox.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
50
class cornerBox {
static get inputProperties () {
return [
`--cornerbox-width`,
`--cornerbox-length`,
`--cornerbox-color`,
];
}
paint(ctx, size, props) {
const lineBox = parseInt(props.get(`--cornerbox-length`));
const lineBoxwidth = parseInt(props.get(`--cornerbox-width`));
const colorBox = props.get(`--cornerbox-color`).toString().trim();
if(lineBox != 0) {
ctx.lineWidth = lineBox;
ctx.beginPath();
/* UP Left */
ctx.moveTo(0, 0);
ctx.lineTo(0, lineBoxwidth);
ctx.moveTo(0, 0);
ctx.lineTo(lineBoxwidth, 0);
/* Up Right */
ctx.moveTo(size.width-lineBoxwidth, 0);
ctx.lineTo(size.width, 0);
ctx.moveTo(size.width, 0);
ctx.lineTo(size.width, lineBoxwidth);
/* Down Left */
ctx.moveTo(0, size.height-lineBoxwidth);
ctx.lineTo(0, size.height);
ctx.moveTo(0, size.height);
ctx.lineTo(lineBoxwidth, size.height);
/* Down Right */
ctx.moveTo(size.width, size.height-lineBoxwidth);
ctx.lineTo(size.width, size.height);
ctx.moveTo(size.width, size.height);
ctx.lineTo(size.width-lineBoxwidth, size.height);
ctx.strokeStyle = colorBox;
ctx.stroke();
}
}
}
registerPaint('cornerbox', cornerBox);