contentControl.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. module BABYLON.GUI {
  3. export class ContentControl extends Control {
  4. private _child: Control;
  5. protected _measureForChild = Measure.Empty();
  6. public get child(): Control {
  7. return this._child;
  8. }
  9. public set child(control: Control) {
  10. if (this._child === control) {
  11. return;
  12. }
  13. this._child = control;
  14. control._link(this._root, this._host);
  15. this._markAsDirty();
  16. }
  17. constructor(public name: string) {
  18. super(name);
  19. }
  20. protected _localDraw(context: CanvasRenderingContext2D): void {
  21. // Implemented by child to be injected inside main draw
  22. }
  23. public _draw(parentMeasure: Measure, context: CanvasRenderingContext2D): void {
  24. context.save();
  25. super._processMeasures(parentMeasure, context);
  26. this.applyStates(context);
  27. this._localDraw(context);
  28. if (this._child) {
  29. this._child._draw(this._measureForChild, context);
  30. }
  31. context.restore();
  32. }
  33. protected _additionalProcessing(parentMeasure: Measure, context: CanvasRenderingContext2D): void {
  34. super._additionalProcessing(parentMeasure, context);
  35. this._measureForChild.copyFrom(this._currentMeasure);
  36. }
  37. }
  38. }