laymur 0.3.16 → 0.3.19
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/elements/UIAnimatedImage.d.ts +119 -0
- package/dist/elements/UIGraphics.d.ts +122 -0
- package/dist/elements/UIText.d.ts +5 -5
- package/dist/index.d.ts +3 -0
- package/dist/index.js +649 -238
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/layers/UIFullscreenLayer.d.ts +21 -88
- package/dist/miscellaneous/UIMicro.d.ts +6 -1
- package/dist/miscellaneous/UITextPadding.d.ts +2 -2
- package/dist/miscellaneous/resizePolicies.d.ts +79 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlaneGeometry, Color, Scene, OrthographicCamera, ShaderMaterial, Vector4, Mesh, Texture, Vector2, Vector3, Matrix2, Matrix3, Matrix4, MathUtils, Quaternion, WebGLRenderTarget, UnsignedByteType,
|
|
1
|
+
import { PlaneGeometry, Color, Scene, OrthographicCamera, ShaderMaterial, Vector4, Mesh, Texture, Vector2, Vector3, Matrix2, Matrix3, Matrix4, MathUtils, Quaternion, CanvasTexture, LinearFilter, WebGLRenderTarget, UnsignedByteType, RGBAFormat, PerspectiveCamera, InstancedBufferGeometry, InstancedBufferAttribute } from 'three';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Mathematical expression builder for constraint equations in the UI layout system.
|
|
@@ -2108,18 +2108,29 @@ class UIColor extends i {
|
|
|
2108
2108
|
*/
|
|
2109
2109
|
copy(color) {
|
|
2110
2110
|
if (color instanceof UIColor) {
|
|
2111
|
-
this.rInternal
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2111
|
+
if (this.rInternal !== color.rInternal &&
|
|
2112
|
+
this.gInternal !== color.gInternal &&
|
|
2113
|
+
this.bInternal !== color.bInternal &&
|
|
2114
|
+
this.aInternal !== color.aInternal) {
|
|
2115
|
+
this.rInternal = color.rInternal;
|
|
2116
|
+
this.gInternal = color.gInternal;
|
|
2117
|
+
this.bInternal = color.bInternal;
|
|
2118
|
+
this.aInternal = color.aInternal;
|
|
2119
|
+
this.emit(UIColorEvent.CHANGE, this);
|
|
2120
|
+
}
|
|
2115
2121
|
}
|
|
2116
2122
|
else {
|
|
2117
|
-
this.rInternal
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2123
|
+
if (this.rInternal !== color.r &&
|
|
2124
|
+
this.gInternal !== color.g &&
|
|
2125
|
+
this.bInternal !== color.b &&
|
|
2126
|
+
this.aInternal !== 1) {
|
|
2127
|
+
this.rInternal = color.r;
|
|
2128
|
+
this.gInternal = color.g;
|
|
2129
|
+
this.bInternal = color.b;
|
|
2130
|
+
this.aInternal = 1;
|
|
2131
|
+
this.emit(UIColorEvent.CHANGE, this);
|
|
2132
|
+
}
|
|
2121
2133
|
}
|
|
2122
|
-
this.emit(UIColorEvent.CHANGE, this);
|
|
2123
2134
|
return this;
|
|
2124
2135
|
}
|
|
2125
2136
|
/**
|
|
@@ -4345,91 +4356,7 @@ class UIAnchor extends i {
|
|
|
4345
4356
|
}
|
|
4346
4357
|
}
|
|
4347
4358
|
|
|
4348
|
-
|
|
4349
|
-
const DEFAULT_SIZE = 100;
|
|
4350
|
-
/**
|
|
4351
|
-
* Abstract UI element that extends UIAnchor with dimensions but without rendering.
|
|
4352
|
-
*
|
|
4353
|
-
* UIDummy represents a rectangular area in the UI layout system that has position
|
|
4354
|
-
* and dimensions (width and height) but does not perform any visual rendering.
|
|
4355
|
-
* It serves as a placeholder or spacer element in constraint-based layouts,
|
|
4356
|
-
* useful for defining layout structure without visual content.
|
|
4357
|
-
*
|
|
4358
|
-
* @see {@link UIAnchor} - Base class providing position functionality
|
|
4359
|
-
* @see {@link UIPlaneElement} - Interface defining dimensional element behavior
|
|
4360
|
-
* @see {@link UILayer} - Container layer for UI elements
|
|
4361
|
-
*/
|
|
4362
|
-
class UIDummy extends UIAnchor {
|
|
4363
|
-
/**
|
|
4364
|
-
* Creates a new UIDummy instance with position and dimensions.
|
|
4365
|
-
*
|
|
4366
|
-
* @param layer - The UI layer that contains this dummy element
|
|
4367
|
-
* @param x - Initial x-coordinate position
|
|
4368
|
-
* @param y - Initial y-coordinate position
|
|
4369
|
-
* @param width - Initial width dimension (defaults to 100)
|
|
4370
|
-
* @param height - Initial height dimension (defaults to 100)
|
|
4371
|
-
* @throws Will throw an error if width or height are not valid positive numbers
|
|
4372
|
-
* @see {@link assertValidPositiveNumber}
|
|
4373
|
-
*/
|
|
4374
|
-
constructor(layer, options = {}) {
|
|
4375
|
-
const x = options.x ?? 0;
|
|
4376
|
-
const y = options.y ?? 0;
|
|
4377
|
-
const w = options.width ?? DEFAULT_SIZE;
|
|
4378
|
-
const h = options.height ?? DEFAULT_SIZE;
|
|
4379
|
-
assertValidPositiveNumber(w, "UIDummy width");
|
|
4380
|
-
assertValidPositiveNumber(h, "UIDummy height");
|
|
4381
|
-
super(layer, x, y);
|
|
4382
|
-
this.wVariable = this.solverWrapper.createVariable(w, UIPriority.P6);
|
|
4383
|
-
this.hVariable = this.solverWrapper.createVariable(h, UIPriority.P6);
|
|
4384
|
-
}
|
|
4385
|
-
/**
|
|
4386
|
-
* Gets the current width value from the solver.
|
|
4387
|
-
* @returns The current width dimension
|
|
4388
|
-
*/
|
|
4389
|
-
get width() {
|
|
4390
|
-
return this.solverWrapper.readVariableValue(this.wVariable);
|
|
4391
|
-
}
|
|
4392
|
-
/**
|
|
4393
|
-
* Gets the current height value from the solver.
|
|
4394
|
-
* @returns The current height dimension
|
|
4395
|
-
*/
|
|
4396
|
-
get height() {
|
|
4397
|
-
return this.solverWrapper.readVariableValue(this.hVariable);
|
|
4398
|
-
}
|
|
4399
|
-
/**
|
|
4400
|
-
* Sets the width value through the solver system.
|
|
4401
|
-
* @param value - The new width dimension (must be positive)
|
|
4402
|
-
* @throws Will throw an error if value is not a valid positive number
|
|
4403
|
-
* @see {@link assertValidPositiveNumber}
|
|
4404
|
-
*/
|
|
4405
|
-
set width(value) {
|
|
4406
|
-
assertValidPositiveNumber(value, "UIDummy width");
|
|
4407
|
-
this.solverWrapper.suggestVariableValue(this.wVariable, value);
|
|
4408
|
-
}
|
|
4409
|
-
/**
|
|
4410
|
-
* Sets the height value through the solver system.
|
|
4411
|
-
* @param value - The new height dimension (must be positive)
|
|
4412
|
-
* @throws Will throw an error if value is not a valid positive number
|
|
4413
|
-
* @see {@link assertValidPositiveNumber}
|
|
4414
|
-
*/
|
|
4415
|
-
set height(value) {
|
|
4416
|
-
assertValidPositiveNumber(value, "UIDummy height");
|
|
4417
|
-
this.solverWrapper.suggestVariableValue(this.hVariable, value);
|
|
4418
|
-
}
|
|
4419
|
-
/**
|
|
4420
|
-
* Destroys the dummy element by removing its solver variables.
|
|
4421
|
-
*
|
|
4422
|
-
* This method cleans up the dimension solver variables (width and height)
|
|
4423
|
-
* associated with this dummy element, then calls the parent destroy method
|
|
4424
|
-
* to clean up position variables. After calling this method, the dummy
|
|
4425
|
-
* element should not be used anymore.
|
|
4426
|
-
*/
|
|
4427
|
-
destroy() {
|
|
4428
|
-
this.solverWrapper.removeVariable(this.hVariable);
|
|
4429
|
-
this.solverWrapper.removeVariable(this.wVariable);
|
|
4430
|
-
super.destroy();
|
|
4431
|
-
}
|
|
4432
|
-
}
|
|
4359
|
+
var source$2 = "void main() {\n vec2 transformedUV = (uvTransform * vec3(io_UV, 1.0)).xy;\n vec4 diffuseColor = texture(map, transformedUV) * color;\n #include <alphatest_fragment>\n #include <alphahash_fragment>\n gl_FragColor = diffuseColor;\n #include <colorspace_fragment>\n}\n";
|
|
4433
4360
|
|
|
4434
4361
|
/**
|
|
4435
4362
|
* Events that can be emitted by UI elements.
|
|
@@ -4451,6 +4378,10 @@ var UIMicroAnchorMode;
|
|
|
4451
4378
|
UIMicroAnchorMode[UIMicroAnchorMode["POSITION_ROTATION_SCALE"] = 1] = "POSITION_ROTATION_SCALE";
|
|
4452
4379
|
})(UIMicroAnchorMode || (UIMicroAnchorMode = {}));
|
|
4453
4380
|
|
|
4381
|
+
var UIMicroEvent;
|
|
4382
|
+
(function (UIMicroEvent) {
|
|
4383
|
+
UIMicroEvent[UIMicroEvent["CHANGE"] = 0] = "CHANGE";
|
|
4384
|
+
})(UIMicroEvent || (UIMicroEvent = {}));
|
|
4454
4385
|
/** Default position value for x and y coordinates. */
|
|
4455
4386
|
const DEFAULT_POSITION = 0;
|
|
4456
4387
|
/** Default anchor point value for anchorX and anchorY. */
|
|
@@ -4473,8 +4404,9 @@ const DEFAULT_ROTATION = 0;
|
|
|
4473
4404
|
*
|
|
4474
4405
|
* @see {@link UIElement} - Elements that use micro transformations
|
|
4475
4406
|
*/
|
|
4476
|
-
class UIMicro {
|
|
4407
|
+
class UIMicro extends i {
|
|
4477
4408
|
constructor() {
|
|
4409
|
+
super(...arguments);
|
|
4478
4410
|
/** Internal storage for x-coordinate offset. */
|
|
4479
4411
|
this._private_xInternal = DEFAULT_POSITION;
|
|
4480
4412
|
/** Internal storage for y-coordinate offset. */
|
|
@@ -4572,6 +4504,7 @@ class UIMicro {
|
|
|
4572
4504
|
if (value !== this._private_xInternal) {
|
|
4573
4505
|
this._private_xInternal = value;
|
|
4574
4506
|
this._private_recalculationRequired = true;
|
|
4507
|
+
this.emit(UIMicroEvent.CHANGE, this);
|
|
4575
4508
|
}
|
|
4576
4509
|
}
|
|
4577
4510
|
/**
|
|
@@ -4582,6 +4515,7 @@ class UIMicro {
|
|
|
4582
4515
|
if (value !== this._private_yInternal) {
|
|
4583
4516
|
this._private_yInternal = value;
|
|
4584
4517
|
this._private_recalculationRequired = true;
|
|
4518
|
+
this.emit(UIMicroEvent.CHANGE, this);
|
|
4585
4519
|
}
|
|
4586
4520
|
}
|
|
4587
4521
|
/**
|
|
@@ -4592,6 +4526,7 @@ class UIMicro {
|
|
|
4592
4526
|
if (value !== this._private_anchorXInternal) {
|
|
4593
4527
|
this._private_anchorXInternal = value;
|
|
4594
4528
|
this._private_recalculationRequired = true;
|
|
4529
|
+
this.emit(UIMicroEvent.CHANGE, this);
|
|
4595
4530
|
}
|
|
4596
4531
|
}
|
|
4597
4532
|
/**
|
|
@@ -4602,6 +4537,7 @@ class UIMicro {
|
|
|
4602
4537
|
if (value !== this._private_anchorYInternal) {
|
|
4603
4538
|
this._private_anchorYInternal = value;
|
|
4604
4539
|
this._private_recalculationRequired = true;
|
|
4540
|
+
this.emit(UIMicroEvent.CHANGE, this);
|
|
4605
4541
|
}
|
|
4606
4542
|
}
|
|
4607
4543
|
/**
|
|
@@ -4612,6 +4548,7 @@ class UIMicro {
|
|
|
4612
4548
|
if (value !== this._private_scaleXInternal) {
|
|
4613
4549
|
this._private_scaleXInternal = value;
|
|
4614
4550
|
this._private_recalculationRequired = true;
|
|
4551
|
+
this.emit(UIMicroEvent.CHANGE, this);
|
|
4615
4552
|
}
|
|
4616
4553
|
}
|
|
4617
4554
|
/**
|
|
@@ -4622,6 +4559,7 @@ class UIMicro {
|
|
|
4622
4559
|
if (value !== this._private_scaleYInternal) {
|
|
4623
4560
|
this._private_scaleYInternal = value;
|
|
4624
4561
|
this._private_recalculationRequired = true;
|
|
4562
|
+
this.emit(UIMicroEvent.CHANGE, this);
|
|
4625
4563
|
}
|
|
4626
4564
|
}
|
|
4627
4565
|
/**
|
|
@@ -4633,6 +4571,7 @@ class UIMicro {
|
|
|
4633
4571
|
this._private_scaleXInternal = value;
|
|
4634
4572
|
this._private_scaleYInternal = value;
|
|
4635
4573
|
this._private_recalculationRequired = true;
|
|
4574
|
+
this.emit(UIMicroEvent.CHANGE, this);
|
|
4636
4575
|
}
|
|
4637
4576
|
}
|
|
4638
4577
|
/**
|
|
@@ -4644,6 +4583,7 @@ class UIMicro {
|
|
|
4644
4583
|
if (rotation !== this._private_rotationInternal) {
|
|
4645
4584
|
this._private_rotationInternal = rotation;
|
|
4646
4585
|
this._private_recalculationRequired = true;
|
|
4586
|
+
this.emit(UIMicroEvent.CHANGE, this);
|
|
4647
4587
|
}
|
|
4648
4588
|
}
|
|
4649
4589
|
/**
|
|
@@ -4654,6 +4594,7 @@ class UIMicro {
|
|
|
4654
4594
|
if (value !== this._private_rotationInternal) {
|
|
4655
4595
|
this._private_rotationInternal = value;
|
|
4656
4596
|
this._private_recalculationRequired = true;
|
|
4597
|
+
this.emit(UIMicroEvent.CHANGE, this);
|
|
4657
4598
|
}
|
|
4658
4599
|
}
|
|
4659
4600
|
/**
|
|
@@ -4664,6 +4605,7 @@ class UIMicro {
|
|
|
4664
4605
|
if (value !== this._private_anchorModeInternal) {
|
|
4665
4606
|
this._private_anchorModeInternal = value;
|
|
4666
4607
|
this._private_recalculationRequired = true;
|
|
4608
|
+
this.emit(UIMicroEvent.CHANGE, this);
|
|
4667
4609
|
}
|
|
4668
4610
|
}
|
|
4669
4611
|
/**
|
|
@@ -4689,6 +4631,28 @@ class UIMicro {
|
|
|
4689
4631
|
this._private_scaleYInternal = DEFAULT_SCALE;
|
|
4690
4632
|
this._private_rotationInternal = DEFAULT_ROTATION;
|
|
4691
4633
|
this._private_recalculationRequired = true;
|
|
4634
|
+
this.emit(UIMicroEvent.CHANGE, this);
|
|
4635
|
+
}
|
|
4636
|
+
}
|
|
4637
|
+
copy(value) {
|
|
4638
|
+
if (this._private_xInternal !== value._private_xInternal &&
|
|
4639
|
+
this._private_yInternal !== value._private_yInternal &&
|
|
4640
|
+
this._private_anchorXInternal !== value._private_anchorXInternal &&
|
|
4641
|
+
this._private_anchorYInternal !== value._private_anchorYInternal &&
|
|
4642
|
+
this._private_scaleXInternal !== value._private_scaleXInternal &&
|
|
4643
|
+
this._private_scaleYInternal !== value._private_scaleYInternal &&
|
|
4644
|
+
this._private_rotationInternal !== value._private_rotationInternal &&
|
|
4645
|
+
this._private_anchorModeInternal !== value._private_anchorModeInternal) {
|
|
4646
|
+
this._private_xInternal = value._private_xInternal;
|
|
4647
|
+
this._private_yInternal = value._private_yInternal;
|
|
4648
|
+
this._private_anchorXInternal = value._private_anchorXInternal;
|
|
4649
|
+
this._private_anchorYInternal = value._private_anchorYInternal;
|
|
4650
|
+
this._private_scaleXInternal = value._private_scaleXInternal;
|
|
4651
|
+
this._private_scaleYInternal = value._private_scaleYInternal;
|
|
4652
|
+
this._private_rotationInternal = value._private_rotationInternal;
|
|
4653
|
+
this._private_anchorModeInternal = value._private_anchorModeInternal;
|
|
4654
|
+
this.emit(UIMicroEvent.CHANGE, this);
|
|
4655
|
+
this._private_recalculationRequired = true;
|
|
4692
4656
|
}
|
|
4693
4657
|
}
|
|
4694
4658
|
/**
|
|
@@ -4973,7 +4937,462 @@ class UIElement extends UIAnchor {
|
|
|
4973
4937
|
}
|
|
4974
4938
|
}
|
|
4975
4939
|
|
|
4976
|
-
var
|
|
4940
|
+
var UIAnimatedImageEvent;
|
|
4941
|
+
(function (UIAnimatedImageEvent) {
|
|
4942
|
+
UIAnimatedImageEvent[UIAnimatedImageEvent["PLAY"] = 0] = "PLAY";
|
|
4943
|
+
UIAnimatedImageEvent[UIAnimatedImageEvent["PAUSE"] = 1] = "PAUSE";
|
|
4944
|
+
UIAnimatedImageEvent[UIAnimatedImageEvent["STOP"] = 2] = "STOP";
|
|
4945
|
+
})(UIAnimatedImageEvent || (UIAnimatedImageEvent = {}));
|
|
4946
|
+
/**
|
|
4947
|
+
* UI element for displaying textured images.
|
|
4948
|
+
*
|
|
4949
|
+
* UIAnimatedImage is a concrete implementation of UIElement that renders a textured
|
|
4950
|
+
* image using shader-based planes. It automatically sizes itself
|
|
4951
|
+
* to match the texture dimensions and provides control over visual properties
|
|
4952
|
+
* such as color tinting.
|
|
4953
|
+
*
|
|
4954
|
+
* @see {@link UIElement} - Base class providing UI element functionality
|
|
4955
|
+
* @see {@link Texture} - Three.js texture for image data
|
|
4956
|
+
*/
|
|
4957
|
+
class UIAnimatedImage extends UIElement {
|
|
4958
|
+
/**
|
|
4959
|
+
* Creates a new UIAnimatedImage instance.
|
|
4960
|
+
*
|
|
4961
|
+
* The image will automatically size itself to match the texture's dimensions.
|
|
4962
|
+
* All options have default values if not specified.
|
|
4963
|
+
*
|
|
4964
|
+
* @param layer - The UI layer that contains this image
|
|
4965
|
+
* @param texture - The Three.js texture to display
|
|
4966
|
+
* @param options - Configuration options for the image
|
|
4967
|
+
* @throws Will throw an error if the texture dimensions are not valid positive numbers
|
|
4968
|
+
*/
|
|
4969
|
+
constructor(layer, sequence, options = {}) {
|
|
4970
|
+
const w = options.width ?? 100;
|
|
4971
|
+
const h = options.height ?? 100;
|
|
4972
|
+
const color = options.color ?? new UIColor();
|
|
4973
|
+
let tempSequence;
|
|
4974
|
+
if (Array.isArray(sequence)) {
|
|
4975
|
+
tempSequence = sequence.map((texture) => {
|
|
4976
|
+
texture.updateMatrix();
|
|
4977
|
+
return {
|
|
4978
|
+
texture,
|
|
4979
|
+
uvTransform: texture.matrix,
|
|
4980
|
+
};
|
|
4981
|
+
});
|
|
4982
|
+
}
|
|
4983
|
+
else {
|
|
4984
|
+
tempSequence = sequence.transforms.map((transform) => {
|
|
4985
|
+
return {
|
|
4986
|
+
texture: sequence.texture,
|
|
4987
|
+
uvTransform: transform,
|
|
4988
|
+
};
|
|
4989
|
+
});
|
|
4990
|
+
}
|
|
4991
|
+
super(layer, options.x ?? 0, options.y ?? 0, w, h, source$2, {
|
|
4992
|
+
map: tempSequence[0].texture,
|
|
4993
|
+
uvTransform: tempSequence[0].uvTransform,
|
|
4994
|
+
color,
|
|
4995
|
+
});
|
|
4996
|
+
this._private_intervalHandler = undefined;
|
|
4997
|
+
this._private_currentFrameIndex = 0;
|
|
4998
|
+
/** Event handler for when the color changes */
|
|
4999
|
+
this._private_onColorChange = (color) => {
|
|
5000
|
+
this.sceneWrapper.setUniform(this.planeHandler, "color", color);
|
|
5001
|
+
};
|
|
5002
|
+
this._private_sequenceInternal = tempSequence;
|
|
5003
|
+
this._private_colorInternal = color;
|
|
5004
|
+
const defaultFrameRate = 24;
|
|
5005
|
+
this._private_frameRateInternal = options.frameRate ?? defaultFrameRate;
|
|
5006
|
+
this._private_loopInternal = options.loop ?? true;
|
|
5007
|
+
this._private_colorInternal.on(UIColorEvent.CHANGE, this._private_onColorChange);
|
|
5008
|
+
}
|
|
5009
|
+
/**
|
|
5010
|
+
* Gets the current color tint applied to the image.
|
|
5011
|
+
* @returns The UIColor instance
|
|
5012
|
+
*/
|
|
5013
|
+
get color() {
|
|
5014
|
+
return this._private_colorInternal;
|
|
5015
|
+
}
|
|
5016
|
+
/**
|
|
5017
|
+
* Gets the frame rate for animation.
|
|
5018
|
+
* @returns The frame rate in frames per second
|
|
5019
|
+
*/
|
|
5020
|
+
get frameRate() {
|
|
5021
|
+
return this._private_frameRateInternal;
|
|
5022
|
+
}
|
|
5023
|
+
/**
|
|
5024
|
+
* Gets whether the animation loops.
|
|
5025
|
+
* @returns True if animation loops
|
|
5026
|
+
*/
|
|
5027
|
+
get loop() {
|
|
5028
|
+
return this._private_loopInternal;
|
|
5029
|
+
}
|
|
5030
|
+
/**
|
|
5031
|
+
* Gets the total duration of the animation in seconds.
|
|
5032
|
+
* @returns The duration in seconds
|
|
5033
|
+
*/
|
|
5034
|
+
get duration() {
|
|
5035
|
+
return this._private_sequenceInternal.length / this._private_frameRateInternal;
|
|
5036
|
+
}
|
|
5037
|
+
/**
|
|
5038
|
+
* Sets the color tint applied to the image.
|
|
5039
|
+
* @param value - The UIColor instance
|
|
5040
|
+
*/
|
|
5041
|
+
set color(value) {
|
|
5042
|
+
this._private_colorInternal.copy(value);
|
|
5043
|
+
}
|
|
5044
|
+
/**
|
|
5045
|
+
* Sets the frame rate for animation.
|
|
5046
|
+
* @param value - The frame rate in frames per second
|
|
5047
|
+
*/
|
|
5048
|
+
set frameRate(value) {
|
|
5049
|
+
if (value <= 0) {
|
|
5050
|
+
throw new Error("Frame rate must be greater than zero");
|
|
5051
|
+
}
|
|
5052
|
+
const wasPlaying = this._private_intervalHandler !== undefined;
|
|
5053
|
+
if (wasPlaying) {
|
|
5054
|
+
this.pause();
|
|
5055
|
+
}
|
|
5056
|
+
this._private_frameRateInternal = value;
|
|
5057
|
+
if (wasPlaying) {
|
|
5058
|
+
this.play();
|
|
5059
|
+
}
|
|
5060
|
+
}
|
|
5061
|
+
/**
|
|
5062
|
+
* Sets whether the animation loops.
|
|
5063
|
+
* @param value - True to enable looping
|
|
5064
|
+
*/
|
|
5065
|
+
set loop(value) {
|
|
5066
|
+
this._private_loopInternal = value;
|
|
5067
|
+
}
|
|
5068
|
+
/**
|
|
5069
|
+
* Starts or resumes playback of the animation.
|
|
5070
|
+
*/
|
|
5071
|
+
play() {
|
|
5072
|
+
if (this._private_intervalHandler !== undefined) {
|
|
5073
|
+
return;
|
|
5074
|
+
}
|
|
5075
|
+
this._private_intervalHandler = setInterval(() => {
|
|
5076
|
+
this._private_currentFrameIndex++;
|
|
5077
|
+
if (this._private_loopInternal) {
|
|
5078
|
+
this._private_currentFrameIndex %= this._private_sequenceInternal.length;
|
|
5079
|
+
}
|
|
5080
|
+
else if (this._private_currentFrameIndex >= this._private_sequenceInternal.length) {
|
|
5081
|
+
this._private_currentFrameIndex = this._private_sequenceInternal.length - 1;
|
|
5082
|
+
this.pause();
|
|
5083
|
+
return;
|
|
5084
|
+
}
|
|
5085
|
+
this._private_updateFrame();
|
|
5086
|
+
}, 1000 / this._private_frameRateInternal);
|
|
5087
|
+
this.emit(UIAnimatedImageEvent.PLAY);
|
|
5088
|
+
}
|
|
5089
|
+
/**
|
|
5090
|
+
* Pauses the animation at the current frame.
|
|
5091
|
+
*/
|
|
5092
|
+
pause() {
|
|
5093
|
+
if (this._private_intervalHandler === undefined) {
|
|
5094
|
+
return;
|
|
5095
|
+
}
|
|
5096
|
+
clearInterval(this._private_intervalHandler);
|
|
5097
|
+
this._private_intervalHandler = undefined;
|
|
5098
|
+
this.emit(UIAnimatedImageEvent.PAUSE);
|
|
5099
|
+
}
|
|
5100
|
+
/**
|
|
5101
|
+
* Stops the animation and resets to the first frame.
|
|
5102
|
+
*/
|
|
5103
|
+
stop() {
|
|
5104
|
+
if (this._private_intervalHandler !== undefined) {
|
|
5105
|
+
clearInterval(this._private_intervalHandler);
|
|
5106
|
+
this._private_intervalHandler = undefined;
|
|
5107
|
+
}
|
|
5108
|
+
this._private_currentFrameIndex = 0;
|
|
5109
|
+
this._private_updateFrame();
|
|
5110
|
+
this.emit(UIAnimatedImageEvent.STOP);
|
|
5111
|
+
}
|
|
5112
|
+
/**
|
|
5113
|
+
* Destroys the UI image by cleaning up color event listeners and all associated resources.
|
|
5114
|
+
*/
|
|
5115
|
+
destroy() {
|
|
5116
|
+
this.stop();
|
|
5117
|
+
this._private_colorInternal.off(UIColorEvent.CHANGE, this._private_onColorChange);
|
|
5118
|
+
super.destroy();
|
|
5119
|
+
}
|
|
5120
|
+
_private_updateFrame() {
|
|
5121
|
+
const frame = this._private_sequenceInternal[this._private_currentFrameIndex];
|
|
5122
|
+
this.sceneWrapper.setUniform(this.planeHandler, "map", frame.texture);
|
|
5123
|
+
this.sceneWrapper.setUniform(this.planeHandler, "uvTransform", frame.uvTransform);
|
|
5124
|
+
}
|
|
5125
|
+
}
|
|
5126
|
+
|
|
5127
|
+
/** Default width and height value for UIDummy elements. */
|
|
5128
|
+
const DEFAULT_SIZE = 100;
|
|
5129
|
+
/**
|
|
5130
|
+
* Abstract UI element that extends UIAnchor with dimensions but without rendering.
|
|
5131
|
+
*
|
|
5132
|
+
* UIDummy represents a rectangular area in the UI layout system that has position
|
|
5133
|
+
* and dimensions (width and height) but does not perform any visual rendering.
|
|
5134
|
+
* It serves as a placeholder or spacer element in constraint-based layouts,
|
|
5135
|
+
* useful for defining layout structure without visual content.
|
|
5136
|
+
*
|
|
5137
|
+
* @see {@link UIAnchor} - Base class providing position functionality
|
|
5138
|
+
* @see {@link UIPlaneElement} - Interface defining dimensional element behavior
|
|
5139
|
+
* @see {@link UILayer} - Container layer for UI elements
|
|
5140
|
+
*/
|
|
5141
|
+
class UIDummy extends UIAnchor {
|
|
5142
|
+
/**
|
|
5143
|
+
* Creates a new UIDummy instance with position and dimensions.
|
|
5144
|
+
*
|
|
5145
|
+
* @param layer - The UI layer that contains this dummy element
|
|
5146
|
+
* @param x - Initial x-coordinate position
|
|
5147
|
+
* @param y - Initial y-coordinate position
|
|
5148
|
+
* @param width - Initial width dimension (defaults to 100)
|
|
5149
|
+
* @param height - Initial height dimension (defaults to 100)
|
|
5150
|
+
* @throws Will throw an error if width or height are not valid positive numbers
|
|
5151
|
+
* @see {@link assertValidPositiveNumber}
|
|
5152
|
+
*/
|
|
5153
|
+
constructor(layer, options = {}) {
|
|
5154
|
+
const x = options.x ?? 0;
|
|
5155
|
+
const y = options.y ?? 0;
|
|
5156
|
+
const w = options.width ?? DEFAULT_SIZE;
|
|
5157
|
+
const h = options.height ?? DEFAULT_SIZE;
|
|
5158
|
+
assertValidPositiveNumber(w, "UIDummy width");
|
|
5159
|
+
assertValidPositiveNumber(h, "UIDummy height");
|
|
5160
|
+
super(layer, x, y);
|
|
5161
|
+
this.wVariable = this.solverWrapper.createVariable(w, UIPriority.P6);
|
|
5162
|
+
this.hVariable = this.solverWrapper.createVariable(h, UIPriority.P6);
|
|
5163
|
+
}
|
|
5164
|
+
/**
|
|
5165
|
+
* Gets the current width value from the solver.
|
|
5166
|
+
* @returns The current width dimension
|
|
5167
|
+
*/
|
|
5168
|
+
get width() {
|
|
5169
|
+
return this.solverWrapper.readVariableValue(this.wVariable);
|
|
5170
|
+
}
|
|
5171
|
+
/**
|
|
5172
|
+
* Gets the current height value from the solver.
|
|
5173
|
+
* @returns The current height dimension
|
|
5174
|
+
*/
|
|
5175
|
+
get height() {
|
|
5176
|
+
return this.solverWrapper.readVariableValue(this.hVariable);
|
|
5177
|
+
}
|
|
5178
|
+
/**
|
|
5179
|
+
* Sets the width value through the solver system.
|
|
5180
|
+
* @param value - The new width dimension (must be positive)
|
|
5181
|
+
* @throws Will throw an error if value is not a valid positive number
|
|
5182
|
+
* @see {@link assertValidPositiveNumber}
|
|
5183
|
+
*/
|
|
5184
|
+
set width(value) {
|
|
5185
|
+
assertValidPositiveNumber(value, "UIDummy width");
|
|
5186
|
+
this.solverWrapper.suggestVariableValue(this.wVariable, value);
|
|
5187
|
+
}
|
|
5188
|
+
/**
|
|
5189
|
+
* Sets the height value through the solver system.
|
|
5190
|
+
* @param value - The new height dimension (must be positive)
|
|
5191
|
+
* @throws Will throw an error if value is not a valid positive number
|
|
5192
|
+
* @see {@link assertValidPositiveNumber}
|
|
5193
|
+
*/
|
|
5194
|
+
set height(value) {
|
|
5195
|
+
assertValidPositiveNumber(value, "UIDummy height");
|
|
5196
|
+
this.solverWrapper.suggestVariableValue(this.hVariable, value);
|
|
5197
|
+
}
|
|
5198
|
+
/**
|
|
5199
|
+
* Destroys the dummy element by removing its solver variables.
|
|
5200
|
+
*
|
|
5201
|
+
* This method cleans up the dimension solver variables (width and height)
|
|
5202
|
+
* associated with this dummy element, then calls the parent destroy method
|
|
5203
|
+
* to clean up position variables. After calling this method, the dummy
|
|
5204
|
+
* element should not be used anymore.
|
|
5205
|
+
*/
|
|
5206
|
+
destroy() {
|
|
5207
|
+
this.solverWrapper.removeVariable(this.hVariable);
|
|
5208
|
+
this.solverWrapper.removeVariable(this.wVariable);
|
|
5209
|
+
super.destroy();
|
|
5210
|
+
}
|
|
5211
|
+
}
|
|
5212
|
+
|
|
5213
|
+
/**
|
|
5214
|
+
* UI element for drawing graphics using 2D canvas API.
|
|
5215
|
+
*
|
|
5216
|
+
* UIGraphics uses an OffscreenCanvas for rendering 2D graphics and converts it
|
|
5217
|
+
* to a Three.js texture for display. It provides access to the canvas context
|
|
5218
|
+
* for custom drawing operations.
|
|
5219
|
+
*/
|
|
5220
|
+
class UIGraphics extends UIElement {
|
|
5221
|
+
/**
|
|
5222
|
+
* Creates a new UIGraphics instance.
|
|
5223
|
+
*
|
|
5224
|
+
* @param layer - The UI layer that contains this graphics element
|
|
5225
|
+
* @param options - Configuration options for the graphics element
|
|
5226
|
+
*/
|
|
5227
|
+
constructor(layer, options = {}) {
|
|
5228
|
+
const defaultCanvasSize = 512;
|
|
5229
|
+
const width = options.width ?? defaultCanvasSize;
|
|
5230
|
+
const height = options.height ?? defaultCanvasSize;
|
|
5231
|
+
const color = options.color ?? new UIColor();
|
|
5232
|
+
// Create OffscreenCanvas
|
|
5233
|
+
const canvas = new OffscreenCanvas(width, height);
|
|
5234
|
+
const ctx = canvas.getContext("2d");
|
|
5235
|
+
if (!ctx) {
|
|
5236
|
+
throw new Error("Failed to get 2D context from OffscreenCanvas");
|
|
5237
|
+
}
|
|
5238
|
+
// Create texture from canvas
|
|
5239
|
+
const canvasTexture = new CanvasTexture(canvas);
|
|
5240
|
+
canvasTexture.minFilter = LinearFilter;
|
|
5241
|
+
canvasTexture.magFilter = LinearFilter;
|
|
5242
|
+
super(layer, options.x ?? 0, options.y ?? 0, width, height, source$2, {
|
|
5243
|
+
map: canvasTexture,
|
|
5244
|
+
uvTransform: canvasTexture.matrix,
|
|
5245
|
+
color,
|
|
5246
|
+
});
|
|
5247
|
+
/** Event handler for when the color changes */
|
|
5248
|
+
this._private_onColorChange = (color) => {
|
|
5249
|
+
this.sceneWrapper.setUniform(this.planeHandler, "color", color);
|
|
5250
|
+
};
|
|
5251
|
+
this._private_canvas = canvas;
|
|
5252
|
+
this._private_ctx = ctx;
|
|
5253
|
+
this._private_canvasTexture = canvasTexture;
|
|
5254
|
+
this._private_colorInternal = color;
|
|
5255
|
+
this._private_colorInternal.on(UIColorEvent.CHANGE, this._private_onColorChange);
|
|
5256
|
+
}
|
|
5257
|
+
/**
|
|
5258
|
+
* Gets the canvas width.
|
|
5259
|
+
*/
|
|
5260
|
+
get canvasWidth() {
|
|
5261
|
+
return this._private_canvas.width;
|
|
5262
|
+
}
|
|
5263
|
+
/**
|
|
5264
|
+
* Gets the canvas height.
|
|
5265
|
+
*/
|
|
5266
|
+
get canvasHeight() {
|
|
5267
|
+
return this._private_canvas.height;
|
|
5268
|
+
}
|
|
5269
|
+
/**
|
|
5270
|
+
* Gets the current color tint applied to the graphics.
|
|
5271
|
+
*/
|
|
5272
|
+
get color() {
|
|
5273
|
+
return this._private_colorInternal;
|
|
5274
|
+
}
|
|
5275
|
+
/**
|
|
5276
|
+
* Sets the color tint applied to the graphics.
|
|
5277
|
+
*/
|
|
5278
|
+
set color(value) {
|
|
5279
|
+
this._private_colorInternal.copy(value);
|
|
5280
|
+
}
|
|
5281
|
+
/**
|
|
5282
|
+
* Clears the canvas with optional fill color.
|
|
5283
|
+
*
|
|
5284
|
+
* @param fillColor - Optional color to fill after clearing (CSS color string)
|
|
5285
|
+
*/
|
|
5286
|
+
clear(fillColor) {
|
|
5287
|
+
this._private_ctx.clearRect(0, 0, this._private_canvas.width, this._private_canvas.height);
|
|
5288
|
+
if (fillColor !== undefined) {
|
|
5289
|
+
this._private_ctx.fillStyle = fillColor;
|
|
5290
|
+
this._private_ctx.fillRect(0, 0, this._private_canvas.width, this._private_canvas.height);
|
|
5291
|
+
}
|
|
5292
|
+
this._private_canvasTexture.needsUpdate = true;
|
|
5293
|
+
}
|
|
5294
|
+
/**
|
|
5295
|
+
* Draws a rectangle on the canvas.
|
|
5296
|
+
*/
|
|
5297
|
+
rect(x, y, width, height) {
|
|
5298
|
+
this._private_ctx.rect(x, y, width, height);
|
|
5299
|
+
this._private_canvasTexture.needsUpdate = true;
|
|
5300
|
+
}
|
|
5301
|
+
/**
|
|
5302
|
+
* Draws a filled rectangle on the canvas.
|
|
5303
|
+
*/
|
|
5304
|
+
fillRect(x, y, width, height) {
|
|
5305
|
+
this._private_ctx.fillRect(x, y, width, height);
|
|
5306
|
+
this._private_canvasTexture.needsUpdate = true;
|
|
5307
|
+
}
|
|
5308
|
+
/**
|
|
5309
|
+
* Draws a stroked rectangle on the canvas.
|
|
5310
|
+
*/
|
|
5311
|
+
strokeRect(x, y, width, height) {
|
|
5312
|
+
this._private_ctx.strokeRect(x, y, width, height);
|
|
5313
|
+
this._private_canvasTexture.needsUpdate = true;
|
|
5314
|
+
}
|
|
5315
|
+
/**
|
|
5316
|
+
* Draws a circle on the canvas.
|
|
5317
|
+
*/
|
|
5318
|
+
circle(x, y, radius) {
|
|
5319
|
+
this._private_ctx.beginPath();
|
|
5320
|
+
this._private_ctx.arc(x, y, radius, 0, Math.PI * 2);
|
|
5321
|
+
this._private_ctx.closePath();
|
|
5322
|
+
this._private_canvasTexture.needsUpdate = true;
|
|
5323
|
+
}
|
|
5324
|
+
/**
|
|
5325
|
+
* Begins a new path.
|
|
5326
|
+
*/
|
|
5327
|
+
beginPath() {
|
|
5328
|
+
this._private_ctx.beginPath();
|
|
5329
|
+
this._private_canvasTexture.needsUpdate = true;
|
|
5330
|
+
}
|
|
5331
|
+
/**
|
|
5332
|
+
* Closes the current path.
|
|
5333
|
+
*/
|
|
5334
|
+
closePath() {
|
|
5335
|
+
this._private_ctx.closePath();
|
|
5336
|
+
this._private_canvasTexture.needsUpdate = true;
|
|
5337
|
+
}
|
|
5338
|
+
/**
|
|
5339
|
+
* Fills the current path.
|
|
5340
|
+
*/
|
|
5341
|
+
fill() {
|
|
5342
|
+
this._private_ctx.fill();
|
|
5343
|
+
this._private_canvasTexture.needsUpdate = true;
|
|
5344
|
+
}
|
|
5345
|
+
/**
|
|
5346
|
+
* Strokes the current path.
|
|
5347
|
+
*/
|
|
5348
|
+
stroke() {
|
|
5349
|
+
this._private_ctx.stroke();
|
|
5350
|
+
this._private_canvasTexture.needsUpdate = true;
|
|
5351
|
+
}
|
|
5352
|
+
/**
|
|
5353
|
+
* Moves the path to a point.
|
|
5354
|
+
*/
|
|
5355
|
+
moveTo(x, y) {
|
|
5356
|
+
this._private_ctx.moveTo(x, y);
|
|
5357
|
+
this._private_canvasTexture.needsUpdate = true;
|
|
5358
|
+
}
|
|
5359
|
+
/**
|
|
5360
|
+
* Draws a line to a point.
|
|
5361
|
+
*/
|
|
5362
|
+
lineTo(x, y) {
|
|
5363
|
+
this._private_ctx.lineTo(x, y);
|
|
5364
|
+
this._private_canvasTexture.needsUpdate = true;
|
|
5365
|
+
}
|
|
5366
|
+
/**
|
|
5367
|
+
* Sets the fill style.
|
|
5368
|
+
*/
|
|
5369
|
+
setFillStyle(style) {
|
|
5370
|
+
this._private_ctx.fillStyle = style;
|
|
5371
|
+
this._private_canvasTexture.needsUpdate = true;
|
|
5372
|
+
}
|
|
5373
|
+
/**
|
|
5374
|
+
* Sets the stroke style.
|
|
5375
|
+
*/
|
|
5376
|
+
setStrokeStyle(style) {
|
|
5377
|
+
this._private_ctx.strokeStyle = style;
|
|
5378
|
+
this._private_canvasTexture.needsUpdate = true;
|
|
5379
|
+
}
|
|
5380
|
+
/**
|
|
5381
|
+
* Sets the line width.
|
|
5382
|
+
*/
|
|
5383
|
+
setLineWidth(width) {
|
|
5384
|
+
this._private_ctx.lineWidth = width;
|
|
5385
|
+
this._private_canvasTexture.needsUpdate = true;
|
|
5386
|
+
}
|
|
5387
|
+
/**
|
|
5388
|
+
* Destroys the graphics element by cleaning up resources.
|
|
5389
|
+
*/
|
|
5390
|
+
destroy() {
|
|
5391
|
+
this._private_colorInternal.off(UIColorEvent.CHANGE, this._private_onColorChange);
|
|
5392
|
+
this._private_canvasTexture.dispose();
|
|
5393
|
+
super.destroy();
|
|
5394
|
+
}
|
|
5395
|
+
}
|
|
4977
5396
|
|
|
4978
5397
|
/**
|
|
4979
5398
|
* UI element for displaying textured images.
|
|
@@ -6053,7 +6472,7 @@ const DEFAULT_MAX_WIDTH = 1024;
|
|
|
6053
6472
|
* @see {@link UIElement} - Base class providing UI element functionality
|
|
6054
6473
|
* @see {@link UITextContent} - Text content structure
|
|
6055
6474
|
* @see {@link UITextStyle} - Text styling options
|
|
6056
|
-
* @see {@link
|
|
6475
|
+
* @see {@link UIPadding} - Padding configuration
|
|
6057
6476
|
*/
|
|
6058
6477
|
class UIText extends UIElement {
|
|
6059
6478
|
/**
|
|
@@ -6221,152 +6640,177 @@ class UIText extends UIElement {
|
|
|
6221
6640
|
}
|
|
6222
6641
|
|
|
6223
6642
|
/**
|
|
6224
|
-
*
|
|
6643
|
+
* Base class for UI resize policies.
|
|
6644
|
+
*
|
|
6645
|
+
* Calculates scale factors based on viewport dimensions. Different policies
|
|
6646
|
+
* implement different scaling strategies.
|
|
6647
|
+
*/
|
|
6648
|
+
class UIResizePolicy {
|
|
6649
|
+
}
|
|
6650
|
+
/**
|
|
6651
|
+
* No scaling applied, always returns 1:1 scale.
|
|
6652
|
+
*/
|
|
6653
|
+
class UIResizePolicyNone extends UIResizePolicy {
|
|
6654
|
+
calculateScaleInternal(width, height) {
|
|
6655
|
+
return 1;
|
|
6656
|
+
}
|
|
6657
|
+
}
|
|
6658
|
+
/**
|
|
6659
|
+
* Maintains fixed width, scales based on window width.
|
|
6660
|
+
*
|
|
6661
|
+
* Uses different widths for landscape vs portrait orientation.
|
|
6662
|
+
*/
|
|
6663
|
+
class UIResizePolicyFixedWidth extends UIResizePolicy {
|
|
6664
|
+
/**
|
|
6665
|
+
* @param fixedWidthLandscape - Target width for landscape (width > height)
|
|
6666
|
+
* @param fixedWidthPortrait - Target width for portrait (width <= height)
|
|
6667
|
+
*/
|
|
6668
|
+
constructor(fixedWidthLandscape, fixedWidthPortrait) {
|
|
6669
|
+
super();
|
|
6670
|
+
this.fixedWidthLandscape = fixedWidthLandscape;
|
|
6671
|
+
this.fixedWidthPortrait = fixedWidthPortrait;
|
|
6672
|
+
assertValidPositiveNumber(fixedWidthLandscape, "UIResizePolicyFixedWidth.fixedWidthLandscape");
|
|
6673
|
+
assertValidPositiveNumber(fixedWidthPortrait, "UIResizePolicyFixedWidth.fixedWidthPortrait");
|
|
6674
|
+
}
|
|
6675
|
+
calculateScaleInternal(width, height) {
|
|
6676
|
+
return width > height
|
|
6677
|
+
? this.fixedWidthLandscape / width
|
|
6678
|
+
: this.fixedWidthPortrait / width;
|
|
6679
|
+
}
|
|
6680
|
+
}
|
|
6681
|
+
/**
|
|
6682
|
+
* Maintains fixed height, scales based on window height.
|
|
6225
6683
|
*
|
|
6226
|
-
*
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
|
|
6684
|
+
* Uses different heights for landscape vs portrait orientation.
|
|
6685
|
+
*/
|
|
6686
|
+
class UIResizePolicyFixedHeight extends UIResizePolicy {
|
|
6687
|
+
/**
|
|
6688
|
+
* @param fixedHeightLandscape - Target height for landscape (width > height)
|
|
6689
|
+
* @param fixedHeightPortrait - Target height for portrait (width <= height)
|
|
6690
|
+
*/
|
|
6691
|
+
constructor(fixedHeightLandscape, fixedHeightPortrait) {
|
|
6692
|
+
super();
|
|
6693
|
+
this.fixedHeightLandscape = fixedHeightLandscape;
|
|
6694
|
+
this.fixedHeightPortrait = fixedHeightPortrait;
|
|
6695
|
+
assertValidPositiveNumber(fixedHeightLandscape, "UIResizePolicyFixedHeight.fixedHeightLandscape");
|
|
6696
|
+
assertValidPositiveNumber(fixedHeightPortrait, "UIResizePolicyFixedHeight.fixedHeightPortrait");
|
|
6697
|
+
}
|
|
6698
|
+
calculateScaleInternal(width, height) {
|
|
6699
|
+
return width > height
|
|
6700
|
+
? this.fixedHeightLandscape / height
|
|
6701
|
+
: this.fixedHeightPortrait / height;
|
|
6702
|
+
}
|
|
6703
|
+
}
|
|
6704
|
+
/**
|
|
6705
|
+
* Scales by width in landscape, by height in portrait.
|
|
6706
|
+
*/
|
|
6707
|
+
class UIResizePolicyCross extends UIResizePolicy {
|
|
6708
|
+
/**
|
|
6709
|
+
* @param fixedWidthLandscape - Target width for landscape
|
|
6710
|
+
* @param fixedHeightPortrait - Target height for portrait
|
|
6711
|
+
*/
|
|
6712
|
+
constructor(fixedWidthLandscape, fixedHeightPortrait) {
|
|
6713
|
+
super();
|
|
6714
|
+
this.fixedWidthLandscape = fixedWidthLandscape;
|
|
6715
|
+
this.fixedHeightPortrait = fixedHeightPortrait;
|
|
6716
|
+
assertValidPositiveNumber(fixedWidthLandscape, "UIResizePolicyCross.fixedWidthLandscape");
|
|
6717
|
+
assertValidPositiveNumber(fixedHeightPortrait, "UIResizePolicyCross.fixedHeightPortrait");
|
|
6718
|
+
}
|
|
6719
|
+
calculateScaleInternal(width, height) {
|
|
6720
|
+
return width > height
|
|
6721
|
+
? this.fixedWidthLandscape / width
|
|
6722
|
+
: this.fixedHeightPortrait / height;
|
|
6723
|
+
}
|
|
6724
|
+
}
|
|
6725
|
+
/**
|
|
6726
|
+
* Scales by height in landscape, by width in portrait.
|
|
6727
|
+
*/
|
|
6728
|
+
class UIResizePolicyCrossInverted extends UIResizePolicy {
|
|
6729
|
+
/**
|
|
6730
|
+
* @param fixedHeightLandscape - Target height for landscape
|
|
6731
|
+
* @param fixedWidthPortrait - Target width for portrait
|
|
6732
|
+
*/
|
|
6733
|
+
constructor(fixedHeightLandscape, fixedWidthPortrait) {
|
|
6734
|
+
super();
|
|
6735
|
+
this.fixedHeightLandscape = fixedHeightLandscape;
|
|
6736
|
+
this.fixedWidthPortrait = fixedWidthPortrait;
|
|
6737
|
+
assertValidPositiveNumber(fixedHeightLandscape, "UIResizePolicyCrossInverted.fixedHeightLandscape");
|
|
6738
|
+
assertValidPositiveNumber(fixedWidthPortrait, "UIResizePolicyCrossInverted.fixedWidthPortrait");
|
|
6739
|
+
}
|
|
6740
|
+
calculateScaleInternal(width, height) {
|
|
6741
|
+
return width > height
|
|
6742
|
+
? this.fixedHeightLandscape / height
|
|
6743
|
+
: this.fixedWidthPortrait / width;
|
|
6744
|
+
}
|
|
6745
|
+
}
|
|
6746
|
+
|
|
6747
|
+
/**
|
|
6748
|
+
* UI layer that covers the full browser window.
|
|
6230
6749
|
*
|
|
6231
|
-
*
|
|
6232
|
-
*
|
|
6233
|
-
* of the actual browser window size.
|
|
6750
|
+
* Handles window resize and pointer events automatically. Scaling is controlled
|
|
6751
|
+
* by the assigned resize policy.
|
|
6234
6752
|
*
|
|
6235
|
-
* @see {@link UILayer}
|
|
6236
|
-
* @see {@link
|
|
6753
|
+
* @see {@link UILayer}
|
|
6754
|
+
* @see {@link UIResizePolicy}
|
|
6237
6755
|
*/
|
|
6238
6756
|
class UIFullscreenLayer extends UILayer {
|
|
6239
6757
|
/**
|
|
6240
|
-
* Creates a
|
|
6241
|
-
*
|
|
6242
|
-
* The layer will automatically resize to match the browser window and set up
|
|
6243
|
-
* event listeners for window resize and pointer events. Fixed dimensions
|
|
6244
|
-
* enable proportional scaling while maintaining design aspect ratios.
|
|
6245
|
-
*
|
|
6246
|
-
* @param fixedWidth - Optional fixed width for proportional scaling
|
|
6247
|
-
* @param fixedHeight - Optional fixed height for proportional scaling
|
|
6248
|
-
* @throws Will throw an error if fixed dimensions are not valid positive numbers
|
|
6249
|
-
* @see {@link assertValidPositiveNumber}
|
|
6758
|
+
* Creates a fullscreen layer and sets up window event listeners.
|
|
6250
6759
|
*/
|
|
6251
|
-
constructor(
|
|
6252
|
-
if (fixedWidth !== undefined) {
|
|
6253
|
-
assertValidPositiveNumber(fixedWidth, "UIFullscreenLayer.fixedWidth");
|
|
6254
|
-
}
|
|
6255
|
-
if (fixedHeight !== undefined) {
|
|
6256
|
-
assertValidPositiveNumber(fixedHeight, "UIFullscreenLayer.fixedHeight");
|
|
6257
|
-
}
|
|
6760
|
+
constructor() {
|
|
6258
6761
|
super(window.innerWidth, window.innerHeight);
|
|
6762
|
+
this.resizePolicy = new UIResizePolicyNone();
|
|
6259
6763
|
/**
|
|
6260
|
-
*
|
|
6261
|
-
*
|
|
6262
|
-
* Recalculates the scaling factor and updates the layer dimensions
|
|
6263
|
-
* based on the new window size and fixed dimension constraints.
|
|
6764
|
+
* Handles window resize. Updates layer dimensions according to resize policy.
|
|
6264
6765
|
*/
|
|
6265
6766
|
this._private_onResize = () => {
|
|
6266
|
-
const scale = this.
|
|
6767
|
+
const scale = this.resizePolicy.calculateScaleInternal(window.innerWidth, window.innerHeight);
|
|
6267
6768
|
this.resizeInternal(window.innerWidth * scale, window.innerHeight * scale);
|
|
6268
6769
|
};
|
|
6269
6770
|
/**
|
|
6270
|
-
*
|
|
6771
|
+
* Handles pointer down. Converts browser coordinates to layer space.
|
|
6772
|
+
* Y-coordinate is flipped to match UI coordinate system.
|
|
6271
6773
|
*
|
|
6272
|
-
*
|
|
6273
|
-
* for element positioning and applying the appropriate scaling factor.
|
|
6274
|
-
* The y-coordinate is flipped to match the UI coordinate system.
|
|
6275
|
-
*
|
|
6276
|
-
* @param event - The pointer event from the browser
|
|
6774
|
+
* @param event - Browser pointer event
|
|
6277
6775
|
*/
|
|
6278
6776
|
this._private_onClick = (event) => {
|
|
6279
|
-
const
|
|
6777
|
+
const rect = event.target instanceof HTMLElement
|
|
6280
6778
|
? event.target.getBoundingClientRect()
|
|
6281
6779
|
: null;
|
|
6282
|
-
const x =
|
|
6283
|
-
const y =
|
|
6284
|
-
|
|
6780
|
+
const x = rect ? event.clientX - rect.left : event.clientX;
|
|
6781
|
+
const y = rect
|
|
6782
|
+
? rect.bottom - event.clientY
|
|
6783
|
+
: window.innerHeight - event.clientY;
|
|
6784
|
+
const scale = this.resizePolicy.calculateScaleInternal(window.innerWidth, window.innerHeight);
|
|
6285
6785
|
this.pointerClickInternal(x * scale, y * scale);
|
|
6286
6786
|
};
|
|
6287
|
-
this._private_fixedWidthInternal = fixedWidth;
|
|
6288
|
-
this._private_fixedHeightInternal = fixedHeight;
|
|
6289
6787
|
window.addEventListener("resize", this._private_onResize);
|
|
6290
6788
|
window.addEventListener("pointerdown", this._private_onClick);
|
|
6291
6789
|
this._private_onResize();
|
|
6292
6790
|
}
|
|
6293
6791
|
/**
|
|
6294
|
-
*
|
|
6295
|
-
* @returns The fixed width in pixels, or undefined if not set
|
|
6296
|
-
*/
|
|
6297
|
-
get fixedWidth() {
|
|
6298
|
-
return this._private_fixedWidthInternal;
|
|
6299
|
-
}
|
|
6300
|
-
/**
|
|
6301
|
-
* Gets the current fixed height constraint.
|
|
6302
|
-
* @returns The fixed height in pixels, or undefined if not set
|
|
6303
|
-
*/
|
|
6304
|
-
get fixedHeight() {
|
|
6305
|
-
return this._private_fixedHeightInternal;
|
|
6306
|
-
}
|
|
6307
|
-
/**
|
|
6308
|
-
* Sets a new fixed width constraint and triggers resize recalculation.
|
|
6309
|
-
* @param value - The new fixed width in pixels, or undefined to remove constraint
|
|
6310
|
-
* @throws Will throw an error if value is not a valid positive number
|
|
6311
|
-
* @see {@link assertValidPositiveNumber}
|
|
6312
|
-
*/
|
|
6313
|
-
set fixedWidth(value) {
|
|
6314
|
-
if (value !== undefined) {
|
|
6315
|
-
assertValidPositiveNumber(value, "UIFullscreenLayer.fixedWidth");
|
|
6316
|
-
}
|
|
6317
|
-
if (value !== this._private_fixedWidthInternal) {
|
|
6318
|
-
this._private_fixedWidthInternal = value;
|
|
6319
|
-
this._private_onResize();
|
|
6320
|
-
}
|
|
6321
|
-
}
|
|
6322
|
-
/**
|
|
6323
|
-
* Sets a new fixed height constraint and triggers resize recalculation.
|
|
6324
|
-
* @param value - The new fixed height in pixels, or undefined to remove constraint
|
|
6325
|
-
* @throws Will throw an error if value is not a valid positive number
|
|
6326
|
-
* @see {@link assertValidPositiveNumber}
|
|
6327
|
-
*/
|
|
6328
|
-
set fixedHeight(value) {
|
|
6329
|
-
if (value !== undefined) {
|
|
6330
|
-
assertValidPositiveNumber(value, "UIFullscreenLayer.fixedHeight");
|
|
6331
|
-
}
|
|
6332
|
-
if (value !== this._private_fixedHeightInternal) {
|
|
6333
|
-
this._private_fixedHeightInternal = value;
|
|
6334
|
-
this._private_onResize();
|
|
6335
|
-
}
|
|
6336
|
-
}
|
|
6337
|
-
/**
|
|
6338
|
-
* Destroys the fullscreen layer by removing all event listeners.
|
|
6339
|
-
*
|
|
6340
|
-
* This method cleans up window event listeners for resize and pointer events.
|
|
6341
|
-
* After calling this method, the layer will no longer respond to window
|
|
6342
|
-
* changes and should not be used anymore.
|
|
6792
|
+
* Removes window event listeners. The layer should not be used after this.
|
|
6343
6793
|
*/
|
|
6344
6794
|
destroy() {
|
|
6345
6795
|
window.removeEventListener("resize", this._private_onResize);
|
|
6346
6796
|
window.removeEventListener("pointerdown", this._private_onClick);
|
|
6347
6797
|
}
|
|
6348
6798
|
/**
|
|
6349
|
-
* Renders the
|
|
6799
|
+
* Renders the layer.
|
|
6350
6800
|
*
|
|
6351
|
-
*
|
|
6352
|
-
*
|
|
6353
|
-
* and buffer management for fullscreen interfaces.
|
|
6354
|
-
*
|
|
6355
|
-
* @param renderer - The WebGL renderer instance
|
|
6356
|
-
* @param deltaTime - Time elapsed since the last frame in seconds
|
|
6357
|
-
* @throws Will throw an error if deltaTime is not a valid number
|
|
6358
|
-
* @see {@link assertValidNumber}
|
|
6801
|
+
* @param renderer - WebGL renderer
|
|
6802
|
+
* @param deltaTime - Time since last frame in seconds
|
|
6359
6803
|
*/
|
|
6360
6804
|
render(renderer, deltaTime) {
|
|
6361
6805
|
assertValidNumber(deltaTime, "UIFullscreenLayer.deltaTime");
|
|
6362
6806
|
super.renderInternal(renderer, deltaTime);
|
|
6363
6807
|
}
|
|
6364
6808
|
/**
|
|
6365
|
-
* Projects
|
|
6809
|
+
* Projects 3D world position to 2D layer coordinates.
|
|
6366
6810
|
*
|
|
6367
|
-
* @param position -
|
|
6368
|
-
* @param camera -
|
|
6369
|
-
* @returns
|
|
6811
|
+
* @param position - 3D world position
|
|
6812
|
+
* @param camera - Camera for projection
|
|
6813
|
+
* @returns 2D position in layer space
|
|
6370
6814
|
*/
|
|
6371
6815
|
projectWorldPosition(position, camera) {
|
|
6372
6816
|
const projectedPosition = position.project(camera);
|
|
@@ -6374,39 +6818,6 @@ class UIFullscreenLayer extends UILayer {
|
|
|
6374
6818
|
projectedPosition.y = MathUtils.mapLinear(projectedPosition.y, -1, 1, this.y, this.height);
|
|
6375
6819
|
return projectedPosition;
|
|
6376
6820
|
}
|
|
6377
|
-
/**
|
|
6378
|
-
* Calculates the scaling factor based on orientation and fixed dimensions.
|
|
6379
|
-
*
|
|
6380
|
-
* The scaling factor is determined by the current orientation and which
|
|
6381
|
-
* fixed dimension constraint is active. In horizontal orientation, fixed
|
|
6382
|
-
* width takes precedence; in vertical orientation, fixed height takes precedence.
|
|
6383
|
-
*
|
|
6384
|
-
* @returns The scaling factor to apply to window dimensions
|
|
6385
|
-
*/
|
|
6386
|
-
_private_calculateScale() {
|
|
6387
|
-
if (this.orientation === UIOrientation.HORIZONTAL) {
|
|
6388
|
-
if (this.fixedWidth !== undefined) {
|
|
6389
|
-
return this.fixedWidth / window.innerWidth;
|
|
6390
|
-
}
|
|
6391
|
-
else if (this.fixedHeight !== undefined) {
|
|
6392
|
-
return this.fixedHeight / window.innerHeight;
|
|
6393
|
-
}
|
|
6394
|
-
else {
|
|
6395
|
-
return 1;
|
|
6396
|
-
}
|
|
6397
|
-
}
|
|
6398
|
-
else {
|
|
6399
|
-
if (this.fixedHeight !== undefined) {
|
|
6400
|
-
return this.fixedHeight / window.innerHeight;
|
|
6401
|
-
}
|
|
6402
|
-
else if (this.fixedWidth !== undefined) {
|
|
6403
|
-
return this.fixedWidth / window.innerWidth;
|
|
6404
|
-
}
|
|
6405
|
-
else {
|
|
6406
|
-
return 1;
|
|
6407
|
-
}
|
|
6408
|
-
}
|
|
6409
|
-
}
|
|
6410
6821
|
}
|
|
6411
6822
|
|
|
6412
6823
|
const INSTANCED_GEOMETRY = (() => {
|
|
@@ -6811,5 +7222,5 @@ function isUITextSpan(obj) {
|
|
|
6811
7222
|
(!("style" in obj) || isUITextStyle(obj.style)));
|
|
6812
7223
|
}
|
|
6813
7224
|
|
|
6814
|
-
export { UIAnchor, UIAspectConstraint, UIColor, UIColorEvent, UIConstraint, UIConstraint2DBuilder, UICoverConstraintBuilder, UICustomConstraint, UIDummy, UIElement, UIExpression, UIFitConstraintBuilder, UIFullscreenLayer, UIGenericInstancedPlane, UIHeightConstraint, UIHorizontalDistanceConstraint, UIHorizontalProportionConstraint, UIImage, UIInputEvent, UILayer, UILayerEvent, UIMicro, UIMicroAnchorMode, UIMode, UINineSlice, UIOrientation, UIPriority, UIProgress, UIProgressMaskFunction, UIRelation, UIScene, UISceneUpdateMode, UISingleParameterConstraint, UIText, UITransparencyMode, UIVerticalDistanceConstraint, UIVerticalProportionConstraint, UIWidthConstraint, convertPriority, convertRelation, isUITextSpan, isUITextStyle, resolveOrientation, resolvePriority, resolveRelation, resolveTextPadding, resolveTextStyle };
|
|
7225
|
+
export { UIAnchor, UIAnimatedImage, UIAnimatedImageEvent, UIAspectConstraint, UIColor, UIColorEvent, UIConstraint, UIConstraint2DBuilder, UICoverConstraintBuilder, UICustomConstraint, UIDummy, UIElement, UIExpression, UIFitConstraintBuilder, UIFullscreenLayer, UIGenericInstancedPlane, UIGraphics, UIHeightConstraint, UIHorizontalDistanceConstraint, UIHorizontalProportionConstraint, UIImage, UIInputEvent, UILayer, UILayerEvent, UIMicro, UIMicroAnchorMode, UIMicroEvent, UIMode, UINineSlice, UIOrientation, UIPriority, UIProgress, UIProgressMaskFunction, UIRelation, UIResizePolicy, UIResizePolicyCross, UIResizePolicyCrossInverted, UIResizePolicyFixedHeight, UIResizePolicyFixedWidth, UIResizePolicyNone, UIScene, UISceneUpdateMode, UISingleParameterConstraint, UIText, UITransparencyMode, UIVerticalDistanceConstraint, UIVerticalProportionConstraint, UIWidthConstraint, convertPriority, convertRelation, isUITextSpan, isUITextStyle, resolveOrientation, resolvePriority, resolveRelation, resolveTextPadding, resolveTextStyle };
|
|
6815
7226
|
//# sourceMappingURL=index.js.map
|