@next2d/core 1.14.20
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/LICENSE +21 -0
- package/README.md +11 -0
- package/dist/Display.d.ts +3 -0
- package/dist/Display.js +24 -0
- package/dist/Events.d.ts +3 -0
- package/dist/Events.js +20 -0
- package/dist/Filters.d.ts +3 -0
- package/dist/Filters.js +20 -0
- package/dist/Geom.d.ts +3 -0
- package/dist/Geom.js +16 -0
- package/dist/Media.d.ts +3 -0
- package/dist/Media.js +15 -0
- package/dist/Net.d.ts +3 -0
- package/dist/Net.js +13 -0
- package/dist/Next2D.d.ts +62 -0
- package/dist/Next2D.js +190 -0
- package/dist/Player.d.ts +328 -0
- package/dist/Player.js +1859 -0
- package/dist/Text.d.ts +3 -0
- package/dist/Text.js +13 -0
- package/dist/UI.d.ts +3 -0
- package/dist/UI.js +14 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/package.json +47 -0
package/dist/Player.js
ADDED
|
@@ -0,0 +1,1859 @@
|
|
|
1
|
+
import { CacheStore } from "@next2d/share";
|
|
2
|
+
import { Stage } from "@next2d/display";
|
|
3
|
+
import { Event as Next2DEvent, MouseEvent as Next2DMouseEvent, EventPhase } from "@next2d/events";
|
|
4
|
+
import { SoundMixer } from "@next2d/media";
|
|
5
|
+
import { CanvasToWebGLContext } from "@next2d/webgl";
|
|
6
|
+
import { $devicePixelRatio, $document, $window, $rendererWorker, $PREFIX, $audioContext, $TOUCH_START, $TOUCH_MOVE, $TOUCH_END, $MOUSE_DOWN, $MOUSE_MOVE, $MOUSE_UP, $MOUSE_WHEEL, $DOUBLE_CLICK, $MOUSE_LEAVE, $loadAudioData, $MATRIX_HIT_ARRAY_IDENTITY, $hitContext, $isTouch, $dropTarget, $dragRules, $isSafari, $getEvent, $setEvent, $setEventType, $setCurrentLoaderInfo, $getEventType } from "@next2d/util";
|
|
7
|
+
import { $Math, $performance, $COLOR_ARRAY_IDENTITY, $doUpdated, $isUpdated, $getArray, $getFloat32Array6, $getMap, $uintToRGBA, $toColorInt, $requestAnimationFrame, $cancelAnimationFrame, $poolArray, $clamp } from "@next2d/share";
|
|
8
|
+
/**
|
|
9
|
+
* 描画のイベントや設定やコントロールの管理クラス
|
|
10
|
+
* Management classes for drawing events, settings and controls
|
|
11
|
+
*
|
|
12
|
+
* @class
|
|
13
|
+
*/
|
|
14
|
+
export class Player {
|
|
15
|
+
/**
|
|
16
|
+
* @constructor
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
constructor() {
|
|
20
|
+
/**
|
|
21
|
+
* @type {Stage}
|
|
22
|
+
* @private
|
|
23
|
+
*/
|
|
24
|
+
this._$stage = new Stage();
|
|
25
|
+
this._$stage._$player = this;
|
|
26
|
+
/**
|
|
27
|
+
* @type {CacheStore}
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
30
|
+
this._$cacheStore = new CacheStore();
|
|
31
|
+
/**
|
|
32
|
+
* @type {string}
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
this._$mode = "loader";
|
|
36
|
+
/**
|
|
37
|
+
* @type {number}
|
|
38
|
+
* @private
|
|
39
|
+
*/
|
|
40
|
+
this._$actionOffset = 0;
|
|
41
|
+
/**
|
|
42
|
+
* @type {array}
|
|
43
|
+
* @private
|
|
44
|
+
*/
|
|
45
|
+
this._$actions = $getArray();
|
|
46
|
+
/**
|
|
47
|
+
* @type {array}
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
this._$loaders = $getArray();
|
|
51
|
+
/**
|
|
52
|
+
* @type {Map}
|
|
53
|
+
* @private
|
|
54
|
+
*/
|
|
55
|
+
this._$sounds = $getMap();
|
|
56
|
+
/**
|
|
57
|
+
* @type {object}
|
|
58
|
+
* @private
|
|
59
|
+
*/
|
|
60
|
+
this._$hitObject = {
|
|
61
|
+
"x": 0,
|
|
62
|
+
"y": 0,
|
|
63
|
+
"pointer": "",
|
|
64
|
+
"hit": null
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* @type {DisplayObject}
|
|
68
|
+
* @default null
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
this._$rollOverObject = null;
|
|
72
|
+
/**
|
|
73
|
+
* @type {DisplayObject}
|
|
74
|
+
* @default null
|
|
75
|
+
* @private
|
|
76
|
+
*/
|
|
77
|
+
this._$mouseOverTarget = null;
|
|
78
|
+
/**
|
|
79
|
+
* @type {number}
|
|
80
|
+
* @private
|
|
81
|
+
*/
|
|
82
|
+
this._$ratio = $devicePixelRatio;
|
|
83
|
+
/**
|
|
84
|
+
* @type {boolean}
|
|
85
|
+
* @default true
|
|
86
|
+
* @private
|
|
87
|
+
*/
|
|
88
|
+
this._$stopFlag = true;
|
|
89
|
+
/**
|
|
90
|
+
* @type {number}
|
|
91
|
+
* @default 0
|
|
92
|
+
* @private
|
|
93
|
+
*/
|
|
94
|
+
this._$startTime = 0;
|
|
95
|
+
/**
|
|
96
|
+
* @type {number}
|
|
97
|
+
* @default 16
|
|
98
|
+
* @private
|
|
99
|
+
*/
|
|
100
|
+
this._$fps = 16;
|
|
101
|
+
/**
|
|
102
|
+
* @type {boolean}
|
|
103
|
+
* @default false
|
|
104
|
+
* @private
|
|
105
|
+
*/
|
|
106
|
+
this._$isLoad = false;
|
|
107
|
+
/**
|
|
108
|
+
* @type {number}
|
|
109
|
+
* @default 0
|
|
110
|
+
* @private
|
|
111
|
+
*/
|
|
112
|
+
this._$loadStatus = 0;
|
|
113
|
+
/**
|
|
114
|
+
* @type {number}
|
|
115
|
+
* @default 0
|
|
116
|
+
* @private
|
|
117
|
+
*/
|
|
118
|
+
this._$width = 0;
|
|
119
|
+
/**
|
|
120
|
+
* @type {number}
|
|
121
|
+
* @default 0
|
|
122
|
+
* @private
|
|
123
|
+
*/
|
|
124
|
+
this._$height = 0;
|
|
125
|
+
/**
|
|
126
|
+
* @type {number}
|
|
127
|
+
* @default 0
|
|
128
|
+
* @private
|
|
129
|
+
*/
|
|
130
|
+
this._$baseWidth = 0;
|
|
131
|
+
/**
|
|
132
|
+
* @type {number}
|
|
133
|
+
* @default 0
|
|
134
|
+
* @private
|
|
135
|
+
*/
|
|
136
|
+
this._$baseHeight = 0;
|
|
137
|
+
/**
|
|
138
|
+
* @type {number}
|
|
139
|
+
* @default 1
|
|
140
|
+
* @private
|
|
141
|
+
*/
|
|
142
|
+
this._$scale = 1;
|
|
143
|
+
/**
|
|
144
|
+
* @type {Float32Array}
|
|
145
|
+
* @private
|
|
146
|
+
*/
|
|
147
|
+
this._$matrix = $getFloat32Array6(1, 0, 0, 1, 0, 0); // fixed size 6
|
|
148
|
+
/**
|
|
149
|
+
* @type {number}
|
|
150
|
+
* @default 0
|
|
151
|
+
* @private
|
|
152
|
+
*/
|
|
153
|
+
this._$tx = 0;
|
|
154
|
+
/**
|
|
155
|
+
* @type {number}
|
|
156
|
+
* @default 0
|
|
157
|
+
* @private
|
|
158
|
+
*/
|
|
159
|
+
this._$ty = 0;
|
|
160
|
+
/**
|
|
161
|
+
* @type {string}
|
|
162
|
+
* @default up
|
|
163
|
+
* @private
|
|
164
|
+
*/
|
|
165
|
+
this._$state = "up";
|
|
166
|
+
/**
|
|
167
|
+
* @type {boolean}
|
|
168
|
+
* @default false
|
|
169
|
+
* @private
|
|
170
|
+
*/
|
|
171
|
+
this._$hitTestStart = false;
|
|
172
|
+
/**
|
|
173
|
+
* @type {number}
|
|
174
|
+
* @default -1
|
|
175
|
+
* @private
|
|
176
|
+
*/
|
|
177
|
+
this._$stageX = -1;
|
|
178
|
+
/**
|
|
179
|
+
* @type {number}
|
|
180
|
+
* @default -1
|
|
181
|
+
* @private
|
|
182
|
+
*/
|
|
183
|
+
this._$stageY = -1;
|
|
184
|
+
/**
|
|
185
|
+
* @type {number}
|
|
186
|
+
* @default 0
|
|
187
|
+
* @private
|
|
188
|
+
*/
|
|
189
|
+
this._$deltaX = 0;
|
|
190
|
+
/**
|
|
191
|
+
* @type {number}
|
|
192
|
+
* @default 0
|
|
193
|
+
* @private
|
|
194
|
+
*/
|
|
195
|
+
this._$deltaY = 0;
|
|
196
|
+
/**
|
|
197
|
+
* @type {Map}
|
|
198
|
+
* @private
|
|
199
|
+
*/
|
|
200
|
+
this._$broadcastEvents = $getMap();
|
|
201
|
+
/**
|
|
202
|
+
* @type {number}
|
|
203
|
+
* @default 0
|
|
204
|
+
* @private
|
|
205
|
+
*/
|
|
206
|
+
this._$optionWidth = 0;
|
|
207
|
+
/**
|
|
208
|
+
* @type {number}
|
|
209
|
+
* @default 0
|
|
210
|
+
* @private
|
|
211
|
+
*/
|
|
212
|
+
this._$optionHeight = 0;
|
|
213
|
+
/**
|
|
214
|
+
* @type {string}
|
|
215
|
+
* @default ""
|
|
216
|
+
* @private
|
|
217
|
+
*/
|
|
218
|
+
this._$tagId = "";
|
|
219
|
+
/**
|
|
220
|
+
* @type {string}
|
|
221
|
+
* @default "transparent"
|
|
222
|
+
* @private
|
|
223
|
+
*/
|
|
224
|
+
this._$bgColor = "transparent";
|
|
225
|
+
/**
|
|
226
|
+
* @type {string}
|
|
227
|
+
* @default ""
|
|
228
|
+
* @private
|
|
229
|
+
*/
|
|
230
|
+
this._$base = "";
|
|
231
|
+
/**
|
|
232
|
+
* @type {boolean}
|
|
233
|
+
* @default false
|
|
234
|
+
* @private
|
|
235
|
+
*/
|
|
236
|
+
this._$fullScreen = false;
|
|
237
|
+
/**
|
|
238
|
+
* @type {string}
|
|
239
|
+
* @default high
|
|
240
|
+
* @private
|
|
241
|
+
*/
|
|
242
|
+
this._$quality = "high";
|
|
243
|
+
/**
|
|
244
|
+
* @type {array}
|
|
245
|
+
* @private
|
|
246
|
+
*/
|
|
247
|
+
this._$sources = $getArray();
|
|
248
|
+
/**
|
|
249
|
+
* @type {array}
|
|
250
|
+
* @private
|
|
251
|
+
*/
|
|
252
|
+
this._$videos = $getArray();
|
|
253
|
+
/**
|
|
254
|
+
* @type {TextField}
|
|
255
|
+
* @default null
|
|
256
|
+
* @private
|
|
257
|
+
*/
|
|
258
|
+
this._$textField = null;
|
|
259
|
+
/**
|
|
260
|
+
* @type {number}
|
|
261
|
+
* @default 0
|
|
262
|
+
* @private
|
|
263
|
+
*/
|
|
264
|
+
this._$touchY = 0;
|
|
265
|
+
/**
|
|
266
|
+
* @type {number}
|
|
267
|
+
* @default -1
|
|
268
|
+
* @private
|
|
269
|
+
*/
|
|
270
|
+
this._$timerId = -1;
|
|
271
|
+
/**
|
|
272
|
+
* @type {number}
|
|
273
|
+
* @default -1
|
|
274
|
+
* @private
|
|
275
|
+
*/
|
|
276
|
+
this._$loadId = -1;
|
|
277
|
+
/**
|
|
278
|
+
* @type {CanvasToWebGLContext}
|
|
279
|
+
* @default null
|
|
280
|
+
* @private
|
|
281
|
+
*/
|
|
282
|
+
this._$context = null;
|
|
283
|
+
/**
|
|
284
|
+
* @type {AttachmentImpl}
|
|
285
|
+
* @default null
|
|
286
|
+
* @private
|
|
287
|
+
*/
|
|
288
|
+
this._$attachment = null;
|
|
289
|
+
/**
|
|
290
|
+
* @type {DisplayObject}
|
|
291
|
+
* @default null
|
|
292
|
+
* @private
|
|
293
|
+
*/
|
|
294
|
+
this._$clickTarget = null;
|
|
295
|
+
/**
|
|
296
|
+
* @type {boolean}
|
|
297
|
+
* @default false
|
|
298
|
+
* @private
|
|
299
|
+
*/
|
|
300
|
+
this._$actionProcess = false;
|
|
301
|
+
/**
|
|
302
|
+
* @type {HTMLCanvasElement}
|
|
303
|
+
* @private
|
|
304
|
+
*/
|
|
305
|
+
this._$canvas = $document.createElement("canvas");
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* @return {number}
|
|
309
|
+
* @default 1
|
|
310
|
+
* @const
|
|
311
|
+
* @static
|
|
312
|
+
*/
|
|
313
|
+
static get LOAD_START() {
|
|
314
|
+
return 1;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* @return {number}
|
|
318
|
+
* @default 2
|
|
319
|
+
* @const
|
|
320
|
+
* @static
|
|
321
|
+
*/
|
|
322
|
+
static get LOAD_END() {
|
|
323
|
+
return 2;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* @type {HTMLCanvasElement}
|
|
327
|
+
* @readonly
|
|
328
|
+
* @public
|
|
329
|
+
*/
|
|
330
|
+
get canvas() {
|
|
331
|
+
return this._$canvas;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* @return {Map}
|
|
335
|
+
* @readonly
|
|
336
|
+
* @public
|
|
337
|
+
*/
|
|
338
|
+
get broadcastEvents() {
|
|
339
|
+
return this._$broadcastEvents;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* @member {CacheStore}
|
|
343
|
+
* @return {CacheStore}
|
|
344
|
+
* @readonly
|
|
345
|
+
* @public
|
|
346
|
+
*/
|
|
347
|
+
get cacheStore() {
|
|
348
|
+
return this._$cacheStore;
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* @member {CanvasToWebGLContext|null}
|
|
352
|
+
* @default null
|
|
353
|
+
* @public
|
|
354
|
+
*/
|
|
355
|
+
get context() {
|
|
356
|
+
return this._$context;
|
|
357
|
+
}
|
|
358
|
+
set context(context) {
|
|
359
|
+
this._$context = context;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* @member {string}
|
|
363
|
+
* @default ""
|
|
364
|
+
* @public
|
|
365
|
+
*/
|
|
366
|
+
get base() {
|
|
367
|
+
return this._$base;
|
|
368
|
+
}
|
|
369
|
+
set base(base) {
|
|
370
|
+
if (base.indexOf("//") === -1) {
|
|
371
|
+
const urls = base.split("/");
|
|
372
|
+
if (urls[0] === "" || urls[0] === ".") {
|
|
373
|
+
urls.shift();
|
|
374
|
+
}
|
|
375
|
+
urls.pop();
|
|
376
|
+
this._$base = `${location.origin}/`;
|
|
377
|
+
if (urls.length) {
|
|
378
|
+
this._$base += `${urls.join("/")}/`;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
if (base.indexOf("?") === -1) {
|
|
383
|
+
this._$base = base.slice(-1) === "/" ? base : `${base}/`;
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
const path = base.split("?")[0];
|
|
387
|
+
this._$base = path.slice(-1) === "/" ? path : `${path}/`;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* @return {Stage}
|
|
393
|
+
* @readonly
|
|
394
|
+
* @public
|
|
395
|
+
*/
|
|
396
|
+
get stage() {
|
|
397
|
+
return this._$stage;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* @member {number}
|
|
401
|
+
* @readonly
|
|
402
|
+
* @public
|
|
403
|
+
*/
|
|
404
|
+
get x() {
|
|
405
|
+
return this._$tx;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* @member {number}
|
|
409
|
+
* @readonly
|
|
410
|
+
* @public
|
|
411
|
+
*/
|
|
412
|
+
get y() {
|
|
413
|
+
return this._$ty;
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* @member {number}
|
|
417
|
+
* @readonly
|
|
418
|
+
* @public
|
|
419
|
+
*/
|
|
420
|
+
get scaleX() {
|
|
421
|
+
return this._$matrix[0];
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* @member {number}
|
|
425
|
+
* @readonly
|
|
426
|
+
* @public
|
|
427
|
+
*/
|
|
428
|
+
get scaleY() {
|
|
429
|
+
return this._$matrix[3];
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* @member {string}
|
|
433
|
+
* @public
|
|
434
|
+
*/
|
|
435
|
+
get mode() {
|
|
436
|
+
return this._$mode;
|
|
437
|
+
}
|
|
438
|
+
set mode(mode) {
|
|
439
|
+
this._$mode = mode;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* @return {string}
|
|
443
|
+
* @readonly
|
|
444
|
+
* @public
|
|
445
|
+
*/
|
|
446
|
+
get contentElementId() {
|
|
447
|
+
return $PREFIX;
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* @member {number}
|
|
451
|
+
* @public
|
|
452
|
+
*/
|
|
453
|
+
get width() {
|
|
454
|
+
return this._$baseWidth;
|
|
455
|
+
}
|
|
456
|
+
set width(width) {
|
|
457
|
+
this._$baseWidth = width | 0;
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* @member {number}
|
|
461
|
+
* @public
|
|
462
|
+
*/
|
|
463
|
+
get height() {
|
|
464
|
+
return this._$baseHeight;
|
|
465
|
+
}
|
|
466
|
+
set height(height) {
|
|
467
|
+
this._$baseHeight = height | 0;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* @member {string}
|
|
471
|
+
* @public
|
|
472
|
+
*/
|
|
473
|
+
get bgColor() {
|
|
474
|
+
return this._$bgColor;
|
|
475
|
+
}
|
|
476
|
+
set bgColor(bg_color) {
|
|
477
|
+
this._$bgColor = `${bg_color}`;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* @return {void}
|
|
481
|
+
* @method
|
|
482
|
+
* @public
|
|
483
|
+
*/
|
|
484
|
+
play() {
|
|
485
|
+
if (this._$stopFlag) {
|
|
486
|
+
this._$stopFlag = false;
|
|
487
|
+
if (this._$timerId > -1) {
|
|
488
|
+
$cancelAnimationFrame(this._$timerId);
|
|
489
|
+
}
|
|
490
|
+
this._$startTime = $performance.now();
|
|
491
|
+
const frameRate = this._$stage._$frameRate;
|
|
492
|
+
this._$fps = 1000 / frameRate | 0;
|
|
493
|
+
this._$timerId = $requestAnimationFrame((timestamp) => {
|
|
494
|
+
this._$run(timestamp);
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* @return {void}
|
|
500
|
+
* @method
|
|
501
|
+
* @public
|
|
502
|
+
*/
|
|
503
|
+
stop() {
|
|
504
|
+
if (this._$timerId > -1) {
|
|
505
|
+
$cancelAnimationFrame(this._$timerId);
|
|
506
|
+
}
|
|
507
|
+
this._$stopFlag = true;
|
|
508
|
+
this._$timerId = -1;
|
|
509
|
+
SoundMixer.stopAll();
|
|
510
|
+
this._$cacheStore.reset();
|
|
511
|
+
if ($rendererWorker) {
|
|
512
|
+
$rendererWorker.postMessage({
|
|
513
|
+
"command": "stop"
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* @param {string} id
|
|
519
|
+
* @return {void}
|
|
520
|
+
* @method
|
|
521
|
+
* @public
|
|
522
|
+
*/
|
|
523
|
+
removeCache(id) {
|
|
524
|
+
this._$cacheStore.removeCache(id);
|
|
525
|
+
if ($rendererWorker) {
|
|
526
|
+
$rendererWorker.postMessage({
|
|
527
|
+
"command": "removeCache",
|
|
528
|
+
"id": id
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* @param {object} [options=null]
|
|
534
|
+
* @return {void}
|
|
535
|
+
* @public
|
|
536
|
+
*/
|
|
537
|
+
setOptions(options = null) {
|
|
538
|
+
if (options) {
|
|
539
|
+
this._$optionWidth = options.width || this._$optionWidth;
|
|
540
|
+
this._$optionHeight = options.height || this._$optionHeight;
|
|
541
|
+
this._$tagId = options.tagId || this._$tagId;
|
|
542
|
+
this.base = options.base || this._$base;
|
|
543
|
+
this._$bgColor = options.bgColor || this._$bgColor;
|
|
544
|
+
this._$fullScreen = !!options.fullScreen;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* @description NoCode Toolからのアクセスのみ
|
|
549
|
+
* Access from NoCode Tool only
|
|
550
|
+
*
|
|
551
|
+
* @param {MouseEvent} [event = null]
|
|
552
|
+
* @return {void}
|
|
553
|
+
* @method
|
|
554
|
+
* @private
|
|
555
|
+
*/
|
|
556
|
+
_$loadWebAudio(event = null) {
|
|
557
|
+
if (event) {
|
|
558
|
+
// @ts-ignore
|
|
559
|
+
this._$canvas.removeEventListener($MOUSE_UP, this._$loadWebAudio);
|
|
560
|
+
}
|
|
561
|
+
if (!$audioContext) {
|
|
562
|
+
$loadAudioData();
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* @return {void}
|
|
567
|
+
* @method
|
|
568
|
+
* @private
|
|
569
|
+
*/
|
|
570
|
+
_$updateLoadStatus() {
|
|
571
|
+
if (this._$loadStatus === Player.LOAD_END) {
|
|
572
|
+
if (this._$loadId > -1) {
|
|
573
|
+
$cancelAnimationFrame(this._$loadId);
|
|
574
|
+
}
|
|
575
|
+
this._$loadId = -1;
|
|
576
|
+
this._$loaded();
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
this._$loadId = $requestAnimationFrame(() => {
|
|
580
|
+
this._$updateLoadStatus();
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* @return {void}
|
|
585
|
+
* @method
|
|
586
|
+
* @private
|
|
587
|
+
*/
|
|
588
|
+
_$loaded() {
|
|
589
|
+
const element = $document
|
|
590
|
+
.getElementById(this.contentElementId);
|
|
591
|
+
if (element) {
|
|
592
|
+
// background color
|
|
593
|
+
this._$setBackgroundColor(this._$bgColor);
|
|
594
|
+
// DOM
|
|
595
|
+
this._$deleteNode();
|
|
596
|
+
// append canvas
|
|
597
|
+
element.appendChild(this._$canvas);
|
|
598
|
+
// stage init action
|
|
599
|
+
this._$stage._$prepareActions();
|
|
600
|
+
// constructed event
|
|
601
|
+
if (this._$broadcastEvents.has(Next2DEvent.FRAME_CONSTRUCTED)) {
|
|
602
|
+
this._$dispatchEvent(new Next2DEvent(Next2DEvent.FRAME_CONSTRUCTED));
|
|
603
|
+
}
|
|
604
|
+
// frame1 action
|
|
605
|
+
this._$doAction();
|
|
606
|
+
// exit event
|
|
607
|
+
if (this._$broadcastEvents.has(Next2DEvent.EXIT_FRAME)) {
|
|
608
|
+
this._$dispatchEvent(new Next2DEvent(Next2DEvent.EXIT_FRAME));
|
|
609
|
+
}
|
|
610
|
+
// loader events
|
|
611
|
+
const length = this._$loaders.length;
|
|
612
|
+
for (let idx = 0; idx < length; ++idx) {
|
|
613
|
+
const loader = this._$loaders.shift();
|
|
614
|
+
// init event
|
|
615
|
+
if (loader.hasEventListener(Next2DEvent.INIT)) {
|
|
616
|
+
loader.dispatchEvent(new Next2DEvent(Next2DEvent.INIT));
|
|
617
|
+
}
|
|
618
|
+
// complete event
|
|
619
|
+
if (loader.hasEventListener(Next2DEvent.COMPLETE)) {
|
|
620
|
+
loader.dispatchEvent(new Next2DEvent(Next2DEvent.COMPLETE));
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
// activate event
|
|
624
|
+
if (this._$broadcastEvents.has(Next2DEvent.ACTIVATE)) {
|
|
625
|
+
this._$dispatchEvent(new Next2DEvent(Next2DEvent.ACTIVATE));
|
|
626
|
+
}
|
|
627
|
+
// frame action
|
|
628
|
+
this._$doAction();
|
|
629
|
+
// render
|
|
630
|
+
this._$draw();
|
|
631
|
+
// start
|
|
632
|
+
this.play();
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* @return {void}
|
|
637
|
+
* @method
|
|
638
|
+
* @private
|
|
639
|
+
*/
|
|
640
|
+
_$initialize() {
|
|
641
|
+
if ($document.readyState === "loading") {
|
|
642
|
+
$window.addEventListener("DOMContentLoaded", () => {
|
|
643
|
+
this._$initialize();
|
|
644
|
+
});
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
const contentElementId = this.contentElementId;
|
|
648
|
+
if (!this._$tagId) {
|
|
649
|
+
$document
|
|
650
|
+
.body
|
|
651
|
+
.insertAdjacentHTML("beforeend", `<div id="${contentElementId}" tabindex="-1"></div>`);
|
|
652
|
+
}
|
|
653
|
+
else {
|
|
654
|
+
const container = $document.getElementById(this._$tagId);
|
|
655
|
+
if (!container) {
|
|
656
|
+
alert("Not Found Tag ID:" + this._$tagId);
|
|
657
|
+
return;
|
|
658
|
+
}
|
|
659
|
+
const div = $document.getElementById(contentElementId);
|
|
660
|
+
if (!div) {
|
|
661
|
+
const element = $document.createElement("div");
|
|
662
|
+
element.id = contentElementId;
|
|
663
|
+
element.tabIndex = -1;
|
|
664
|
+
container.appendChild(element);
|
|
665
|
+
}
|
|
666
|
+
else {
|
|
667
|
+
this._$deleteNode();
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
const element = $document.getElementById(contentElementId);
|
|
671
|
+
if (!element) {
|
|
672
|
+
throw new Error("the content element is null.");
|
|
673
|
+
}
|
|
674
|
+
const parent = element.parentElement;
|
|
675
|
+
if (parent) {
|
|
676
|
+
this._$initStyle(element);
|
|
677
|
+
this._$buildWait();
|
|
678
|
+
const width = this._$optionWidth
|
|
679
|
+
? this._$optionWidth
|
|
680
|
+
: parent.tagName === "BODY"
|
|
681
|
+
? $window.innerWidth
|
|
682
|
+
: parent.offsetWidth;
|
|
683
|
+
const height = this._$optionHeight
|
|
684
|
+
? this._$optionHeight
|
|
685
|
+
: parent.tagName === "BODY"
|
|
686
|
+
? $window.innerHeight
|
|
687
|
+
: parent.offsetHeight;
|
|
688
|
+
// set center
|
|
689
|
+
if (this._$mode === "loader" && width && height) {
|
|
690
|
+
this._$baseWidth = width;
|
|
691
|
+
this._$baseHeight = height;
|
|
692
|
+
this._$resize();
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
if (this._$mode === "loader") {
|
|
696
|
+
this._$loadStatus = Player.LOAD_START;
|
|
697
|
+
this._$updateLoadStatus();
|
|
698
|
+
}
|
|
699
|
+
else {
|
|
700
|
+
this._$resize();
|
|
701
|
+
this._$loaded();
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* @param {object} element
|
|
706
|
+
* @returns {void}
|
|
707
|
+
* @method
|
|
708
|
+
* @private
|
|
709
|
+
*/
|
|
710
|
+
_$initStyle(element) {
|
|
711
|
+
const style = element.style;
|
|
712
|
+
// set css
|
|
713
|
+
style.position = "relative";
|
|
714
|
+
style.top = "0";
|
|
715
|
+
style.left = "0";
|
|
716
|
+
style.backgroundColor = "transparent";
|
|
717
|
+
style.overflow = "hidden";
|
|
718
|
+
style.padding = "0";
|
|
719
|
+
style.margin = "0";
|
|
720
|
+
style.userSelect = "none";
|
|
721
|
+
style.outline = "none";
|
|
722
|
+
const width = this._$optionWidth;
|
|
723
|
+
const height = this._$optionHeight;
|
|
724
|
+
const parent = element.parentElement;
|
|
725
|
+
if (!parent) {
|
|
726
|
+
throw new Error("the parentElement is null.");
|
|
727
|
+
}
|
|
728
|
+
if (parent.tagName === "BODY") {
|
|
729
|
+
style.width = width ? `${width}px` : `${window.innerWidth}px`;
|
|
730
|
+
style.height = height ? `${height}px` : `${window.innerHeight}px`;
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
style.width = width ? `${width}px` : `${parent.offsetWidth}px`;
|
|
734
|
+
style.height = height ? `${height}px` : `${parent.offsetHeight}px`;
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* @return {void}
|
|
738
|
+
* @method
|
|
739
|
+
* @private
|
|
740
|
+
*/
|
|
741
|
+
_$buildWait() {
|
|
742
|
+
const element = $document
|
|
743
|
+
.getElementById(this.contentElementId);
|
|
744
|
+
if (element) {
|
|
745
|
+
const loadingId = `${this.contentElementId}_loading`;
|
|
746
|
+
element.innerHTML = `<style>
|
|
747
|
+
#${loadingId} {
|
|
748
|
+
position: absolute;
|
|
749
|
+
top: 50%;
|
|
750
|
+
left: 50%;
|
|
751
|
+
margin: -24px 0 0 -24px;
|
|
752
|
+
width: 50px;
|
|
753
|
+
height: 50px;
|
|
754
|
+
border-radius: 50px;
|
|
755
|
+
border: 8px solid #dcdcdc;
|
|
756
|
+
border-right-color: transparent;
|
|
757
|
+
box-sizing: border-box;
|
|
758
|
+
animation: ${loadingId} 0.8s infinite linear;
|
|
759
|
+
}
|
|
760
|
+
@keyframes ${loadingId} {
|
|
761
|
+
0% {
|
|
762
|
+
transform: rotate(0deg);
|
|
763
|
+
}
|
|
764
|
+
100% {
|
|
765
|
+
transform: rotate(360deg);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
</style>`;
|
|
769
|
+
const div = $document.createElement("div");
|
|
770
|
+
div.id = loadingId;
|
|
771
|
+
element.appendChild(div);
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
/**
|
|
775
|
+
* @returns {void}
|
|
776
|
+
* @method
|
|
777
|
+
* @private
|
|
778
|
+
*/
|
|
779
|
+
_$deleteNode() {
|
|
780
|
+
const element = $document.getElementById(this.contentElementId);
|
|
781
|
+
if (element) {
|
|
782
|
+
while (element.childNodes.length) {
|
|
783
|
+
element.removeChild(element.childNodes[0]);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* @return {void}
|
|
789
|
+
* @private
|
|
790
|
+
*/
|
|
791
|
+
_$initializeCanvas() {
|
|
792
|
+
// main canvas
|
|
793
|
+
this._$canvas.width = 1;
|
|
794
|
+
this._$canvas.height = 1;
|
|
795
|
+
if ($rendererWorker) {
|
|
796
|
+
$rendererWorker.postMessage({
|
|
797
|
+
"command": "setStage",
|
|
798
|
+
"instanceId": this._$stage._$instanceId
|
|
799
|
+
});
|
|
800
|
+
const offscreenCanvas = this
|
|
801
|
+
._$canvas
|
|
802
|
+
.transferControlToOffscreen();
|
|
803
|
+
$rendererWorker.postMessage({
|
|
804
|
+
"command": "initialize",
|
|
805
|
+
"canvas": offscreenCanvas,
|
|
806
|
+
"samples": this._$getSamples(),
|
|
807
|
+
"devicePixelRatio": $devicePixelRatio,
|
|
808
|
+
"isSafari": $isSafari
|
|
809
|
+
}, [offscreenCanvas]);
|
|
810
|
+
}
|
|
811
|
+
else {
|
|
812
|
+
// create gl context
|
|
813
|
+
const gl = this._$canvas.getContext("webgl2", {
|
|
814
|
+
"stencil": true,
|
|
815
|
+
"premultipliedAlpha": true,
|
|
816
|
+
"antialias": false,
|
|
817
|
+
"depth": false,
|
|
818
|
+
"preserveDrawingBuffer": true
|
|
819
|
+
});
|
|
820
|
+
if (gl) {
|
|
821
|
+
this._$context = new CanvasToWebGLContext(gl, this._$getSamples());
|
|
822
|
+
this._$cacheStore.context = this._$context;
|
|
823
|
+
}
|
|
824
|
+
else {
|
|
825
|
+
alert("WebGL setting is off. Please turn the setting on.");
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* @return {void}
|
|
830
|
+
* @method
|
|
831
|
+
* @private
|
|
832
|
+
*/
|
|
833
|
+
const loadWebAudio = () => {
|
|
834
|
+
this._$canvas.removeEventListener($MOUSE_UP, loadWebAudio);
|
|
835
|
+
this._$canvas.removeEventListener($TOUCH_END, loadWebAudio);
|
|
836
|
+
if (!$audioContext) {
|
|
837
|
+
$loadAudioData();
|
|
838
|
+
for (let idx = 0; idx < this._$videos.length; ++idx) {
|
|
839
|
+
const video = this._$videos[idx];
|
|
840
|
+
if (!video._$video) {
|
|
841
|
+
continue;
|
|
842
|
+
}
|
|
843
|
+
video._$video.muted = false;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
// @ts-ignore
|
|
848
|
+
this._$canvas.addEventListener($TOUCH_END, loadWebAudio);
|
|
849
|
+
// @ts-ignore
|
|
850
|
+
this._$canvas.addEventListener($MOUSE_UP, loadWebAudio);
|
|
851
|
+
// touch event
|
|
852
|
+
this._$canvas.addEventListener($TOUCH_START, (event) => {
|
|
853
|
+
$setEvent(event);
|
|
854
|
+
$setEventType($TOUCH_START);
|
|
855
|
+
// start position
|
|
856
|
+
this._$touchY = event.changedTouches[0].pageY;
|
|
857
|
+
this._$hitTest();
|
|
858
|
+
});
|
|
859
|
+
this._$canvas.addEventListener($TOUCH_MOVE, (event) => {
|
|
860
|
+
$setEvent(event);
|
|
861
|
+
$setEventType($TOUCH_MOVE);
|
|
862
|
+
this._$hitTest();
|
|
863
|
+
});
|
|
864
|
+
this._$canvas.addEventListener($TOUCH_END, (event) => {
|
|
865
|
+
$setEvent(event);
|
|
866
|
+
$setEventType($TOUCH_END);
|
|
867
|
+
this._$hitTest();
|
|
868
|
+
});
|
|
869
|
+
// mouse wheel
|
|
870
|
+
this._$canvas.addEventListener($TOUCH_MOVE, (event) => {
|
|
871
|
+
// update
|
|
872
|
+
const pageY = event.changedTouches[0].pageY;
|
|
873
|
+
this._$deltaY = this._$touchY - pageY;
|
|
874
|
+
this._$touchY = pageY;
|
|
875
|
+
$setEvent(event);
|
|
876
|
+
$setEventType($TOUCH_MOVE);
|
|
877
|
+
this._$hitTest();
|
|
878
|
+
}, { "passive": false });
|
|
879
|
+
// mouse event
|
|
880
|
+
this._$canvas.addEventListener($MOUSE_DOWN, (event) => {
|
|
881
|
+
$setEvent(event);
|
|
882
|
+
$setEventType($MOUSE_DOWN);
|
|
883
|
+
if (!event.button) {
|
|
884
|
+
this._$hitTest();
|
|
885
|
+
}
|
|
886
|
+
});
|
|
887
|
+
this._$canvas.addEventListener($DOUBLE_CLICK, (event) => {
|
|
888
|
+
$setEvent(event);
|
|
889
|
+
$setEventType($DOUBLE_CLICK);
|
|
890
|
+
if (!event.button) {
|
|
891
|
+
this._$hitTest();
|
|
892
|
+
}
|
|
893
|
+
});
|
|
894
|
+
this._$canvas.addEventListener($MOUSE_LEAVE, (event) => {
|
|
895
|
+
$setEvent(event);
|
|
896
|
+
$setEventType($MOUSE_LEAVE);
|
|
897
|
+
this._$hitTest();
|
|
898
|
+
$setEvent(null);
|
|
899
|
+
this._$stageX = -1;
|
|
900
|
+
this._$stageY = -1;
|
|
901
|
+
});
|
|
902
|
+
this._$canvas.addEventListener($MOUSE_UP, (event) => {
|
|
903
|
+
$setEvent(event);
|
|
904
|
+
$setEventType($MOUSE_UP);
|
|
905
|
+
if (!event.button) {
|
|
906
|
+
this._$hitTest();
|
|
907
|
+
}
|
|
908
|
+
});
|
|
909
|
+
this._$canvas.addEventListener($MOUSE_MOVE, (event) => {
|
|
910
|
+
$setEvent(event);
|
|
911
|
+
$setEventType($MOUSE_MOVE);
|
|
912
|
+
this._$hitTest();
|
|
913
|
+
});
|
|
914
|
+
// mouse wheel
|
|
915
|
+
this._$canvas.addEventListener($MOUSE_WHEEL, (event) => {
|
|
916
|
+
if (!event.defaultPrevented) {
|
|
917
|
+
$setEvent(event);
|
|
918
|
+
$setEventType($MOUSE_WHEEL);
|
|
919
|
+
this._$hitTest();
|
|
920
|
+
}
|
|
921
|
+
}, { "passive": false });
|
|
922
|
+
// set css
|
|
923
|
+
let style = "";
|
|
924
|
+
style += "position: absolute;";
|
|
925
|
+
style += "top: 0;";
|
|
926
|
+
style += "left: 0;";
|
|
927
|
+
style += "-webkit-tap-highlight-color: rgba(0,0,0,0);";
|
|
928
|
+
style += "backface-visibility: hidden;";
|
|
929
|
+
style += "transform-origin: 0 0;";
|
|
930
|
+
if ($devicePixelRatio !== 1) {
|
|
931
|
+
style += `transform: scale(${1 / $devicePixelRatio});`;
|
|
932
|
+
}
|
|
933
|
+
this._$canvas.setAttribute("style", style);
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* @return {void}
|
|
937
|
+
* @method
|
|
938
|
+
* @private
|
|
939
|
+
*/
|
|
940
|
+
_$resize() {
|
|
941
|
+
const div = $document
|
|
942
|
+
.getElementById(this.contentElementId);
|
|
943
|
+
if (div) {
|
|
944
|
+
// cache reset
|
|
945
|
+
this._$stage._$doChanged();
|
|
946
|
+
this._$cacheStore.reset();
|
|
947
|
+
const parent = div.parentElement;
|
|
948
|
+
if (!parent) {
|
|
949
|
+
throw new Error("the parentElement is null.");
|
|
950
|
+
}
|
|
951
|
+
const innerWidth = this._$optionWidth
|
|
952
|
+
? this._$optionWidth
|
|
953
|
+
: parent.tagName === "BODY"
|
|
954
|
+
? $window.innerWidth
|
|
955
|
+
: parent.offsetWidth
|
|
956
|
+
? parent.offsetWidth
|
|
957
|
+
: parseFloat(parent.style.width);
|
|
958
|
+
const innerHeight = this._$optionHeight
|
|
959
|
+
? this._$optionHeight
|
|
960
|
+
: parent.tagName === "BODY"
|
|
961
|
+
? $window.innerHeight
|
|
962
|
+
: parent.offsetHeight
|
|
963
|
+
? parent.offsetHeight
|
|
964
|
+
: parseFloat(parent.style.height);
|
|
965
|
+
const screenWidth = parent.tagName === "BODY"
|
|
966
|
+
? $window.innerWidth
|
|
967
|
+
: parent.offsetWidth;
|
|
968
|
+
const scale = $Math.min(innerWidth / this._$baseWidth, innerHeight / this._$baseHeight);
|
|
969
|
+
let width = this._$fullScreen
|
|
970
|
+
? innerWidth
|
|
971
|
+
: this._$baseWidth * scale | 0;
|
|
972
|
+
let height = this._$fullScreen
|
|
973
|
+
? innerHeight
|
|
974
|
+
: this._$baseHeight * scale | 0;
|
|
975
|
+
// div
|
|
976
|
+
const style = div.style;
|
|
977
|
+
style.width = `${width}px`;
|
|
978
|
+
style.height = `${height}px`;
|
|
979
|
+
style.top = "0";
|
|
980
|
+
style.left = this._$fullScreen
|
|
981
|
+
? "0"
|
|
982
|
+
: `${screenWidth / 2 - width / 2}px`;
|
|
983
|
+
width *= $devicePixelRatio;
|
|
984
|
+
height *= $devicePixelRatio;
|
|
985
|
+
// params
|
|
986
|
+
this._$scale = scale;
|
|
987
|
+
this._$width = width;
|
|
988
|
+
this._$height = height;
|
|
989
|
+
const mScale = this._$scale * this._$ratio;
|
|
990
|
+
this._$matrix[0] = mScale;
|
|
991
|
+
this._$matrix[3] = mScale;
|
|
992
|
+
if (this._$fullScreen) {
|
|
993
|
+
this._$tx = (width -
|
|
994
|
+
this._$baseWidth
|
|
995
|
+
* scale
|
|
996
|
+
* $devicePixelRatio) / 2;
|
|
997
|
+
this._$ty = (height -
|
|
998
|
+
this._$baseHeight
|
|
999
|
+
* scale
|
|
1000
|
+
* $devicePixelRatio) / 2;
|
|
1001
|
+
this._$matrix[4] = this._$tx;
|
|
1002
|
+
this._$matrix[5] = this._$ty;
|
|
1003
|
+
}
|
|
1004
|
+
// main canvas resize
|
|
1005
|
+
this._$resizeCanvas(width, height, mScale, this._$tx, this._$ty);
|
|
1006
|
+
if (this._$ratio > 1 && $devicePixelRatio > 1) {
|
|
1007
|
+
this._$canvas.style.transform = `scale(${1 / this._$ratio})`;
|
|
1008
|
+
}
|
|
1009
|
+
if (div.children.length > 1) {
|
|
1010
|
+
div.children[1].dispatchEvent(new Event(`${$PREFIX}_blur`));
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
/**
|
|
1015
|
+
* @description 表示用のcanvasを更新
|
|
1016
|
+
* Update canvas for display
|
|
1017
|
+
*
|
|
1018
|
+
* @param {string} [background_color=transparent]
|
|
1019
|
+
* @return {void}
|
|
1020
|
+
* @method
|
|
1021
|
+
* @public
|
|
1022
|
+
*/
|
|
1023
|
+
_$setBackgroundColor(background_color = "transparent") {
|
|
1024
|
+
if ($rendererWorker) {
|
|
1025
|
+
$rendererWorker.postMessage({
|
|
1026
|
+
"command": "setBackgroundColor",
|
|
1027
|
+
"backgroundColor": background_color
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
else {
|
|
1031
|
+
const context = this._$context;
|
|
1032
|
+
if (!context) {
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
if (background_color === "transparent") {
|
|
1036
|
+
context._$setColor(0, 0, 0, 0);
|
|
1037
|
+
}
|
|
1038
|
+
else {
|
|
1039
|
+
const color = $uintToRGBA($toColorInt(background_color));
|
|
1040
|
+
context._$setColor(color.R / 255, color.G / 255, color.B / 255, 1);
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* @param {number} width
|
|
1046
|
+
* @param {number} height
|
|
1047
|
+
* @param {number} scale
|
|
1048
|
+
* @param {number} [tx = 0]
|
|
1049
|
+
* @param {number} [ty = 0]
|
|
1050
|
+
* @return {void}
|
|
1051
|
+
* @method
|
|
1052
|
+
* @private
|
|
1053
|
+
*/
|
|
1054
|
+
_$resizeCanvas(width, height, scale, tx = 0, ty = 0) {
|
|
1055
|
+
if ($rendererWorker) {
|
|
1056
|
+
$rendererWorker.postMessage({
|
|
1057
|
+
"command": "resize",
|
|
1058
|
+
"width": width,
|
|
1059
|
+
"height": height,
|
|
1060
|
+
"scale": scale,
|
|
1061
|
+
"tx": tx,
|
|
1062
|
+
"ty": ty
|
|
1063
|
+
});
|
|
1064
|
+
}
|
|
1065
|
+
else {
|
|
1066
|
+
const context = this._$context;
|
|
1067
|
+
if (!context) { // unit test
|
|
1068
|
+
return;
|
|
1069
|
+
}
|
|
1070
|
+
this._$canvas.width = width;
|
|
1071
|
+
this._$canvas.height = height;
|
|
1072
|
+
context._$gl.viewport(0, 0, width, height);
|
|
1073
|
+
const manager = context.frameBuffer;
|
|
1074
|
+
if (this._$attachment) {
|
|
1075
|
+
manager.unbind();
|
|
1076
|
+
manager.releaseAttachment(this._$attachment, true);
|
|
1077
|
+
}
|
|
1078
|
+
this._$attachment = manager
|
|
1079
|
+
.createCacheAttachment(width, height, false);
|
|
1080
|
+
// update cache max size
|
|
1081
|
+
context.setMaxSize(width, height);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
/**
|
|
1085
|
+
* @return {number}
|
|
1086
|
+
* @method
|
|
1087
|
+
* @private
|
|
1088
|
+
*/
|
|
1089
|
+
_$getSamples() {
|
|
1090
|
+
switch (this._$quality) {
|
|
1091
|
+
case "high":
|
|
1092
|
+
return 4;
|
|
1093
|
+
case "medium":
|
|
1094
|
+
return 2;
|
|
1095
|
+
default:
|
|
1096
|
+
return 0;
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* @param {Event} event
|
|
1101
|
+
* @return {boolean}
|
|
1102
|
+
* @method
|
|
1103
|
+
* @private
|
|
1104
|
+
*/
|
|
1105
|
+
_$dispatchEvent(event) {
|
|
1106
|
+
if (this._$broadcastEvents.size
|
|
1107
|
+
&& this._$broadcastEvents.has(event.type)) {
|
|
1108
|
+
// clone
|
|
1109
|
+
const events = this
|
|
1110
|
+
._$broadcastEvents
|
|
1111
|
+
.get(event.type)
|
|
1112
|
+
.slice(0);
|
|
1113
|
+
// start target
|
|
1114
|
+
event.eventPhase = EventPhase.AT_TARGET;
|
|
1115
|
+
for (let idx = 0; idx < events.length; ++idx) {
|
|
1116
|
+
const obj = events[idx];
|
|
1117
|
+
// event execute
|
|
1118
|
+
event.currentTarget = obj.target;
|
|
1119
|
+
event.listener = obj.listener;
|
|
1120
|
+
obj.listener.call(null, event);
|
|
1121
|
+
if (event._$stopImmediatePropagation) {
|
|
1122
|
+
break;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
$poolArray(events);
|
|
1126
|
+
return true;
|
|
1127
|
+
}
|
|
1128
|
+
return false;
|
|
1129
|
+
}
|
|
1130
|
+
/**
|
|
1131
|
+
* @param {number} timestamp
|
|
1132
|
+
* @return {void}
|
|
1133
|
+
* @method
|
|
1134
|
+
* @private
|
|
1135
|
+
*/
|
|
1136
|
+
_$run(timestamp = 0) {
|
|
1137
|
+
if (this._$stopFlag) {
|
|
1138
|
+
return;
|
|
1139
|
+
}
|
|
1140
|
+
// delay action
|
|
1141
|
+
this._$doAction();
|
|
1142
|
+
const delta = timestamp - this._$startTime;
|
|
1143
|
+
if (delta > this._$fps) {
|
|
1144
|
+
// update
|
|
1145
|
+
this._$startTime = timestamp - delta % this._$fps;
|
|
1146
|
+
// execute
|
|
1147
|
+
this._$action();
|
|
1148
|
+
// start sound
|
|
1149
|
+
if (this._$sounds.size) {
|
|
1150
|
+
for (const movieClip of this._$sounds.values()) {
|
|
1151
|
+
movieClip._$soundPlay();
|
|
1152
|
+
}
|
|
1153
|
+
this._$sounds.clear();
|
|
1154
|
+
}
|
|
1155
|
+
// draw
|
|
1156
|
+
this._$draw();
|
|
1157
|
+
// draw event
|
|
1158
|
+
if (!$isTouch
|
|
1159
|
+
&& !this._$hitTestStart
|
|
1160
|
+
&& this._$state === "up"
|
|
1161
|
+
&& this._$stageX > -1
|
|
1162
|
+
&& this._$stageY > -1
|
|
1163
|
+
&& $getEvent()) {
|
|
1164
|
+
this._$pointerCheck();
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
else {
|
|
1168
|
+
if (this._$videos.length && !$rendererWorker) {
|
|
1169
|
+
this._$draw();
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
// next frame
|
|
1173
|
+
this._$timerId = $requestAnimationFrame((timestamp) => {
|
|
1174
|
+
this._$run(timestamp);
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
/**
|
|
1178
|
+
* @return {void}
|
|
1179
|
+
* @method
|
|
1180
|
+
* @private
|
|
1181
|
+
*/
|
|
1182
|
+
_$pointerCheck() {
|
|
1183
|
+
const stageX = this._$stageX;
|
|
1184
|
+
const stageY = this._$stageY;
|
|
1185
|
+
// setup
|
|
1186
|
+
this._$hitObject.x = stageX;
|
|
1187
|
+
this._$hitObject.y = stageY;
|
|
1188
|
+
this._$hitObject.pointer = "";
|
|
1189
|
+
this._$hitObject.hit = null;
|
|
1190
|
+
// reset
|
|
1191
|
+
$hitContext.setTransform(1, 0, 0, 1, 0, 0);
|
|
1192
|
+
$hitContext.beginPath();
|
|
1193
|
+
// hit test
|
|
1194
|
+
$MATRIX_HIT_ARRAY_IDENTITY[4] = this._$tx / this._$scale / $devicePixelRatio;
|
|
1195
|
+
$MATRIX_HIT_ARRAY_IDENTITY[5] = this._$ty / this._$scale / $devicePixelRatio;
|
|
1196
|
+
this._$stage._$mouseHit($hitContext, $MATRIX_HIT_ARRAY_IDENTITY, this._$hitObject, true);
|
|
1197
|
+
// change state
|
|
1198
|
+
// params
|
|
1199
|
+
let instance = null;
|
|
1200
|
+
let target = null;
|
|
1201
|
+
let canPointerText = false;
|
|
1202
|
+
let canPointer = false;
|
|
1203
|
+
// execute
|
|
1204
|
+
if (this._$hitObject.hit) {
|
|
1205
|
+
instance = this._$hitObject.hit;
|
|
1206
|
+
// (1) mouseOut
|
|
1207
|
+
if (this._$mouseOverTarget
|
|
1208
|
+
&& this._$mouseOverTarget !== instance) {
|
|
1209
|
+
const outInstance = this._$mouseOverTarget;
|
|
1210
|
+
if (outInstance.willTrigger(Next2DMouseEvent.MOUSE_OUT)) {
|
|
1211
|
+
outInstance.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.MOUSE_OUT, true, false));
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
// rollOut and rollOver
|
|
1215
|
+
if (this._$rollOverObject !== instance) {
|
|
1216
|
+
let hitParent = null;
|
|
1217
|
+
if (this._$rollOverObject) {
|
|
1218
|
+
// (2) prev object rollOut
|
|
1219
|
+
target = this._$rollOverObject;
|
|
1220
|
+
if (target.willTrigger(Next2DMouseEvent.ROLL_OUT)) {
|
|
1221
|
+
target.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.ROLL_OUT, false, false));
|
|
1222
|
+
}
|
|
1223
|
+
// rollOver flag instance
|
|
1224
|
+
hitParent = target._$parent;
|
|
1225
|
+
while (hitParent && hitParent._$root !== hitParent) {
|
|
1226
|
+
if (hitParent === instance) {
|
|
1227
|
+
break;
|
|
1228
|
+
}
|
|
1229
|
+
if (hitParent._$mouseEnabled
|
|
1230
|
+
&& hitParent._$outCheck(stageX, stageY)) {
|
|
1231
|
+
let isUpperLayer = false;
|
|
1232
|
+
let check = instance;
|
|
1233
|
+
while (check && check._$root !== check) {
|
|
1234
|
+
if (check !== hitParent) {
|
|
1235
|
+
check = check._$parent;
|
|
1236
|
+
continue;
|
|
1237
|
+
}
|
|
1238
|
+
isUpperLayer = true;
|
|
1239
|
+
break;
|
|
1240
|
+
}
|
|
1241
|
+
if (!isUpperLayer && hitParent._$parent === instance._$parent
|
|
1242
|
+
&& hitParent._$index > instance._$index) {
|
|
1243
|
+
isUpperLayer = true;
|
|
1244
|
+
}
|
|
1245
|
+
if (isUpperLayer) {
|
|
1246
|
+
break;
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
if (hitParent.willTrigger(Next2DMouseEvent.ROLL_OUT)) {
|
|
1250
|
+
hitParent.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.ROLL_OUT, false, false));
|
|
1251
|
+
}
|
|
1252
|
+
hitParent = hitParent._$parent;
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
// (3) current object rollOver
|
|
1256
|
+
target = instance;
|
|
1257
|
+
for (;;) {
|
|
1258
|
+
if (target.willTrigger(Next2DMouseEvent.ROLL_OVER)) {
|
|
1259
|
+
target.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.ROLL_OVER, false, false));
|
|
1260
|
+
}
|
|
1261
|
+
target = target._$parent;
|
|
1262
|
+
if (!target || target === hitParent
|
|
1263
|
+
|| target.stage === target) {
|
|
1264
|
+
break;
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
this._$rollOverObject = instance;
|
|
1269
|
+
// (4) mouseOver
|
|
1270
|
+
switch (true) {
|
|
1271
|
+
case this._$mouseOverTarget === null:
|
|
1272
|
+
case this._$mouseOverTarget !== instance:
|
|
1273
|
+
if (instance && instance.willTrigger(Next2DMouseEvent.MOUSE_OVER)) {
|
|
1274
|
+
instance.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.MOUSE_OVER, true, false));
|
|
1275
|
+
}
|
|
1276
|
+
// set target
|
|
1277
|
+
this._$mouseOverTarget = instance;
|
|
1278
|
+
break;
|
|
1279
|
+
}
|
|
1280
|
+
// click reset
|
|
1281
|
+
if (this._$state === "up") {
|
|
1282
|
+
this._$clickTarget = null;
|
|
1283
|
+
}
|
|
1284
|
+
// PC
|
|
1285
|
+
if (!$isTouch && this._$state === "up") {
|
|
1286
|
+
target = instance;
|
|
1287
|
+
while (target && target.root !== target) {
|
|
1288
|
+
if ("_$text" in target) {
|
|
1289
|
+
if (target.type === "input") {
|
|
1290
|
+
canPointerText = true;
|
|
1291
|
+
break;
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
if ("buttonMode" in target && target.buttonMode) {
|
|
1295
|
+
canPointer = true;
|
|
1296
|
+
break;
|
|
1297
|
+
}
|
|
1298
|
+
target = target._$parent;
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
else {
|
|
1303
|
+
// (1) mouseOut
|
|
1304
|
+
if (this._$mouseOverTarget) {
|
|
1305
|
+
instance = this._$mouseOverTarget;
|
|
1306
|
+
if (instance.willTrigger(Next2DMouseEvent.MOUSE_OUT)) {
|
|
1307
|
+
instance.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.MOUSE_OUT, true, false));
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
// (2) rollOut
|
|
1311
|
+
if (this._$rollOverObject) {
|
|
1312
|
+
target = this._$rollOverObject;
|
|
1313
|
+
// parent target
|
|
1314
|
+
while (target && target.root !== target) {
|
|
1315
|
+
if (target.willTrigger(Next2DMouseEvent.ROLL_OUT)) {
|
|
1316
|
+
target.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.ROLL_OUT, false, false));
|
|
1317
|
+
}
|
|
1318
|
+
target = target._$parent;
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
// reset
|
|
1322
|
+
this._$rollOverObject = null;
|
|
1323
|
+
this._$mouseOverTarget = null;
|
|
1324
|
+
}
|
|
1325
|
+
// change cursor
|
|
1326
|
+
switch (true) {
|
|
1327
|
+
case canPointerText:
|
|
1328
|
+
this._$canvas.style.cursor = "text";
|
|
1329
|
+
break;
|
|
1330
|
+
case canPointer:
|
|
1331
|
+
this._$canvas.style.cursor = "pointer";
|
|
1332
|
+
break;
|
|
1333
|
+
case !$isTouch && this._$state === "up":
|
|
1334
|
+
this._$canvas.style.cursor = "auto";
|
|
1335
|
+
break;
|
|
1336
|
+
}
|
|
1337
|
+
if (this._$actions.length > 1) {
|
|
1338
|
+
this._$doAction();
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
/**
|
|
1342
|
+
* @return {void}
|
|
1343
|
+
* @method
|
|
1344
|
+
* @private
|
|
1345
|
+
*/
|
|
1346
|
+
_$action() {
|
|
1347
|
+
if (this._$stopFlag) {
|
|
1348
|
+
return;
|
|
1349
|
+
}
|
|
1350
|
+
let loaders = null;
|
|
1351
|
+
const length = this._$loaders.length;
|
|
1352
|
+
if (length) {
|
|
1353
|
+
// clone
|
|
1354
|
+
loaders = this._$loaders.slice(0);
|
|
1355
|
+
// array reset
|
|
1356
|
+
this._$loaders.length = 0;
|
|
1357
|
+
for (let idx = 0; idx < length; ++idx) {
|
|
1358
|
+
const loader = loaders[idx];
|
|
1359
|
+
// first action
|
|
1360
|
+
if ("content" in loader) {
|
|
1361
|
+
loader.content._$prepareActions();
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
// next frame
|
|
1366
|
+
this._$stage._$nextFrame();
|
|
1367
|
+
// enter frame event
|
|
1368
|
+
if (this._$broadcastEvents.has(Next2DEvent.ENTER_FRAME)) {
|
|
1369
|
+
this._$dispatchEvent(new Next2DEvent(Next2DEvent.ENTER_FRAME));
|
|
1370
|
+
}
|
|
1371
|
+
// constructed event
|
|
1372
|
+
if (this._$broadcastEvents.has(Next2DEvent.FRAME_CONSTRUCTED)) {
|
|
1373
|
+
this._$dispatchEvent(new Next2DEvent(Next2DEvent.FRAME_CONSTRUCTED));
|
|
1374
|
+
}
|
|
1375
|
+
// execute frame action
|
|
1376
|
+
this._$doAction();
|
|
1377
|
+
// exit event
|
|
1378
|
+
if (this._$broadcastEvents.has(Next2DEvent.EXIT_FRAME)) {
|
|
1379
|
+
this._$dispatchEvent(new Next2DEvent(Next2DEvent.EXIT_FRAME));
|
|
1380
|
+
}
|
|
1381
|
+
// render event
|
|
1382
|
+
if (this._$stage._$invalidate) {
|
|
1383
|
+
// reset
|
|
1384
|
+
this._$stage._$invalidate = false;
|
|
1385
|
+
// execute render event
|
|
1386
|
+
this._$dispatchEvent(new Next2DEvent(Next2DEvent.RENDER));
|
|
1387
|
+
}
|
|
1388
|
+
// loader events
|
|
1389
|
+
if (loaders) {
|
|
1390
|
+
for (let idx = 0; idx < loaders.length; ++idx) {
|
|
1391
|
+
const loader = loaders[idx];
|
|
1392
|
+
// init event
|
|
1393
|
+
if (loader.hasEventListener(Next2DEvent.INIT)) {
|
|
1394
|
+
loader.dispatchEvent(new Next2DEvent(Next2DEvent.INIT));
|
|
1395
|
+
}
|
|
1396
|
+
// complete event
|
|
1397
|
+
if (loader.hasEventListener(Next2DEvent.COMPLETE)) {
|
|
1398
|
+
loader.dispatchEvent(new Next2DEvent(Next2DEvent.COMPLETE));
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
// pool
|
|
1402
|
+
$poolArray(loaders);
|
|
1403
|
+
}
|
|
1404
|
+
// execute frame action
|
|
1405
|
+
this._$doAction();
|
|
1406
|
+
}
|
|
1407
|
+
/**
|
|
1408
|
+
* @returns void
|
|
1409
|
+
* @private
|
|
1410
|
+
*/
|
|
1411
|
+
_$draw() {
|
|
1412
|
+
if (!this._$width || !this._$height) {
|
|
1413
|
+
return;
|
|
1414
|
+
}
|
|
1415
|
+
if ($rendererWorker) {
|
|
1416
|
+
$rendererWorker.postMessage({
|
|
1417
|
+
"command": "draw"
|
|
1418
|
+
});
|
|
1419
|
+
}
|
|
1420
|
+
if (!this._$stage._$isUpdated()) {
|
|
1421
|
+
return;
|
|
1422
|
+
}
|
|
1423
|
+
const context = this._$context;
|
|
1424
|
+
if (!context) {
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1427
|
+
context._$bind(this._$attachment);
|
|
1428
|
+
// reset
|
|
1429
|
+
context.reset();
|
|
1430
|
+
context.setTransform(1, 0, 0, 1, 0, 0);
|
|
1431
|
+
context.clearRect(0, 0, this._$width, this._$height);
|
|
1432
|
+
context.beginPath();
|
|
1433
|
+
this._$stage._$draw(context, this._$matrix, $COLOR_ARRAY_IDENTITY);
|
|
1434
|
+
// stage end
|
|
1435
|
+
this._$stage._$updated = false;
|
|
1436
|
+
const manager = context.frameBuffer;
|
|
1437
|
+
const texture = manager
|
|
1438
|
+
.getTextureFromCurrentAttachment();
|
|
1439
|
+
manager.unbind();
|
|
1440
|
+
// reset and draw to main canvas
|
|
1441
|
+
context.reset();
|
|
1442
|
+
context.setTransform(1, 0, 0, 1, 0, 0);
|
|
1443
|
+
context.clearRect(0, 0, this._$width, this._$height);
|
|
1444
|
+
context.drawImage(texture, 0, 0, this._$width, this._$height);
|
|
1445
|
+
// re bind
|
|
1446
|
+
context._$bind(this._$attachment);
|
|
1447
|
+
}
|
|
1448
|
+
/**
|
|
1449
|
+
* @return {void}
|
|
1450
|
+
* @method
|
|
1451
|
+
* @private
|
|
1452
|
+
*/
|
|
1453
|
+
_$doAction() {
|
|
1454
|
+
while (this._$actions.length) {
|
|
1455
|
+
this._$actionProcess = true;
|
|
1456
|
+
// target object
|
|
1457
|
+
const mc = this._$actions.pop();
|
|
1458
|
+
if (!mc) {
|
|
1459
|
+
continue;
|
|
1460
|
+
}
|
|
1461
|
+
mc._$canAction = false;
|
|
1462
|
+
mc._$actionOffset = 0;
|
|
1463
|
+
mc._$actionLimit = 0;
|
|
1464
|
+
const frame = mc._$currentFrame;
|
|
1465
|
+
if (!mc._$actions.has(frame)) {
|
|
1466
|
+
continue;
|
|
1467
|
+
}
|
|
1468
|
+
const actions = mc._$actions.get(frame);
|
|
1469
|
+
if (!actions) {
|
|
1470
|
+
continue;
|
|
1471
|
+
}
|
|
1472
|
+
mc._$actionProcess = true;
|
|
1473
|
+
for (let idx = 0; idx < actions.length; ++idx) {
|
|
1474
|
+
$setCurrentLoaderInfo(mc._$loaderInfo);
|
|
1475
|
+
actions[idx].apply(mc);
|
|
1476
|
+
}
|
|
1477
|
+
mc._$actionProcess = false;
|
|
1478
|
+
// adjustment
|
|
1479
|
+
if (mc._$frameCache.size) {
|
|
1480
|
+
mc._$currentFrame = mc._$frameCache.get("nextFrame");
|
|
1481
|
+
mc._$clearChildren();
|
|
1482
|
+
mc._$stopFlag = mc._$frameCache.get("stopFlag");
|
|
1483
|
+
mc._$isPlaying = mc._$frameCache.get("isPlaying");
|
|
1484
|
+
mc._$frameCache.clear();
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
this._$actionProcess = false;
|
|
1488
|
+
$setCurrentLoaderInfo(null);
|
|
1489
|
+
}
|
|
1490
|
+
/**
|
|
1491
|
+
* @return {void}
|
|
1492
|
+
* @method
|
|
1493
|
+
* @private
|
|
1494
|
+
*/
|
|
1495
|
+
_$hitTest() {
|
|
1496
|
+
if (this._$stopFlag) {
|
|
1497
|
+
return;
|
|
1498
|
+
}
|
|
1499
|
+
// setup
|
|
1500
|
+
const event = $getEvent();
|
|
1501
|
+
if (!event) {
|
|
1502
|
+
return;
|
|
1503
|
+
}
|
|
1504
|
+
// update flags
|
|
1505
|
+
this._$hitTestStart = true;
|
|
1506
|
+
$doUpdated(false);
|
|
1507
|
+
// params
|
|
1508
|
+
let instance = null;
|
|
1509
|
+
let target = null;
|
|
1510
|
+
let x = $window.scrollX;
|
|
1511
|
+
let y = $window.scrollY;
|
|
1512
|
+
const div = $document
|
|
1513
|
+
.getElementById(this.contentElementId);
|
|
1514
|
+
if (div) {
|
|
1515
|
+
const rect = div.getBoundingClientRect();
|
|
1516
|
+
x += rect.left;
|
|
1517
|
+
y += rect.top;
|
|
1518
|
+
}
|
|
1519
|
+
let stageX = 0;
|
|
1520
|
+
let stageY = 0;
|
|
1521
|
+
if ("changedTouches" in event) {
|
|
1522
|
+
const changedTouche = event.changedTouches[0];
|
|
1523
|
+
stageX = changedTouche.pageX;
|
|
1524
|
+
stageY = changedTouche.pageY;
|
|
1525
|
+
}
|
|
1526
|
+
else if ("pageX" in event) {
|
|
1527
|
+
stageX = event.pageX;
|
|
1528
|
+
stageY = event.pageY;
|
|
1529
|
+
}
|
|
1530
|
+
// drop point
|
|
1531
|
+
stageX = (stageX - x) / this._$scale;
|
|
1532
|
+
stageY = (stageY - y) / this._$scale;
|
|
1533
|
+
// update
|
|
1534
|
+
this._$stageX = stageX;
|
|
1535
|
+
this._$stageY = stageY;
|
|
1536
|
+
// setup
|
|
1537
|
+
this._$hitObject.x = stageX;
|
|
1538
|
+
this._$hitObject.y = stageY;
|
|
1539
|
+
this._$hitObject.pointer = "";
|
|
1540
|
+
this._$hitObject.hit = null;
|
|
1541
|
+
// reset
|
|
1542
|
+
$hitContext.setTransform(1, 0, 0, 1, 0, 0);
|
|
1543
|
+
$hitContext.beginPath();
|
|
1544
|
+
// hit test
|
|
1545
|
+
$MATRIX_HIT_ARRAY_IDENTITY[4] = this._$tx / this._$scale / $devicePixelRatio;
|
|
1546
|
+
$MATRIX_HIT_ARRAY_IDENTITY[5] = this._$ty / this._$scale / $devicePixelRatio;
|
|
1547
|
+
this._$stage._$mouseHit($hitContext, $MATRIX_HIT_ARRAY_IDENTITY, this._$hitObject, true);
|
|
1548
|
+
// stop event
|
|
1549
|
+
if (this._$hitObject.hit) {
|
|
1550
|
+
event.preventDefault();
|
|
1551
|
+
}
|
|
1552
|
+
// change state
|
|
1553
|
+
let canPointerText = false;
|
|
1554
|
+
let staticPointer = false;
|
|
1555
|
+
let canPointer = false;
|
|
1556
|
+
const eventType = $getEventType();
|
|
1557
|
+
switch (eventType) {
|
|
1558
|
+
case $TOUCH_MOVE:
|
|
1559
|
+
case $MOUSE_MOVE:
|
|
1560
|
+
if ($dropTarget) {
|
|
1561
|
+
const point = $dropTarget._$dragMousePoint();
|
|
1562
|
+
let dragX = point.x;
|
|
1563
|
+
let dragY = point.y;
|
|
1564
|
+
if (!$dragRules.lock) {
|
|
1565
|
+
dragX += $dragRules.position.x;
|
|
1566
|
+
dragY += $dragRules.position.y;
|
|
1567
|
+
}
|
|
1568
|
+
const bounds = $dragRules.bounds;
|
|
1569
|
+
if (bounds) {
|
|
1570
|
+
dragX = $clamp(dragX, bounds.left, bounds.right);
|
|
1571
|
+
dragY = $clamp(dragY, bounds.top, bounds.bottom);
|
|
1572
|
+
}
|
|
1573
|
+
// set move xy
|
|
1574
|
+
$dropTarget.x = dragX;
|
|
1575
|
+
$dropTarget.y = dragY;
|
|
1576
|
+
}
|
|
1577
|
+
break;
|
|
1578
|
+
case $TOUCH_START:
|
|
1579
|
+
case $MOUSE_DOWN:
|
|
1580
|
+
this._$state = "down";
|
|
1581
|
+
canPointer = this._$canvas.style.cursor === "pointer";
|
|
1582
|
+
staticPointer = true;
|
|
1583
|
+
break;
|
|
1584
|
+
case $TOUCH_END:
|
|
1585
|
+
case $MOUSE_UP:
|
|
1586
|
+
case $DOUBLE_CLICK:
|
|
1587
|
+
this._$state = "up";
|
|
1588
|
+
break;
|
|
1589
|
+
}
|
|
1590
|
+
// execute
|
|
1591
|
+
switch (true) {
|
|
1592
|
+
case this._$hitObject.hit === null:
|
|
1593
|
+
case eventType === $MOUSE_LEAVE:
|
|
1594
|
+
// (1) mouseOut
|
|
1595
|
+
if (this._$mouseOverTarget) {
|
|
1596
|
+
instance = this._$mouseOverTarget;
|
|
1597
|
+
if (instance.willTrigger(Next2DMouseEvent.MOUSE_OUT)) {
|
|
1598
|
+
instance.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.MOUSE_OUT, true, false));
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
// (2) rollOut
|
|
1602
|
+
if (this._$rollOverObject) {
|
|
1603
|
+
target = this._$rollOverObject;
|
|
1604
|
+
// parent target
|
|
1605
|
+
while (target && target.root !== target) {
|
|
1606
|
+
if (target.willTrigger(Next2DMouseEvent.ROLL_OUT)) {
|
|
1607
|
+
target.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.ROLL_OUT, false, false));
|
|
1608
|
+
}
|
|
1609
|
+
target = target._$parent;
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
// reset
|
|
1613
|
+
this._$rollOverObject = null;
|
|
1614
|
+
this._$mouseOverTarget = null;
|
|
1615
|
+
// stage event
|
|
1616
|
+
switch (eventType) {
|
|
1617
|
+
case $MOUSE_WHEEL:
|
|
1618
|
+
if (this._$stage.hasEventListener(Next2DMouseEvent.MOUSE_WHEEL)) {
|
|
1619
|
+
this._$stage.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.MOUSE_WHEEL, true, false));
|
|
1620
|
+
}
|
|
1621
|
+
break;
|
|
1622
|
+
case $TOUCH_START:
|
|
1623
|
+
case $MOUSE_DOWN:
|
|
1624
|
+
if (this._$stage.hasEventListener(Next2DMouseEvent.MOUSE_DOWN)) {
|
|
1625
|
+
this._$stage.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.MOUSE_DOWN, true, false));
|
|
1626
|
+
}
|
|
1627
|
+
// TextField focus out
|
|
1628
|
+
if (this._$textField) {
|
|
1629
|
+
this._$textField.focus = false;
|
|
1630
|
+
this._$textField = null;
|
|
1631
|
+
}
|
|
1632
|
+
break;
|
|
1633
|
+
case $TOUCH_END:
|
|
1634
|
+
case $MOUSE_UP:
|
|
1635
|
+
// TextField focus out
|
|
1636
|
+
if (this._$textField) {
|
|
1637
|
+
this._$textField.focus = false;
|
|
1638
|
+
this._$textField = null;
|
|
1639
|
+
}
|
|
1640
|
+
if (this._$stage.hasEventListener(Next2DMouseEvent.CLICK)) {
|
|
1641
|
+
this._$stage.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.CLICK, true, false));
|
|
1642
|
+
}
|
|
1643
|
+
if (this._$stage.hasEventListener(Next2DMouseEvent.MOUSE_UP)) {
|
|
1644
|
+
this._$stage.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.MOUSE_UP, true, false));
|
|
1645
|
+
}
|
|
1646
|
+
break;
|
|
1647
|
+
case $TOUCH_MOVE:
|
|
1648
|
+
case $MOUSE_MOVE:
|
|
1649
|
+
if (this._$stage.hasEventListener(Next2DMouseEvent.MOUSE_MOVE)) {
|
|
1650
|
+
this._$stage.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.MOUSE_MOVE, true, false));
|
|
1651
|
+
}
|
|
1652
|
+
break;
|
|
1653
|
+
case $DOUBLE_CLICK:
|
|
1654
|
+
if (this._$stage.hasEventListener(Next2DMouseEvent.DOUBLE_CLICK)) {
|
|
1655
|
+
this._$stage.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.DOUBLE_CLICK, true, false));
|
|
1656
|
+
}
|
|
1657
|
+
break;
|
|
1658
|
+
}
|
|
1659
|
+
break;
|
|
1660
|
+
default:
|
|
1661
|
+
instance = this._$hitObject.hit;
|
|
1662
|
+
switch (eventType) {
|
|
1663
|
+
// move event
|
|
1664
|
+
case $TOUCH_MOVE:
|
|
1665
|
+
case $MOUSE_MOVE:
|
|
1666
|
+
// (1) mouseMove
|
|
1667
|
+
if (instance.willTrigger(Next2DMouseEvent.MOUSE_MOVE)) {
|
|
1668
|
+
instance.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.MOUSE_MOVE, true, false));
|
|
1669
|
+
}
|
|
1670
|
+
// (2) mouseOut
|
|
1671
|
+
if (this._$mouseOverTarget
|
|
1672
|
+
&& this._$mouseOverTarget !== instance) {
|
|
1673
|
+
const outInstance = this._$mouseOverTarget;
|
|
1674
|
+
if (outInstance.willTrigger(Next2DMouseEvent.MOUSE_OUT)) {
|
|
1675
|
+
outInstance.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.MOUSE_OUT, true, false));
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
// rollOut and rollOver
|
|
1679
|
+
if (this._$rollOverObject !== instance) {
|
|
1680
|
+
let hitParent = null;
|
|
1681
|
+
if (this._$rollOverObject) {
|
|
1682
|
+
// (3) prev object rollOut
|
|
1683
|
+
target = this._$rollOverObject;
|
|
1684
|
+
if (target.willTrigger(Next2DMouseEvent.ROLL_OUT)) {
|
|
1685
|
+
target.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.ROLL_OUT, false, false));
|
|
1686
|
+
}
|
|
1687
|
+
// rollOver flag instance
|
|
1688
|
+
hitParent = target._$parent;
|
|
1689
|
+
while (hitParent && hitParent._$root !== hitParent) {
|
|
1690
|
+
if (hitParent === instance) {
|
|
1691
|
+
break;
|
|
1692
|
+
}
|
|
1693
|
+
if (hitParent._$mouseEnabled
|
|
1694
|
+
&& hitParent._$outCheck(stageX, stageY)) {
|
|
1695
|
+
let isUpperLayer = false;
|
|
1696
|
+
let check = instance;
|
|
1697
|
+
while (check && check._$root !== check) {
|
|
1698
|
+
if (check !== hitParent) {
|
|
1699
|
+
check = check._$parent;
|
|
1700
|
+
continue;
|
|
1701
|
+
}
|
|
1702
|
+
isUpperLayer = true;
|
|
1703
|
+
break;
|
|
1704
|
+
}
|
|
1705
|
+
if (!isUpperLayer && hitParent._$parent === instance._$parent
|
|
1706
|
+
&& hitParent._$index > instance._$index) {
|
|
1707
|
+
isUpperLayer = true;
|
|
1708
|
+
}
|
|
1709
|
+
if (isUpperLayer) {
|
|
1710
|
+
break;
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
if (hitParent.willTrigger(Next2DMouseEvent.ROLL_OUT)) {
|
|
1714
|
+
hitParent.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.ROLL_OUT, false, false));
|
|
1715
|
+
}
|
|
1716
|
+
hitParent = hitParent._$parent;
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
// (4) current object rollOver
|
|
1720
|
+
target = instance;
|
|
1721
|
+
for (;;) {
|
|
1722
|
+
if (target.willTrigger(Next2DMouseEvent.ROLL_OVER)) {
|
|
1723
|
+
target.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.ROLL_OVER, false, false));
|
|
1724
|
+
}
|
|
1725
|
+
target = target._$parent;
|
|
1726
|
+
if (!target || target === hitParent
|
|
1727
|
+
|| target.stage === target) {
|
|
1728
|
+
break;
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
this._$rollOverObject = instance;
|
|
1733
|
+
// (5) mouseOver
|
|
1734
|
+
switch (true) {
|
|
1735
|
+
case this._$mouseOverTarget === null:
|
|
1736
|
+
case this._$mouseOverTarget !== instance:
|
|
1737
|
+
if (instance.willTrigger(Next2DMouseEvent.MOUSE_OVER)) {
|
|
1738
|
+
instance.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.MOUSE_OVER, true, false));
|
|
1739
|
+
}
|
|
1740
|
+
// set target
|
|
1741
|
+
this._$mouseOverTarget = instance;
|
|
1742
|
+
break;
|
|
1743
|
+
}
|
|
1744
|
+
// click reset
|
|
1745
|
+
if (this._$state === "up") {
|
|
1746
|
+
this._$clickTarget = null;
|
|
1747
|
+
}
|
|
1748
|
+
break;
|
|
1749
|
+
// down event
|
|
1750
|
+
case $TOUCH_START:
|
|
1751
|
+
case $MOUSE_DOWN:
|
|
1752
|
+
// TextField focus out
|
|
1753
|
+
if (this._$textField
|
|
1754
|
+
&& instance !== this._$textField
|
|
1755
|
+
&& "_$text" in this._$textField) {
|
|
1756
|
+
this._$textField.focus = false;
|
|
1757
|
+
this._$textField = null;
|
|
1758
|
+
}
|
|
1759
|
+
// TextField focus out
|
|
1760
|
+
if ("_$text" in instance) {
|
|
1761
|
+
instance.focus = true;
|
|
1762
|
+
this._$textField = instance;
|
|
1763
|
+
}
|
|
1764
|
+
// (3) mouseDown
|
|
1765
|
+
if (instance.willTrigger(Next2DMouseEvent.MOUSE_DOWN)) {
|
|
1766
|
+
instance.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.MOUSE_DOWN, true, false));
|
|
1767
|
+
}
|
|
1768
|
+
// (4) click
|
|
1769
|
+
this._$clickTarget = instance;
|
|
1770
|
+
break;
|
|
1771
|
+
// up event
|
|
1772
|
+
case $TOUCH_END:
|
|
1773
|
+
case $MOUSE_UP:
|
|
1774
|
+
// TextField focus out
|
|
1775
|
+
if (this._$textField
|
|
1776
|
+
&& instance !== this._$textField
|
|
1777
|
+
&& "_$text" in this._$textField) {
|
|
1778
|
+
this._$textField.focus = false;
|
|
1779
|
+
this._$textField = null;
|
|
1780
|
+
}
|
|
1781
|
+
// (1) mouseUp
|
|
1782
|
+
if (instance.willTrigger(Next2DMouseEvent.MOUSE_UP)) {
|
|
1783
|
+
instance.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.MOUSE_UP, true, false));
|
|
1784
|
+
}
|
|
1785
|
+
// (2) click
|
|
1786
|
+
if (this._$clickTarget === instance) {
|
|
1787
|
+
if (instance.willTrigger(Next2DMouseEvent.CLICK)) {
|
|
1788
|
+
instance.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.CLICK, true, false));
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
// reset
|
|
1792
|
+
this._$clickTarget = null;
|
|
1793
|
+
break;
|
|
1794
|
+
case $MOUSE_WHEEL:
|
|
1795
|
+
if (instance.willTrigger(Next2DMouseEvent.MOUSE_WHEEL)) {
|
|
1796
|
+
instance.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.MOUSE_WHEEL));
|
|
1797
|
+
}
|
|
1798
|
+
if ("deltaY" in event && instance.scrollEnabled) {
|
|
1799
|
+
// @ts-ignore
|
|
1800
|
+
instance.scrollV += $clamp(event.deltaY, -1, 1, 0);
|
|
1801
|
+
}
|
|
1802
|
+
break;
|
|
1803
|
+
case $DOUBLE_CLICK:
|
|
1804
|
+
if (instance.willTrigger(Next2DMouseEvent.DOUBLE_CLICK)) {
|
|
1805
|
+
instance.dispatchEvent(new Next2DMouseEvent(Next2DMouseEvent.DOUBLE_CLICK));
|
|
1806
|
+
}
|
|
1807
|
+
break;
|
|
1808
|
+
default:
|
|
1809
|
+
break;
|
|
1810
|
+
}
|
|
1811
|
+
// PC
|
|
1812
|
+
if (!staticPointer) {
|
|
1813
|
+
if (!$isTouch && this._$state === "up") {
|
|
1814
|
+
target = instance;
|
|
1815
|
+
while (target && target.root !== target) {
|
|
1816
|
+
if ("_$text" in target) {
|
|
1817
|
+
if (target.type === "input") {
|
|
1818
|
+
canPointerText = true;
|
|
1819
|
+
break;
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
else {
|
|
1823
|
+
if (target._$buttonMode) {
|
|
1824
|
+
canPointer = true;
|
|
1825
|
+
break;
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
target = target._$parent;
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
break;
|
|
1833
|
+
}
|
|
1834
|
+
// change cursor
|
|
1835
|
+
switch (true) {
|
|
1836
|
+
case canPointerText:
|
|
1837
|
+
this._$canvas.style.cursor = "text";
|
|
1838
|
+
break;
|
|
1839
|
+
case canPointer:
|
|
1840
|
+
this._$canvas.style.cursor = "pointer";
|
|
1841
|
+
break;
|
|
1842
|
+
case !$isTouch && this._$state === "up":
|
|
1843
|
+
this._$canvas.style.cursor = "auto";
|
|
1844
|
+
break;
|
|
1845
|
+
}
|
|
1846
|
+
// execute action
|
|
1847
|
+
if (!this._$actionProcess && this._$actions.length > 1) {
|
|
1848
|
+
this._$doAction();
|
|
1849
|
+
}
|
|
1850
|
+
if ($isUpdated()) {
|
|
1851
|
+
// action script
|
|
1852
|
+
this._$stage._$prepareActions();
|
|
1853
|
+
if (!this._$actionProcess) {
|
|
1854
|
+
this._$doAction();
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
this._$hitTestStart = false;
|
|
1858
|
+
}
|
|
1859
|
+
}
|