babylon.gui.UIElement.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. var __extends = (this && this.__extends) || function (d, b) {
  2. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  3. function __() { this.constructor = d; }
  4. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  5. };
  6. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  7. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  8. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  9. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  10. return c > 3 && r && Object.defineProperty(target, key, r), r;
  11. };
  12. var BABYLON;
  13. (function (BABYLON) {
  14. var Command = (function () {
  15. function Command(execute, canExecute) {
  16. if (!execute) {
  17. throw Error("At least an execute lambda must be given at Command creation time");
  18. }
  19. this._canExecuteChanged = null;
  20. this._lastCanExecuteResult = null;
  21. this.execute = execute;
  22. this.canExecute = canExecute;
  23. }
  24. Command.prototype.canExecute = function (parameter) {
  25. var res = true;
  26. if (this._canExecute) {
  27. res = this._canExecute(parameter);
  28. }
  29. if (res !== this._lastCanExecuteResult) {
  30. if (this._canExecuteChanged && this._canExecuteChanged.hasObservers()) {
  31. this._canExecuteChanged.notifyObservers(null);
  32. }
  33. this._lastCanExecuteResult = res;
  34. }
  35. return res;
  36. };
  37. Command.prototype.execute = function (parameter) {
  38. this._execute(parameter);
  39. };
  40. Object.defineProperty(Command.prototype, "canExecuteChanged", {
  41. get: function () {
  42. if (!this._canExecuteChanged) {
  43. this._canExecuteChanged = new BABYLON.Observable();
  44. }
  45. return this._canExecuteChanged;
  46. },
  47. enumerable: true,
  48. configurable: true
  49. });
  50. return Command;
  51. }());
  52. BABYLON.Command = Command;
  53. var UIElement = (function (_super) {
  54. __extends(UIElement, _super);
  55. function UIElement(settings) {
  56. _super.call(this);
  57. if (!settings) {
  58. throw Error("A settings object must be passed with at least either a parent or owner parameter");
  59. }
  60. var type = BABYLON.Tools.getFullClassName(this);
  61. this._ownerWindow = null;
  62. this._parent = null;
  63. this._visualPlaceholder = null;
  64. this._visualTemplateRoot = null;
  65. this._visualChildrenPlaceholder = null;
  66. this._hierarchyDepth = 0;
  67. this._style = (settings.styleName != null) ? UIElementStyleManager.getStyle(type, settings.styleName) : null;
  68. this._flags = 0;
  69. this._id = (settings.id != null) ? settings.id : null;
  70. this._uid = null;
  71. this._width = (settings.width != null) ? settings.width : null;
  72. this._height = (settings.height != null) ? settings.height : null;
  73. this._minWidth = (settings.minWidth != null) ? settings.minWidth : 0;
  74. this._minHeight = (settings.minHeight != null) ? settings.minHeight : 0;
  75. this._maxWidth = (settings.maxWidth != null) ? settings.maxWidth : Number.MAX_VALUE;
  76. this._maxHeight = (settings.maxHeight != null) ? settings.maxHeight : Number.MAX_VALUE;
  77. this._margin = null;
  78. this._padding = null;
  79. this._marginAlignment = null;
  80. this._isEnabled = true;
  81. this._isFocused = false;
  82. this._isMouseOver = false;
  83. // Default Margin Alignment for UIElement is stretch for horizontal/vertical and not left/bottom (which is the default for Canvas2D Primitives)
  84. //this.marginAlignment.horizontal = PrimitiveAlignment.AlignStretch;
  85. //this.marginAlignment.vertical = PrimitiveAlignment.AlignStretch;
  86. // Set the layout/margin stuffs
  87. if (settings.marginTop) {
  88. this.margin.setTop(settings.marginTop);
  89. }
  90. if (settings.marginLeft) {
  91. this.margin.setLeft(settings.marginLeft);
  92. }
  93. if (settings.marginRight) {
  94. this.margin.setRight(settings.marginRight);
  95. }
  96. if (settings.marginBottom) {
  97. this.margin.setBottom(settings.marginBottom);
  98. }
  99. if (settings.margin) {
  100. if (typeof settings.margin === "string") {
  101. this.margin.fromString(settings.margin);
  102. }
  103. else {
  104. this.margin.fromUniformPixels(settings.margin);
  105. }
  106. }
  107. if (settings.marginHAlignment) {
  108. this.marginAlignment.horizontal = settings.marginHAlignment;
  109. }
  110. if (settings.marginVAlignment) {
  111. this.marginAlignment.vertical = settings.marginVAlignment;
  112. }
  113. if (settings.marginAlignment) {
  114. this.marginAlignment.fromString(settings.marginAlignment);
  115. }
  116. if (settings.paddingTop) {
  117. this.padding.setTop(settings.paddingTop);
  118. }
  119. if (settings.paddingLeft) {
  120. this.padding.setLeft(settings.paddingLeft);
  121. }
  122. if (settings.paddingRight) {
  123. this.padding.setRight(settings.paddingRight);
  124. }
  125. if (settings.paddingBottom) {
  126. this.padding.setBottom(settings.paddingBottom);
  127. }
  128. if (settings.padding) {
  129. this.padding.fromString(settings.padding);
  130. }
  131. this._assignTemplate(settings.templateName);
  132. if (settings.parent != null) {
  133. this._parent = settings.parent;
  134. this._hierarchyDepth = this._parent._hierarchyDepth + 1;
  135. }
  136. }
  137. UIElement.prototype.dispose = function () {
  138. if (this.isDisposed) {
  139. return false;
  140. }
  141. if (this._renderingTemplate) {
  142. this._renderingTemplate.detach();
  143. this._renderingTemplate = null;
  144. }
  145. _super.prototype.dispose.call(this);
  146. // Don't set to null, it may upset somebody...
  147. this.animations.splice(0);
  148. return true;
  149. };
  150. /**
  151. * Returns as a new array populated with the Animatable used by the primitive. Must be overloaded by derived primitives.
  152. * Look at Sprite2D for more information
  153. */
  154. UIElement.prototype.getAnimatables = function () {
  155. return new Array();
  156. };
  157. Object.defineProperty(UIElement.prototype, "ownerWindows", {
  158. // TODO
  159. // PROPERTIES
  160. // Style
  161. // Id
  162. // Parent/Children
  163. // ActualWidth/Height, MinWidth/Height, MaxWidth/Height,
  164. // Alignment/Margin
  165. // Visibility, IsVisible
  166. // IsEnabled (is false, control is disabled, no interaction and a specific render state)
  167. // CacheMode of Visual Elements
  168. // Focusable/IsFocused
  169. // IsPointerCaptured, CapturePointer, IsPointerDirectlyOver, IsPointerOver. De-correlate mouse, stylus, touch?
  170. // ContextMenu
  171. // Cursor
  172. // DesiredSize
  173. // IsInputEnable ?
  174. // Opacity, OpacityMask ?
  175. // SnapToDevicePixels
  176. // Tag
  177. // ToolTip
  178. // METHODS
  179. // BringIntoView (for scrollable content, to move the scroll to bring the given element visible in the parent's area)
  180. // Capture/ReleaseCapture (mouse, touch, stylus)
  181. // Focus
  182. // PointFrom/ToScreen to translate coordinates
  183. // EVENTS
  184. // ContextMenuOpening/Closing/Changed
  185. // DragEnter/LeaveOver, Drop
  186. // Got/LostFocus
  187. // IsEnabledChanged
  188. // IsPointerOver/DirectlyOverChanged
  189. // IsVisibleChanged
  190. // KeyDown/Up
  191. // LayoutUpdated ?
  192. // Pointer related events
  193. // SizeChanged
  194. // ToolTipOpening/Closing
  195. get: function () {
  196. return this._ownerWindow;
  197. },
  198. enumerable: true,
  199. configurable: true
  200. });
  201. Object.defineProperty(UIElement.prototype, "style", {
  202. get: function () {
  203. if (!this.style) {
  204. return UIElementStyleManager.DefaultStyleName;
  205. }
  206. return this._style.name;
  207. },
  208. set: function (value) {
  209. if (this._style && (this._style.name === value)) {
  210. return;
  211. }
  212. var newStyle = null;
  213. if (value) {
  214. newStyle = UIElementStyleManager.getStyle(BABYLON.Tools.getFullClassName(this), value);
  215. if (!newStyle) {
  216. throw Error("Couldn't find Style " + value + " for UIElement " + BABYLON.Tools.getFullClassName(this));
  217. }
  218. }
  219. if (this._style) {
  220. this._style.removeStyle(this);
  221. }
  222. if (newStyle) {
  223. newStyle.applyStyle(this);
  224. }
  225. this._style = newStyle;
  226. },
  227. enumerable: true,
  228. configurable: true
  229. });
  230. Object.defineProperty(UIElement.prototype, "id", {
  231. /**
  232. * A string that identifies the UIElement.
  233. * The id is optional and there's possible collision with other UIElement's id as the uniqueness is not supported.
  234. */
  235. get: function () {
  236. return this._id;
  237. },
  238. set: function (value) {
  239. if (this._id === value) {
  240. return;
  241. }
  242. this._id = value;
  243. },
  244. enumerable: true,
  245. configurable: true
  246. });
  247. Object.defineProperty(UIElement.prototype, "uid", {
  248. /**
  249. * Return a unique id automatically generated.
  250. * This property is mainly used for serialization to ensure a perfect way of identifying a UIElement
  251. */
  252. get: function () {
  253. if (!this._uid) {
  254. this._uid = BABYLON.Tools.RandomId();
  255. }
  256. return this._uid;
  257. },
  258. enumerable: true,
  259. configurable: true
  260. });
  261. Object.defineProperty(UIElement.prototype, "hierarchyDepth", {
  262. get: function () {
  263. return this._hierarchyDepth;
  264. },
  265. enumerable: true,
  266. configurable: true
  267. });
  268. Object.defineProperty(UIElement.prototype, "parent", {
  269. get: function () {
  270. return this._parent;
  271. },
  272. set: function (value) {
  273. this._parent = value;
  274. },
  275. enumerable: true,
  276. configurable: true
  277. });
  278. Object.defineProperty(UIElement.prototype, "width", {
  279. get: function () {
  280. return this._width;
  281. },
  282. set: function (value) {
  283. this._width = value;
  284. },
  285. enumerable: true,
  286. configurable: true
  287. });
  288. Object.defineProperty(UIElement.prototype, "height", {
  289. get: function () {
  290. return this._height;
  291. },
  292. set: function (value) {
  293. this._height = value;
  294. },
  295. enumerable: true,
  296. configurable: true
  297. });
  298. Object.defineProperty(UIElement.prototype, "minWidth", {
  299. get: function () {
  300. return this._minWidth;
  301. },
  302. set: function (value) {
  303. this._minWidth = value;
  304. },
  305. enumerable: true,
  306. configurable: true
  307. });
  308. Object.defineProperty(UIElement.prototype, "minHheight", {
  309. get: function () {
  310. return this._minHeight;
  311. },
  312. enumerable: true,
  313. configurable: true
  314. });
  315. Object.defineProperty(UIElement.prototype, "minHeight", {
  316. set: function (value) {
  317. this._minHeight = value;
  318. },
  319. enumerable: true,
  320. configurable: true
  321. });
  322. Object.defineProperty(UIElement.prototype, "maxWidth", {
  323. get: function () {
  324. return this._maxWidth;
  325. },
  326. set: function (value) {
  327. this._maxWidth = value;
  328. },
  329. enumerable: true,
  330. configurable: true
  331. });
  332. Object.defineProperty(UIElement.prototype, "maxHeight", {
  333. get: function () {
  334. return this._maxHeight;
  335. },
  336. set: function (value) {
  337. this._maxHeight = value;
  338. },
  339. enumerable: true,
  340. configurable: true
  341. });
  342. Object.defineProperty(UIElement.prototype, "actualWidth", {
  343. get: function () {
  344. return this._actualWidth;
  345. },
  346. set: function (value) {
  347. this._actualWidth = value;
  348. },
  349. enumerable: true,
  350. configurable: true
  351. });
  352. Object.defineProperty(UIElement.prototype, "actualHeight", {
  353. get: function () {
  354. return this._actualHeight;
  355. },
  356. set: function (value) {
  357. this._actualHeight = value;
  358. },
  359. enumerable: true,
  360. configurable: true
  361. });
  362. Object.defineProperty(UIElement.prototype, "margin", {
  363. get: function () {
  364. var _this = this;
  365. if (!this._margin) {
  366. this._margin = new BABYLON.PrimitiveThickness(function () {
  367. if (!_this.parent) {
  368. return null;
  369. }
  370. return _this.parent.margin;
  371. });
  372. }
  373. return this._margin;
  374. },
  375. set: function (value) {
  376. this.margin.copyFrom(value);
  377. },
  378. enumerable: true,
  379. configurable: true
  380. });
  381. Object.defineProperty(UIElement.prototype, "_hasMargin", {
  382. get: function () {
  383. return (this._margin !== null && !this._margin.isDefault) || (this._marginAlignment !== null && !this._marginAlignment.isDefault);
  384. },
  385. enumerable: true,
  386. configurable: true
  387. });
  388. Object.defineProperty(UIElement.prototype, "padding", {
  389. get: function () {
  390. var _this = this;
  391. if (!this._padding) {
  392. this._padding = new BABYLON.PrimitiveThickness(function () {
  393. if (!_this.parent) {
  394. return null;
  395. }
  396. return _this.parent.padding;
  397. });
  398. }
  399. return this._padding;
  400. },
  401. set: function (value) {
  402. this.padding.copyFrom(value);
  403. },
  404. enumerable: true,
  405. configurable: true
  406. });
  407. Object.defineProperty(UIElement.prototype, "_hasPadding", {
  408. get: function () {
  409. return this._padding !== null && !this._padding.isDefault;
  410. },
  411. enumerable: true,
  412. configurable: true
  413. });
  414. Object.defineProperty(UIElement.prototype, "marginAlignment", {
  415. get: function () {
  416. if (!this._marginAlignment) {
  417. this._marginAlignment = new BABYLON.PrimitiveAlignment();
  418. }
  419. return this._marginAlignment;
  420. },
  421. set: function (value) {
  422. this.marginAlignment.copyFrom(value);
  423. },
  424. enumerable: true,
  425. configurable: true
  426. });
  427. Object.defineProperty(UIElement.prototype, "_hasMarginAlignment", {
  428. /**
  429. * Check if there a marginAlignment specified (non null and not default)
  430. */
  431. get: function () {
  432. return (this._marginAlignment !== null && !this._marginAlignment.isDefault);
  433. },
  434. enumerable: true,
  435. configurable: true
  436. });
  437. Object.defineProperty(UIElement.prototype, "isEnabled", {
  438. get: function () {
  439. return this._isEnabled;
  440. },
  441. set: function (value) {
  442. this._isEnabled = value;
  443. },
  444. enumerable: true,
  445. configurable: true
  446. });
  447. Object.defineProperty(UIElement.prototype, "isFocused", {
  448. get: function () {
  449. return this._isFocused;
  450. },
  451. set: function (value) {
  452. this._isFocused = value;
  453. },
  454. enumerable: true,
  455. configurable: true
  456. });
  457. Object.defineProperty(UIElement.prototype, "isMouseOver", {
  458. get: function () {
  459. return this._isMouseOver;
  460. },
  461. set: function (value) {
  462. this._isMouseOver = value;
  463. },
  464. enumerable: true,
  465. configurable: true
  466. });
  467. /**
  468. * Check if a given flag is set
  469. * @param flag the flag value
  470. * @return true if set, false otherwise
  471. */
  472. UIElement.prototype._isFlagSet = function (flag) {
  473. return (this._flags & flag) !== 0;
  474. };
  475. /**
  476. * Check if all given flags are set
  477. * @param flags the flags ORed
  478. * @return true if all the flags are set, false otherwise
  479. */
  480. UIElement.prototype._areAllFlagsSet = function (flags) {
  481. return (this._flags & flags) === flags;
  482. };
  483. /**
  484. * Check if at least one flag of the given flags is set
  485. * @param flags the flags ORed
  486. * @return true if at least one flag is set, false otherwise
  487. */
  488. UIElement.prototype._areSomeFlagsSet = function (flags) {
  489. return (this._flags & flags) !== 0;
  490. };
  491. /**
  492. * Clear the given flags
  493. * @param flags the flags to clear
  494. */
  495. UIElement.prototype._clearFlags = function (flags) {
  496. this._flags &= ~flags;
  497. };
  498. /**
  499. * Set the given flags to true state
  500. * @param flags the flags ORed to set
  501. * @return the flags state before this call
  502. */
  503. UIElement.prototype._setFlags = function (flags) {
  504. var cur = this._flags;
  505. this._flags |= flags;
  506. return cur;
  507. };
  508. /**
  509. * Change the state of the given flags
  510. * @param flags the flags ORed to change
  511. * @param state true to set them, false to clear them
  512. */
  513. UIElement.prototype._changeFlags = function (flags, state) {
  514. if (state) {
  515. this._flags |= flags;
  516. }
  517. else {
  518. this._flags &= ~flags;
  519. }
  520. };
  521. UIElement.prototype._assignTemplate = function (templateName) {
  522. if (!templateName) {
  523. templateName = UIElementRenderingTemplateManager.DefaultTemplateName;
  524. }
  525. var className = BABYLON.Tools.getFullClassName(this);
  526. if (!className) {
  527. throw Error("Couldn't access class name of this UIElement, you have to decorate the type with the className decorator");
  528. }
  529. var factory = UIElementRenderingTemplateManager.getRenderingTemplate(className, templateName);
  530. if (!factory) {
  531. throw Error("Couldn't get the renderingTemplate " + templateName + " of class " + className);
  532. }
  533. this._renderingTemplate = factory();
  534. this._renderingTemplate.attach(this);
  535. };
  536. UIElement.prototype._createVisualTree = function () {
  537. var parentPrim = this.ownerWindows.canvas;
  538. if (this.parent) {
  539. parentPrim = this.parent.visualChildrenPlaceholder;
  540. }
  541. this._visualPlaceholder = new BABYLON.Group2D({ parent: parentPrim, id: "GUI Visual Placeholder of " + this.id });
  542. var p = this._visualPlaceholder;
  543. p.addExternalData("_GUIOwnerElement_", this);
  544. p.dataSource = this;
  545. p.createSimpleDataBinding(BABYLON.Prim2DBase.widthProperty, "width", BABYLON.DataBinding.MODE_ONEWAY);
  546. p.createSimpleDataBinding(BABYLON.Prim2DBase.heightProperty, "height", BABYLON.DataBinding.MODE_ONEWAY);
  547. p.createSimpleDataBinding(BABYLON.Prim2DBase.actualWidthProperty, "actualWidth", BABYLON.DataBinding.MODE_ONEWAYTOSOURCE);
  548. p.createSimpleDataBinding(BABYLON.Prim2DBase.actualHeightProperty, "actualHeight", BABYLON.DataBinding.MODE_ONEWAYTOSOURCE);
  549. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginProperty, "margin", BABYLON.DataBinding.MODE_ONEWAY);
  550. p.createSimpleDataBinding(BABYLON.Prim2DBase.paddingProperty, "padding", BABYLON.DataBinding.MODE_ONEWAY);
  551. p.createSimpleDataBinding(BABYLON.Prim2DBase.marginAlignmentProperty, "marginAlignment", BABYLON.DataBinding.MODE_ONEWAY);
  552. this.createVisualTree();
  553. };
  554. UIElement.prototype._patchUIElement = function (ownerWindow, parent) {
  555. if (ownerWindow) {
  556. if (!this._ownerWindow) {
  557. ownerWindow._registerVisualToBuild(this);
  558. }
  559. this._ownerWindow = ownerWindow;
  560. }
  561. this._parent = parent;
  562. if (parent) {
  563. this._hierarchyDepth = parent.hierarchyDepth + 1;
  564. }
  565. var children = this._getChildren();
  566. if (children) {
  567. for (var _i = 0, children_1 = children; _i < children_1.length; _i++) {
  568. var curChild = children_1[_i];
  569. curChild._patchUIElement(ownerWindow, this);
  570. }
  571. }
  572. };
  573. // Overload the SmartPropertyBase's method to provide the additional logic of returning the parent's dataSource if there's no dataSource specified at this level.
  574. UIElement.prototype._getDataSource = function () {
  575. var levelDS = _super.prototype._getDataSource.call(this);
  576. if (levelDS != null) {
  577. return levelDS;
  578. }
  579. var p = this.parent;
  580. if (p != null) {
  581. return p.dataSource;
  582. }
  583. return null;
  584. };
  585. UIElement.prototype.createVisualTree = function () {
  586. var res = this._renderingTemplate.createVisualTree(this, this._visualPlaceholder);
  587. this._visualTemplateRoot = res.root;
  588. this._visualChildrenPlaceholder = res.contentPlaceholder;
  589. };
  590. Object.defineProperty(UIElement.prototype, "visualPlaceholder", {
  591. get: function () {
  592. return this._visualPlaceholder;
  593. },
  594. enumerable: true,
  595. configurable: true
  596. });
  597. Object.defineProperty(UIElement.prototype, "visualTemplateRoot", {
  598. get: function () {
  599. return this._visualTemplateRoot;
  600. },
  601. enumerable: true,
  602. configurable: true
  603. });
  604. Object.defineProperty(UIElement.prototype, "visualChildrenPlaceholder", {
  605. get: function () {
  606. return this._visualChildrenPlaceholder;
  607. },
  608. enumerable: true,
  609. configurable: true
  610. });
  611. Object.defineProperty(UIElement.prototype, "_position", {
  612. get: function () { return null; } // TODO use abstract keyword when TS 2.0 will be approved
  613. ,
  614. enumerable: true,
  615. configurable: true
  616. });
  617. UIElement.UIELEMENT_PROPCOUNT = 15;
  618. UIElement.flagVisualToBuild = 0x0000001; // set if the UIElement visual must be updated
  619. __decorate([
  620. BABYLON.dependencyProperty(0, function (pi) { return UIElement.parentProperty = pi; })
  621. ], UIElement.prototype, "parent", null);
  622. __decorate([
  623. BABYLON.dependencyProperty(1, function (pi) { return UIElement.widthProperty = pi; })
  624. ], UIElement.prototype, "width", null);
  625. __decorate([
  626. BABYLON.dependencyProperty(2, function (pi) { return UIElement.heightProperty = pi; })
  627. ], UIElement.prototype, "height", null);
  628. __decorate([
  629. BABYLON.dependencyProperty(3, function (pi) { return UIElement.minWidthProperty = pi; })
  630. ], UIElement.prototype, "minWidth", null);
  631. __decorate([
  632. BABYLON.dependencyProperty(4, function (pi) { return UIElement.minHeightProperty = pi; })
  633. ], UIElement.prototype, "minHheight", null);
  634. __decorate([
  635. BABYLON.dependencyProperty(5, function (pi) { return UIElement.maxWidthProperty = pi; })
  636. ], UIElement.prototype, "maxWidth", null);
  637. __decorate([
  638. BABYLON.dependencyProperty(6, function (pi) { return UIElement.maxHeightProperty = pi; })
  639. ], UIElement.prototype, "maxHeight", null);
  640. __decorate([
  641. BABYLON.dependencyProperty(7, function (pi) { return UIElement.actualWidthProperty = pi; })
  642. ], UIElement.prototype, "actualWidth", null);
  643. __decorate([
  644. BABYLON.dependencyProperty(8, function (pi) { return UIElement.actualHeightProperty = pi; })
  645. ], UIElement.prototype, "actualHeight", null);
  646. __decorate([
  647. BABYLON.dynamicLevelProperty(9, function (pi) { return UIElement.marginProperty = pi; })
  648. ], UIElement.prototype, "margin", null);
  649. __decorate([
  650. BABYLON.dynamicLevelProperty(10, function (pi) { return UIElement.paddingProperty = pi; })
  651. ], UIElement.prototype, "padding", null);
  652. __decorate([
  653. BABYLON.dynamicLevelProperty(11, function (pi) { return UIElement.marginAlignmentProperty = pi; })
  654. ], UIElement.prototype, "marginAlignment", null);
  655. __decorate([
  656. BABYLON.dynamicLevelProperty(12, function (pi) { return UIElement.isEnabledProperty = pi; })
  657. ], UIElement.prototype, "isEnabled", null);
  658. __decorate([
  659. BABYLON.dynamicLevelProperty(13, function (pi) { return UIElement.isFocusedProperty = pi; })
  660. ], UIElement.prototype, "isFocused", null);
  661. __decorate([
  662. BABYLON.dynamicLevelProperty(14, function (pi) { return UIElement.isMouseOverProperty = pi; })
  663. ], UIElement.prototype, "isMouseOver", null);
  664. return UIElement;
  665. }(BABYLON.SmartPropertyBase));
  666. BABYLON.UIElement = UIElement;
  667. var UIElementStyle = (function () {
  668. function UIElementStyle() {
  669. }
  670. Object.defineProperty(UIElementStyle.prototype, "name", {
  671. get: function () { return null; } // TODO use abstract keyword when TS 2.0 will be approved
  672. ,
  673. enumerable: true,
  674. configurable: true
  675. });
  676. return UIElementStyle;
  677. }());
  678. BABYLON.UIElementStyle = UIElementStyle;
  679. var UIElementStyleManager = (function () {
  680. function UIElementStyleManager() {
  681. }
  682. UIElementStyleManager.getStyle = function (uiElType, styleName) {
  683. var styles = UIElementStyleManager.stylesByUIElement.get(uiElType);
  684. if (!styles) {
  685. throw Error("The type " + uiElType + " is unknown, no style were registered for it.");
  686. }
  687. var style = styles.get(styleName);
  688. if (!style) {
  689. throw Error("Couldn't find Template " + styleName + " of UIElement type " + uiElType);
  690. }
  691. return style;
  692. };
  693. UIElementStyleManager.registerStyle = function (uiElType, templateName, style) {
  694. var templates = UIElementStyleManager.stylesByUIElement.getOrAddWithFactory(uiElType, function () { return new BABYLON.StringDictionary(); });
  695. if (templates.contains(templateName)) {
  696. templates[templateName] = style;
  697. }
  698. else {
  699. templates.add(templateName, style);
  700. }
  701. };
  702. Object.defineProperty(UIElementStyleManager, "DefaultStyleName", {
  703. get: function () {
  704. return UIElementStyleManager._defaultStyleName;
  705. },
  706. set: function (value) {
  707. UIElementStyleManager._defaultStyleName = value;
  708. },
  709. enumerable: true,
  710. configurable: true
  711. });
  712. UIElementStyleManager.stylesByUIElement = new BABYLON.StringDictionary();
  713. UIElementStyleManager._defaultStyleName = "Default";
  714. return UIElementStyleManager;
  715. }());
  716. BABYLON.UIElementStyleManager = UIElementStyleManager;
  717. var UIElementRenderingTemplateManager = (function () {
  718. function UIElementRenderingTemplateManager() {
  719. }
  720. UIElementRenderingTemplateManager.getRenderingTemplate = function (uiElType, templateName) {
  721. var templates = UIElementRenderingTemplateManager.renderingTemplatesByUIElement.get(uiElType);
  722. if (!templates) {
  723. throw Error("The type " + uiElType + " is unknown, no Rendering Template were registered for it.");
  724. }
  725. var templateFactory = templates.get(templateName);
  726. if (!templateFactory) {
  727. throw Error("Couldn't find Template " + templateName + " of UI Element type " + uiElType);
  728. }
  729. return templateFactory;
  730. };
  731. UIElementRenderingTemplateManager.registerRenderingTemplate = function (uiElType, templateName, factory) {
  732. var templates = UIElementRenderingTemplateManager.renderingTemplatesByUIElement.getOrAddWithFactory(uiElType, function () { return new BABYLON.StringDictionary(); });
  733. if (templates.contains(templateName)) {
  734. templates[templateName] = factory;
  735. }
  736. else {
  737. templates.add(templateName, factory);
  738. }
  739. };
  740. Object.defineProperty(UIElementRenderingTemplateManager, "DefaultTemplateName", {
  741. get: function () {
  742. return UIElementRenderingTemplateManager._defaultTemplateName;
  743. },
  744. set: function (value) {
  745. UIElementRenderingTemplateManager._defaultTemplateName = value;
  746. },
  747. enumerable: true,
  748. configurable: true
  749. });
  750. UIElementRenderingTemplateManager.renderingTemplatesByUIElement = new BABYLON.StringDictionary();
  751. UIElementRenderingTemplateManager._defaultTemplateName = "Default";
  752. return UIElementRenderingTemplateManager;
  753. }());
  754. BABYLON.UIElementRenderingTemplateManager = UIElementRenderingTemplateManager;
  755. var UIElementRenderingTemplateBase = (function () {
  756. function UIElementRenderingTemplateBase() {
  757. }
  758. UIElementRenderingTemplateBase.prototype.attach = function (owner) {
  759. this._owner = owner;
  760. };
  761. UIElementRenderingTemplateBase.prototype.detach = function () {
  762. };
  763. Object.defineProperty(UIElementRenderingTemplateBase.prototype, "owner", {
  764. get: function () {
  765. return this._owner;
  766. },
  767. enumerable: true,
  768. configurable: true
  769. });
  770. return UIElementRenderingTemplateBase;
  771. }());
  772. BABYLON.UIElementRenderingTemplateBase = UIElementRenderingTemplateBase;
  773. function registerWindowRenderingTemplate(uiElType, templateName, factory) {
  774. return function () {
  775. UIElementRenderingTemplateManager.registerRenderingTemplate(uiElType, templateName, factory);
  776. };
  777. }
  778. BABYLON.registerWindowRenderingTemplate = registerWindowRenderingTemplate;
  779. })(BABYLON || (BABYLON = {}));