@galacean/engine-ui 0.0.0-experimental-2.0-migrate.4 → 0.0.0-experimental-2.0-migrate.6

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/dist/browser.js DELETED
@@ -1,4213 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@galacean/engine')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@galacean/engine'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.Galacean = global.Galacean || {}, global.Galacean.UI = {}), global.Galacean));
5
- })(this, (function (exports, engine) { 'use strict';
6
-
7
- function _set_prototype_of(o, p) {
8
- _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
9
- o.__proto__ = p;
10
-
11
- return o;
12
- };
13
-
14
- return _set_prototype_of(o, p);
15
- }
16
-
17
- function _inherits(subClass, superClass) {
18
- if (typeof superClass !== "function" && superClass !== null) {
19
- throw new TypeError("Super expression must either be null or a function");
20
- }
21
-
22
- subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });
23
-
24
- if (superClass) _set_prototype_of(subClass, superClass);
25
- }
26
-
27
- function _defineProperties(target, props) {
28
- for (var i = 0; i < props.length; i++) {
29
- var descriptor = props[i];
30
- descriptor.enumerable = descriptor.enumerable || false;
31
- descriptor.configurable = true;
32
-
33
- if ("value" in descriptor) descriptor.writable = true;
34
-
35
- Object.defineProperty(target, descriptor.key, descriptor);
36
- }
37
- }
38
- function _create_class(Constructor, protoProps, staticProps) {
39
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
40
- if (staticProps) _defineProperties(Constructor, staticProps);
41
-
42
- return Constructor;
43
- }
44
-
45
- /******************************************************************************
46
- Copyright (c) Microsoft Corporation.
47
-
48
- Permission to use, copy, modify, and/or distribute this software for any
49
- purpose with or without fee is hereby granted.
50
-
51
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
52
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
53
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
54
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
55
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
56
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
57
- PERFORMANCE OF THIS SOFTWARE.
58
- ***************************************************************************** */
59
-
60
- function __decorate(decorators, target, key, desc) {
61
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
62
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
63
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
64
- return c > 3 && r && Object.defineProperty(target, key, r), r;
65
- }
66
-
67
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
68
- var e = new Error(message);
69
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
70
- };
71
-
72
- function _instanceof(left, right) {
73
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
74
- return !!right[Symbol.hasInstance](left);
75
- } else return left instanceof right;
76
- }
77
-
78
- /**
79
- * @internal
80
- * Visual-layering driven UI batching: solve visual correctness first, batching falls out for free.
81
- *
82
- * Think of it as stacking elements onto numbered shelves (depths):
83
- * - Non-overlapping elements share shelf 0 — free to cluster regardless of material.
84
- * - Overlapping + batch-compatible — share the same shelf, still cluster.
85
- * - Overlapping + batch-incompatible — bumped one shelf higher (drawn on top).
86
- *
87
- * `depth` is a global tag, not a spatial group: distant elements at the same visual layer
88
- * share the same depth and get clustered together. Once depth is assigned, sort by
89
- * (depth, material, texture, hierarchyIndex) — visual order is locked, batching is the
90
- * by-product of materials clustering within each depth band.
91
- *
92
- * Overlap detection is accelerated by a 10×10 spatial grid. Grid origin and cell size
93
- * are derived from the union AABB of input elements (the bounds transform itself is the
94
- * work the loop must do anyway, so the union accumulation just piggybacks). This stays
95
- * correct across SS/WS canvases, any pivot, and any element distribution — no dependency
96
- * on canvas configuration.
97
- */ var UIBatchSorter = /*#__PURE__*/ function() {
98
- function UIBatchSorter() {}
99
- /**
100
- * Reorders `elements` in place for optimal batching.
101
- * @param elements - in hierarchy order (depth-first traversal); mutated in place
102
- * @param canvasWorldMatrix - reduces world bounds to canvas-local for precise overlap
103
- */ UIBatchSorter.sort = function sort(elements, canvasWorldMatrix) {
104
- var count = elements.length;
105
- if (count <= 1) return;
106
- var gridDim = this._gridDim;
107
- var entries = this._entries;
108
- var grid = this._grid;
109
- var dirtyCells = this._dirtyCells;
110
- var localBoundsPool = this._localBoundsPool;
111
- var worldToLocal = this._worldToLocal;
112
- engine.Matrix.invert(canvasWorldMatrix, worldToLocal);
113
- while(entries.length < count)entries.push(new SortEntry());
114
- // Allocate grid once, reuse forever (each cell must be a real [], not a sparse hole)
115
- if (grid.length < gridDim) {
116
- while(grid.length < gridDim)grid.push([]);
117
- for(var i = 0; i < gridDim; i++){
118
- var row = grid[i];
119
- while(row.length < gridDim)row.push([]);
120
- }
121
- }
122
- // Clear only previously-used cells (no full sweep)
123
- for(var k = 0, n = dirtyCells.length; k < n; k += 2){
124
- grid[dirtyCells[k]][dirtyCells[k + 1]].length = 0;
125
- }
126
- dirtyCells.length = 0;
127
- // Pass 1: transform world bounds to canvas-local + accumulate the union AABB.
128
- // Transform is already required to do precise overlap, so the union accumulation
129
- // is essentially free — just a few minmax compares riding on the existing pass
130
- var unionMinX = Infinity;
131
- var unionMinY = Infinity;
132
- var unionMaxX = -Infinity;
133
- var unionMaxY = -Infinity;
134
- for(var i1 = 0; i1 < count; i1++){
135
- var _localBoundsPool, _i;
136
- var localBounds = (_localBoundsPool = localBoundsPool)[_i = i1] || (_localBoundsPool[_i] = new engine.BoundingBox());
137
- engine.BoundingBox.transform(elements[i1].component.bounds, worldToLocal, localBounds);
138
- var min = localBounds.min, max = localBounds.max;
139
- if (min.x < unionMinX) unionMinX = min.x;
140
- if (min.y < unionMinY) unionMinY = min.y;
141
- if (max.x > unionMaxX) unionMaxX = max.x;
142
- if (max.y > unionMaxY) unionMaxY = max.y;
143
- }
144
- // Guard against a degenerate union (all elements collapsed onto a single point /
145
- // axis); the grid then collapses to cell 0 which is semantically correct
146
- var cellSizeX = Math.max(1e-6, unionMaxX - unionMinX) / gridDim;
147
- var cellSizeY = Math.max(1e-6, unionMaxY - unionMinY) / gridDim;
148
- var maxCell = gridDim - 1;
149
- // Pass 2: register each element into grid cells and compute its depth
150
- for(var i2 = 0; i2 < count; i2++){
151
- var element = elements[i2];
152
- var localBounds1 = localBoundsPool[i2];
153
- var materialId = element.material.instanceId;
154
- var textureId = element.texture ? element.texture.instanceId : 0;
155
- // Floor + clamp guards floating-point edge cases (a `max` exactly on the union
156
- // boundary would otherwise produce `gridDim`)
157
- var minCellX = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.min.x - unionMinX) / cellSizeX)));
158
- var maxCellX = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.max.x - unionMinX) / cellSizeX)));
159
- var minCellY = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.min.y - unionMinY) / cellSizeY)));
160
- var maxCellY = Math.min(maxCell, Math.max(0, Math.floor((localBounds1.max.y - unionMinY) / cellSizeY)));
161
- // Find the deepest overlapping prior, and whether that shelf has any incompatible occupant
162
- var maxDepth = -1;
163
- var maxDepthIncompatible = false;
164
- for(var cellY = minCellY; cellY <= maxCellY; cellY++){
165
- for(var cellX = minCellX; cellX <= maxCellX; cellX++){
166
- var cell = grid[cellX][cellY];
167
- for(var j = 0, m = cell.length; j < m; j++){
168
- var other = cell[j];
169
- if (!UIBatchSorter._rectOverlap(localBounds1, other.bounds)) continue;
170
- var otherDepth = other.depth;
171
- var otherIncompatible = other.materialId !== materialId || other.textureId !== textureId;
172
- if (otherDepth > maxDepth) {
173
- maxDepth = otherDepth;
174
- maxDepthIncompatible = otherIncompatible;
175
- } else if (otherDepth === maxDepth && otherIncompatible) {
176
- maxDepthIncompatible = true;
177
- }
178
- }
179
- }
180
- }
181
- var entry = entries[i2];
182
- entry.element = element;
183
- entry.hierarchyIndex = i2;
184
- // Share the deepest shelf if compatible; bump up one if blocked by an incompatible occupant
185
- entry.depth = maxDepth < 0 ? 0 : maxDepth + (maxDepthIncompatible ? 1 : 0);
186
- entry.materialId = materialId;
187
- entry.textureId = textureId;
188
- entry.bounds = localBounds1;
189
- for(var cellY1 = minCellY; cellY1 <= maxCellY; cellY1++){
190
- for(var cellX1 = minCellX; cellX1 <= maxCellX; cellX1++){
191
- var cell1 = grid[cellX1][cellY1];
192
- if (cell1.length === 0) dirtyCells.push(cellX1, cellY1);
193
- cell1.push(entry);
194
- }
195
- }
196
- }
197
- // @ts-ignore — Utils._quickSort is @internal
198
- engine.Utils._quickSort(entries, 0, count, UIBatchSorter._compareEntries);
199
- for(var i3 = 0; i3 < count; i3++)elements[i3] = entries[i3].element;
200
- };
201
- UIBatchSorter._rectOverlap = function _rectOverlap(a, b) {
202
- return a.min.x < b.max.x && a.max.x > b.min.x && a.min.y < b.max.y && a.max.y > b.min.y;
203
- };
204
- UIBatchSorter._compareEntries = function _compareEntries(a, b) {
205
- return a.depth - b.depth || a.materialId - b.materialId || a.textureId - b.textureId || a.hierarchyIndex - b.hierarchyIndex;
206
- };
207
- return UIBatchSorter;
208
- }();
209
- // Spatial-hash is fastest when cell size ≈ typical element size (one element per cell).
210
- // UI elements typically span ~10% of the canvas → 10×10 grid.
211
- UIBatchSorter._gridDim = 10;
212
- UIBatchSorter._entries = new Array();
213
- UIBatchSorter._grid = [];
214
- // Interleaved (x, y) cell coords touched in the previous frame
215
- UIBatchSorter._dirtyCells = new Array();
216
- UIBatchSorter._localBoundsPool = new Array();
217
- UIBatchSorter._worldToLocal = new engine.Matrix();
218
- // materialId/textureId/bounds are flattened from RenderElement to avoid
219
- // multi-hop property access in the hot inner loop and the sort comparator.
220
- var SortEntry = function SortEntry() {
221
- this.hierarchyIndex = 0;
222
- this.depth = 0;
223
- this.materialId = 0;
224
- this.textureId = 0;
225
- };
226
-
227
- /**
228
- * Render mode for ui canvas.
229
- */ var CanvasRenderMode = /*#__PURE__*/ function(CanvasRenderMode) {
230
- /**
231
- * The UI canvas will be rendered directly onto the screen and adapted to screen space,
232
- * overlaying other rendering elements in the same scene.
233
- * @remarks if the `engine.canvas` size change, the UI canvas will automatically adapt.
234
- */ CanvasRenderMode[CanvasRenderMode["ScreenSpaceOverlay"] = 0] = "ScreenSpaceOverlay";
235
- /**
236
- * The UI canvas is placed at a specified distance in front of the camera and adapted to screen space,
237
- * with all objects rendered by the camera.
238
- * @remarks if the camera's properties or the `engine.canvas` size change, the UI canvas will automatically adapt.
239
- * @remarks if set `ScreenSpaceCamera` but no corresponding camera is assigned, the actual rendering mode defaults to `ScreenSpaceOverlay`.
240
- */ CanvasRenderMode[CanvasRenderMode["ScreenSpaceCamera"] = 1] = "ScreenSpaceCamera";
241
- /**
242
- * The UI canvas is placed in the 3D world space and rendered by every camera in the same scene.
243
- */ CanvasRenderMode[CanvasRenderMode["WorldSpace"] = 2] = "WorldSpace";
244
- return CanvasRenderMode;
245
- }({});
246
-
247
- /**
248
- * Resolution adaptation mode.
249
- * @remarks Only effective in screen space.
250
- */ var ResolutionAdaptationMode = /*#__PURE__*/ function(ResolutionAdaptationMode) {
251
- /** Adapt based on width.(`referenceResolution.x`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["WidthAdaptation"] = 0] = "WidthAdaptation";
252
- /** Adapt based on height.(`referenceResolution.y`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["HeightAdaptation"] = 1] = "HeightAdaptation";
253
- /** Adapt based on both width and height.(`referenceResolution`) */ ResolutionAdaptationMode[ResolutionAdaptationMode["BothAdaptation"] = 2] = "BothAdaptation";
254
- /** Adapt to the side with a larger ratio. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ExpandAdaptation"] = 3] = "ExpandAdaptation";
255
- /** Adapt to the side with smaller ratio. */ ResolutionAdaptationMode[ResolutionAdaptationMode["ShrinkAdaptation"] = 4] = "ShrinkAdaptation";
256
- return ResolutionAdaptationMode;
257
- }({});
258
-
259
- /** Horizontal alignment mode. */ var HorizontalAlignmentMode = /*#__PURE__*/ function(HorizontalAlignmentMode) {
260
- /** No horizontal alignment. */ HorizontalAlignmentMode[HorizontalAlignmentMode["None"] = 0] = "None";
261
- /** Left-aligned, `alignLeft` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Left"] = 1] = "Left";
262
- /** Right-aligned, `alignRight` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Right"] = 2] = "Right";
263
- /** Horizontal stretch, `alignLeft` and `alignRight` drive `position.x` and `size.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["LeftAndRight"] = 3] = "LeftAndRight";
264
- /** Center-aligned, `alignCenter` drives `position.x`. */ HorizontalAlignmentMode[HorizontalAlignmentMode["Center"] = 4] = "Center";
265
- return HorizontalAlignmentMode;
266
- }({});
267
-
268
- /** Vertical alignment mode. */ var VerticalAlignmentMode = /*#__PURE__*/ function(VerticalAlignmentMode) {
269
- /** No vertical alignment. */ VerticalAlignmentMode[VerticalAlignmentMode["None"] = 0] = "None";
270
- /** Top-aligned, `alignTop` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Top"] = 1] = "Top";
271
- /** Bottom-aligned, `alignBottom` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Bottom"] = 2] = "Bottom";
272
- /** Vertical stretch, `alignTop` and `alignBottom` drive `position.y` and `size.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["TopAndBottom"] = 3] = "TopAndBottom";
273
- /** Middle-aligned, `alignMiddle` drives `position.y`. */ VerticalAlignmentMode[VerticalAlignmentMode["Middle"] = 4] = "Middle";
274
- return VerticalAlignmentMode;
275
- }({});
276
-
277
- /**
278
- * The Transform component exclusive to the UI element.
279
- */ var UITransform = /*#__PURE__*/ function(Transform) {
280
- _inherits(UITransform, Transform);
281
- function UITransform(entity) {
282
- var _this;
283
- _this = Transform.call(this, entity) || this, _this._size = new engine.Vector2(100, 100), _this._pivot = new engine.Vector2(0.5, 0.5), _this._rect = new engine.Rect(-50, -50, 100, 100), _this._alignLeft = 0, _this._alignRight = 0, _this._alignCenter = 0, _this._alignTop = 0, _this._alignBottom = 0, _this._alignMiddle = 0, _this._horizontalAlignment = HorizontalAlignmentMode.None, _this._verticalAlignment = VerticalAlignmentMode.None;
284
- _this._onSizeChanged = _this._onSizeChanged.bind(_this);
285
- _this._onPivotChanged = _this._onPivotChanged.bind(_this);
286
- // @ts-ignore
287
- _this._size._onValueChanged = _this._onSizeChanged;
288
- // @ts-ignore
289
- _this._pivot._onValueChanged = _this._onPivotChanged;
290
- return _this;
291
- }
292
- var _proto = UITransform.prototype;
293
- /**
294
- * @internal
295
- */ _proto._parentChange = function _parentChange() {
296
- this._isParentDirty = true;
297
- this._updateWorldFlagWithParentRectChange(engine.TransformModifyFlags.WmWpWeWqWsWus);
298
- };
299
- // @ts-ignore
300
- _proto._cloneTo = function _cloneTo(target) {
301
- // @ts-ignore
302
- Transform.prototype._cloneTo.call(this, target);
303
- var size = target._size, pivot = target._pivot;
304
- // @ts-ignore
305
- size._onValueChanged = pivot._onValueChanged = null;
306
- size.copyFrom(this._size);
307
- pivot.copyFrom(this._pivot);
308
- // @ts-ignore
309
- size._onValueChanged = target._onSizeChanged;
310
- // @ts-ignore
311
- pivot._onValueChanged = target._onPivotChanged;
312
- };
313
- _proto._onLocalMatrixChanging = function _onLocalMatrixChanging() {
314
- // `super._onLocalMatrixChanging()` will set `LocalMatrix` dirty flag `false`
315
- // If there is an alignment, `position` and `localMatrix` will be reset again
316
- if (this._horizontalAlignment || this._verticalAlignment) {
317
- this._updatePositionByAlignment();
318
- this._setDirtyFlagTrue(engine.TransformModifyFlags.LocalMatrix);
319
- } else {
320
- Transform.prototype._onLocalMatrixChanging.call(this);
321
- }
322
- };
323
- _proto._onWorldMatrixChanging = function _onWorldMatrixChanging() {
324
- // `super._onWorldMatrixChanging()` will set `WorldMatrix` dirty flag `false`
325
- // If there is an alignment, `position` and `worldMatrix` will be reset again(`worldMatrix` dirty flag is already `true`)
326
- !this._horizontalAlignment && !this._verticalAlignment && Transform.prototype._onWorldMatrixChanging.call(this);
327
- };
328
- _proto._onPositionChanged = function _onPositionChanged() {
329
- (this._horizontalAlignment || this._verticalAlignment) && this._updatePositionByAlignment();
330
- Transform.prototype._onPositionChanged.call(this);
331
- };
332
- _proto._onWorldPositionChanged = function _onWorldPositionChanged() {
333
- Transform.prototype._onWorldPositionChanged.call(this);
334
- if (this._horizontalAlignment || this._verticalAlignment) {
335
- this._setDirtyFlagTrue(engine.TransformModifyFlags.WorldPosition);
336
- }
337
- };
338
- _proto._updatePositionByAlignment = function _updatePositionByAlignment() {
339
- var _this__getParentTransform;
340
- var parentRect = (_this__getParentTransform = this._getParentTransform()) == null ? void 0 : _this__getParentTransform._rect;
341
- if (parentRect) {
342
- var position = this.position;
343
- // @ts-ignore
344
- position._onValueChanged = null;
345
- var rect = this._rect;
346
- switch(this._horizontalAlignment){
347
- case HorizontalAlignmentMode.Left:
348
- case HorizontalAlignmentMode.LeftAndRight:
349
- position.x = parentRect.x - rect.x + this._alignLeft;
350
- break;
351
- case HorizontalAlignmentMode.Center:
352
- position.x = parentRect.x + parentRect.width * 0.5 - rect.x - rect.width * 0.5 + this._alignCenter;
353
- break;
354
- case HorizontalAlignmentMode.Right:
355
- position.x = parentRect.x + parentRect.width - rect.x - rect.width - this._alignRight;
356
- break;
357
- }
358
- switch(this._verticalAlignment){
359
- case VerticalAlignmentMode.Top:
360
- position.y = parentRect.y + parentRect.height - rect.y - rect.height - this._alignTop;
361
- break;
362
- case VerticalAlignmentMode.Middle:
363
- position.y = parentRect.y + parentRect.height * 0.5 - rect.y - rect.height * 0.5 + this._alignMiddle;
364
- break;
365
- case VerticalAlignmentMode.Bottom:
366
- case VerticalAlignmentMode.TopAndBottom:
367
- position.y = parentRect.y - rect.y + this._alignBottom;
368
- break;
369
- }
370
- // @ts-ignore
371
- position._onValueChanged = this._onPositionChanged;
372
- }
373
- };
374
- _proto._updateSizeByAlignment = function _updateSizeByAlignment() {
375
- var _this__getParentTransform;
376
- var parentRect = (_this__getParentTransform = this._getParentTransform()) == null ? void 0 : _this__getParentTransform._rect;
377
- if (parentRect) {
378
- var size = this._size;
379
- // @ts-ignore
380
- size._onValueChanged = null;
381
- // The values of size must be greater than 0
382
- if (this._horizontalAlignment === HorizontalAlignmentMode.LeftAndRight) {
383
- size.x = Math.max(parentRect.width - this._alignLeft - this._alignRight, 0);
384
- }
385
- if (this._verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
386
- size.y = Math.max(parentRect.height - this._alignTop - this._alignBottom, 0);
387
- }
388
- // @ts-ignore
389
- size._onValueChanged = this._onSizeChanged;
390
- }
391
- };
392
- _proto._updateRectBySizeAndPivot = function _updateRectBySizeAndPivot() {
393
- var _this = this, size = _this.size, pivot = _this._pivot;
394
- var x = -pivot.x * size.x;
395
- var y = -pivot.y * size.y;
396
- this._rect.set(x, y, size.x, size.y);
397
- };
398
- _proto._onSizeChanged = function _onSizeChanged() {
399
- if (this._horizontalAlignment === HorizontalAlignmentMode.LeftAndRight || this._verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
400
- this._updateSizeByAlignment();
401
- }
402
- this._updateRectBySizeAndPivot();
403
- this._updateWorldFlagWithSelfRectChange();
404
- // @ts-ignore
405
- this._entity._updateFlagManager.dispatch(512);
406
- };
407
- _proto._onPivotChanged = function _onPivotChanged() {
408
- this._updateRectBySizeAndPivot();
409
- this._updateWorldFlagWithSelfRectChange();
410
- // @ts-ignore
411
- this._entity._updateFlagManager.dispatch(1024);
412
- };
413
- _proto._updateWorldFlagWithSelfRectChange = function _updateWorldFlagWithSelfRectChange() {
414
- var worldFlags = 0;
415
- if (this._horizontalAlignment || this._verticalAlignment) {
416
- this._updatePositionByAlignment();
417
- this._setDirtyFlagTrue(engine.TransformModifyFlags.LocalMatrix);
418
- worldFlags = engine.TransformModifyFlags.WmWp;
419
- !this._isContainDirtyFlags(worldFlags) && this._worldAssociatedChange(worldFlags);
420
- }
421
- var children = this.entity.children;
422
- for(var i = 0, n = children.length; i < n; i++){
423
- var _children_i_transform__updateWorldFlagWithParentRectChange, _children_i_transform;
424
- (_children_i_transform = children[i].transform) == null ? void 0 : (_children_i_transform__updateWorldFlagWithParentRectChange = _children_i_transform._updateWorldFlagWithParentRectChange) == null ? void 0 : _children_i_transform__updateWorldFlagWithParentRectChange.call(_children_i_transform, worldFlags);
425
- }
426
- };
427
- _proto._updateWorldFlagWithParentRectChange = function _updateWorldFlagWithParentRectChange(flags, parentChange) {
428
- if (parentChange === void 0) parentChange = true;
429
- var selfChange = false;
430
- if (parentChange) {
431
- var _this = this, horizontalAlignment = _this._horizontalAlignment, verticalAlignment = _this._verticalAlignment;
432
- if (horizontalAlignment || verticalAlignment) {
433
- if (horizontalAlignment === HorizontalAlignmentMode.LeftAndRight || verticalAlignment === VerticalAlignmentMode.TopAndBottom) {
434
- this._updateSizeByAlignment();
435
- this._updateRectBySizeAndPivot();
436
- selfChange = true;
437
- }
438
- this._updatePositionByAlignment();
439
- this._setDirtyFlagTrue(engine.TransformModifyFlags.LocalMatrix);
440
- flags |= engine.TransformModifyFlags.WmWp;
441
- }
442
- }
443
- var containDirtyFlags = this._isContainDirtyFlags(flags);
444
- !containDirtyFlags && this._worldAssociatedChange(flags);
445
- if (selfChange || !containDirtyFlags) {
446
- var children = this.entity.children;
447
- for(var i = 0, n = children.length; i < n; i++){
448
- var _children_i_transform__updateWorldFlagWithParentRectChange, _children_i_transform;
449
- (_children_i_transform = children[i].transform) == null ? void 0 : (_children_i_transform__updateWorldFlagWithParentRectChange = _children_i_transform._updateWorldFlagWithParentRectChange) == null ? void 0 : _children_i_transform__updateWorldFlagWithParentRectChange.call(_children_i_transform, flags, selfChange);
450
- }
451
- }
452
- // @ts-ignore
453
- selfChange && this._entity._updateFlagManager.dispatch(512);
454
- };
455
- _create_class(UITransform, [
456
- {
457
- key: "size",
458
- get: /**
459
- * Width and height of UI element.
460
- */ function get() {
461
- return this._size;
462
- },
463
- set: function set(value) {
464
- var _this = this, size = _this._size;
465
- if (size === value) return;
466
- (size.x !== value.x || size.y !== value.y) && size.copyFrom(value);
467
- }
468
- },
469
- {
470
- key: "pivot",
471
- get: /**
472
- * Pivot of UI element.
473
- */ function get() {
474
- return this._pivot;
475
- },
476
- set: function set(value) {
477
- var _this = this, pivot = _this._pivot;
478
- if (pivot === value) return;
479
- (pivot.x !== value.x || pivot.y !== value.y) && pivot.copyFrom(value);
480
- }
481
- },
482
- {
483
- key: "horizontalAlignment",
484
- get: /**
485
- * Horizontal alignment mode.
486
- *
487
- * @remarks
488
- * Controls how the element aligns horizontally within its parent:
489
- * - `Left` - Align to parent's left edge
490
- * - `Center` - Align to parent's horizontal center
491
- * - `Right` - Align to parent's right edge
492
- * - `LeftAndRight` - Align to both left and right edges (stretch to fill width)
493
- */ function get() {
494
- return this._horizontalAlignment;
495
- },
496
- set: function set(value) {
497
- if (this._horizontalAlignment === value) return;
498
- this._horizontalAlignment = value;
499
- switch(value){
500
- case HorizontalAlignmentMode.Left:
501
- case HorizontalAlignmentMode.Right:
502
- case HorizontalAlignmentMode.Center:
503
- this._onPositionChanged();
504
- break;
505
- case HorizontalAlignmentMode.LeftAndRight:
506
- this._onPositionChanged();
507
- this._onSizeChanged();
508
- break;
509
- }
510
- }
511
- },
512
- {
513
- key: "alignLeft",
514
- get: /**
515
- * Left margin when horizontalAlignment is Left or LeftAndRight.
516
- *
517
- * @remarks
518
- * Only effective when horizontalAlignment includes Left mode.
519
- * Distance from the parent's left edge to the element's left edge.
520
- */ function get() {
521
- return this._alignLeft;
522
- },
523
- set: function set(value) {
524
- if (!Number.isFinite(value)) return;
525
- if (engine.MathUtil.equals(value, this._alignLeft)) return;
526
- this._alignLeft = value;
527
- if (this._horizontalAlignment & HorizontalAlignmentMode.Left) {
528
- this._onPositionChanged();
529
- this._horizontalAlignment & HorizontalAlignmentMode.Right && this._onSizeChanged();
530
- }
531
- }
532
- },
533
- {
534
- key: "alignRight",
535
- get: /**
536
- * Right margin when horizontalAlignment is Right or LeftAndRight.
537
- *
538
- * @remarks
539
- * Only effective when horizontalAlignment includes Right mode.
540
- * Distance from the parent's right edge to the element's right edge.
541
- */ function get() {
542
- return this._alignRight;
543
- },
544
- set: function set(value) {
545
- if (!Number.isFinite(value)) return;
546
- if (engine.MathUtil.equals(value, this._alignRight)) return;
547
- this._alignRight = value;
548
- if (this._horizontalAlignment & HorizontalAlignmentMode.Right) {
549
- this._onPositionChanged();
550
- this._horizontalAlignment & HorizontalAlignmentMode.Left && this._onSizeChanged();
551
- }
552
- }
553
- },
554
- {
555
- key: "alignCenter",
556
- get: /**
557
- * Horizontal center offset when horizontalAlignment is Center.
558
- *
559
- * @remarks
560
- * Only effective when horizontalAlignment is Center mode.
561
- * Positive values move the element to the right, negative values to the left.
562
- */ function get() {
563
- return this._alignCenter;
564
- },
565
- set: function set(value) {
566
- if (!Number.isFinite(value)) return;
567
- if (engine.MathUtil.equals(value, this._alignCenter)) return;
568
- this._alignCenter = value;
569
- this._horizontalAlignment & HorizontalAlignmentMode.Center && this._onPositionChanged();
570
- }
571
- },
572
- {
573
- key: "verticalAlignment",
574
- get: /**
575
- * Vertical alignment mode.
576
- *
577
- * @remarks
578
- * Controls how the element aligns vertically within its parent:
579
- * - `Top` - Align to parent's top edge
580
- * - `Middle` - Align to parent's vertical center
581
- * - `Bottom` - Align to parent's bottom edge
582
- * - `TopAndBottom` - Align to both top and bottom edges (stretch to fill height)
583
- */ function get() {
584
- return this._verticalAlignment;
585
- },
586
- set: function set(value) {
587
- if (this._verticalAlignment === value) return;
588
- this._verticalAlignment = value;
589
- switch(value){
590
- case VerticalAlignmentMode.Top:
591
- case VerticalAlignmentMode.Bottom:
592
- case VerticalAlignmentMode.Middle:
593
- this._onPositionChanged();
594
- break;
595
- case VerticalAlignmentMode.TopAndBottom:
596
- this._onPositionChanged();
597
- this._onSizeChanged();
598
- break;
599
- }
600
- }
601
- },
602
- {
603
- key: "alignTop",
604
- get: /**
605
- * Top margin when verticalAlignment is Top or TopAndBottom.
606
- *
607
- * @remarks
608
- * Only effective when verticalAlignment includes Top mode.
609
- * Used to offset the element from the parent's top edge.
610
- */ function get() {
611
- return this._alignTop;
612
- },
613
- set: function set(value) {
614
- if (!Number.isFinite(value)) return;
615
- if (engine.MathUtil.equals(value, this._alignTop)) return;
616
- this._alignTop = value;
617
- if (this._verticalAlignment & VerticalAlignmentMode.Top) {
618
- this._onPositionChanged();
619
- this._verticalAlignment & VerticalAlignmentMode.Bottom && this._onSizeChanged();
620
- }
621
- }
622
- },
623
- {
624
- key: "alignBottom",
625
- get: /**
626
- * Bottom inset used in vertical alignment formulas.
627
- */ function get() {
628
- return this._alignBottom;
629
- },
630
- set: function set(value) {
631
- if (!Number.isFinite(value)) return;
632
- if (engine.MathUtil.equals(value, this._alignBottom)) return;
633
- this._alignBottom = value;
634
- if (this._verticalAlignment & VerticalAlignmentMode.Bottom) {
635
- this._onPositionChanged();
636
- this._verticalAlignment & VerticalAlignmentMode.Top && this._onSizeChanged();
637
- }
638
- }
639
- },
640
- {
641
- key: "alignMiddle",
642
- get: /**
643
- * Vertical middle offset relative to parent's middle.
644
- */ function get() {
645
- return this._alignMiddle;
646
- },
647
- set: function set(value) {
648
- if (!Number.isFinite(value)) return;
649
- if (engine.MathUtil.equals(value, this._alignMiddle)) return;
650
- this._alignMiddle = value;
651
- this._verticalAlignment & VerticalAlignmentMode.Middle && this._onPositionChanged();
652
- }
653
- }
654
- ]);
655
- return UITransform;
656
- }(engine.Transform);
657
- __decorate([
658
- engine.ignoreClone
659
- ], UITransform.prototype, "_size", void 0);
660
- __decorate([
661
- engine.ignoreClone
662
- ], UITransform.prototype, "_pivot", void 0);
663
- __decorate([
664
- engine.ignoreClone
665
- ], UITransform.prototype, "_onPositionChanged", null);
666
- __decorate([
667
- engine.ignoreClone
668
- ], UITransform.prototype, "_onWorldPositionChanged", null);
669
- __decorate([
670
- engine.ignoreClone
671
- ], UITransform.prototype, "_onSizeChanged", null);
672
- __decorate([
673
- engine.ignoreClone
674
- ], UITransform.prototype, "_onPivotChanged", null);
675
- /**
676
- * @internal
677
- * extends TransformModifyFlags
678
- */ var UITransformModifyFlags = /*#__PURE__*/ function(UITransformModifyFlags) {
679
- UITransformModifyFlags[UITransformModifyFlags["Size"] = 512] = "Size";
680
- UITransformModifyFlags[UITransformModifyFlags["Pivot"] = 1024] = "Pivot";
681
- return UITransformModifyFlags;
682
- }({});
683
-
684
- exports.RectMask2D = /*#__PURE__*/ function(Component) {
685
- _inherits(RectMask2D, Component);
686
- function RectMask2D(entity) {
687
- var _this;
688
- _this = Component.call(this, entity) || this, _this._softness = new engine.Vector2(0, 0), _this._alphaClip = false;
689
- _this._onSoftnessChanged = _this._onSoftnessChanged.bind(_this);
690
- // @ts-ignore
691
- _this._softness._onValueChanged = _this._onSoftnessChanged;
692
- return _this;
693
- }
694
- var _proto = RectMask2D.prototype;
695
- /**
696
- * @internal
697
- */ _proto._getWorldRect = function _getWorldRect(out) {
698
- var transform = this.entity.transform;
699
- var _transform_size = transform.size, width = _transform_size.x, height = _transform_size.y;
700
- if (!width || !height) {
701
- return false;
702
- }
703
- var _transform_pivot = transform.pivot, pivotX = _transform_pivot.x, pivotY = _transform_pivot.y;
704
- var left = -width * pivotX;
705
- var right = width * (1 - pivotX);
706
- var bottom = -height * pivotY;
707
- var top = height * (1 - pivotY);
708
- var worldMatrix = transform.worldMatrix;
709
- var corner0 = RectMask2D._tempCorner0;
710
- var corner1 = RectMask2D._tempCorner1;
711
- var corner2 = RectMask2D._tempCorner2;
712
- var corner3 = RectMask2D._tempCorner3;
713
- engine.Vector3.transformCoordinate(corner0.set(left, bottom, 0), worldMatrix, corner0);
714
- engine.Vector3.transformCoordinate(corner1.set(left, top, 0), worldMatrix, corner1);
715
- engine.Vector3.transformCoordinate(corner2.set(right, bottom, 0), worldMatrix, corner2);
716
- engine.Vector3.transformCoordinate(corner3.set(right, top, 0), worldMatrix, corner3);
717
- var minX = Math.min(corner0.x, corner1.x, corner2.x, corner3.x);
718
- var minY = Math.min(corner0.y, corner1.y, corner2.y, corner3.y);
719
- var maxX = Math.max(corner0.x, corner1.x, corner2.x, corner3.x);
720
- var maxY = Math.max(corner0.y, corner1.y, corner2.y, corner3.y);
721
- out.set(minX, minY, maxX, maxY);
722
- return true;
723
- };
724
- /**
725
- * @internal
726
- */ _proto._containsWorldPoint = function _containsWorldPoint(worldPoint) {
727
- var worldRect = RectMask2D._tempRect;
728
- if (!this._getWorldRect(worldRect)) {
729
- return false;
730
- }
731
- var x = worldPoint.x, y = worldPoint.y;
732
- return x >= worldRect.x && x <= worldRect.z && y >= worldRect.y && y <= worldRect.w;
733
- };
734
- // @ts-ignore
735
- _proto._onEnableInScene = function _onEnableInScene() {
736
- this.entity._updateUIHierarchyVersion(exports.UICanvas._hierarchyCounter);
737
- };
738
- // @ts-ignore
739
- _proto._onDisableInScene = function _onDisableInScene() {
740
- this.entity._updateUIHierarchyVersion(exports.UICanvas._hierarchyCounter);
741
- };
742
- // @ts-ignore
743
- _proto._cloneTo = function _cloneTo(target) {
744
- // RectMask2D extends Component directly; Component.prototype 上没有 _cloneTo,
745
- // 不能 super._cloneTo(target) — 会拿到 undefined 报 "Cannot read properties of undefined (reading 'call')"。
746
- // (Image/Mask 走 Renderer 链路所以能 super;RectMask2D 不在 Renderer 链路里。)
747
- var targetSoftness = target._softness;
748
- // @ts-ignore
749
- targetSoftness._onValueChanged = null;
750
- targetSoftness.copyFrom(this._softness);
751
- target._clampSoftness();
752
- // @ts-ignore
753
- targetSoftness._onValueChanged = target._onSoftnessChanged;
754
- };
755
- _proto._onDestroy = function _onDestroy() {
756
- // @ts-ignore
757
- this._softness._onValueChanged = null;
758
- this._softness = null;
759
- Component.prototype._onDestroy.call(this);
760
- };
761
- _proto._onSoftnessChanged = function _onSoftnessChanged() {
762
- this._clampSoftness();
763
- };
764
- _proto._clampSoftness = function _clampSoftness() {
765
- var softness = this._softness;
766
- if (softness.x < 0) {
767
- softness.x = 0;
768
- }
769
- if (softness.y < 0) {
770
- softness.y = 0;
771
- }
772
- };
773
- _create_class(RectMask2D, [
774
- {
775
- key: "softness",
776
- get: /**
777
- * Soft clipping width on X/Y axis in world space.
778
- */ function get() {
779
- return this._softness;
780
- },
781
- set: function set(value) {
782
- var softness = this._softness;
783
- if (softness === value) {
784
- return;
785
- }
786
- if (softness.x !== value.x || softness.y !== value.y) {
787
- softness.copyFrom(value);
788
- this._clampSoftness();
789
- }
790
- }
791
- },
792
- {
793
- key: "alphaClip",
794
- get: /**
795
- * Whether to enable hard clip (discard) when outside the rect.
796
- */ function get() {
797
- return this._alphaClip;
798
- },
799
- set: function set(value) {
800
- this._alphaClip = value;
801
- }
802
- }
803
- ]);
804
- return RectMask2D;
805
- }(engine.Component);
806
- exports.RectMask2D._tempRect = new engine.Vector4();
807
- exports.RectMask2D._tempCorner0 = new engine.Vector3();
808
- exports.RectMask2D._tempCorner1 = new engine.Vector3();
809
- exports.RectMask2D._tempCorner2 = new engine.Vector3();
810
- exports.RectMask2D._tempCorner3 = new engine.Vector3();
811
- exports.RectMask2D = __decorate([
812
- engine.dependentComponents(UITransform, engine.DependentMode.AutoAdd)
813
- ], exports.RectMask2D);
814
-
815
- var UIGroup = /*#__PURE__*/ function(Component) {
816
- _inherits(UIGroup, Component);
817
- function UIGroup(entity) {
818
- var _this;
819
- _this = Component.call(this, entity) || this, /** @internal */ _this._indexInGroup = -1, /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._disorderedElements = new engine.DisorderedArray(), /** @internal */ _this._globalAlpha = 1, /** @internal */ _this._globalInteractive = true, _this._alpha = 1, _this._interactive = true, _this._ignoreParentGroup = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._groupListeningEntities = [], /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._isGroupDirty = false, /** @internal */ _this._groupDirtyFlags = 0;
820
- _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
821
- _this._groupListener = _this._groupListener.bind(_this);
822
- return _this;
823
- }
824
- var _proto = UIGroup.prototype;
825
- /**
826
- * @internal
827
- */ _proto._getGlobalAlpha = function _getGlobalAlpha() {
828
- if (this._isContainDirtyFlag(1)) {
829
- if (this._ignoreParentGroup) {
830
- this._globalAlpha = this._alpha;
831
- } else {
832
- var parentGroup = this._getGroup();
833
- this._globalAlpha = this._alpha * (parentGroup ? parentGroup._getGlobalAlpha() : 1);
834
- }
835
- this._setDirtyFlagFalse(1);
836
- }
837
- return this._globalAlpha;
838
- };
839
- /**
840
- * @internal
841
- */ _proto._getGlobalInteractive = function _getGlobalInteractive() {
842
- if (this._isContainDirtyFlag(2)) {
843
- if (this._ignoreParentGroup) {
844
- this._globalInteractive = this._interactive;
845
- } else {
846
- var parentGroup = this._getGroup();
847
- this._globalInteractive = this._interactive && (!parentGroup || parentGroup._getGlobalInteractive());
848
- }
849
- this._setDirtyFlagFalse(2);
850
- }
851
- return this._globalInteractive;
852
- };
853
- // @ts-ignore
854
- _proto._onEnableInScene = function _onEnableInScene() {
855
- Utils.setRootCanvasDirty(this);
856
- Utils.setGroupDirty(this);
857
- // @ts-ignore
858
- this.entity._dispatchModify(EntityUIModifyFlags.GroupEnableInScene);
859
- };
860
- // @ts-ignore
861
- _proto._onDisableInScene = function _onDisableInScene() {
862
- Utils.cleanRootCanvas(this);
863
- Utils.cleanGroup(this);
864
- var disorderedElements = this._disorderedElements;
865
- disorderedElements.forEach(function(element) {
866
- Utils.setGroupDirty(element);
867
- });
868
- disorderedElements.length = 0;
869
- disorderedElements.garbageCollection();
870
- this._isRootCanvasDirty = this._isGroupDirty = false;
871
- };
872
- /**
873
- * @internal
874
- */ _proto._getRootCanvas = function _getRootCanvas() {
875
- this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
876
- return this._rootCanvas;
877
- };
878
- /**
879
- * @internal
880
- */ _proto._getGroup = function _getGroup() {
881
- this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
882
- return this._group;
883
- };
884
- /**
885
- * @internal
886
- */ _proto._groupListener = function _groupListener(flag) {
887
- if (flag === engine.EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
888
- Utils.setGroupDirty(this);
889
- }
890
- };
891
- /**
892
- * @internal
893
- */ _proto._rootCanvasListener = function _rootCanvasListener(flag) {
894
- if (flag === engine.EntityModifyFlags.Parent || flag === EntityUIModifyFlags.CanvasEnableInScene) {
895
- Utils.setRootCanvasDirty(this);
896
- Utils.setGroupDirty(this);
897
- }
898
- };
899
- /**
900
- * @internal
901
- */ _proto._onGroupModify = function _onGroupModify(flags, isPass) {
902
- if (isPass === void 0) isPass = false;
903
- if (isPass && this._ignoreParentGroup) return;
904
- if (this._isContainDirtyFlags(flags)) return;
905
- this._setDirtyFlagTrue(flags);
906
- this._disorderedElements.forEach(function(element) {
907
- element._onGroupModify(flags, true);
908
- });
909
- };
910
- _proto._isContainDirtyFlags = function _isContainDirtyFlags(targetDirtyFlags) {
911
- return (this._groupDirtyFlags & targetDirtyFlags) === targetDirtyFlags;
912
- };
913
- _proto._isContainDirtyFlag = function _isContainDirtyFlag(type) {
914
- return (this._groupDirtyFlags & type) != 0;
915
- };
916
- _proto._setDirtyFlagTrue = function _setDirtyFlagTrue(type) {
917
- this._groupDirtyFlags |= type;
918
- };
919
- _proto._setDirtyFlagFalse = function _setDirtyFlagFalse(type) {
920
- this._groupDirtyFlags &= ~type;
921
- };
922
- _create_class(UIGroup, [
923
- {
924
- key: "ignoreParentGroup",
925
- get: /**
926
- * Whether to ignore the parent group.
927
- * @remarks If this parameter set to `true`,
928
- * all settings of the parent group will be ignored.
929
- */ function get() {
930
- return this._ignoreParentGroup;
931
- },
932
- set: function set(value) {
933
- if (this._ignoreParentGroup !== value) {
934
- this._ignoreParentGroup = value;
935
- this._onGroupModify(3);
936
- }
937
- }
938
- },
939
- {
940
- key: "interactive",
941
- get: /**
942
- * Whether the group is interactive.
943
- */ function get() {
944
- return this._interactive;
945
- },
946
- set: function set(value) {
947
- if (this._interactive !== value) {
948
- this._interactive = value;
949
- this._onGroupModify(2);
950
- }
951
- }
952
- },
953
- {
954
- key: "alpha",
955
- get: /**
956
- * The alpha value of the group.
957
- */ function get() {
958
- return this._alpha;
959
- },
960
- set: function set(value) {
961
- value = Math.max(0, Math.min(value, 1));
962
- if (this._alpha !== value) {
963
- this._alpha = value;
964
- this._onGroupModify(1);
965
- }
966
- }
967
- }
968
- ]);
969
- return UIGroup;
970
- }(engine.Component);
971
- __decorate([
972
- engine.ignoreClone
973
- ], UIGroup.prototype, "_indexInGroup", void 0);
974
- __decorate([
975
- engine.ignoreClone
976
- ], UIGroup.prototype, "_indexInRootCanvas", void 0);
977
- __decorate([
978
- engine.ignoreClone
979
- ], UIGroup.prototype, "_globalAlpha", void 0);
980
- __decorate([
981
- engine.ignoreClone
982
- ], UIGroup.prototype, "_globalInteractive", void 0);
983
- __decorate([
984
- engine.ignoreClone
985
- ], UIGroup.prototype, "_rootCanvasListeningEntities", void 0);
986
- __decorate([
987
- engine.ignoreClone
988
- ], UIGroup.prototype, "_groupListeningEntities", void 0);
989
- __decorate([
990
- engine.ignoreClone
991
- ], UIGroup.prototype, "_isRootCanvasDirty", void 0);
992
- __decorate([
993
- engine.ignoreClone
994
- ], UIGroup.prototype, "_isGroupDirty", void 0);
995
- __decorate([
996
- engine.ignoreClone
997
- ], UIGroup.prototype, "_groupDirtyFlags", void 0);
998
- __decorate([
999
- engine.ignoreClone
1000
- ], UIGroup.prototype, "_groupListener", null);
1001
- __decorate([
1002
- engine.ignoreClone
1003
- ], UIGroup.prototype, "_rootCanvasListener", null);
1004
- var GroupModifyFlags = /*#__PURE__*/ function(GroupModifyFlags) {
1005
- GroupModifyFlags[GroupModifyFlags["None"] = 0] = "None";
1006
- GroupModifyFlags[GroupModifyFlags["GlobalAlpha"] = 1] = "GlobalAlpha";
1007
- GroupModifyFlags[GroupModifyFlags["GlobalInteractive"] = 2] = "GlobalInteractive";
1008
- GroupModifyFlags[GroupModifyFlags["All"] = 3] = "All";
1009
- return GroupModifyFlags;
1010
- }({});
1011
-
1012
- exports.UIRenderer = /*#__PURE__*/ function(Renderer) {
1013
- _inherits(UIRenderer, Renderer);
1014
- function UIRenderer(entity) {
1015
- var _this;
1016
- _this = Renderer.call(this, entity) || this, /**
1017
- * Custom boundary for raycast detection.
1018
- * @remarks this is based on `this.entity.transform`.
1019
- */ _this.raycastPadding = new engine.Vector4(0, 0, 0, 0), /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._indexInGroup = -1, /** @internal */ _this._isGroupDirty = false, /** @internal */ _this._groupListeningEntities = [], /** @internal */ _this._rectMasks = [], /** @internal */ _this._rectMaskRect = new engine.Vector4(), /** @internal */ _this._rectMaskEnabled = false, /** @internal */ _this._rectMaskSoftness = new engine.Vector4(), /** @internal */ _this._rectMaskHardClip = false, _this._raycastEnabled = false, _this._color = new engine.Color(1, 1, 1, 1);
1020
- _this._dirtyUpdateFlag = engine.RendererUpdateFlags.WorldVolume | 2;
1021
- _this._onColorChanged = _this._onColorChanged.bind(_this);
1022
- //@ts-ignore
1023
- _this._color._onValueChanged = _this._onColorChanged;
1024
- _this._groupListener = _this._groupListener.bind(_this);
1025
- _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
1026
- _this.shaderData.setFloat(UIRenderer._rectClipEnabledProperty, 0);
1027
- _this.shaderData.setVector4(UIRenderer._rectClipSoftnessProperty, _this._rectMaskSoftness);
1028
- _this.shaderData.setFloat(UIRenderer._rectClipHardClipProperty, 0);
1029
- return _this;
1030
- }
1031
- var _proto = UIRenderer.prototype;
1032
- // @ts-ignore
1033
- _proto._canBatch = function _canBatch(preElement, curElement) {
1034
- return engine.VertexMergeBatcher.canBatchSprite(preElement, curElement);
1035
- };
1036
- // @ts-ignore
1037
- _proto._batch = function _batch(preElement, curElement) {
1038
- engine.VertexMergeBatcher.batch(preElement, curElement);
1039
- };
1040
- // @ts-ignore
1041
- _proto._updateTransformShaderData = function _updateTransformShaderData(context, onlyMVP) {
1042
- // @ts-ignore
1043
- this._updateWorldSpaceTransformShaderData(context, onlyMVP);
1044
- };
1045
- // @ts-ignore
1046
- _proto._prepareRender = function _prepareRender(context) {
1047
- // Update once per frame per renderer, not influenced by batched
1048
- if (this._renderFrameCount !== this.engine.time.frameCount) {
1049
- this._update(context);
1050
- }
1051
- this._updateRectMaskClipState();
1052
- this._render(context);
1053
- // union camera global macro and renderer macro.
1054
- engine.ShaderMacroCollection.unionCollection(context.camera._globalShaderMacro, // @ts-ignore
1055
- this.shaderData._macroCollection, //@ts-ignore
1056
- this._globalShaderMacro);
1057
- };
1058
- // @ts-ignore
1059
- _proto._onEnableInScene = function _onEnableInScene() {
1060
- // @ts-ignore
1061
- this._overrideUpdate && this.scene._componentsManager.addOnUpdateRenderers(this);
1062
- this.entity._updateUIHierarchyVersion(exports.UICanvas._hierarchyCounter);
1063
- Utils.setRootCanvasDirty(this);
1064
- Utils.setGroupDirty(this);
1065
- };
1066
- // @ts-ignore
1067
- _proto._onDisableInScene = function _onDisableInScene() {
1068
- // @ts-ignore
1069
- this._overrideUpdate && this.scene._componentsManager.removeOnUpdateRenderers(this);
1070
- this.entity._updateUIHierarchyVersion(exports.UICanvas._hierarchyCounter);
1071
- Utils.cleanRootCanvas(this);
1072
- Utils.cleanGroup(this);
1073
- };
1074
- /**
1075
- * @internal
1076
- */ _proto._getGlobalAlpha = function _getGlobalAlpha() {
1077
- var _this__getGroup;
1078
- var _this__getGroup__getGlobalAlpha;
1079
- return (_this__getGroup__getGlobalAlpha = (_this__getGroup = this._getGroup()) == null ? void 0 : _this__getGroup._getGlobalAlpha()) != null ? _this__getGroup__getGlobalAlpha : 1;
1080
- };
1081
- /**
1082
- * @internal
1083
- */ _proto._getRootCanvas = function _getRootCanvas() {
1084
- this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
1085
- return this._rootCanvas;
1086
- };
1087
- /**
1088
- * @internal
1089
- */ _proto._getGroup = function _getGroup() {
1090
- this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
1091
- return this._group;
1092
- };
1093
- /**
1094
- * @internal
1095
- */ _proto._groupListener = function _groupListener(flag) {
1096
- if (flag === engine.EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
1097
- Utils.setGroupDirty(this);
1098
- }
1099
- };
1100
- /**
1101
- * @internal
1102
- */ _proto._rootCanvasListener = function _rootCanvasListener(flag, entity) {
1103
- switch(flag){
1104
- case engine.EntityModifyFlags.Parent:
1105
- Utils.setRootCanvasDirty(this);
1106
- Utils.setGroupDirty(this);
1107
- case engine.EntityModifyFlags.Child:
1108
- entity._updateUIHierarchyVersion(exports.UICanvas._hierarchyCounter);
1109
- break;
1110
- }
1111
- };
1112
- /**
1113
- * @internal
1114
- */ _proto._onGroupModify = function _onGroupModify(flags) {
1115
- if (flags & GroupModifyFlags.GlobalAlpha) {
1116
- this._dirtyUpdateFlag |= 2;
1117
- }
1118
- };
1119
- _proto._onColorChanged = function _onColorChanged() {
1120
- this._dirtyUpdateFlag |= 2;
1121
- };
1122
- /**
1123
- * @internal
1124
- */ _proto._getChunkManager = function _getChunkManager() {
1125
- // @ts-ignore
1126
- return this.engine._batcherManager.primitiveChunkManagerUI;
1127
- };
1128
- /**
1129
- * @internal
1130
- */ _proto._setRectMasks = function _setRectMasks(rectMasks, count) {
1131
- var targetMasks = this._rectMasks;
1132
- targetMasks.length = count;
1133
- for(var i = 0; i < count; i++){
1134
- targetMasks[i] = rectMasks[i];
1135
- }
1136
- };
1137
- /**
1138
- * @internal
1139
- */ _proto._raycast = function _raycast(ray, out, distance) {
1140
- if (distance === void 0) distance = Number.MAX_SAFE_INTEGER;
1141
- var plane = UIRenderer._tempPlane;
1142
- var transform = this._transformEntity.transform;
1143
- var normal = plane.normal.copyFrom(transform.worldForward);
1144
- plane.distance = -engine.Vector3.dot(normal, transform.worldPosition);
1145
- var curDistance = ray.intersectPlane(plane);
1146
- if (curDistance >= 0 && curDistance < distance) {
1147
- var hitPointWorld = ray.getPoint(curDistance, UIRenderer._tempVec30);
1148
- var worldMatrixInv = UIRenderer._tempMat;
1149
- engine.Matrix.invert(transform.worldMatrix, worldMatrixInv);
1150
- var localPosition = UIRenderer._tempVec31;
1151
- engine.Vector3.transformCoordinate(hitPointWorld, worldMatrixInv, localPosition);
1152
- if (this._hitTest(localPosition) && this._isRaycastVisibleByRectMask(hitPointWorld) && this._isRaycastVisibleByMask(hitPointWorld)) {
1153
- out.component = this;
1154
- out.distance = curDistance;
1155
- out.entity = this.entity;
1156
- out.normal.copyFrom(normal);
1157
- out.point.copyFrom(hitPointWorld);
1158
- return true;
1159
- }
1160
- }
1161
- return false;
1162
- };
1163
- _proto._hitTest = function _hitTest(localPosition) {
1164
- var x = localPosition.x, y = localPosition.y;
1165
- var uiTransform = this._transformEntity.transform;
1166
- var _uiTransform_size = uiTransform.size, width = _uiTransform_size.x, height = _uiTransform_size.y;
1167
- var _uiTransform_pivot = uiTransform.pivot, pivotX = _uiTransform_pivot.x, pivotY = _uiTransform_pivot.y;
1168
- var _this_raycastPadding = this.raycastPadding, paddingLeft = _this_raycastPadding.x, paddingBottom = _this_raycastPadding.y, paddingRight = _this_raycastPadding.z, paddingTop = _this_raycastPadding.w;
1169
- return x >= -width * pivotX + paddingLeft && x <= width * (1 - pivotX) - paddingRight && y >= -height * pivotY + paddingTop && y <= height * (1 - pivotY) - paddingBottom;
1170
- };
1171
- _proto._isRaycastVisibleByMask = function _isRaycastVisibleByMask(hitPointWorld) {
1172
- var maskInteraction = this._maskInteraction;
1173
- if (maskInteraction === engine.SpriteMaskInteraction.None) {
1174
- return true;
1175
- }
1176
- // @ts-ignore
1177
- return this.scene._maskManager.isVisibleByMask(maskInteraction, this._maskLayer, hitPointWorld);
1178
- };
1179
- _proto._isRaycastVisibleByRectMask = function _isRaycastVisibleByRectMask(hitPointWorld) {
1180
- var rectMasks = this._rectMasks;
1181
- for(var i = 0, n = rectMasks.length; i < n; i++){
1182
- var rectMask = rectMasks[i];
1183
- if (!rectMask.enabled || !rectMask.entity.isActiveInHierarchy) {
1184
- continue;
1185
- }
1186
- if (!rectMask._containsWorldPoint(hitPointWorld)) {
1187
- return false;
1188
- }
1189
- }
1190
- return true;
1191
- };
1192
- _proto._updateRectMaskClipState = function _updateRectMaskClipState() {
1193
- var rectMasks = this._rectMasks;
1194
- var count = rectMasks.length;
1195
- if (count <= 0) {
1196
- this._resetRectMaskClipState();
1197
- return;
1198
- }
1199
- var minX = Number.NEGATIVE_INFINITY;
1200
- var minY = Number.NEGATIVE_INFINITY;
1201
- var maxX = Number.POSITIVE_INFINITY;
1202
- var maxY = Number.POSITIVE_INFINITY;
1203
- var clipSoftnessLeft = 0;
1204
- var clipSoftnessBottom = 0;
1205
- var clipSoftnessRight = 0;
1206
- var clipSoftnessTop = 0;
1207
- var clipHardClip = false;
1208
- var hasActiveMask = false;
1209
- var tempRect = UIRenderer._tempRect;
1210
- for(var i = 0; i < count; i++){
1211
- var rectMask = rectMasks[i];
1212
- if (!rectMask.enabled || !rectMask.entity.isActiveInHierarchy) {
1213
- continue;
1214
- }
1215
- hasActiveMask = true;
1216
- var softness = rectMask.softness;
1217
- if (!clipHardClip && rectMask.alphaClip) {
1218
- clipHardClip = true;
1219
- }
1220
- if (!rectMask._getWorldRect(tempRect)) {
1221
- minX = 1;
1222
- minY = 1;
1223
- maxX = 0;
1224
- maxY = 0;
1225
- break;
1226
- }
1227
- if (tempRect.x > minX) {
1228
- minX = tempRect.x;
1229
- clipSoftnessLeft = softness.x;
1230
- }
1231
- if (tempRect.y > minY) {
1232
- minY = tempRect.y;
1233
- clipSoftnessBottom = softness.y;
1234
- }
1235
- if (tempRect.z < maxX) {
1236
- maxX = tempRect.z;
1237
- clipSoftnessRight = softness.x;
1238
- }
1239
- if (tempRect.w < maxY) {
1240
- maxY = tempRect.w;
1241
- clipSoftnessTop = softness.y;
1242
- }
1243
- }
1244
- if (!hasActiveMask) {
1245
- this._resetRectMaskClipState();
1246
- return;
1247
- }
1248
- if (minX >= maxX || minY >= maxY) {
1249
- minX = 1;
1250
- minY = 1;
1251
- maxX = 0;
1252
- maxY = 0;
1253
- clipSoftnessLeft = 0;
1254
- clipSoftnessBottom = 0;
1255
- clipSoftnessRight = 0;
1256
- clipSoftnessTop = 0;
1257
- }
1258
- var rectMaskRect = this._rectMaskRect;
1259
- if (rectMaskRect.x !== minX || rectMaskRect.y !== minY || rectMaskRect.z !== maxX || rectMaskRect.w !== maxY) {
1260
- rectMaskRect.set(minX, minY, maxX, maxY);
1261
- this.shaderData.setVector4(UIRenderer._rectClipRectProperty, rectMaskRect);
1262
- }
1263
- var rectMaskSoftness = this._rectMaskSoftness;
1264
- if (rectMaskSoftness.x !== clipSoftnessLeft || rectMaskSoftness.y !== clipSoftnessBottom || rectMaskSoftness.z !== clipSoftnessRight || rectMaskSoftness.w !== clipSoftnessTop) {
1265
- rectMaskSoftness.set(clipSoftnessLeft, clipSoftnessBottom, clipSoftnessRight, clipSoftnessTop);
1266
- this.shaderData.setVector4(UIRenderer._rectClipSoftnessProperty, rectMaskSoftness);
1267
- }
1268
- if (this._rectMaskHardClip !== clipHardClip) {
1269
- this._rectMaskHardClip = clipHardClip;
1270
- this.shaderData.setFloat(UIRenderer._rectClipHardClipProperty, clipHardClip ? 1 : 0);
1271
- }
1272
- if (!this._rectMaskEnabled) {
1273
- this._rectMaskEnabled = true;
1274
- this.shaderData.setFloat(UIRenderer._rectClipEnabledProperty, 1);
1275
- }
1276
- };
1277
- _proto._resetRectMaskClipState = function _resetRectMaskClipState() {
1278
- if (this._rectMaskEnabled) {
1279
- this._rectMaskEnabled = false;
1280
- this.shaderData.setFloat(UIRenderer._rectClipEnabledProperty, 0);
1281
- }
1282
- var rectMaskSoftness = this._rectMaskSoftness;
1283
- if (rectMaskSoftness.x !== 0 || rectMaskSoftness.y !== 0 || rectMaskSoftness.z !== 0 || rectMaskSoftness.w !== 0) {
1284
- rectMaskSoftness.set(0, 0, 0, 0);
1285
- this.shaderData.setVector4(UIRenderer._rectClipSoftnessProperty, rectMaskSoftness);
1286
- }
1287
- if (this._rectMaskHardClip) {
1288
- this._rectMaskHardClip = false;
1289
- this.shaderData.setFloat(UIRenderer._rectClipHardClipProperty, 0);
1290
- }
1291
- };
1292
- _proto._onDestroy = function _onDestroy() {
1293
- if (this._subChunk) {
1294
- this._getChunkManager().freeSubChunk(this._subChunk);
1295
- this._subChunk = null;
1296
- }
1297
- Renderer.prototype._onDestroy.call(this);
1298
- //@ts-ignore
1299
- this._color._onValueChanged = null;
1300
- this._color = null;
1301
- this._rectMasks = null;
1302
- this._rectMaskSoftness = null;
1303
- };
1304
- _create_class(UIRenderer, [
1305
- {
1306
- key: "color",
1307
- get: /**
1308
- * Rendering color for the ui renderer.
1309
- */ function get() {
1310
- return this._color;
1311
- },
1312
- set: function set(value) {
1313
- if (this._color !== value) {
1314
- this._color.copyFrom(value);
1315
- }
1316
- }
1317
- },
1318
- {
1319
- key: "maskLayer",
1320
- get: /**
1321
- * The mask layer the ui renderer belongs to.
1322
- */ function get() {
1323
- return this._maskLayer;
1324
- },
1325
- set: function set(value) {
1326
- this._maskLayer = value;
1327
- }
1328
- },
1329
- {
1330
- key: "maskInteraction",
1331
- get: /**
1332
- * Interacts with the masks.
1333
- */ function get() {
1334
- return this._maskInteraction;
1335
- },
1336
- set: function set(value) {
1337
- if (this._maskInteraction !== value) {
1338
- this._maskInteraction = value;
1339
- }
1340
- }
1341
- },
1342
- {
1343
- key: "raycastEnabled",
1344
- get: /**
1345
- * Whether this renderer be picked up by raycast.
1346
- */ function get() {
1347
- return this._raycastEnabled;
1348
- },
1349
- set: function set(value) {
1350
- this._raycastEnabled = value;
1351
- }
1352
- }
1353
- ]);
1354
- return UIRenderer;
1355
- }(engine.Renderer);
1356
- /** @internal */ exports.UIRenderer._tempVec20 = new engine.Vector2();
1357
- /** @internal */ exports.UIRenderer._tempVec30 = new engine.Vector3();
1358
- /** @internal */ exports.UIRenderer._tempVec31 = new engine.Vector3();
1359
- /** @internal */ exports.UIRenderer._tempMat = new engine.Matrix();
1360
- /** @internal */ exports.UIRenderer._tempPlane = new engine.Plane();
1361
- /** @internal */ exports.UIRenderer._textureProperty = engine.ShaderProperty.getByName("renderer_UITexture");
1362
- /** @internal */ exports.UIRenderer._rectClipRectProperty = engine.ShaderProperty.getByName("renderer_UIRectClipRect");
1363
- /** @internal */ exports.UIRenderer._rectClipEnabledProperty = engine.ShaderProperty.getByName("renderer_UIRectClipEnabled");
1364
- /** @internal */ exports.UIRenderer._rectClipSoftnessProperty = engine.ShaderProperty.getByName("renderer_UIRectClipSoftness");
1365
- /** @internal */ exports.UIRenderer._rectClipHardClipProperty = engine.ShaderProperty.getByName("renderer_UIRectClipHardClip");
1366
- /** @internal */ exports.UIRenderer._tempRect = new engine.Vector4();
1367
- __decorate([
1368
- engine.ignoreClone
1369
- ], exports.UIRenderer.prototype, "_indexInRootCanvas", void 0);
1370
- __decorate([
1371
- engine.ignoreClone
1372
- ], exports.UIRenderer.prototype, "_isRootCanvasDirty", void 0);
1373
- __decorate([
1374
- engine.ignoreClone
1375
- ], exports.UIRenderer.prototype, "_rootCanvasListeningEntities", void 0);
1376
- __decorate([
1377
- engine.ignoreClone
1378
- ], exports.UIRenderer.prototype, "_indexInGroup", void 0);
1379
- __decorate([
1380
- engine.ignoreClone
1381
- ], exports.UIRenderer.prototype, "_isGroupDirty", void 0);
1382
- __decorate([
1383
- engine.ignoreClone
1384
- ], exports.UIRenderer.prototype, "_groupListeningEntities", void 0);
1385
- __decorate([
1386
- engine.ignoreClone
1387
- ], exports.UIRenderer.prototype, "_subChunk", void 0);
1388
- __decorate([
1389
- engine.ignoreClone
1390
- ], exports.UIRenderer.prototype, "_rectMasks", void 0);
1391
- __decorate([
1392
- engine.ignoreClone
1393
- ], exports.UIRenderer.prototype, "_rectMaskRect", void 0);
1394
- __decorate([
1395
- engine.ignoreClone
1396
- ], exports.UIRenderer.prototype, "_rectMaskEnabled", void 0);
1397
- __decorate([
1398
- engine.ignoreClone
1399
- ], exports.UIRenderer.prototype, "_rectMaskSoftness", void 0);
1400
- __decorate([
1401
- engine.ignoreClone
1402
- ], exports.UIRenderer.prototype, "_rectMaskHardClip", void 0);
1403
- __decorate([
1404
- engine.ignoreClone
1405
- ], exports.UIRenderer.prototype, "_groupListener", null);
1406
- __decorate([
1407
- engine.ignoreClone
1408
- ], exports.UIRenderer.prototype, "_rootCanvasListener", null);
1409
- __decorate([
1410
- engine.ignoreClone
1411
- ], exports.UIRenderer.prototype, "_onColorChanged", null);
1412
- exports.UIRenderer = __decorate([
1413
- engine.dependentComponents(UITransform, engine.DependentMode.AutoAdd)
1414
- ], exports.UIRenderer);
1415
- /**
1416
- * @remarks Extends `RendererUpdateFlags`.
1417
- */ var UIRendererUpdateFlags = /*#__PURE__*/ function(UIRendererUpdateFlags) {
1418
- UIRendererUpdateFlags[UIRendererUpdateFlags["Color"] = 2] = "Color";
1419
- return UIRendererUpdateFlags;
1420
- }({});
1421
-
1422
- exports.UICanvas = /*#__PURE__*/ function(Component) {
1423
- _inherits(UICanvas, Component);
1424
- function UICanvas(entity) {
1425
- var _this;
1426
- _this = Component.call(this, entity) || this, /** @internal */ _this._canvasIndex = -1, /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._isRootCanvas = false, /** @internal */ _this._renderElements = [], /** @internal */ _this._batchedRenderElements = [], /** @internal */ _this._sortDistance = 0, /** @internal */ _this._orderedRenderers = [], /** @internal */ _this._realRenderMode = 4, /** @internal */ _this._disorderedElements = new engine.DisorderedArray(), _this._renderMode = CanvasRenderMode.WorldSpace, _this._resolutionAdaptationMode = ResolutionAdaptationMode.HeightAdaptation, _this._sortOrder = 0, _this._distance = 10, _this._referenceResolution = new engine.Vector2(800, 600), _this._referenceResolutionPerUnit = 100, _this._hierarchyVersion = -1, _this._center = new engine.Vector3();
1427
- _this._onCanvasSizeListener = _this._onCanvasSizeListener.bind(_this);
1428
- _this._onCameraModifyListener = _this._onCameraModifyListener.bind(_this);
1429
- _this._onCameraTransformListener = _this._onCameraTransformListener.bind(_this);
1430
- _this._onReferenceResolutionChanged = _this._onReferenceResolutionChanged.bind(_this);
1431
- // @ts-ignore
1432
- _this._referenceResolution._onValueChanged = _this._onReferenceResolutionChanged;
1433
- _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
1434
- _this._centerDirtyFlag = entity.registerWorldChangeFlag();
1435
- return _this;
1436
- }
1437
- var _proto = UICanvas.prototype;
1438
- /**
1439
- * @internal
1440
- */ _proto._raycast = function _raycast(ray, out, distance) {
1441
- if (distance === void 0) distance = Number.MAX_SAFE_INTEGER;
1442
- var renderers = this._getRenderers();
1443
- for(var i = renderers.length - 1; i >= 0; i--){
1444
- var element = renderers[i];
1445
- if (element.raycastEnabled && element._raycast(ray, out, distance)) {
1446
- return true;
1447
- }
1448
- }
1449
- out.component = null;
1450
- out.entity = null;
1451
- out.distance = 0;
1452
- out.point.set(0, 0, 0);
1453
- out.normal.set(0, 0, 0);
1454
- return false;
1455
- };
1456
- /**
1457
- * @internal
1458
- */ _proto._getRootCanvas = function _getRootCanvas() {
1459
- return this._rootCanvas;
1460
- };
1461
- /**
1462
- * @internal
1463
- */ _proto._canRender = function _canRender(camera) {
1464
- return this._realRenderMode !== CanvasRenderMode.ScreenSpaceCamera || this._camera === camera;
1465
- };
1466
- /**
1467
- * @internal
1468
- */ _proto._canDispatchEvent = function _canDispatchEvent(camera) {
1469
- var realMode = this._realRenderMode;
1470
- if (realMode === CanvasRenderMode.ScreenSpaceOverlay) {
1471
- return true;
1472
- }
1473
- var assignedCamera = this._camera;
1474
- // @ts-ignore
1475
- return !assignedCamera || !assignedCamera._phasedActiveInScene || assignedCamera === camera;
1476
- };
1477
- /**
1478
- * @internal
1479
- */ _proto._prepareRender = function _prepareRender(context) {
1480
- var _this = this, engine = _this.engine, mode = _this._realRenderMode;
1481
- var _context_camera = context.camera, enableFrustumCulling = _context_camera.enableFrustumCulling, cullingMask = _context_camera.cullingMask, frustum = _context_camera._frustum;
1482
- var frameCount = engine.time.frameCount;
1483
- var renderElements = this._renderElements;
1484
- renderElements.length = 0;
1485
- var virtualCamera = context.virtualCamera;
1486
- this._updateSortDistance(virtualCamera.isOrthographic, virtualCamera.position, virtualCamera.forward);
1487
- var _engine_canvas = engine.canvas, width = _engine_canvas.width, height = _engine_canvas.height;
1488
- var renderers = this._getRenderers();
1489
- for(var i = 0, n = renderers.length; i < n; i++){
1490
- var renderer = renderers[i];
1491
- // Filter by camera culling mask
1492
- if (!(cullingMask & renderer.entity.layer)) {
1493
- continue;
1494
- }
1495
- // Filter by camera frustum
1496
- if (enableFrustumCulling) {
1497
- switch(mode){
1498
- case CanvasRenderMode.ScreenSpaceOverlay:
1499
- var _renderer_bounds = renderer.bounds, min = _renderer_bounds.min, max = _renderer_bounds.max;
1500
- if (min.x > width || max.x < 0 || min.y > height || max.y < 0) {
1501
- continue;
1502
- }
1503
- break;
1504
- case CanvasRenderMode.ScreenSpaceCamera:
1505
- case CanvasRenderMode.WorldSpace:
1506
- if (!frustum.intersectsBox(renderer.bounds)) {
1507
- continue;
1508
- }
1509
- break;
1510
- }
1511
- }
1512
- renderer._prepareRender(context);
1513
- renderer._renderFrameCount = frameCount;
1514
- }
1515
- var batchedRenderElements = this._batchedRenderElements;
1516
- batchedRenderElements.length = 0;
1517
- UIBatchSorter.sort(renderElements, this.entity.transform.worldMatrix);
1518
- engine._batcherManager.batch(renderElements, batchedRenderElements);
1519
- for(var i1 = 0, n1 = batchedRenderElements.length; i1 < n1; i1++){
1520
- batchedRenderElements[i1].subDistancePriority = i1;
1521
- }
1522
- };
1523
- /**
1524
- * @internal
1525
- */ _proto._updateSortDistance = function _updateSortDistance(isOrthographic, cameraPosition, cameraForward) {
1526
- switch(this._realRenderMode){
1527
- case CanvasRenderMode.ScreenSpaceOverlay:
1528
- this._sortDistance = 0;
1529
- break;
1530
- case CanvasRenderMode.ScreenSpaceCamera:
1531
- this._sortDistance = this._distance;
1532
- break;
1533
- case CanvasRenderMode.WorldSpace:
1534
- var boundsCenter = this._getCenter();
1535
- if (isOrthographic) {
1536
- var distance = UICanvas._tempVec3;
1537
- engine.Vector3.subtract(boundsCenter, cameraPosition, distance);
1538
- this._sortDistance = engine.Vector3.dot(distance, cameraForward);
1539
- } else {
1540
- this._sortDistance = engine.Vector3.distanceSquared(boundsCenter, cameraPosition);
1541
- }
1542
- break;
1543
- }
1544
- };
1545
- // @ts-ignore
1546
- _proto._onEnableInScene = function _onEnableInScene() {
1547
- var entity = this.entity;
1548
- // @ts-ignore
1549
- entity._dispatchModify(4, this);
1550
- var rootCanvas = Utils.searchRootCanvasInParents(this);
1551
- this._setIsRootCanvas(!rootCanvas);
1552
- Utils.setRootCanvas(this, rootCanvas);
1553
- };
1554
- // @ts-ignore
1555
- _proto._onDisableInScene = function _onDisableInScene() {
1556
- this._setIsRootCanvas(false);
1557
- Utils.cleanRootCanvas(this);
1558
- };
1559
- // @ts-ignore
1560
- _proto._onDisable = function _onDisable() {
1561
- this._renderElements.length = 0;
1562
- this._batchedRenderElements.length = 0;
1563
- };
1564
- /**
1565
- * @internal
1566
- */ _proto._rootCanvasListener = function _rootCanvasListener(flag, param) {
1567
- if (this._isRootCanvas) {
1568
- if (flag === engine.EntityModifyFlags.Parent) {
1569
- var rootCanvas = Utils.searchRootCanvasInParents(this);
1570
- this._setIsRootCanvas(!rootCanvas);
1571
- Utils.setRootCanvas(this, rootCanvas);
1572
- } else if (flag === 4) {
1573
- this._setIsRootCanvas(false);
1574
- Utils.setRootCanvas(this, param);
1575
- }
1576
- } else {
1577
- if (flag === engine.EntityModifyFlags.Parent) {
1578
- var rootCanvas1 = Utils.searchRootCanvasInParents(this);
1579
- this._setIsRootCanvas(!rootCanvas1);
1580
- Utils.setRootCanvas(this, rootCanvas1);
1581
- }
1582
- }
1583
- };
1584
- /**
1585
- * @internal
1586
- */ _proto._cloneTo = function _cloneTo(target) {
1587
- target.renderMode = this._renderMode;
1588
- };
1589
- _proto._getRenderers = function _getRenderers() {
1590
- var _this = this, renderers = _this._orderedRenderers, entity = _this.entity;
1591
- var uiHierarchyVersion = entity._uiHierarchyVersion;
1592
- if (this._hierarchyVersion !== uiHierarchyVersion) {
1593
- UICanvas._tempRectMaskList.length = 0;
1594
- renderers.length = this._walk(this.entity, renderers, 0, null, 0);
1595
- UICanvas._tempGroupAbleList.length = 0;
1596
- this._hierarchyVersion = uiHierarchyVersion;
1597
- ++UICanvas._hierarchyCounter;
1598
- }
1599
- return renderers;
1600
- };
1601
- _proto._adapterPoseInScreenSpace = function _adapterPoseInScreenSpace() {
1602
- var transform = this.entity.transform;
1603
- var realRenderMode = this._realRenderMode;
1604
- if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1605
- var cameraEntity = this._camera.entity;
1606
- if (!this._isSameOrChildEntity(cameraEntity)) {
1607
- var cameraTransform = cameraEntity.transform;
1608
- var cameraWorldPosition = cameraTransform.worldPosition, cameraWorldForward = cameraTransform.worldForward;
1609
- var distance = this._distance;
1610
- transform.setWorldPosition(cameraWorldPosition.x + cameraWorldForward.x * distance, cameraWorldPosition.y + cameraWorldForward.y * distance, cameraWorldPosition.z + cameraWorldForward.z * distance);
1611
- transform.worldRotationQuaternion.copyFrom(cameraTransform.worldRotationQuaternion);
1612
- }
1613
- } else {
1614
- var canvas = this.engine.canvas;
1615
- transform.setWorldPosition(canvas.width * 0.5, canvas.height * 0.5, 0);
1616
- transform.worldRotationQuaternion.set(0, 0, 0, 1);
1617
- }
1618
- };
1619
- _proto._adapterSizeInScreenSpace = function _adapterSizeInScreenSpace() {
1620
- var transform = this.entity.transform;
1621
- var realRenderMode = this._realRenderMode;
1622
- var _this__referenceResolution = this._referenceResolution, width = _this__referenceResolution.x, height = _this__referenceResolution.y;
1623
- var curWidth;
1624
- var curHeight;
1625
- if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1626
- var camera = this._camera;
1627
- curHeight = camera.isOrthographic ? camera.orthographicSize * 2 : 2 * (Math.tan(engine.MathUtil.degreeToRadian(camera.fieldOfView * 0.5)) * this._distance);
1628
- curWidth = camera.aspectRatio * curHeight;
1629
- } else {
1630
- var canvas = this.engine.canvas;
1631
- curHeight = canvas.height;
1632
- curWidth = canvas.width;
1633
- }
1634
- var expectX, expectY, expectZ;
1635
- switch(this._resolutionAdaptationMode){
1636
- case ResolutionAdaptationMode.WidthAdaptation:
1637
- expectX = expectY = expectZ = curWidth / width;
1638
- break;
1639
- case ResolutionAdaptationMode.HeightAdaptation:
1640
- expectX = expectY = expectZ = curHeight / height;
1641
- break;
1642
- case ResolutionAdaptationMode.BothAdaptation:
1643
- expectX = curWidth / width;
1644
- expectY = curHeight / height;
1645
- expectZ = (expectX + expectY) * 0.5;
1646
- break;
1647
- case ResolutionAdaptationMode.ExpandAdaptation:
1648
- expectX = expectY = expectZ = Math.min(curWidth / width, curHeight / height);
1649
- break;
1650
- case ResolutionAdaptationMode.ShrinkAdaptation:
1651
- expectX = expectY = expectZ = Math.max(curWidth / width, curHeight / height);
1652
- break;
1653
- }
1654
- var worldMatrix = UICanvas._tempMat;
1655
- engine.Matrix.affineTransformation(UICanvas._tempVec3.set(expectX, expectY, expectZ), transform.worldRotationQuaternion, transform.worldPosition, worldMatrix);
1656
- transform.worldMatrix = worldMatrix;
1657
- transform.size.set(curWidth / expectX, curHeight / expectY);
1658
- };
1659
- _proto._walk = function _walk(entity, renderers, depth, group, rectMaskCount) {
1660
- if (depth === void 0) depth = 0;
1661
- if (group === void 0) group = null;
1662
- if (rectMaskCount === void 0) rectMaskCount = 0;
1663
- // @ts-ignore
1664
- var components = entity._components;
1665
- var tempGroupAbleList = UICanvas._tempGroupAbleList;
1666
- var tempRectMaskList = UICanvas._tempRectMaskList;
1667
- var rectMask = null;
1668
- var groupAbleCount = 0;
1669
- for(var i = 0, n = components.length; i < n; i++){
1670
- var component = components[i];
1671
- if (!component.enabled) continue;
1672
- if (_instanceof(component, exports.UIRenderer)) {
1673
- renderers[depth] = component;
1674
- ++depth;
1675
- component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1676
- if (component._isGroupDirty) {
1677
- tempGroupAbleList[groupAbleCount++] = component;
1678
- }
1679
- component._setRectMasks(tempRectMaskList, rectMaskCount);
1680
- } else if (_instanceof(component, UIInteractive)) {
1681
- component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1682
- if (component._isGroupDirty) {
1683
- tempGroupAbleList[groupAbleCount++] = component;
1684
- }
1685
- } else if (_instanceof(component, exports.RectMask2D)) {
1686
- rectMask = component;
1687
- } else if (_instanceof(component, UIGroup)) {
1688
- component._isRootCanvasDirty && Utils.setRootCanvas(component, this);
1689
- component._isGroupDirty && Utils.setGroup(component, group);
1690
- group = component;
1691
- }
1692
- }
1693
- for(var i1 = 0; i1 < groupAbleCount; i1++){
1694
- Utils.setGroup(tempGroupAbleList[i1], group);
1695
- }
1696
- if (rectMask) {
1697
- tempRectMaskList[rectMaskCount++] = rectMask;
1698
- }
1699
- var children = entity.children;
1700
- for(var i2 = 0, n1 = children.length; i2 < n1; i2++){
1701
- var child = children[i2];
1702
- child.isActive && (depth = this._walk(child, renderers, depth, group, rectMaskCount));
1703
- }
1704
- return depth;
1705
- };
1706
- _proto._updateCameraObserver = function _updateCameraObserver() {
1707
- var camera = this._isRootCanvas && this._renderMode === CanvasRenderMode.ScreenSpaceCamera ? this._camera : null;
1708
- var preCamera = this._cameraObserver;
1709
- if (preCamera !== camera) {
1710
- this._cameraObserver = camera;
1711
- if (preCamera) {
1712
- // @ts-ignore
1713
- preCamera.entity._updateFlagManager.removeListener(this._onCameraTransformListener);
1714
- // @ts-ignore
1715
- preCamera._unRegisterModifyListener(this._onCameraModifyListener);
1716
- }
1717
- if (camera) {
1718
- // @ts-ignore
1719
- camera.entity._updateFlagManager.addListener(this._onCameraTransformListener);
1720
- // @ts-ignore
1721
- camera._registerModifyListener(this._onCameraModifyListener);
1722
- }
1723
- }
1724
- };
1725
- _proto._onCameraModifyListener = function _onCameraModifyListener(flag) {
1726
- if (this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1727
- switch(flag){
1728
- case engine.CameraModifyFlags.ProjectionType:
1729
- case engine.CameraModifyFlags.AspectRatio:
1730
- this._adapterSizeInScreenSpace();
1731
- break;
1732
- case engine.CameraModifyFlags.FieldOfView:
1733
- !this._camera.isOrthographic && this._adapterSizeInScreenSpace();
1734
- break;
1735
- case engine.CameraModifyFlags.OrthographicSize:
1736
- this._camera.isOrthographic && this._adapterSizeInScreenSpace();
1737
- break;
1738
- case engine.CameraModifyFlags.DisableInScene:
1739
- this._setRealRenderMode(CanvasRenderMode.ScreenSpaceOverlay);
1740
- break;
1741
- }
1742
- } else {
1743
- flag === engine.CameraModifyFlags.EnableInScene && this._setRealRenderMode(CanvasRenderMode.ScreenSpaceCamera);
1744
- }
1745
- };
1746
- _proto._onCameraTransformListener = function _onCameraTransformListener() {
1747
- this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera && this._adapterPoseInScreenSpace();
1748
- };
1749
- _proto._addCanvasListener = function _addCanvasListener() {
1750
- // @ts-ignore
1751
- this.engine.canvas._sizeUpdateFlagManager.addListener(this._onCanvasSizeListener);
1752
- };
1753
- _proto._removeCanvasListener = function _removeCanvasListener() {
1754
- // @ts-ignore
1755
- this.engine.canvas._sizeUpdateFlagManager.removeListener(this._onCanvasSizeListener);
1756
- };
1757
- _proto._onCanvasSizeListener = function _onCanvasSizeListener() {
1758
- var canvas = this.engine.canvas;
1759
- this.entity.transform.setWorldPosition(canvas.width * 0.5, canvas.height * 0.5, 0);
1760
- this._adapterSizeInScreenSpace();
1761
- };
1762
- _proto._onReferenceResolutionChanged = function _onReferenceResolutionChanged() {
1763
- var realRenderMode = this._realRenderMode;
1764
- if (realRenderMode === CanvasRenderMode.ScreenSpaceOverlay || realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1765
- this._adapterSizeInScreenSpace();
1766
- }
1767
- };
1768
- _proto._setIsRootCanvas = function _setIsRootCanvas(isRootCanvas) {
1769
- var _this = this;
1770
- if (this._isRootCanvas !== isRootCanvas) {
1771
- this._isRootCanvas = isRootCanvas;
1772
- this._updateCameraObserver();
1773
- this._setRealRenderMode(this._getRealRenderMode());
1774
- if (isRootCanvas) {
1775
- this.entity._updateUIHierarchyVersion(UICanvas._hierarchyCounter);
1776
- } else {
1777
- var _this1 = this, disorderedElements = _this1._disorderedElements;
1778
- disorderedElements.forEach(function(element) {
1779
- if (_instanceof(element, UICanvas)) {
1780
- var rootCanvas = Utils.searchRootCanvasInParents(element);
1781
- element._setIsRootCanvas(!rootCanvas);
1782
- Utils.setRootCanvas(element, rootCanvas);
1783
- } else {
1784
- Utils.setRootCanvasDirty(_this);
1785
- Utils.setGroupDirty(element);
1786
- }
1787
- });
1788
- disorderedElements.length = 0;
1789
- disorderedElements.garbageCollection();
1790
- this._orderedRenderers.length = 0;
1791
- }
1792
- }
1793
- };
1794
- _proto._getCenter = function _getCenter() {
1795
- if (this._centerDirtyFlag.flag) {
1796
- var center = this._center;
1797
- var uiTransform = this.entity.transform;
1798
- var pivot = uiTransform.pivot, size = uiTransform.size;
1799
- center.set((0.5 - pivot.x) * size.x, (0.5 - pivot.y) * size.y, 0);
1800
- engine.Vector3.transformCoordinate(center, uiTransform.worldMatrix, center);
1801
- this._centerDirtyFlag.flag = false;
1802
- }
1803
- return this._center;
1804
- };
1805
- _proto._getRealRenderMode = function _getRealRenderMode() {
1806
- if (this._isRootCanvas) {
1807
- var _this__camera;
1808
- var mode = this._renderMode;
1809
- // @ts-ignore
1810
- if (mode === CanvasRenderMode.ScreenSpaceCamera && !((_this__camera = this._camera) == null ? void 0 : _this__camera._phasedActiveInScene)) {
1811
- return CanvasRenderMode.ScreenSpaceOverlay;
1812
- } else {
1813
- return mode;
1814
- }
1815
- } else {
1816
- return 4;
1817
- }
1818
- };
1819
- _proto._setRealRenderMode = function _setRealRenderMode(curRealMode) {
1820
- var preRealMode = this._realRenderMode;
1821
- if (preRealMode !== curRealMode) {
1822
- this._realRenderMode = curRealMode;
1823
- // @ts-ignore
1824
- var componentsManager = this.scene._componentsManager;
1825
- switch(preRealMode){
1826
- case CanvasRenderMode.ScreenSpaceOverlay:
1827
- this._removeCanvasListener();
1828
- case CanvasRenderMode.ScreenSpaceCamera:
1829
- case CanvasRenderMode.WorldSpace:
1830
- componentsManager.removeUICanvas(this, preRealMode === CanvasRenderMode.ScreenSpaceOverlay);
1831
- break;
1832
- }
1833
- switch(curRealMode){
1834
- case CanvasRenderMode.ScreenSpaceOverlay:
1835
- this._addCanvasListener();
1836
- case CanvasRenderMode.ScreenSpaceCamera:
1837
- this._adapterPoseInScreenSpace();
1838
- this._adapterSizeInScreenSpace();
1839
- case CanvasRenderMode.WorldSpace:
1840
- componentsManager.addUICanvas(this, curRealMode === CanvasRenderMode.ScreenSpaceOverlay);
1841
- break;
1842
- }
1843
- }
1844
- };
1845
- _proto._isSameOrChildEntity = function _isSameOrChildEntity(cameraEntity) {
1846
- var canvasEntity = this.entity;
1847
- while(cameraEntity){
1848
- if (cameraEntity === canvasEntity) return true;
1849
- cameraEntity = cameraEntity.parent;
1850
- }
1851
- return false;
1852
- };
1853
- _create_class(UICanvas, [
1854
- {
1855
- key: "referenceResolutionPerUnit",
1856
- get: /**
1857
- * The conversion ratio between reference resolution and unit for UI elements in this canvas.
1858
- */ function get() {
1859
- return this._referenceResolutionPerUnit;
1860
- },
1861
- set: function set(value) {
1862
- if (this._referenceResolutionPerUnit !== value) {
1863
- this._referenceResolutionPerUnit = value;
1864
- this._disorderedElements.forEach(function(element) {
1865
- element._onRootCanvasModify == null ? void 0 : element._onRootCanvasModify.call(element, 1);
1866
- });
1867
- }
1868
- }
1869
- },
1870
- {
1871
- key: "referenceResolution",
1872
- get: /**
1873
- * The reference resolution of the UI canvas in `ScreenSpaceCamera` and `ScreenSpaceOverlay` mode.
1874
- */ function get() {
1875
- return this._referenceResolution;
1876
- },
1877
- set: function set(value) {
1878
- var referenceResolution = this._referenceResolution;
1879
- if (referenceResolution === value) return;
1880
- (referenceResolution.x !== value.x || referenceResolution.y !== value.y) && referenceResolution.copyFrom(value);
1881
- }
1882
- },
1883
- {
1884
- key: "renderMode",
1885
- get: /**
1886
- * The rendering mode of the UI canvas.
1887
- */ function get() {
1888
- return this._renderMode;
1889
- },
1890
- set: function set(mode) {
1891
- var preMode = this._renderMode;
1892
- if (preMode !== mode) {
1893
- this._renderMode = mode;
1894
- this._updateCameraObserver();
1895
- this._setRealRenderMode(this._getRealRenderMode());
1896
- }
1897
- }
1898
- },
1899
- {
1900
- key: "camera",
1901
- get: /**
1902
- * The camera associated with this canvas.
1903
- * @remarks
1904
- * - `ScreenSpaceCamera` mode: Used for rendering adaptation. Defaults to `ScreenSpaceOverlay` if not assigned.
1905
- * - `WorldSpace` mode: Used for event detection. If not assigned, events are handled by the highest-priority camera.
1906
- */ function get() {
1907
- return this._camera;
1908
- },
1909
- set: function set(value) {
1910
- var preCamera = this._camera;
1911
- if (preCamera !== value) {
1912
- if (value && this._isSameOrChildEntity(value.entity)) {
1913
- engine.Logger.warn("Camera entity matching or nested within the canvas entity disables canvas auto-adaptation in ScreenSpaceCamera mode.");
1914
- }
1915
- this._camera = value;
1916
- this._updateCameraObserver();
1917
- var preRenderMode = this._realRenderMode;
1918
- var curRenderMode = this._getRealRenderMode();
1919
- if (preRenderMode === curRenderMode) {
1920
- if (curRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1921
- this._adapterPoseInScreenSpace();
1922
- this._adapterSizeInScreenSpace();
1923
- }
1924
- } else {
1925
- this._setRealRenderMode(curRenderMode);
1926
- }
1927
- }
1928
- }
1929
- },
1930
- {
1931
- key: "renderCamera",
1932
- get: /**
1933
- * @deprecated Use {@link camera} instead.
1934
- */ function get() {
1935
- return this.camera;
1936
- },
1937
- set: function set(value) {
1938
- this.camera = value;
1939
- }
1940
- },
1941
- {
1942
- key: "resolutionAdaptationMode",
1943
- get: /**
1944
- * The screen resolution adaptation mode of the UI canvas in `ScreenSpaceCamera` and `ScreenSpaceOverlay` mode.
1945
- */ function get() {
1946
- return this._resolutionAdaptationMode;
1947
- },
1948
- set: function set(value) {
1949
- if (this._resolutionAdaptationMode !== value) {
1950
- this._resolutionAdaptationMode = value;
1951
- var realRenderMode = this._realRenderMode;
1952
- if (realRenderMode === CanvasRenderMode.ScreenSpaceCamera || realRenderMode === CanvasRenderMode.ScreenSpaceOverlay) {
1953
- this._adapterSizeInScreenSpace();
1954
- }
1955
- }
1956
- }
1957
- },
1958
- {
1959
- key: "sortOrder",
1960
- get: /**
1961
- * The rendering order priority of the UI canvas in `ScreenSpaceOverlay` mode.
1962
- */ function get() {
1963
- return this._sortOrder;
1964
- },
1965
- set: function set(value) {
1966
- if (this._sortOrder !== value) {
1967
- this._sortOrder = value;
1968
- this._realRenderMode === CanvasRenderMode.ScreenSpaceOverlay && // @ts-ignore
1969
- (this.scene._componentsManager._overlayCanvasesSortingFlag = true);
1970
- }
1971
- }
1972
- },
1973
- {
1974
- key: "distance",
1975
- get: /**
1976
- * The distance between the UI canvas and the camera in `ScreenSpaceCamera` mode.
1977
- */ function get() {
1978
- return this._distance;
1979
- },
1980
- set: function set(value) {
1981
- if (this._distance !== value) {
1982
- this._distance = value;
1983
- if (this._realRenderMode === CanvasRenderMode.ScreenSpaceCamera) {
1984
- this._adapterPoseInScreenSpace();
1985
- this._adapterSizeInScreenSpace();
1986
- }
1987
- }
1988
- }
1989
- }
1990
- ]);
1991
- return UICanvas;
1992
- }(engine.Component);
1993
- /** @internal */ exports.UICanvas._hierarchyCounter = 1;
1994
- exports.UICanvas._tempGroupAbleList = [];
1995
- exports.UICanvas._tempRectMaskList = [];
1996
- exports.UICanvas._tempVec3 = new engine.Vector3();
1997
- exports.UICanvas._tempMat = new engine.Matrix();
1998
- __decorate([
1999
- engine.ignoreClone
2000
- ], exports.UICanvas.prototype, "_canvasIndex", void 0);
2001
- __decorate([
2002
- engine.ignoreClone
2003
- ], exports.UICanvas.prototype, "_indexInRootCanvas", void 0);
2004
- __decorate([
2005
- engine.ignoreClone
2006
- ], exports.UICanvas.prototype, "_isRootCanvasDirty", void 0);
2007
- __decorate([
2008
- engine.ignoreClone
2009
- ], exports.UICanvas.prototype, "_rootCanvasListeningEntities", void 0);
2010
- __decorate([
2011
- engine.ignoreClone
2012
- ], exports.UICanvas.prototype, "_isRootCanvas", void 0);
2013
- __decorate([
2014
- engine.ignoreClone
2015
- ], exports.UICanvas.prototype, "_renderElements", void 0);
2016
- __decorate([
2017
- engine.ignoreClone
2018
- ], exports.UICanvas.prototype, "_batchedRenderElements", void 0);
2019
- __decorate([
2020
- engine.ignoreClone
2021
- ], exports.UICanvas.prototype, "_sortDistance", void 0);
2022
- __decorate([
2023
- engine.ignoreClone
2024
- ], exports.UICanvas.prototype, "_orderedRenderers", void 0);
2025
- __decorate([
2026
- engine.ignoreClone
2027
- ], exports.UICanvas.prototype, "_realRenderMode", void 0);
2028
- __decorate([
2029
- engine.ignoreClone
2030
- ], exports.UICanvas.prototype, "_renderMode", void 0);
2031
- __decorate([
2032
- engine.ignoreClone
2033
- ], exports.UICanvas.prototype, "_hierarchyVersion", void 0);
2034
- __decorate([
2035
- engine.ignoreClone
2036
- ], exports.UICanvas.prototype, "_center", void 0);
2037
- __decorate([
2038
- engine.ignoreClone
2039
- ], exports.UICanvas.prototype, "_rootCanvasListener", null);
2040
- __decorate([
2041
- engine.ignoreClone
2042
- ], exports.UICanvas.prototype, "_onCameraModifyListener", null);
2043
- __decorate([
2044
- engine.ignoreClone
2045
- ], exports.UICanvas.prototype, "_onCameraTransformListener", null);
2046
- __decorate([
2047
- engine.ignoreClone
2048
- ], exports.UICanvas.prototype, "_onCanvasSizeListener", null);
2049
- __decorate([
2050
- engine.ignoreClone
2051
- ], exports.UICanvas.prototype, "_onReferenceResolutionChanged", null);
2052
- exports.UICanvas = __decorate([
2053
- engine.dependentComponents(UITransform, engine.DependentMode.AutoAdd)
2054
- ], exports.UICanvas);
2055
- /**
2056
- * @remarks Extends `EntityModifyFlags`.
2057
- */ var EntityUIModifyFlags = /*#__PURE__*/ function(EntityUIModifyFlags) {
2058
- EntityUIModifyFlags[EntityUIModifyFlags["CanvasEnableInScene"] = 4] = "CanvasEnableInScene";
2059
- EntityUIModifyFlags[EntityUIModifyFlags["GroupEnableInScene"] = 8] = "GroupEnableInScene";
2060
- return EntityUIModifyFlags;
2061
- }({});
2062
- var RootCanvasModifyFlags = /*#__PURE__*/ function(RootCanvasModifyFlags) {
2063
- RootCanvasModifyFlags[RootCanvasModifyFlags["None"] = 0] = "None";
2064
- RootCanvasModifyFlags[RootCanvasModifyFlags["ReferenceResolutionPerUnit"] = 1] = "ReferenceResolutionPerUnit";
2065
- RootCanvasModifyFlags[RootCanvasModifyFlags["All"] = 1] = "All";
2066
- return RootCanvasModifyFlags;
2067
- }({});
2068
-
2069
- var Utils = /*#__PURE__*/ function() {
2070
- function Utils() {}
2071
- /**
2072
- * Local position of a screen point in the component
2073
- */ Utils.screenToLocalPoint = function screenToLocalPoint(position, transform, out) {
2074
- var engine$1 = transform.engine;
2075
- // Get root canvas
2076
- var entity = transform.entity;
2077
- var rootCanvas;
2078
- while(entity){
2079
- // @ts-ignore
2080
- var components = entity._components;
2081
- for(var i = 0, n = components.length; i < n; i++){
2082
- var component = components[i];
2083
- if (component.enabled && _instanceof(component, exports.UICanvas) && component._isRootCanvas) {
2084
- rootCanvas = component;
2085
- }
2086
- }
2087
- entity = entity.parent;
2088
- }
2089
- if (!rootCanvas) return false;
2090
- // Calculate ray
2091
- var ray = this._tempRay;
2092
- switch(rootCanvas._realRenderMode){
2093
- case CanvasRenderMode.ScreenSpaceOverlay:
2094
- // Screen to world ( Assume that world units have a one-to-one relationship with pixel units )
2095
- ray.origin.set(position.x, engine$1.canvas.height - position.y, 1);
2096
- ray.direction.set(0, 0, -1);
2097
- break;
2098
- case CanvasRenderMode.ScreenSpaceCamera:
2099
- rootCanvas.renderCamera.screenPointToRay(position, ray);
2100
- break;
2101
- default:
2102
- // World space not yet supported, see issue #2793
2103
- return false;
2104
- }
2105
- // Intersect ray with UI plane to get local coordinates
2106
- var plane = this._tempPlane;
2107
- var normal = plane.normal.copyFrom(transform.worldForward);
2108
- plane.distance = -engine.Vector3.dot(normal, transform.worldPosition);
2109
- var curDistance = ray.intersectPlane(plane);
2110
- if (curDistance >= 0 && curDistance < Number.MAX_SAFE_INTEGER) {
2111
- var hitPointWorld = ray.getPoint(curDistance, this._tempVec3);
2112
- var worldMatrixInv = this._tempMat;
2113
- engine.Matrix.invert(transform.worldMatrix, worldMatrixInv);
2114
- engine.Vector3.transformCoordinate(hitPointWorld, worldMatrixInv, out);
2115
- return true;
2116
- }
2117
- return false;
2118
- };
2119
- Utils.setRootCanvasDirty = function setRootCanvasDirty(element) {
2120
- if (element._isRootCanvasDirty) return;
2121
- element._isRootCanvasDirty = true;
2122
- this._registerRootCanvas(element, null);
2123
- element._onRootCanvasModify == null ? void 0 : element._onRootCanvasModify.call(element, RootCanvasModifyFlags.All);
2124
- };
2125
- Utils.setRootCanvas = function setRootCanvas(element, rootCanvas) {
2126
- element._isRootCanvasDirty = false;
2127
- this._registerRootCanvas(element, rootCanvas);
2128
- var fromEntity = _instanceof(element, exports.UICanvas) ? element.entity.parent : element.entity;
2129
- var _rootCanvas_entity_parent;
2130
- var toEntity = (_rootCanvas_entity_parent = rootCanvas == null ? void 0 : rootCanvas.entity.parent) != null ? _rootCanvas_entity_parent : null;
2131
- this._registerListener(fromEntity, toEntity, element._rootCanvasListener, element._rootCanvasListeningEntities);
2132
- };
2133
- Utils.cleanRootCanvas = function cleanRootCanvas(element) {
2134
- this._registerRootCanvas(element, null);
2135
- this._unRegisterListener(element._rootCanvasListener, element._rootCanvasListeningEntities);
2136
- };
2137
- Utils.searchRootCanvasInParents = function searchRootCanvasInParents(element) {
2138
- var entity = _instanceof(element, exports.UICanvas) ? element.entity.parent : element.entity;
2139
- while(entity){
2140
- // @ts-ignore
2141
- var components = entity._components;
2142
- for(var i = 0, n = components.length; i < n; i++){
2143
- var component = components[i];
2144
- if (component.enabled && _instanceof(component, exports.UICanvas) && component._isRootCanvas) {
2145
- return component;
2146
- }
2147
- }
2148
- entity = entity.parent;
2149
- }
2150
- return null;
2151
- };
2152
- Utils.setGroupDirty = function setGroupDirty(element) {
2153
- if (element._isGroupDirty) return;
2154
- element._isGroupDirty = true;
2155
- this._registerGroup(element, null);
2156
- element._onGroupModify(GroupModifyFlags.All);
2157
- };
2158
- Utils.setGroup = function setGroup(element, group) {
2159
- element._isGroupDirty = false;
2160
- this._registerGroup(element, group);
2161
- var rootCanvas = element._getRootCanvas();
2162
- if (rootCanvas) {
2163
- var fromEntity = _instanceof(element, UIGroup) ? element.entity.parent : element.entity;
2164
- var _group_entity;
2165
- var toEntity = (_group_entity = group == null ? void 0 : group.entity) != null ? _group_entity : rootCanvas.entity.parent;
2166
- this._registerListener(fromEntity, toEntity, element._groupListener, element._groupListeningEntities);
2167
- } else {
2168
- this._unRegisterListener(element._groupListener, element._groupListeningEntities);
2169
- }
2170
- };
2171
- Utils.cleanGroup = function cleanGroup(element) {
2172
- this._registerGroup(element, null);
2173
- this._unRegisterListener(element._groupListener, element._groupListeningEntities);
2174
- };
2175
- Utils.searchGroupInParents = function searchGroupInParents(element) {
2176
- var rootCanvas = element._getRootCanvas();
2177
- if (!rootCanvas) return null;
2178
- var entity = _instanceof(element, UIGroup) ? element.entity.parent : element.entity;
2179
- var rootCanvasParent = rootCanvas.entity.parent;
2180
- while(entity && entity !== rootCanvasParent){
2181
- // @ts-ignore
2182
- var components = entity._components;
2183
- for(var i = 0, n = components.length; i < n; i++){
2184
- var component = components[i];
2185
- if (component.enabled && _instanceof(component, UIGroup)) {
2186
- return component;
2187
- }
2188
- }
2189
- entity = entity.parent;
2190
- }
2191
- return null;
2192
- };
2193
- Utils._registerRootCanvas = function _registerRootCanvas(element, canvas) {
2194
- var preCanvas = element._rootCanvas;
2195
- if (preCanvas !== canvas) {
2196
- if (preCanvas) {
2197
- var replaced = preCanvas._disorderedElements.deleteByIndex(element._indexInRootCanvas);
2198
- replaced && (replaced._indexInRootCanvas = element._indexInRootCanvas);
2199
- element._indexInRootCanvas = -1;
2200
- }
2201
- if (canvas) {
2202
- var disorderedElements = canvas._disorderedElements;
2203
- element._indexInRootCanvas = disorderedElements.length;
2204
- disorderedElements.add(element);
2205
- }
2206
- element._rootCanvas = canvas;
2207
- }
2208
- };
2209
- Utils._registerGroup = function _registerGroup(element, group) {
2210
- var preGroup = element._group;
2211
- if (preGroup !== group) {
2212
- if (preGroup) {
2213
- var replaced = preGroup._disorderedElements.deleteByIndex(element._indexInGroup);
2214
- replaced && (replaced._indexInGroup = element._indexInGroup);
2215
- element._indexInGroup = -1;
2216
- }
2217
- if (group) {
2218
- var disorderedElements = group._disorderedElements;
2219
- element._indexInGroup = disorderedElements.length;
2220
- disorderedElements.add(element);
2221
- }
2222
- element._group = group;
2223
- element._onGroupModify(GroupModifyFlags.All);
2224
- }
2225
- };
2226
- Utils._registerListener = function _registerListener(entity, root, listener, listeningEntities) {
2227
- var count = 0;
2228
- while(entity && entity !== root){
2229
- var preEntity = listeningEntities[count];
2230
- if (preEntity !== entity) {
2231
- // @ts-ignore
2232
- preEntity == null ? void 0 : preEntity._unRegisterModifyListener(listener);
2233
- listeningEntities[count] = entity;
2234
- // @ts-ignore
2235
- entity._registerModifyListener(listener);
2236
- }
2237
- entity = entity.parent;
2238
- count++;
2239
- }
2240
- listeningEntities.length = count;
2241
- };
2242
- Utils._unRegisterListener = function _unRegisterListener(listener, listeningEntities) {
2243
- for(var i = 0, n = listeningEntities.length; i < n; i++){
2244
- // @ts-ignore
2245
- listeningEntities[i]._unRegisterModifyListener(listener);
2246
- }
2247
- listeningEntities.length = 0;
2248
- };
2249
- return Utils;
2250
- }();
2251
- Utils._tempRay = new engine.Ray();
2252
- Utils._tempPlane = new engine.Plane();
2253
- Utils._tempVec3 = new engine.Vector3();
2254
- Utils._tempMat = new engine.Matrix();
2255
-
2256
- /**
2257
- * Interactive component.
2258
- */ var UIInteractive = /*#__PURE__*/ function(Script) {
2259
- _inherits(UIInteractive, Script);
2260
- function UIInteractive(entity) {
2261
- var _this;
2262
- _this = Script.call(this, entity) || this, /** @internal */ _this._indexInRootCanvas = -1, /** @internal */ _this._isRootCanvasDirty = false, /** @internal */ _this._rootCanvasListeningEntities = [], /** @internal */ _this._indexInGroup = -1, /** @internal */ _this._isGroupDirty = false, /** @internal */ _this._groupListeningEntities = [], /** @internal */ _this._globalInteractive = false, /** @internal */ _this._globalInteractiveDirty = false, _this._transitions = [], _this._interactive = true, _this._state = 0, /** @todo Multi-touch points are not considered yet. */ _this._isPointerInside = false, _this._isPointerDragging = false;
2263
- _this._groupListener = _this._groupListener.bind(_this);
2264
- _this._rootCanvasListener = _this._rootCanvasListener.bind(_this);
2265
- return _this;
2266
- }
2267
- var _proto = UIInteractive.prototype;
2268
- /**
2269
- * Add transition on this interactive.
2270
- * @param transition - The transition
2271
- */ _proto.addTransition = function addTransition(transition) {
2272
- var interactive = transition._interactive;
2273
- if (interactive !== this) {
2274
- interactive == null ? void 0 : interactive.removeTransition(transition);
2275
- this._transitions.push(transition);
2276
- transition._interactive = this;
2277
- transition._setState(this._state, true);
2278
- }
2279
- };
2280
- /**
2281
- * Remove a transition.
2282
- * @param shape - The transition.
2283
- */ _proto.removeTransition = function removeTransition(transition) {
2284
- var transitions = this._transitions;
2285
- var lastOneIndex = transitions.length - 1;
2286
- for(var i = lastOneIndex; i >= 0; i--){
2287
- if (transitions[i] === transition) {
2288
- i !== lastOneIndex && (transitions[i] = transitions[lastOneIndex]);
2289
- transitions.length = lastOneIndex;
2290
- transition._interactive = null;
2291
- break;
2292
- }
2293
- }
2294
- };
2295
- /**
2296
- * Remove all transitions.
2297
- */ _proto.clearTransitions = function clearTransitions() {
2298
- var transitions = this._transitions;
2299
- for(var i = 0, n = transitions.length; i < n; i++){
2300
- transitions[i]._interactive = null;
2301
- }
2302
- transitions.length = 0;
2303
- };
2304
- _proto.onUpdate = function onUpdate(deltaTime) {
2305
- if (this._getGlobalInteractive()) {
2306
- var transitions = this._transitions;
2307
- for(var i = 0, n = transitions.length; i < n; i++){
2308
- transitions[i]._onUpdate(deltaTime);
2309
- }
2310
- }
2311
- };
2312
- _proto.onPointerBeginDrag = function onPointerBeginDrag() {
2313
- this._isPointerDragging = true;
2314
- this._updateState(false);
2315
- };
2316
- _proto.onPointerEndDrag = function onPointerEndDrag() {
2317
- this._isPointerDragging = false;
2318
- this._updateState(false);
2319
- };
2320
- _proto.onPointerEnter = function onPointerEnter() {
2321
- this._isPointerInside = true;
2322
- this._updateState(false);
2323
- };
2324
- _proto.onPointerExit = function onPointerExit() {
2325
- this._isPointerInside = false;
2326
- this._updateState(false);
2327
- };
2328
- _proto.onDestroy = function onDestroy() {
2329
- Script.prototype.onDestroy.call(this);
2330
- var transitions = this._transitions;
2331
- for(var i = transitions.length - 1; i >= 0; i--){
2332
- transitions[i].destroy();
2333
- }
2334
- };
2335
- /**
2336
- * @internal
2337
- */ _proto._getRootCanvas = function _getRootCanvas() {
2338
- this._isRootCanvasDirty && Utils.setRootCanvas(this, Utils.searchRootCanvasInParents(this));
2339
- return this._rootCanvas;
2340
- };
2341
- /**
2342
- * @internal
2343
- */ _proto._getGroup = function _getGroup() {
2344
- this._isGroupDirty && Utils.setGroup(this, Utils.searchGroupInParents(this));
2345
- return this._group;
2346
- };
2347
- // @ts-ignore
2348
- _proto._onEnableInScene = function _onEnableInScene() {
2349
- // @ts-ignore
2350
- Script.prototype._onEnableInScene.call(this);
2351
- Utils.setRootCanvasDirty(this);
2352
- Utils.setGroupDirty(this);
2353
- this._updateState(true);
2354
- };
2355
- // @ts-ignore
2356
- _proto._onDisableInScene = function _onDisableInScene() {
2357
- // @ts-ignore
2358
- Script.prototype._onDisableInScene.call(this);
2359
- Utils.cleanRootCanvas(this);
2360
- Utils.cleanGroup(this);
2361
- this._isPointerInside = this._isPointerDragging = false;
2362
- };
2363
- /**
2364
- * @internal
2365
- */ _proto._groupListener = function _groupListener(flag) {
2366
- if (flag === engine.EntityModifyFlags.Parent || flag === EntityUIModifyFlags.GroupEnableInScene) {
2367
- Utils.setGroupDirty(this);
2368
- }
2369
- };
2370
- /**
2371
- * @internal
2372
- */ _proto._rootCanvasListener = function _rootCanvasListener(flag) {
2373
- if (flag === engine.EntityModifyFlags.Parent || flag === EntityUIModifyFlags.CanvasEnableInScene) {
2374
- Utils.setRootCanvasDirty(this);
2375
- Utils.setGroupDirty(this);
2376
- }
2377
- };
2378
- /**
2379
- * @internal
2380
- */ _proto._onGroupModify = function _onGroupModify(flags) {
2381
- if (flags & GroupModifyFlags.GlobalInteractive) {
2382
- this._globalInteractiveDirty = true;
2383
- }
2384
- };
2385
- /**
2386
- * @internal
2387
- */ _proto._getGlobalInteractive = function _getGlobalInteractive() {
2388
- if (this._globalInteractiveDirty) {
2389
- var group = this._getGroup();
2390
- var globalInteractive = this._interactive && (!group || group._getGlobalInteractive());
2391
- if (this._globalInteractive !== globalInteractive) {
2392
- this._globalInteractive = globalInteractive;
2393
- this._updateState(true);
2394
- }
2395
- this._globalInteractiveDirty = false;
2396
- }
2397
- return this._globalInteractive;
2398
- };
2399
- _proto._updateState = function _updateState(instant) {
2400
- var state = this._getInteractiveState();
2401
- if (this._state !== state) {
2402
- this._state = state;
2403
- var transitions = this._transitions;
2404
- for(var i = 0, n = transitions.length; i < n; i++){
2405
- transitions[i]._setState(state, instant);
2406
- }
2407
- }
2408
- };
2409
- _proto._getInteractiveState = function _getInteractiveState() {
2410
- if (!this._getGlobalInteractive()) {
2411
- return 3;
2412
- }
2413
- if (this._isPointerDragging) {
2414
- return 1;
2415
- } else {
2416
- return this._isPointerInside ? 2 : 0;
2417
- }
2418
- };
2419
- _create_class(UIInteractive, [
2420
- {
2421
- key: "transitions",
2422
- get: /**
2423
- * The transitions of this interactive.
2424
- */ function get() {
2425
- return this._transitions;
2426
- }
2427
- },
2428
- {
2429
- key: "interactive",
2430
- get: /**
2431
- * Whether the interactive is enabled.
2432
- */ function get() {
2433
- return this._interactive;
2434
- },
2435
- set: function set(value) {
2436
- if (this._interactive !== value) {
2437
- this._interactive = value;
2438
- this._globalInteractiveDirty = true;
2439
- }
2440
- }
2441
- }
2442
- ]);
2443
- return UIInteractive;
2444
- }(engine.Script);
2445
- __decorate([
2446
- engine.ignoreClone
2447
- ], UIInteractive.prototype, "_indexInRootCanvas", void 0);
2448
- __decorate([
2449
- engine.ignoreClone
2450
- ], UIInteractive.prototype, "_isRootCanvasDirty", void 0);
2451
- __decorate([
2452
- engine.ignoreClone
2453
- ], UIInteractive.prototype, "_rootCanvasListeningEntities", void 0);
2454
- __decorate([
2455
- engine.ignoreClone
2456
- ], UIInteractive.prototype, "_indexInGroup", void 0);
2457
- __decorate([
2458
- engine.ignoreClone
2459
- ], UIInteractive.prototype, "_isGroupDirty", void 0);
2460
- __decorate([
2461
- engine.ignoreClone
2462
- ], UIInteractive.prototype, "_groupListeningEntities", void 0);
2463
- __decorate([
2464
- engine.ignoreClone
2465
- ], UIInteractive.prototype, "_globalInteractive", void 0);
2466
- __decorate([
2467
- engine.ignoreClone
2468
- ], UIInteractive.prototype, "_globalInteractiveDirty", void 0);
2469
- __decorate([
2470
- engine.ignoreClone
2471
- ], UIInteractive.prototype, "_state", void 0);
2472
- __decorate([
2473
- engine.ignoreClone
2474
- ], UIInteractive.prototype, "_isPointerInside", void 0);
2475
- __decorate([
2476
- engine.ignoreClone
2477
- ], UIInteractive.prototype, "_isPointerDragging", void 0);
2478
- __decorate([
2479
- engine.ignoreClone
2480
- ], UIInteractive.prototype, "_groupListener", null);
2481
- __decorate([
2482
- engine.ignoreClone
2483
- ], UIInteractive.prototype, "_rootCanvasListener", null);
2484
- __decorate([
2485
- engine.ignoreClone
2486
- ], UIInteractive.prototype, "_onGroupModify", null);
2487
- var InteractiveState = /*#__PURE__*/ function(InteractiveState) {
2488
- InteractiveState[InteractiveState["Normal"] = 0] = "Normal";
2489
- InteractiveState[InteractiveState["Pressed"] = 1] = "Pressed";
2490
- InteractiveState[InteractiveState["Hover"] = 2] = "Hover";
2491
- InteractiveState[InteractiveState["Disable"] = 3] = "Disable";
2492
- return InteractiveState;
2493
- }({});
2494
-
2495
- var Button = /*#__PURE__*/ function(UIInteractive) {
2496
- _inherits(Button, UIInteractive);
2497
- function Button() {
2498
- var _this;
2499
- _this = UIInteractive.apply(this, arguments) || this, /** Signal emitted when the button is clicked. */ _this.onClick = new engine.Signal();
2500
- return _this;
2501
- }
2502
- var _proto = Button.prototype;
2503
- _proto.onPointerClick = function onPointerClick(event) {
2504
- if (!this._getGlobalInteractive()) return;
2505
- this.onClick.invoke(event);
2506
- };
2507
- _proto.onDestroy = function onDestroy() {
2508
- UIInteractive.prototype.onDestroy.call(this);
2509
- this.onClick.removeAll();
2510
- };
2511
- /**
2512
- * Add a listening function for click.
2513
- * @deprecated Use `onClick.on(listener, context)` instead.
2514
- */ _proto.addClicked = function addClicked(listener) {
2515
- this.onClick.on(listener);
2516
- };
2517
- /**
2518
- * Remove a listening function of click.
2519
- * @deprecated Use `onClick.off(listener, context)` instead.
2520
- */ _proto.removeClicked = function removeClicked(listener) {
2521
- this.onClick.off(listener);
2522
- };
2523
- return Button;
2524
- }(UIInteractive);
2525
-
2526
- /**
2527
- * UI element that renders an image.
2528
- */ var Image = /*#__PURE__*/ function(UIRenderer1) {
2529
- _inherits(Image, UIRenderer1);
2530
- function Image(entity) {
2531
- var _this;
2532
- _this = UIRenderer1.call(this, entity) || this, _this._sprite = null, _this._tileMode = engine.SpriteTileMode.Continuous, _this._tiledAdaptiveThreshold = 0.5, _this._filledMode = engine.SpriteFilledMode.Radial360, _this._filledAmount = 1, _this._filledOrigin = engine.SpriteFilledOrigin.Bottom, _this._filledClockWise = true;
2533
- _this.drawMode = engine.SpriteDrawMode.Simple;
2534
- // @ts-ignore
2535
- _this.setMaterial(_this._engine._getUIDefaultMaterial());
2536
- _this._onSpriteChange = _this._onSpriteChange.bind(_this);
2537
- return _this;
2538
- }
2539
- var _proto = Image.prototype;
2540
- /**
2541
- * @internal
2542
- */ _proto._onRootCanvasModify = function _onRootCanvasModify(flag) {
2543
- if (flag & RootCanvasModifyFlags.ReferenceResolutionPerUnit) {
2544
- var drawMode = this._drawMode;
2545
- if (drawMode === engine.SpriteDrawMode.Tiled) {
2546
- this._dirtyUpdateFlag |= 15;
2547
- } else if (drawMode === engine.SpriteDrawMode.Sliced) {
2548
- this._dirtyUpdateFlag |= engine.RendererUpdateFlags.WorldVolume;
2549
- }
2550
- }
2551
- };
2552
- /**
2553
- * @internal
2554
- */ _proto._cloneTo = function _cloneTo(target) {
2555
- // @ts-ignore
2556
- UIRenderer1.prototype._cloneTo.call(this, target);
2557
- target.sprite = this._sprite;
2558
- target.drawMode = this._drawMode;
2559
- };
2560
- _proto._updateBounds = function _updateBounds(worldBounds) {
2561
- var sprite = this._sprite;
2562
- var rootCanvas = this._getRootCanvas();
2563
- if (sprite && rootCanvas) {
2564
- var transform = this._transformEntity.transform;
2565
- var size = transform.size;
2566
- this._assembler.updatePositions(this, transform.worldMatrix, size.x, size.y, transform.pivot, false, false, rootCanvas.referenceResolutionPerUnit);
2567
- } else {
2568
- var worldPosition = this._transformEntity.transform.worldPosition;
2569
- worldBounds.min.copyFrom(worldPosition);
2570
- worldBounds.max.copyFrom(worldPosition);
2571
- }
2572
- };
2573
- _proto._render = function _render(context) {
2574
- var _this = this, sprite = _this._sprite;
2575
- var transform = this._transformEntity.transform;
2576
- var _transform_size = transform.size, width = _transform_size.x, height = _transform_size.y;
2577
- if (!(sprite == null ? void 0 : sprite.texture) || !width || !height) {
2578
- return;
2579
- }
2580
- var material = this.getMaterial();
2581
- if (!material) {
2582
- return;
2583
- }
2584
- // @todo: This question needs to be raised rather than hidden.
2585
- if (material.destroyed) {
2586
- // @ts-ignore
2587
- material = this._engine._getUIDefaultMaterial();
2588
- }
2589
- var alpha = this._getGlobalAlpha();
2590
- if (this._color.a * alpha <= 0) {
2591
- return;
2592
- }
2593
- var _this1 = this, dirtyUpdateFlag = _this1._dirtyUpdateFlag;
2594
- var canvas = this._getRootCanvas();
2595
- // Update position
2596
- if (dirtyUpdateFlag & engine.RendererUpdateFlags.WorldVolume) {
2597
- this._assembler.updatePositions(this, transform.worldMatrix, width, height, transform.pivot, false, false, canvas.referenceResolutionPerUnit);
2598
- dirtyUpdateFlag &= ~engine.RendererUpdateFlags.WorldVolume;
2599
- }
2600
- // Update uv
2601
- if (dirtyUpdateFlag & 4) {
2602
- this._assembler.updateUVs(this);
2603
- dirtyUpdateFlag &= ~4;
2604
- }
2605
- // Update color
2606
- if (dirtyUpdateFlag & UIRendererUpdateFlags.Color) {
2607
- this._assembler.updateColor(this, alpha);
2608
- dirtyUpdateFlag &= ~UIRendererUpdateFlags.Color;
2609
- }
2610
- this._dirtyUpdateFlag = dirtyUpdateFlag;
2611
- var engine$1 = context.camera.engine;
2612
- var renderElement = engine$1._renderElementPool.get();
2613
- var subChunk = this._subChunk;
2614
- renderElement.set(this, material, subChunk.chunk.primitive, subChunk.subMesh, this.sprite.texture, subChunk);
2615
- renderElement.subShader = material.shader.subShaders[0];
2616
- renderElement.priority = canvas.sortOrder;
2617
- renderElement.distanceForSort = canvas._sortDistance;
2618
- canvas._renderElements.push(renderElement);
2619
- };
2620
- _proto._onTransformChanged = function _onTransformChanged(type) {
2621
- if (type & UITransformModifyFlags.Size && (this._drawMode === engine.SpriteDrawMode.Tiled || this._drawMode === engine.SpriteDrawMode.Filled)) {
2622
- this._dirtyUpdateFlag |= 15;
2623
- }
2624
- this._dirtyUpdateFlag |= engine.RendererUpdateFlags.WorldVolume;
2625
- };
2626
- _proto._onDestroy = function _onDestroy() {
2627
- var sprite = this._sprite;
2628
- if (sprite) {
2629
- this._addResourceReferCount(sprite, -1);
2630
- // @ts-ignore
2631
- sprite._updateFlagManager.removeListener(this._onSpriteChange);
2632
- this._sprite = null;
2633
- }
2634
- UIRenderer1.prototype._onDestroy.call(this);
2635
- };
2636
- _proto._onSpriteChange = function _onSpriteChange(type) {
2637
- switch(type){
2638
- case engine.SpriteModifyFlags.texture:
2639
- this.shaderData.setTexture(exports.UIRenderer._textureProperty, this.sprite.texture);
2640
- break;
2641
- case engine.SpriteModifyFlags.size:
2642
- switch(this._drawMode){
2643
- case engine.SpriteDrawMode.Sliced:
2644
- this._dirtyUpdateFlag |= engine.RendererUpdateFlags.WorldVolume;
2645
- break;
2646
- case engine.SpriteDrawMode.Tiled:
2647
- this._dirtyUpdateFlag |= 7;
2648
- break;
2649
- case engine.SpriteDrawMode.Filled:
2650
- this._dirtyUpdateFlag |= 7;
2651
- break;
2652
- }
2653
- break;
2654
- case engine.SpriteModifyFlags.border:
2655
- switch(this._drawMode){
2656
- case engine.SpriteDrawMode.Sliced:
2657
- this._dirtyUpdateFlag |= 5;
2658
- break;
2659
- case engine.SpriteDrawMode.Tiled:
2660
- this._dirtyUpdateFlag |= 7;
2661
- break;
2662
- }
2663
- break;
2664
- case engine.SpriteModifyFlags.region:
2665
- case engine.SpriteModifyFlags.atlasRegionOffset:
2666
- this._dirtyUpdateFlag |= 5;
2667
- break;
2668
- case engine.SpriteModifyFlags.atlasRegion:
2669
- this._dirtyUpdateFlag |= this._drawMode === engine.SpriteDrawMode.Filled ? 5 : 4;
2670
- break;
2671
- case engine.SpriteModifyFlags.destroy:
2672
- this.sprite = null;
2673
- break;
2674
- }
2675
- };
2676
- Image._correctOrigin = function _correctOrigin(mode, origin) {
2677
- switch(mode){
2678
- case engine.SpriteFilledMode.Horizontal:
2679
- return origin === engine.SpriteFilledOrigin.Left || origin === engine.SpriteFilledOrigin.Right ? origin : engine.SpriteFilledOrigin.Left;
2680
- case engine.SpriteFilledMode.Vertical:
2681
- return origin === engine.SpriteFilledOrigin.Top || origin === engine.SpriteFilledOrigin.Bottom ? origin : engine.SpriteFilledOrigin.Bottom;
2682
- case engine.SpriteFilledMode.Radial90:
2683
- return origin === engine.SpriteFilledOrigin.TopLeft || origin === engine.SpriteFilledOrigin.TopRight || origin === engine.SpriteFilledOrigin.BottomLeft || origin === engine.SpriteFilledOrigin.BottomRight ? origin : engine.SpriteFilledOrigin.BottomLeft;
2684
- default:
2685
- return origin === engine.SpriteFilledOrigin.Top || origin === engine.SpriteFilledOrigin.Bottom || origin === engine.SpriteFilledOrigin.Left || origin === engine.SpriteFilledOrigin.Right ? origin : engine.SpriteFilledOrigin.Bottom;
2686
- }
2687
- };
2688
- _create_class(Image, [
2689
- {
2690
- key: "drawMode",
2691
- get: /**
2692
- * The draw mode of the image.
2693
- */ function get() {
2694
- return this._drawMode;
2695
- },
2696
- set: function set(value) {
2697
- if (this._drawMode !== value) {
2698
- this._drawMode = value;
2699
- switch(value){
2700
- case engine.SpriteDrawMode.Simple:
2701
- this._assembler = engine.SimpleSpriteAssembler;
2702
- break;
2703
- case engine.SpriteDrawMode.Sliced:
2704
- this._assembler = engine.SlicedSpriteAssembler;
2705
- break;
2706
- case engine.SpriteDrawMode.Tiled:
2707
- this._assembler = engine.TiledSpriteAssembler;
2708
- break;
2709
- case engine.SpriteDrawMode.Filled:
2710
- this._assembler = engine.FilledSpriteAssembler;
2711
- break;
2712
- }
2713
- this._assembler.resetData(this);
2714
- this._dirtyUpdateFlag |= 7;
2715
- }
2716
- }
2717
- },
2718
- {
2719
- key: "tileMode",
2720
- get: /**
2721
- * The tiling mode of the image. (Only works in tiled mode.)
2722
- */ function get() {
2723
- return this._tileMode;
2724
- },
2725
- set: function set(value) {
2726
- if (this._tileMode !== value) {
2727
- this._tileMode = value;
2728
- if (this.drawMode === engine.SpriteDrawMode.Tiled) {
2729
- this._dirtyUpdateFlag |= 7;
2730
- }
2731
- }
2732
- }
2733
- },
2734
- {
2735
- key: "tiledAdaptiveThreshold",
2736
- get: /**
2737
- * Stretch Threshold in Tile Adaptive Mode, specified in normalized. (Only works in tiled adaptive mode.)
2738
- */ function get() {
2739
- return this._tiledAdaptiveThreshold;
2740
- },
2741
- set: function set(value) {
2742
- if (value !== this._tiledAdaptiveThreshold) {
2743
- value = engine.MathUtil.clamp(value, 0, 1);
2744
- this._tiledAdaptiveThreshold = value;
2745
- if (this.drawMode === engine.SpriteDrawMode.Tiled) {
2746
- this._dirtyUpdateFlag |= 7;
2747
- }
2748
- }
2749
- }
2750
- },
2751
- {
2752
- key: "filledAmount",
2753
- get: /**
2754
- * The fill amount of the image, range from 0 to 1. (Only works in filled mode.)
2755
- */ function get() {
2756
- return this._filledAmount;
2757
- },
2758
- set: function set(value) {
2759
- value = engine.MathUtil.clamp(value, 0, 1);
2760
- if (this._filledAmount !== value) {
2761
- this._filledAmount = value;
2762
- if (this._drawMode === engine.SpriteDrawMode.Filled) {
2763
- this._dirtyUpdateFlag |= 5;
2764
- }
2765
- }
2766
- }
2767
- },
2768
- {
2769
- key: "filledMode",
2770
- get: /**
2771
- * The fill mode of the image. (Only works in filled mode.)
2772
- */ function get() {
2773
- return this._filledMode;
2774
- },
2775
- set: function set(value) {
2776
- if (this._filledMode !== value) {
2777
- this._filledMode = value;
2778
- this._filledOrigin = Image._correctOrigin(value, this._filledOrigin);
2779
- if (this._drawMode === engine.SpriteDrawMode.Filled) {
2780
- this._dirtyUpdateFlag |= 5;
2781
- }
2782
- }
2783
- }
2784
- },
2785
- {
2786
- key: "filledOrigin",
2787
- get: /**
2788
- * The fill origin of the image. (Only works in filled mode.)
2789
- */ function get() {
2790
- return this._filledOrigin;
2791
- },
2792
- set: function set(value) {
2793
- value = Image._correctOrigin(this._filledMode, value);
2794
- if (this._filledOrigin !== value) {
2795
- this._filledOrigin = value;
2796
- if (this._drawMode === engine.SpriteDrawMode.Filled) {
2797
- this._dirtyUpdateFlag |= 5;
2798
- }
2799
- }
2800
- }
2801
- },
2802
- {
2803
- key: "filledClockWise",
2804
- get: /**
2805
- * Whether the fill is clockwise. (Only works in filled radial mode.)
2806
- */ function get() {
2807
- return this._filledClockWise;
2808
- },
2809
- set: function set(value) {
2810
- if (this._filledClockWise !== value) {
2811
- this._filledClockWise = value;
2812
- if (this._drawMode === engine.SpriteDrawMode.Filled) {
2813
- this._dirtyUpdateFlag |= 5;
2814
- }
2815
- }
2816
- }
2817
- },
2818
- {
2819
- key: "sprite",
2820
- get: /**
2821
- * The Sprite to render.
2822
- */ function get() {
2823
- return this._sprite;
2824
- },
2825
- set: function set(value) {
2826
- var lastSprite = this._sprite;
2827
- if (lastSprite !== value) {
2828
- if (lastSprite) {
2829
- this._addResourceReferCount(lastSprite, -1);
2830
- // @ts-ignore
2831
- lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
2832
- }
2833
- this._dirtyUpdateFlag |= 7;
2834
- if (value) {
2835
- this._addResourceReferCount(value, 1);
2836
- // @ts-ignore
2837
- value._updateFlagManager.addListener(this._onSpriteChange);
2838
- this.shaderData.setTexture(exports.UIRenderer._textureProperty, value.texture);
2839
- } else {
2840
- this.shaderData.setTexture(exports.UIRenderer._textureProperty, null);
2841
- }
2842
- this._sprite = value;
2843
- }
2844
- }
2845
- }
2846
- ]);
2847
- return Image;
2848
- }(exports.UIRenderer);
2849
- __decorate([
2850
- engine.ignoreClone
2851
- ], Image.prototype, "_sprite", void 0);
2852
- __decorate([
2853
- engine.ignoreClone
2854
- ], Image.prototype, "_drawMode", void 0);
2855
- __decorate([
2856
- engine.ignoreClone
2857
- ], Image.prototype, "_assembler", void 0);
2858
- __decorate([
2859
- engine.ignoreClone
2860
- ], Image.prototype, "_onTransformChanged", null);
2861
- __decorate([
2862
- engine.ignoreClone
2863
- ], Image.prototype, "_onSpriteChange", null);
2864
-
2865
- /**
2866
- * UI component that uses a sprite to mask child UI renderers via stencil.
2867
- */ var Mask = /*#__PURE__*/ function(_MaskRenderable) {
2868
- _inherits(Mask, _MaskRenderable);
2869
- function Mask(entity) {
2870
- var _this;
2871
- _this = _MaskRenderable.call(this, entity) || this;
2872
- _this._initMask();
2873
- _this.raycastEnabled = false;
2874
- return _this;
2875
- }
2876
- var _proto = Mask.prototype;
2877
- /**
2878
- * @internal
2879
- */ _proto._getChunkManager = function _getChunkManager() {
2880
- // @ts-ignore
2881
- return this.engine._batcherManager.primitiveChunkManagerMask;
2882
- };
2883
- /**
2884
- * @internal
2885
- */ // @ts-ignore
2886
- _proto._cloneTo = function _cloneTo(target) {
2887
- // @ts-ignore
2888
- _MaskRenderable.prototype._cloneTo.call(this, target);
2889
- this._cloneMaskData(target);
2890
- };
2891
- _proto._updateBounds = function _updateBounds(worldBounds) {
2892
- var rootCanvas = this._getRootCanvas();
2893
- if (this.sprite && rootCanvas) {
2894
- this._updateMaskBounds(worldBounds);
2895
- } else {
2896
- var worldPosition = this._transformEntity.transform.worldPosition;
2897
- worldBounds.min.copyFrom(worldPosition);
2898
- worldBounds.max.copyFrom(worldPosition);
2899
- }
2900
- };
2901
- /**
2902
- * @inheritdoc
2903
- */ _proto._render = function _render(context) {
2904
- this._renderMask(0);
2905
- };
2906
- /**
2907
- * @inheritdoc
2908
- */ _proto._onDestroy = function _onDestroy() {
2909
- this._destroyMaskResources();
2910
- _MaskRenderable.prototype._onDestroy.call(this);
2911
- if (this._subChunk) {
2912
- this._getChunkManager().freeSubChunk(this._subChunk);
2913
- this._subChunk = null;
2914
- }
2915
- };
2916
- _proto._getSpriteWidth = function _getSpriteWidth() {
2917
- return this._transformEntity.transform.size.x;
2918
- };
2919
- _proto._getSpriteHeight = function _getSpriteHeight() {
2920
- return this._transformEntity.transform.size.y;
2921
- };
2922
- _proto._getSpritePivot = function _getSpritePivot() {
2923
- return this._transformEntity.transform.pivot;
2924
- };
2925
- return Mask;
2926
- }(engine.MaskRenderable(exports.UIRenderer));
2927
-
2928
- /**
2929
- * UI component used to render text.
2930
- */ var Text = /*#__PURE__*/ function(UIRenderer1) {
2931
- _inherits(Text, UIRenderer1);
2932
- function Text(entity) {
2933
- var _this;
2934
- _this = UIRenderer1.call(this, entity) || this, _this._textChunks = Array(), _this._subFont = null, _this._text = "", _this._localBounds = new engine.BoundingBox(), _this._font = null, _this._fontSize = 24, _this._fontStyle = engine.FontStyle.None, _this._lineSpacing = 0, _this._characterSpacing = 0, _this._horizontalAlignment = engine.TextHorizontalAlignment.Center, _this._verticalAlignment = engine.TextVerticalAlignment.Center, _this._enableWrapping = false, _this._overflowMode = engine.OverflowMode.Overflow, _this._outlineColor = new engine.Color(0, 0, 0, 1), _this._outlineWidth = 0;
2935
- var engine$1 = _this.engine;
2936
- // @ts-ignore
2937
- _this.font = engine$1._textDefaultFont;
2938
- _this.raycastEnabled = false;
2939
- // @ts-ignore
2940
- _this.setMaterial(engine$1._basicResources.textDefaultMaterial);
2941
- var shaderData = _this.shaderData;
2942
- shaderData.setFloat(Text._outlineWidthProperty, _this._outlineWidth);
2943
- shaderData.setColor(Text._outlineColorProperty, _this._outlineColor);
2944
- // @ts-ignore
2945
- _this._outlineColor._onValueChanged = _this._onOutlineColorChanged.bind(_this);
2946
- return _this;
2947
- }
2948
- var _proto = Text.prototype;
2949
- /**
2950
- * @internal
2951
- */ _proto._onDestroy = function _onDestroy() {
2952
- if (this._font) {
2953
- this._addResourceReferCount(this._font, -1);
2954
- this._font = null;
2955
- }
2956
- UIRenderer1.prototype._onDestroy.call(this);
2957
- this._freeTextChunks();
2958
- this._textChunks = null;
2959
- this._subFont && (this._subFont = null);
2960
- };
2961
- /**
2962
- * @internal
2963
- */ _proto._isContainDirtyFlag = function _isContainDirtyFlag(type) {
2964
- return (this._dirtyUpdateFlag & type) != 0;
2965
- };
2966
- /**
2967
- * @internal
2968
- */ _proto._setDirtyFlagTrue = function _setDirtyFlagTrue(type) {
2969
- this._dirtyUpdateFlag |= type;
2970
- };
2971
- /**
2972
- * @internal
2973
- */ _proto._setDirtyFlagFalse = function _setDirtyFlagFalse(type) {
2974
- this._dirtyUpdateFlag &= ~type;
2975
- };
2976
- /**
2977
- * @internal
2978
- */ _proto._getSubFont = function _getSubFont() {
2979
- if (!this._subFont) {
2980
- this._resetSubFont();
2981
- }
2982
- return this._subFont;
2983
- };
2984
- /**
2985
- * @internal
2986
- */ _proto._onRootCanvasModify = function _onRootCanvasModify(flag) {
2987
- if (flag === RootCanvasModifyFlags.ReferenceResolutionPerUnit) {
2988
- this._setDirtyFlagTrue(25);
2989
- }
2990
- };
2991
- /**
2992
- * @internal
2993
- */ _proto._canBatch = function _canBatch(preElement, curElement) {
2994
- return engine.VertexMergeBatcher.canBatchText(preElement, curElement);
2995
- };
2996
- _proto._updateBounds = function _updateBounds(worldBounds) {
2997
- engine.BoundingBox.transform(this._localBounds, this._transformEntity.transform.worldMatrix, worldBounds);
2998
- };
2999
- _proto._render = function _render(context) {
3000
- if (this._isTextNoVisible()) {
3001
- return;
3002
- }
3003
- if (this._isContainDirtyFlag(4)) {
3004
- this._resetSubFont();
3005
- this._setDirtyFlagFalse(4);
3006
- }
3007
- var canvas = this._getRootCanvas();
3008
- if (this._isContainDirtyFlag(8)) {
3009
- this._updateLocalData();
3010
- this._setDirtyFlagFalse(8);
3011
- }
3012
- if (this._isContainDirtyFlag(16)) {
3013
- this._updatePosition();
3014
- this._setDirtyFlagFalse(16);
3015
- }
3016
- if (this._isContainDirtyFlag(UIRendererUpdateFlags.Color)) {
3017
- this._updateColor();
3018
- this._setDirtyFlagFalse(UIRendererUpdateFlags.Color);
3019
- }
3020
- var engine$1 = context.camera.engine;
3021
- var textRenderElementPool = engine$1._textRenderElementPool;
3022
- var material = this.getMaterial();
3023
- var renderElements = canvas._renderElements;
3024
- var priority = canvas.sortOrder;
3025
- var distanceForSort = canvas._sortDistance;
3026
- var textChunks = this._textChunks;
3027
- var subShader = material.shader.subShaders[0];
3028
- var textTextureSize = Text._tempVec20;
3029
- for(var i = 0, n = textChunks.length; i < n; ++i){
3030
- var // @ts-ignore
3031
- _renderElement;
3032
- var _textChunks_i = textChunks[i], subChunk = _textChunks_i.subChunk, texture = _textChunks_i.texture;
3033
- var renderElement = textRenderElementPool.get();
3034
- renderElement.set(this, material, subChunk.chunk.primitive, subChunk.subMesh, texture, subChunk);
3035
- (_renderElement = renderElement).shaderData || (_renderElement.shaderData = new engine.ShaderData(engine.ShaderDataGroup.RenderElement));
3036
- renderElement.shaderData.setTexture(Text._textTextureProperty, texture);
3037
- renderElement.shaderData.setVector2(Text._textTextureSizeProperty, textTextureSize.set(texture.width, texture.height));
3038
- renderElement.subShader = subShader;
3039
- renderElement.priority = priority;
3040
- renderElement.distanceForSort = distanceForSort;
3041
- renderElements.push(renderElement);
3042
- }
3043
- };
3044
- _proto._resetSubFont = function _resetSubFont() {
3045
- var font = this._font;
3046
- // @ts-ignore
3047
- this._subFont = font._getSubFont(this.fontSize, this.fontStyle);
3048
- this._subFont.nativeFontString = engine.TextUtils.getNativeFontString(font.name, this.fontSize, this.fontStyle);
3049
- };
3050
- /**
3051
- * Switch the sub font to a specific font size, used by the SHRINK overflow measurement.
3052
- */ _proto._applyFontSizeForShrink = function _applyFontSizeForShrink(fontSize) {
3053
- var font = this._font;
3054
- // @ts-ignore
3055
- var subFont = font._getSubFont(fontSize, this._fontStyle);
3056
- subFont.nativeFontString = engine.TextUtils.getNativeFontString(font.name, fontSize, this._fontStyle);
3057
- this._subFont = subFont;
3058
- };
3059
- _proto._updatePosition = function _updatePosition() {
3060
- var e = this._transformEntity.transform.worldMatrix.elements;
3061
- // prettier-ignore
3062
- var e0 = e[0], e1 = e[1], e2 = e[2], e4 = e[4], e5 = e[5], e6 = e[6], e12 = e[12], e13 = e[13], e14 = e[14];
3063
- var up = exports.UIRenderer._tempVec31.set(e4, e5, e6);
3064
- var right = exports.UIRenderer._tempVec30.set(e0, e1, e2);
3065
- var worldPositions = Text._worldPositions;
3066
- var worldPosition0 = worldPositions[0], worldPosition1 = worldPositions[1], worldPosition2 = worldPositions[2], worldPosition3 = worldPositions[3];
3067
- var textChunks = this._textChunks;
3068
- for(var i = 0, n = textChunks.length; i < n; ++i){
3069
- var _textChunks_i = textChunks[i], subChunk = _textChunks_i.subChunk, charRenderInfos = _textChunks_i.charRenderInfos;
3070
- for(var j = 0, m = charRenderInfos.length; j < m; ++j){
3071
- var charRenderInfo = charRenderInfos[j];
3072
- var localPositions = charRenderInfo.localPositions;
3073
- var topLeftX = localPositions.x, topLeftY = localPositions.y;
3074
- // Top-Left
3075
- worldPosition0.set(topLeftX * e0 + topLeftY * e4 + e12, topLeftX * e1 + topLeftY * e5 + e13, topLeftX * e2 + topLeftY * e6 + e14);
3076
- // Right offset
3077
- engine.Vector3.scale(right, localPositions.z - topLeftX, worldPosition1);
3078
- // Top-Right
3079
- engine.Vector3.add(worldPosition0, worldPosition1, worldPosition1);
3080
- // Up offset
3081
- engine.Vector3.scale(up, localPositions.w - topLeftY, worldPosition2);
3082
- // Bottom-Left
3083
- engine.Vector3.add(worldPosition0, worldPosition2, worldPosition3);
3084
- // Bottom-Right
3085
- engine.Vector3.add(worldPosition1, worldPosition2, worldPosition2);
3086
- var vertices = subChunk.chunk.vertices;
3087
- for(var k = 0, o = subChunk.vertexArea.start + charRenderInfo.indexInChunk * 36; k < 4; ++k, o += 9){
3088
- worldPositions[k].copyToArray(vertices, o);
3089
- }
3090
- }
3091
- }
3092
- };
3093
- _proto._updateColor = function _updateColor() {
3094
- var _this__color = this._color, r = _this__color.r, g = _this__color.g, b = _this__color.b, a = _this__color.a;
3095
- var finalAlpha = a * this._getGlobalAlpha();
3096
- var textChunks = this._textChunks;
3097
- for(var i = 0, n = textChunks.length; i < n; ++i){
3098
- var subChunk = textChunks[i].subChunk;
3099
- var vertexArea = subChunk.vertexArea;
3100
- var vertexCount = vertexArea.size / 9;
3101
- var vertices = subChunk.chunk.vertices;
3102
- for(var j = 0, o = vertexArea.start + 5; j < vertexCount; ++j, o += 9){
3103
- vertices[o] = r;
3104
- vertices[o + 1] = g;
3105
- vertices[o + 2] = b;
3106
- vertices[o + 3] = finalAlpha;
3107
- }
3108
- }
3109
- };
3110
- _proto._updateLocalData = function _updateLocalData() {
3111
- var _this = this;
3112
- // @ts-ignore
3113
- var pixelsPerResolution = engine.Engine._pixelsPerUnit / this._getRootCanvas().referenceResolutionPerUnit;
3114
- var _this__localBounds = this._localBounds, min = _this__localBounds.min, max = _this__localBounds.max;
3115
- var charRenderInfos = Text._charRenderInfos;
3116
- var _this__transformEntity_transform = this._transformEntity.transform, size = _this__transformEntity_transform.size, pivot = _this__transformEntity_transform.pivot;
3117
- var rendererWidth = size.x;
3118
- var rendererHeight = size.y;
3119
- var offsetWidth = rendererWidth * (0.5 - pivot.x);
3120
- var offsetHeight = rendererHeight * (0.5 - pivot.y);
3121
- var fontSize = this._fontSize;
3122
- var textMetrics;
3123
- if (this._overflowMode === engine.OverflowMode.Shrink) {
3124
- var result = engine.TextUtils.measureTextWithShrink(this, rendererWidth * pixelsPerResolution, rendererHeight * pixelsPerResolution, this._fontSize, this._lineSpacing, this._characterSpacing, this.enableWrapping, function(sizeValue) {
3125
- return _this._applyFontSizeForShrink(sizeValue);
3126
- });
3127
- fontSize = result.fontSize;
3128
- textMetrics = result.metrics;
3129
- } else {
3130
- var characterSpacing = this._characterSpacing * fontSize;
3131
- textMetrics = this.enableWrapping ? engine.TextUtils.measureTextWithWrap(this, rendererWidth * pixelsPerResolution, rendererHeight * pixelsPerResolution, this._lineSpacing * fontSize, characterSpacing) : engine.TextUtils.measureTextWithoutWrap(this, rendererHeight * pixelsPerResolution, this._lineSpacing * fontSize, characterSpacing);
3132
- }
3133
- var charFont = this._getSubFont();
3134
- var characterSpacing1 = this._characterSpacing * fontSize;
3135
- var height = textMetrics.height, lines = textMetrics.lines, lineWidths = textMetrics.lineWidths, lineHeight = textMetrics.lineHeight, lineMaxSizes = textMetrics.lineMaxSizes;
3136
- // @ts-ignore
3137
- var charRenderInfoPool = this.engine._charRenderInfoPool;
3138
- var linesLen = lines.length;
3139
- var renderElementCount = 0;
3140
- if (linesLen > 0) {
3141
- var horizontalAlignment = this.horizontalAlignment;
3142
- var pixelsPerUnitReciprocal = 1.0 / pixelsPerResolution;
3143
- rendererWidth *= pixelsPerResolution;
3144
- rendererHeight *= pixelsPerResolution;
3145
- var halfRendererWidth = rendererWidth * 0.5;
3146
- var halfLineHeight = lineHeight * 0.5;
3147
- var startY = 0;
3148
- var topDiff = lineHeight * 0.5 - lineMaxSizes[0].ascent;
3149
- var bottomDiff = lineHeight * 0.5 - lineMaxSizes[linesLen - 1].descent - 1;
3150
- switch(this.verticalAlignment){
3151
- case engine.TextVerticalAlignment.Top:
3152
- startY = rendererHeight * 0.5 - halfLineHeight + topDiff;
3153
- break;
3154
- case engine.TextVerticalAlignment.Center:
3155
- // Center the text block (lineHeight * lineCount) within the renderer, independent of
3156
- // `height` — which equals the renderer height for Truncate/Shrink and would otherwise
3157
- // push the text upward by (rendererHeight - blockHeight) / 2 when the box is taller.
3158
- startY = lineHeight * linesLen * 0.5 - halfLineHeight - (bottomDiff - topDiff) * 0.5;
3159
- break;
3160
- case engine.TextVerticalAlignment.Bottom:
3161
- startY = height - rendererHeight * 0.5 - halfLineHeight - bottomDiff;
3162
- break;
3163
- }
3164
- var firstLine = -1;
3165
- var minX = Number.MAX_SAFE_INTEGER;
3166
- var minY = Number.MAX_SAFE_INTEGER;
3167
- var maxX = Number.MIN_SAFE_INTEGER;
3168
- var maxY = Number.MIN_SAFE_INTEGER;
3169
- for(var i = 0; i < linesLen; ++i){
3170
- var lineWidth = lineWidths[i];
3171
- if (lineWidth > 0) {
3172
- var line = lines[i];
3173
- var startX = 0;
3174
- var firstRow = -1;
3175
- if (firstLine < 0) {
3176
- firstLine = i;
3177
- }
3178
- switch(horizontalAlignment){
3179
- case engine.TextHorizontalAlignment.Left:
3180
- startX = -halfRendererWidth;
3181
- break;
3182
- case engine.TextHorizontalAlignment.Center:
3183
- startX = -lineWidth * 0.5;
3184
- break;
3185
- case engine.TextHorizontalAlignment.Right:
3186
- startX = halfRendererWidth - lineWidth;
3187
- break;
3188
- }
3189
- for(var j = 0, n = line.length; j < n; ++j){
3190
- var char = line[j];
3191
- var charInfo = charFont._getCharInfo(char);
3192
- if (charInfo.h > 0) {
3193
- firstRow < 0 && (firstRow = j);
3194
- var charRenderInfo = charRenderInfos[renderElementCount++] = charRenderInfoPool.get();
3195
- var localPositions = charRenderInfo.localPositions;
3196
- charRenderInfo.texture = charFont._getTextureByIndex(charInfo.index);
3197
- charRenderInfo.uvs = charInfo.uvs;
3198
- var w = charInfo.w, ascent = charInfo.ascent, descent = charInfo.descent;
3199
- var ow = this._outlineWidth * pixelsPerUnitReciprocal;
3200
- var left = (startX + offsetWidth) * pixelsPerUnitReciprocal - ow;
3201
- var right = (startX + w + offsetWidth) * pixelsPerUnitReciprocal + ow;
3202
- var top = (startY + ascent + offsetHeight) * pixelsPerUnitReciprocal + ow;
3203
- var bottom = (startY - descent + offsetHeight) * pixelsPerUnitReciprocal - ow;
3204
- localPositions.set(left, top, right, bottom);
3205
- i === firstLine && (maxY = Math.max(maxY, top));
3206
- minY = Math.min(minY, bottom);
3207
- j === firstRow && (minX = Math.min(minX, left));
3208
- maxX = Math.max(maxX, right);
3209
- }
3210
- startX += charInfo.xAdvance + characterSpacing1;
3211
- }
3212
- }
3213
- startY -= lineHeight;
3214
- }
3215
- if (firstLine < 0) {
3216
- min.set(0, 0, 0);
3217
- max.set(0, 0, 0);
3218
- } else {
3219
- min.set(minX, minY, 0);
3220
- max.set(maxX, maxY, 0);
3221
- }
3222
- } else {
3223
- min.set(0, 0, 0);
3224
- max.set(0, 0, 0);
3225
- }
3226
- charFont._getLastIndex() > 0 && charRenderInfos.sort(function(a, b) {
3227
- return a.texture.instanceId - b.texture.instanceId;
3228
- });
3229
- this._freeTextChunks();
3230
- if (renderElementCount === 0) {
3231
- return;
3232
- }
3233
- var textChunks = this._textChunks;
3234
- var curTextChunk = new TextChunk();
3235
- textChunks.push(curTextChunk);
3236
- var chunkMaxVertexCount = this._getChunkManager().maxVertexCount;
3237
- var curCharRenderInfo = charRenderInfos[0];
3238
- var curTexture = curCharRenderInfo.texture;
3239
- curTextChunk.texture = curTexture;
3240
- var curCharInfos = curTextChunk.charRenderInfos;
3241
- curCharInfos.push(curCharRenderInfo);
3242
- for(var i1 = 1; i1 < renderElementCount; ++i1){
3243
- var charRenderInfo1 = charRenderInfos[i1];
3244
- var texture = charRenderInfo1.texture;
3245
- if (curTexture !== texture || curCharInfos.length * 4 + 4 > chunkMaxVertexCount) {
3246
- this._buildChunk(curTextChunk, curCharInfos.length);
3247
- curTextChunk = new TextChunk();
3248
- textChunks.push(curTextChunk);
3249
- curTexture = texture;
3250
- curTextChunk.texture = texture;
3251
- curCharInfos = curTextChunk.charRenderInfos;
3252
- }
3253
- curCharInfos.push(charRenderInfo1);
3254
- }
3255
- var charLength = curCharInfos.length;
3256
- if (charLength > 0) {
3257
- this._buildChunk(curTextChunk, charLength);
3258
- }
3259
- charRenderInfos.length = 0;
3260
- };
3261
- _proto._onTransformChanged = function _onTransformChanged(type) {
3262
- if (type & UITransformModifyFlags.Size || type & UITransformModifyFlags.Pivot) {
3263
- this._dirtyUpdateFlag |= 8;
3264
- }
3265
- UIRenderer1.prototype._onTransformChanged.call(this, type);
3266
- this._setDirtyFlagTrue(16);
3267
- };
3268
- _proto._isTextNoVisible = function _isTextNoVisible() {
3269
- var size = this._transformEntity.transform.size;
3270
- return !this._font || this._text === "" || this._fontSize === 0 || this.enableWrapping && size.x <= 0 || (this.overflowMode === engine.OverflowMode.Truncate || this.overflowMode === engine.OverflowMode.Shrink) && size.y <= 0 || !this._getRootCanvas();
3271
- };
3272
- _proto._buildChunk = function _buildChunk(textChunk, count) {
3273
- var _this_color = this.color, r = _this_color.r, g = _this_color.g, b = _this_color.b, a = _this_color.a;
3274
- var finalAlpha = a * this._getGlobalAlpha();
3275
- var tempIndices = engine.CharRenderInfo.triangles;
3276
- var tempIndicesLength = tempIndices.length;
3277
- var subChunk = textChunk.subChunk = this._getChunkManager().allocateSubChunk(count * 4);
3278
- var vertices = subChunk.chunk.vertices;
3279
- var indices = subChunk.indices = [];
3280
- var charRenderInfos = textChunk.charRenderInfos;
3281
- var ow = this._outlineWidth;
3282
- var texture = textChunk.texture;
3283
- var owU = ow > 0 ? ow / texture.width : 0;
3284
- var owV = ow > 0 ? ow / texture.height : 0;
3285
- for(var i = 0, ii = 0, io = 0, vo = subChunk.vertexArea.start + 3; i < count; ++i, io += 4){
3286
- var charRenderInfo = charRenderInfos[i];
3287
- charRenderInfo.indexInChunk = i;
3288
- // Set indices
3289
- for(var j = 0; j < tempIndicesLength; ++j){
3290
- indices[ii++] = tempIndices[j] + io;
3291
- }
3292
- // Set uv and color for vertices, expand uv outward by outline width
3293
- for(var j1 = 0; j1 < 4; ++j1, vo += 9){
3294
- var uv = charRenderInfo.uvs[j1];
3295
- var su = j1 === 1 || j1 === 2 ? 1 : -1;
3296
- var sv = j1 >= 2 ? 1 : -1;
3297
- vertices[vo] = uv.x + owU * su;
3298
- vertices[vo + 1] = uv.y + owV * sv;
3299
- vertices[vo + 2] = r;
3300
- vertices[vo + 3] = g;
3301
- vertices[vo + 4] = b;
3302
- vertices[vo + 5] = finalAlpha;
3303
- }
3304
- }
3305
- return subChunk;
3306
- };
3307
- _proto._freeTextChunks = function _freeTextChunks() {
3308
- var textChunks = this._textChunks;
3309
- // @ts-ignore
3310
- var charRenderInfoPool = this.engine._charRenderInfoPool;
3311
- var manager = this._getChunkManager();
3312
- for(var i = 0, n = textChunks.length; i < n; ++i){
3313
- var textChunk = textChunks[i];
3314
- var charRenderInfos = textChunk.charRenderInfos;
3315
- for(var j = 0, m = charRenderInfos.length; j < m; ++j){
3316
- charRenderInfoPool.return(charRenderInfos[j]);
3317
- }
3318
- charRenderInfos.length = 0;
3319
- manager.freeSubChunk(textChunk.subChunk);
3320
- textChunk.subChunk = null;
3321
- textChunk.texture = null;
3322
- }
3323
- textChunks.length = 0;
3324
- };
3325
- _proto._onOutlineColorChanged = function _onOutlineColorChanged() {
3326
- this.shaderData.setColor(Text._outlineColorProperty, this._outlineColor);
3327
- };
3328
- _create_class(Text, [
3329
- {
3330
- key: "text",
3331
- get: /**
3332
- * Rendering string for the Text.
3333
- */ function get() {
3334
- return this._text;
3335
- },
3336
- set: function set(value) {
3337
- value = value || "";
3338
- if (this._text !== value) {
3339
- this._text = value;
3340
- this._setDirtyFlagTrue(25);
3341
- }
3342
- }
3343
- },
3344
- {
3345
- key: "font",
3346
- get: /**
3347
- * The font of the Text.
3348
- */ function get() {
3349
- return this._font;
3350
- },
3351
- set: function set(value) {
3352
- var lastFont = this._font;
3353
- if (lastFont !== value) {
3354
- lastFont && this._addResourceReferCount(lastFont, -1);
3355
- value && this._addResourceReferCount(value, 1);
3356
- this._font = value;
3357
- this._setDirtyFlagTrue(29);
3358
- }
3359
- }
3360
- },
3361
- {
3362
- key: "fontSize",
3363
- get: /**
3364
- * The font size of the Text.
3365
- */ function get() {
3366
- return this._fontSize;
3367
- },
3368
- set: function set(value) {
3369
- if (this._fontSize !== value) {
3370
- this._fontSize = value;
3371
- this._setDirtyFlagTrue(29);
3372
- }
3373
- }
3374
- },
3375
- {
3376
- key: "fontStyle",
3377
- get: /**
3378
- * The style of the font.
3379
- */ function get() {
3380
- return this._fontStyle;
3381
- },
3382
- set: function set(value) {
3383
- if (this.fontStyle !== value) {
3384
- this._fontStyle = value;
3385
- this._setDirtyFlagTrue(29);
3386
- }
3387
- }
3388
- },
3389
- {
3390
- key: "lineSpacing",
3391
- get: /**
3392
- * The space between two lines, in em (ratio of fontSize).
3393
- */ function get() {
3394
- return this._lineSpacing;
3395
- },
3396
- set: function set(value) {
3397
- if (this._lineSpacing !== value) {
3398
- this._lineSpacing = value;
3399
- this._setDirtyFlagTrue(25);
3400
- }
3401
- }
3402
- },
3403
- {
3404
- key: "characterSpacing",
3405
- get: /**
3406
- * The space between two characters, in em (ratio of fontSize).
3407
- */ function get() {
3408
- return this._characterSpacing;
3409
- },
3410
- set: function set(value) {
3411
- if (this._characterSpacing !== value) {
3412
- this._characterSpacing = value;
3413
- this._setDirtyFlagTrue(25);
3414
- }
3415
- }
3416
- },
3417
- {
3418
- key: "horizontalAlignment",
3419
- get: /**
3420
- * The horizontal alignment.
3421
- */ function get() {
3422
- return this._horizontalAlignment;
3423
- },
3424
- set: function set(value) {
3425
- if (this._horizontalAlignment !== value) {
3426
- this._horizontalAlignment = value;
3427
- this._setDirtyFlagTrue(25);
3428
- }
3429
- }
3430
- },
3431
- {
3432
- key: "verticalAlignment",
3433
- get: /**
3434
- * The vertical alignment.
3435
- */ function get() {
3436
- return this._verticalAlignment;
3437
- },
3438
- set: function set(value) {
3439
- if (this._verticalAlignment !== value) {
3440
- this._verticalAlignment = value;
3441
- this._setDirtyFlagTrue(25);
3442
- }
3443
- }
3444
- },
3445
- {
3446
- key: "enableWrapping",
3447
- get: /**
3448
- * Whether wrap text to next line when exceeds the width of the container.
3449
- */ function get() {
3450
- return this._enableWrapping;
3451
- },
3452
- set: function set(value) {
3453
- if (this._enableWrapping !== value) {
3454
- this._enableWrapping = value;
3455
- this._setDirtyFlagTrue(25);
3456
- }
3457
- }
3458
- },
3459
- {
3460
- key: "overflowMode",
3461
- get: /**
3462
- * The overflow mode.
3463
- */ function get() {
3464
- return this._overflowMode;
3465
- },
3466
- set: function set(value) {
3467
- if (this._overflowMode !== value) {
3468
- this._overflowMode = value;
3469
- this._setDirtyFlagTrue(25);
3470
- }
3471
- }
3472
- },
3473
- {
3474
- key: "outlineWidth",
3475
- get: /**
3476
- * The outline width in pixels. 0 means outline is disabled. Clamped to [0, 8].
3477
- */ function get() {
3478
- return this._outlineWidth;
3479
- },
3480
- set: function set(value) {
3481
- value = Math.max(0, Math.min(value, 3));
3482
- if (this._outlineWidth !== value) {
3483
- this._outlineWidth = value;
3484
- this.shaderData.setFloat(Text._outlineWidthProperty, value);
3485
- this._setDirtyFlagTrue(25);
3486
- }
3487
- }
3488
- },
3489
- {
3490
- key: "outlineColor",
3491
- get: /**
3492
- * The outline color. Only effective when outlineWidth > 0.
3493
- */ function get() {
3494
- return this._outlineColor;
3495
- },
3496
- set: function set(value) {
3497
- if (this._outlineColor !== value) {
3498
- this._outlineColor.copyFrom(value);
3499
- }
3500
- }
3501
- },
3502
- {
3503
- key: "bounds",
3504
- get: /**
3505
- * The bounding volume of the TextRenderer.
3506
- */ function get() {
3507
- if (this._isTextNoVisible()) {
3508
- if (this._isContainDirtyFlag(engine.RendererUpdateFlags.WorldVolume)) {
3509
- var localBounds = this._localBounds;
3510
- if (this._getRootCanvas()) {
3511
- localBounds.min.set(0, 0, 0);
3512
- localBounds.max.set(0, 0, 0);
3513
- } else {
3514
- var _this_entity_transform = this.entity.transform, size = _this_entity_transform.size, pivot = _this_entity_transform.pivot;
3515
- localBounds.min.set(-size.x * pivot.x, -size.y * pivot.y, 0);
3516
- localBounds.max.set(size.x * (1 - pivot.x), size.y * (1 - pivot.y), 0);
3517
- }
3518
- this._updateBounds(this._bounds);
3519
- this._setDirtyFlagFalse(engine.RendererUpdateFlags.WorldVolume);
3520
- }
3521
- return this._bounds;
3522
- }
3523
- this._isContainDirtyFlag(4) && this._resetSubFont();
3524
- this._isContainDirtyFlag(8) && this._updateLocalData();
3525
- this._isContainDirtyFlag(16) && this._updatePosition();
3526
- this._isContainDirtyFlag(engine.RendererUpdateFlags.WorldVolume) && this._updateBounds(this._bounds);
3527
- this._setDirtyFlagFalse(29);
3528
- return this._bounds;
3529
- }
3530
- }
3531
- ]);
3532
- return Text;
3533
- }(exports.UIRenderer);
3534
- Text._textTextureProperty = engine.ShaderProperty.getByName("renderElement_TextTexture");
3535
- Text._textTextureSizeProperty = engine.ShaderProperty.getByName("renderElement_TextTextureSize");
3536
- Text._outlineColorProperty = engine.ShaderProperty.getByName("renderer_OutlineColor");
3537
- Text._outlineWidthProperty = engine.ShaderProperty.getByName("renderer_OutlineWidth");
3538
- Text._worldPositions = [
3539
- new engine.Vector3(),
3540
- new engine.Vector3(),
3541
- new engine.Vector3(),
3542
- new engine.Vector3()
3543
- ];
3544
- Text._charRenderInfos = [];
3545
- __decorate([
3546
- engine.ignoreClone
3547
- ], Text.prototype, "_textChunks", void 0);
3548
- __decorate([
3549
- engine.ignoreClone
3550
- ], Text.prototype, "_subFont", void 0);
3551
- __decorate([
3552
- engine.ignoreClone
3553
- ], Text.prototype, "_localBounds", void 0);
3554
- __decorate([
3555
- engine.ignoreClone
3556
- ], Text.prototype, "_onTransformChanged", null);
3557
- __decorate([
3558
- engine.ignoreClone
3559
- ], Text.prototype, "_onOutlineColorChanged", null);
3560
- var TextChunk = function TextChunk() {
3561
- this.charRenderInfos = new Array();
3562
- };
3563
-
3564
- /**
3565
- * The transition behavior of UIInteractive.
3566
- */ var Transition = /*#__PURE__*/ function(DataObject) {
3567
- _inherits(Transition, DataObject);
3568
- function Transition() {
3569
- var _this;
3570
- _this = DataObject.apply(this, arguments) || this, _this._duration = 0, _this._countDown = 0, _this._finalState = InteractiveState.Normal;
3571
- return _this;
3572
- }
3573
- var _proto = Transition.prototype;
3574
- _proto.destroy = function destroy() {
3575
- var _this__interactive;
3576
- (_this__interactive = this._interactive) == null ? void 0 : _this__interactive.removeTransition(this);
3577
- this._addStateValuesReferCount(-1);
3578
- this._normal = this._pressed = this._hover = this._disabled = null;
3579
- this._initialValue = this._currentValue = this._finalValue = null;
3580
- this._target = null;
3581
- };
3582
- /**
3583
- * @internal
3584
- */ _proto._cloneTo = function _cloneTo(target) {
3585
- target._addStateValuesReferCount(1);
3586
- };
3587
- /**
3588
- * @internal
3589
- */ _proto._setState = function _setState(state, instant) {
3590
- this._finalState = state;
3591
- var value = this._getValueByState(state);
3592
- if (instant) {
3593
- this._countDown = 0;
3594
- this._initialValue = this._finalValue = value;
3595
- } else {
3596
- this._countDown = this._duration;
3597
- this._initialValue = this._getTargetValueCopy();
3598
- this._finalValue = value;
3599
- }
3600
- this._updateValue();
3601
- };
3602
- /**
3603
- * @internal
3604
- */ _proto._onUpdate = function _onUpdate(delta) {
3605
- if (this._countDown > 0) {
3606
- this._countDown -= delta;
3607
- this._updateValue();
3608
- }
3609
- };
3610
- _proto._onStateValueDirty = function _onStateValueDirty(state, preValue, curValue) {
3611
- // @ts-ignore
3612
- _instanceof(preValue, engine.ReferResource) && preValue._addReferCount(-1);
3613
- // @ts-ignore
3614
- _instanceof(curValue, engine.ReferResource) && curValue._addReferCount(1);
3615
- if (this._finalState === state) {
3616
- this._finalValue = curValue;
3617
- this._updateValue();
3618
- }
3619
- };
3620
- _proto._updateValue = function _updateValue() {
3621
- var _this__target;
3622
- var weight = this._duration ? 1 - this._countDown / this._duration : 1;
3623
- this._updateCurrentValue(this._initialValue, this._finalValue, weight);
3624
- ((_this__target = this._target) == null ? void 0 : _this__target.enabled) && this._applyValue(this._currentValue);
3625
- };
3626
- _proto._addStateValuesReferCount = function _addStateValuesReferCount(count) {
3627
- var _this = this, _normal = _this._normal, _pressed = _this._pressed, _hover = _this._hover, _disabled = _this._disabled;
3628
- // @ts-ignore
3629
- _instanceof(_normal, engine.ReferResource) && _normal._addReferCount(count);
3630
- // @ts-ignore
3631
- _instanceof(_pressed, engine.ReferResource) && _pressed._addReferCount(count);
3632
- // @ts-ignore
3633
- _instanceof(_hover, engine.ReferResource) && _hover._addReferCount(count);
3634
- // @ts-ignore
3635
- _instanceof(_disabled, engine.ReferResource) && _disabled._addReferCount(count);
3636
- };
3637
- _proto._getValueByState = function _getValueByState(state) {
3638
- switch(state){
3639
- case InteractiveState.Normal:
3640
- return this.normal;
3641
- case InteractiveState.Pressed:
3642
- return this.pressed;
3643
- case InteractiveState.Hover:
3644
- return this.hover;
3645
- case InteractiveState.Disable:
3646
- return this.disabled;
3647
- }
3648
- };
3649
- _create_class(Transition, [
3650
- {
3651
- key: "normal",
3652
- get: /**
3653
- * The normal state of the transition.
3654
- */ function get() {
3655
- return this._normal;
3656
- },
3657
- set: function set(value) {
3658
- var preNormal = this._normal;
3659
- if (preNormal !== value) {
3660
- this._normal = value;
3661
- this._onStateValueDirty(InteractiveState.Normal, preNormal, value);
3662
- }
3663
- }
3664
- },
3665
- {
3666
- key: "pressed",
3667
- get: /**
3668
- * The pressed state of the transition.
3669
- */ function get() {
3670
- return this._pressed;
3671
- },
3672
- set: function set(value) {
3673
- var prePressed = this._pressed;
3674
- if (prePressed !== value) {
3675
- this._pressed = value;
3676
- this._onStateValueDirty(InteractiveState.Pressed, prePressed, value);
3677
- }
3678
- }
3679
- },
3680
- {
3681
- key: "hover",
3682
- get: /**
3683
- * The hover state of the transition.
3684
- */ function get() {
3685
- return this._hover;
3686
- },
3687
- set: function set(value) {
3688
- var preHover = this._hover;
3689
- if (preHover !== value) {
3690
- this._hover = value;
3691
- this._onStateValueDirty(InteractiveState.Hover, preHover, value);
3692
- }
3693
- }
3694
- },
3695
- {
3696
- key: "disabled",
3697
- get: /**
3698
- * The disabled state of the transition.
3699
- */ function get() {
3700
- return this._disabled;
3701
- },
3702
- set: function set(value) {
3703
- var preDisabled = this._disabled;
3704
- if (preDisabled !== value) {
3705
- this._disabled = value;
3706
- this._onStateValueDirty(InteractiveState.Disable, preDisabled, value);
3707
- }
3708
- }
3709
- },
3710
- {
3711
- key: "target",
3712
- get: /**
3713
- * The target of the transition.
3714
- */ function get() {
3715
- return this._target;
3716
- },
3717
- set: function set(value) {
3718
- if (this._target !== value) {
3719
- this._target = value;
3720
- (value == null ? void 0 : value.enabled) && this._applyValue(this._currentValue);
3721
- }
3722
- }
3723
- },
3724
- {
3725
- key: "duration",
3726
- get: /**
3727
- * The duration of the transition.
3728
- */ function get() {
3729
- return this._duration;
3730
- },
3731
- set: function set(value) {
3732
- if (value < 0) value = 0;
3733
- var preDuration = this._duration;
3734
- if (preDuration !== value) {
3735
- this._duration = value;
3736
- if (this._countDown > 0) {
3737
- this._countDown = value * (1 - this._countDown / preDuration);
3738
- this._updateValue();
3739
- }
3740
- }
3741
- }
3742
- }
3743
- ]);
3744
- return Transition;
3745
- }(engine.DataObject);
3746
- __decorate([
3747
- engine.ignoreClone
3748
- ], Transition.prototype, "_countDown", void 0);
3749
- __decorate([
3750
- engine.ignoreClone
3751
- ], Transition.prototype, "_initialValue", void 0);
3752
- __decorate([
3753
- engine.ignoreClone
3754
- ], Transition.prototype, "_finalValue", void 0);
3755
- __decorate([
3756
- engine.ignoreClone
3757
- ], Transition.prototype, "_currentValue", void 0);
3758
- __decorate([
3759
- engine.ignoreClone
3760
- ], Transition.prototype, "_finalState", void 0);
3761
-
3762
- /**
3763
- * Color transition.
3764
- */ var ColorTransition = /*#__PURE__*/ function(Transition) {
3765
- _inherits(ColorTransition, Transition);
3766
- function ColorTransition() {
3767
- var _this;
3768
- _this = Transition.call(this) || this, _this._color = new engine.Color();
3769
- _this._normal = new engine.Color(1, 1, 1, 1);
3770
- _this._hover = new engine.Color(0.9130986517934192, 0.9130986517934192, 0.9130986517934192, 1);
3771
- _this._pressed = new engine.Color(0.5775804404296506, 0.5775804404296506, 0.5775804404296506, 1);
3772
- _this._disabled = new engine.Color(0.5775804404296506, 0.5775804404296506, 0.5775804404296506, 1);
3773
- _this._duration = 0.1;
3774
- _this._currentValue = new engine.Color();
3775
- _this._onNormalValueChanged = _this._onNormalValueChanged.bind(_this);
3776
- _this._onHoverValueChanged = _this._onHoverValueChanged.bind(_this);
3777
- _this._onPressedValueChanged = _this._onPressedValueChanged.bind(_this);
3778
- _this._onDisabledValueChanged = _this._onDisabledValueChanged.bind(_this);
3779
- // @ts-ignore
3780
- _this._normal._onValueChanged = _this._onNormalValueChanged;
3781
- // @ts-ignore
3782
- _this._hover._onValueChanged = _this._onHoverValueChanged;
3783
- // @ts-ignore
3784
- _this._pressed._onValueChanged = _this._onPressedValueChanged;
3785
- // @ts-ignore
3786
- _this._disabled._onValueChanged = _this._onDisabledValueChanged;
3787
- return _this;
3788
- }
3789
- var _proto = ColorTransition.prototype;
3790
- _proto._onNormalValueChanged = function _onNormalValueChanged() {
3791
- if (this._finalState === InteractiveState.Normal) {
3792
- this._finalValue = this._normal;
3793
- this._updateValue();
3794
- }
3795
- };
3796
- _proto._onHoverValueChanged = function _onHoverValueChanged() {
3797
- if (this._finalState === InteractiveState.Hover) {
3798
- this._finalValue = this._hover;
3799
- this._updateValue();
3800
- }
3801
- };
3802
- _proto._onPressedValueChanged = function _onPressedValueChanged() {
3803
- if (this._finalState === InteractiveState.Pressed) {
3804
- this._finalValue = this._pressed;
3805
- this._updateValue();
3806
- }
3807
- };
3808
- _proto._onDisabledValueChanged = function _onDisabledValueChanged() {
3809
- if (this._finalState === InteractiveState.Disable) {
3810
- this._finalValue = this._disabled;
3811
- this._updateValue();
3812
- }
3813
- };
3814
- _proto._getTargetValueCopy = function _getTargetValueCopy() {
3815
- var _this__target;
3816
- var color = this._color;
3817
- color.copyFrom(((_this__target = this._target) == null ? void 0 : _this__target.color) || this._normal);
3818
- return color;
3819
- };
3820
- _proto._updateCurrentValue = function _updateCurrentValue(srcValue, destValue, weight) {
3821
- if (weight >= 1) {
3822
- this._currentValue.copyFrom(destValue);
3823
- } else {
3824
- engine.Color.lerp(srcValue, destValue, weight, this._currentValue);
3825
- }
3826
- };
3827
- _proto._applyValue = function _applyValue(value) {
3828
- this._target.color = value;
3829
- };
3830
- return ColorTransition;
3831
- }(Transition);
3832
-
3833
- /**
3834
- * Scale transition.
3835
- */ var ScaleTransition = /*#__PURE__*/ function(Transition) {
3836
- _inherits(ScaleTransition, Transition);
3837
- function ScaleTransition() {
3838
- var _this;
3839
- _this = Transition.call(this) || this;
3840
- _this._normal = 1;
3841
- _this._hover = 1;
3842
- _this._pressed = 1.2;
3843
- _this._disabled = 1;
3844
- _this._duration = 0.1;
3845
- return _this;
3846
- }
3847
- var _proto = ScaleTransition.prototype;
3848
- _proto._getTargetValueCopy = function _getTargetValueCopy() {
3849
- var _this__target;
3850
- return ((_this__target = this._target) == null ? void 0 : _this__target.entity.transform.scale.x) || this._normal;
3851
- };
3852
- _proto._updateCurrentValue = function _updateCurrentValue(srcValue, destValue, weight) {
3853
- this._currentValue = weight >= 1 ? destValue : (destValue - srcValue) * weight + srcValue;
3854
- };
3855
- _proto._applyValue = function _applyValue(value) {
3856
- this._target.entity.transform.setScale(value, value, value);
3857
- };
3858
- return ScaleTransition;
3859
- }(Transition);
3860
-
3861
- /**
3862
- * Sprite transition.
3863
- */ var SpriteTransition = /*#__PURE__*/ function(Transition) {
3864
- _inherits(SpriteTransition, Transition);
3865
- function SpriteTransition() {
3866
- return Transition.apply(this, arguments) || this;
3867
- }
3868
- var _proto = SpriteTransition.prototype;
3869
- _proto._getTargetValueCopy = function _getTargetValueCopy() {
3870
- var _this__target;
3871
- return (_this__target = this._target) == null ? void 0 : _this__target.sprite;
3872
- };
3873
- _proto._updateCurrentValue = function _updateCurrentValue(srcValue, destValue, weight) {
3874
- this._currentValue = weight >= 1 ? destValue : srcValue;
3875
- };
3876
- _proto._applyValue = function _applyValue(value) {
3877
- this._target.sprite = value;
3878
- };
3879
- return SpriteTransition;
3880
- }(Transition);
3881
-
3882
- var GUIComponent = /*#__PURE__*/Object.freeze({
3883
- __proto__: null,
3884
- Button: Button,
3885
- Image: Image,
3886
- Mask: Mask,
3887
- get RectMask2D () { return exports.RectMask2D; },
3888
- Text: Text,
3889
- ColorTransition: ColorTransition,
3890
- ScaleTransition: ScaleTransition,
3891
- SpriteTransition: SpriteTransition,
3892
- Transition: Transition,
3893
- get UICanvas () { return exports.UICanvas; },
3894
- UIGroup: UIGroup,
3895
- get UIRenderer () { return exports.UIRenderer; },
3896
- UITransform: UITransform
3897
- });
3898
-
3899
- /**
3900
- * @internal
3901
- */ var UIHitResult = function UIHitResult() {
3902
- this.entity = null;
3903
- this.distance = 0;
3904
- this.point = new engine.Vector3();
3905
- this.normal = new engine.Vector3();
3906
- this.component = null;
3907
- };
3908
-
3909
- exports.UIPointerEventEmitter = /*#__PURE__*/ function(PointerEventEmitter1) {
3910
- _inherits(UIPointerEventEmitter, PointerEventEmitter1);
3911
- function UIPointerEventEmitter() {
3912
- var _this;
3913
- _this = PointerEventEmitter1.apply(this, arguments) || this, _this._enteredPath = [], _this._pressedPath = [], _this._draggedPath = [];
3914
- return _this;
3915
- }
3916
- var _proto = UIPointerEventEmitter.prototype;
3917
- _proto._init = function _init() {
3918
- this._hitResult = new UIHitResult();
3919
- };
3920
- _proto.processRaycast = function processRaycast(scenes, pointer) {
3921
- var ray = engine.PointerEventEmitter._tempRay;
3922
- var hitResult = this._hitResult;
3923
- var position = pointer.position;
3924
- var x = position.x, y = position.y;
3925
- for(var i = scenes.length - 1; i >= 0; i--){
3926
- var scene = scenes[i];
3927
- if (!scene.isActive || scene.destroyed) continue;
3928
- // @ts-ignore
3929
- var componentsManager = scene._componentsManager;
3930
- // Overlay Canvas
3931
- var canvasElements = componentsManager._overlayCanvases;
3932
- // Screen to world ( Assume that world units have a one-to-one relationship with pixel units )
3933
- ray.origin.set(position.x, scene.engine.canvas.height - position.y, 1);
3934
- ray.direction.set(0, 0, -1);
3935
- for(var j = canvasElements.length - 1; j >= 0; j--){
3936
- if (canvasElements.get(j)._raycast(ray, hitResult)) {
3937
- this._updateRaycast(hitResult.component, pointer);
3938
- return;
3939
- }
3940
- }
3941
- var cameras = componentsManager._activeCameras;
3942
- for(var j1 = cameras.length - 1; j1 >= 0; j1--){
3943
- var camera = cameras.get(j1);
3944
- if (camera.renderTarget) continue;
3945
- var pixelViewport = camera.pixelViewport;
3946
- if (x < pixelViewport.x || y < pixelViewport.y || x > pixelViewport.x + pixelViewport.width || y > pixelViewport.y + pixelViewport.height) {
3947
- continue;
3948
- }
3949
- camera.screenPointToRay(pointer.position, ray);
3950
- // Other canvases
3951
- var isOrthographic = camera.isOrthographic;
3952
- var _camera_entity_transform = camera.entity.transform, cameraPosition = _camera_entity_transform.worldPosition, cameraForward = _camera_entity_transform.worldForward;
3953
- // Sort by rendering order
3954
- canvasElements = componentsManager._canvases;
3955
- for(var k = 0, n = canvasElements.length; k < n; k++){
3956
- canvasElements.get(k)._updateSortDistance(isOrthographic, cameraPosition, cameraForward);
3957
- }
3958
- canvasElements.sort(function(a, b) {
3959
- return a.sortOrder - b.sortOrder || a._sortDistance - b._sortDistance;
3960
- });
3961
- for(var k1 = 0, n1 = canvasElements.length; k1 < n1; k1++){
3962
- canvasElements.get(k1)._canvasIndex = k1;
3963
- }
3964
- var farClipPlane = camera.farClipPlane;
3965
- // Post-rendering first detection
3966
- for(var k2 = 0, n2 = canvasElements.length; k2 < n2; k2++){
3967
- var canvas = canvasElements.get(k2);
3968
- if (!canvas._canDispatchEvent(camera)) continue;
3969
- if (canvas._raycast(ray, hitResult, farClipPlane)) {
3970
- this._updateRaycast(hitResult.component, pointer);
3971
- return;
3972
- }
3973
- }
3974
- if (camera.clearFlags & engine.CameraClearFlags.Color) {
3975
- this._updateRaycast(null, pointer);
3976
- return;
3977
- }
3978
- }
3979
- this._updateRaycast(null, pointer);
3980
- }
3981
- };
3982
- _proto.processDrag = function processDrag(pointer) {
3983
- var draggedPath = this._draggedPath;
3984
- if (draggedPath.length > 0) {
3985
- this._bubble(draggedPath, pointer, this._fireDrag);
3986
- }
3987
- };
3988
- _proto.processDown = function processDown(pointer) {
3989
- var enteredPath = this._enteredPath;
3990
- var pressedPath = this._pressedPath;
3991
- var draggedPath = this._draggedPath;
3992
- var length = draggedPath.length = pressedPath.length = enteredPath.length;
3993
- if (length > 0) {
3994
- for(var i = 0; i < length; i++){
3995
- pressedPath[i] = draggedPath[i] = enteredPath[i];
3996
- }
3997
- this._bubble(pressedPath, pointer, this._fireDown);
3998
- this._bubble(draggedPath, pointer, this._fireBeginDrag);
3999
- }
4000
- };
4001
- _proto.processUp = function processUp(pointer) {
4002
- var enteredPath = this._enteredPath;
4003
- var pressedPath = this._pressedPath;
4004
- if (enteredPath.length > 0) {
4005
- this._bubble(enteredPath, pointer, this._fireUp);
4006
- if (pressedPath.length > 0) {
4007
- var common = UIPointerEventEmitter._tempArray0;
4008
- if (this._findCommonInPath(enteredPath, pressedPath, common)) {
4009
- this._bubble(common, pointer, this._fireClick);
4010
- common.length = 0;
4011
- }
4012
- }
4013
- }
4014
- pressedPath.length = 0;
4015
- var draggedPath = this._draggedPath;
4016
- if (draggedPath.length > 0) {
4017
- this._bubble(draggedPath, pointer, this._fireEndDrag);
4018
- draggedPath.length = 0;
4019
- }
4020
- if (enteredPath.length > 0) {
4021
- this._bubble(enteredPath, pointer, this._fireDrop);
4022
- }
4023
- };
4024
- _proto.processLeave = function processLeave(pointer) {
4025
- var enteredPath = this._enteredPath;
4026
- if (enteredPath.length > 0) {
4027
- this._bubble(enteredPath, pointer, this._fireExit);
4028
- enteredPath.length = 0;
4029
- }
4030
- var draggedPath = this._draggedPath;
4031
- if (draggedPath.length > 0) {
4032
- this._bubble(draggedPath, pointer, this._fireEndDrag);
4033
- draggedPath.length = 0;
4034
- }
4035
- this._pressedPath.length = 0;
4036
- };
4037
- _proto.dispose = function dispose() {
4038
- this._enteredPath.length = this._pressedPath.length = this._draggedPath.length = 0;
4039
- };
4040
- _proto._updateRaycast = function _updateRaycast(element, pointer) {
4041
- var enteredPath = this._enteredPath;
4042
- var curPath = this._composedPath(element, UIPointerEventEmitter._path);
4043
- var add = UIPointerEventEmitter._tempArray0;
4044
- var del = UIPointerEventEmitter._tempArray1;
4045
- if (this._findDiffInPath(enteredPath, curPath, add, del)) {
4046
- for(var i = 0, n = add.length; i < n; i++){
4047
- this._fireEnter(add[i], this._createEventData(pointer, add[i]));
4048
- }
4049
- for(var i1 = 0, n1 = del.length; i1 < n1; i1++){
4050
- this._fireExit(del[i1], this._createEventData(pointer, del[i1]));
4051
- }
4052
- var length = enteredPath.length = curPath.length;
4053
- for(var i2 = 0; i2 < length; i2++){
4054
- enteredPath[i2] = curPath[i2];
4055
- }
4056
- add.length = del.length = 0;
4057
- }
4058
- curPath.length = 0;
4059
- };
4060
- _proto._composedPath = function _composedPath(element, path) {
4061
- if (!element) {
4062
- path.length = 0;
4063
- return path;
4064
- }
4065
- var entity = path[0] = element.entity;
4066
- var i = 1;
4067
- var rootEntity = element._getRootCanvas().entity;
4068
- for(; i < UIPointerEventEmitter._MAX_PATH_DEPTH && !!entity && entity !== rootEntity; i++){
4069
- entity = path[i] = entity.parent;
4070
- }
4071
- path.length = i;
4072
- return path;
4073
- };
4074
- _proto._findCommonInPath = function _findCommonInPath(prePath, curPath, common) {
4075
- var idSet = UIPointerEventEmitter._tempSet;
4076
- idSet.clear();
4077
- for(var i = 0, n = prePath.length; i < n; i++){
4078
- idSet.add(prePath[i].instanceId);
4079
- }
4080
- var hasCommon = false;
4081
- for(var i1 = 0, n1 = curPath.length; i1 < n1; i1++){
4082
- var entity = curPath[i1];
4083
- if (idSet.has(entity.instanceId)) {
4084
- common.push(entity);
4085
- hasCommon = true;
4086
- }
4087
- }
4088
- return hasCommon;
4089
- };
4090
- _proto._findDiffInPath = function _findDiffInPath(prePath, curPath, add, del) {
4091
- var idSet = UIPointerEventEmitter._tempSet;
4092
- idSet.clear();
4093
- var changed = false;
4094
- for(var i = 0, n = prePath.length; i < n; i++){
4095
- idSet.add(prePath[i].instanceId);
4096
- }
4097
- for(var i1 = 0, n1 = curPath.length; i1 < n1; i1++){
4098
- var entity = curPath[i1];
4099
- if (!idSet.has(entity.instanceId)) {
4100
- add.push(entity);
4101
- changed = true;
4102
- }
4103
- }
4104
- idSet.clear();
4105
- for(var i2 = 0, n2 = curPath.length; i2 < n2; i2++){
4106
- idSet.add(curPath[i2].instanceId);
4107
- }
4108
- for(var i3 = 0, n3 = prePath.length; i3 < n3; i3++){
4109
- var entity1 = prePath[i3];
4110
- if (!idSet.has(entity1.instanceId)) {
4111
- del.push(entity1);
4112
- changed = true;
4113
- }
4114
- }
4115
- return changed;
4116
- };
4117
- _proto._bubble = function _bubble(path, pointer, fireEvent) {
4118
- var length = path.length;
4119
- if (length <= 0) return;
4120
- var eventData = this._createEventData(pointer, path[0]);
4121
- for(var i = 0; i < length; i++){
4122
- eventData.currentTarget = path[i];
4123
- fireEvent(path[i], eventData);
4124
- }
4125
- };
4126
- return UIPointerEventEmitter;
4127
- }(engine.PointerEventEmitter);
4128
- exports.UIPointerEventEmitter._MAX_PATH_DEPTH = 2048;
4129
- exports.UIPointerEventEmitter._tempSet = new Set();
4130
- exports.UIPointerEventEmitter._path = [];
4131
- exports.UIPointerEventEmitter._tempArray0 = [];
4132
- exports.UIPointerEventEmitter._tempArray1 = [];
4133
- exports.UIPointerEventEmitter = __decorate([
4134
- engine.registerPointerEventEmitter()
4135
- ], exports.UIPointerEventEmitter);
4136
-
4137
- var EngineExtension = /*#__PURE__*/ function() {
4138
- function EngineExtension() {}
4139
- var _proto = EngineExtension.prototype;
4140
- _proto._getUIDefaultMaterial = function _getUIDefaultMaterial() {
4141
- if (!this._uiDefaultMaterial) {
4142
- var shader = _getOrCreateUIShader();
4143
- // @ts-ignore
4144
- var material = new engine.Material(this, shader);
4145
- material.isGCIgnored = true;
4146
- this._uiDefaultMaterial = material;
4147
- }
4148
- return this._uiDefaultMaterial;
4149
- };
4150
- return EngineExtension;
4151
- }();
4152
- var EntityExtension = /*#__PURE__*/ function() {
4153
- function EntityExtension() {
4154
- this._uiHierarchyVersion = 0;
4155
- }
4156
- var _proto = EntityExtension.prototype;
4157
- _proto._updateUIHierarchyVersion = function _updateUIHierarchyVersion(version) {
4158
- if (this._uiHierarchyVersion !== version) {
4159
- var // @ts-ignore
4160
- _this_parent;
4161
- this._uiHierarchyVersion = version;
4162
- (_this_parent = this.parent) == null ? void 0 : _this_parent._updateUIHierarchyVersion(version);
4163
- }
4164
- };
4165
- return EntityExtension;
4166
- }();
4167
- function ApplyMixins(derivedCtor, baseCtors) {
4168
- baseCtors.forEach(function(baseCtor) {
4169
- Object.getOwnPropertyNames(baseCtor.prototype).forEach(function(name) {
4170
- Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name) || Object.create(null));
4171
- });
4172
- });
4173
- }
4174
- ApplyMixins(engine.Engine, [
4175
- EngineExtension
4176
- ]);
4177
- ApplyMixins(engine.Entity, [
4178
- EntityExtension
4179
- ]);
4180
- /**
4181
- * Register GUI components for the editor.
4182
- */ function registerGUI() {
4183
- for(var key in GUIComponent){
4184
- engine.Loader.registerClass(key, GUIComponent[key]);
4185
- }
4186
- _getOrCreateUIShader();
4187
- }
4188
- function _getOrCreateUIShader() {
4189
- return engine.Shader.find("2D/UIDefault");
4190
- }
4191
-
4192
- exports.Button = Button;
4193
- exports.CanvasRenderMode = CanvasRenderMode;
4194
- exports.ColorTransition = ColorTransition;
4195
- exports.EngineExtension = EngineExtension;
4196
- exports.EntityExtension = EntityExtension;
4197
- exports.HorizontalAlignmentMode = HorizontalAlignmentMode;
4198
- exports.Image = Image;
4199
- exports.Mask = Mask;
4200
- exports.ResolutionAdaptationMode = ResolutionAdaptationMode;
4201
- exports.ScaleTransition = ScaleTransition;
4202
- exports.SpriteTransition = SpriteTransition;
4203
- exports.Text = Text;
4204
- exports.Transition = Transition;
4205
- exports.UIGroup = UIGroup;
4206
- exports.UITransform = UITransform;
4207
- exports.VerticalAlignmentMode = VerticalAlignmentMode;
4208
- exports.registerGUI = registerGUI;
4209
-
4210
- Object.defineProperty(exports, '__esModule', { value: true });
4211
-
4212
- }));
4213
- //# sourceMappingURL=browser.js.map