-
Notifications
You must be signed in to change notification settings - Fork 0
/
THREEDBox.js
121 lines (100 loc) · 4.45 KB
/
THREEDBox.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
class THREEDBox {
static get inputProperties () {
return [
`--threedbox-angle-vertical`,
`--threedbox-angle-horitzontal`,
`--threedbox-padding`,
`--threedbox-color`,
`--threedbox-color-back`,
`--threedbox-color-border`,
];
}
static get inputArguments() { return ['<length>']; }
paint(ctx, size, props) {
let DBOX_ANGLE_VERTICAL = parseInt(props.get(`--threedbox-angle-vertical`));
let DBOX_ANGLE_HORITZONTAL = parseInt(props.get(`--threedbox-angle-horitzontal`));
const DBOX_PADDING = parseInt(props.get(`--threedbox-padding`));
const DBOX_COLOR = props.get(`--threedbox-color`).toString().trim();
const DBOX_COLOR_BACK = props.get(`--threedbox-color-back`).toString().trim();
const DBOX_COLOR_BORDER = props.get(`--threedbox-color-border`).toString().trim();
ctx.lineWidth = 1;
/* CUBE FRONT */
ctx.beginPath();
ctx.strokeStyle = DBOX_COLOR_BORDER;
ctx.moveTo(DBOX_PADDING,DBOX_PADDING);
ctx.lineTo(size.width-DBOX_PADDING, DBOX_PADDING);
ctx.lineTo(size.width-DBOX_PADDING, size.height-DBOX_PADDING);
ctx.lineTo(DBOX_PADDING,size.height-DBOX_PADDING);
ctx.lineTo(DBOX_PADDING,DBOX_PADDING);
ctx.fillStyle = DBOX_COLOR;
ctx.fill();
ctx.stroke();
if(DBOX_ANGLE_HORITZONTAL !== 0 || DBOX_ANGLE_VERTICAL !== 0) {
if(DBOX_ANGLE_HORITZONTAL >= DBOX_PADDING) {
DBOX_ANGLE_HORITZONTAL = DBOX_PADDING-1;
}
if(DBOX_ANGLE_VERTICAL >= DBOX_PADDING) {
DBOX_ANGLE_VERTICAL = DBOX_PADDING-1;
}
if(DBOX_ANGLE_HORITZONTAL <= DBOX_PADDING*-1) {
DBOX_ANGLE_HORITZONTAL = DBOX_PADDING*-1+1;
}
if(DBOX_ANGLE_VERTICAL <= DBOX_PADDING*-1) {
DBOX_ANGLE_VERTICAL = DBOX_PADDING*-1+1;
}
/* POINT CENTER */
//ctx.fillStyle = '#FF0000';
//ctx.fillRect(size.width/2, size.height/2,1,1);
/* POINT OF ANGLE */
//ctx.fillStyle = '#1100fc';
//ctx.fillRect(size.width/2+DBOX_ANGLE_HORITZONTAL, size.height/2+DBOX_ANGLE_VERTICAL,1,1);
if(DBOX_ANGLE_HORITZONTAL < 0) {
/* CUBE RIGHT */
ctx.beginPath();
ctx.strokeStyle = DBOX_COLOR_BORDER;
ctx.fillStyle = DBOX_COLOR_BACK;
ctx.moveTo(size.width - DBOX_PADDING,DBOX_PADDING);
ctx.lineTo(size.width - DBOX_PADDING - DBOX_ANGLE_HORITZONTAL, DBOX_PADDING - DBOX_ANGLE_VERTICAL);
ctx.lineTo(size.width - DBOX_PADDING - DBOX_ANGLE_HORITZONTAL, size.height - DBOX_PADDING - DBOX_ANGLE_VERTICAL);
ctx.lineTo(size.width - DBOX_PADDING,size.height - DBOX_PADDING)
ctx.fill();
ctx.stroke();
} else {
/* CUBE LEFT */
ctx.beginPath();
ctx.strokeStyle = DBOX_COLOR_BORDER;
ctx.fillStyle = DBOX_COLOR_BACK;
ctx.moveTo(DBOX_PADDING,DBOX_PADDING);
ctx.lineTo(DBOX_PADDING - DBOX_ANGLE_HORITZONTAL, DBOX_PADDING - DBOX_ANGLE_VERTICAL);
ctx.lineTo(DBOX_PADDING - DBOX_ANGLE_HORITZONTAL, size.height - DBOX_PADDING - DBOX_ANGLE_VERTICAL);
ctx.lineTo(DBOX_PADDING,size.height - DBOX_PADDING)
ctx.fill();
ctx.stroke();
}
if(DBOX_ANGLE_VERTICAL > 0) {
/* CUBE UP */
ctx.beginPath();
ctx.strokeStyle = DBOX_COLOR_BORDER;
ctx.fillStyle = DBOX_COLOR_BACK;
ctx.moveTo(DBOX_PADDING,DBOX_PADDING);
ctx.lineTo(DBOX_PADDING - DBOX_ANGLE_HORITZONTAL, DBOX_PADDING - DBOX_ANGLE_VERTICAL);
ctx.lineTo(size.width-DBOX_PADDING - DBOX_ANGLE_HORITZONTAL, DBOX_PADDING - DBOX_ANGLE_VERTICAL);
ctx.lineTo(size.width-DBOX_PADDING, DBOX_PADDING);
ctx.fill();
ctx.stroke();
} else {
/* CUBE DOWN */
ctx.beginPath();
ctx.strokeStyle = DBOX_COLOR_BORDER;
ctx.fillStyle = DBOX_COLOR_BACK;
ctx.moveTo(DBOX_PADDING,size.height - DBOX_PADDING);
ctx.lineTo(DBOX_PADDING - DBOX_ANGLE_HORITZONTAL,size.height - DBOX_PADDING - DBOX_ANGLE_VERTICAL);
ctx.lineTo(size.width-DBOX_PADDING - DBOX_ANGLE_HORITZONTAL,size.height - DBOX_PADDING - DBOX_ANGLE_VERTICAL);
ctx.lineTo(size.width-DBOX_PADDING,size.height - DBOX_PADDING);
ctx.fill();
ctx.stroke();
}
}
}
}
registerPaint('threedbox', THREEDBox);