-
Notifications
You must be signed in to change notification settings - Fork 1
/
spark-platform.js
949 lines (858 loc) · 27.1 KB
/
spark-platform.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
class SparkPlatform {
init(stage) {
let _this = this
this.stage = stage
this._looping = false
this._awaitingLoop = false
this._sparkCanvas = null
this._appRoot = global.sparkscene.root
this._supportsRequestAnimationFrame = global.sparkscene && global.sparkscene.capabilities && global.sparkscene.capabilities.sparkgl && global.sparkscene.capabilities.sparkgl.api;
global.sparkscene.on('onClose', function () {
_this._appRoot = null
})
}
destroy() {}
startLoop() {
this._looping = true
if (!this._awaitingLoop) {
this.loop()
}
}
stopLoop() {
this._looping = false
}
loop() {
let self = this
let lp = function () {
self._awaitingLoop = false
if (self._looping) {
self.stage.drawFrame()
// We depend on blit to limit to 60fps.
if (self._supportsRequestAnimationFrame) {
requestAnimationFrame(lp);
} else {
if (self.changes) {
setImmediate(lp);
} else {
setTimeout(lp, 32);
}
}
self._awaitingLoop = true
}
}
setTimeout(lp, 32)
}
uploadGlTexture(gl, textureSource, source, options) {
if (options.imageRef && source == -1) {
// we'll be calling Spark's paint method directly instead of rendering a texture
return
} else {
gl.texImage2D(
gl.TEXTURE_2D,
0,
options.internalFormat,
textureSource.w,
textureSource.h,
0,
options.format,
options.type,
source
)
}
}
loadSrcTexture({ src }, cb) {
let proxyServer = ''
if (global.sparkQueryParams && global.sparkQueryParams.sparkProxyServer) {
proxyServer = global.sparkQueryParams.sparkProxyServer
}
src = src.replace(/ /g, '%20')
let imageResource = global.sparkscene.create({
t: 'imageResource',
url: src,
proxy: proxyServer,
})
let sparkImage = global.sparkscene.create({ t: 'image', resource: imageResource })
const sparkGl = this.stage.gl
sparkImage.ready.then(function () {
let texture = sparkImage.texture()
cb(null, {
source: sparkGl.createWebGLTexture(texture),
w: sparkImage.resource.w,
h: sparkImage.resource.h,
premultiplyAlpha: false,
flipBlueRed: false,
imageRef: sparkImage,
flipTextureY: true,
})
})
}
createRoundRect(cb, stage, w, h, radius, strokeWidth, strokeColor, fill, fillColor) {
if (fill === undefined) fill = true
if (strokeWidth === undefined) strokeWidth = 0
if (fillColor === undefined) fillColor = 0
fillColor = fill ? fillColor : '0x00000000'
fillColor = fillColor.toString(16)
let opacity = 1
if (fillColor.length >= 8) {
let alpha = fillColor.substring(0, 2)
let red = fillColor.substring(2, 4)
let green = fillColor.substring(4, 6)
let blue = fillColor.substring(6)
fillColor = '#' + red + green + blue
opacity = '0x' + alpha
opacity = parseInt(opacity, 16) / 255
}
let boundW = w + strokeWidth
let boundH = h + strokeWidth
let data =
'data:image/svg,' +
`<svg viewBox="0 0 ${boundW} ${boundH}" xmlns="http://www.w3.org/2000/svg">` +
`<rect x="${strokeWidth / 2}" y="${
strokeWidth / 2
}" width="${w}" height="${h}" fill="${fillColor}" fill-opacity="${opacity}" rx="${radius}" stroke="${strokeColor}" stroke-width="${strokeWidth}"/>` +
'</svg>'
let imageObj = global.sparkscene.create({ t: 'image', url: data })
imageObj.ready.then(function () {
let canvas = {}
canvas.flipTextureY = true
canvas.internal = imageObj
canvas.width = w
canvas.height = h
imageObj.w = w
imageObj.h = h
cb(null, canvas)
})
}
createShadowRect(cb, stage, w, h, radius, blur, margin) {
let boundW = w + margin * 2
let boundH = h + margin * 2
let data =
'data:image/svg,' +
'<svg viewBox="0 0 ' +
boundW +
' ' +
boundH +
'" xmlns="http://www.w3.org/2000/svg" version="1.1"> \
<linearGradient id="rectGradient" gradientUnits="userSpaceOnUse" x1="0%" y1="180%" x2="100%" y2="-60%" gradientTransform="rotate(0)"> \
<stop offset="20%" stop-color="#00FF00" stop-opacity="0.5"/> \
<stop offset="50%" stop-color="#0000FF" stop-opacity=".8"/> \
<stop offset="80%" stop-color="#00FF00" stop-opacity=".5"/> \
</linearGradient> \
<filter id="rectBlur" x="0" y="0"> \
<feGaussianBlur in="SourceGraphic" stdDeviation="' +
blur +
'" /> \
</filter> \
</defs> \
<g enable-background="new" > \
<rect x="0" y="0" width="' +
boundW +
'" height="' +
boundH +
'" fill="url(#rectGradient)" rx="' +
radius +
'" stroke-width="' +
margin +
'" filter="url(#rectBlur)"/> \
</g> \
</svg>'
let imageObj = global.sparkscene.create({ t: 'image', url: data })
imageObj.ready.then(function () {
let canvas = {}
canvas.flipTextureY = true
canvas.internal = imageObj
canvas.width = w
canvas.height = h
imageObj.w = w
imageObj.h = h
cb(null, canvas)
})
}
createSvg(cb, stage, url, w, h) {
let proxyServer = ''
if (global.sparkQueryParams && global.sparkQueryParams.sparkProxyServer) {
proxyServer = global.sparkQueryParams.sparkProxyServer
}
let imageResource = global.sparkscene.create({
t: 'imageResource',
url: url,
proxy: proxyServer,
})
let imageObj = global.sparkscene.create({ t: 'image', resource: imageResource })
imageObj.ready.then(
function () {
let canvas = {}
canvas.flipTextureY = true
canvas.internal = imageObj
canvas.width = w
canvas.height = h
imageObj.w = w
imageObj.h = h
cb(null, canvas)
},
function () {
let canvas = {}
canvas.internal = imageObj
cb(null, canvas)
}
)
}
createWebGLContext(w, h) {
let options = { width: w, height: h, title: 'WebGL' }
const windowOptions = this.stage.getOption('window')
if (windowOptions) {
options = Object.assign(options, windowOptions)
}
let gl = global.sparkgles2.init(options)
gl.canvas = {
width: w,
height: h,
style: {
set display(value) {
if (value === 'none') {
global.beginDrawing()
gl.scissor(0, 0, w, h)
gl.clear(gl.COLOR_BUFFER_BIT)
gl.scissor(0, 0, 0, 0)
global.endDrawing()
}
},
},
remove: () => {
gl.canvas.style.display = 'none'
},
}
return gl
}
getTextureOptionsForDrawingCanvas(canvas) {
let options = {}
if (canvas && canvas.internal) {
if (
canvas.internal.drawNatively &&
global.sparkscene.capabilities.sparkgl &&
global.sparkscene.capabilities.sparkgl.nativedrawing
) {
options.source = -1
} else {
options.source = this.stage.gl.createWebGLTexture(canvas.internal.texture())
}
options.w = canvas.width
options.h = canvas.height
options.imageRef = canvas.internal
if (canvas.flipTextureY) {
options.flipTextureY = true
}
}
options.premultiplyAlpha = false
options.flipBlueRed = false
return options
}
getHrTime() {
let hrTime = process.hrtime()
return 1e3 * hrTime[0] + hrTime[1] / 1e6
}
getDrawingCanvas() {
let sparkCanvas
let reuse = false // We don't reuse this canvas because textures may load async.
if (!reuse) {
this._sparkCanvas = null
}
if (this._sparkCanvas === null) {
sparkCanvas = {}
sparkCanvas.internal = global.sparkscene.create({ t: 'textCanvas' })
sparkCanvas.internal.colorMode = 'ARGB'
this._sparkCanvas = sparkCanvas
this._sparkCanvas.getContext = function () {
return sparkCanvas.internal
}
}
return this._sparkCanvas
}
nextFrame(changes) {
this.changes = changes
if (this.stage && this.stage.gl) {
this.stage.gl.scissor(0, 0, 0, 0)
}
//gles2.nextFrame(changes);
}
registerKeydownHandler(keyhandler) {
global.sparkscene.root.on('onKeyDown', function (e) {
keyhandler(e)
})
}
registerKeyupHandler(keyhandler) {
global.sparkscene.root.on('onKeyUp', function (e) {
keyhandler(e)
})
}
drawText(textTextureRenderer) {
let canvasInternal = textTextureRenderer._canvas.internal // _canvas.internal is a pxTextCanvas object created in getDrawingCanvas()
let drawPromise = new Promise((resolve) => {
canvasInternal.ready.then(() => {
// waiting for the empty scene
canvasInternal.parent = global.sparkscene.root
textTextureRenderer.setFontProperties()
canvasInternal.font.ready.then(() => {
// the font might have been coerced
canvasInternal.pixelSize =
textTextureRenderer._settings.fontSize * textTextureRenderer.getPrecision()
// Original Lightining code with some changes begins here
// Changes to the original code are:
// Replaced: `this.` => `textTextureRenderer.`
// Replaced `StageUtils.getRgbaString(color)` => `color`
// Replaced `this._canvas.width` => `canvasInternal.width` and `this._canvas.height` => `canvasInternal.height` after the line: // Add extra margin to prevent issue with clipped text when scaling.
// setFontProperties() calls are commented out as redundant
// Setting canvas label to faciliatate debugging (this is optional and can be removed):
// canvasInternal.label = textTextureRenderer._settings.text.slice(0, 10) + '..';
let renderInfo = {}
const precision = textTextureRenderer.getPrecision()
let paddingLeft = textTextureRenderer._settings.paddingLeft * precision
let paddingRight = textTextureRenderer._settings.paddingRight * precision
const fontSize = textTextureRenderer._settings.fontSize * precision
let offsetY =
textTextureRenderer._settings.offsetY === null
? null
: textTextureRenderer._settings.offsetY * precision
let lineHeight = textTextureRenderer._settings.lineHeight * precision
const w = textTextureRenderer._settings.w * precision
const h = textTextureRenderer._settings.h * precision
let wordWrapWidth = textTextureRenderer._settings.wordWrapWidth * precision
const cutSx = textTextureRenderer._settings.cutSx * precision
const cutEx = textTextureRenderer._settings.cutEx * precision
const cutSy = textTextureRenderer._settings.cutSy * precision
const cutEy = textTextureRenderer._settings.cutEy * precision
canvasInternal.label = textTextureRenderer._settings.text.slice(0, 10) + '..' // allows to distinguish different canvases by label, useful for debugging
if (global.sparkQueryParams && global.sparkQueryParams.nativeText){
canvasInternal.drawNatively = true;
}
// Set font properties.
// textTextureRenderer.setFontProperties();
// Total width.
let width = w || 2048 / textTextureRenderer.getPrecision()
// Inner width.
let innerWidth = width - paddingLeft
if (innerWidth < 10) {
width += 10 - innerWidth
innerWidth += 10 - innerWidth
}
if (!wordWrapWidth) {
wordWrapWidth = innerWidth
}
// word wrap
// preserve original text
let linesInfo
if (textTextureRenderer._settings.wordWrap) {
linesInfo = textTextureRenderer.wrapText(
textTextureRenderer._settings.text,
wordWrapWidth
)
} else {
linesInfo = { l: textTextureRenderer._settings.text.split(/(?:\r\n|\r|\n)/), n: [] }
let n = linesInfo.l.length
for (let i = 0; i < n - 1; i++) {
linesInfo.n.push(i)
}
}
let lines = linesInfo.l
if (
textTextureRenderer._settings.maxLines &&
lines.length > textTextureRenderer._settings.maxLines
) {
let usedLines = lines.slice(0, textTextureRenderer._settings.maxLines)
let otherLines = null
let suf = textTextureRenderer._settings.maxLinesSuffix
if (suf) {
// Wrap again with max lines suffix enabled.
let w = suf ? textTextureRenderer._context.measureText(suf).width : 0
let al = textTextureRenderer.wrapText(
usedLines[usedLines.length - 1],
wordWrapWidth - w
)
usedLines[usedLines.length - 1] = al.l[0] + suf
otherLines = [al.l.length > 1 ? al.l[1] : '']
} else {
otherLines = ['']
}
// Re-assemble the remaining text.
let i,
n = lines.length
let j = 0
let m = linesInfo.n.length
for (i = textTextureRenderer._settings.maxLines; i < n; i++) {
otherLines[j] += (otherLines[j] ? ' ' : '') + lines[i]
if (i + 1 < m && linesInfo.n[i + 1]) {
j++
}
}
renderInfo.remainingText = otherLines.join('\n')
renderInfo.moreTextLines = true
lines = usedLines
} else {
renderInfo.moreTextLines = false
renderInfo.remainingText = ''
}
// calculate text width
let maxLineWidth = 0
let lineWidths = []
for (let i = 0; i < lines.length; i++) {
let lineWidth = textTextureRenderer._context.measureText(lines[i]).width
lineWidths.push(lineWidth)
maxLineWidth = Math.max(maxLineWidth, lineWidth)
}
renderInfo.lineWidths = lineWidths
if (!w) {
// Auto-set width to max text length.
width = maxLineWidth + paddingLeft + paddingRight
innerWidth = maxLineWidth
}
// calculate text height
lineHeight = lineHeight || fontSize
let height
if (h) {
height = h
} else {
height =
lineHeight * (lines.length - 1) +
0.5 * fontSize +
Math.max(lineHeight, fontSize) +
offsetY
}
if (offsetY === null) {
offsetY = fontSize
}
renderInfo.w = width
renderInfo.h = height
renderInfo.lines = lines
renderInfo.precision = precision
if (!width) {
// To prevent canvas errors.
width = 1
}
if (!height) {
// To prevent canvas errors.
height = 1
}
if (cutSx || cutEx) {
width = Math.min(width, cutEx - cutSx)
}
if (cutSy || cutEy) {
height = Math.min(height, cutEy - cutSy)
}
// Add extra margin to prevent issue with clipped text when scaling.
canvasInternal.width = Math.ceil(
width + textTextureRenderer._stage.getOption('textRenderIssueMargin')
)
canvasInternal.height = Math.ceil(height)
// Canvas context has been reset.
// textTextureRenderer.setFontProperties();
if (fontSize >= 128) {
// WpeWebKit bug: must force compositing because cairo-traps-compositor will not work with text first.
textTextureRenderer._context.globalAlpha = 0.01
textTextureRenderer._context.fillRect(0, 0, 0.01, 0.01)
textTextureRenderer._context.globalAlpha = 1.0
}
if (cutSx || cutSy) {
textTextureRenderer._context.translate(-cutSx, -cutSy)
}
let linePositionX
let linePositionY
let drawLines = []
// Draw lines line by line.
for (let i = 0, n = lines.length; i < n; i++) {
linePositionX = 0
linePositionY = i * lineHeight + offsetY
if (textTextureRenderer._settings.textAlign === 'right') {
linePositionX += innerWidth - lineWidths[i]
} else if (textTextureRenderer._settings.textAlign === 'center') {
linePositionX += (innerWidth - lineWidths[i]) / 2
}
linePositionX += paddingLeft
drawLines.push({ text: lines[i], x: linePositionX, y: linePositionY, w: lineWidths[i] })
}
// Highlight.
if (textTextureRenderer._settings.highlight) {
let color = textTextureRenderer._settings.highlightColor || 0x00000000
let hlHeight =
textTextureRenderer._settings.highlightHeight * precision || fontSize * 1.5
let offset =
textTextureRenderer._settings.highlightOffset !== null
? textTextureRenderer._settings.highlightOffset * precision
: -0.5 * fontSize
const hlPaddingLeft =
textTextureRenderer._settings.highlightPaddingLeft !== null
? textTextureRenderer._settings.highlightPaddingLeft * precision
: paddingLeft
const hlPaddingRight =
textTextureRenderer._settings.highlightPaddingRight !== null
? textTextureRenderer._settings.highlightPaddingRight * precision
: paddingRight
textTextureRenderer._context.fillStyle = color
for (let i = 0; i < drawLines.length; i++) {
let drawLine = drawLines[i]
textTextureRenderer._context.fillRect(
drawLine.x - hlPaddingLeft,
drawLine.y + offset,
drawLine.w + hlPaddingRight + hlPaddingLeft,
hlHeight
)
}
}
// Text shadow.
let prevShadowSettings = null
if (textTextureRenderer._settings.shadow) {
prevShadowSettings = [
textTextureRenderer._context.shadowColor,
textTextureRenderer._context.shadowOffsetX,
textTextureRenderer._context.shadowOffsetY,
textTextureRenderer._context.shadowBlur,
]
textTextureRenderer._context.shadowColor = textTextureRenderer._settings.shadowColor
textTextureRenderer._context.shadowOffsetX =
textTextureRenderer._settings.shadowOffsetX * precision
textTextureRenderer._context.shadowOffsetY =
textTextureRenderer._settings.shadowOffsetY * precision
textTextureRenderer._context.shadowBlur =
textTextureRenderer._settings.shadowBlur * precision
}
textTextureRenderer._context.fillStyle = textTextureRenderer._settings.textColor
for (let i = 0, n = drawLines.length; i < n; i++) {
let drawLine = drawLines[i]
textTextureRenderer._context.fillText(drawLine.text, drawLine.x, drawLine.y)
}
if (prevShadowSettings) {
textTextureRenderer._context.shadowColor = prevShadowSettings[0]
textTextureRenderer._context.shadowOffsetX = prevShadowSettings[1]
textTextureRenderer._context.shadowOffsetY = prevShadowSettings[2]
textTextureRenderer._context.shadowBlur = prevShadowSettings[3]
}
if (cutSx || cutSy) {
textTextureRenderer._context.translate(cutSx, cutSy)
}
// Original Lightining code ends here
canvasInternal.ready.then(() => {
// everything is drawn
renderInfo.w = canvasInternal.w
renderInfo.h = canvasInternal.h
textTextureRenderer._canvas.width = canvasInternal.w
textTextureRenderer._canvas.height = canvasInternal.h
textTextureRenderer.renderInfo = renderInfo
resolve()
})
})
})
})
return drawPromise
}
paint(gl, obj, x, y, color, e) {
if (obj) {
let translateOnly = true
if (e && e.rotation !== 0) {
obj.r = (e.rotation * 180) / Math.PI
translateOnly = false
} else {
obj.r = 0
}
gl.beginNativeSparkRendering()
if (
typeof obj.description === 'function' &&
(obj.description() === 'pxWaylandContainer' || obj.description() === 'pxSceneContainer')
) {
obj.paint(x, y, color, false)
this.stage.forceRenderUpdate() // keep updating
} else {
obj.paint(x, y, color, translateOnly)
}
gl.endNativeSparkRendering()
}
}
getFontSetting(textTextureRenderer) {
let fontResource = textTextureRenderer._context.font
let fontFace = textTextureRenderer._settings.fontFace
let fontStyle = textTextureRenderer._settings.fontStyle.toLowerCase()
if (this._fontResources !== undefined && this._fontResources.has(fontFace)) {
fontResource = this._fontResources.get(fontFace)
if (fontResource.needsStyleCoercion(fontStyle)) {
let url = fontResource.url
fontResource = global.sparkscene.create({
t: 'fontResource',
url: url,
fontStyle: fontStyle,
})
}
}
return fontResource
}
addServiceProvider(provider) {
if (typeof provider == 'function') {
global.sparkscene.addServiceProvider(provider)
} else {
console.error('service provider need to be a function !!!')
}
}
// extensions API
static createApplicationTexture() {
return ApplicationTexture
}
}
// eslint-disable-next-line no-undef
class ApplicationTexture extends lng.Texture {
constructor(stage) {
super(stage)
let _this = this
this._ready = new Promise(function (resolve, reject) {
_this._readyResolve = resolve
_this._readyReject = reject
})
global.sparkscene.on('onClose', function () {
if (_this._app) {
_this._app.destroy()
_this._app = null
}
if (_this._optimus) {
_this._optimus.setScene(null)
_this._optimus = null
}
})
}
get id() {
return this._id
}
set id(value) {
this._id = value
this._changed()
}
get priority() {
return this._priority
}
set priority(value) {
this._priority = value
this._changed()
}
get x() {
return this._x
}
set x(value) {
this._x = value
this._changed()
}
get y() {
return this._y
}
set y(value) {
this._y = value
this._changed()
}
get cx() {
return this._cx
}
set cx(value) {
this._cx = value
this._changed()
}
get cy() {
return this._cy
}
set cy(value) {
this._cy = value
this._changed()
}
get sx() {
return this._sx
}
set sx(value) {
this._sx = value
this._changed()
}
get sy() {
return this._sy
}
set sy(value) {
this._sy = value
this._changed()
}
get r() {
return this._r
}
set r(value) {
this._r = value
this._changed()
}
get a() {
return this._a
}
set a(value) {
this._a = value
this._changed()
}
get interactive() {
return this._interactive
}
set interactive(value) {
this._interactive = value
this._changed()
}
get painting() {
return this._painting
}
set painting(value) {
this._painting = value
this._changed()
}
get clip() {
return this._clip
}
set clip(value) {
this._clip = value
this._changed()
}
get mask() {
return this._mask
}
set mask(value) {
this._mask = value
this._changed()
}
get draw() {
return this._draw
}
set draw(value) {
this._draw = value
this._changed()
}
get launchParams() {
return this._launchParams
}
set launchParams(value) {
this._launchParams = value
this._changed()
}
get ready() {
return this._ready
}
suspend(o) {
return this._app.suspend(o)
}
resume(o) {
return this._app.resume(o)
}
destroy() {
return this._app.destroy()
}
moveToFront() {
return this._app.moveToFront()
}
moveToBack() {
return this._app.moveToBack()
}
moveForward() {
return this._app.moveForward()
}
moveBackward() {
return this._app.moveBackward()
}
setFocus(b) {
return this._app.setFocus(b)
}
isFocused() {
return this._app.isFocused()
}
onKeyDown(e) {
return this._app.onKeyDown(e)
}
onKeyUp(e) {
return this._app.onKeyUp(e)
}
onChar(e) {
return this._app.onChar(e)
}
animateTo(animationProperties, duration, tween, type, count) {
return this._app.animateTo(animationProperties, duration, tween, type, count)
}
animate(animationProperties, duration, tween, type, count) {
return this._app.animate(animationProperties, duration, tween, type, count)
}
on(e, fn) {
return this._app.on(e, fn)
}
api() {
return this._app.api()
}
setProperties(props) {
return this._app.setProperties(props)
}
state() {
return this._app.state()
}
_getIsValid() {
return (
typeof this._launchParams === 'object' &&
typeof this._id === 'number' &&
typeof this._priority === 'number' &&
typeof this._x === 'number' &&
typeof this._y === 'number' &&
typeof this._w === 'number' &&
typeof this._h === 'number' &&
typeof this._cx === 'number' &&
typeof this._cy === 'number' &&
typeof this._sx === 'number' &&
typeof this._sy === 'number' &&
typeof this._r === 'number' &&
typeof this._a === 'number' &&
typeof this._interactive === 'boolean' &&
typeof this._painting === 'boolean' &&
typeof this._clip === 'boolean' &&
typeof this._mask === 'boolean' &&
typeof this._draw === 'boolean'
)
}
_getLookupId() {
return '__app_' + this._id
}
_getSourceLoader() {
const _this = this
return function (cb) {
if (!_this._optimus) _this._optimus = require('optimus')
if (!_this._app) {
_this._optimus.setScene(global.sparkscene)
_this._app = _this._optimus.createApplication({
id: _this._id,
priority: _this._priority,
x: _this._x,
y: _this._y,
w: _this._w,
h: _this._h,
cx: _this._cx,
cy: _this._cy,
sx: _this._sx,
sy: _this._sy,
r: _this._r,
a: _this._a,
interactive: _this._interactive,
painting: _this._painting,
clip: _this._clip,
mask: _this._mask,
draw: _this._draw,
launchParams: _this._launchParams,
})
}
_this._app.drawNatively = true
_this._app.readyBase
.then(function () {
cb(null, {
source: -1,
w: _this._w,
h: _this._h,
premultiplyAlpha: false,
flipBlueRed: false,
flipTextureY: true,
imageRef: _this._app,
})
})
.catch((e) => {
console.error(`optimus error: ${e}`)
})
}
}
}
// eslint-disable-next-line no-undef
lng.Stage.platform = SparkPlatform