wgge 0.1.28 → 0.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -19,14 +19,26 @@ export default class CanvasRenderer extends RendererBase {
|
|
|
19
19
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
activate() {
|
|
23
23
|
this.context2d = this.canvas.getContext('2d');
|
|
24
|
+
|
|
25
|
+
super.activate();
|
|
24
26
|
}
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
deactivate() {
|
|
29
|
+
super.deactivate();
|
|
30
|
+
|
|
27
31
|
this.context2d = null;
|
|
28
32
|
}
|
|
29
33
|
|
|
34
|
+
checkContext() {
|
|
35
|
+
const ok = (this.context2d !== null);
|
|
36
|
+
if (!ok) {
|
|
37
|
+
console.error('No context to draw!');
|
|
38
|
+
}
|
|
39
|
+
return ok;
|
|
40
|
+
}
|
|
41
|
+
|
|
30
42
|
/**
|
|
31
43
|
*
|
|
32
44
|
* @param {Vector2} start
|
|
@@ -34,6 +46,7 @@ export default class CanvasRenderer extends RendererBase {
|
|
|
34
46
|
* @param {CanvasGradient|string} fill
|
|
35
47
|
*/
|
|
36
48
|
drawRect(start, size, fill = 'black') {
|
|
49
|
+
if (!this.checkContext()) return;
|
|
37
50
|
const end = start.add(size);
|
|
38
51
|
this.context2d.fillStyle = fill;
|
|
39
52
|
this.context2d.fillRect(start.x, start.y, end.x, end.y);
|
|
@@ -48,6 +61,7 @@ export default class CanvasRenderer extends RendererBase {
|
|
|
48
61
|
* @param {[[Number, string|color]]} stops
|
|
49
62
|
*/
|
|
50
63
|
drawGradient(start, size, gradientStart, gradientSize, stops) {
|
|
64
|
+
if (!this.checkContext()) return;
|
|
51
65
|
const gradientEnd = gradientStart.add(gradientSize);
|
|
52
66
|
const grd = this.context2d.createLinearGradient(gradientStart.x, gradientStart.y, gradientEnd.x, gradientEnd.y);
|
|
53
67
|
stops.forEach((s) => {
|
|
@@ -73,6 +87,7 @@ export default class CanvasRenderer extends RendererBase {
|
|
|
73
87
|
startAngle = 0,
|
|
74
88
|
endAngle = 2 * Math.PI
|
|
75
89
|
) {
|
|
90
|
+
if (!this.checkContext()) return;
|
|
76
91
|
this.context2d.beginPath();
|
|
77
92
|
this.context2d.fillStyle = (fill) ? fill : 'transparent';
|
|
78
93
|
this.context2d.strokeStyle = stroke ? stroke.color ? stroke.color : 'orange' : 'transparent';
|
|
@@ -94,7 +109,7 @@ export default class CanvasRenderer extends RendererBase {
|
|
|
94
109
|
}
|
|
95
110
|
|
|
96
111
|
drawImage(image, drawStart, drawEnd, imageStart, imageEnd, opacity = 1, clear = true) {
|
|
97
|
-
if (!(image && this.
|
|
112
|
+
if (!(image && this.checkContext())) return;
|
|
98
113
|
if (clear) this.context2d.clearRect(drawStart.x, drawStart.y, drawEnd.x, drawEnd.y);
|
|
99
114
|
this.context2d.globalAlpha = opacity;
|
|
100
115
|
console.log(
|
|
@@ -73,10 +73,13 @@ export default class ImageViewModel extends ObjectModel {
|
|
|
73
73
|
this.viewSize.addEventListener('change', () => this.updateCoordinates());
|
|
74
74
|
this.actualZoom.addEventListener('change', () => this.updateCoordinates());
|
|
75
75
|
this.image.size.addEventListener('change', () => this.updateCoordinates());
|
|
76
|
+
|
|
77
|
+
this.updateOpacity();
|
|
78
|
+
this.updateZoom();
|
|
76
79
|
}
|
|
77
80
|
|
|
78
81
|
updateOpacity() {
|
|
79
|
-
this.
|
|
82
|
+
this.actualOpacity.set(NumberHelper.between(0, 1, this.opacity.get()));
|
|
80
83
|
}
|
|
81
84
|
|
|
82
85
|
updateCoordinates() {
|