camstreamerlib 3.5.2 → 4.0.0-beta.2
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.
- package/CamOverlayAPI.d.ts +11 -28
- package/CamOverlayAPI.js +116 -138
- package/CamOverlayDrawingAPI.js +26 -18
- package/CamOverlayPainter/Frame.js +167 -182
- package/CamOverlayPainter/Painter.js +80 -101
- package/CamOverlayPainter/ResourceManager.js +31 -46
- package/CamScripterAPI.d.ts +19 -0
- package/CamScripterAPI.js +66 -0
- package/CamScripterAPICameraEventsGenerator.js +22 -16
- package/CamStreamerAPI.d.ts +5 -27
- package/CamStreamerAPI.js +45 -71
- package/CamSwitcherAPI.d.ts +38 -71
- package/CamSwitcherAPI.js +329 -91
- package/CamSwitcherEvents.d.ts +15 -33
- package/CamSwitcherEvents.js +53 -97
- package/CreatePackage.js +5 -7
- package/README.md +3 -1
- package/VapixAPI.d.ts +66 -0
- package/VapixAPI.js +454 -0
- package/VapixEvents.js +18 -16
- package/errors/errors.d.ts +34 -0
- package/errors/errors.js +66 -0
- package/events/AxisCameraStationEvents.js +29 -42
- package/events/GenetecAgent.d.ts +14 -15
- package/events/GenetecAgent.js +81 -100
- package/internal/Digest.js +5 -11
- package/internal/ProxyClient.d.ts +11 -0
- package/internal/ProxyClient.js +40 -0
- package/internal/common.d.ts +19 -4
- package/internal/common.js +11 -26
- package/internal/constants.d.ts +1 -0
- package/internal/constants.js +1 -0
- package/internal/transformers.d.ts +5 -0
- package/internal/transformers.js +25 -0
- package/internal/utils.d.ts +11 -0
- package/internal/utils.js +34 -0
- package/internal/versionCompare.d.ts +6 -0
- package/internal/versionCompare.js +44 -0
- package/node/DefaultClient.d.ts +15 -0
- package/node/DefaultClient.js +50 -0
- package/{internal → node}/HttpRequestSender.d.ts +2 -2
- package/node/HttpRequestSender.js +85 -0
- package/{HttpServer.d.ts → node/HttpServer.d.ts} +1 -1
- package/{HttpServer.js → node/HttpServer.js} +22 -24
- package/{internal → node}/WsClient.d.ts +1 -1
- package/{internal → node}/WsClient.js +32 -39
- package/node/WsEventClient.d.ts +13 -0
- package/node/WsEventClient.js +18 -0
- package/package.json +7 -3
- package/types/CamOverlayAPI.d.ts +188 -0
- package/types/CamOverlayAPI.js +44 -0
- package/types/CamScripterAPI.d.ts +67 -0
- package/types/CamScripterAPI.js +17 -0
- package/types/CamStreamerAPI.d.ts +139 -0
- package/types/CamStreamerAPI.js +25 -0
- package/types/CamSwitcherAPI.d.ts +814 -0
- package/types/CamSwitcherAPI.js +134 -0
- package/types/CamswitcherEvents.d.ts +491 -0
- package/types/CamswitcherEvents.js +59 -0
- package/types/VapixAPI.d.ts +1704 -0
- package/types/VapixAPI.js +129 -0
- package/types/common.d.ts +37 -0
- package/types/common.js +11 -0
- package/web/DefaultClient.d.ts +6 -0
- package/web/DefaultClient.js +16 -0
- package/web/WsClient.d.ts +13 -0
- package/web/WsClient.js +58 -0
- package/CameraVapix.d.ts +0 -98
- package/CameraVapix.js +0 -441
- package/DefaultAgent.d.ts +0 -15
- package/DefaultAgent.js +0 -68
- package/internal/HttpRequestSender.js +0 -117
|
@@ -1,40 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
export class Frame extends EventEmitter {
|
|
3
|
+
enabled;
|
|
4
|
+
posX;
|
|
5
|
+
posY;
|
|
6
|
+
width;
|
|
7
|
+
height;
|
|
8
|
+
text = '';
|
|
9
|
+
fontColor;
|
|
10
|
+
fontName;
|
|
11
|
+
font;
|
|
12
|
+
align = 'A_LEFT';
|
|
13
|
+
textType = 'TFM_OVERFLOW';
|
|
14
|
+
bgColor;
|
|
15
|
+
bgImageName;
|
|
16
|
+
bgImage;
|
|
17
|
+
bgType;
|
|
18
|
+
borderRadius;
|
|
19
|
+
borderWidth;
|
|
20
|
+
borderColor;
|
|
21
|
+
customDraw;
|
|
22
|
+
layer;
|
|
23
|
+
children = new Array();
|
|
15
24
|
constructor(opt) {
|
|
16
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
17
25
|
super();
|
|
18
|
-
this.
|
|
19
|
-
this.align = 'A_LEFT';
|
|
20
|
-
this.textType = 'TFM_OVERFLOW';
|
|
21
|
-
this.children = new Array();
|
|
22
|
-
this.enabled = (_a = opt.enabled) !== null && _a !== void 0 ? _a : true;
|
|
26
|
+
this.enabled = opt.enabled ?? true;
|
|
23
27
|
this.posX = opt.x;
|
|
24
28
|
this.posY = opt.y;
|
|
25
29
|
this.width = opt.width;
|
|
26
30
|
this.height = opt.height;
|
|
27
|
-
this.setText(
|
|
28
|
-
this.fontColor =
|
|
31
|
+
this.setText(opt.text ?? '', 'A_LEFT');
|
|
32
|
+
this.fontColor = opt.fontColor ?? [1.0, 1.0, 1.0];
|
|
29
33
|
this.fontName = opt.font;
|
|
30
34
|
this.bgColor = opt.bgColor;
|
|
31
35
|
this.bgImageName = opt.bgImage;
|
|
32
36
|
this.bgType = opt.bgType;
|
|
33
|
-
this.borderRadius =
|
|
34
|
-
this.borderWidth =
|
|
35
|
-
this.borderColor =
|
|
37
|
+
this.borderRadius = opt.borderRadius ?? 0;
|
|
38
|
+
this.borderWidth = opt.borderWidth ?? 0;
|
|
39
|
+
this.borderColor = opt.borderColor ?? [1, 1, 1, 1];
|
|
36
40
|
this.customDraw = opt.customDraw;
|
|
37
|
-
this.layer =
|
|
41
|
+
this.layer = opt.layer ?? 0;
|
|
38
42
|
}
|
|
39
43
|
enable() {
|
|
40
44
|
this.enabled = true;
|
|
@@ -141,172 +145,153 @@ class Frame extends events_1.EventEmitter {
|
|
|
141
145
|
layoutChanged() {
|
|
142
146
|
this.emit('layoutChanged');
|
|
143
147
|
}
|
|
144
|
-
displayImage(cod, resourceManager, cairo, ppX, ppY, scale, layer) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
yield this.displayOwnImage(cod, cairo, ppX, ppY, scale);
|
|
154
|
-
}
|
|
155
|
-
for (const child of this.children) {
|
|
156
|
-
yield child.displayImage(cod, resourceManager, cairo, ppX, ppY, scale, layer);
|
|
157
|
-
}
|
|
158
|
-
yield cod.cairo('cairo_restore', cairo);
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
prepareResources(resourceManager) {
|
|
163
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
-
if (this.bgImageName !== undefined) {
|
|
165
|
-
this.bgImage = yield resourceManager.image(this.bgImageName);
|
|
166
|
-
}
|
|
167
|
-
if (this.fontName !== undefined) {
|
|
168
|
-
this.font = yield resourceManager.font(this.fontName);
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
displayOwnImage(cod, cairo, ppX, ppY, scale) {
|
|
173
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
-
if (!this.enabled) {
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
const promises = new Array();
|
|
178
|
-
if (this.font !== undefined) {
|
|
179
|
-
promises.push(cod.cairo('cairo_set_font_face', cairo, this.font.var));
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
promises.push(cod.cairo('cairo_set_font_face', cairo, 'NULL'));
|
|
183
|
-
}
|
|
184
|
-
if (this.bgColor !== undefined) {
|
|
185
|
-
promises.push(this.drawFrame(cod, cairo, scale, ppX, ppY));
|
|
186
|
-
}
|
|
187
|
-
if (this.bgImage !== undefined) {
|
|
188
|
-
promises.push(this.drawImage(cod, cairo, scale, ppX, ppY));
|
|
189
|
-
}
|
|
190
|
-
if (this.borderWidth > 0) {
|
|
191
|
-
promises.push(this.drawBorder(cod, cairo, scale, ppX, ppY));
|
|
148
|
+
async displayImage(cod, resourceManager, cairo, ppX, ppY, scale, layer) {
|
|
149
|
+
if (this.enabled) {
|
|
150
|
+
const posX = ppX + this.posX;
|
|
151
|
+
const posY = ppY + this.posY;
|
|
152
|
+
await this.prepareResources(resourceManager);
|
|
153
|
+
await cod.cairo('cairo_save', cairo);
|
|
154
|
+
await this.clipDrawing(cod, cairo, scale, posX, posY);
|
|
155
|
+
if (this.layer === layer) {
|
|
156
|
+
await this.displayOwnImage(cod, cairo, posX, posY, scale);
|
|
192
157
|
}
|
|
193
|
-
|
|
194
|
-
|
|
158
|
+
for (const child of this.children) {
|
|
159
|
+
await child.displayImage(cod, resourceManager, cairo, posX, posY, scale, layer);
|
|
195
160
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
promises.push(cod.cairo('cairo_translate', cairo, scale * ppX, scale * ppY));
|
|
199
|
-
promises.push(cod.cairo('cairo_scale', cairo, scale, scale));
|
|
200
|
-
promises.push(this.customDraw(cod, cairo, { width: this.width, height: this.height }));
|
|
201
|
-
}
|
|
202
|
-
yield Promise.all(promises);
|
|
203
|
-
});
|
|
161
|
+
await cod.cairo('cairo_restore', cairo);
|
|
162
|
+
}
|
|
204
163
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
cod.cairo('cairo_clip', cairo),
|
|
213
|
-
]);
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
drawFrame(cod, cairo, scale, ppX, ppY) {
|
|
217
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
218
|
-
if (this.bgColor) {
|
|
219
|
-
const promises = [
|
|
220
|
-
cod.cairo('cairo_identity_matrix', cairo),
|
|
221
|
-
cod.cairo('cairo_translate', cairo, scale * ppX, scale * ppY),
|
|
222
|
-
cod.cairo('cairo_scale', cairo, scale, scale),
|
|
223
|
-
cod.cairo('cairo_set_source_rgba', cairo, this.bgColor[0], this.bgColor[1], this.bgColor[2], this.bgColor[3]),
|
|
224
|
-
cod.cairo('cairo_rectangle', cairo, 0, 0, this.width, this.height),
|
|
225
|
-
cod.cairo('cairo_fill', cairo),
|
|
226
|
-
cod.cairo('cairo_stroke', cairo),
|
|
227
|
-
];
|
|
228
|
-
yield Promise.all(promises);
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
throw new Error('Color of the frame is undefined.');
|
|
232
|
-
}
|
|
233
|
-
});
|
|
164
|
+
async prepareResources(resourceManager) {
|
|
165
|
+
if (this.bgImageName !== undefined) {
|
|
166
|
+
this.bgImage = await resourceManager.image(this.bgImageName);
|
|
167
|
+
}
|
|
168
|
+
if (this.fontName !== undefined) {
|
|
169
|
+
this.font = await resourceManager.font(this.fontName);
|
|
170
|
+
}
|
|
234
171
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
172
|
+
async displayOwnImage(cod, cairo, ppX, ppY, scale) {
|
|
173
|
+
if (!this.enabled) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const promises = new Array();
|
|
177
|
+
if (this.font !== undefined) {
|
|
178
|
+
promises.push(cod.cairo('cairo_set_font_face', cairo, this.font.var));
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
promises.push(cod.cairo('cairo_set_font_face', cairo, 'NULL'));
|
|
182
|
+
}
|
|
183
|
+
if (this.bgColor !== undefined) {
|
|
184
|
+
promises.push(this.drawFrame(cod, cairo, scale, ppX, ppY));
|
|
185
|
+
}
|
|
186
|
+
if (this.bgImage !== undefined) {
|
|
187
|
+
promises.push(this.drawImage(cod, cairo, scale, ppX, ppY));
|
|
188
|
+
}
|
|
189
|
+
if (this.borderWidth > 0) {
|
|
190
|
+
promises.push(this.drawBorder(cod, cairo, scale, ppX, ppY));
|
|
191
|
+
}
|
|
192
|
+
if (this.text) {
|
|
193
|
+
promises.push(this.drawText(cod, cairo, scale, ppX, ppY));
|
|
194
|
+
}
|
|
195
|
+
if (this.customDraw) {
|
|
244
196
|
promises.push(cod.cairo('cairo_identity_matrix', cairo));
|
|
245
197
|
promises.push(cod.cairo('cairo_translate', cairo, scale * ppX, scale * ppY));
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
else if (this.bgType === 'fit') {
|
|
252
|
-
const sx = this.width / bgWidth;
|
|
253
|
-
const sy = this.height / bgHeight;
|
|
254
|
-
const scaleRatio = scale * Math.min(sx, sy);
|
|
255
|
-
promises.push(cod.cairo('cairo_scale', cairo, scaleRatio, scaleRatio));
|
|
256
|
-
}
|
|
257
|
-
else {
|
|
258
|
-
promises.push(cod.cairo('cairo_scale', cairo, scale, scale));
|
|
259
|
-
}
|
|
260
|
-
promises.push(cod.cairo('cairo_set_source_surface', cairo, bgImage, 0, 0));
|
|
261
|
-
promises.push(cod.cairo('cairo_paint', cairo));
|
|
262
|
-
yield Promise.all(promises);
|
|
263
|
-
});
|
|
198
|
+
promises.push(cod.cairo('cairo_scale', cairo, scale, scale));
|
|
199
|
+
promises.push(this.customDraw(cod, cairo, { width: this.width, height: this.height }));
|
|
200
|
+
}
|
|
201
|
+
await Promise.all(promises);
|
|
264
202
|
}
|
|
265
|
-
|
|
266
|
-
|
|
203
|
+
async clipDrawing(cod, cairo, scale, ppX, ppY) {
|
|
204
|
+
if (this.borderRadius === 0) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
await Promise.all([
|
|
208
|
+
this.drawRectPath(cod, cairo, scale, ppX, ppY, this.borderRadius),
|
|
209
|
+
cod.cairo('cairo_clip', cairo),
|
|
210
|
+
]);
|
|
211
|
+
}
|
|
212
|
+
async drawFrame(cod, cairo, scale, ppX, ppY) {
|
|
213
|
+
if (this.bgColor) {
|
|
267
214
|
const promises = [
|
|
268
215
|
cod.cairo('cairo_identity_matrix', cairo),
|
|
269
|
-
cod.cairo('
|
|
270
|
-
cod.
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
drawBorder(cod, cairo, scale, ppX, ppY) {
|
|
276
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
277
|
-
yield Promise.all([
|
|
278
|
-
this.drawRectPath(cod, cairo, scale, ppX, ppY, this.borderRadius),
|
|
279
|
-
cod.cairo('cairo_set_source_rgba', cairo, this.borderColor[0], this.borderColor[1], this.borderColor[2], this.borderColor[3]),
|
|
280
|
-
cod.cairo('cairo_set_line_width', cairo, this.borderWidth),
|
|
216
|
+
cod.cairo('cairo_translate', cairo, scale * ppX, scale * ppY),
|
|
217
|
+
cod.cairo('cairo_scale', cairo, scale, scale),
|
|
218
|
+
cod.cairo('cairo_set_source_rgba', cairo, this.bgColor[0], this.bgColor[1], this.bgColor[2], this.bgColor[3]),
|
|
219
|
+
cod.cairo('cairo_rectangle', cairo, 0, 0, this.width, this.height),
|
|
220
|
+
cod.cairo('cairo_fill', cairo),
|
|
281
221
|
cod.cairo('cairo_stroke', cairo),
|
|
222
|
+
];
|
|
223
|
+
await Promise.all(promises);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
throw new Error('Color of the frame is undefined.');
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
async drawImage(cod, cairo, scale, ppX, ppY) {
|
|
230
|
+
if (this.bgImage === undefined) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const bgImage = this.bgImage.var;
|
|
234
|
+
const bgWidth = this.bgImage.width;
|
|
235
|
+
const bgHeight = this.bgImage.height;
|
|
236
|
+
const promises = new Array();
|
|
237
|
+
promises.push(cod.cairo('cairo_identity_matrix', cairo));
|
|
238
|
+
promises.push(cod.cairo('cairo_translate', cairo, scale * ppX, scale * ppY));
|
|
239
|
+
if (this.bgType === 'fill') {
|
|
240
|
+
const sx = (scale * this.width) / bgWidth;
|
|
241
|
+
const sy = (scale * this.height) / bgHeight;
|
|
242
|
+
promises.push(cod.cairo('cairo_scale', cairo, sx, sy));
|
|
243
|
+
}
|
|
244
|
+
else if (this.bgType === 'fit') {
|
|
245
|
+
const sx = this.width / bgWidth;
|
|
246
|
+
const sy = this.height / bgHeight;
|
|
247
|
+
const scaleRatio = scale * Math.min(sx, sy);
|
|
248
|
+
promises.push(cod.cairo('cairo_scale', cairo, scaleRatio, scaleRatio));
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
promises.push(cod.cairo('cairo_scale', cairo, scale, scale));
|
|
252
|
+
}
|
|
253
|
+
promises.push(cod.cairo('cairo_set_source_surface', cairo, bgImage, 0, 0));
|
|
254
|
+
promises.push(cod.cairo('cairo_paint', cairo));
|
|
255
|
+
await Promise.all(promises);
|
|
256
|
+
}
|
|
257
|
+
async drawText(cod, cairo, scale, ppX, ppY) {
|
|
258
|
+
const promises = [
|
|
259
|
+
cod.cairo('cairo_identity_matrix', cairo),
|
|
260
|
+
cod.cairo('cairo_set_source_rgb', cairo, this.fontColor[0], this.fontColor[1], this.fontColor[2]),
|
|
261
|
+
cod.writeText(cairo, '' + this.text, Math.floor(scale * ppX), Math.floor(scale * ppY), Math.floor(scale * this.width), Math.floor(scale * this.height), this.align, this.textType),
|
|
262
|
+
];
|
|
263
|
+
await Promise.all(promises);
|
|
264
|
+
}
|
|
265
|
+
async drawBorder(cod, cairo, scale, ppX, ppY) {
|
|
266
|
+
await Promise.all([
|
|
267
|
+
this.drawRectPath(cod, cairo, scale, ppX, ppY, this.borderRadius),
|
|
268
|
+
cod.cairo('cairo_set_source_rgba', cairo, this.borderColor[0], this.borderColor[1], this.borderColor[2], this.borderColor[3]),
|
|
269
|
+
cod.cairo('cairo_set_line_width', cairo, this.borderWidth),
|
|
270
|
+
cod.cairo('cairo_stroke', cairo),
|
|
271
|
+
]);
|
|
272
|
+
}
|
|
273
|
+
async drawRectPath(cod, cairo, scale, ppX, ppY, radius) {
|
|
274
|
+
if (radius === 0) {
|
|
275
|
+
return await Promise.all([
|
|
276
|
+
cod.cairo('cairo_identity_matrix', cairo),
|
|
277
|
+
cod.cairo('cairo_translate', cairo, scale * ppX, scale * ppY),
|
|
278
|
+
cod.cairo('cairo_scale', cairo, scale, scale),
|
|
279
|
+
cod.cairo('cairo_rectangle', cairo, 0, 0, this.width, this.height),
|
|
282
280
|
]);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
cod.cairo('cairo_identity_matrix', cairo),
|
|
299
|
-
cod.cairo('cairo_translate', cairo, scale * ppX, scale * ppY),
|
|
300
|
-
cod.cairo('cairo_scale', cairo, scale, scale),
|
|
301
|
-
cod.cairo('cairo_new_sub_path', cairo),
|
|
302
|
-
cod.cairo('cairo_arc', cairo, this.width - radius, radius, radius, -90 * degrees, 0 * degrees),
|
|
303
|
-
cod.cairo('cairo_arc', cairo, this.width - radius, this.height - radius, radius, 0 * degrees, 90 * degrees),
|
|
304
|
-
cod.cairo('cairo_arc', cairo, radius, this.height - radius, radius, 90 * degrees, 180 * degrees),
|
|
305
|
-
cod.cairo('cairo_arc', cairo, radius, radius, radius, 180 * degrees, 270 * degrees),
|
|
306
|
-
cod.cairo('cairo_close_path', cairo),
|
|
307
|
-
]);
|
|
308
|
-
}
|
|
309
|
-
});
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
const degrees = Math.PI / 180;
|
|
284
|
+
return await Promise.all([
|
|
285
|
+
cod.cairo('cairo_identity_matrix', cairo),
|
|
286
|
+
cod.cairo('cairo_translate', cairo, scale * ppX, scale * ppY),
|
|
287
|
+
cod.cairo('cairo_scale', cairo, scale, scale),
|
|
288
|
+
cod.cairo('cairo_new_sub_path', cairo),
|
|
289
|
+
cod.cairo('cairo_arc', cairo, this.width - radius, radius, radius, -90 * degrees, 0 * degrees),
|
|
290
|
+
cod.cairo('cairo_arc', cairo, this.width - radius, this.height - radius, radius, 0 * degrees, 90 * degrees),
|
|
291
|
+
cod.cairo('cairo_arc', cairo, radius, this.height - radius, radius, 90 * degrees, 180 * degrees),
|
|
292
|
+
cod.cairo('cairo_arc', cairo, radius, radius, radius, 180 * degrees, 270 * degrees),
|
|
293
|
+
cod.cairo('cairo_close_path', cairo),
|
|
294
|
+
]);
|
|
295
|
+
}
|
|
310
296
|
}
|
|
311
297
|
}
|
|
312
|
-
exports.Frame = Frame;
|
|
@@ -1,21 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.ResourceManager = exports.Frame = exports.Painter = exports.COORD = void 0;
|
|
13
|
-
const CamOverlayDrawingAPI_1 = require("../CamOverlayDrawingAPI");
|
|
14
|
-
const ResourceManager_1 = require("./ResourceManager");
|
|
15
|
-
exports.ResourceManager = ResourceManager_1.default;
|
|
16
|
-
const Frame_1 = require("./Frame");
|
|
17
|
-
Object.defineProperty(exports, "Frame", { enumerable: true, get: function () { return Frame_1.Frame; } });
|
|
18
|
-
exports.COORD = {
|
|
1
|
+
import { CamOverlayDrawingAPI } from '../CamOverlayDrawingAPI';
|
|
2
|
+
import ResourceManager from './ResourceManager';
|
|
3
|
+
import { Frame } from './Frame';
|
|
4
|
+
export const COORD = {
|
|
19
5
|
top_left: [-1, -1],
|
|
20
6
|
center_left: [-1, 0],
|
|
21
7
|
bottom_left: [-1, 1],
|
|
@@ -26,16 +12,21 @@ exports.COORD = {
|
|
|
26
12
|
center_right: [1, 0],
|
|
27
13
|
bottom_right: [1, 1],
|
|
28
14
|
};
|
|
29
|
-
class Painter extends
|
|
15
|
+
export class Painter extends Frame {
|
|
16
|
+
screenWidth;
|
|
17
|
+
screenHeight;
|
|
18
|
+
coAlignment;
|
|
19
|
+
cod;
|
|
20
|
+
rm;
|
|
21
|
+
refreshLayers = true;
|
|
22
|
+
layers = [];
|
|
30
23
|
constructor(opt, coopt) {
|
|
31
24
|
super(opt);
|
|
32
|
-
this.
|
|
33
|
-
this.layers = [];
|
|
34
|
-
this.coAlignment = exports.COORD[opt.coAlignment];
|
|
25
|
+
this.coAlignment = COORD[opt.coAlignment];
|
|
35
26
|
this.screenWidth = opt.screenWidth;
|
|
36
27
|
this.screenHeight = opt.screenHeight;
|
|
37
|
-
this.cod = new
|
|
38
|
-
this.rm = new
|
|
28
|
+
this.cod = new CamOverlayDrawingAPI(coopt);
|
|
29
|
+
this.rm = new ResourceManager(this.cod);
|
|
39
30
|
}
|
|
40
31
|
get camOverlayDrawingAPI() {
|
|
41
32
|
return this.cod;
|
|
@@ -75,98 +66,86 @@ class Painter extends Frame_1.Frame {
|
|
|
75
66
|
this.screenHeight = sh;
|
|
76
67
|
}
|
|
77
68
|
setCoAlignment(coAlignment) {
|
|
78
|
-
this.coAlignment =
|
|
69
|
+
this.coAlignment = COORD[coAlignment];
|
|
79
70
|
}
|
|
80
71
|
layoutChanged() {
|
|
81
72
|
this.refreshLayers = true;
|
|
82
73
|
}
|
|
83
|
-
display(scale = 1.0) {
|
|
84
|
-
|
|
85
|
-
if (this.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
74
|
+
async display(scale = 1.0) {
|
|
75
|
+
if (this.enabled) {
|
|
76
|
+
if (this.refreshLayers) {
|
|
77
|
+
this.refreshLayers = false;
|
|
78
|
+
await this.prepareLayers();
|
|
79
|
+
}
|
|
80
|
+
let cairo;
|
|
81
|
+
let surface;
|
|
82
|
+
let lastCachedLayer;
|
|
83
|
+
for (let i = 0; i < this.layers.length; i++) {
|
|
84
|
+
const layer = this.layers[i];
|
|
85
|
+
if (layer.cairoCache !== undefined &&
|
|
86
|
+
layer.surfaceCache !== undefined &&
|
|
87
|
+
surface === undefined &&
|
|
88
|
+
cairo === undefined) {
|
|
89
|
+
lastCachedLayer = layer;
|
|
90
|
+
continue;
|
|
89
91
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
let lastCachedLayer;
|
|
93
|
-
for (let i = 0; i < this.layers.length; i++) {
|
|
94
|
-
const layer = this.layers[i];
|
|
95
|
-
if (layer.cairoCache !== undefined &&
|
|
96
|
-
layer.surfaceCache !== undefined &&
|
|
97
|
-
surface === undefined &&
|
|
98
|
-
cairo === undefined) {
|
|
99
|
-
lastCachedLayer = layer;
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
if (surface === undefined || cairo === undefined) {
|
|
103
|
-
[surface, cairo] = yield this.prepareSurface(scale, lastCachedLayer === null || lastCachedLayer === void 0 ? void 0 : lastCachedLayer.surfaceCache, lastCachedLayer === null || lastCachedLayer === void 0 ? void 0 : lastCachedLayer.cairoCache);
|
|
104
|
-
}
|
|
105
|
-
yield this.displayImage(this.cod, this.rm, cairo, -this.posX, -this.posY, scale, layer.layer);
|
|
106
|
-
if (i < this.layers.length - 1) {
|
|
107
|
-
const [surfaceToCache, cairoToCache] = yield this.prepareSurface(scale, surface, cairo);
|
|
108
|
-
layer.surfaceCache = surfaceToCache;
|
|
109
|
-
layer.cairoCache = cairoToCache;
|
|
110
|
-
}
|
|
92
|
+
if (surface === undefined || cairo === undefined) {
|
|
93
|
+
[surface, cairo] = await this.prepareSurface(scale, lastCachedLayer?.surfaceCache, lastCachedLayer?.cairoCache);
|
|
111
94
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
95
|
+
await this.displayImage(this.cod, this.rm, cairo, -this.posX, -this.posY, scale, layer.layer);
|
|
96
|
+
if (i < this.layers.length - 1) {
|
|
97
|
+
const [surfaceToCache, cairoToCache] = await this.prepareSurface(scale, surface, cairo);
|
|
98
|
+
layer.surfaceCache = surfaceToCache;
|
|
99
|
+
layer.cairoCache = cairoToCache;
|
|
115
100
|
}
|
|
116
101
|
}
|
|
117
|
-
|
|
102
|
+
if (surface !== undefined && cairo !== undefined) {
|
|
103
|
+
await this.cod.showCairoImage(surface, this.positionConvertor(this.coAlignment[0], this.screenWidth, this.posX, scale * this.width), this.positionConvertor(this.coAlignment[1], this.screenHeight, this.posY, scale * this.height));
|
|
104
|
+
await this.cleanupSurface(surface, cairo);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
118
107
|
}
|
|
119
|
-
hide() {
|
|
120
|
-
|
|
121
|
-
yield this.cod.removeImage();
|
|
122
|
-
});
|
|
108
|
+
async hide() {
|
|
109
|
+
await this.cod.removeImage();
|
|
123
110
|
}
|
|
124
|
-
invalidateLayer(layer) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
layer.cairoCache = undefined;
|
|
136
|
-
}
|
|
111
|
+
async invalidateLayer(layer) {
|
|
112
|
+
const layerIdx = this.layers.findIndex((l) => l.layer === layer);
|
|
113
|
+
if (layerIdx === -1) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
for (let i = layerIdx; i < this.layers.length; i++) {
|
|
117
|
+
const currentLayer = this.layers[i];
|
|
118
|
+
if (currentLayer.surfaceCache !== undefined && currentLayer.cairoCache !== undefined) {
|
|
119
|
+
await this.cleanupSurface(currentLayer.surfaceCache, currentLayer.cairoCache);
|
|
120
|
+
currentLayer.surfaceCache = undefined;
|
|
121
|
+
currentLayer.cairoCache = undefined;
|
|
137
122
|
}
|
|
138
|
-
}
|
|
123
|
+
}
|
|
139
124
|
}
|
|
140
|
-
prepareLayers() {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
yield this.cleanupSurface(layer.surfaceCache, layer.cairoCache);
|
|
145
|
-
}
|
|
125
|
+
async prepareLayers() {
|
|
126
|
+
for (const layer of this.layers) {
|
|
127
|
+
if (layer.surfaceCache !== undefined && layer.cairoCache !== undefined) {
|
|
128
|
+
await this.cleanupSurface(layer.surfaceCache, layer.cairoCache);
|
|
146
129
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
130
|
+
}
|
|
131
|
+
const uniqueLayers = this.getLayers();
|
|
132
|
+
const sortedLayers = Array.from(uniqueLayers).sort((a, b) => a - b);
|
|
133
|
+
this.layers = sortedLayers.map((layer) => {
|
|
134
|
+
return { layer };
|
|
152
135
|
});
|
|
153
136
|
}
|
|
154
|
-
prepareSurface(scale, cachedSurface, cachedCairo) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
return [surface.var, cairo.var];
|
|
163
|
-
});
|
|
137
|
+
async prepareSurface(scale, cachedSurface, cachedCairo) {
|
|
138
|
+
const surface = (await this.cod.cairo('cairo_image_surface_create', 'CAIRO_FORMAT_ARGB32', Math.floor(this.width * scale), Math.floor(this.height * scale)));
|
|
139
|
+
const cairo = (await this.cod.cairo('cairo_create', surface.var));
|
|
140
|
+
if (cachedSurface !== undefined && cachedCairo !== undefined) {
|
|
141
|
+
await this.cod.cairo('cairo_set_source_surface', cairo.var, cachedSurface, 0, 0);
|
|
142
|
+
await this.cod.cairo('cairo_paint', cairo.var);
|
|
143
|
+
}
|
|
144
|
+
return [surface.var, cairo.var];
|
|
164
145
|
}
|
|
165
|
-
cleanupSurface(surface, cairo) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
yield this.cod.cairo('cairo_destroy', cairo);
|
|
169
|
-
});
|
|
146
|
+
async cleanupSurface(surface, cairo) {
|
|
147
|
+
await this.cod.cairo('cairo_surface_destroy', surface);
|
|
148
|
+
await this.cod.cairo('cairo_destroy', cairo);
|
|
170
149
|
}
|
|
171
150
|
positionConvertor(alignment, screenSize, position, graphicsSize) {
|
|
172
151
|
switch (alignment) {
|
|
@@ -181,4 +160,4 @@ class Painter extends Frame_1.Frame {
|
|
|
181
160
|
}
|
|
182
161
|
}
|
|
183
162
|
}
|
|
184
|
-
|
|
163
|
+
export { Frame, ResourceManager };
|