babylon.gui.d.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. declare module BABYLON.GUI {
  2. class AdvancedDynamicTexture extends DynamicTexture {
  3. private _isDirty;
  4. private _renderObserver;
  5. private _resizeObserver;
  6. private _pointerMoveObserver;
  7. private _pointerObserver;
  8. private _canvasBlurObserver;
  9. private _background;
  10. _rootContainer: Container;
  11. _lastControlOver: Control;
  12. _lastControlDown: Control;
  13. _capturingControl: Control;
  14. _shouldBlockPointer: boolean;
  15. _layerToDispose: Layer;
  16. _linkedControls: Control[];
  17. private _isFullscreen;
  18. private _fullscreenViewport;
  19. private _idealWidth;
  20. private _idealHeight;
  21. background: string;
  22. idealWidth: number;
  23. idealHeight: number;
  24. readonly layer: Layer;
  25. constructor(name: string, width: number, height: number, scene: Scene, generateMipMaps?: boolean, samplingMode?: number);
  26. markAsDirty(): void;
  27. addControl(control: Control): AdvancedDynamicTexture;
  28. removeControl(control: Control): AdvancedDynamicTexture;
  29. dispose(): void;
  30. private _onResize();
  31. private _checkUpdate(camera);
  32. private _render();
  33. private _doPicking(x, y, type);
  34. attach(): void;
  35. attachToMesh(mesh: AbstractMesh): void;
  36. static CreateForMesh(mesh: AbstractMesh, width?: number, height?: number): AdvancedDynamicTexture;
  37. static CreateFullscreenUI(name: string, foreground?: boolean, scene?: Scene): AdvancedDynamicTexture;
  38. }
  39. }
  40. declare module BABYLON.GUI {
  41. class Measure {
  42. left: number;
  43. top: number;
  44. width: number;
  45. height: number;
  46. constructor(left: number, top: number, width: number, height: number);
  47. copyFrom(other: Measure): void;
  48. isEqualsTo(other: Measure): boolean;
  49. static Empty(): Measure;
  50. }
  51. }
  52. declare module BABYLON.GUI {
  53. class Matrix2D {
  54. m: Float32Array;
  55. constructor(m00: number, m01: number, m10: number, m11: number, m20: number, m21: number);
  56. fromValues(m00: number, m01: number, m10: number, m11: number, m20: number, m21: number): Matrix2D;
  57. determinant(): number;
  58. invertToRef(result: Matrix2D): Matrix2D;
  59. multiplyToRef(other: Matrix2D, result: Matrix2D): Matrix2D;
  60. transformCoordinates(x: number, y: number, result: Vector2): Matrix2D;
  61. static Identity(): Matrix2D;
  62. static TranslationToRef(x: number, y: number, result: Matrix2D): void;
  63. static ScalingToRef(x: number, y: number, result: Matrix2D): void;
  64. static RotationToRef(angle: number, result: Matrix2D): void;
  65. private static _TempPreTranslationMatrix;
  66. private static _TempPostTranslationMatrix;
  67. private static _TempRotationMatrix;
  68. private static _TempScalingMatrix;
  69. private static _TempCompose0;
  70. private static _TempCompose1;
  71. private static _TempCompose2;
  72. static ComposeToRef(tx: number, ty: number, angle: number, scaleX: number, scaleY: number, parentMatrix: Matrix2D, result: Matrix2D): void;
  73. }
  74. }
  75. declare module BABYLON.GUI {
  76. class ValueAndUnit {
  77. unit: number;
  78. negativeValueAllowed: boolean;
  79. private _value;
  80. ignoreAdaptiveScaling: boolean;
  81. constructor(value: any, unit?: number, negativeValueAllowed?: boolean);
  82. readonly isPercentage: boolean;
  83. readonly isPixel: boolean;
  84. readonly internalValue: number;
  85. getValue(host: AdvancedDynamicTexture): number;
  86. toString(host: AdvancedDynamicTexture): string;
  87. fromString(source: string | number): boolean;
  88. private static _Regex;
  89. private static _UNITMODE_PERCENTAGE;
  90. private static _UNITMODE_PIXEL;
  91. static readonly UNITMODE_PERCENTAGE: number;
  92. static readonly UNITMODE_PIXEL: number;
  93. }
  94. }
  95. declare module BABYLON.GUI {
  96. class Control {
  97. name: string;
  98. private _alpha;
  99. private _zIndex;
  100. _root: Container;
  101. _host: AdvancedDynamicTexture;
  102. _currentMeasure: Measure;
  103. private _fontFamily;
  104. private _fontSize;
  105. private _font;
  106. _width: ValueAndUnit;
  107. _height: ValueAndUnit;
  108. private _lastMeasuredFont;
  109. protected _fontOffset: {
  110. ascent: number;
  111. height: number;
  112. descent: number;
  113. };
  114. private _color;
  115. protected _horizontalAlignment: number;
  116. protected _verticalAlignment: number;
  117. private _isDirty;
  118. private _cachedParentMeasure;
  119. private _marginLeft;
  120. private _marginRight;
  121. private _marginTop;
  122. private _marginBottom;
  123. private _left;
  124. private _top;
  125. private _scaleX;
  126. private _scaleY;
  127. private _rotation;
  128. private _transformCenterX;
  129. private _transformCenterY;
  130. private _transformMatrix;
  131. private _invertTransformMatrix;
  132. private _transformedPosition;
  133. private _isMatrixDirty;
  134. private _cachedOffsetX;
  135. private _cachedOffsetY;
  136. private _isVisible;
  137. _linkedMesh: AbstractMesh;
  138. private _fontSet;
  139. private _dummyVector2;
  140. isHitTestVisible: boolean;
  141. isPointerBlocker: boolean;
  142. protected _linkOffsetX: ValueAndUnit;
  143. protected _linkOffsetY: ValueAndUnit;
  144. /**
  145. * An event triggered when the pointer move over the control.
  146. * @type {BABYLON.Observable}
  147. */
  148. onPointerMoveObservable: Observable<Vector2>;
  149. /**
  150. * An event triggered when the pointer move out of the control.
  151. * @type {BABYLON.Observable}
  152. */
  153. onPointerOutObservable: Observable<Control>;
  154. /**
  155. * An event triggered when the pointer taps the control
  156. * @type {BABYLON.Observable}
  157. */
  158. onPointerDownObservable: Observable<Vector2>;
  159. /**
  160. * An event triggered when pointer up
  161. * @type {BABYLON.Observable}
  162. */
  163. onPointerUpObservable: Observable<Vector2>;
  164. /**
  165. * An event triggered when pointer enters the control
  166. * @type {BABYLON.Observable}
  167. */
  168. onPointerEnterObservable: Observable<Control>;
  169. /**
  170. * An event triggered when the control is marked as dirty
  171. * @type {BABYLON.Observable}
  172. */
  173. onDirtyObservable: Observable<Control>;
  174. alpha: number;
  175. scaleX: number;
  176. scaleY: number;
  177. rotation: number;
  178. transformCenterY: number;
  179. transformCenterX: number;
  180. horizontalAlignment: number;
  181. verticalAlignment: number;
  182. width: string | number;
  183. height: string | number;
  184. fontFamily: string;
  185. fontSize: string | number;
  186. color: string;
  187. zIndex: number;
  188. isVisible: boolean;
  189. readonly isDirty: boolean;
  190. marginLeft: string | number;
  191. marginRight: string | number;
  192. marginTop: string | number;
  193. marginBottom: string | number;
  194. left: string | number;
  195. top: string | number;
  196. linkOffsetX: string | number;
  197. linkOffsetY: string | number;
  198. readonly centerX: number;
  199. readonly centerY: number;
  200. constructor(name?: string);
  201. linkWithMesh(mesh: AbstractMesh): void;
  202. _moveToProjectedPosition(projectedPosition: Vector3): void;
  203. _markMatrixAsDirty(): void;
  204. _markAsDirty(): void;
  205. _markAllAsDirty(): void;
  206. _link(root: Container, host: AdvancedDynamicTexture): void;
  207. protected _transform(context: CanvasRenderingContext2D): void;
  208. protected _applyStates(context: CanvasRenderingContext2D): void;
  209. protected _processMeasures(parentMeasure: Measure, context: CanvasRenderingContext2D): boolean;
  210. protected _clip(context: CanvasRenderingContext2D): void;
  211. _measure(): void;
  212. protected _computeAlignment(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
  213. protected _additionalProcessing(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
  214. _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
  215. contains(x: number, y: number): boolean;
  216. _processPicking(x: number, y: number, type: number): boolean;
  217. protected _onPointerMove(coordinates: Vector2): void;
  218. protected _onPointerEnter(): void;
  219. protected _onPointerOut(): void;
  220. protected _onPointerDown(coordinates: Vector2): void;
  221. protected _onPointerUp(coordinates: Vector2): void;
  222. forcePointerUp(): void;
  223. _processObservables(type: number, x: number, y: number): boolean;
  224. private _prepareFont();
  225. private static _HORIZONTAL_ALIGNMENT_LEFT;
  226. private static _HORIZONTAL_ALIGNMENT_RIGHT;
  227. private static _HORIZONTAL_ALIGNMENT_CENTER;
  228. private static _VERTICAL_ALIGNMENT_TOP;
  229. private static _VERTICAL_ALIGNMENT_BOTTOM;
  230. private static _VERTICAL_ALIGNMENT_CENTER;
  231. static readonly HORIZONTAL_ALIGNMENT_LEFT: number;
  232. static readonly HORIZONTAL_ALIGNMENT_RIGHT: number;
  233. static readonly HORIZONTAL_ALIGNMENT_CENTER: number;
  234. static readonly VERTICAL_ALIGNMENT_TOP: number;
  235. static readonly VERTICAL_ALIGNMENT_BOTTOM: number;
  236. static readonly VERTICAL_ALIGNMENT_CENTER: number;
  237. private static _FontHeightSizes;
  238. static _GetFontOffset(font: string): {
  239. ascent: number;
  240. height: number;
  241. descent: number;
  242. };
  243. }
  244. }
  245. declare module BABYLON.GUI {
  246. class Container extends Control {
  247. name: string;
  248. protected _children: Control[];
  249. protected _measureForChildren: Measure;
  250. protected _background: string;
  251. background: string;
  252. readonly children: Control[];
  253. constructor(name?: string);
  254. containsControl(control: Control): boolean;
  255. addControl(control: Control): Container;
  256. removeControl(control: Control): Container;
  257. _reOrderControl(control: Control): void;
  258. _markMatrixAsDirty(): void;
  259. _markAllAsDirty(): void;
  260. protected _localDraw(context: CanvasRenderingContext2D): void;
  261. _link(root: Container, host: AdvancedDynamicTexture): void;
  262. _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
  263. _processPicking(x: number, y: number, type: number): boolean;
  264. protected _clipForChildren(context: CanvasRenderingContext2D): void;
  265. protected _additionalProcessing(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
  266. }
  267. }
  268. declare module BABYLON.GUI {
  269. class StackPanel extends Container {
  270. name: string;
  271. private _isVertical;
  272. isVertical: boolean;
  273. constructor(name?: string);
  274. protected _additionalProcessing(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
  275. }
  276. }
  277. declare module BABYLON.GUI {
  278. class Rectangle extends Container {
  279. name: string;
  280. private _thickness;
  281. private _cornerRadius;
  282. thickness: number;
  283. cornerRadius: number;
  284. constructor(name?: string);
  285. protected _localDraw(context: CanvasRenderingContext2D): void;
  286. protected _additionalProcessing(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
  287. private _drawRoundedRect(context, offset?);
  288. protected _clipForChildren(context: CanvasRenderingContext2D): void;
  289. }
  290. }
  291. declare module BABYLON.GUI {
  292. class Ellipse extends Container {
  293. name: string;
  294. private _thickness;
  295. thickness: number;
  296. constructor(name?: string);
  297. protected _localDraw(context: CanvasRenderingContext2D): void;
  298. protected _additionalProcessing(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
  299. protected _clipForChildren(context: CanvasRenderingContext2D): void;
  300. }
  301. }
  302. declare var DOMImage: new (width?: number, height?: number) => HTMLImageElement;
  303. declare module BABYLON.GUI {
  304. class Line extends Control {
  305. name: string;
  306. private _lineWidth;
  307. private _background;
  308. private _x1;
  309. private _y1;
  310. private _x2;
  311. private _y2;
  312. private _dash;
  313. private _connectedControl;
  314. private _connectedControlDirtyObserver;
  315. dash: Array<number>;
  316. connectedControl: Control;
  317. x1: string | number;
  318. y1: string | number;
  319. x2: string | number;
  320. y2: string | number;
  321. lineWidth: number;
  322. horizontalAlignment: number;
  323. verticalAlignment: number;
  324. private readonly _effectiveX2;
  325. private readonly _effectiveY2;
  326. constructor(name?: string);
  327. _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
  328. _measure(): void;
  329. protected _computeAlignment(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
  330. _moveToProjectedPosition(projectedPosition: Vector3): void;
  331. }
  332. }
  333. declare var DOMImage: new (width?: number, height?: number) => HTMLImageElement;
  334. declare module BABYLON.GUI {
  335. class Slider extends Control {
  336. name: string;
  337. private _thumbWidth;
  338. private _minimum;
  339. private _maximum;
  340. private _value;
  341. private _background;
  342. private _foreground;
  343. private _borderColor;
  344. private _barOffset;
  345. onValueChangedObservable: Observable<number>;
  346. borderColor: string;
  347. foreground: string;
  348. background: string;
  349. minimum: number;
  350. maximum: number;
  351. value: number;
  352. constructor(name?: string);
  353. _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
  354. private _pointerIsDown;
  355. private _updateValueFromPointer(x);
  356. protected _onPointerDown(coordinates: Vector2): void;
  357. protected _onPointerMove(coordinates: Vector2): void;
  358. protected _onPointerUp(coordinates: Vector2): void;
  359. }
  360. }
  361. declare module BABYLON.GUI {
  362. class TextBlock extends Control {
  363. name: string;
  364. private _text;
  365. private _textY;
  366. private _textWrapping;
  367. private _textHorizontalAlignment;
  368. private _textVerticalAlignment;
  369. private _lines;
  370. private _totalHeight;
  371. textWrapping: boolean;
  372. text: string;
  373. textHorizontalAlignment: number;
  374. textVerticalAlignment: number;
  375. constructor(name?: string, text?: string);
  376. private _drawText(text, textWidth, y, context);
  377. _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
  378. protected _additionalProcessing(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
  379. protected _renderLines(context: CanvasRenderingContext2D): void;
  380. }
  381. }
  382. declare var DOMImage: new (width?: number, height?: number) => HTMLImageElement;
  383. declare module BABYLON.GUI {
  384. class Image extends Control {
  385. name: string;
  386. private _domImage;
  387. private _imageWidth;
  388. private _imageHeight;
  389. private _loaded;
  390. private _stretch;
  391. private _source;
  392. private _autoScale;
  393. autoScale: boolean;
  394. stretch: number;
  395. domImage: HTMLImageElement;
  396. private _onImageLoaded();
  397. source: string;
  398. constructor(name?: string, url?: string);
  399. synchronizeSizeWithContent(): void;
  400. _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void;
  401. private static _STRETCH_NONE;
  402. private static _STRETCH_FILL;
  403. private static _STRETCH_UNIFORM;
  404. private static _STRETCH_EXTEND;
  405. static readonly STRETCH_NONE: number;
  406. static readonly STRETCH_FILL: number;
  407. static readonly STRETCH_UNIFORM: number;
  408. static readonly STRETCH_EXTEND: number;
  409. }
  410. }
  411. declare module BABYLON.GUI {
  412. class Button extends Rectangle {
  413. name: string;
  414. pointerEnterAnimation: () => void;
  415. pointerOutAnimation: () => void;
  416. pointerDownAnimation: () => void;
  417. pointerUpAnimation: () => void;
  418. constructor(name?: string);
  419. _processPicking(x: number, y: number, type: number): boolean;
  420. protected _onPointerEnter(): void;
  421. protected _onPointerOut(): void;
  422. protected _onPointerDown(coordinates: Vector2): void;
  423. protected _onPointerUp(coordinates: Vector2): void;
  424. static CreateImageButton(name: string, text: string, imageUrl: string): Button;
  425. static CreateImageOnlyButton(name: string, imageUrl: string): Button;
  426. static CreateSimpleButton(name: string, text: string): Button;
  427. }
  428. }