container3D.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 _children = new Array<Control3D>();
  8. /**
  9. * Creates a new container
  10. * @param name defines the container name
  11. */
  12. constructor(name?: string) {
  13. super(name);
  14. }
  15. /**
  16. * Gets a boolean indicating if the given control is in the children of this control
  17. * @param control defines the control to check
  18. * @returns true if the control is in the child list
  19. */
  20. public containsControl(control: Control3D): boolean {
  21. return this._children.indexOf(control) !== -1;
  22. }
  23. /**
  24. * Adds a control to the children of this control
  25. * @param control defines the control to add
  26. * @returns the current container
  27. */
  28. public addControl(control: Control3D): Container3D {
  29. var index = this._children.indexOf(control);
  30. if (index !== -1) {
  31. return this;
  32. }
  33. control.parent = this;
  34. control._host = this._host;
  35. if (this._host.utilityLayer) {
  36. control.prepareMesh(this._host.utilityLayer.utilityLayerScene);
  37. }
  38. return this;
  39. }
  40. /**
  41. * Removes the control from the children of this control
  42. * @param control defines the control to remove
  43. * @returns the current container
  44. */
  45. public removeControl(control: Control3D): Container3D {
  46. var index = this._children.indexOf(control);
  47. if (index !== -1) {
  48. this._children.splice(index, 1);
  49. control.parent = null;
  50. }
  51. return this;
  52. }
  53. protected _getTypeName(): string {
  54. return "Container3D";
  55. }
  56. /**
  57. * Releases all associated resources
  58. */
  59. public dispose() {
  60. for (var control of this._children) {
  61. control.dispose();
  62. }
  63. this._children = [];
  64. super.dispose();
  65. }
  66. }
  67. }