laymur 0.2.17 → 0.3.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 +31 -24
- package/dist/builders/UIConstraint2DBuilder.d.ts +1 -1
- package/dist/builders/UICoverConstraintBuilder.d.ts +3 -1
- package/dist/builders/UIFitConstraintBuilder.d.ts +3 -1
- package/dist/constraints/UIAspectConstraint.d.ts +0 -1
- package/dist/constraints/UIConstraint.d.ts +3 -0
- package/dist/constraints/UIHorizontalDistanceConstraint.d.ts +0 -1
- package/dist/constraints/UIHorizontalProportionConstraint.d.ts +2 -3
- package/dist/constraints/UISingleParameterConstraint.d.ts +0 -2
- package/dist/constraints/UIVerticalDistanceConstraint.d.ts +0 -1
- package/dist/constraints/UIVerticalProportionConstraint.d.ts +2 -3
- package/dist/elements/UIDummy.d.ts +7 -1
- package/dist/elements/UIElement.d.ts +52 -38
- package/dist/elements/UIImage.d.ts +30 -42
- package/dist/elements/UINineSline.d.ts +61 -68
- package/dist/elements/UIProgress.d.ts +86 -110
- package/dist/elements/UIScene.d.ts +21 -30
- package/dist/elements/UIText.d.ts +27 -41
- package/dist/index.d.ts +4 -1
- package/dist/index.js +1237 -942
- 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 +0 -4
- package/dist/layers/UILayer.d.ts +50 -3
- package/dist/miscellaneous/UIColor.d.ts +171 -0
- package/dist/miscellaneous/UIInputEvent.d.ts +7 -0
- package/dist/miscellaneous/UIMicro.d.ts +3 -3
- package/dist/miscellaneous/{UIAnchorMode.d.ts → UIMicroAnchorMode.d.ts} +1 -1
- package/dist/miscellaneous/UINineSliceBorder.d.ts +6 -6
- package/dist/miscellaneous/UISceneWrapperClientAPI.d.ts +10 -0
- package/dist/miscellaneous/UITextPadding.d.ts +1 -1
- package/dist/miscellaneous/UITransparencyMode.d.ts +26 -0
- package/dist/miscellaneous/textTools.d.ts +4 -4
- package/dist/scalable/UIScalableMesh.d.ts +0 -16
- package/dist/scalable/UIScalablePlaneMesh.d.ts +0 -14
- package/dist/wrappers/UISceneWrapper.d.ts +17 -15
- package/dist/wrappers/UISolverWrapper.d.ts +185 -0
- package/package.json +1 -1
- package/dist/materials/UIMaterial.d.ts +0 -13
- package/dist/materials/UINineSliceMaterial.d.ts +0 -27
- package/dist/materials/UIProgressMaterial.d.ts +0 -29
- package/dist/miscellaneous/threeInstances.d.ts +0 -2
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Color, Scene, OrthographicCamera,
|
|
1
|
+
import { PlaneGeometry, Color, Scene, OrthographicCamera, ShaderMaterial, Vector4, Mesh, Texture, Vector2, Vector3, Matrix2, Matrix3, Matrix4, MathUtils, Quaternion, WebGLRenderTarget, UnsignedByteType, LinearFilter, RGBAFormat, PerspectiveCamera, CanvasTexture } from 'three';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Mathematical expression builder for constraint equations in the UI layout system.
|
|
@@ -1816,16 +1816,380 @@ function resolvePriority(priority) {
|
|
|
1816
1816
|
}
|
|
1817
1817
|
|
|
1818
1818
|
/**
|
|
1819
|
-
*
|
|
1819
|
+
* Database of predefined color names mapped to their hexadecimal RGB values.
|
|
1820
|
+
* Used for creating UIColor instances from named colors.
|
|
1820
1821
|
*/
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1822
|
+
const COLOR_NAMES = {
|
|
1823
|
+
// Basic colors
|
|
1824
|
+
black: 0x000000,
|
|
1825
|
+
white: 0xffffff,
|
|
1826
|
+
red: 0xff0000,
|
|
1827
|
+
green: 0x008000,
|
|
1828
|
+
blue: 0x0000ff,
|
|
1829
|
+
yellow: 0xffff00,
|
|
1830
|
+
cyan: 0x00ffff,
|
|
1831
|
+
magenta: 0xff00ff,
|
|
1832
|
+
// Extended colors
|
|
1833
|
+
gray: 0x808080,
|
|
1834
|
+
grey: 0x808080,
|
|
1835
|
+
silver: 0xc0c0c0,
|
|
1836
|
+
maroon: 0x800000,
|
|
1837
|
+
olive: 0x808000,
|
|
1838
|
+
lime: 0x00ff00,
|
|
1839
|
+
aqua: 0x00ffff,
|
|
1840
|
+
teal: 0x008080,
|
|
1841
|
+
navy: 0x000080,
|
|
1842
|
+
fuchsia: 0xff00ff,
|
|
1843
|
+
purple: 0x800080,
|
|
1844
|
+
// Additional common colors
|
|
1845
|
+
orange: 0xffa500,
|
|
1846
|
+
pink: 0xffc0cb,
|
|
1847
|
+
brown: 0xa52a2a,
|
|
1848
|
+
gold: 0xffd700,
|
|
1849
|
+
violet: 0xee82ee,
|
|
1850
|
+
indigo: 0x4b0082,
|
|
1851
|
+
coral: 0xff7f50,
|
|
1852
|
+
salmon: 0xfa8072,
|
|
1853
|
+
khaki: 0xf0e68c,
|
|
1854
|
+
plum: 0xdda0dd,
|
|
1855
|
+
orchid: 0xda70d6,
|
|
1856
|
+
tan: 0xd2b48c,
|
|
1857
|
+
beige: 0xf5f5dc,
|
|
1858
|
+
mint: 0x98fb98,
|
|
1859
|
+
lavender: 0xe6e6fa,
|
|
1860
|
+
crimson: 0xdc143c,
|
|
1861
|
+
azure: 0xf0ffff,
|
|
1862
|
+
ivory: 0xfffff0,
|
|
1863
|
+
snow: 0xfffafa,
|
|
1864
|
+
};
|
|
1865
|
+
/**
|
|
1866
|
+
* Events that can be emitted by UIColor instances.
|
|
1867
|
+
*/
|
|
1868
|
+
var UIColorEvent;
|
|
1869
|
+
(function (UIColorEvent) {
|
|
1870
|
+
/** Emitted when any color property (r, g, b, a) changes. */
|
|
1871
|
+
UIColorEvent["CHANGE"] = "change";
|
|
1872
|
+
})(UIColorEvent || (UIColorEvent = {}));
|
|
1873
|
+
/**
|
|
1874
|
+
* Event-based RGBA color class with support for multiple color formats and named colors.
|
|
1875
|
+
*
|
|
1876
|
+
* UIColor provides a comprehensive color management system with support for RGB, HSL,
|
|
1877
|
+
* hexadecimal formats, and named colors. It extends Eventail to emit change events
|
|
1878
|
+
* when color properties are modified, enabling reactive color updates throughout
|
|
1879
|
+
* the UI system.
|
|
1880
|
+
*
|
|
1881
|
+
* Color components are stored as normalized values (0-1) for precision and
|
|
1882
|
+
* compatibility with graphics APIs.
|
|
1883
|
+
*
|
|
1884
|
+
* @see {@link UIColorEvent} - Events emitted by color instances
|
|
1885
|
+
* @see {@link UIColorName} - Supported named color values
|
|
1886
|
+
*/
|
|
1887
|
+
class UIColor extends i {
|
|
1888
|
+
constructor(...args) {
|
|
1889
|
+
super();
|
|
1890
|
+
/** Internal storage for the red component (0-1). */
|
|
1891
|
+
this.rInternal = 1;
|
|
1892
|
+
/** Internal storage for the green component (0-1). */
|
|
1893
|
+
this.gInternal = 1;
|
|
1894
|
+
/** Internal storage for the blue component (0-1). */
|
|
1895
|
+
this.bInternal = 1;
|
|
1896
|
+
/** Internal storage for the alpha component (0-1). */
|
|
1897
|
+
this.aInternal = 1;
|
|
1898
|
+
if (args.length >= 3 && typeof args[0] === "number") {
|
|
1899
|
+
const [r, g, b, a = 1] = args;
|
|
1900
|
+
this.rInternal = r;
|
|
1901
|
+
this.gInternal = g;
|
|
1902
|
+
this.bInternal = b;
|
|
1903
|
+
this.aInternal = a;
|
|
1904
|
+
}
|
|
1905
|
+
else if (args.length >= 1) {
|
|
1906
|
+
const [first, a = 1] = args;
|
|
1907
|
+
if (typeof first === "string") {
|
|
1908
|
+
this.setName(first, a);
|
|
1909
|
+
}
|
|
1910
|
+
else {
|
|
1911
|
+
this.setHexRGB(first, a);
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1915
|
+
/**
|
|
1916
|
+
* Gets the red component value.
|
|
1917
|
+
* @returns The red component (0-1)
|
|
1918
|
+
*/
|
|
1919
|
+
get r() {
|
|
1920
|
+
return this.rInternal;
|
|
1921
|
+
}
|
|
1922
|
+
/**
|
|
1923
|
+
* Gets the green component value.
|
|
1924
|
+
* @returns The green component (0-1)
|
|
1925
|
+
*/
|
|
1926
|
+
get g() {
|
|
1927
|
+
return this.gInternal;
|
|
1928
|
+
}
|
|
1929
|
+
/**
|
|
1930
|
+
* Gets the blue component value.
|
|
1931
|
+
* @returns The blue component (0-1)
|
|
1932
|
+
*/
|
|
1933
|
+
get b() {
|
|
1934
|
+
return this.bInternal;
|
|
1935
|
+
}
|
|
1936
|
+
/**
|
|
1937
|
+
* Gets the alpha component value.
|
|
1938
|
+
* @returns The alpha component (0-1)
|
|
1939
|
+
*/
|
|
1940
|
+
get a() {
|
|
1941
|
+
return this.aInternal;
|
|
1942
|
+
}
|
|
1943
|
+
/**
|
|
1944
|
+
* Sets the red component value and emits change event.
|
|
1945
|
+
* @param value - The red component (0-1)
|
|
1946
|
+
*/
|
|
1947
|
+
set r(value) {
|
|
1948
|
+
this.rInternal = value;
|
|
1949
|
+
this.emit(UIColorEvent.CHANGE, this);
|
|
1950
|
+
}
|
|
1951
|
+
/**
|
|
1952
|
+
* Sets the green component value and emits change event.
|
|
1953
|
+
* @param value - The green component (0-1)
|
|
1954
|
+
*/
|
|
1955
|
+
set g(value) {
|
|
1956
|
+
this.gInternal = value;
|
|
1957
|
+
this.emit(UIColorEvent.CHANGE, this);
|
|
1958
|
+
}
|
|
1959
|
+
/**
|
|
1960
|
+
* Sets the blue component value and emits change event.
|
|
1961
|
+
* @param value - The blue component (0-1)
|
|
1962
|
+
*/
|
|
1963
|
+
set b(value) {
|
|
1964
|
+
this.bInternal = value;
|
|
1965
|
+
this.emit(UIColorEvent.CHANGE, this);
|
|
1966
|
+
}
|
|
1967
|
+
/**
|
|
1968
|
+
* Sets the alpha component value and emits change event.
|
|
1969
|
+
* @param value - The alpha component (0-1)
|
|
1970
|
+
*/
|
|
1971
|
+
set a(value) {
|
|
1972
|
+
this.aInternal = value;
|
|
1973
|
+
this.emit(UIColorEvent.CHANGE, this);
|
|
1974
|
+
}
|
|
1975
|
+
/**
|
|
1976
|
+
* Sets all color components at once and emits change event.
|
|
1977
|
+
* @param r - Red component (0-1)
|
|
1978
|
+
* @param g - Green component (0-1)
|
|
1979
|
+
* @param b - Blue component (0-1)
|
|
1980
|
+
* @param a - Alpha component (0-1), defaults to current alpha value
|
|
1981
|
+
* @returns This UIColor instance for method chaining
|
|
1982
|
+
*/
|
|
1983
|
+
set(r, g, b, a = this.aInternal) {
|
|
1984
|
+
this.rInternal = r;
|
|
1985
|
+
this.gInternal = g;
|
|
1986
|
+
this.bInternal = b;
|
|
1987
|
+
this.aInternal = a;
|
|
1988
|
+
this.emit(UIColorEvent.CHANGE, this);
|
|
1989
|
+
return this;
|
|
1990
|
+
}
|
|
1991
|
+
/**
|
|
1992
|
+
* Converts the color to a 32-bit hexadecimal RGBA value.
|
|
1993
|
+
* @returns Hexadecimal RGBA value with alpha in the most significant byte
|
|
1994
|
+
*/
|
|
1995
|
+
getHexRGBA() {
|
|
1996
|
+
return ((Math.round(this.rInternal * 255) << 24) |
|
|
1997
|
+
(Math.round(this.gInternal * 255) << 16) |
|
|
1998
|
+
(Math.round(this.bInternal * 255) << 8) |
|
|
1999
|
+
Math.round(this.aInternal * 255));
|
|
2000
|
+
}
|
|
2001
|
+
/**
|
|
2002
|
+
* Converts the color to a 24-bit hexadecimal RGB value (ignores alpha).
|
|
2003
|
+
* @returns Hexadecimal RGB value (e.g., 0xFF0000 for red)
|
|
2004
|
+
*/
|
|
2005
|
+
getHexRGB() {
|
|
2006
|
+
return ((Math.round(this.rInternal * 255) << 16) |
|
|
2007
|
+
(Math.round(this.gInternal * 255) << 8) |
|
|
2008
|
+
Math.round(this.bInternal * 255));
|
|
2009
|
+
}
|
|
2010
|
+
/**
|
|
2011
|
+
* Converts the color to HSL (Hue, Saturation, Lightness) format.
|
|
2012
|
+
* @returns Object containing h (0-360), s (0-1), and l (0-1) values
|
|
2013
|
+
*/
|
|
2014
|
+
getHSL() {
|
|
2015
|
+
const { rInternal: r, gInternal: g, bInternal: b } = this;
|
|
2016
|
+
const max = Math.max(r, g, b);
|
|
2017
|
+
const min = Math.min(r, g, b);
|
|
2018
|
+
const d = max - min;
|
|
2019
|
+
const l = (max + min) / 2;
|
|
2020
|
+
let h = 0;
|
|
2021
|
+
if (d !== 0) {
|
|
2022
|
+
if (max === r) {
|
|
2023
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
2024
|
+
}
|
|
2025
|
+
else if (max === g) {
|
|
2026
|
+
h = (b - r) / d + 2;
|
|
2027
|
+
}
|
|
2028
|
+
else {
|
|
2029
|
+
h = (r - g) / d + 4;
|
|
2030
|
+
}
|
|
2031
|
+
h *= 60;
|
|
2032
|
+
}
|
|
2033
|
+
const s = d === 0 ? 0 : d / (1 - Math.abs(2 * l - 1));
|
|
2034
|
+
return { h, s, l };
|
|
2035
|
+
}
|
|
2036
|
+
/**
|
|
2037
|
+
* Sets the color from a 32-bit hexadecimal RGBA value and emits change event.
|
|
2038
|
+
* @param hex - Hexadecimal RGBA value with alpha in the most significant byte
|
|
2039
|
+
* @returns This UIColor instance for method chaining
|
|
2040
|
+
*/
|
|
2041
|
+
setHexRGBA(hex) {
|
|
2042
|
+
this.rInternal = ((hex >> 16) & 0xff) / 255;
|
|
2043
|
+
this.gInternal = ((hex >> 8) & 0xff) / 255;
|
|
2044
|
+
this.bInternal = (hex & 0xff) / 255;
|
|
2045
|
+
this.aInternal = ((hex >> 24) & 0xff) / 255;
|
|
2046
|
+
this.emit(UIColorEvent.CHANGE, this);
|
|
2047
|
+
return this;
|
|
2048
|
+
}
|
|
2049
|
+
/**
|
|
2050
|
+
* Sets the color from a 24-bit hexadecimal RGB value and emits change event.
|
|
2051
|
+
* @param hex - Hexadecimal RGB value (e.g., 0xFF0000 for red)
|
|
2052
|
+
* @param a - Alpha value (0-1), defaults to current alpha
|
|
2053
|
+
* @returns This UIColor instance for method chaining
|
|
2054
|
+
*/
|
|
2055
|
+
setHexRGB(hex, a = this.aInternal) {
|
|
2056
|
+
this.rInternal = ((hex >> 16) & 0xff) / 255;
|
|
2057
|
+
this.gInternal = ((hex >> 8) & 0xff) / 255;
|
|
2058
|
+
this.bInternal = (hex & 0xff) / 255;
|
|
2059
|
+
this.aInternal = a;
|
|
2060
|
+
this.emit(UIColorEvent.CHANGE, this);
|
|
2061
|
+
return this;
|
|
2062
|
+
}
|
|
2063
|
+
/**
|
|
2064
|
+
* Sets the color from HSL (Hue, Saturation, Lightness) values and emits change event.
|
|
2065
|
+
* @param h - Hue value (0-360)
|
|
2066
|
+
* @param s - Saturation value (0-1)
|
|
2067
|
+
* @param l - Lightness value (0-1)
|
|
2068
|
+
* @param a - Alpha value (0-1), defaults to current alpha
|
|
2069
|
+
* @returns This UIColor instance for method chaining
|
|
2070
|
+
*/
|
|
2071
|
+
setHSL(h, s, l, a = this.aInternal) {
|
|
2072
|
+
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
2073
|
+
const hp = h / 60;
|
|
2074
|
+
const x = c * (1 - Math.abs((hp % 2) - 1));
|
|
2075
|
+
let [r, g, b] = hp < 1
|
|
2076
|
+
? [c, x, 0]
|
|
2077
|
+
: hp < 2
|
|
2078
|
+
? [x, c, 0]
|
|
2079
|
+
: hp < 3
|
|
2080
|
+
? [0, c, x]
|
|
2081
|
+
: hp < 4
|
|
2082
|
+
? [0, x, c]
|
|
2083
|
+
: hp < 5
|
|
2084
|
+
? [x, 0, c]
|
|
2085
|
+
: [c, 0, x];
|
|
2086
|
+
const m = l - c / 2;
|
|
2087
|
+
return this.set(r + m, g + m, b + m, a);
|
|
2088
|
+
}
|
|
2089
|
+
/**
|
|
2090
|
+
* Sets the color from a predefined color name and emits change event.
|
|
2091
|
+
* @param colorName - Name of the color from the predefined color database
|
|
2092
|
+
* @param a - Alpha value (0-1), defaults to current alpha
|
|
2093
|
+
* @returns This UIColor instance for method chaining
|
|
2094
|
+
* @throws Will throw an error if the color name is not recognized
|
|
2095
|
+
*/
|
|
2096
|
+
setName(colorName, a = this.aInternal) {
|
|
2097
|
+
const normalizedName = colorName.toLowerCase().trim();
|
|
2098
|
+
const hex = COLOR_NAMES[normalizedName];
|
|
2099
|
+
if (hex === undefined) {
|
|
2100
|
+
throw new Error(`Unknown color name: "${colorName}".`);
|
|
2101
|
+
}
|
|
2102
|
+
return this.setHexRGB(hex, a);
|
|
2103
|
+
}
|
|
2104
|
+
/**
|
|
2105
|
+
* Copies color values from another UIColor or Three.js Color instance and emits change event.
|
|
2106
|
+
* @param color - The color to copy from (UIColor or Three.js Color)
|
|
2107
|
+
* @returns This UIColor instance for method chaining
|
|
2108
|
+
*/
|
|
2109
|
+
copy(color) {
|
|
2110
|
+
if (color instanceof UIColor) {
|
|
2111
|
+
this.rInternal = color.rInternal;
|
|
2112
|
+
this.gInternal = color.gInternal;
|
|
2113
|
+
this.bInternal = color.bInternal;
|
|
2114
|
+
this.aInternal = color.aInternal;
|
|
2115
|
+
}
|
|
2116
|
+
else {
|
|
2117
|
+
this.rInternal = color.r;
|
|
2118
|
+
this.gInternal = color.g;
|
|
2119
|
+
this.bInternal = color.b;
|
|
2120
|
+
this.aInternal = 1;
|
|
2121
|
+
}
|
|
2122
|
+
this.emit(UIColorEvent.CHANGE, this);
|
|
2123
|
+
return this;
|
|
2124
|
+
}
|
|
2125
|
+
/**
|
|
2126
|
+
* Creates a new UIColor instance with identical color values.
|
|
2127
|
+
* @returns A new UIColor instance with the same RGBA values
|
|
2128
|
+
*/
|
|
2129
|
+
clone() {
|
|
2130
|
+
return new UIColor(this.rInternal, this.gInternal, this.bInternal, this.aInternal);
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
|
|
2134
|
+
/**
|
|
2135
|
+
* Transparency rendering modes for UI elements.
|
|
2136
|
+
*
|
|
2137
|
+
* Controls how transparent and semi-transparent pixels are handled during rendering.
|
|
2138
|
+
* Each mode offers different performance and visual quality trade-offs.
|
|
2139
|
+
*/
|
|
2140
|
+
var UITransparencyMode;
|
|
2141
|
+
(function (UITransparencyMode) {
|
|
2142
|
+
/**
|
|
2143
|
+
* Clip mode - pixels are either fully opaque or fully transparent.
|
|
2144
|
+
* Uses alpha testing to discard pixels below a threshold.
|
|
2145
|
+
* Best performance but no smooth transparency gradients.
|
|
2146
|
+
*/
|
|
2147
|
+
UITransparencyMode[UITransparencyMode["CLIP"] = 0] = "CLIP";
|
|
2148
|
+
/**
|
|
2149
|
+
* Hash mode - dithered transparency using screen-door transparency.
|
|
2150
|
+
* Creates transparency illusion through pixel patterns.
|
|
2151
|
+
* Good performance with better visual quality than CLIP.
|
|
2152
|
+
*/
|
|
2153
|
+
UITransparencyMode[UITransparencyMode["HASH"] = 1] = "HASH";
|
|
2154
|
+
/**
|
|
2155
|
+
* Blend mode - true alpha blending with smooth transparency.
|
|
2156
|
+
* Supports full range of transparency values with smooth gradients.
|
|
2157
|
+
* Best visual quality but requires depth sorting and impacts performance.
|
|
2158
|
+
*/
|
|
2159
|
+
UITransparencyMode[UITransparencyMode["BLEND"] = 2] = "BLEND";
|
|
2160
|
+
})(UITransparencyMode || (UITransparencyMode = {}));
|
|
1828
2161
|
|
|
2162
|
+
var fragmentShader = "in vec2 io_UV;\n\nuniform float alphaTest;\n\n#include <common>\n#include <alphahash_pars_fragment>\n";
|
|
2163
|
+
|
|
2164
|
+
var vertexShader = "out vec2 io_UV;\n#include <common>\n\nvoid main() {\n #include <begin_vertex>\n io_UV = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n";
|
|
2165
|
+
|
|
2166
|
+
const DEFAULT_ALPHA_TEST = 0.25;
|
|
2167
|
+
const UNIFROM_TYPE_MAP = new Map([
|
|
2168
|
+
[UIColor, "vec4"],
|
|
2169
|
+
[Color, "vec3"],
|
|
2170
|
+
[Texture, "sampler2D"],
|
|
2171
|
+
[Vector2, "vec2"],
|
|
2172
|
+
[Vector3, "vec3"],
|
|
2173
|
+
[Vector4, "vec4"],
|
|
2174
|
+
[Matrix2, "mat2"],
|
|
2175
|
+
[Matrix3, "mat3"],
|
|
2176
|
+
[Matrix4, "mat4"],
|
|
2177
|
+
]);
|
|
2178
|
+
function buildUniformDeclaraction(name, value) {
|
|
2179
|
+
if (typeof value === "number") {
|
|
2180
|
+
return `uniform float ${name};`;
|
|
2181
|
+
}
|
|
2182
|
+
for (const [objectType, glslType] of UNIFROM_TYPE_MAP) {
|
|
2183
|
+
if (value instanceof objectType) {
|
|
2184
|
+
return `uniform ${glslType} ${name};`;
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
throw new Error(`Unsupported uniform type for key "${name}"`);
|
|
2188
|
+
}
|
|
2189
|
+
const Z_LIMIT = 1024;
|
|
2190
|
+
const GEOMETRY_SIZE = 1;
|
|
2191
|
+
const GEOMETRY_OFFSET = GEOMETRY_SIZE / 2;
|
|
2192
|
+
const geometry = new PlaneGeometry(GEOMETRY_SIZE, GEOMETRY_SIZE).translate(GEOMETRY_OFFSET, GEOMETRY_OFFSET, 0);
|
|
1829
2193
|
let originalClearColor = new Color();
|
|
1830
2194
|
let originalClearAlpha = 0;
|
|
1831
2195
|
let originalAutoClear = false;
|
|
@@ -1835,70 +2199,102 @@ let originalAutoClearStencil = false;
|
|
|
1835
2199
|
class UISceneWrapper {
|
|
1836
2200
|
constructor(w, h) {
|
|
1837
2201
|
this._private_scene = new Scene();
|
|
1838
|
-
this.
|
|
1839
|
-
this.
|
|
1840
|
-
|
|
1841
|
-
insertObject(element, object) {
|
|
1842
|
-
if (this._private_elements.has(element)) {
|
|
1843
|
-
throw new Error("Element already exists");
|
|
1844
|
-
}
|
|
1845
|
-
this._private_elements.set(element, object);
|
|
1846
|
-
this._private_scene.add(object);
|
|
2202
|
+
this._private_descriptors = new Map();
|
|
2203
|
+
this._private_lastPlaneIndex = 0;
|
|
2204
|
+
this._private_camera = new OrthographicCamera(0, w, h, 0, -Z_LIMIT, Z_LIMIT);
|
|
1847
2205
|
}
|
|
1848
|
-
|
|
1849
|
-
const
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
2206
|
+
createPlane(source, uniforms) {
|
|
2207
|
+
const entries = Object.entries(uniforms);
|
|
2208
|
+
const material = new ShaderMaterial({
|
|
2209
|
+
uniforms: {
|
|
2210
|
+
alphaTest: { value: DEFAULT_ALPHA_TEST },
|
|
2211
|
+
...Object.fromEntries(entries.map(([k, v]) => [
|
|
2212
|
+
k,
|
|
2213
|
+
{
|
|
2214
|
+
value: v instanceof UIColor ? new Vector4(v.r, v.g, v.b, v.a) : v,
|
|
2215
|
+
},
|
|
2216
|
+
])),
|
|
2217
|
+
},
|
|
2218
|
+
vertexShader,
|
|
2219
|
+
fragmentShader: fragmentShader +
|
|
2220
|
+
entries.map(([k, v]) => buildUniformDeclaraction(k, v)).join("\n") +
|
|
2221
|
+
source,
|
|
2222
|
+
transparent: false,
|
|
2223
|
+
alphaTest: DEFAULT_ALPHA_TEST,
|
|
2224
|
+
alphaHash: false,
|
|
2225
|
+
lights: false,
|
|
2226
|
+
fog: false,
|
|
2227
|
+
depthWrite: false,
|
|
2228
|
+
depthTest: false,
|
|
2229
|
+
});
|
|
2230
|
+
const plane = new Mesh(geometry, material);
|
|
2231
|
+
plane.matrixAutoUpdate = false;
|
|
2232
|
+
this._private_scene.add(plane);
|
|
2233
|
+
const index = this._private_lastPlaneIndex++;
|
|
2234
|
+
this._private_descriptors.set(index, { plane, material });
|
|
2235
|
+
return index;
|
|
1856
2236
|
}
|
|
1857
|
-
|
|
1858
|
-
const
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
this._private_scene.remove(object);
|
|
1863
|
-
this._private_elements.delete(element);
|
|
2237
|
+
destroyPlane(handler) {
|
|
2238
|
+
const descriptor = this._private_resolveDescriptor(handler);
|
|
2239
|
+
this._private_scene.remove(descriptor.plane);
|
|
2240
|
+
this._private_descriptors.delete(handler);
|
|
2241
|
+
return this;
|
|
1864
2242
|
}
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
2243
|
+
setTransform(handler, value) {
|
|
2244
|
+
const descriptor = this._private_resolveDescriptor(handler);
|
|
2245
|
+
descriptor.plane.matrix.copy(value);
|
|
2246
|
+
descriptor.plane.matrixWorldNeedsUpdate = true;
|
|
2247
|
+
return this;
|
|
1869
2248
|
}
|
|
1870
|
-
|
|
1871
|
-
const
|
|
1872
|
-
if (
|
|
1873
|
-
throw new Error(
|
|
2249
|
+
setUniform(handler, uniform, value) {
|
|
2250
|
+
const descriptor = this._private_resolveDescriptor(handler);
|
|
2251
|
+
if (!(uniform in descriptor.material.uniforms)) {
|
|
2252
|
+
throw new Error(`Uniform ${uniform} not found in material`);
|
|
1874
2253
|
}
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
getZIndex(element) {
|
|
1878
|
-
const object = this._private_elements.get(element);
|
|
1879
|
-
if (object === undefined) {
|
|
1880
|
-
throw new Error("Element not found");
|
|
2254
|
+
if (value instanceof UIColor) {
|
|
2255
|
+
descriptor.material.uniforms[uniform].value.set(value.r, value.g, value.b, value.a);
|
|
1881
2256
|
}
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
setZIndex(element, zIndex) {
|
|
1885
|
-
const object = this._private_elements.get(element);
|
|
1886
|
-
if (object === undefined) {
|
|
1887
|
-
throw new Error("Element not found");
|
|
2257
|
+
else {
|
|
2258
|
+
descriptor.material.uniforms[uniform].value = value;
|
|
1888
2259
|
}
|
|
1889
|
-
|
|
2260
|
+
return this;
|
|
1890
2261
|
}
|
|
1891
|
-
|
|
1892
|
-
const
|
|
1893
|
-
if (
|
|
1894
|
-
|
|
2262
|
+
setTransparency(handler, mode) {
|
|
2263
|
+
const descriptor = this._private_resolveDescriptor(handler);
|
|
2264
|
+
if (mode === UITransparencyMode.BLEND) {
|
|
2265
|
+
descriptor.material.transparent = true;
|
|
2266
|
+
descriptor.material.alphaTest = 0;
|
|
2267
|
+
descriptor.material.uniforms["alphaTest"].value = 0;
|
|
2268
|
+
descriptor.material.alphaHash = false;
|
|
2269
|
+
}
|
|
2270
|
+
else if (mode === UITransparencyMode.CLIP) {
|
|
2271
|
+
descriptor.material.transparent = false;
|
|
2272
|
+
descriptor.material.alphaTest = DEFAULT_ALPHA_TEST;
|
|
2273
|
+
descriptor.material.uniforms["alphaTest"].value = DEFAULT_ALPHA_TEST;
|
|
2274
|
+
descriptor.material.alphaHash = false;
|
|
2275
|
+
}
|
|
2276
|
+
else {
|
|
2277
|
+
descriptor.material.transparent = false;
|
|
2278
|
+
descriptor.material.alphaTest = 0;
|
|
2279
|
+
descriptor.material.uniforms["alphaTest"].value = 0;
|
|
2280
|
+
descriptor.material.alphaHash = true;
|
|
1895
2281
|
}
|
|
1896
|
-
|
|
2282
|
+
descriptor.material.uniformsNeedUpdate = true;
|
|
2283
|
+
descriptor.material.needsUpdate = true;
|
|
2284
|
+
return this;
|
|
2285
|
+
}
|
|
2286
|
+
setVisibility(handler, visible) {
|
|
2287
|
+
const descriptor = this._private_resolveDescriptor(handler);
|
|
2288
|
+
descriptor.plane.visible = visible;
|
|
2289
|
+
return this;
|
|
1897
2290
|
}
|
|
1898
|
-
|
|
1899
|
-
|
|
2291
|
+
resize(width, height) {
|
|
2292
|
+
this._private_camera.right = width;
|
|
2293
|
+
this._private_camera.top = height;
|
|
2294
|
+
this._private_camera.updateProjectionMatrix();
|
|
2295
|
+
return this;
|
|
1900
2296
|
}
|
|
1901
|
-
|
|
2297
|
+
render(renderer) {
|
|
1902
2298
|
originalClearColor = renderer.getClearColor(originalClearColor);
|
|
1903
2299
|
originalClearAlpha = renderer.getClearAlpha();
|
|
1904
2300
|
originalAutoClear = renderer.autoClear;
|
|
@@ -1910,34 +2306,6 @@ class UISceneWrapper {
|
|
|
1910
2306
|
renderer.autoClearDepth = false;
|
|
1911
2307
|
renderer.autoClearStencil = false;
|
|
1912
2308
|
renderer.setClearColor(0x000000, 1);
|
|
1913
|
-
for (const [element, object] of this._private_elements) {
|
|
1914
|
-
const micro = element.micro;
|
|
1915
|
-
const width = element.width * micro.scaleX;
|
|
1916
|
-
const height = element.height * micro.scaleY;
|
|
1917
|
-
const anchorOffsetX = micro.anchorX * width;
|
|
1918
|
-
const anchorOffsetY = micro.anchorY * height;
|
|
1919
|
-
const cos = Math.cos(micro.rotation);
|
|
1920
|
-
const sin = Math.sin(micro.rotation);
|
|
1921
|
-
const rotatedAnchorX = anchorOffsetX * cos - anchorOffsetY * sin;
|
|
1922
|
-
const rotatedAnchorY = anchorOffsetX * sin + anchorOffsetY * cos;
|
|
1923
|
-
if (micro.anchorMode === UIAnchorMode.POSITION_ROTATION_SCALE) {
|
|
1924
|
-
object.position.x = element.x + micro.x - rotatedAnchorX;
|
|
1925
|
-
object.position.y = element.y + micro.y - rotatedAnchorY;
|
|
1926
|
-
}
|
|
1927
|
-
else {
|
|
1928
|
-
const rawAnchorOffsetX = micro.anchorX * element.width;
|
|
1929
|
-
const rawAnchorOffsetY = micro.anchorY * element.height;
|
|
1930
|
-
object.position.x =
|
|
1931
|
-
element.x + rawAnchorOffsetX - rotatedAnchorX + micro.x;
|
|
1932
|
-
object.position.y =
|
|
1933
|
-
element.y + rawAnchorOffsetY - rotatedAnchorY + micro.y;
|
|
1934
|
-
}
|
|
1935
|
-
object.scale.x = width;
|
|
1936
|
-
object.scale.y = height;
|
|
1937
|
-
object.rotation.z = micro.rotation;
|
|
1938
|
-
}
|
|
1939
|
-
}
|
|
1940
|
-
render(renderer) {
|
|
1941
2309
|
renderer.clear(false, true, true);
|
|
1942
2310
|
renderer.render(this._private_scene, this._private_camera);
|
|
1943
2311
|
renderer.setClearColor(originalClearColor);
|
|
@@ -1946,6 +2314,14 @@ class UISceneWrapper {
|
|
|
1946
2314
|
renderer.autoClearColor = originalAutoClearColor;
|
|
1947
2315
|
renderer.autoClearDepth = originalAutoClearDepth;
|
|
1948
2316
|
renderer.autoClearStencil = originalAutoClearStencil;
|
|
2317
|
+
return this;
|
|
2318
|
+
}
|
|
2319
|
+
_private_resolveDescriptor(handler) {
|
|
2320
|
+
const descriptor = this._private_descriptors.get(handler);
|
|
2321
|
+
if (!descriptor) {
|
|
2322
|
+
throw new Error(`No descriptor found for handler ${handler}`);
|
|
2323
|
+
}
|
|
2324
|
+
return descriptor;
|
|
1949
2325
|
}
|
|
1950
2326
|
}
|
|
1951
2327
|
|
|
@@ -2006,15 +2382,52 @@ function resolveRelation(relation) {
|
|
|
2006
2382
|
return relation ?? UIRelation.EQUAL;
|
|
2007
2383
|
}
|
|
2008
2384
|
|
|
2385
|
+
/**
|
|
2386
|
+
* Wrapper around the Kiwi constraint solver providing enhanced UI-specific functionality.
|
|
2387
|
+
*
|
|
2388
|
+
* UISolverWrapper abstracts the Kiwi (Cassowary) constraint solver to provide a more
|
|
2389
|
+
* UI-friendly interface with additional features like dynamic constraint modification,
|
|
2390
|
+
* required variables (P0 priority), partial constraint updates, and automatic solver
|
|
2391
|
+
* recovery. It manages variables and constraints through index-based references,
|
|
2392
|
+
* allowing for easy tracking and modification of layout constraints.
|
|
2393
|
+
*
|
|
2394
|
+
* Key features:
|
|
2395
|
+
* - Index-based variable and constraint management
|
|
2396
|
+
* - Required variables with P0 priority (always satisfied)
|
|
2397
|
+
* - Dynamic constraint modification without full rebuilds
|
|
2398
|
+
* - Automatic solver recovery on constraint conflicts
|
|
2399
|
+
* - Lazy evaluation with recalculation flags
|
|
2400
|
+
*
|
|
2401
|
+
* @see {@link UIExpression} - Expression system for constraint definitions
|
|
2402
|
+
* @see {@link UIPriority} - Priority levels for variables and constraints
|
|
2403
|
+
* @see {@link UIRelation} - Relational operators for constraints
|
|
2404
|
+
*/
|
|
2009
2405
|
class UISolverWrapper {
|
|
2010
2406
|
constructor() {
|
|
2407
|
+
/** The underlying Kiwi solver instance, undefined when solver needs rebuilding. */
|
|
2011
2408
|
this._private_solver = new Solver();
|
|
2409
|
+
/** Flag indicating whether variable values need recalculation. */
|
|
2012
2410
|
this._private_recalculationRequired = false;
|
|
2411
|
+
/** Map of variable indices to their descriptions. */
|
|
2013
2412
|
this._private_variables = new Map();
|
|
2413
|
+
/** Counter for generating unique variable indices. */
|
|
2014
2414
|
this._private_lastVariableIndex = 0;
|
|
2415
|
+
/** Map of constraint indices to their descriptions. */
|
|
2015
2416
|
this._private_constraints = new Map();
|
|
2417
|
+
/** Counter for generating unique constraint indices. */
|
|
2016
2418
|
this._private_lastConstraintIndex = 0;
|
|
2017
2419
|
}
|
|
2420
|
+
/**
|
|
2421
|
+
* Creates a new solver variable with the specified value and priority.
|
|
2422
|
+
*
|
|
2423
|
+
* Variables with P0 priority are treated as required (must be satisfied exactly)
|
|
2424
|
+
* and are implemented using equality constraints. Other priorities use edit
|
|
2425
|
+
* variables that can be adjusted by the solver.
|
|
2426
|
+
*
|
|
2427
|
+
* @param value - Initial value for the variable
|
|
2428
|
+
* @param priority - Priority level for constraint solving
|
|
2429
|
+
* @returns Unique index identifier for the created variable
|
|
2430
|
+
*/
|
|
2018
2431
|
createVariable(value, priority) {
|
|
2019
2432
|
const index = this._private_lastVariableIndex++;
|
|
2020
2433
|
const variable = new Variable();
|
|
@@ -2042,6 +2455,15 @@ class UISolverWrapper {
|
|
|
2042
2455
|
this._private_recalculationRequired = true;
|
|
2043
2456
|
return index;
|
|
2044
2457
|
}
|
|
2458
|
+
/**
|
|
2459
|
+
* Removes a variable from the solver system.
|
|
2460
|
+
*
|
|
2461
|
+
* The variable must not be referenced by any existing constraints.
|
|
2462
|
+
* Cleans up both the variable itself and any associated required constraint.
|
|
2463
|
+
*
|
|
2464
|
+
* @param index - Index of the variable to remove
|
|
2465
|
+
* @throws Will throw an error if the variable doesn't exist or is still in use
|
|
2466
|
+
*/
|
|
2045
2467
|
removeVariable(index) {
|
|
2046
2468
|
const description = this._private_variables.get(index);
|
|
2047
2469
|
if (description === undefined) {
|
|
@@ -2063,6 +2485,17 @@ class UISolverWrapper {
|
|
|
2063
2485
|
this._private_variables.delete(index);
|
|
2064
2486
|
this._private_recalculationRequired = true;
|
|
2065
2487
|
}
|
|
2488
|
+
/**
|
|
2489
|
+
* Suggests a new value for an existing variable.
|
|
2490
|
+
*
|
|
2491
|
+
* For P0 priority variables, rebuilds the associated constraint.
|
|
2492
|
+
* For other priorities, suggests the value to the solver's edit system.
|
|
2493
|
+
* Only triggers updates if the value actually changes.
|
|
2494
|
+
*
|
|
2495
|
+
* @param index - Index of the variable to update
|
|
2496
|
+
* @param value - New suggested value
|
|
2497
|
+
* @throws Will throw an error if the variable doesn't exist
|
|
2498
|
+
*/
|
|
2066
2499
|
suggestVariableValue(index, value) {
|
|
2067
2500
|
const description = this._private_variables.get(index);
|
|
2068
2501
|
if (description === undefined) {
|
|
@@ -2079,6 +2512,17 @@ class UISolverWrapper {
|
|
|
2079
2512
|
this._private_recalculationRequired = true;
|
|
2080
2513
|
}
|
|
2081
2514
|
}
|
|
2515
|
+
/**
|
|
2516
|
+
* Changes the priority of an existing variable.
|
|
2517
|
+
*
|
|
2518
|
+
* Switching to/from P0 priority changes how the variable is handled:
|
|
2519
|
+
* - P0: Creates required constraint (must be satisfied exactly)
|
|
2520
|
+
* - Other: Uses edit variable system (can be adjusted by solver)
|
|
2521
|
+
*
|
|
2522
|
+
* @param index - Index of the variable to modify
|
|
2523
|
+
* @param priority - New priority level
|
|
2524
|
+
* @throws Will throw an error if the variable doesn't exist
|
|
2525
|
+
*/
|
|
2082
2526
|
setVariablePriority(index, priority) {
|
|
2083
2527
|
const description = this._private_variables.get(index);
|
|
2084
2528
|
if (description === undefined) {
|
|
@@ -2112,6 +2556,16 @@ class UISolverWrapper {
|
|
|
2112
2556
|
this._private_recalculationRequired = true;
|
|
2113
2557
|
}
|
|
2114
2558
|
}
|
|
2559
|
+
/**
|
|
2560
|
+
* Reads the current solved value of a variable.
|
|
2561
|
+
*
|
|
2562
|
+
* Triggers solver recalculation if needed and rebuilds the solver
|
|
2563
|
+
* if it was invalidated due to constraint conflicts.
|
|
2564
|
+
*
|
|
2565
|
+
* @param index - Index of the variable to read
|
|
2566
|
+
* @returns Current solved value of the variable
|
|
2567
|
+
* @throws Will throw an error if the variable doesn't exist
|
|
2568
|
+
*/
|
|
2115
2569
|
readVariableValue(index) {
|
|
2116
2570
|
const description = this._private_variables.get(index);
|
|
2117
2571
|
if (description === undefined) {
|
|
@@ -2126,6 +2580,19 @@ class UISolverWrapper {
|
|
|
2126
2580
|
}
|
|
2127
2581
|
return description.variable.value();
|
|
2128
2582
|
}
|
|
2583
|
+
/**
|
|
2584
|
+
* Creates a new constraint between two expressions.
|
|
2585
|
+
*
|
|
2586
|
+
* Constraints can be enabled or disabled, and all properties can be
|
|
2587
|
+
* modified later without recreating the constraint.
|
|
2588
|
+
*
|
|
2589
|
+
* @param lhs - Left-hand side expression
|
|
2590
|
+
* @param rhs - Right-hand side expression
|
|
2591
|
+
* @param relation - Relational operator (equal, less than, greater than)
|
|
2592
|
+
* @param priority - Priority level for constraint solving
|
|
2593
|
+
* @param enabled - Whether the constraint is initially active
|
|
2594
|
+
* @returns Unique index identifier for the created constraint
|
|
2595
|
+
*/
|
|
2129
2596
|
createConstraint(lhs, rhs, relation, priority, enabled) {
|
|
2130
2597
|
const index = this._private_lastConstraintIndex++;
|
|
2131
2598
|
const constraint = this._private_buildConstraint(lhs, rhs, relation, priority);
|
|
@@ -2148,6 +2615,15 @@ class UISolverWrapper {
|
|
|
2148
2615
|
}
|
|
2149
2616
|
return index;
|
|
2150
2617
|
}
|
|
2618
|
+
/**
|
|
2619
|
+
* Removes a constraint from the solver system.
|
|
2620
|
+
*
|
|
2621
|
+
* If the constraint is currently enabled, it will be removed from
|
|
2622
|
+
* the active solver before deletion.
|
|
2623
|
+
*
|
|
2624
|
+
* @param index - Index of the constraint to remove
|
|
2625
|
+
* @throws Will throw an error if the constraint doesn't exist
|
|
2626
|
+
*/
|
|
2151
2627
|
removeConstraint(index) {
|
|
2152
2628
|
const description = this._private_constraints.get(index);
|
|
2153
2629
|
if (description === undefined) {
|
|
@@ -2164,6 +2640,16 @@ class UISolverWrapper {
|
|
|
2164
2640
|
this._private_constraints.delete(index);
|
|
2165
2641
|
this._private_recalculationRequired = true;
|
|
2166
2642
|
}
|
|
2643
|
+
/**
|
|
2644
|
+
* Updates the left-hand side expression of an existing constraint.
|
|
2645
|
+
*
|
|
2646
|
+
* Rebuilds the underlying constraint with the new expression while
|
|
2647
|
+
* preserving all other properties.
|
|
2648
|
+
*
|
|
2649
|
+
* @param index - Index of the constraint to modify
|
|
2650
|
+
* @param lhs - New left-hand side expression
|
|
2651
|
+
* @throws Will throw an error if the constraint doesn't exist
|
|
2652
|
+
*/
|
|
2167
2653
|
setConstraintLHS(index, lhs) {
|
|
2168
2654
|
const description = this._private_constraints.get(index);
|
|
2169
2655
|
if (description === undefined) {
|
|
@@ -2173,6 +2659,16 @@ class UISolverWrapper {
|
|
|
2173
2659
|
this._private_rebuildConstraintByDescription(description);
|
|
2174
2660
|
this._private_recalculationRequired = true;
|
|
2175
2661
|
}
|
|
2662
|
+
/**
|
|
2663
|
+
* Updates the right-hand side expression of an existing constraint.
|
|
2664
|
+
*
|
|
2665
|
+
* Rebuilds the underlying constraint with the new expression while
|
|
2666
|
+
* preserving all other properties.
|
|
2667
|
+
*
|
|
2668
|
+
* @param index - Index of the constraint to modify
|
|
2669
|
+
* @param rhs - New right-hand side expression
|
|
2670
|
+
* @throws Will throw an error if the constraint doesn't exist
|
|
2671
|
+
*/
|
|
2176
2672
|
setConstraintRHS(index, rhs) {
|
|
2177
2673
|
const description = this._private_constraints.get(index);
|
|
2178
2674
|
if (description === undefined) {
|
|
@@ -2182,24 +2678,58 @@ class UISolverWrapper {
|
|
|
2182
2678
|
this._private_rebuildConstraintByDescription(description);
|
|
2183
2679
|
this._private_recalculationRequired = true;
|
|
2184
2680
|
}
|
|
2681
|
+
/**
|
|
2682
|
+
* Updates the relational operator of an existing constraint.
|
|
2683
|
+
*
|
|
2684
|
+
* Changes how the left and right expressions are compared
|
|
2685
|
+
* (equal, less than, greater than).
|
|
2686
|
+
*
|
|
2687
|
+
* @param index - Index of the constraint to modify
|
|
2688
|
+
* @param relation - New relational operator
|
|
2689
|
+
* @throws Will throw an error if the constraint doesn't exist
|
|
2690
|
+
*/
|
|
2185
2691
|
setConstraintRelation(index, relation) {
|
|
2186
2692
|
const description = this._private_constraints.get(index);
|
|
2187
2693
|
if (description === undefined) {
|
|
2188
2694
|
throw new Error(`Constraint ${index} does not exist`);
|
|
2189
2695
|
}
|
|
2190
|
-
description.relation
|
|
2191
|
-
|
|
2192
|
-
|
|
2696
|
+
if (description.relation !== relation) {
|
|
2697
|
+
description.relation = relation;
|
|
2698
|
+
this._private_rebuildConstraintByDescription(description);
|
|
2699
|
+
this._private_recalculationRequired = true;
|
|
2700
|
+
}
|
|
2193
2701
|
}
|
|
2702
|
+
/**
|
|
2703
|
+
* Updates the priority level of an existing constraint.
|
|
2704
|
+
*
|
|
2705
|
+
* Higher priority constraints are more likely to be satisfied
|
|
2706
|
+
* when conflicts arise.
|
|
2707
|
+
*
|
|
2708
|
+
* @param index - Index of the constraint to modify
|
|
2709
|
+
* @param priority - New priority level
|
|
2710
|
+
* @throws Will throw an error if the constraint doesn't exist
|
|
2711
|
+
*/
|
|
2194
2712
|
setConstraintPriority(index, priority) {
|
|
2195
2713
|
const description = this._private_constraints.get(index);
|
|
2196
2714
|
if (description === undefined) {
|
|
2197
2715
|
throw new Error(`Constraint ${index} does not exist`);
|
|
2198
2716
|
}
|
|
2199
|
-
description.priority
|
|
2200
|
-
|
|
2201
|
-
|
|
2717
|
+
if (description.priority !== priority) {
|
|
2718
|
+
description.priority = priority;
|
|
2719
|
+
this._private_rebuildConstraintByDescription(description);
|
|
2720
|
+
this._private_recalculationRequired = true;
|
|
2721
|
+
}
|
|
2202
2722
|
}
|
|
2723
|
+
/**
|
|
2724
|
+
* Enables or disables an existing constraint.
|
|
2725
|
+
*
|
|
2726
|
+
* Disabled constraints are not considered during solving but
|
|
2727
|
+
* remain in the system for potential re-enabling.
|
|
2728
|
+
*
|
|
2729
|
+
* @param index - Index of the constraint to modify
|
|
2730
|
+
* @param enabled - Whether the constraint should be active
|
|
2731
|
+
* @throws Will throw an error if the constraint doesn't exist
|
|
2732
|
+
*/
|
|
2203
2733
|
setConstraintEnabled(index, enabled) {
|
|
2204
2734
|
const description = this._private_constraints.get(index);
|
|
2205
2735
|
if (description === undefined) {
|
|
@@ -2218,6 +2748,13 @@ class UISolverWrapper {
|
|
|
2218
2748
|
this._private_recalculationRequired = true;
|
|
2219
2749
|
}
|
|
2220
2750
|
}
|
|
2751
|
+
/**
|
|
2752
|
+
* Rebuilds a variable in the solver system with new properties.
|
|
2753
|
+
*
|
|
2754
|
+
* Temporarily removes all constraints that reference the variable,
|
|
2755
|
+
* updates the variable configuration, then rebuilds and re-adds
|
|
2756
|
+
* the dependent constraints.
|
|
2757
|
+
*/
|
|
2221
2758
|
_private_rebuildVariable(index, description) {
|
|
2222
2759
|
const dependConstraints = [];
|
|
2223
2760
|
for (const cDescription of this._private_constraints.values()) {
|
|
@@ -2246,11 +2783,22 @@ class UISolverWrapper {
|
|
|
2246
2783
|
}
|
|
2247
2784
|
}
|
|
2248
2785
|
}
|
|
2786
|
+
/**
|
|
2787
|
+
* Rebuilds a constraint based on its current description.
|
|
2788
|
+
*
|
|
2789
|
+
* Uses different rebuild strategies depending on whether the
|
|
2790
|
+
* constraint is currently enabled.
|
|
2791
|
+
*/
|
|
2249
2792
|
_private_rebuildConstraintByDescription(description) {
|
|
2250
2793
|
description.constraint = description.enabled
|
|
2251
2794
|
? this._private_rebuildConstraint(description.constraint, description.lhs, description.rhs, description.relation, description.priority)
|
|
2252
2795
|
: this._private_buildConstraint(description.lhs, description.rhs, description.relation, description.priority);
|
|
2253
2796
|
}
|
|
2797
|
+
/**
|
|
2798
|
+
* Rebuilds a constraint by removing the old one and creating a new one.
|
|
2799
|
+
*
|
|
2800
|
+
* Safely handles solver state transitions and constraint replacement.
|
|
2801
|
+
*/
|
|
2254
2802
|
_private_rebuildConstraint(oldConstraint, lhs, rhs, relation, priority) {
|
|
2255
2803
|
try {
|
|
2256
2804
|
this._private_solver?.removeConstraint(oldConstraint);
|
|
@@ -2267,9 +2815,20 @@ class UISolverWrapper {
|
|
|
2267
2815
|
}
|
|
2268
2816
|
return constraint;
|
|
2269
2817
|
}
|
|
2818
|
+
/**
|
|
2819
|
+
* Creates a new Kiwi constraint from UI expressions and parameters.
|
|
2820
|
+
*
|
|
2821
|
+
* Converts UI-level expressions and enums to Kiwi-compatible formats.
|
|
2822
|
+
*/
|
|
2270
2823
|
_private_buildConstraint(lhs, rhs, relation, priority) {
|
|
2271
2824
|
return new Constraint(this._private_convertExpression(lhs), convertRelation(relation), this._private_convertExpression(rhs), convertPriority(priority));
|
|
2272
2825
|
}
|
|
2826
|
+
/**
|
|
2827
|
+
* Converts a UIExpression to a Kiwi Expression.
|
|
2828
|
+
*
|
|
2829
|
+
* Maps variable indices to their corresponding Kiwi Variable instances
|
|
2830
|
+
* and preserves coefficients and constants.
|
|
2831
|
+
*/
|
|
2273
2832
|
_private_convertExpression(expression) {
|
|
2274
2833
|
return new Expression(...expression["prepareTermsInternal"]().map(([variableIndex, coefficient]) => {
|
|
2275
2834
|
const description = this._private_variables.get(variableIndex);
|
|
@@ -2279,6 +2838,12 @@ class UISolverWrapper {
|
|
|
2279
2838
|
return [coefficient, description.variable];
|
|
2280
2839
|
}), expression.constant);
|
|
2281
2840
|
}
|
|
2841
|
+
/**
|
|
2842
|
+
* Completely rebuilds the solver from scratch.
|
|
2843
|
+
*
|
|
2844
|
+
* Re-adds all variables and constraints to a fresh solver instance.
|
|
2845
|
+
* Used for recovery when the solver enters an invalid state.
|
|
2846
|
+
*/
|
|
2282
2847
|
_private_rebuildSolver() {
|
|
2283
2848
|
if (this._private_solver) {
|
|
2284
2849
|
throw new Error("Solver already exists");
|
|
@@ -2352,6 +2917,8 @@ class UILayer extends i {
|
|
|
2352
2917
|
this.solverWrapper = new UISolverWrapper();
|
|
2353
2918
|
/** Internal storage for the current visibility/interaction mode. */
|
|
2354
2919
|
this.modeInternal = UIMode.VISIBLE;
|
|
2920
|
+
/** Collection of input listeners for handling user interactions, sorted by z-index. */
|
|
2921
|
+
this._private_inputListeners = [];
|
|
2355
2922
|
this.sceneWrapper = new UISceneWrapper(w, h);
|
|
2356
2923
|
this.xVariable = this.solverWrapper.createVariable(0, UIPriority.P0);
|
|
2357
2924
|
this.yVariable = this.solverWrapper.createVariable(0, UIPriority.P0);
|
|
@@ -2435,7 +3002,6 @@ class UILayer extends i {
|
|
|
2435
3002
|
*/
|
|
2436
3003
|
renderInternal(renderer, deltaTime) {
|
|
2437
3004
|
if (this.mode !== UIMode.HIDDEN) {
|
|
2438
|
-
this.sceneWrapper.prepareRender(renderer);
|
|
2439
3005
|
this.emit(UILayerEvent.WILL_RENDER, renderer, deltaTime, this);
|
|
2440
3006
|
this.sceneWrapper.render(renderer);
|
|
2441
3007
|
}
|
|
@@ -2451,10 +3017,11 @@ class UILayer extends i {
|
|
|
2451
3017
|
* @param y - The y-coordinate of the click
|
|
2452
3018
|
* @protected
|
|
2453
3019
|
*/
|
|
2454
|
-
|
|
3020
|
+
pointerClickInternal(x, y) {
|
|
2455
3021
|
if (this.mode === UIMode.INTERACTIVE) {
|
|
2456
|
-
|
|
2457
|
-
|
|
3022
|
+
this._private_inputListeners.sort((a, b) => b.zIndex - a.zIndex);
|
|
3023
|
+
for (const listener of this._private_inputListeners) {
|
|
3024
|
+
if (listener.listener.catchClick(x, y)) {
|
|
2458
3025
|
return;
|
|
2459
3026
|
}
|
|
2460
3027
|
}
|
|
@@ -2479,9 +3046,58 @@ class UILayer extends i {
|
|
|
2479
3046
|
*
|
|
2480
3047
|
* @returns The scene wrapper instance
|
|
2481
3048
|
*/
|
|
2482
|
-
["
|
|
3049
|
+
["getSceneWrapperClientAPI"]() {
|
|
2483
3050
|
return this.sceneWrapper;
|
|
2484
3051
|
}
|
|
3052
|
+
/**
|
|
3053
|
+
* Internal method for registering an input listener for pointer events.
|
|
3054
|
+
*
|
|
3055
|
+
* Adds a listener to handle click events with the specified z-index priority.
|
|
3056
|
+
* Higher z-index listeners are processed first during event handling.
|
|
3057
|
+
*
|
|
3058
|
+
* @param listener - The input listener to register
|
|
3059
|
+
* @param zIndex - The z-index priority for event handling order
|
|
3060
|
+
* @throws Will throw an error if the listener is already registered
|
|
3061
|
+
*/
|
|
3062
|
+
["listenPointerInput"](listener, zIndex) {
|
|
3063
|
+
if (this._private_inputListeners.find((l) => l.listener === listener)) {
|
|
3064
|
+
throw new Error("Listener already exists");
|
|
3065
|
+
}
|
|
3066
|
+
this._private_inputListeners.push({ zIndex, listener });
|
|
3067
|
+
}
|
|
3068
|
+
/**
|
|
3069
|
+
* Internal method for updating the z-index of an existing input listener.
|
|
3070
|
+
*
|
|
3071
|
+
* Changes the priority order for event handling of an already registered listener.
|
|
3072
|
+
* The listener must already exist in the system.
|
|
3073
|
+
*
|
|
3074
|
+
* @param listener - The input listener to update
|
|
3075
|
+
* @param zIndex - The new z-index priority
|
|
3076
|
+
* @throws Will throw an error if the listener is not found
|
|
3077
|
+
*/
|
|
3078
|
+
["setListenerZIndex"](listener, zIndex) {
|
|
3079
|
+
const index = this._private_inputListeners.findIndex((l) => l.listener === listener);
|
|
3080
|
+
if (index === -1) {
|
|
3081
|
+
throw new Error("Listener not found");
|
|
3082
|
+
}
|
|
3083
|
+
this._private_inputListeners[index].zIndex = zIndex;
|
|
3084
|
+
}
|
|
3085
|
+
/**
|
|
3086
|
+
* Internal method for unregistering an input listener.
|
|
3087
|
+
*
|
|
3088
|
+
* Removes the specified listener from the event handling system.
|
|
3089
|
+
* The listener will no longer receive click events.
|
|
3090
|
+
*
|
|
3091
|
+
* @param listener - The input listener to remove
|
|
3092
|
+
* @throws Will throw an error if the listener is not found
|
|
3093
|
+
*/
|
|
3094
|
+
["unlistenPointerInput"](listener) {
|
|
3095
|
+
const index = this._private_inputListeners.findIndex((l) => l.listener === listener);
|
|
3096
|
+
if (index === -1) {
|
|
3097
|
+
throw new Error("Listener not found");
|
|
3098
|
+
}
|
|
3099
|
+
this._private_inputListeners.splice(index, 1);
|
|
3100
|
+
}
|
|
2485
3101
|
}
|
|
2486
3102
|
|
|
2487
3103
|
/**
|
|
@@ -2499,6 +3115,9 @@ class UIConstraint {
|
|
|
2499
3115
|
/**
|
|
2500
3116
|
* Creates a new UIConstraint instance.
|
|
2501
3117
|
*
|
|
3118
|
+
* Automatically connects to the layer's constraint solver for managing
|
|
3119
|
+
* layout relationships and constraint operations.
|
|
3120
|
+
*
|
|
2502
3121
|
* @param layer - The UI layer that contains this constraint
|
|
2503
3122
|
*/
|
|
2504
3123
|
constructor(layer) {
|
|
@@ -2541,8 +3160,6 @@ class UISingleParameterConstraint extends UIConstraint {
|
|
|
2541
3160
|
*
|
|
2542
3161
|
* Updates the constraint's enabled state in the solver based on the
|
|
2543
3162
|
* current orientation and the constraint's orientation setting.
|
|
2544
|
-
*
|
|
2545
|
-
* @private
|
|
2546
3163
|
*/
|
|
2547
3164
|
this._private_onOrientationChange = () => {
|
|
2548
3165
|
this.solverWrapper.setConstraintEnabled(this.constraint, this.isConstraintEnabled());
|
|
@@ -2917,7 +3534,6 @@ class UIHorizontalDistanceConstraint extends UISingleParameterConstraint {
|
|
|
2917
3534
|
* For plane elements, the anchor determines the reference point within the element's width.
|
|
2918
3535
|
*
|
|
2919
3536
|
* @returns The UIExpression representing the horizontal distance calculation
|
|
2920
|
-
* @private
|
|
2921
3537
|
*/
|
|
2922
3538
|
_private_buildLHS() {
|
|
2923
3539
|
let aExpression;
|
|
@@ -2988,7 +3604,7 @@ class UIHorizontalProportionConstraint extends UISingleParameterConstraint {
|
|
|
2988
3604
|
}
|
|
2989
3605
|
/**
|
|
2990
3606
|
* Gets the current proportion value being enforced.
|
|
2991
|
-
* @returns The proportion ratio (elementA.width = elementB.width
|
|
3607
|
+
* @returns The proportion ratio (elementA.width * proportion = elementB.width)
|
|
2992
3608
|
*/
|
|
2993
3609
|
get proportion() {
|
|
2994
3610
|
return this._private_proportionInternal;
|
|
@@ -3010,7 +3626,6 @@ class UIHorizontalProportionConstraint extends UISingleParameterConstraint {
|
|
|
3010
3626
|
* This enforces the relationship: elementA.width * proportion = elementB.width
|
|
3011
3627
|
*
|
|
3012
3628
|
* @returns The UIExpression representing the proportional width relationship
|
|
3013
|
-
* @private
|
|
3014
3629
|
*/
|
|
3015
3630
|
_private_buildRHS() {
|
|
3016
3631
|
return UIExpression.minus(new UIExpression(0, [[this._private_a.wVariable, this._private_proportionInternal]]), new UIExpression(0, [[this._private_b.wVariable, 1]]));
|
|
@@ -3114,7 +3729,6 @@ class UIVerticalDistanceConstraint extends UISingleParameterConstraint {
|
|
|
3114
3729
|
* For plane elements, the anchor determines the reference point within the element's height.
|
|
3115
3730
|
*
|
|
3116
3731
|
* @returns The UIExpression representing the vertical distance calculation
|
|
3117
|
-
* @private
|
|
3118
3732
|
*/
|
|
3119
3733
|
_private_buildLHS() {
|
|
3120
3734
|
let aExpression;
|
|
@@ -3185,7 +3799,7 @@ class UIVerticalProportionConstraint extends UISingleParameterConstraint {
|
|
|
3185
3799
|
}
|
|
3186
3800
|
/**
|
|
3187
3801
|
* Gets the current proportion value being enforced.
|
|
3188
|
-
* @returns The proportion ratio (elementA.height = elementB.height
|
|
3802
|
+
* @returns The proportion ratio (elementA.height * proportion = elementB.height)
|
|
3189
3803
|
*/
|
|
3190
3804
|
get proportion() {
|
|
3191
3805
|
return this._private_proportionInternal;
|
|
@@ -3207,7 +3821,6 @@ class UIVerticalProportionConstraint extends UISingleParameterConstraint {
|
|
|
3207
3821
|
* This enforces the relationship: elementA.height * proportion = elementB.height
|
|
3208
3822
|
*
|
|
3209
3823
|
* @returns The UIExpression representing the proportional height relationship
|
|
3210
|
-
* @private
|
|
3211
3824
|
*/
|
|
3212
3825
|
_private_buildRHS() {
|
|
3213
3826
|
return UIExpression.minus(new UIExpression(0, [[this._private_a.hVariable, this._private_proportionInternal]]), new UIExpression(0, [[this._private_b.hVariable, 1]]));
|
|
@@ -3420,7 +4033,6 @@ class UIAspectConstraint extends UISingleParameterConstraint {
|
|
|
3420
4033
|
* This enforces the relationship: width = height * aspect
|
|
3421
4034
|
*
|
|
3422
4035
|
* @returns The UIExpression representing the constraint equation
|
|
3423
|
-
* @private
|
|
3424
4036
|
*/
|
|
3425
4037
|
_private_buildLHS() {
|
|
3426
4038
|
return new UIExpression(0, [
|
|
@@ -3442,6 +4054,8 @@ const DEFAULT_ANCHOR$2 = 0.5;
|
|
|
3442
4054
|
* - Positioned at the specified anchor point within the passive element
|
|
3443
4055
|
* - Sized to be at least as large as the passive element in both dimensions
|
|
3444
4056
|
* - Scaled proportionally to maintain aspect ratio (if enabled)
|
|
4057
|
+
*
|
|
4058
|
+
* The constraints ensure: passive.dimension * 1 ≤ active.dimension (active covers passive)
|
|
3445
4059
|
*/
|
|
3446
4060
|
class UICoverConstraintBuilder {
|
|
3447
4061
|
/**
|
|
@@ -3501,6 +4115,8 @@ const DEFAULT_ANCHOR$1 = 0.5;
|
|
|
3501
4115
|
* - Positioned at the specified anchor point within the passive element
|
|
3502
4116
|
* - Sized to fit entirely within the passive element in both dimensions
|
|
3503
4117
|
* - Scaled proportionally to maintain aspect ratio (if enabled)
|
|
4118
|
+
*
|
|
4119
|
+
* The constraints ensure: passive.dimension * 1 ≥ active.dimension (active fits within passive)
|
|
3504
4120
|
*/
|
|
3505
4121
|
class UIFitConstraintBuilder {
|
|
3506
4122
|
/**
|
|
@@ -3720,12 +4336,16 @@ class UIDummy extends UIAnchor {
|
|
|
3720
4336
|
* @throws Will throw an error if width or height are not valid positive numbers
|
|
3721
4337
|
* @see {@link assertValidPositiveNumber}
|
|
3722
4338
|
*/
|
|
3723
|
-
constructor(layer,
|
|
3724
|
-
|
|
3725
|
-
|
|
4339
|
+
constructor(layer, options = {}) {
|
|
4340
|
+
const x = options.x ?? 0;
|
|
4341
|
+
const y = options.y ?? 0;
|
|
4342
|
+
const w = options.width ?? DEFAULT_SIZE;
|
|
4343
|
+
const h = options.height ?? DEFAULT_SIZE;
|
|
4344
|
+
assertValidPositiveNumber(w, "UIDummy width");
|
|
4345
|
+
assertValidPositiveNumber(h, "UIDummy height");
|
|
3726
4346
|
super(layer, x, y);
|
|
3727
|
-
this.wVariable = this.solverWrapper.createVariable(
|
|
3728
|
-
this.hVariable = this.solverWrapper.createVariable(
|
|
4347
|
+
this.wVariable = this.solverWrapper.createVariable(w, UIPriority.P6);
|
|
4348
|
+
this.hVariable = this.solverWrapper.createVariable(h, UIPriority.P6);
|
|
3729
4349
|
}
|
|
3730
4350
|
/**
|
|
3731
4351
|
* Gets the current width value from the solver.
|
|
@@ -3776,13 +4396,33 @@ class UIDummy extends UIAnchor {
|
|
|
3776
4396
|
}
|
|
3777
4397
|
}
|
|
3778
4398
|
|
|
3779
|
-
/**
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
4399
|
+
/**
|
|
4400
|
+
* Events that can be emitted by UI elements.
|
|
4401
|
+
*/
|
|
4402
|
+
var UIInputEvent;
|
|
4403
|
+
(function (UIInputEvent) {
|
|
4404
|
+
/** Emitted when the element is clicked. */
|
|
4405
|
+
UIInputEvent["CLICK"] = "click";
|
|
4406
|
+
})(UIInputEvent || (UIInputEvent = {}));
|
|
4407
|
+
|
|
4408
|
+
/**
|
|
4409
|
+
* Defines the anchor mode for UIMicro, determining which transformations are applied around the anchor point.
|
|
4410
|
+
*/
|
|
4411
|
+
var UIMicroAnchorMode;
|
|
4412
|
+
(function (UIMicroAnchorMode) {
|
|
4413
|
+
/** Rotation and scaling are applied around the anchor point */
|
|
4414
|
+
UIMicroAnchorMode[UIMicroAnchorMode["ROTATION_SCALE"] = 0] = "ROTATION_SCALE";
|
|
4415
|
+
/** Position, rotation, and scaling transformations are all applied around the anchor point */
|
|
4416
|
+
UIMicroAnchorMode[UIMicroAnchorMode["POSITION_ROTATION_SCALE"] = 1] = "POSITION_ROTATION_SCALE";
|
|
4417
|
+
})(UIMicroAnchorMode || (UIMicroAnchorMode = {}));
|
|
4418
|
+
|
|
4419
|
+
/** Default position value for x and y coordinates. */
|
|
4420
|
+
const DEFAULT_POSITION = 0;
|
|
4421
|
+
/** Default anchor point value for anchorX and anchorY. */
|
|
4422
|
+
const DEFAULT_ANCHOR = 0.5;
|
|
4423
|
+
/** Default scale value for scaleX and scaleY. */
|
|
4424
|
+
const DEFAULT_SCALE = 1;
|
|
4425
|
+
/** Default rotation value in radians. */
|
|
3786
4426
|
const DEFAULT_ROTATION = 0;
|
|
3787
4427
|
/**
|
|
3788
4428
|
* Micro-transformation system for non-constraint based UI element adjustments.
|
|
@@ -3815,7 +4455,7 @@ class UIMicro {
|
|
|
3815
4455
|
/** Internal storage for rotation in radians. */
|
|
3816
4456
|
this._private_rotationInternal = DEFAULT_ROTATION;
|
|
3817
4457
|
/** Internal storage for anchor mode determining which transformations are applied around the anchor point. */
|
|
3818
|
-
this._private_anchorModeInternal =
|
|
4458
|
+
this._private_anchorModeInternal = UIMicroAnchorMode.ROTATION_SCALE;
|
|
3819
4459
|
/** Flag indicating if any transformation properties have changed. */
|
|
3820
4460
|
this._private_recalculationRequired = false;
|
|
3821
4461
|
}
|
|
@@ -4041,27 +4681,35 @@ class UIMicro {
|
|
|
4041
4681
|
}
|
|
4042
4682
|
}
|
|
4043
4683
|
|
|
4684
|
+
const position = new Vector3();
|
|
4685
|
+
const quaternion = new Quaternion();
|
|
4686
|
+
const scale = new Vector3();
|
|
4687
|
+
const matrix = new Matrix4();
|
|
4688
|
+
const axis = new Vector3(0, 0, 1);
|
|
4044
4689
|
/**
|
|
4045
|
-
*
|
|
4690
|
+
* Checks if a point (x, y) is within the bounds of a UI element.
|
|
4691
|
+
* @param x - The x coordinate to test
|
|
4692
|
+
* @param y - The y coordinate to test
|
|
4693
|
+
* @param element - The UI element to test against
|
|
4694
|
+
* @returns True if the point is within the element's bounds
|
|
4046
4695
|
*/
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4696
|
+
function isElementClicked(x, y, element) {
|
|
4697
|
+
return (x > element.x &&
|
|
4698
|
+
x < element.x + element.width &&
|
|
4699
|
+
y > element.y &&
|
|
4700
|
+
y < element.y + element.height);
|
|
4701
|
+
}
|
|
4052
4702
|
/**
|
|
4053
4703
|
* Abstract base class for all renderable UI elements with dimensions.
|
|
4054
4704
|
*
|
|
4055
4705
|
* UIElement serves as the fundamental building block for all other UI elements
|
|
4056
4706
|
* that need to be visually rendered. It extends UIAnchor with dimensional properties
|
|
4057
|
-
* and integrates with the Three.js rendering system through
|
|
4707
|
+
* and integrates with the Three.js rendering system through shader-based planes. This class
|
|
4058
4708
|
* provides essential functionality for positioning, sizing, rendering, visibility,
|
|
4059
4709
|
* z-index management, and user interaction.
|
|
4060
4710
|
*
|
|
4061
|
-
* @template T - The type of Three.js Object3D used for rendering
|
|
4062
4711
|
* @see {@link UIAnchor} - Base class providing position functionality
|
|
4063
4712
|
* @see {@link UIPlaneElement} - Interface defining dimensional element behavior
|
|
4064
|
-
* @see {@link UISceneWrapper} - Scene management for rendering
|
|
4065
4713
|
* @see {@link UIMicro} - Micro-optimization utilities
|
|
4066
4714
|
*/
|
|
4067
4715
|
class UIElement extends UIAnchor {
|
|
@@ -4073,23 +4721,41 @@ class UIElement extends UIAnchor {
|
|
|
4073
4721
|
* @param y - Initial y-coordinate position
|
|
4074
4722
|
* @param width - Initial width dimension (must be positive)
|
|
4075
4723
|
* @param height - Initial height dimension (must be positive)
|
|
4076
|
-
* @param
|
|
4724
|
+
* @param source - GLSL shader source code for rendering this element
|
|
4725
|
+
* @param uniforms - Uniform values to pass to the shader
|
|
4077
4726
|
* @throws Will throw an error if width or height are not valid positive numbers
|
|
4078
4727
|
* @see {@link assertValidPositiveNumber}
|
|
4079
4728
|
*/
|
|
4080
|
-
constructor(layer, x, y, width, height,
|
|
4729
|
+
constructor(layer, x, y, width, height, source, uniforms) {
|
|
4081
4730
|
assertValidPositiveNumber(width, "UIElement width");
|
|
4082
4731
|
assertValidPositiveNumber(height, "UIElement height");
|
|
4083
4732
|
super(layer, x, y);
|
|
4084
|
-
this.object = object;
|
|
4085
4733
|
/** Micro-transformation system for non-constraint based positioning, scaling, and rotation adjustments. */
|
|
4086
4734
|
this.micro = new UIMicro();
|
|
4087
4735
|
/** Internal storage for the current visibility/interaction mode. */
|
|
4088
4736
|
this.modeInternal = UIMode.VISIBLE;
|
|
4089
|
-
|
|
4090
|
-
this.
|
|
4737
|
+
/** Internal storage for the transparency rendering mode. */
|
|
4738
|
+
this.transparencyInternal = UITransparencyMode.CLIP;
|
|
4739
|
+
/** Internal storage for the z-index (depth) value. */
|
|
4740
|
+
this.zIndexInternal = 0;
|
|
4741
|
+
/**
|
|
4742
|
+
* Handles click events when the element is in interactive mode.
|
|
4743
|
+
* @param x - The x coordinate of the click
|
|
4744
|
+
* @param y - The y coordinate of the click
|
|
4745
|
+
* @returns True if the click was within this element's bounds
|
|
4746
|
+
*/
|
|
4747
|
+
this.onClick = (x, y) => {
|
|
4748
|
+
const clicked = isElementClicked(x, y, this);
|
|
4749
|
+
if (clicked) {
|
|
4750
|
+
this.emit(UIInputEvent.CLICK, x, y, this);
|
|
4751
|
+
}
|
|
4752
|
+
return clicked;
|
|
4753
|
+
};
|
|
4754
|
+
this.layer.on(UILayerEvent.WILL_RENDER, this.onWillRender, this);
|
|
4091
4755
|
this.wVariable = this.solverWrapper.createVariable(width, UIPriority.P6);
|
|
4092
4756
|
this.hVariable = this.solverWrapper.createVariable(height, UIPriority.P6);
|
|
4757
|
+
this.sceneWrapper = layer["getSceneWrapperClientAPI"]();
|
|
4758
|
+
this.planeHandler = this.sceneWrapper.createPlane(source, uniforms);
|
|
4093
4759
|
}
|
|
4094
4760
|
/**
|
|
4095
4761
|
* Gets the current width value from the solver.
|
|
@@ -4106,11 +4772,11 @@ class UIElement extends UIAnchor {
|
|
|
4106
4772
|
return this.solverWrapper.readVariableValue(this.hVariable);
|
|
4107
4773
|
}
|
|
4108
4774
|
/**
|
|
4109
|
-
* Gets the current z-index (depth) value
|
|
4110
|
-
* @returns The current z-index
|
|
4775
|
+
* Gets the current z-index (depth) value.
|
|
4776
|
+
* @returns The current z-index value
|
|
4111
4777
|
*/
|
|
4112
4778
|
get zIndex() {
|
|
4113
|
-
return this.
|
|
4779
|
+
return this.zIndexInternal;
|
|
4114
4780
|
}
|
|
4115
4781
|
/**
|
|
4116
4782
|
* Gets the current visibility and interaction mode.
|
|
@@ -4120,6 +4786,14 @@ class UIElement extends UIAnchor {
|
|
|
4120
4786
|
get mode() {
|
|
4121
4787
|
return this.modeInternal;
|
|
4122
4788
|
}
|
|
4789
|
+
/**
|
|
4790
|
+
* Gets the current transparency rendering mode.
|
|
4791
|
+
* @returns The current transparency mode
|
|
4792
|
+
* @see {@link UITransparencyMode}
|
|
4793
|
+
*/
|
|
4794
|
+
get transparency() {
|
|
4795
|
+
return this.transparencyInternal;
|
|
4796
|
+
}
|
|
4123
4797
|
/**
|
|
4124
4798
|
* Sets the width value through the solver system.
|
|
4125
4799
|
* @param value - The new width dimension (must be positive)
|
|
@@ -4141,139 +4815,115 @@ class UIElement extends UIAnchor {
|
|
|
4141
4815
|
this.solverWrapper.suggestVariableValue(this.hVariable, value);
|
|
4142
4816
|
}
|
|
4143
4817
|
/**
|
|
4144
|
-
* Sets the z-index (depth) value for rendering order.
|
|
4818
|
+
* Sets the z-index (depth) value for rendering order and input handling.
|
|
4145
4819
|
* @param value - The new z-index value
|
|
4146
4820
|
* @throws Will throw an error if value is not a valid number
|
|
4147
4821
|
* @see {@link assertValidNumber}
|
|
4148
4822
|
*/
|
|
4149
4823
|
set zIndex(value) {
|
|
4150
4824
|
assertValidNumber(value, "UIElement zIndex");
|
|
4151
|
-
this.
|
|
4825
|
+
this.zIndexInternal = value;
|
|
4826
|
+
if (this.listener) {
|
|
4827
|
+
this.layer["setListenerZIndex"](this.listener, value);
|
|
4828
|
+
}
|
|
4152
4829
|
}
|
|
4153
4830
|
/**
|
|
4154
|
-
* Sets the visibility and interaction mode.
|
|
4831
|
+
* Sets the current visibility and interaction mode.
|
|
4155
4832
|
* @param value - The new UIMode setting
|
|
4156
4833
|
* @see {@link UIMode}
|
|
4157
4834
|
*/
|
|
4158
4835
|
set mode(value) {
|
|
4159
|
-
if (
|
|
4836
|
+
if (this.modeInternal !== value) {
|
|
4837
|
+
if (value === UIMode.INTERACTIVE) {
|
|
4838
|
+
this.listener = { catchClick: this.onClick };
|
|
4839
|
+
this.layer["listenPointerInput"](this.listener, this.zIndexInternal);
|
|
4840
|
+
}
|
|
4841
|
+
else if (this.modeInternal === UIMode.INTERACTIVE && this.listener) {
|
|
4842
|
+
this.layer["unlistenPointerInput"](this.listener);
|
|
4843
|
+
this.listener = undefined;
|
|
4844
|
+
}
|
|
4160
4845
|
this.modeInternal = value;
|
|
4161
|
-
this.sceneWrapper.setVisibility(this, value !== UIMode.HIDDEN);
|
|
4846
|
+
this.sceneWrapper.setVisibility(this.planeHandler, value !== UIMode.HIDDEN);
|
|
4162
4847
|
}
|
|
4163
4848
|
}
|
|
4849
|
+
/**
|
|
4850
|
+
* Sets the transparency rendering mode.
|
|
4851
|
+
* @param value - The new transparency mode
|
|
4852
|
+
* @see {@link UITransparencyMode}
|
|
4853
|
+
*/
|
|
4854
|
+
set transparency(value) {
|
|
4855
|
+
this.transparencyInternal = value;
|
|
4856
|
+
this.sceneWrapper.setTransparency(this.planeHandler, value);
|
|
4857
|
+
}
|
|
4164
4858
|
/**
|
|
4165
4859
|
* Destroys the UI element by cleaning up all associated resources.
|
|
4166
4860
|
*
|
|
4167
4861
|
* This method removes the element from the rendering scene, cleans up
|
|
4168
|
-
* dimension solver variables, and calls the parent
|
|
4169
|
-
* clean up position variables. After calling this method,
|
|
4170
|
-
* should not be used anymore.
|
|
4862
|
+
* dimension solver variables, removes input listeners, and calls the parent
|
|
4863
|
+
* destroy method to clean up position variables. After calling this method,
|
|
4864
|
+
* the element should not be used anymore.
|
|
4171
4865
|
*/
|
|
4172
4866
|
destroy() {
|
|
4867
|
+
this.layer.off(UILayerEvent.WILL_RENDER, this.onWillRender, this);
|
|
4868
|
+
if (this.listener) {
|
|
4869
|
+
this.layer["unlistenPointerInput"](this.listener);
|
|
4870
|
+
}
|
|
4173
4871
|
this.solverWrapper.removeVariable(this.hVariable);
|
|
4174
4872
|
this.solverWrapper.removeVariable(this.wVariable);
|
|
4175
|
-
this.sceneWrapper.
|
|
4873
|
+
this.sceneWrapper.destroyPlane(this.planeHandler);
|
|
4176
4874
|
super.destroy();
|
|
4177
4875
|
}
|
|
4178
4876
|
/**
|
|
4179
|
-
*
|
|
4180
|
-
*
|
|
4181
|
-
*
|
|
4182
|
-
*
|
|
4183
|
-
*
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4877
|
+
* Called before each render frame to update the element's transform matrix.
|
|
4878
|
+
* Applies micro-transformations (position, rotation, scale, anchor) and updates
|
|
4879
|
+
* the rendering system with the final transformation matrix.
|
|
4880
|
+
* @param renderer - The WebGL renderer (unused in base implementation)
|
|
4881
|
+
* @param deltaTime - Time since last frame in seconds (unused in base implementation)
|
|
4882
|
+
*/
|
|
4883
|
+
onWillRender(
|
|
4884
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Required by UILayer event interface but not used in base implementation
|
|
4885
|
+
renderer,
|
|
4886
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Required by UILayer event interface but not used in base implementation
|
|
4887
|
+
deltaTime) {
|
|
4888
|
+
const micro = this.micro;
|
|
4889
|
+
const width = this.width * micro.scaleX;
|
|
4890
|
+
const height = this.height * micro.scaleY;
|
|
4891
|
+
const anchorOffsetX = micro.anchorX * width;
|
|
4892
|
+
const anchorOffsetY = micro.anchorY * height;
|
|
4893
|
+
const cos = Math.cos(micro.rotation);
|
|
4894
|
+
const sin = Math.sin(micro.rotation);
|
|
4895
|
+
const rotatedAnchorX = anchorOffsetX * cos - anchorOffsetY * sin;
|
|
4896
|
+
const rotatedAnchorY = anchorOffsetX * sin + anchorOffsetY * cos;
|
|
4897
|
+
if (micro.anchorMode === UIMicroAnchorMode.POSITION_ROTATION_SCALE) {
|
|
4898
|
+
position.x = this.x + micro.x - rotatedAnchorX;
|
|
4899
|
+
position.y = this.y + micro.y - rotatedAnchorY;
|
|
4196
4900
|
}
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
uniforms: {
|
|
4210
|
-
map: { value: map },
|
|
4211
|
-
opacity: { value: 1.0 },
|
|
4212
|
-
color: { value: new Color(1.0, 1.0, 1.0) },
|
|
4213
|
-
alphaTest: { value: DEFAULT_ALPHA_TEST$2 },
|
|
4214
|
-
},
|
|
4215
|
-
vertexShader: vertexShader$2,
|
|
4216
|
-
fragmentShader: fragmentShader$2,
|
|
4217
|
-
transparent: false,
|
|
4218
|
-
alphaTest: DEFAULT_ALPHA_TEST$2,
|
|
4219
|
-
lights: false,
|
|
4220
|
-
fog: false,
|
|
4221
|
-
depthWrite: false,
|
|
4222
|
-
depthTest: false,
|
|
4223
|
-
});
|
|
4224
|
-
}
|
|
4225
|
-
getTexture() {
|
|
4226
|
-
return this.uniforms.map.value;
|
|
4227
|
-
}
|
|
4228
|
-
getColor() {
|
|
4229
|
-
return this.uniforms.color.value.getHex();
|
|
4230
|
-
}
|
|
4231
|
-
getOpacity() {
|
|
4232
|
-
return this.uniforms.opacity.value;
|
|
4233
|
-
}
|
|
4234
|
-
getTransparency() {
|
|
4235
|
-
return this.transparent;
|
|
4236
|
-
}
|
|
4237
|
-
setTexture(value) {
|
|
4238
|
-
this.uniforms.map.value = value;
|
|
4239
|
-
this.uniformsNeedUpdate = true;
|
|
4240
|
-
return this;
|
|
4241
|
-
}
|
|
4242
|
-
setColor(value) {
|
|
4243
|
-
this.uniforms.color.value.setHex(value);
|
|
4244
|
-
this.uniformsNeedUpdate = true;
|
|
4245
|
-
return this;
|
|
4246
|
-
}
|
|
4247
|
-
setOpacity(value) {
|
|
4248
|
-
this.uniforms.opacity.value = value;
|
|
4249
|
-
this.uniformsNeedUpdate = true;
|
|
4250
|
-
return this;
|
|
4251
|
-
}
|
|
4252
|
-
setTransparency(value) {
|
|
4253
|
-
if (this.transparent !== value) {
|
|
4254
|
-
this.transparent = value;
|
|
4255
|
-
this.uniforms.alphaTest.value = !value ? DEFAULT_ALPHA_TEST$2 : 0;
|
|
4256
|
-
this.needsUpdate = true;
|
|
4257
|
-
this.uniformsNeedUpdate = true;
|
|
4258
|
-
}
|
|
4259
|
-
return this;
|
|
4901
|
+
else {
|
|
4902
|
+
const rawAnchorOffsetX = micro.anchorX * this.width;
|
|
4903
|
+
const rawAnchorOffsetY = micro.anchorY * this.height;
|
|
4904
|
+
position.x = this.x + rawAnchorOffsetX - rotatedAnchorX + micro.x;
|
|
4905
|
+
position.y = this.y + rawAnchorOffsetY - rotatedAnchorY + micro.y;
|
|
4906
|
+
}
|
|
4907
|
+
position.z = this.zIndexInternal;
|
|
4908
|
+
scale.x = width;
|
|
4909
|
+
scale.y = height;
|
|
4910
|
+
quaternion.setFromAxisAngle(axis, micro.rotation);
|
|
4911
|
+
matrix.compose(position, quaternion, scale);
|
|
4912
|
+
this.sceneWrapper.setTransform(this.planeHandler, matrix);
|
|
4260
4913
|
}
|
|
4261
4914
|
}
|
|
4262
4915
|
|
|
4263
|
-
|
|
4264
|
-
const GEOMETRY_OFFSET = GEOMETRY_SIZE / 2;
|
|
4265
|
-
const geometry = new PlaneGeometry(GEOMETRY_SIZE, GEOMETRY_SIZE).translate(GEOMETRY_OFFSET, GEOMETRY_OFFSET, 0);
|
|
4916
|
+
var source$2 = "void main() {\n vec4 diffuseColor = texture(map, io_UV) * color;\n #include <alphatest_fragment>\n #include <alphahash_fragment>\n gl_FragColor = diffuseColor;\n #include <colorspace_fragment>\n}\n";
|
|
4266
4917
|
|
|
4267
4918
|
/**
|
|
4268
4919
|
* UI element for displaying textured images.
|
|
4269
4920
|
*
|
|
4270
4921
|
* UIImage is a concrete implementation of UIElement that renders a textured
|
|
4271
|
-
* image using
|
|
4922
|
+
* image using shader-based planes. It automatically sizes itself
|
|
4272
4923
|
* to match the texture dimensions and provides control over visual properties
|
|
4273
|
-
* such as color tinting
|
|
4924
|
+
* such as color tinting.
|
|
4274
4925
|
*
|
|
4275
4926
|
* @see {@link UIElement} - Base class providing UI element functionality
|
|
4276
|
-
* @see {@link UIMaterial} - Material system for rendering
|
|
4277
4927
|
* @see {@link Texture} - Three.js texture for image data
|
|
4278
4928
|
*/
|
|
4279
4929
|
class UIImage extends UIElement {
|
|
@@ -4281,21 +4931,28 @@ class UIImage extends UIElement {
|
|
|
4281
4931
|
* Creates a new UIImage instance.
|
|
4282
4932
|
*
|
|
4283
4933
|
* The image will automatically size itself to match the texture's dimensions.
|
|
4284
|
-
*
|
|
4934
|
+
* All options have default values if not specified.
|
|
4285
4935
|
*
|
|
4286
4936
|
* @param layer - The UI layer that contains this image
|
|
4287
4937
|
* @param texture - The Three.js texture to display
|
|
4288
|
-
* @param
|
|
4289
|
-
* @
|
|
4938
|
+
* @param options - Configuration options for the image
|
|
4939
|
+
* @throws Will throw an error if the texture dimensions are not valid positive numbers
|
|
4290
4940
|
*/
|
|
4291
|
-
constructor(layer, texture,
|
|
4292
|
-
const
|
|
4293
|
-
const
|
|
4294
|
-
const
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4941
|
+
constructor(layer, texture, options = {}) {
|
|
4942
|
+
const w = texture.image.width;
|
|
4943
|
+
const h = texture.image.height;
|
|
4944
|
+
const color = options.color ?? new UIColor();
|
|
4945
|
+
super(layer, options.x ?? 0, options.y ?? 0, w, h, source$2, {
|
|
4946
|
+
map: texture,
|
|
4947
|
+
color,
|
|
4948
|
+
});
|
|
4949
|
+
/** Event handler for when the color changes */
|
|
4950
|
+
this._private_onColorChange = (color) => {
|
|
4951
|
+
this.sceneWrapper.setUniform(this.planeHandler, "color", color);
|
|
4952
|
+
};
|
|
4298
4953
|
this._private_textureInternal = texture;
|
|
4954
|
+
this._private_colorInternal = color;
|
|
4955
|
+
this._private_colorInternal.on(UIColorEvent.CHANGE, this._private_onColorChange);
|
|
4299
4956
|
}
|
|
4300
4957
|
/**
|
|
4301
4958
|
* Gets the current texture being displayed.
|
|
@@ -4306,24 +4963,10 @@ class UIImage extends UIElement {
|
|
|
4306
4963
|
}
|
|
4307
4964
|
/**
|
|
4308
4965
|
* Gets the current color tint applied to the image.
|
|
4309
|
-
* @returns The
|
|
4966
|
+
* @returns The UIColor instance
|
|
4310
4967
|
*/
|
|
4311
4968
|
get color() {
|
|
4312
|
-
return this.
|
|
4313
|
-
}
|
|
4314
|
-
/**
|
|
4315
|
-
* Gets the current opacity level of the image.
|
|
4316
|
-
* @returns The opacity value between 0.0 (transparent) and 1.0 (opaque)
|
|
4317
|
-
*/
|
|
4318
|
-
get opacity() {
|
|
4319
|
-
return this._private_material.getOpacity();
|
|
4320
|
-
}
|
|
4321
|
-
/**
|
|
4322
|
-
* Gets whether transparency is enabled for the image.
|
|
4323
|
-
* @returns True if transparency is enabled, false otherwise
|
|
4324
|
-
*/
|
|
4325
|
-
get transparency() {
|
|
4326
|
-
return this._private_material.getTransparency();
|
|
4969
|
+
return this._private_colorInternal;
|
|
4327
4970
|
}
|
|
4328
4971
|
/**
|
|
4329
4972
|
* Sets a new texture for the image.
|
|
@@ -4336,163 +4979,31 @@ class UIImage extends UIElement {
|
|
|
4336
4979
|
* @see {@link assertValidPositiveNumber}
|
|
4337
4980
|
*/
|
|
4338
4981
|
set texture(value) {
|
|
4339
|
-
const
|
|
4340
|
-
const
|
|
4341
|
-
assertValidPositiveNumber(
|
|
4342
|
-
assertValidPositiveNumber(
|
|
4343
|
-
this.
|
|
4344
|
-
this.solverWrapper.suggestVariableValue(this.
|
|
4345
|
-
this.
|
|
4982
|
+
const w = value.image.width;
|
|
4983
|
+
const h = value.image.height;
|
|
4984
|
+
assertValidPositiveNumber(w, "UIImage texture width");
|
|
4985
|
+
assertValidPositiveNumber(h, "UIImage texture height");
|
|
4986
|
+
this.solverWrapper.suggestVariableValue(this.wVariable, w);
|
|
4987
|
+
this.solverWrapper.suggestVariableValue(this.hVariable, h);
|
|
4988
|
+
this._private_textureInternal = value;
|
|
4989
|
+
this.sceneWrapper.setUniform(this.planeHandler, "map", value);
|
|
4346
4990
|
}
|
|
4347
4991
|
/**
|
|
4348
4992
|
* Sets the color tint applied to the image.
|
|
4349
|
-
* @param value - The
|
|
4993
|
+
* @param value - The UIColor instance
|
|
4350
4994
|
*/
|
|
4351
4995
|
set color(value) {
|
|
4352
|
-
this.
|
|
4353
|
-
}
|
|
4354
|
-
/**
|
|
4355
|
-
* Sets the opacity level of the image.
|
|
4356
|
-
* @param value - The opacity value between 0.0 (transparent) and 1.0 (opaque)
|
|
4357
|
-
*/
|
|
4358
|
-
set opacity(value) {
|
|
4359
|
-
this._private_material.setOpacity(value);
|
|
4996
|
+
this._private_colorInternal.copy(value);
|
|
4360
4997
|
}
|
|
4361
4998
|
/**
|
|
4362
|
-
*
|
|
4363
|
-
* @param value - True to enable transparency, false to disable
|
|
4364
|
-
*/
|
|
4365
|
-
set transparency(value) {
|
|
4366
|
-
this._private_material.setTransparency(value);
|
|
4367
|
-
}
|
|
4368
|
-
/**
|
|
4369
|
-
* Destroys the image by cleaning up all associated resources.
|
|
4370
|
-
*
|
|
4371
|
-
* This method disposes of the material resources and calls the parent
|
|
4372
|
-
* destroy method to clean up the underlying UI element. After calling
|
|
4373
|
-
* this method, the image should not be used anymore.
|
|
4999
|
+
* Destroys the UI image by cleaning up color event listeners and all associated resources.
|
|
4374
5000
|
*/
|
|
4375
5001
|
destroy() {
|
|
4376
|
-
this.
|
|
5002
|
+
this._private_colorInternal.off(UIColorEvent.CHANGE, this._private_onColorChange);
|
|
4377
5003
|
super.destroy();
|
|
4378
5004
|
}
|
|
4379
5005
|
}
|
|
4380
5006
|
|
|
4381
|
-
var fragmentShader$1 = "uniform sampler2D map;\nuniform vec3 color;\nuniform float opacity;\nuniform float alphaTest;\nuniform vec4 sliceBorders;\nuniform vec2 quadSize;\nuniform vec2 textureSize;\nvarying vec2 vUv;\n\nvec2 calculateNineSliceUV(vec2 uv) {\n vec2 localUV = uv;\n\n float left = sliceBorders.x;\n float right = sliceBorders.y;\n float top = sliceBorders.z;\n float bottom = sliceBorders.w;\n\n float leftPx = left * textureSize.x;\n float rightPx = right * textureSize.x;\n float topPx = top * textureSize.y;\n float bottomPx = bottom * textureSize.y;\n\n float lB = leftPx / quadSize.x;\n float rB = 1.0 - (rightPx / quadSize.x);\n float tB = topPx / quadSize.y;\n float bB = 1.0 - (bottomPx / quadSize.y);\n\n {\n float regionL = step(uv.x, lB);\n float regionR = step(rB, uv.x);\n float regionM = 1.0 - regionL - regionR;\n\n float xL = uv.x * (left / lB);\n float xR = 1.0 - right + ((uv.x - rB) / (1.0 - rB)) * right;\n float xM = left + ((uv.x - lB) / (rB - lB)) * (1.0 - left - right);\n\n localUV.x = regionL * xL + regionM * xM + regionR * xR;\n }\n\n {\n float regionT = step(uv.y, tB);\n float regionB = step(bB, uv.y);\n float regionC = 1.0 - regionT - regionB;\n\n float yT = uv.y * (top / tB);\n float yB = 1.0 - bottom + ((uv.y - bB) / (1.0 - bB)) * bottom;\n float yC = top + ((uv.y - tB) / (bB - tB)) * (1.0 - top - bottom);\n\n localUV.y = regionT * yT + regionC * yC + regionB * yB;\n }\n\n return localUV;\n}\n\nvoid main() {\n vec4 textureColor = texture2D(map, calculateNineSliceUV(vUv));\n if (textureColor.a < alphaTest) {\n discard;\n }\n gl_FragColor = vec4(textureColor.rgb * color, textureColor.a * opacity);\n #include <colorspace_fragment>\n}\n";
|
|
4382
|
-
|
|
4383
|
-
var vertexShader$1 = "varying vec2 vUv;\nvoid main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n";
|
|
4384
|
-
|
|
4385
|
-
const DEFAULT_ALPHA_TEST$1 = 0.25;
|
|
4386
|
-
class UINineSliceMaterial extends ShaderMaterial {
|
|
4387
|
-
constructor(texture) {
|
|
4388
|
-
super({
|
|
4389
|
-
uniforms: {
|
|
4390
|
-
map: { value: texture },
|
|
4391
|
-
color: { value: new Color(0xffffff) },
|
|
4392
|
-
opacity: { value: 1.0 },
|
|
4393
|
-
alphaTest: { value: DEFAULT_ALPHA_TEST$1 },
|
|
4394
|
-
sliceBorders: {
|
|
4395
|
-
value: new Vector4(0, 0, 0, 0),
|
|
4396
|
-
}, // left, right, top, bottom (in UV)
|
|
4397
|
-
quadSize: { value: new Vector2(1, 1) }, // width, height (in World)
|
|
4398
|
-
textureSize: {
|
|
4399
|
-
value: new Vector2(texture.image.width, texture.image.height),
|
|
4400
|
-
},
|
|
4401
|
-
},
|
|
4402
|
-
vertexShader: vertexShader$1,
|
|
4403
|
-
fragmentShader: fragmentShader$1,
|
|
4404
|
-
transparent: false,
|
|
4405
|
-
alphaTest: DEFAULT_ALPHA_TEST$1,
|
|
4406
|
-
lights: false,
|
|
4407
|
-
fog: false,
|
|
4408
|
-
depthWrite: false,
|
|
4409
|
-
depthTest: false,
|
|
4410
|
-
});
|
|
4411
|
-
}
|
|
4412
|
-
getSliceBorderLeft() {
|
|
4413
|
-
return this.uniforms.sliceBorders.value.x;
|
|
4414
|
-
}
|
|
4415
|
-
getSliceBorderRight() {
|
|
4416
|
-
return this.uniforms.sliceBorders.value.y;
|
|
4417
|
-
}
|
|
4418
|
-
getSliceBorderTop() {
|
|
4419
|
-
return this.uniforms.sliceBorders.value.z;
|
|
4420
|
-
}
|
|
4421
|
-
getSliceBorderBottom() {
|
|
4422
|
-
return this.uniforms.sliceBorders.value.w;
|
|
4423
|
-
}
|
|
4424
|
-
getQuadSize() {
|
|
4425
|
-
const quadSize = this.uniforms.quadSize.value;
|
|
4426
|
-
return { w: quadSize.x, h: quadSize.y };
|
|
4427
|
-
}
|
|
4428
|
-
getTexture() {
|
|
4429
|
-
return this.uniforms.map.value;
|
|
4430
|
-
}
|
|
4431
|
-
getColor() {
|
|
4432
|
-
return this.uniforms.color.value.getHex();
|
|
4433
|
-
}
|
|
4434
|
-
getOpacity() {
|
|
4435
|
-
return this.uniforms.opacity.value;
|
|
4436
|
-
}
|
|
4437
|
-
getTransparency() {
|
|
4438
|
-
return this.transparent;
|
|
4439
|
-
}
|
|
4440
|
-
setSliceBorderLeft(l) {
|
|
4441
|
-
this.uniforms.sliceBorders.value.x = l;
|
|
4442
|
-
this.uniformsNeedUpdate = true;
|
|
4443
|
-
return this;
|
|
4444
|
-
}
|
|
4445
|
-
setSliceBorderRight(r) {
|
|
4446
|
-
this.uniforms.sliceBorders.value.y = r;
|
|
4447
|
-
this.uniformsNeedUpdate = true;
|
|
4448
|
-
return this;
|
|
4449
|
-
}
|
|
4450
|
-
setSliceBorderTop(t) {
|
|
4451
|
-
this.uniforms.sliceBorders.value.z = t;
|
|
4452
|
-
this.uniformsNeedUpdate = true;
|
|
4453
|
-
return this;
|
|
4454
|
-
}
|
|
4455
|
-
setSliceBorderBottom(b) {
|
|
4456
|
-
this.uniforms.sliceBorders.value.w = b;
|
|
4457
|
-
this.uniformsNeedUpdate = true;
|
|
4458
|
-
return this;
|
|
4459
|
-
}
|
|
4460
|
-
setSliceBorder(l, r, t, b) {
|
|
4461
|
-
this.uniforms.sliceBorders.value.set(l, r, t, b);
|
|
4462
|
-
this.uniformsNeedUpdate = true;
|
|
4463
|
-
return this;
|
|
4464
|
-
}
|
|
4465
|
-
setQuadSize(w, h) {
|
|
4466
|
-
this.uniforms.quadSize.value.set(w, h);
|
|
4467
|
-
this.uniformsNeedUpdate = true;
|
|
4468
|
-
return this;
|
|
4469
|
-
}
|
|
4470
|
-
setTexture(value) {
|
|
4471
|
-
this.uniforms.map.value = value;
|
|
4472
|
-
this.uniformsNeedUpdate = true;
|
|
4473
|
-
return this;
|
|
4474
|
-
}
|
|
4475
|
-
setColor(color) {
|
|
4476
|
-
this.uniforms.color.value.setHex(color);
|
|
4477
|
-
this.uniformsNeedUpdate = true;
|
|
4478
|
-
return this;
|
|
4479
|
-
}
|
|
4480
|
-
setOpacity(opacity) {
|
|
4481
|
-
this.uniforms.opacity.value = opacity;
|
|
4482
|
-
this.uniformsNeedUpdate = true;
|
|
4483
|
-
return this;
|
|
4484
|
-
}
|
|
4485
|
-
setTransparency(value) {
|
|
4486
|
-
if (this.transparent !== value) {
|
|
4487
|
-
this.transparent = value;
|
|
4488
|
-
this.uniforms.alphaTest.value = !value ? DEFAULT_ALPHA_TEST$1 : 0;
|
|
4489
|
-
this.needsUpdate = true;
|
|
4490
|
-
this.uniformsNeedUpdate = true;
|
|
4491
|
-
}
|
|
4492
|
-
return this;
|
|
4493
|
-
}
|
|
4494
|
-
}
|
|
4495
|
-
|
|
4496
5007
|
const DEFAULT_SLICE_BORDER = 0.25;
|
|
4497
5008
|
/**
|
|
4498
5009
|
* Resolves various nine-slice border inputs into a normalized border object.
|
|
@@ -4500,23 +5011,23 @@ const DEFAULT_SLICE_BORDER = 0.25;
|
|
|
4500
5011
|
* @param value - The border value to resolve (can be number, partial object, or full object)
|
|
4501
5012
|
* @returns Normalized border object with left, right, top, bottom properties
|
|
4502
5013
|
*/
|
|
4503
|
-
function
|
|
5014
|
+
function resolveNineSliceBorders(value) {
|
|
4504
5015
|
// Handle null/undefined
|
|
4505
5016
|
if (value === null || value === undefined) {
|
|
4506
5017
|
return {
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
5018
|
+
l: DEFAULT_SLICE_BORDER,
|
|
5019
|
+
r: DEFAULT_SLICE_BORDER,
|
|
5020
|
+
t: DEFAULT_SLICE_BORDER,
|
|
5021
|
+
b: DEFAULT_SLICE_BORDER,
|
|
4511
5022
|
};
|
|
4512
5023
|
}
|
|
4513
5024
|
// Handle number
|
|
4514
5025
|
if (typeof value === "number") {
|
|
4515
5026
|
return {
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
5027
|
+
l: value,
|
|
5028
|
+
r: value,
|
|
5029
|
+
t: value,
|
|
5030
|
+
b: value,
|
|
4520
5031
|
};
|
|
4521
5032
|
}
|
|
4522
5033
|
// Handle object
|
|
@@ -4529,10 +5040,10 @@ function resolveNineSliceBorder(value) {
|
|
|
4529
5040
|
: DEFAULT_SLICE_BORDER;
|
|
4530
5041
|
const vertical = typeof obj.vertical === "number" ? obj.vertical : DEFAULT_SLICE_BORDER;
|
|
4531
5042
|
return {
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
5043
|
+
l: horizontal,
|
|
5044
|
+
r: horizontal,
|
|
5045
|
+
t: vertical,
|
|
5046
|
+
b: vertical,
|
|
4536
5047
|
};
|
|
4537
5048
|
}
|
|
4538
5049
|
// Handle { left, right, top, bottom } format
|
|
@@ -4540,17 +5051,19 @@ function resolveNineSliceBorder(value) {
|
|
|
4540
5051
|
const right = typeof obj.right === "number" ? obj.right : DEFAULT_SLICE_BORDER;
|
|
4541
5052
|
const top = typeof obj.top === "number" ? obj.top : DEFAULT_SLICE_BORDER;
|
|
4542
5053
|
const bottom = typeof obj.bottom === "number" ? obj.bottom : DEFAULT_SLICE_BORDER;
|
|
4543
|
-
return { left, right, top, bottom };
|
|
5054
|
+
return { l: left, r: right, t: top, b: bottom };
|
|
4544
5055
|
}
|
|
4545
5056
|
// Fallback to default
|
|
4546
5057
|
return {
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
|
|
5058
|
+
l: DEFAULT_SLICE_BORDER,
|
|
5059
|
+
r: DEFAULT_SLICE_BORDER,
|
|
5060
|
+
t: DEFAULT_SLICE_BORDER,
|
|
5061
|
+
b: DEFAULT_SLICE_BORDER,
|
|
4551
5062
|
};
|
|
4552
5063
|
}
|
|
4553
5064
|
|
|
5065
|
+
var source$1 = "vec2 calculateNineSliceUV() {\n vec2 localUV = io_UV;\n\n float left = sliceBorders.x;\n float right = sliceBorders.y;\n float top = sliceBorders.z;\n float bottom = sliceBorders.w;\n\n float leftPx = left * dimensions.x;\n float rightPx = right * dimensions.x;\n float topPx = top * dimensions.y;\n float bottomPx = bottom * dimensions.y;\n\n float lB = leftPx / dimensions.z;\n float rB = 1.0 - (rightPx / dimensions.z);\n float tB = topPx / dimensions.w;\n float bB = 1.0 - (bottomPx / dimensions.w);\n\n {\n float regionL = step(io_UV.x, lB);\n float regionR = step(rB, io_UV.x);\n float regionM = 1.0 - regionL - regionR;\n\n float xL = io_UV.x * (left / lB);\n float xR = 1.0 - right + ((io_UV.x - rB) / (1.0 - rB)) * right;\n float xM = left + ((io_UV.x - lB) / (rB - lB)) * (1.0 - left - right);\n\n localUV.x = regionL * xL + regionM * xM + regionR * xR;\n }\n\n {\n float regionT = step(io_UV.y, tB);\n float regionB = step(bB, io_UV.y);\n float regionC = 1.0 - regionT - regionB;\n\n float yT = io_UV.y * (top / tB);\n float yB = 1.0 - bottom + ((io_UV.y - bB) / (1.0 - bB)) * bottom;\n float yC = top + ((io_UV.y - tB) / (bB - tB)) * (1.0 - top - bottom);\n\n localUV.y = regionT * yT + regionC * yC + regionB * yB;\n }\n\n return localUV;\n}\n\nvoid main() {\n vec4 diffuseColor = texture(map, calculateNineSliceUV()) * color;\n #include <alphatest_fragment>\n #include <alphahash_fragment>\n gl_FragColor = diffuseColor;\n #include <colorspace_fragment>\n}\n";
|
|
5066
|
+
|
|
4554
5067
|
/**
|
|
4555
5068
|
* Nine-slice UI element for scalable images with preserved border regions.
|
|
4556
5069
|
*
|
|
@@ -4563,302 +5076,191 @@ class UINineSlice extends UIElement {
|
|
|
4563
5076
|
/**
|
|
4564
5077
|
* Creates a new nine-slice UI element.
|
|
4565
5078
|
*
|
|
5079
|
+
* The element initially sizes itself to match the texture's dimensions.
|
|
5080
|
+
* Border regions are defined by the slice borders configuration.
|
|
5081
|
+
*
|
|
4566
5082
|
* @param layer - The UI layer to add this element to
|
|
4567
5083
|
* @param texture - The texture to use for nine-slice rendering
|
|
4568
5084
|
* @param options - Configuration options for the nine-slice element
|
|
5085
|
+
* @throws Will throw an error if the texture dimensions are not valid positive numbers
|
|
4569
5086
|
*/
|
|
4570
5087
|
constructor(layer, texture, options = {}) {
|
|
4571
|
-
const
|
|
4572
|
-
const
|
|
4573
|
-
const
|
|
4574
|
-
const
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
5088
|
+
const width = texture.image.width;
|
|
5089
|
+
const height = texture.image.height;
|
|
5090
|
+
const color = options.color ?? new UIColor();
|
|
5091
|
+
const resolvedSliceBorders = resolveNineSliceBorders(options.sliceBorders);
|
|
5092
|
+
const sliceBorders = new Vector4(resolvedSliceBorders.l, resolvedSliceBorders.r, resolvedSliceBorders.t, resolvedSliceBorders.b);
|
|
5093
|
+
const dimensions = new Vector4(width, height, width, height);
|
|
5094
|
+
super(layer, options.x ?? 0, options.y ?? 0, width, height, source$1, {
|
|
5095
|
+
map: texture,
|
|
5096
|
+
color,
|
|
5097
|
+
sliceBorders,
|
|
5098
|
+
dimensions,
|
|
5099
|
+
});
|
|
5100
|
+
/** Event handler for when the color changes */
|
|
5101
|
+
this._private_onColorChange = (color) => {
|
|
5102
|
+
this.sceneWrapper.setUniform(this.planeHandler, "color", color);
|
|
4582
5103
|
};
|
|
4583
|
-
this.layer.on(UILayerEvent.WILL_RENDER, this._private_onWillRenderInternal);
|
|
4584
|
-
this._private_material = material;
|
|
4585
5104
|
this._private_textureInternal = texture;
|
|
4586
|
-
|
|
4587
|
-
this.
|
|
5105
|
+
this._private_colorInternal = color;
|
|
5106
|
+
this._private_sliceBordersInternal = sliceBorders;
|
|
5107
|
+
this._private_dimensions = dimensions;
|
|
5108
|
+
this._private_colorInternal.on(UIColorEvent.CHANGE, this._private_onColorChange);
|
|
5109
|
+
}
|
|
5110
|
+
/**
|
|
5111
|
+
* Gets the current texture being displayed.
|
|
5112
|
+
* @returns The current Three.js texture
|
|
5113
|
+
*/
|
|
5114
|
+
get texture() {
|
|
5115
|
+
return this._private_textureInternal;
|
|
5116
|
+
}
|
|
5117
|
+
/**
|
|
5118
|
+
* Gets the current color tint applied to the nine-slice element.
|
|
5119
|
+
* @returns The UIColor instance
|
|
5120
|
+
*/
|
|
5121
|
+
get color() {
|
|
5122
|
+
return this._private_colorInternal;
|
|
4588
5123
|
}
|
|
4589
5124
|
/**
|
|
4590
5125
|
* Gets the left border size for nine-slice scaling.
|
|
4591
|
-
* @returns The left border size
|
|
5126
|
+
* @returns The left border size as a percentage (0-1) of texture width
|
|
4592
5127
|
*/
|
|
4593
5128
|
get sliceBorderLeft() {
|
|
4594
|
-
return this.
|
|
5129
|
+
return this._private_sliceBordersInternal.x;
|
|
4595
5130
|
}
|
|
4596
5131
|
/**
|
|
4597
5132
|
* Gets the right border size for nine-slice scaling.
|
|
4598
|
-
* @returns The right border size
|
|
5133
|
+
* @returns The right border size as a percentage (0-1) of texture width
|
|
4599
5134
|
*/
|
|
4600
5135
|
get sliceBorderRight() {
|
|
4601
|
-
return this.
|
|
5136
|
+
return this._private_sliceBordersInternal.y;
|
|
4602
5137
|
}
|
|
4603
5138
|
/**
|
|
4604
5139
|
* Gets the top border size for nine-slice scaling.
|
|
4605
|
-
* @returns The top border size
|
|
5140
|
+
* @returns The top border size as a percentage (0-1) of texture height
|
|
4606
5141
|
*/
|
|
4607
5142
|
get sliceBorderTop() {
|
|
4608
|
-
return this.
|
|
5143
|
+
return this._private_sliceBordersInternal.z;
|
|
4609
5144
|
}
|
|
4610
5145
|
/**
|
|
4611
5146
|
* Gets the bottom border size for nine-slice scaling.
|
|
4612
|
-
* @returns The bottom border size
|
|
5147
|
+
* @returns The bottom border size as a percentage (0-1) of texture height
|
|
4613
5148
|
*/
|
|
4614
5149
|
get sliceBorderBottom() {
|
|
4615
|
-
return this.
|
|
4616
|
-
}
|
|
4617
|
-
/**
|
|
4618
|
-
* Gets the current texture being displayed.
|
|
4619
|
-
* @returns The current Three.js texture
|
|
4620
|
-
*/
|
|
4621
|
-
get texture() {
|
|
4622
|
-
return this._private_textureInternal;
|
|
5150
|
+
return this._private_sliceBordersInternal.w;
|
|
4623
5151
|
}
|
|
4624
5152
|
/**
|
|
4625
|
-
*
|
|
4626
|
-
*
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
*
|
|
4633
|
-
* @returns The opacity value between 0.0 (transparent) and 1.0 (opaque)
|
|
5153
|
+
* Sets a new texture for the nine-slice element.
|
|
5154
|
+
*
|
|
5155
|
+
* When setting a new texture, the element will update its internal dimensions
|
|
5156
|
+
* but maintain the current world size. The nine-slice borders remain unchanged.
|
|
5157
|
+
*
|
|
5158
|
+
* @param value - The new Three.js texture to display
|
|
5159
|
+
* @throws Will throw an error if the texture dimensions are not valid positive numbers
|
|
5160
|
+
* @see {@link assertValidPositiveNumber}
|
|
4634
5161
|
*/
|
|
4635
|
-
|
|
4636
|
-
|
|
5162
|
+
set texture(value) {
|
|
5163
|
+
const w = value.image.width;
|
|
5164
|
+
const h = value.image.height;
|
|
5165
|
+
assertValidPositiveNumber(w, "UINineSlice texture width");
|
|
5166
|
+
assertValidPositiveNumber(h, "UINineSlice texture height");
|
|
5167
|
+
this.solverWrapper.suggestVariableValue(this.wVariable, w);
|
|
5168
|
+
this.solverWrapper.suggestVariableValue(this.hVariable, h);
|
|
5169
|
+
this._private_dimensions.x = w;
|
|
5170
|
+
this._private_dimensions.y = h;
|
|
5171
|
+
this.sceneWrapper.setUniform(this.planeHandler, "dimensions", this._private_dimensions);
|
|
5172
|
+
this.sceneWrapper.setUniform(this.planeHandler, "map", value);
|
|
4637
5173
|
}
|
|
4638
5174
|
/**
|
|
4639
|
-
*
|
|
4640
|
-
* @
|
|
5175
|
+
* Sets the color tint applied to the nine-slice element.
|
|
5176
|
+
* @param value - The UIColor instance
|
|
4641
5177
|
*/
|
|
4642
|
-
|
|
4643
|
-
|
|
5178
|
+
set color(value) {
|
|
5179
|
+
this._private_colorInternal.copy(value);
|
|
4644
5180
|
}
|
|
4645
5181
|
/**
|
|
4646
5182
|
* Sets the left border size for nine-slice scaling.
|
|
4647
|
-
* @param value - The left border size
|
|
5183
|
+
* @param value - The left border size as a percentage (0-1) of texture width
|
|
4648
5184
|
*/
|
|
4649
5185
|
set sliceBorderLeft(value) {
|
|
4650
|
-
this.
|
|
5186
|
+
this._private_sliceBordersInternal.x = value;
|
|
5187
|
+
this.sceneWrapper.setUniform(this.planeHandler, "sliceBorders", this._private_sliceBordersInternal);
|
|
4651
5188
|
}
|
|
4652
5189
|
/**
|
|
4653
5190
|
* Sets the right border size for nine-slice scaling.
|
|
4654
|
-
* @param value - The right border size
|
|
5191
|
+
* @param value - The right border size as a percentage (0-1) of texture width
|
|
4655
5192
|
*/
|
|
4656
5193
|
set sliceBorderRight(value) {
|
|
4657
|
-
this.
|
|
5194
|
+
this._private_sliceBordersInternal.y = value;
|
|
5195
|
+
this.sceneWrapper.setUniform(this.planeHandler, "sliceBorders", this._private_sliceBordersInternal);
|
|
4658
5196
|
}
|
|
4659
5197
|
/**
|
|
4660
5198
|
* Sets the top border size for nine-slice scaling.
|
|
4661
|
-
* @param value - The top border size
|
|
5199
|
+
* @param value - The top border size as a percentage (0-1) of texture height
|
|
4662
5200
|
*/
|
|
4663
5201
|
set sliceBorderTop(value) {
|
|
4664
|
-
this.
|
|
5202
|
+
this._private_sliceBordersInternal.z = value;
|
|
5203
|
+
this.sceneWrapper.setUniform(this.planeHandler, "sliceBorders", this._private_sliceBordersInternal);
|
|
4665
5204
|
}
|
|
4666
5205
|
/**
|
|
4667
5206
|
* Sets the bottom border size for nine-slice scaling.
|
|
4668
|
-
* @param value - The bottom border size
|
|
5207
|
+
* @param value - The bottom border size as a percentage (0-1) of texture height
|
|
4669
5208
|
*/
|
|
4670
5209
|
set sliceBorderBottom(value) {
|
|
4671
|
-
this.
|
|
4672
|
-
|
|
4673
|
-
/**
|
|
4674
|
-
* Sets a new texture for the image.
|
|
4675
|
-
*
|
|
4676
|
-
* When setting a new texture, the image will automatically resize to match
|
|
4677
|
-
* the new texture's dimensions.
|
|
4678
|
-
*
|
|
4679
|
-
* @param value - The new Three.js texture to display
|
|
4680
|
-
* @throws Will throw an error if the texture dimensions are not valid positive numbers
|
|
4681
|
-
* @see {@link assertValidPositiveNumber}
|
|
4682
|
-
*/
|
|
4683
|
-
set texture(value) {
|
|
4684
|
-
const width = value.image.width;
|
|
4685
|
-
const height = value.image.height;
|
|
4686
|
-
assertValidPositiveNumber(width, "UINineSlice texture width");
|
|
4687
|
-
assertValidPositiveNumber(height, "UINineSlice texture height");
|
|
4688
|
-
this._private_material.setTexture(value);
|
|
4689
|
-
this.solverWrapper.suggestVariableValue(this.wVariable, width);
|
|
4690
|
-
this.solverWrapper.suggestVariableValue(this.hVariable, height);
|
|
4691
|
-
}
|
|
4692
|
-
/**
|
|
4693
|
-
* Sets the color tint applied to the image.
|
|
4694
|
-
* @param value - The color value as a number (e.g., 0xFFFFFF for white)
|
|
4695
|
-
*/
|
|
4696
|
-
set color(value) {
|
|
4697
|
-
this._private_material.setColor(value);
|
|
4698
|
-
}
|
|
4699
|
-
/**
|
|
4700
|
-
* Sets the opacity level of the image.
|
|
4701
|
-
* @param value - The opacity value between 0.0 (transparent) and 1.0 (opaque)
|
|
4702
|
-
*/
|
|
4703
|
-
set opacity(value) {
|
|
4704
|
-
this._private_material.setOpacity(value);
|
|
4705
|
-
}
|
|
4706
|
-
/**
|
|
4707
|
-
* Sets whether transparency is enabled for the image.
|
|
4708
|
-
* @param value - True to enable transparency, false to disable
|
|
4709
|
-
*/
|
|
4710
|
-
set transparency(value) {
|
|
4711
|
-
this._private_material.setTransparency(value);
|
|
5210
|
+
this._private_sliceBordersInternal.w = value;
|
|
5211
|
+
this.sceneWrapper.setUniform(this.planeHandler, "sliceBorders", this._private_sliceBordersInternal);
|
|
4712
5212
|
}
|
|
4713
5213
|
/**
|
|
4714
5214
|
* Sets all four border sizes for nine-slice scaling at once.
|
|
4715
5215
|
*
|
|
4716
|
-
* @param left - The left border size
|
|
4717
|
-
* @param right - The right border size
|
|
4718
|
-
* @param top - The top border size
|
|
4719
|
-
* @param bottom - The bottom border size
|
|
5216
|
+
* @param left - The left border size as a percentage (0-1) of texture width
|
|
5217
|
+
* @param right - The right border size as a percentage (0-1) of texture width
|
|
5218
|
+
* @param top - The top border size as a percentage (0-1) of texture height
|
|
5219
|
+
* @param bottom - The bottom border size as a percentage (0-1) of texture height
|
|
4720
5220
|
*/
|
|
4721
5221
|
setSliceBorders(left, right, top, bottom) {
|
|
4722
|
-
this.
|
|
5222
|
+
this._private_sliceBordersInternal.set(left, right, top, bottom);
|
|
5223
|
+
this.sceneWrapper.setUniform(this.planeHandler, "sliceBorders", this._private_sliceBordersInternal);
|
|
4723
5224
|
}
|
|
4724
5225
|
/**
|
|
4725
|
-
* Destroys the nine-slice element
|
|
4726
|
-
*
|
|
4727
|
-
* This method removes event listeners, disposes of the material,
|
|
4728
|
-
* and calls the parent destroy method.
|
|
5226
|
+
* Destroys the nine-slice UI element by cleaning up color event listeners and all associated resources.
|
|
4729
5227
|
*/
|
|
4730
5228
|
destroy() {
|
|
4731
|
-
this.
|
|
4732
|
-
this._private_material.dispose();
|
|
5229
|
+
this._private_colorInternal.off(UIColorEvent.CHANGE, this._private_onColorChange);
|
|
4733
5230
|
super.destroy();
|
|
4734
5231
|
}
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
{
|
|
4747
|
-
background: { value: backgroundTexture },
|
|
4748
|
-
foreground: { value: foregroundTexture },
|
|
4749
|
-
progress: { value: 1 },
|
|
4750
|
-
color: { value: new Color(1, 1, 1) },
|
|
4751
|
-
backgroundColor: { value: new Color(1, 1, 1) },
|
|
4752
|
-
foregroundColor: { value: new Color(1, 1, 1) },
|
|
4753
|
-
opacity: { value: 1 },
|
|
4754
|
-
backgroundOpacity: { value: 1 },
|
|
4755
|
-
foregroundOpacity: { value: 1 },
|
|
4756
|
-
alphaTest: { value: DEFAULT_ALPHA_TEST },
|
|
4757
|
-
angle: { value: 0 },
|
|
4758
|
-
direction: { value: 1 },
|
|
4759
|
-
},
|
|
4760
|
-
]),
|
|
4761
|
-
vertexShader,
|
|
4762
|
-
fragmentShader,
|
|
4763
|
-
transparent: false,
|
|
4764
|
-
alphaTest: DEFAULT_ALPHA_TEST,
|
|
4765
|
-
lights: false,
|
|
4766
|
-
fog: false,
|
|
4767
|
-
depthWrite: false,
|
|
4768
|
-
depthTest: false,
|
|
4769
|
-
});
|
|
4770
|
-
}
|
|
4771
|
-
getProgress() {
|
|
4772
|
-
return this.uniforms.progress.value;
|
|
4773
|
-
}
|
|
4774
|
-
getBackgroundTexture() {
|
|
4775
|
-
return this.uniforms.background.value;
|
|
4776
|
-
}
|
|
4777
|
-
getForegroundTexture() {
|
|
4778
|
-
return this.uniforms.foreground.value;
|
|
4779
|
-
}
|
|
4780
|
-
getColor() {
|
|
4781
|
-
return this.uniforms.color.value.getHex();
|
|
4782
|
-
}
|
|
4783
|
-
getBackgroundColor() {
|
|
4784
|
-
return this.uniforms.backgroundColor.value.getHex();
|
|
4785
|
-
}
|
|
4786
|
-
getForegroundColor() {
|
|
4787
|
-
return this.uniforms.foregroundColor.value.getHex();
|
|
4788
|
-
}
|
|
4789
|
-
getOpacity() {
|
|
4790
|
-
return this.uniforms.opacity.value;
|
|
4791
|
-
}
|
|
4792
|
-
getBackgroundOpacity() {
|
|
4793
|
-
return this.uniforms.backgroundOpacity.value;
|
|
4794
|
-
}
|
|
4795
|
-
getForegroundOpacity() {
|
|
4796
|
-
return this.uniforms.foregroundOpacity.value;
|
|
4797
|
-
}
|
|
4798
|
-
getTransparency() {
|
|
4799
|
-
return this.transparent;
|
|
4800
|
-
}
|
|
4801
|
-
getAngle() {
|
|
4802
|
-
return this.uniforms.angle.value;
|
|
4803
|
-
}
|
|
4804
|
-
getIsForwardDirection() {
|
|
4805
|
-
return this.uniforms.direction.value === 1;
|
|
4806
|
-
}
|
|
4807
|
-
setProgress(value) {
|
|
4808
|
-
this.uniforms.progress.value = value;
|
|
4809
|
-
this.uniformsNeedUpdate = true;
|
|
4810
|
-
}
|
|
4811
|
-
setBackgroundTexture(value) {
|
|
4812
|
-
this.uniforms.background.value = value;
|
|
4813
|
-
this.uniformsNeedUpdate = true;
|
|
4814
|
-
}
|
|
4815
|
-
setForegroundTexture(value) {
|
|
4816
|
-
this.uniforms.foreground.value = value;
|
|
4817
|
-
this.uniformsNeedUpdate = true;
|
|
4818
|
-
}
|
|
4819
|
-
setColor(value) {
|
|
4820
|
-
this.uniforms.color.value.setHex(value);
|
|
4821
|
-
this.uniformsNeedUpdate = true;
|
|
4822
|
-
}
|
|
4823
|
-
setBackgroundColor(value) {
|
|
4824
|
-
this.uniforms.backgroundColor.value.setHex(value);
|
|
4825
|
-
this.uniformsNeedUpdate = true;
|
|
4826
|
-
}
|
|
4827
|
-
setForegroundColor(value) {
|
|
4828
|
-
this.uniforms.foregroundColor.value.setHex(value);
|
|
4829
|
-
this.uniformsNeedUpdate = true;
|
|
4830
|
-
}
|
|
4831
|
-
setOpacity(value) {
|
|
4832
|
-
this.uniforms.opacity.value = value;
|
|
4833
|
-
this.uniformsNeedUpdate = true;
|
|
4834
|
-
}
|
|
4835
|
-
setBackgroundOpacity(value) {
|
|
4836
|
-
this.uniforms.backgroundOpacity.value = value;
|
|
4837
|
-
this.uniformsNeedUpdate = true;
|
|
4838
|
-
}
|
|
4839
|
-
setForegroundOpacity(value) {
|
|
4840
|
-
this.uniforms.foregroundOpacity.value = value;
|
|
4841
|
-
this.uniformsNeedUpdate = true;
|
|
4842
|
-
}
|
|
4843
|
-
setTransparency(value) {
|
|
4844
|
-
if (this.transparent !== value) {
|
|
4845
|
-
this.transparent = value;
|
|
4846
|
-
this.uniforms.alphaTest.value = !value ? DEFAULT_ALPHA_TEST : 0;
|
|
4847
|
-
this.needsUpdate = true;
|
|
4848
|
-
this.uniformsNeedUpdate = true;
|
|
4849
|
-
}
|
|
4850
|
-
return this;
|
|
4851
|
-
}
|
|
4852
|
-
setAngle(value) {
|
|
4853
|
-
this.uniforms.angle.value = value;
|
|
4854
|
-
this.uniformsNeedUpdate = true;
|
|
4855
|
-
}
|
|
4856
|
-
setIsForwardDirection(value) {
|
|
4857
|
-
this.uniforms.direction.value = value ? 1 : -1;
|
|
4858
|
-
this.uniformsNeedUpdate = true;
|
|
5232
|
+
/**
|
|
5233
|
+
* Called before each render frame to update the element's dimensions for nine-slice scaling.
|
|
5234
|
+
* Updates the world dimensions (z, w components) based on current width, height, and micro scaling.
|
|
5235
|
+
* @param renderer - The WebGL renderer
|
|
5236
|
+
* @param deltaTime - Time since last frame in seconds
|
|
5237
|
+
*/
|
|
5238
|
+
onWillRender(renderer, deltaTime) {
|
|
5239
|
+
super.onWillRender(renderer, deltaTime);
|
|
5240
|
+
this._private_dimensions.z = this.width * this.micro.scaleX;
|
|
5241
|
+
this._private_dimensions.w = this.height * this.micro.scaleY;
|
|
5242
|
+
this.sceneWrapper.setUniform(this.planeHandler, "dimensions", this._private_dimensions);
|
|
4859
5243
|
}
|
|
4860
5244
|
}
|
|
4861
5245
|
|
|
5246
|
+
var source = "void main() {\n vec4 foregroundDiffuseColor = texture(foregroundTexture, io_UV) * foregroundColor * color;\n vec4 backgroundDiffuseColor = texture(backgroundTexture, io_UV) * backgroundColor * color;\n\n float mask = calculateMask();\n vec4 diffuseColor = foregroundDiffuseColor * mask\n + backgroundDiffuseColor * (1.0 - foregroundDiffuseColor.a * mask);\n\n #include <alphatest_fragment>\n #include <alphahash_fragment>\n gl_FragColor = diffuseColor;\n #include <colorspace_fragment>\n}\n";
|
|
5247
|
+
|
|
5248
|
+
const DEFAULT_TEXTURE = new Texture();
|
|
5249
|
+
/**
|
|
5250
|
+
* Predefined mask functions that control how the progress bar fills.
|
|
5251
|
+
* Each function defines a different fill pattern using GLSL shader code.
|
|
5252
|
+
*/
|
|
5253
|
+
var UIProgressMaskFunction;
|
|
5254
|
+
(function (UIProgressMaskFunction) {
|
|
5255
|
+
/** Fill horizontally from left to right (or right to left if inverse) */
|
|
5256
|
+
UIProgressMaskFunction["HORIZONTAL"] = "float calculateMask() {\n return step((direction * io_UV.x + (1.0 - direction) * 0.5), progress);\n }";
|
|
5257
|
+
/** Fill vertically from bottom to top (or top to bottom if inverse) */
|
|
5258
|
+
UIProgressMaskFunction["VERTICAL"] = "float calculateMask() {\n return step((direction * io_UV.y + (1.0 - direction) * 0.5), progress);\n }";
|
|
5259
|
+
/** Fill diagonally from bottom-left to top-right */
|
|
5260
|
+
UIProgressMaskFunction["DIAGONAL"] = "float calculateMask() {\n float d = (io_UV.x + io_UV.y) * (0.1);\n return step((direction * d + (1.0 - direction) * 0.5), progress);\n }";
|
|
5261
|
+
/** Fill in a circular pattern around the center */
|
|
5262
|
+
UIProgressMaskFunction["CIRCLE"] = "float calculateMask() {\n vec2 p = io_UV - 0.5;\n float angle = atan(p.y, p.x);\n angle = (angle + 3.14159265) / 3.14159265;\n angle *= 0.5;\n return step((direction * angle + (1.0 - direction) * 0.5), progress);\n }";
|
|
5263
|
+
})(UIProgressMaskFunction || (UIProgressMaskFunction = {}));
|
|
4862
5264
|
/**
|
|
4863
5265
|
* Progress bar UI element with customizable fill direction and appearance.
|
|
4864
5266
|
*
|
|
@@ -4874,151 +5276,103 @@ class UIProgress extends UIElement {
|
|
|
4874
5276
|
* Creates a new progress bar UI element.
|
|
4875
5277
|
*
|
|
4876
5278
|
* @param layer - The UI layer to add this element to
|
|
4877
|
-
* @param
|
|
5279
|
+
* @param foregroundTexture - The texture used for the progress fill
|
|
4878
5280
|
* @param options - Configuration options for the progress bar
|
|
4879
5281
|
*/
|
|
4880
|
-
constructor(layer,
|
|
4881
|
-
const
|
|
4882
|
-
const
|
|
4883
|
-
assertValidPositiveNumber(
|
|
4884
|
-
assertValidPositiveNumber(
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
const
|
|
4892
|
-
const
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
}
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
4915
|
-
|
|
4916
|
-
|
|
4917
|
-
this.
|
|
5282
|
+
constructor(layer, foregroundTexture, options = {}) {
|
|
5283
|
+
const w = foregroundTexture.image?.width;
|
|
5284
|
+
const h = foregroundTexture.image?.height;
|
|
5285
|
+
assertValidPositiveNumber(w, "UIProgress foreground texture width");
|
|
5286
|
+
assertValidPositiveNumber(h, "UIProgress foreground texture height");
|
|
5287
|
+
if (options.backgroundTexture) {
|
|
5288
|
+
assertValidPositiveNumber(options.backgroundTexture.image.width, "UIProgress background texture width");
|
|
5289
|
+
assertValidPositiveNumber(options.backgroundTexture.image.height, "UIProgress background texture height");
|
|
5290
|
+
}
|
|
5291
|
+
const color = options.color ?? new UIColor();
|
|
5292
|
+
const foregroundColor = options.foregroundColor ?? new UIColor();
|
|
5293
|
+
const backgroundColor = options.backgroundColor ?? new UIColor();
|
|
5294
|
+
const progress = options.progress ?? 1;
|
|
5295
|
+
const inverseDirection = options.inverseDirection ?? false;
|
|
5296
|
+
super(layer, options.x ?? 0, options.y ?? 0, w, h, (options.maskFunction ?? UIProgressMaskFunction.HORIZONTAL) + source, {
|
|
5297
|
+
foregroundTexture,
|
|
5298
|
+
backgroundTexture: options.backgroundTexture ?? DEFAULT_TEXTURE,
|
|
5299
|
+
color,
|
|
5300
|
+
foregroundColor,
|
|
5301
|
+
backgroundColor,
|
|
5302
|
+
progress,
|
|
5303
|
+
direction: inverseDirection ? -1 : 1,
|
|
5304
|
+
});
|
|
5305
|
+
/** Event handler for when the overall color changes */
|
|
5306
|
+
this._private_onColorChange = (color) => {
|
|
5307
|
+
this.sceneWrapper.setUniform(this.planeHandler, "color", color);
|
|
5308
|
+
};
|
|
5309
|
+
/** Event handler for when the foreground color changes */
|
|
5310
|
+
this._private_onForegroundColorChange = (color) => {
|
|
5311
|
+
this.sceneWrapper.setUniform(this.planeHandler, "foregroundColor", color);
|
|
5312
|
+
};
|
|
5313
|
+
/** Event handler for when the background color changes */
|
|
5314
|
+
this._private_onBackgroundColorChange = (color) => {
|
|
5315
|
+
this.sceneWrapper.setUniform(this.planeHandler, "backgroundColor", color);
|
|
5316
|
+
};
|
|
5317
|
+
this._private_foregroundTextureInternal = foregroundTexture;
|
|
5318
|
+
this._private_backgroundTextureInternal = options.backgroundTexture;
|
|
5319
|
+
this._private_colorInternal = color;
|
|
5320
|
+
this._private_foregroundColorInternal = foregroundColor;
|
|
5321
|
+
this._private_backgroundColorInternal = backgroundColor;
|
|
5322
|
+
this._private_progressInternal = progress;
|
|
5323
|
+
this._private_inverseDirectionInternal = inverseDirection;
|
|
5324
|
+
this._private_colorInternal.on(UIColorEvent.CHANGE, this._private_onColorChange);
|
|
5325
|
+
this._private_foregroundColorInternal.on(UIColorEvent.CHANGE, this._private_onForegroundColorChange);
|
|
5326
|
+
this._private_backgroundColorInternal.on(UIColorEvent.CHANGE, this._private_onBackgroundColorChange);
|
|
4918
5327
|
}
|
|
4919
5328
|
/**
|
|
4920
|
-
* Gets the
|
|
4921
|
-
* @returns
|
|
5329
|
+
* Gets the foreground (fill) texture.
|
|
5330
|
+
* @returns The foreground texture
|
|
4922
5331
|
*/
|
|
4923
|
-
get
|
|
4924
|
-
return this.
|
|
5332
|
+
get foregroundTexture() {
|
|
5333
|
+
return this._private_foregroundTextureInternal;
|
|
4925
5334
|
}
|
|
4926
5335
|
/**
|
|
4927
5336
|
* Gets the background texture.
|
|
4928
5337
|
* @returns The background texture, or undefined if none is set
|
|
4929
5338
|
*/
|
|
4930
5339
|
get backgroundTexture() {
|
|
4931
|
-
return this.
|
|
4932
|
-
}
|
|
4933
|
-
/**
|
|
4934
|
-
* Gets the foreground (fill) texture.
|
|
4935
|
-
* @returns The foreground texture
|
|
4936
|
-
*/
|
|
4937
|
-
get foregroundTexture() {
|
|
4938
|
-
return this._private_material.getForegroundTexture();
|
|
5340
|
+
return this._private_backgroundTextureInternal;
|
|
4939
5341
|
}
|
|
4940
5342
|
/**
|
|
4941
5343
|
* Gets the color tint.
|
|
4942
|
-
* @returns The
|
|
5344
|
+
* @returns The UIColor instance
|
|
4943
5345
|
*/
|
|
4944
5346
|
get color() {
|
|
4945
|
-
return this.
|
|
4946
|
-
}
|
|
4947
|
-
/**
|
|
4948
|
-
* Gets the background color tint.
|
|
4949
|
-
* @returns The background color as a hex number (e.g., 0xFFFFFF)
|
|
4950
|
-
*/
|
|
4951
|
-
get backgroundColor() {
|
|
4952
|
-
return this._private_material.getBackgroundColor();
|
|
5347
|
+
return this._private_colorInternal;
|
|
4953
5348
|
}
|
|
4954
5349
|
/**
|
|
4955
5350
|
* Gets the foreground color tint.
|
|
4956
|
-
* @returns The foreground color
|
|
5351
|
+
* @returns The foreground color UIColor instance
|
|
4957
5352
|
*/
|
|
4958
5353
|
get foregroundColor() {
|
|
4959
|
-
return this.
|
|
4960
|
-
}
|
|
4961
|
-
/**
|
|
4962
|
-
* Gets the opacity.
|
|
4963
|
-
* @returns Opacity value between 0.0 (transparent) and 1.0 (opaque)
|
|
4964
|
-
*/
|
|
4965
|
-
get opacity() {
|
|
4966
|
-
return this._private_material.getOpacity();
|
|
4967
|
-
}
|
|
4968
|
-
/**
|
|
4969
|
-
* Gets the background opacity.
|
|
4970
|
-
* @returns Opacity value between 0.0 (transparent) and 1.0 (opaque)
|
|
4971
|
-
*/
|
|
4972
|
-
get backgroundOpacity() {
|
|
4973
|
-
return this._private_material.getBackgroundOpacity();
|
|
4974
|
-
}
|
|
4975
|
-
/**
|
|
4976
|
-
* Gets the foreground opacity.
|
|
4977
|
-
* @returns Opacity value between 0.0 (transparent) and 1.0 (opaque)
|
|
4978
|
-
*/
|
|
4979
|
-
get foregroundOpacity() {
|
|
4980
|
-
return this._private_material.getForegroundOpacity();
|
|
4981
|
-
}
|
|
4982
|
-
/**
|
|
4983
|
-
* Gets whether transparency is enabled for the image.
|
|
4984
|
-
* @returns True if transparency is enabled, false otherwise
|
|
4985
|
-
*/
|
|
4986
|
-
get transparency() {
|
|
4987
|
-
return this._private_material.getTransparency();
|
|
5354
|
+
return this._private_foregroundColorInternal;
|
|
4988
5355
|
}
|
|
4989
5356
|
/**
|
|
4990
|
-
* Gets the
|
|
4991
|
-
* @returns
|
|
5357
|
+
* Gets the background color tint.
|
|
5358
|
+
* @returns The background color UIColor instance
|
|
4992
5359
|
*/
|
|
4993
|
-
get
|
|
4994
|
-
return
|
|
5360
|
+
get backgroundColor() {
|
|
5361
|
+
return this._private_backgroundColorInternal;
|
|
4995
5362
|
}
|
|
4996
5363
|
/**
|
|
4997
|
-
* Gets
|
|
4998
|
-
* @returns
|
|
5364
|
+
* Gets the current progress value.
|
|
5365
|
+
* @returns Progress value between 0.0 (empty) and 1.0 (full)
|
|
4999
5366
|
*/
|
|
5000
|
-
get
|
|
5001
|
-
return this.
|
|
5367
|
+
get progress() {
|
|
5368
|
+
return this._private_progressInternal;
|
|
5002
5369
|
}
|
|
5003
5370
|
/**
|
|
5004
|
-
*
|
|
5005
|
-
* @
|
|
5371
|
+
* Gets whether the progress fills in reverse direction.
|
|
5372
|
+
* @returns True if filling in reverse, false if filling forward
|
|
5006
5373
|
*/
|
|
5007
|
-
|
|
5008
|
-
this.
|
|
5009
|
-
}
|
|
5010
|
-
/**
|
|
5011
|
-
* Sets the background texture.
|
|
5012
|
-
* @param value - The background texture, or undefined to remove background
|
|
5013
|
-
*/
|
|
5014
|
-
set backgroundTexture(value) {
|
|
5015
|
-
if (value) {
|
|
5016
|
-
const width = value.image.width;
|
|
5017
|
-
const height = value.image.height;
|
|
5018
|
-
assertValidPositiveNumber(width, "UIProgress background texture width");
|
|
5019
|
-
assertValidPositiveNumber(height, "UIProgress background texture height");
|
|
5020
|
-
}
|
|
5021
|
-
this._private_material.setBackgroundTexture(value);
|
|
5374
|
+
get inverseDirection() {
|
|
5375
|
+
return this._private_inverseDirectionInternal;
|
|
5022
5376
|
}
|
|
5023
5377
|
/**
|
|
5024
5378
|
* Sets the foreground (fill) texture.
|
|
@@ -5030,84 +5384,68 @@ class UIProgress extends UIElement {
|
|
|
5030
5384
|
* @throws Will throw an error if the texture dimensions are not valid positive numbers
|
|
5031
5385
|
*/
|
|
5032
5386
|
set foregroundTexture(value) {
|
|
5033
|
-
const
|
|
5034
|
-
const
|
|
5035
|
-
assertValidPositiveNumber(
|
|
5036
|
-
assertValidPositiveNumber(
|
|
5037
|
-
this.
|
|
5038
|
-
this.solverWrapper.suggestVariableValue(this.
|
|
5039
|
-
this.
|
|
5387
|
+
const w = value.image.width;
|
|
5388
|
+
const h = value.image.height;
|
|
5389
|
+
assertValidPositiveNumber(w, "UIProgress foreground texture width");
|
|
5390
|
+
assertValidPositiveNumber(h, "UIProgress foreground texture height");
|
|
5391
|
+
this.solverWrapper.suggestVariableValue(this.wVariable, w);
|
|
5392
|
+
this.solverWrapper.suggestVariableValue(this.hVariable, h);
|
|
5393
|
+
this._private_foregroundTextureInternal = value;
|
|
5394
|
+
this.sceneWrapper.setUniform(this.planeHandler, "foregroundTexture", value);
|
|
5040
5395
|
}
|
|
5041
5396
|
/**
|
|
5042
|
-
* Sets the
|
|
5043
|
-
* @param value - The
|
|
5397
|
+
* Sets the background texture.
|
|
5398
|
+
* @param value - The background texture, or undefined to remove background
|
|
5044
5399
|
*/
|
|
5045
|
-
set
|
|
5046
|
-
|
|
5400
|
+
set backgroundTexture(value) {
|
|
5401
|
+
if (value !== undefined) {
|
|
5402
|
+
assertValidPositiveNumber(value.image.width, "UIProgress background texture width");
|
|
5403
|
+
assertValidPositiveNumber(value.image.height, "UIProgress background texture height");
|
|
5404
|
+
}
|
|
5405
|
+
this._private_backgroundTextureInternal = value;
|
|
5406
|
+
this.sceneWrapper.setUniform(this.planeHandler, "backgroundTexture", value);
|
|
5047
5407
|
}
|
|
5048
5408
|
/**
|
|
5049
|
-
* Sets the
|
|
5050
|
-
* @param value - The
|
|
5409
|
+
* Sets the color tint.
|
|
5410
|
+
* @param value - The UIColor instance
|
|
5051
5411
|
*/
|
|
5052
|
-
set
|
|
5053
|
-
this.
|
|
5412
|
+
set color(value) {
|
|
5413
|
+
this._private_colorInternal.copy(value);
|
|
5054
5414
|
}
|
|
5055
5415
|
/**
|
|
5056
5416
|
* Sets the foreground color tint.
|
|
5057
|
-
* @param value - The foreground color
|
|
5417
|
+
* @param value - The foreground color UIColor instance
|
|
5058
5418
|
*/
|
|
5059
5419
|
set foregroundColor(value) {
|
|
5060
|
-
this.
|
|
5061
|
-
}
|
|
5062
|
-
/**
|
|
5063
|
-
* Sets the opacity.
|
|
5064
|
-
* @param value - Opacity value between 0.0 (transparent) and 1.0 (opaque)
|
|
5065
|
-
*/
|
|
5066
|
-
set opacity(value) {
|
|
5067
|
-
this._private_material.setOpacity(value);
|
|
5068
|
-
}
|
|
5069
|
-
/**
|
|
5070
|
-
* Sets the background opacity.
|
|
5071
|
-
* @param value - Opacity value between 0.0 (transparent) and 1.0 (opaque)
|
|
5072
|
-
*/
|
|
5073
|
-
set backgroundOpacity(value) {
|
|
5074
|
-
this._private_material.setBackgroundOpacity(value);
|
|
5075
|
-
}
|
|
5076
|
-
/**
|
|
5077
|
-
* Sets the foreground opacity.
|
|
5078
|
-
* @param value - Opacity value between 0.0 (transparent) and 1.0 (opaque)
|
|
5079
|
-
*/
|
|
5080
|
-
set foregroundOpacity(value) {
|
|
5081
|
-
this._private_material.setForegroundOpacity(value);
|
|
5082
|
-
}
|
|
5083
|
-
/**
|
|
5084
|
-
* Sets whether transparency is enabled for the image.
|
|
5085
|
-
* @param value - True to enable transparency, false to disable
|
|
5086
|
-
*/
|
|
5087
|
-
set transparency(value) {
|
|
5088
|
-
this._private_material.setTransparency(value);
|
|
5420
|
+
this._private_foregroundColorInternal.copy(value);
|
|
5089
5421
|
}
|
|
5090
5422
|
/**
|
|
5091
|
-
* Sets the
|
|
5092
|
-
* @param value -
|
|
5423
|
+
* Sets the background color tint.
|
|
5424
|
+
* @param value - The background color UIColor instance
|
|
5093
5425
|
*/
|
|
5094
|
-
set
|
|
5095
|
-
this.
|
|
5426
|
+
set backgroundColor(value) {
|
|
5427
|
+
this._private_backgroundColorInternal.copy(value);
|
|
5096
5428
|
}
|
|
5097
5429
|
/**
|
|
5098
5430
|
* Sets the progress fill direction.
|
|
5099
|
-
* @param value - True for
|
|
5431
|
+
* @param value - True for reverse direction, false for forward
|
|
5100
5432
|
*/
|
|
5101
|
-
set
|
|
5102
|
-
this.
|
|
5433
|
+
set inverseDirection(value) {
|
|
5434
|
+
this._private_inverseDirectionInternal = value;
|
|
5435
|
+
this.sceneWrapper.setUniform(this.planeHandler, "direction", value ? -1 : 1);
|
|
5103
5436
|
}
|
|
5104
5437
|
/**
|
|
5105
|
-
*
|
|
5106
|
-
*
|
|
5107
|
-
* This method disposes of the material and calls the parent destroy method.
|
|
5438
|
+
* Sets the progress value.
|
|
5439
|
+
* @param value - Progress value between 0.0 (empty) and 1.0 (full)
|
|
5108
5440
|
*/
|
|
5441
|
+
set progress(value) {
|
|
5442
|
+
this._private_progressInternal = value;
|
|
5443
|
+
this.sceneWrapper.setUniform(this.planeHandler, "progress", value);
|
|
5444
|
+
}
|
|
5109
5445
|
destroy() {
|
|
5110
|
-
this.
|
|
5446
|
+
this._private_colorInternal.off(UIColorEvent.CHANGE, this._private_onColorChange);
|
|
5447
|
+
this._private_foregroundColorInternal.off(UIColorEvent.CHANGE, this._private_onForegroundColorChange);
|
|
5448
|
+
this._private_backgroundColorInternal.off(UIColorEvent.CHANGE, this._private_onBackgroundColorChange);
|
|
5111
5449
|
super.destroy();
|
|
5112
5450
|
}
|
|
5113
5451
|
}
|
|
@@ -5182,9 +5520,9 @@ class UIScene extends UIElement {
|
|
|
5182
5520
|
resolutionFactor > MAX_RESOLUTION_FACTOR) {
|
|
5183
5521
|
throw new Error(`Invalid resolution factor: ${resolutionFactor}. Must be between ${MIN_RESOLUTION_FACTOR} and ${MAX_RESOLUTION_FACTOR}.`);
|
|
5184
5522
|
}
|
|
5185
|
-
const
|
|
5186
|
-
const
|
|
5187
|
-
const renderTarget = new WebGLRenderTarget(
|
|
5523
|
+
const w = options.width ?? DEFAULT_WIDTH;
|
|
5524
|
+
const h = options.height ?? DEFAULT_HEIGHT;
|
|
5525
|
+
const renderTarget = new WebGLRenderTarget(w * resolutionFactor, h * resolutionFactor, {
|
|
5188
5526
|
format: RGBAFormat,
|
|
5189
5527
|
minFilter: LinearFilter,
|
|
5190
5528
|
magFilter: LinearFilter,
|
|
@@ -5192,37 +5530,27 @@ class UIScene extends UIElement {
|
|
|
5192
5530
|
depthBuffer: options.enableDepthBuffer ?? DEFAULT_USE_DEPTH,
|
|
5193
5531
|
stencilBuffer: false,
|
|
5194
5532
|
});
|
|
5195
|
-
const
|
|
5196
|
-
|
|
5197
|
-
|
|
5533
|
+
const color = options.color ?? new UIColor();
|
|
5534
|
+
super(layer, 0, 0, w, h, source$2, {
|
|
5535
|
+
map: renderTarget.texture,
|
|
5536
|
+
color,
|
|
5537
|
+
});
|
|
5198
5538
|
/** Frame alternation boolean for EACH_SECOND_FRAME update mode. */
|
|
5199
5539
|
this._private_frameBoolean = true;
|
|
5200
5540
|
/** Flag indicating if properties have changed requiring a re-render. */
|
|
5201
5541
|
this._private_propertyChanged = false;
|
|
5202
5542
|
/** Flag indicating if a manual render has been requested. */
|
|
5203
5543
|
this._private_renderRequired = false;
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
(this._private_updateModeInternal === UISceneUpdateMode.PROPERTY_CHANGED && this._private_propertyChanged) ||
|
|
5208
|
-
(this._private_updateModeInternal === UISceneUpdateMode.MANUAL && this._private_renderRequired)) {
|
|
5209
|
-
this._private_renderRequired = false;
|
|
5210
|
-
this._private_propertyChanged = false;
|
|
5211
|
-
this._private_frameBoolean = !this._private_frameBoolean;
|
|
5212
|
-
this._private_renderTarget.setSize(this.width * this._private_resolutionFactorInternal, this.height * this._private_resolutionFactorInternal);
|
|
5213
|
-
renderer.setClearColor(this._private_clearColorInternal, this.clearAlpha);
|
|
5214
|
-
renderer.setRenderTarget(this._private_renderTarget);
|
|
5215
|
-
renderer.clear(true, true, false);
|
|
5216
|
-
renderer.render(this._private_sceneInternal, this._private_cameraInternal);
|
|
5217
|
-
}
|
|
5544
|
+
/** Event handler for when the color changes */
|
|
5545
|
+
this._private_onColorChange = (color) => {
|
|
5546
|
+
this.sceneWrapper.setUniform(this.planeHandler, "color", color);
|
|
5218
5547
|
};
|
|
5219
|
-
this.layer.on(UILayerEvent.WILL_RENDER, this._private_onWillRenderInternal);
|
|
5220
|
-
this._private_material = material;
|
|
5221
5548
|
this._private_renderTarget = renderTarget;
|
|
5549
|
+
this._private_colorInternal = color;
|
|
5222
5550
|
this._private_sceneInternal = options.scene ?? new Scene();
|
|
5223
5551
|
this._private_cameraInternal =
|
|
5224
5552
|
options.camera ??
|
|
5225
|
-
new PerspectiveCamera(DEFAULT_CAMERA_FOV,
|
|
5553
|
+
new PerspectiveCamera(DEFAULT_CAMERA_FOV, w / h, DEFAULT_CAMERA_NEAR, DEFAULT_CAMERA_FAR);
|
|
5226
5554
|
this._private_resolutionFactorInternal = resolutionFactor;
|
|
5227
5555
|
this._private_updateModeInternal = options.updateMode ?? DEFAULT_UPDATE_MODE;
|
|
5228
5556
|
this._private_clearColorInternal = options.clearColor ?? DEFAULT_CLEAR_COLOR;
|
|
@@ -5230,27 +5558,14 @@ class UIScene extends UIElement {
|
|
|
5230
5558
|
if (options.updateMode === UISceneUpdateMode.PROPERTY_CHANGED) {
|
|
5231
5559
|
this._private_renderRequired = true;
|
|
5232
5560
|
}
|
|
5561
|
+
this._private_colorInternal.on(UIColorEvent.CHANGE, this._private_onColorChange);
|
|
5233
5562
|
}
|
|
5234
5563
|
/**
|
|
5235
5564
|
* Gets the current color tint applied to the scene texture.
|
|
5236
|
-
* @returns The
|
|
5565
|
+
* @returns The UIColor instance
|
|
5237
5566
|
*/
|
|
5238
5567
|
get color() {
|
|
5239
|
-
return this.
|
|
5240
|
-
}
|
|
5241
|
-
/**
|
|
5242
|
-
* Gets the current opacity level of the scene texture.
|
|
5243
|
-
* @returns The opacity value between 0.0 (transparent) and 1.0 (opaque)
|
|
5244
|
-
*/
|
|
5245
|
-
get opacity() {
|
|
5246
|
-
return this._private_material.getOpacity();
|
|
5247
|
-
}
|
|
5248
|
-
/**
|
|
5249
|
-
* Gets whether transparency is enabled for the scene texture.
|
|
5250
|
-
* @returns True if transparency is enabled, false otherwise
|
|
5251
|
-
*/
|
|
5252
|
-
get transparency() {
|
|
5253
|
-
return this._private_material.getTransparency();
|
|
5568
|
+
return this._private_colorInternal;
|
|
5254
5569
|
}
|
|
5255
5570
|
/**
|
|
5256
5571
|
* Gets the Three.js scene being rendered.
|
|
@@ -5296,24 +5611,10 @@ class UIScene extends UIElement {
|
|
|
5296
5611
|
}
|
|
5297
5612
|
/**
|
|
5298
5613
|
* Sets the color tint applied to the scene texture.
|
|
5299
|
-
* @param value - The
|
|
5614
|
+
* @param value - The UIColor instance
|
|
5300
5615
|
*/
|
|
5301
5616
|
set color(value) {
|
|
5302
|
-
this.
|
|
5303
|
-
}
|
|
5304
|
-
/**
|
|
5305
|
-
* Sets the opacity level of the scene texture.
|
|
5306
|
-
* @param value - The opacity value between 0.0 (transparent) and 1.0 (opaque)
|
|
5307
|
-
*/
|
|
5308
|
-
set opacity(value) {
|
|
5309
|
-
this._private_material.setOpacity(value);
|
|
5310
|
-
}
|
|
5311
|
-
/**
|
|
5312
|
-
* Sets whether transparency is enabled for the scene texture.
|
|
5313
|
-
* @param value - True to enable transparency, false to disable
|
|
5314
|
-
*/
|
|
5315
|
-
set transparency(value) {
|
|
5316
|
-
this._private_material.setTransparency(value);
|
|
5617
|
+
this._private_colorInternal.copy(value);
|
|
5317
5618
|
}
|
|
5318
5619
|
/**
|
|
5319
5620
|
* Sets a new Three.js scene to render and marks for re-render.
|
|
@@ -5384,8 +5685,7 @@ class UIScene extends UIElement {
|
|
|
5384
5685
|
* After calling this method, the scene element should not be used anymore.
|
|
5385
5686
|
*/
|
|
5386
5687
|
destroy() {
|
|
5387
|
-
this.
|
|
5388
|
-
this._private_material.dispose();
|
|
5688
|
+
this._private_colorInternal.off(UIColorEvent.CHANGE, this._private_onColorChange);
|
|
5389
5689
|
this._private_renderTarget.dispose();
|
|
5390
5690
|
super.destroy();
|
|
5391
5691
|
}
|
|
@@ -5398,6 +5698,27 @@ class UIScene extends UIElement {
|
|
|
5398
5698
|
requestRender() {
|
|
5399
5699
|
this._private_renderRequired = true;
|
|
5400
5700
|
}
|
|
5701
|
+
/**
|
|
5702
|
+
* Called before each render frame to update the 3D scene rendering.
|
|
5703
|
+
* Handles different update modes and renders the 3D scene to the render target
|
|
5704
|
+
* based on the current update mode and property change state.
|
|
5705
|
+
* @param renderer - The WebGL renderer used for scene rendering
|
|
5706
|
+
*/
|
|
5707
|
+
onWillRender(renderer) {
|
|
5708
|
+
if (this._private_updateModeInternal === UISceneUpdateMode.EACH_FRAME ||
|
|
5709
|
+
(this._private_updateModeInternal === UISceneUpdateMode.EACH_SECOND_FRAME && this._private_frameBoolean) ||
|
|
5710
|
+
(this._private_updateModeInternal === UISceneUpdateMode.PROPERTY_CHANGED && this._private_propertyChanged) ||
|
|
5711
|
+
(this._private_updateModeInternal === UISceneUpdateMode.MANUAL && this._private_renderRequired)) {
|
|
5712
|
+
this._private_renderRequired = false;
|
|
5713
|
+
this._private_propertyChanged = false;
|
|
5714
|
+
this._private_frameBoolean = !this._private_frameBoolean;
|
|
5715
|
+
this._private_renderTarget.setSize(this.width * this._private_resolutionFactorInternal, this.height * this._private_resolutionFactorInternal);
|
|
5716
|
+
renderer.setClearColor(this._private_clearColorInternal, this.clearAlpha);
|
|
5717
|
+
renderer.setRenderTarget(this._private_renderTarget);
|
|
5718
|
+
renderer.clear(true, true, false);
|
|
5719
|
+
renderer.render(this._private_sceneInternal, this._private_cameraInternal);
|
|
5720
|
+
}
|
|
5721
|
+
}
|
|
5401
5722
|
}
|
|
5402
5723
|
|
|
5403
5724
|
function isUITextStyle(obj) {
|
|
@@ -5642,7 +5963,7 @@ function calculateTextContentParameters(context, content, maxLineWidth, commonSt
|
|
|
5642
5963
|
return { lines, size: textSize };
|
|
5643
5964
|
}
|
|
5644
5965
|
|
|
5645
|
-
function
|
|
5966
|
+
function resolveTextPadding(value) {
|
|
5646
5967
|
if (typeof value === "number") {
|
|
5647
5968
|
return { left: value, right: value, top: value, bottom: value };
|
|
5648
5969
|
}
|
|
@@ -5687,61 +6008,45 @@ class UIText extends UIElement {
|
|
|
5687
6008
|
* @param layer - The UI layer that contains this text element
|
|
5688
6009
|
* @param content - The text content to display
|
|
5689
6010
|
* @param options - Configuration options for text rendering
|
|
5690
|
-
* @param x - Initial x-coordinate position (defaults to 0)
|
|
5691
|
-
* @param y - Initial y-coordinate position (defaults to 0)
|
|
5692
6011
|
* @throws Will throw an error if canvas context creation fails
|
|
5693
6012
|
*/
|
|
5694
6013
|
constructor(layer, content, options = {}) {
|
|
5695
|
-
const canvas =
|
|
6014
|
+
const canvas = new OffscreenCanvas(2, 2);
|
|
5696
6015
|
const context = canvas.getContext("2d");
|
|
5697
6016
|
if (!context) {
|
|
5698
|
-
throw new Error("
|
|
6017
|
+
throw new Error("UIText failed to create canvas context");
|
|
5699
6018
|
}
|
|
5700
6019
|
const texture = new CanvasTexture(canvas);
|
|
5701
|
-
const
|
|
5702
|
-
|
|
5703
|
-
|
|
6020
|
+
const color = options.color ?? new UIColor();
|
|
6021
|
+
super(layer, options.x ?? 0, options.y ?? 0, 2, 2, source$2, {
|
|
6022
|
+
map: texture,
|
|
6023
|
+
color,
|
|
6024
|
+
});
|
|
5704
6025
|
/** Target aspect ratio for the text element based on content. */
|
|
5705
6026
|
this._private_targetAspectRatio = 1;
|
|
5706
6027
|
/** Last calculated aspect ratio for comparison during rendering. */
|
|
5707
6028
|
this._private_lastAspectRatio = 1;
|
|
5708
|
-
|
|
5709
|
-
|
|
5710
|
-
|
|
5711
|
-
this.height = this.width / this._private_targetAspectRatio;
|
|
5712
|
-
}
|
|
6029
|
+
/** Event handler for when the color changes */
|
|
6030
|
+
this._private_onColorChange = (color) => {
|
|
6031
|
+
this.sceneWrapper.setUniform(this.planeHandler, "color", color);
|
|
5713
6032
|
};
|
|
5714
|
-
this.layer.on(UILayerEvent.WILL_RENDER, this._private_onWillRenderInternal);
|
|
5715
|
-
this._private_material = material;
|
|
5716
|
-
this._private_texture = texture;
|
|
5717
6033
|
this._private_canvas = canvas;
|
|
5718
6034
|
this._private_context = context;
|
|
6035
|
+
this._private_texture = texture;
|
|
6036
|
+
this._private_colorInternal = color;
|
|
5719
6037
|
this._private_contentInternal = content;
|
|
5720
6038
|
this._private_maxWidthInternal = options.maxWidth ?? DEFAULT_MAX_WIDTH;
|
|
5721
|
-
this._private_paddingInternal =
|
|
6039
|
+
this._private_paddingInternal = resolveTextPadding(options.padding);
|
|
5722
6040
|
this._private_commonStyleInternal = options.commonStyle ?? {};
|
|
6041
|
+
this._private_colorInternal.on(UIColorEvent.CHANGE, this._private_onColorChange);
|
|
5723
6042
|
this._private_rebuildText();
|
|
5724
6043
|
}
|
|
5725
6044
|
/**
|
|
5726
6045
|
* Gets the current color tint applied to the text.
|
|
5727
|
-
* @returns The
|
|
6046
|
+
* @returns The UIColor instance
|
|
5728
6047
|
*/
|
|
5729
6048
|
get color() {
|
|
5730
|
-
return this.
|
|
5731
|
-
}
|
|
5732
|
-
/**
|
|
5733
|
-
* Gets the current opacity level of the text.
|
|
5734
|
-
* @returns The opacity value between 0.0 (transparent) and 1.0 (opaque)
|
|
5735
|
-
*/
|
|
5736
|
-
get opacity() {
|
|
5737
|
-
return this._private_material.getOpacity();
|
|
5738
|
-
}
|
|
5739
|
-
/**
|
|
5740
|
-
* Gets whether transparency is enabled for the text.
|
|
5741
|
-
* @returns True if transparency is enabled, false otherwise
|
|
5742
|
-
*/
|
|
5743
|
-
get transparency() {
|
|
5744
|
-
return this._private_material.getTransparency();
|
|
6049
|
+
return this._private_colorInternal;
|
|
5745
6050
|
}
|
|
5746
6051
|
/**
|
|
5747
6052
|
* Gets the current text content being displayed.
|
|
@@ -5773,24 +6078,10 @@ class UIText extends UIElement {
|
|
|
5773
6078
|
}
|
|
5774
6079
|
/**
|
|
5775
6080
|
* Sets the color tint applied to the text.
|
|
5776
|
-
* @param value - The
|
|
6081
|
+
* @param value - The UIColor instance
|
|
5777
6082
|
*/
|
|
5778
6083
|
set color(value) {
|
|
5779
|
-
this.
|
|
5780
|
-
}
|
|
5781
|
-
/**
|
|
5782
|
-
* Sets the opacity level of the text.
|
|
5783
|
-
* @param value - The opacity value between 0.0 (transparent) and 1.0 (opaque)
|
|
5784
|
-
*/
|
|
5785
|
-
set opacity(value) {
|
|
5786
|
-
this._private_material.setOpacity(value);
|
|
5787
|
-
}
|
|
5788
|
-
/**
|
|
5789
|
-
* Sets whether transparency is enabled for the text.
|
|
5790
|
-
* @param value - True to enable transparency, false to disable
|
|
5791
|
-
*/
|
|
5792
|
-
set transparency(value) {
|
|
5793
|
-
this._private_material.setTransparency(value);
|
|
6084
|
+
this._private_colorInternal.copy(value);
|
|
5794
6085
|
}
|
|
5795
6086
|
/**
|
|
5796
6087
|
* Sets new text content and triggers a rebuild.
|
|
@@ -5827,26 +6118,34 @@ class UIText extends UIElement {
|
|
|
5827
6118
|
/**
|
|
5828
6119
|
* Destroys the text element by cleaning up all associated resources.
|
|
5829
6120
|
*
|
|
5830
|
-
* This method disposes of the
|
|
5831
|
-
* the canvas element from the DOM, and calls the parent destroy method
|
|
6121
|
+
* This method disposes of the texture resources and calls the parent destroy method
|
|
5832
6122
|
* to clean up the underlying UI element. After calling this method,
|
|
5833
6123
|
* the text element should not be used anymore.
|
|
5834
6124
|
*/
|
|
5835
6125
|
destroy() {
|
|
5836
|
-
this.
|
|
5837
|
-
this._private_material.dispose();
|
|
6126
|
+
this._private_colorInternal.off(UIColorEvent.CHANGE, this._private_onColorChange);
|
|
5838
6127
|
this._private_texture.dispose();
|
|
5839
|
-
this._private_canvas.remove();
|
|
5840
6128
|
super.destroy();
|
|
5841
6129
|
}
|
|
6130
|
+
/**
|
|
6131
|
+
* Called before each render frame to maintain proper text aspect ratio.
|
|
6132
|
+
* Adjusts the height based on the target aspect ratio calculated from text content.
|
|
6133
|
+
* @param renderer - The WebGL renderer
|
|
6134
|
+
* @param deltaTime - Time since last frame in seconds
|
|
6135
|
+
*/
|
|
6136
|
+
onWillRender(renderer, deltaTime) {
|
|
6137
|
+
super.onWillRender(renderer, deltaTime);
|
|
6138
|
+
if (this._private_lastAspectRatio !== this.width / this.height) {
|
|
6139
|
+
this._private_lastAspectRatio = this._private_targetAspectRatio;
|
|
6140
|
+
this.height = this.width / this._private_targetAspectRatio;
|
|
6141
|
+
}
|
|
6142
|
+
}
|
|
5842
6143
|
/**
|
|
5843
6144
|
* Rebuilds the text canvas and texture based on current content and settings.
|
|
5844
6145
|
*
|
|
5845
6146
|
* This method calculates the text layout, resizes the canvas to fit the content
|
|
5846
6147
|
* with padding, renders the text lines to the canvas, and updates the texture.
|
|
5847
6148
|
* It also calculates and sets the target aspect ratio for proper display.
|
|
5848
|
-
*
|
|
5849
|
-
* @private
|
|
5850
6149
|
*/
|
|
5851
6150
|
_private_rebuildText() {
|
|
5852
6151
|
const { lines, size } = calculateTextContentParameters(this._private_context, this.content, this._private_maxWidthInternal, this._private_commonStyleInternal);
|
|
@@ -5899,14 +6198,12 @@ class UIFullscreenLayer extends UILayer {
|
|
|
5899
6198
|
if (fixedHeight !== undefined) {
|
|
5900
6199
|
assertValidPositiveNumber(fixedHeight, "UIFullscreenLayer.fixedHeight");
|
|
5901
6200
|
}
|
|
5902
|
-
super(
|
|
6201
|
+
super(window.innerWidth, window.innerHeight);
|
|
5903
6202
|
/**
|
|
5904
6203
|
* Event handler for window resize events.
|
|
5905
6204
|
*
|
|
5906
6205
|
* Recalculates the scaling factor and updates the layer dimensions
|
|
5907
6206
|
* based on the new window size and fixed dimension constraints.
|
|
5908
|
-
*
|
|
5909
|
-
* @private
|
|
5910
6207
|
*/
|
|
5911
6208
|
this._private_onResize = () => {
|
|
5912
6209
|
const scale = this._private_calculateScale();
|
|
@@ -5920,7 +6217,6 @@ class UIFullscreenLayer extends UILayer {
|
|
|
5920
6217
|
* The y-coordinate is flipped to match the UI coordinate system.
|
|
5921
6218
|
*
|
|
5922
6219
|
* @param event - The pointer event from the browser
|
|
5923
|
-
* @private
|
|
5924
6220
|
*/
|
|
5925
6221
|
this._private_onClick = (event) => {
|
|
5926
6222
|
const r = event.target instanceof HTMLElement
|
|
@@ -5929,7 +6225,7 @@ class UIFullscreenLayer extends UILayer {
|
|
|
5929
6225
|
const x = r ? event.clientX - r.left : event.clientX;
|
|
5930
6226
|
const y = r ? r.bottom - event.clientY : window.innerHeight - event.clientY;
|
|
5931
6227
|
const scale = this._private_calculateScale();
|
|
5932
|
-
this.
|
|
6228
|
+
this.pointerClickInternal(x * scale, y * scale);
|
|
5933
6229
|
};
|
|
5934
6230
|
this._private_fixedWidthInternal = fixedWidth;
|
|
5935
6231
|
this._private_fixedHeightInternal = fixedHeight;
|
|
@@ -6016,7 +6312,6 @@ class UIFullscreenLayer extends UILayer {
|
|
|
6016
6312
|
* width takes precedence; in vertical orientation, fixed height takes precedence.
|
|
6017
6313
|
*
|
|
6018
6314
|
* @returns The scaling factor to apply to window dimensions
|
|
6019
|
-
* @private
|
|
6020
6315
|
*/
|
|
6021
6316
|
_private_calculateScale() {
|
|
6022
6317
|
if (this.orientation === UIOrientation.HORIZONTAL) {
|
|
@@ -6052,5 +6347,5 @@ function isUITextSpan(obj) {
|
|
|
6052
6347
|
(!("style" in obj) || isUITextStyle(obj.style)));
|
|
6053
6348
|
}
|
|
6054
6349
|
|
|
6055
|
-
export { UIAnchor,
|
|
6350
|
+
export { UIAnchor, UIAspectConstraint, UIColor, UIColorEvent, UIConstraint, UIConstraint2DBuilder, UICoverConstraintBuilder, UICustomConstraint, UIDummy, UIElement, UIExpression, UIFitConstraintBuilder, UIFullscreenLayer, 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 };
|
|
6056
6351
|
//# sourceMappingURL=index.js.map
|