laymur 0.25.2 → 0.27.0
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/README.md +114 -34
- package/dist/core/constraints/UICustomConstraint.d.ts +1 -1
- package/dist/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.js +1 -1
- package/dist/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.js +1 -1
- package/dist/core/constraints/builders/UIConstraint2DBuilder.d.ts +2 -3
- package/dist/core/elements/UIAnchor/UIAnchor.d.ts +2 -2
- package/dist/core/elements/UIAnchor/UIAnchor.js +3 -2
- package/dist/core/elements/UIAnimatedImage/UIAnimatedImage.d.ts +2 -2
- package/dist/core/elements/UIAnimatedImage/UIAnimatedImage.js +24 -12
- package/dist/core/elements/UIDummy/UIDummy.Internal.d.ts +13 -0
- package/dist/core/elements/UIDummy/UIDummy.d.ts +74 -5
- package/dist/core/elements/UIDummy/UIDummy.js +222 -29
- package/dist/core/elements/UIElement/UIElement.Internal.d.ts +1 -1
- package/dist/core/elements/UIElement/UIElement.d.ts +37 -1
- package/dist/core/elements/UIElement/UIElement.js +84 -6
- package/dist/core/elements/UIGraphics/UIGraphics.Internal.d.ts +1 -1
- package/dist/core/elements/UIGraphics/UIGraphics.d.ts +1 -1
- package/dist/core/elements/UIGraphics/UIGraphics.js +4 -4
- package/dist/core/elements/UIImage/UIImage.d.ts +2 -2
- package/dist/core/elements/UIImage/UIImage.js +10 -8
- package/dist/core/elements/UINineSlice/UINineSlice.d.ts +4 -4
- package/dist/core/elements/UINineSlice/UINineSlice.js +11 -9
- package/dist/core/elements/UIProgress/UIProgress.d.ts +2 -2
- package/dist/core/elements/UIProgress/UIProgress.js +17 -15
- package/dist/core/elements/UIScene/UIScene.Internal.d.ts +1 -1
- package/dist/core/elements/UIScene/UIScene.d.ts +3 -2
- package/dist/core/elements/UIScene/UIScene.js +21 -14
- package/dist/core/elements/UIText/UIText.Measuring.d.ts +1 -1
- package/dist/core/elements/UIText/UIText.d.ts +3 -3
- package/dist/core/elements/UIText/UIText.js +8 -8
- package/dist/core/index.d.ts +60 -11
- package/dist/core/index.js +22 -7
- package/dist/core/layers/UILayer/UILayer.d.ts +45 -5
- package/dist/core/layers/UILayer/UILayer.js +103 -10
- package/dist/core/layers/UIViewportLayer/UIViewportLayer.Internal.d.ts +27 -0
- package/dist/core/layers/{UIFullscreenLayer/UIFullscreenLayer.Internal.js → UIViewportLayer/UIViewportLayer.Internal.js} +1 -1
- package/dist/core/layers/UIViewportLayer/UIViewportLayer.d.ts +98 -0
- package/dist/core/layers/UIViewportLayer/UIViewportLayer.js +251 -0
- package/dist/core/miscellaneous/UIAffineMatrix3.d.ts +13 -0
- package/dist/core/miscellaneous/UIAffineMatrix3.js +13 -0
- package/dist/core/miscellaneous/area/UIArea.d.ts +10 -1
- package/dist/core/miscellaneous/area/UIArea.js +4 -1
- package/dist/core/miscellaneous/area/UIAreaCircle.d.ts +1 -0
- package/dist/core/miscellaneous/area/UIAreaCircle.js +0 -1
- package/dist/core/miscellaneous/area/UIAreaPolygon.d.ts +1 -0
- package/dist/core/miscellaneous/area/UIAreaPolygon.js +0 -1
- package/dist/core/miscellaneous/area/UIAreaRectangle.d.ts +1 -0
- package/dist/core/miscellaneous/area/UIAreaRectangle.js +0 -1
- package/dist/core/miscellaneous/area/UIAreaRoundedRectangle.d.ts +1 -0
- package/dist/core/miscellaneous/area/UIAreaRoundedRectangle.js +0 -1
- package/dist/core/miscellaneous/asserts.d.ts +23 -0
- package/dist/core/miscellaneous/asserts.js +44 -0
- package/dist/core/miscellaneous/canvas.js +7 -2
- package/dist/core/miscellaneous/color/UIColor.js +5 -2
- package/dist/core/miscellaneous/computeTransform.d.ts +12 -0
- package/dist/core/miscellaneous/computeTransform.js +20 -0
- package/dist/core/miscellaneous/context-monitor/UIContextMonitor.d.ts +1 -0
- package/dist/core/miscellaneous/context-monitor/UIContextMonitor.js +60 -0
- package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.d.ts +17 -3
- package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.js +88 -26
- package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Layout.d.ts +9 -0
- package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Layout.js +29 -6
- package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.js +51 -11
- package/dist/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.Internal.d.ts +2 -0
- package/dist/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.js +47 -6
- package/dist/core/miscellaneous/generic-plane/shared.d.ts +15 -3
- package/dist/core/miscellaneous/generic-plane/shared.js +38 -7
- package/dist/core/miscellaneous/generic-plane/varyingPacking.d.ts +46 -0
- package/dist/core/miscellaneous/generic-plane/varyingPacking.js +170 -0
- package/dist/core/miscellaneous/mask/UIMask.Internal.d.ts +61 -0
- package/dist/core/miscellaneous/mask/UIMask.Internal.js +56 -0
- package/dist/core/miscellaneous/mask/UIMask.d.ts +84 -0
- package/dist/core/miscellaneous/mask/UIMask.js +265 -0
- package/dist/core/miscellaneous/mask/UIMaskMaterialPatch.d.ts +50 -0
- package/dist/core/miscellaneous/mask/UIMaskMaterialPatch.js +233 -0
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunction.d.ts +10 -1
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunction.js +7 -1
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.d.ts +2 -0
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.js +0 -1
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionDirectional.d.ts +2 -0
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionDirectional.js +0 -1
- package/dist/core/miscellaneous/micro/UIMicro.Internal.d.ts +3 -0
- package/dist/core/miscellaneous/micro/UIMicro.Internal.js +1 -0
- package/dist/core/miscellaneous/micro/UIMicro.d.ts +18 -1
- package/dist/core/miscellaneous/micro/UIMicro.js +23 -2
- package/dist/core/miscellaneous/resize-policy/UIResizePolicy.d.ts +19 -1
- package/dist/core/miscellaneous/resize-policy/UIResizePolicy.js +16 -3
- package/dist/core/miscellaneous/resize-policy/UIResizePolicyCover.js +2 -2
- package/dist/core/miscellaneous/resize-policy/UIResizePolicyCross.js +2 -2
- package/dist/core/miscellaneous/resize-policy/UIResizePolicyCrossInverted.js +2 -2
- package/dist/core/miscellaneous/resize-policy/UIResizePolicyFit.js +2 -2
- package/dist/core/miscellaneous/resize-policy/UIResizePolicyFixedHeight.js +2 -2
- package/dist/core/miscellaneous/resize-policy/UIResizePolicyFixedWidth.js +2 -2
- package/dist/core/miscellaneous/text-style/UITextStyle.js +2 -2
- package/dist/core/miscellaneous/texture/UITextureView.d.ts +6 -2
- package/dist/core/miscellaneous/texture/UITextureView.js +13 -9
- package/dist/core/miscellaneous/viewport/UIElementViewport.d.ts +31 -0
- package/dist/core/miscellaneous/viewport/UIElementViewport.js +54 -0
- package/dist/core/miscellaneous/viewport/UIViewport.d.ts +37 -0
- package/dist/core/miscellaneous/viewport/UIViewport.js +31 -0
- package/dist/core/miscellaneous/viewport/UIWindowViewport.d.ts +13 -0
- package/dist/core/miscellaneous/viewport/UIWindowViewport.js +25 -0
- package/dist/core/miscellaneous/webglCapabilities.js +61 -55
- package/dist/core/shaders/UIMask.d.ts +15 -0
- package/dist/core/shaders/UIMask.js +45 -0
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.Internal.d.ts +36 -5
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.d.ts +23 -2
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.js +153 -15
- package/dist/core/wrappers/UISceneWrapper/UISceneWrapper.Internal.d.ts +3 -1
- package/dist/core/wrappers/UISceneWrapper/UISceneWrapper.d.ts +1 -0
- package/dist/core/wrappers/UISceneWrapper/UISceneWrapper.js +3 -0
- package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.Internal.d.ts +2 -0
- package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.d.ts +3 -0
- package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.js +36 -16
- package/dist/debug/UIAspectDebug.js +4 -0
- package/dist/debug/UIHeightDebug.js +4 -0
- package/dist/debug/UIHorizontalDistanceDebug.js +5 -0
- package/dist/debug/UIHorizontalInterpolationDebug.js +5 -0
- package/dist/debug/UILayerDebug.d.ts +7 -0
- package/dist/debug/UILayerDebug.js +21 -0
- package/dist/debug/UIVerticalDistanceDebug.js +5 -0
- package/dist/debug/UIVerticalInterpolationDebug.js +5 -0
- package/dist/debug/UIWidthDebug.js +4 -0
- package/dist/debug/index.d.ts +2 -0
- package/dist/particles/behaviorModules/UIBehaviorDirectionalGravity.d.ts +8 -1
- package/dist/particles/behaviorModules/UIBehaviorDirectionalGravity.js +0 -2
- package/dist/particles/behaviorModules/UIBehaviorModule.d.ts +12 -2
- package/dist/particles/behaviorModules/UIBehaviorModule.js +2 -1
- package/dist/particles/behaviorModules/UIBehaviorPointGravity.d.ts +8 -1
- package/dist/particles/behaviorModules/UIBehaviorPointGravity.js +13 -12
- package/dist/particles/behaviorModules/UIBehaviorScaleOscillation.d.ts +7 -0
- package/dist/particles/behaviorModules/UIBehaviorScaleOscillation.js +6 -6
- package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.d.ts +7 -0
- package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.js +4 -5
- package/dist/particles/behaviorModules/UIBehaviorTorqueDamping.d.ts +8 -1
- package/dist/particles/behaviorModules/UIBehaviorTorqueDamping.js +8 -10
- package/dist/particles/behaviorModules/UIBehaviorTorqueNoise.d.ts +10 -2
- package/dist/particles/behaviorModules/UIBehaviorTorqueNoise.js +8 -7
- package/dist/particles/behaviorModules/UIBehaviorVelocityDamping.d.ts +7 -0
- package/dist/particles/behaviorModules/UIBehaviorVelocityDamping.js +8 -10
- package/dist/particles/behaviorModules/UIBehaviorVelocityNoise.d.ts +13 -4
- package/dist/particles/behaviorModules/UIBehaviorVelocityNoise.js +12 -10
- package/dist/particles/elements/UIEmitter.Internal.d.ts +21 -1
- package/dist/particles/elements/UIEmitter.Internal.js +6 -0
- package/dist/particles/elements/UIEmitter.d.ts +20 -11
- package/dist/particles/elements/UIEmitter.js +100 -54
- package/dist/particles/index.d.ts +7 -1
- package/dist/particles/index.js +4 -0
- package/dist/particles/instancedParticle/UIInstancedParticle.Internal.d.ts +19 -4
- package/dist/particles/instancedParticle/UIInstancedParticle.Internal.js +117 -83
- package/dist/particles/instancedParticle/UIInstancedParticle.d.ts +8 -0
- package/dist/particles/instancedParticle/UIInstancedParticle.js +41 -4
- package/dist/particles/miscellaneous/miscellaneous.d.ts +34 -0
- package/dist/particles/miscellaneous/miscellaneous.js +72 -0
- package/dist/particles/renderingModules/UIRenderingColorOverLife.d.ts +4 -0
- package/dist/particles/renderingModules/UIRenderingColorOverLife.js +2 -4
- package/dist/particles/renderingModules/UIRenderingColorOverVelocity.d.ts +4 -0
- package/dist/particles/renderingModules/UIRenderingColorOverVelocity.js +2 -5
- package/dist/particles/renderingModules/UIRenderingModule.d.ts +11 -1
- package/dist/particles/renderingModules/UIRenderingModule.js +4 -1
- package/dist/particles/renderingModules/UIRenderingTexture.d.ts +4 -0
- package/dist/particles/renderingModules/UIRenderingTexture.js +2 -1
- package/dist/particles/shaders/UIRenderingColorOverLife.d.ts +1 -2
- package/dist/particles/shaders/UIRenderingColorOverLife.js +5 -3
- package/dist/particles/shaders/UIRenderingColorOverVelocity.d.ts +1 -9
- package/dist/particles/shaders/UIRenderingColorOverVelocity.js +6 -13
- package/dist/particles/spawnModules/UISpawnModule.d.ts +16 -1
- package/dist/particles/spawnModules/UISpawnModule.js +3 -1
- package/dist/particles/spawnModules/UISpawnOffset.d.ts +7 -0
- package/dist/particles/spawnModules/UISpawnOffset.js +0 -2
- package/dist/particles/spawnModules/UISpawnRandomLifetime.d.ts +8 -1
- package/dist/particles/spawnModules/UISpawnRandomLifetime.js +5 -7
- package/dist/particles/spawnModules/UISpawnRandomRotation.d.ts +7 -0
- package/dist/particles/spawnModules/UISpawnRandomRotation.js +5 -5
- package/dist/particles/spawnModules/UISpawnRandomScale.d.ts +7 -0
- package/dist/particles/spawnModules/UISpawnRandomScale.js +4 -5
- package/dist/particles/spawnModules/UISpawnRandomTorque.d.ts +7 -0
- package/dist/particles/spawnModules/UISpawnRandomTorque.js +5 -5
- package/dist/particles/spawnModules/UISpawnRandomVelocity.d.ts +7 -0
- package/dist/particles/spawnModules/UISpawnRandomVelocity.js +6 -6
- package/dist/particles/spawnModules/UISpawnRectangle.d.ts +7 -0
- package/dist/particles/spawnModules/UISpawnRectangle.js +6 -6
- package/package.json +13 -4
- package/dist/core/layers/UIFullscreenLayer/UIFullscreenLayer.Internal.d.ts +0 -21
- package/dist/core/layers/UIFullscreenLayer/UIFullscreenLayer.d.ts +0 -63
- package/dist/core/layers/UIFullscreenLayer/UIFullscreenLayer.js +0 -144
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Ferrsign1 } from "ferrsign";
|
|
2
|
-
import { MathUtils } from "three";
|
|
2
|
+
import { MathUtils, Matrix4 } from "three";
|
|
3
3
|
import { UIAreaRectangle } from "../../miscellaneous/area/UIAreaRectangle.js";
|
|
4
4
|
import { assertValidNumber, assertValidPositiveNumber } from "../../miscellaneous/asserts.js";
|
|
5
|
+
import { computeTransformMatrix } from "../../miscellaneous/computeTransform.js";
|
|
5
6
|
import { isUIModeInteractive, UIMode } from "../../miscellaneous/UIMode.js";
|
|
6
7
|
import { UIPriority } from "../../miscellaneous/UIPriority.js";
|
|
7
8
|
import { UIAnchor } from "../UIAnchor/UIAnchor.js";
|
|
8
9
|
import { DUMMY_DEFAULT_HEIGHT, DUMMY_DEFAULT_MODE, DUMMY_DEFAULT_WIDTH, DUMMY_DEFAULT_Z_INDEX, } from "./UIDummy.Internal.js";
|
|
10
|
+
const TEMP_INPUT_TRANSFORM = new Matrix4();
|
|
9
11
|
/** Rectangular area with dimensions but no rendering */
|
|
10
12
|
export class UIDummy extends UIAnchor {
|
|
11
13
|
/**
|
|
@@ -20,28 +22,64 @@ export class UIDummy extends UIAnchor {
|
|
|
20
22
|
assertValidPositiveNumber(w, "UIDummy.constructor.width");
|
|
21
23
|
assertValidPositiveNumber(h, "UIDummy.constructor.height");
|
|
22
24
|
super(layer, options);
|
|
23
|
-
this.
|
|
25
|
+
this.pointers = new Map();
|
|
26
|
+
this.maskInternal = null;
|
|
24
27
|
this.signalPointerPressedInternal = new Ferrsign1();
|
|
25
28
|
this.signalPointerMovedInternal = new Ferrsign1();
|
|
26
29
|
this.signalPointerReleasedInternal = new Ferrsign1();
|
|
27
30
|
this.signalPointerEnteredInternal = new Ferrsign1();
|
|
28
31
|
this.signalPointerLeftInternal = new Ferrsign1();
|
|
32
|
+
this.signalPointerCancelledInternal = new Ferrsign1();
|
|
33
|
+
this.signalPointerClickedInternal = new Ferrsign1();
|
|
34
|
+
this.signalPointerDraggedInternal = new Ferrsign1();
|
|
29
35
|
this.catchPointerDown = (x, y, identifier) => {
|
|
30
|
-
|
|
36
|
+
const state = this.trackPointer(x, y, identifier, this.signalPointerPressedInternal);
|
|
37
|
+
const caught = this.catches(state);
|
|
38
|
+
if (caught) {
|
|
39
|
+
state.pressed = true;
|
|
40
|
+
}
|
|
41
|
+
this.forgetIfUntracked(identifier, state);
|
|
42
|
+
return caught;
|
|
31
43
|
};
|
|
32
44
|
this.catchPointerMove = (x, y, identifier) => {
|
|
33
|
-
|
|
45
|
+
const state = this.trackPointer(x, y, identifier, this.signalPointerMovedInternal);
|
|
46
|
+
if (state.pressed) {
|
|
47
|
+
this.emitPointer(this.signalPointerDraggedInternal, state, identifier);
|
|
48
|
+
}
|
|
49
|
+
this.forgetIfUntracked(identifier, state);
|
|
50
|
+
return this.catches(state);
|
|
34
51
|
};
|
|
35
52
|
this.catchPointerUp = (x, y, identifier) => {
|
|
36
|
-
|
|
53
|
+
const state = this.trackPointer(x, y, identifier, this.signalPointerReleasedInternal);
|
|
54
|
+
const caught = this.catches(state);
|
|
55
|
+
this.endPointer(identifier, state, state.inside);
|
|
56
|
+
return caught;
|
|
57
|
+
};
|
|
58
|
+
/** Signals of a cancel carry the last known position */
|
|
59
|
+
this.catchPointerCancel = (identifier) => {
|
|
60
|
+
const state = this.pointers.get(identifier);
|
|
61
|
+
if (state !== undefined) {
|
|
62
|
+
this.endPointer(identifier, state, false);
|
|
63
|
+
}
|
|
37
64
|
};
|
|
38
65
|
this.interactionArea = options?.interactionArea ?? new UIAreaRectangle(0, 0, 1, 1);
|
|
39
66
|
this.modeInternal = options?.mode ?? DUMMY_DEFAULT_MODE;
|
|
40
67
|
this.inputWrapper = this.layer.inputWrapper;
|
|
41
68
|
this.wVariable = this.solverWrapper.createVariable(w, UIPriority.P6);
|
|
42
69
|
this.hVariable = this.solverWrapper.createVariable(h, UIPriority.P6);
|
|
43
|
-
this.catcherHandler = this.inputWrapper.createInputCatcher(
|
|
70
|
+
this.catcherHandler = this.inputWrapper.createInputCatcher({
|
|
71
|
+
catchPointerDown: this.catchPointerDown,
|
|
72
|
+
catchPointerMove: this.catchPointerMove,
|
|
73
|
+
catchPointerUp: this.catchPointerUp,
|
|
74
|
+
catchPointerCancel: this.catchPointerCancel,
|
|
75
|
+
}, DUMMY_DEFAULT_Z_INDEX);
|
|
44
76
|
this.inputWrapper.setActive(this.catcherHandler, isUIModeInteractive(this.modeInternal));
|
|
77
|
+
const mask = options?.mask ?? null;
|
|
78
|
+
if (mask !== null) {
|
|
79
|
+
this.assertValidMask(mask, "UIDummy.constructor.options.mask");
|
|
80
|
+
this.maskInternal = mask;
|
|
81
|
+
mask.attach(this);
|
|
82
|
+
}
|
|
45
83
|
}
|
|
46
84
|
/** Width in world units */
|
|
47
85
|
get width() {
|
|
@@ -78,7 +116,15 @@ export class UIDummy extends UIAnchor {
|
|
|
78
116
|
get zIndex() {
|
|
79
117
|
return this.inputWrapper.getZIndex(this.catcherHandler);
|
|
80
118
|
}
|
|
81
|
-
/**
|
|
119
|
+
/** Mask clipping the element (input only, for an element that draws nothing); null for none */
|
|
120
|
+
get mask() {
|
|
121
|
+
return this.maskInternal;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Signal fired when pointer is pressed over the element. An element that catches the press
|
|
125
|
+
* (any interactive mode but INTERACTIVE_TRANSPARENT) holds the pointer until it is released:
|
|
126
|
+
* then exactly one of `signalPointerClicked` and `signalPointerCancelled` follows.
|
|
127
|
+
*/
|
|
82
128
|
get signalPointerPressed() {
|
|
83
129
|
return this.signalPointerPressedInternal;
|
|
84
130
|
}
|
|
@@ -94,10 +140,29 @@ export class UIDummy extends UIAnchor {
|
|
|
94
140
|
get signalPointerEntered() {
|
|
95
141
|
return this.signalPointerEnteredInternal;
|
|
96
142
|
}
|
|
97
|
-
/**
|
|
143
|
+
/**
|
|
144
|
+
* Signal fired when pointer leaves element. A released or cancelled pointer leaves too: a
|
|
145
|
+
* mouse still over the element enters again on its next move.
|
|
146
|
+
*/
|
|
98
147
|
get signalPointerLeft() {
|
|
99
148
|
return this.signalPointerLeftInternal;
|
|
100
149
|
}
|
|
150
|
+
/** Signal fired when a pointer pressed on the element is released over it */
|
|
151
|
+
get signalPointerClicked() {
|
|
152
|
+
return this.signalPointerClickedInternal;
|
|
153
|
+
}
|
|
154
|
+
/** Signal fired when a pointer pressed on the element moves, over the element or not */
|
|
155
|
+
get signalPointerDragged() {
|
|
156
|
+
return this.signalPointerDraggedInternal;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Signal fired when a press on the element ends without a click: released outside the
|
|
160
|
+
* element, cancelled by the browser (a system gesture, scrolling, a popup), or the element
|
|
161
|
+
* stopped taking input. Reset what was started on press. The position is the last known one.
|
|
162
|
+
*/
|
|
163
|
+
get signalPointerCancelled() {
|
|
164
|
+
return this.signalPointerCancelledInternal;
|
|
165
|
+
}
|
|
101
166
|
/** Unique depth of the element among the elements of the layer, derived from `zIndex` */
|
|
102
167
|
get renderDepth() {
|
|
103
168
|
return this.inputWrapper.getDepth(this.catcherHandler);
|
|
@@ -145,6 +210,9 @@ export class UIDummy extends UIAnchor {
|
|
|
145
210
|
const newInteractivity = isUIModeInteractive(value);
|
|
146
211
|
this.inputWrapper.setActive(this.catcherHandler, newInteractivity);
|
|
147
212
|
this.modeInternal = value;
|
|
213
|
+
if (!newInteractivity) {
|
|
214
|
+
this.dropPointers();
|
|
215
|
+
}
|
|
148
216
|
}
|
|
149
217
|
}
|
|
150
218
|
/**
|
|
@@ -156,35 +224,160 @@ export class UIDummy extends UIAnchor {
|
|
|
156
224
|
assertValidNumber(value, "UIDummy.zIndex");
|
|
157
225
|
this.inputWrapper.setZIndex(this.catcherHandler, value);
|
|
158
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Mask clipping the element (input only, for an element that draws nothing); null for none
|
|
229
|
+
* @throws If the mask is destroyed or belongs to another layer
|
|
230
|
+
*/
|
|
231
|
+
set mask(value) {
|
|
232
|
+
this.assertNotDestroyed("UIDummy.mask");
|
|
233
|
+
if (value === this.maskInternal) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
if (value !== null) {
|
|
237
|
+
this.assertValidMask(value, "UIDummy.mask");
|
|
238
|
+
}
|
|
239
|
+
this.maskInternal?.detach(this);
|
|
240
|
+
this.maskInternal = value;
|
|
241
|
+
value?.attach(this);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Transform of the full element rectangle as drawn: maps the unit square
|
|
245
|
+
* (0,0 = bottom-left, 1,1 = top-right) to layer coordinates.
|
|
246
|
+
* @param includeMicro Whether to apply the micro transform, if the element has one
|
|
247
|
+
* @param result Matrix to write into
|
|
248
|
+
* @param depth Translation z of the result, such as the render depth
|
|
249
|
+
* @returns The result matrix
|
|
250
|
+
*/
|
|
251
|
+
computeVisualTransform(includeMicro, result, depth = 0) {
|
|
252
|
+
const micro = includeMicro ? this.getMicro() : undefined;
|
|
253
|
+
if (micro === undefined) {
|
|
254
|
+
return result.makeScale(this.width, this.height, 1).setPosition(this.x, this.y, depth);
|
|
255
|
+
}
|
|
256
|
+
return result.copy(computeTransformMatrix(this.x, this.y, this.width, this.height, depth, micro.x, micro.y, micro.anchorX, micro.anchorY, micro.scaleX, micro.scaleY, micro.rotation, micro.anchorMode));
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Takes the mask off the element when the mask is destroyed. Works on a destroyed element
|
|
260
|
+
* too, since a mask may be destroyed as part of destroying its own source.
|
|
261
|
+
* @internal
|
|
262
|
+
*/
|
|
263
|
+
releaseMask(mask) {
|
|
264
|
+
if (this.maskInternal === mask) {
|
|
265
|
+
this.maskInternal = null;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Micro transform the element is drawn with. Elements that have one override this, so that
|
|
270
|
+
* input and masks follow it; see {@link UIMicro.affectsInput}.
|
|
271
|
+
*/
|
|
272
|
+
getMicro() {
|
|
273
|
+
return undefined;
|
|
274
|
+
}
|
|
159
275
|
getSolverVariables() {
|
|
160
276
|
return [...super.getSolverVariables(), this.wVariable, this.hVariable];
|
|
161
277
|
}
|
|
162
278
|
destroyInternal() {
|
|
279
|
+
// A press held by the element still ends with a cancel, and its pointers leave it
|
|
280
|
+
this.dropPointers();
|
|
281
|
+
this.maskInternal?.detach(this);
|
|
282
|
+
this.maskInternal = null;
|
|
163
283
|
this.solverWrapper.removeVariable(this.hVariable);
|
|
164
284
|
this.solverWrapper.removeVariable(this.wVariable);
|
|
165
285
|
this.inputWrapper.destroyInputCatcher(this.catcherHandler);
|
|
166
286
|
super.destroyInternal();
|
|
167
287
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
288
|
+
/**
|
|
289
|
+
* Updates what the element knows of a pointer: fires the signal of the event if the pointer
|
|
290
|
+
* is over the element, then entered or left if that changed.
|
|
291
|
+
*/
|
|
292
|
+
trackPointer(x, y, identifier, signal) {
|
|
293
|
+
assertValidNumber(x, "UIDummy.trackPointer.x");
|
|
294
|
+
assertValidNumber(y, "UIDummy.trackPointer.y");
|
|
295
|
+
assertValidNumber(identifier, "UIDummy.trackPointer.identifier");
|
|
296
|
+
let state = this.pointers.get(identifier);
|
|
297
|
+
if (state === undefined) {
|
|
298
|
+
state = { x, y, inside: false, pressed: false };
|
|
299
|
+
this.pointers.set(identifier, state);
|
|
300
|
+
}
|
|
301
|
+
state.x = x;
|
|
302
|
+
state.y = y;
|
|
303
|
+
const inside = this.isInputPointInside(x, y);
|
|
304
|
+
if (inside) {
|
|
305
|
+
this.emitPointer(signal, state, identifier);
|
|
306
|
+
}
|
|
307
|
+
if (inside !== state.inside) {
|
|
308
|
+
state.inside = inside;
|
|
309
|
+
this.emitPointer(inside ? this.signalPointerEnteredInternal : this.signalPointerLeftInternal, state, identifier);
|
|
310
|
+
}
|
|
311
|
+
return state;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Ends a pointer: a press on the element ends as a click or as cancelled, and the pointer
|
|
315
|
+
* leaves. A released or cancelled pointer is forgotten, so that a touch, which never comes
|
|
316
|
+
* back with the same identifier, does not stay over the element.
|
|
317
|
+
*/
|
|
318
|
+
endPointer(identifier, state, clicked) {
|
|
319
|
+
this.pointers.delete(identifier);
|
|
320
|
+
if (state.pressed) {
|
|
321
|
+
state.pressed = false;
|
|
322
|
+
this.emitPointer(clicked ? this.signalPointerClickedInternal : this.signalPointerCancelledInternal, state, identifier);
|
|
323
|
+
}
|
|
324
|
+
if (state.inside) {
|
|
325
|
+
state.inside = false;
|
|
326
|
+
this.emitPointer(this.signalPointerLeftInternal, state, identifier);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/** Ends every pointer, for an element that stops taking input */
|
|
330
|
+
dropPointers() {
|
|
331
|
+
for (const [identifier, state] of [...this.pointers]) {
|
|
332
|
+
this.endPointer(identifier, state, false);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
forgetIfUntracked(identifier, state) {
|
|
336
|
+
if (!state.inside && !state.pressed) {
|
|
337
|
+
this.pointers.delete(identifier);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
/** Whether the event stops at the element: catchers below do not get it */
|
|
341
|
+
catches(state) {
|
|
342
|
+
return state.inside && this.modeInternal !== UIMode.INTERACTIVE_TRANSPARENT;
|
|
343
|
+
}
|
|
344
|
+
emitPointer(signal, state, identifier) {
|
|
345
|
+
signal.emit({ x: state.x, y: state.y, identifier, element: this });
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Whether a point in layer coordinates hits the element: it is in the visible part of the
|
|
349
|
+
* mask, if the mask clips input, and in the interaction area of the rectangle as drawn, when
|
|
350
|
+
* micro affects input.
|
|
351
|
+
*/
|
|
352
|
+
isInputPointInside(x, y) {
|
|
353
|
+
const mask = this.maskInternal;
|
|
354
|
+
if (mask !== null && mask.clipInput && !mask.containsPoint(x, y)) {
|
|
355
|
+
return false;
|
|
356
|
+
}
|
|
357
|
+
const micro = this.getMicro();
|
|
358
|
+
if (micro?.affectsInput !== true) {
|
|
359
|
+
return this.interactionArea.contains(MathUtils.mapLinear(x, this.x, this.oppositeX, 0, 1), MathUtils.mapLinear(y, this.y, this.oppositeY, 0, 1));
|
|
360
|
+
}
|
|
361
|
+
const e = this.computeVisualTransform(true, TEMP_INPUT_TRANSFORM).elements;
|
|
362
|
+
const axisXx = e[0];
|
|
363
|
+
const axisXy = e[1];
|
|
364
|
+
const axisYx = e[4];
|
|
365
|
+
const axisYy = e[5];
|
|
366
|
+
const determinant = axisXx * axisYy - axisYx * axisXy;
|
|
367
|
+
// Scaled to nothing: the element is not on screen
|
|
368
|
+
if (Math.abs(determinant) < Number.EPSILON) {
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
const deltaX = x - e[12];
|
|
372
|
+
const deltaY = y - e[13];
|
|
373
|
+
return this.interactionArea.contains((deltaX * axisYy - axisYx * deltaY) / determinant, (axisXx * deltaY - deltaX * axisXy) / determinant);
|
|
374
|
+
}
|
|
375
|
+
assertValidMask(mask, subject) {
|
|
376
|
+
if (mask.destroyed) {
|
|
377
|
+
throw new Error(`${subject}: mask is destroyed`);
|
|
378
|
+
}
|
|
379
|
+
if (mask.layer !== this.layer) {
|
|
380
|
+
throw new Error(`${subject}: mask belongs to another layer`);
|
|
381
|
+
}
|
|
189
382
|
}
|
|
190
383
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { HSLAdjustment } from "../../miscellaneous/generic-plane/shared.js";
|
|
2
|
-
import { UIBlendMode } from "../../miscellaneous/UIBlendMode.js";
|
|
3
2
|
import type { UIMicroConfig } from "../../miscellaneous/micro/UIMicro.Internal.js";
|
|
3
|
+
import { UIBlendMode } from "../../miscellaneous/UIBlendMode.js";
|
|
4
4
|
import { UITransparencyMode } from "../../miscellaneous/UITransparencyMode.js";
|
|
5
5
|
import type { UIDummyOptions } from "../UIDummy/UIDummy.Internal.js";
|
|
6
6
|
/** Configuration options for UIElement */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { WebGLRenderer } from "three";
|
|
2
|
+
import { Matrix4 } from "three";
|
|
2
3
|
import type { UILayer } from "../../layers/UILayer/UILayer.js";
|
|
3
4
|
import type { UIProperty } from "../../miscellaneous/generic-plane/shared.js";
|
|
4
5
|
import { UIMicro } from "../../miscellaneous/micro/UIMicro.js";
|
|
@@ -8,7 +9,13 @@ import type { UITransparencyMode } from "../../miscellaneous/UITransparencyMode.
|
|
|
8
9
|
import type { UISceneWrapperView } from "../../wrappers/UISceneWrapper/UISceneWrapper.Internal.js";
|
|
9
10
|
import { UIDummy } from "../UIDummy/UIDummy.js";
|
|
10
11
|
import type { UIElementOptions } from "./UIElement.Internal.js";
|
|
11
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Base class for renderable UI elements: a quad drawn with a custom fragment shader.
|
|
14
|
+
*
|
|
15
|
+
* The source defines `vec4 draw()` and reads `p_uv` and each property as `p_<name>`.
|
|
16
|
+
* Textures are uniforms, other properties are per instance, so elements sharing the source
|
|
17
|
+
* and textures batch together. Update properties with `sceneWrapper.setProperties`.
|
|
18
|
+
*/
|
|
12
19
|
export declare abstract class UIElement extends UIDummy {
|
|
13
20
|
/** Transforms that don't affect constraints */
|
|
14
21
|
readonly micro: UIMicro;
|
|
@@ -24,6 +31,15 @@ export declare abstract class UIElement extends UIDummy {
|
|
|
24
31
|
private hslDirty;
|
|
25
32
|
private readonly hslValue;
|
|
26
33
|
private visibilityDirty;
|
|
34
|
+
/** Layout and draw-order versions the plane was last placed by */
|
|
35
|
+
private placedSolverVersion;
|
|
36
|
+
private placedInputVersion;
|
|
37
|
+
/** Layout version content sized by the element was last measured at */
|
|
38
|
+
private measuredSolverVersion;
|
|
39
|
+
/** Mask as last applied to the plane; compared every frame, see applyMask */
|
|
40
|
+
private appliedMask;
|
|
41
|
+
private appliedMaskVersion;
|
|
42
|
+
private appliedMaskHandler;
|
|
27
43
|
/**
|
|
28
44
|
* Creates a new UIElement instance.
|
|
29
45
|
*
|
|
@@ -50,6 +66,8 @@ export declare abstract class UIElement extends UIDummy {
|
|
|
50
66
|
* pair inherited from {@link UIDummy}, making reads return undefined.
|
|
51
67
|
*/
|
|
52
68
|
get mode(): UIMode;
|
|
69
|
+
/** Whether the layout or the draw order changed since the plane was last placed */
|
|
70
|
+
protected get placementDirty(): boolean;
|
|
53
71
|
/** Alpha blending mode */
|
|
54
72
|
set transparencyMode(value: UITransparencyMode);
|
|
55
73
|
/** Color blending mode (only affects BLEND transparency) */
|
|
@@ -64,7 +82,25 @@ export declare abstract class UIElement extends UIDummy {
|
|
|
64
82
|
set mode(value: UIMode);
|
|
65
83
|
/** Frees resources of the element */
|
|
66
84
|
protected destroyInternal(): void;
|
|
85
|
+
protected getMicro(): UIMicro;
|
|
67
86
|
protected setPlaneTransform(): void;
|
|
87
|
+
/**
|
|
88
|
+
* Whether the layout changed since the last call. Content that depends on the element size,
|
|
89
|
+
* such as text or nine-slice regions, reads the size only then: a read runs the solver.
|
|
90
|
+
*/
|
|
91
|
+
protected consumeLayoutChange(): boolean;
|
|
92
|
+
/** Records the layout and draw order the plane is placed by */
|
|
93
|
+
protected setPlacementDirtyFalse(): void;
|
|
94
|
+
/**
|
|
95
|
+
* Replaces the plane with one drawn by another shader source, keeping the visibility,
|
|
96
|
+
* transparency, blend, color adjustment and mask of the element.
|
|
97
|
+
*/
|
|
98
|
+
protected recreatePlane(source: string, properties: Record<string, UIProperty>, transform: Matrix4): void;
|
|
68
99
|
protected onWillRender(renderer: WebGLRenderer, deltaTime: number): void;
|
|
100
|
+
/**
|
|
101
|
+
* Brings the plane mask up to date. Pulled every frame rather than pushed: the mask data
|
|
102
|
+
* depends on the layout and micro of the mask source, whose dirty flags belong to the source.
|
|
103
|
+
*/
|
|
104
|
+
private applyMask;
|
|
69
105
|
private readonly handleWillRender;
|
|
70
106
|
}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { Matrix4 } from "three";
|
|
2
|
-
import { computeTransformMatrix } from "../../miscellaneous/computeTransform.js";
|
|
3
2
|
import { UIMicro } from "../../miscellaneous/micro/UIMicro.js";
|
|
4
3
|
import { isUIModeVisible } from "../../miscellaneous/UIMode.js";
|
|
5
4
|
import { UIDummy } from "../UIDummy/UIDummy.js";
|
|
6
5
|
import { blendModeToFactor, ELEMENT_DEFAULT_BLEND_MODE, ELEMENT_DEFAULT_HUE, ELEMENT_DEFAULT_LIGHTNESS, ELEMENT_DEFAULT_SATURATION, ELEMENT_DEFAULT_TRANSPARENCY_MODE, packHSL, } from "./UIElement.Internal.js";
|
|
7
|
-
|
|
6
|
+
const TEMP_TRANSFORM = new Matrix4();
|
|
7
|
+
/**
|
|
8
|
+
* Base class for renderable UI elements: a quad drawn with a custom fragment shader.
|
|
9
|
+
*
|
|
10
|
+
* The source defines `vec4 draw()` and reads `p_uv` and each property as `p_<name>`.
|
|
11
|
+
* Textures are uniforms, other properties are per instance, so elements sharing the source
|
|
12
|
+
* and textures batch together. Update properties with `sceneWrapper.setProperties`.
|
|
13
|
+
*/
|
|
8
14
|
export class UIElement extends UIDummy {
|
|
9
15
|
/**
|
|
10
16
|
* Creates a new UIElement instance.
|
|
@@ -21,6 +27,15 @@ export class UIElement extends UIDummy {
|
|
|
21
27
|
this.hslDirty = false;
|
|
22
28
|
this.hslValue = { h: 0, s: 0, l: 0 };
|
|
23
29
|
this.visibilityDirty = false;
|
|
30
|
+
/** Layout and draw-order versions the plane was last placed by */
|
|
31
|
+
this.placedSolverVersion = -1;
|
|
32
|
+
this.placedInputVersion = -1;
|
|
33
|
+
/** Layout version content sized by the element was last measured at */
|
|
34
|
+
this.measuredSolverVersion = -1;
|
|
35
|
+
/** Mask as last applied to the plane; compared every frame, see applyMask */
|
|
36
|
+
this.appliedMask = null;
|
|
37
|
+
this.appliedMaskVersion = -1;
|
|
38
|
+
this.appliedMaskHandler = -1;
|
|
24
39
|
this.handleWillRender = (renderer, deltaTime) => {
|
|
25
40
|
this.onWillRender(renderer, deltaTime);
|
|
26
41
|
};
|
|
@@ -31,7 +46,10 @@ export class UIElement extends UIDummy {
|
|
|
31
46
|
this.saturationInternal = options?.saturation ?? ELEMENT_DEFAULT_SATURATION;
|
|
32
47
|
this.lightnessInternal = options?.lightness ?? ELEMENT_DEFAULT_LIGHTNESS;
|
|
33
48
|
this.sceneWrapper = this.layer.sceneWrapper;
|
|
34
|
-
this.planeHandler = this.sceneWrapper.createPlane(source, properties,
|
|
49
|
+
this.planeHandler = this.sceneWrapper.createPlane(source, properties,
|
|
50
|
+
// A plane created during a frame is placed on the next one. Until then it is collapsed to
|
|
51
|
+
// nothing, at its own depth: planes may not share one
|
|
52
|
+
new Matrix4().makeScale(0, 0, 1).setPosition(0, 0, this.renderDepth), isUIModeVisible(options?.mode ?? this.mode), this.transparencyModeInternal, blendModeToFactor(this.blendModeInternal), packHSL(this.hslValue, this.hueInternal, this.saturationInternal, this.lightnessInternal));
|
|
35
53
|
this.layer.signalRendering.on(this.handleWillRender);
|
|
36
54
|
}
|
|
37
55
|
/** Alpha blending mode */
|
|
@@ -63,6 +81,11 @@ export class UIElement extends UIDummy {
|
|
|
63
81
|
get mode() {
|
|
64
82
|
return this.modeInternal;
|
|
65
83
|
}
|
|
84
|
+
/** Whether the layout or the draw order changed since the plane was last placed */
|
|
85
|
+
get placementDirty() {
|
|
86
|
+
return (this.solverWrapper.version !== this.placedSolverVersion ||
|
|
87
|
+
this.inputWrapper.version !== this.placedInputVersion);
|
|
88
|
+
}
|
|
66
89
|
/** Alpha blending mode */
|
|
67
90
|
set transparencyMode(value) {
|
|
68
91
|
if (this.transparencyModeInternal !== value) {
|
|
@@ -101,7 +124,7 @@ export class UIElement extends UIDummy {
|
|
|
101
124
|
/** Controls visibility and interactivity */
|
|
102
125
|
set mode(value) {
|
|
103
126
|
if (this.modeInternal !== value) {
|
|
104
|
-
this.visibilityDirty = isUIModeVisible(this.modeInternal) !== isUIModeVisible(value);
|
|
127
|
+
this.visibilityDirty || (this.visibilityDirty = isUIModeVisible(this.modeInternal) !== isUIModeVisible(value));
|
|
105
128
|
super.mode = value;
|
|
106
129
|
}
|
|
107
130
|
}
|
|
@@ -111,11 +134,41 @@ export class UIElement extends UIDummy {
|
|
|
111
134
|
this.sceneWrapper.destroyPlane(this.planeHandler);
|
|
112
135
|
super.destroyInternal();
|
|
113
136
|
}
|
|
137
|
+
getMicro() {
|
|
138
|
+
return this.micro;
|
|
139
|
+
}
|
|
114
140
|
setPlaneTransform() {
|
|
115
|
-
if (this.micro.dirty || this.
|
|
116
|
-
this.sceneWrapper.setTransform(this.planeHandler,
|
|
141
|
+
if (this.micro.dirty || this.placementDirty) {
|
|
142
|
+
this.sceneWrapper.setTransform(this.planeHandler, this.computeVisualTransform(true, TEMP_TRANSFORM, this.renderDepth));
|
|
117
143
|
this.micro.setDirtyFalse();
|
|
144
|
+
this.setPlacementDirtyFalse();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Whether the layout changed since the last call. Content that depends on the element size,
|
|
149
|
+
* such as text or nine-slice regions, reads the size only then: a read runs the solver.
|
|
150
|
+
*/
|
|
151
|
+
consumeLayoutChange() {
|
|
152
|
+
const version = this.solverWrapper.version;
|
|
153
|
+
if (version === this.measuredSolverVersion) {
|
|
154
|
+
return false;
|
|
118
155
|
}
|
|
156
|
+
this.measuredSolverVersion = version;
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
/** Records the layout and draw order the plane is placed by */
|
|
160
|
+
setPlacementDirtyFalse() {
|
|
161
|
+
this.placedSolverVersion = this.solverWrapper.version;
|
|
162
|
+
this.placedInputVersion = this.inputWrapper.version;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Replaces the plane with one drawn by another shader source, keeping the visibility,
|
|
166
|
+
* transparency, blend, color adjustment and mask of the element.
|
|
167
|
+
*/
|
|
168
|
+
recreatePlane(source, properties, transform) {
|
|
169
|
+
this.sceneWrapper.destroyPlane(this.planeHandler);
|
|
170
|
+
this.planeHandler = this.sceneWrapper.createPlane(source, properties, transform, isUIModeVisible(this.modeInternal), this.transparencyModeInternal, blendModeToFactor(this.blendModeInternal), packHSL(this.hslValue, this.hueInternal, this.saturationInternal, this.lightnessInternal));
|
|
171
|
+
this.applyMask();
|
|
119
172
|
}
|
|
120
173
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Required by UILayer event interface but not used in base implementation
|
|
121
174
|
onWillRender(renderer, deltaTime) {
|
|
@@ -135,6 +188,31 @@ export class UIElement extends UIDummy {
|
|
|
135
188
|
this.sceneWrapper.setVisibility(this.planeHandler, isUIModeVisible(this.modeInternal));
|
|
136
189
|
this.visibilityDirty = false;
|
|
137
190
|
}
|
|
191
|
+
this.applyMask();
|
|
138
192
|
this.setPlaneTransform();
|
|
139
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Brings the plane mask up to date. Pulled every frame rather than pushed: the mask data
|
|
196
|
+
* depends on the layout and micro of the mask source, whose dirty flags belong to the source.
|
|
197
|
+
*/
|
|
198
|
+
applyMask() {
|
|
199
|
+
const mask = this.mask;
|
|
200
|
+
const planeChanged = this.appliedMaskHandler !== this.planeHandler;
|
|
201
|
+
if (mask !== this.appliedMask || planeChanged) {
|
|
202
|
+
this.appliedMask = mask;
|
|
203
|
+
this.appliedMaskHandler = this.planeHandler;
|
|
204
|
+
this.appliedMaskVersion = -1;
|
|
205
|
+
if (mask === null) {
|
|
206
|
+
this.sceneWrapper.setMask(this.planeHandler, null);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (mask !== null) {
|
|
211
|
+
mask.resolve();
|
|
212
|
+
if (mask.version !== this.appliedMaskVersion) {
|
|
213
|
+
this.sceneWrapper.setMask(this.planeHandler, mask.data);
|
|
214
|
+
this.appliedMaskVersion = mask.version;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
140
218
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { UIColor } from "../../miscellaneous/color/UIColor.js";
|
|
2
1
|
import type { UIColorConfig } from "../../miscellaneous/color/UIColor.Internal.js";
|
|
2
|
+
import { UIColor } from "../../miscellaneous/color/UIColor.js";
|
|
3
3
|
import type { UIElementOptions } from "../UIElement/UIElement.Internal.js";
|
|
4
4
|
/** Configuration options for UIGraphics */
|
|
5
5
|
export interface UIGraphicsOptions extends UIElementOptions {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { WebGLRenderer } from "three";
|
|
2
2
|
import type { UILayer } from "../../layers/UILayer/UILayer.js";
|
|
3
|
-
import { UIColor } from "../../miscellaneous/color/UIColor.js";
|
|
4
3
|
import type { UIColorConfig } from "../../miscellaneous/color/UIColor.Internal.js";
|
|
4
|
+
import { UIColor } from "../../miscellaneous/color/UIColor.js";
|
|
5
5
|
import { UIElement } from "../UIElement/UIElement.js";
|
|
6
6
|
import type { UIGraphicsOptions } from "./UIGraphics.Internal.js";
|
|
7
7
|
/** Canvas-based 2D drawing element */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createCanvas, createCanvasTexture } from "../../miscellaneous/canvas.js";
|
|
1
|
+
import { createCanvas, createCanvasTexture, getCanvas2DContext, } from "../../miscellaneous/canvas.js";
|
|
3
2
|
import { UIColor } from "../../miscellaneous/color/UIColor.js";
|
|
3
|
+
import { UIAffineMatrix3 } from "../../miscellaneous/UIAffineMatrix3.js";
|
|
4
4
|
import source from "../../shaders/UIImage.js";
|
|
5
5
|
import { UIElement } from "../UIElement/UIElement.js";
|
|
6
6
|
import { GRAPHICS_DEFAULT_HEIGHT, GRAPHICS_DEFAULT_WIDTH, GRAPHICS_TEMP_COLOR, } from "./UIGraphics.Internal.js";
|
|
@@ -17,7 +17,7 @@ export class UIGraphics extends UIElement {
|
|
|
17
17
|
const h = options?.height ?? GRAPHICS_DEFAULT_HEIGHT;
|
|
18
18
|
const color = new UIColor(options?.color);
|
|
19
19
|
const canvas = createCanvas(w, h);
|
|
20
|
-
const context = canvas
|
|
20
|
+
const context = getCanvas2DContext(canvas);
|
|
21
21
|
if (!context) {
|
|
22
22
|
throw new Error("UIGraphics.constructor: failed to get 2D context from canvas");
|
|
23
23
|
}
|
|
@@ -25,7 +25,7 @@ export class UIGraphics extends UIElement {
|
|
|
25
25
|
texture.needsUpdate = true;
|
|
26
26
|
super(layer, source, {
|
|
27
27
|
texture: texture,
|
|
28
|
-
textureTransform: new
|
|
28
|
+
textureTransform: new UIAffineMatrix3(),
|
|
29
29
|
color,
|
|
30
30
|
}, options);
|
|
31
31
|
this.canvas = canvas;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { UILayer } from "../../layers/UILayer/UILayer.js";
|
|
2
|
-
import { UIColor } from "../../miscellaneous/color/UIColor.js";
|
|
3
2
|
import type { UIColorConfig } from "../../miscellaneous/color/UIColor.Internal.js";
|
|
4
|
-
import {
|
|
3
|
+
import { UIColor } from "../../miscellaneous/color/UIColor.js";
|
|
5
4
|
import type { UITextureConfig } from "../../miscellaneous/texture/UITextureView.Internal.js";
|
|
5
|
+
import { UITextureView } from "../../miscellaneous/texture/UITextureView.js";
|
|
6
6
|
import { UIElement } from "../UIElement/UIElement.js";
|
|
7
7
|
import type { UIImageOptions } from "./UIImage.Internal.js";
|
|
8
8
|
/** Textured image element */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UIColor } from "../../miscellaneous/color/UIColor.js";
|
|
2
|
-
import { computeTrimmedTransformMatrix } from "../../miscellaneous/computeTransform.js";
|
|
2
|
+
import { computeTrimmedTransformMatrix, scaleTrim } from "../../miscellaneous/computeTransform.js";
|
|
3
3
|
import { UITextureView } from "../../miscellaneous/texture/UITextureView.js";
|
|
4
4
|
import source from "../../shaders/UIImage.js";
|
|
5
5
|
import { UIElement } from "../UIElement/UIElement.js";
|
|
@@ -18,8 +18,12 @@ export class UIImage extends UIElement {
|
|
|
18
18
|
const color = new UIColor(options.color);
|
|
19
19
|
const textureView = new UITextureView(texture);
|
|
20
20
|
const textureTransform = textureView.calculateUVTransform();
|
|
21
|
-
|
|
22
|
-
options
|
|
21
|
+
// A copy: the caller may pass the same options to several elements
|
|
22
|
+
options = {
|
|
23
|
+
...options,
|
|
24
|
+
width: options.width ?? textureView.width,
|
|
25
|
+
height: options.height ?? textureView.height,
|
|
26
|
+
};
|
|
23
27
|
super(layer, source, {
|
|
24
28
|
texture: textureView.texture,
|
|
25
29
|
textureTransform: textureTransform,
|
|
@@ -67,16 +71,14 @@ export class UIImage extends UIElement {
|
|
|
67
71
|
if (properties) {
|
|
68
72
|
this.sceneWrapper.setProperties(this.planeHandler, properties);
|
|
69
73
|
}
|
|
70
|
-
const isTransformDirty = this.micro.dirty ||
|
|
71
|
-
this.texture.trimDirty ||
|
|
72
|
-
this.inputWrapper.dirty ||
|
|
73
|
-
this.solverWrapper.dirty;
|
|
74
|
+
const isTransformDirty = this.micro.dirty || this.texture.trimDirty || this.placementDirty;
|
|
74
75
|
if (isTransformDirty) {
|
|
75
76
|
const micro = this.micro;
|
|
76
|
-
const textureTrim = this.texture.trim;
|
|
77
|
+
const textureTrim = scaleTrim(this.texture.trim, this.width, this.height, this.texture.width, this.texture.height);
|
|
77
78
|
this.sceneWrapper.setTransform(this.planeHandler, computeTrimmedTransformMatrix(this.x, this.y, this.width, this.height, this.renderDepth, micro.x, micro.y, micro.anchorX, micro.anchorY, micro.scaleX, micro.scaleY, micro.rotation, micro.anchorMode, textureTrim.left, textureTrim.right, textureTrim.top, textureTrim.bottom));
|
|
78
79
|
this.micro.setDirtyFalse();
|
|
79
80
|
this.texture.setTrimDirtyFalse();
|
|
81
|
+
this.setPlacementDirtyFalse();
|
|
80
82
|
}
|
|
81
83
|
}
|
|
82
84
|
}
|