container3D.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /// <reference path="../../../../dist/preview release/babylon.d.ts"/>
  2. module BABYLON.GUI {
  3. /**
  4. * Class used to create containers for controls
  5. */
  6. export class Container3D extends Control3D {
  7. private _blockLayout = false;
  8. /**
  9. * Gets the list of child controls
  10. */
  11. protected _children = new Array<Control3D>();
  12. /**
  13. * Gets the list of child controls
  14. */
  15. public get children(): Array<Control3D> {
  16. return this._children;
  17. }
  18. /**
  19. * Gets or sets a boolean indicating if the layout must be blocked (default is false).
  20. * This is helpful to optimize layout operation when adding multiple children in a row
  21. */
  22. public get blockLayout(): boolean {
  23. return this._blockLayout;
  24. }
  25. public set blockLayout(value: boolean) {
  26. if (this._blockLayout === value) {
  27. return;
  28. }
  29. this._blockLayout = value;
  30. if (!this._blockLayout) {
  31. this._arrangeChildren();
  32. }
  33. }
  34. /**
  35. * Creates a new container
  36. * @param name defines the container name
  37. */
  38. constructor(name?: string) {
  39. super(name);
  40. }
  41. /**
  42. * Gets a boolean indicating if the given control is in the children of this control
  43. * @param control defines the control to check
  44. * @returns true if the control is in the child list
  45. */
  46. public containsControl(control: Control3D): boolean {
  47. return this._children.indexOf(control) !== -1;
  48. }
  49. /**
  50. * Adds a control to the children of this control
  51. * @param control defines the control to add
  52. * @returns the current container
  53. */
  54. public addControl(control: Control3D): Container3D {
  55. var index = this._children.indexOf(control);
  56. if (index !== -1) {
  57. return this;
  58. }
  59. control.parent = this;
  60. control._host = this._host;
  61. this._children.push(control);
  62. if (this._host.utilityLayer) {
  63. control._prepareNode(this._host.utilityLayer.utilityLayerScene);
  64. if (control.node) {
  65. control.node.parent = this.node;
  66. }
  67. if (!this.blockLayout) {
  68. this._arrangeChildren();
  69. }
  70. }
  71. return this;
  72. }
  73. /**
  74. * This function will be called everytime a new control is added
  75. */
  76. protected _arrangeChildren() {
  77. }
  78. protected _createNode(scene: Scene): Nullable<TransformNode> {
  79. return new TransformNode("ContainerNode", scene);
  80. }
  81. /**
  82. * Removes a control from the children of this control
  83. * @param control defines the control to remove
  84. * @returns the current container
  85. */
  86. public removeControl(control: Control3D): Container3D {
  87. var index = this._children.indexOf(control);
  88. if (index !== -1) {
  89. this._children.splice(index, 1);
  90. control.parent = null;
  91. control._disposeNode();
  92. }
  93. return this;
  94. }
  95. protected _getTypeName(): string {
  96. return "Container3D";
  97. }
  98. /**
  99. * Releases all associated resources
  100. */
  101. public dispose() {
  102. for (var control of this._children) {
  103. control.dispose();
  104. }
  105. this._children = [];
  106. super.dispose();
  107. }
  108. /** Control rotation will remain unchanged */
  109. public static readonly UNSET_ORIENTATION = 0;
  110. /** Control will rotate to make it look at sphere central axis */
  111. public static readonly FACEORIGIN_ORIENTATION = 1;
  112. /** Control will rotate to make it look back at sphere central axis */
  113. public static readonly FACEORIGINREVERSED_ORIENTATION = 2;
  114. /** Control will rotate to look at z axis (0, 0, 1) */
  115. public static readonly FACEFORWARD_ORIENTATION = 3;
  116. /** Control will rotate to look at negative z axis (0, 0, -1) */
  117. public static readonly FACEFORWARDREVERSED_ORIENTATION = 4;
  118. }
  119. }