container.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = Object.setPrototypeOf ||
  4. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  6. return function (d, b) {
  7. extendStatics(d, b);
  8. function __() { this.constructor = d; }
  9. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10. };
  11. })();
  12. var BABYLON;
  13. (function (BABYLON) {
  14. var GUI;
  15. (function (GUI) {
  16. var Container = (function (_super) {
  17. __extends(Container, _super);
  18. function Container(name) {
  19. var _this = _super.call(this, name) || this;
  20. _this.name = name;
  21. _this._children = new Array();
  22. return _this;
  23. }
  24. Container.prototype.addControl = function (control) {
  25. var index = this._children.indexOf(control);
  26. if (index !== -1) {
  27. return this;
  28. }
  29. control._setRoot(this);
  30. this._reOrderControl(control);
  31. this._markAsDirty();
  32. return this;
  33. };
  34. Container.prototype.removeControl = function (control) {
  35. var index = this._children.indexOf(control);
  36. if (index !== -1) {
  37. this._children.splice(index, 1);
  38. }
  39. this._markAsDirty();
  40. return this;
  41. };
  42. Container.prototype._reOrderControl = function (control) {
  43. this.removeControl(control);
  44. for (var index = 0; index < this._children.length; index++) {
  45. if (this._children[index].zIndex > control.zIndex) {
  46. this._children.splice(index, 0, control);
  47. return;
  48. }
  49. }
  50. this._children.push(control);
  51. this._markAsDirty();
  52. };
  53. Container.prototype._draw = function (parentMeasure, context) {
  54. this._currentMeasure = parentMeasure.copy();
  55. context.save();
  56. if (this.font) {
  57. context.font = this.font;
  58. }
  59. if (this.color) {
  60. context.fillStyle = this.color;
  61. }
  62. for (var _i = 0, _a = this._children; _i < _a.length; _i++) {
  63. var child = _a[_i];
  64. child._draw(this._currentMeasure, context);
  65. }
  66. context.restore();
  67. };
  68. return Container;
  69. }(GUI.Control));
  70. GUI.Container = Container;
  71. })(GUI = BABYLON.GUI || (BABYLON.GUI = {}));
  72. })(BABYLON || (BABYLON = {}));
  73. //# sourceMappingURL=container.js.map