container3D.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. /**
  8. * Gets the list of child controls
  9. */
  10. protected _children = new Array<Control3D>();
  11. /**
  12. * Creates a new container
  13. * @param name defines the container name
  14. */
  15. constructor(name?: string) {
  16. super(name);
  17. }
  18. /**
  19. * Gets a boolean indicating if the given control is in the children of this control
  20. * @param control defines the control to check
  21. * @returns true if the control is in the child list
  22. */
  23. public containsControl(control: Control3D): boolean {
  24. return this._children.indexOf(control) !== -1;
  25. }
  26. /**
  27. * Adds a control to the children of this control
  28. * @param control defines the control to add
  29. * @returns the current container
  30. */
  31. public addControl(control: Control3D): Container3D {
  32. var index = this._children.indexOf(control);
  33. if (index !== -1) {
  34. return this;
  35. }
  36. control.parent = this;
  37. control._host = this._host;
  38. this._children.push(control);
  39. if (this._host.utilityLayer) {
  40. control._prepareNode(this._host.utilityLayer.utilityLayerScene);
  41. if (control.node) {
  42. control.node.parent = this.node;
  43. }
  44. this._arrangeChildren();
  45. }
  46. return this;
  47. }
  48. /**
  49. * This function will be called everytime a new control is added
  50. */
  51. protected _arrangeChildren() {
  52. }
  53. protected _createNode(scene: Scene): Nullable<TransformNode> {
  54. return new TransformNode("ContainerNode", scene);
  55. }
  56. /**
  57. * Removes the control from the children of this control
  58. * @param control defines the control to remove
  59. * @returns the current container
  60. */
  61. public removeControl(control: Control3D): Container3D {
  62. var index = this._children.indexOf(control);
  63. if (index !== -1) {
  64. this._children.splice(index, 1);
  65. control.parent = null;
  66. }
  67. return this;
  68. }
  69. protected _getTypeName(): string {
  70. return "Container3D";
  71. }
  72. /**
  73. * Releases all associated resources
  74. */
  75. public dispose() {
  76. for (var control of this._children) {
  77. control.dispose();
  78. }
  79. this._children = [];
  80. super.dispose();
  81. }
  82. }
  83. }