ellipse.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. module BABYLON.GUI {
  3. export class Ellipse extends Container {
  4. private _thickness = 1;
  5. public get thickness(): number {
  6. return this._thickness;
  7. }
  8. public set thickness(value: number) {
  9. if (this._thickness === value) {
  10. return;
  11. }
  12. this._thickness = value;
  13. this._markAsDirty();
  14. }
  15. constructor(public name?: string) {
  16. super(name);
  17. }
  18. protected _localDraw(context: CanvasRenderingContext2D): void {
  19. context.save();
  20. context.beginPath();
  21. context.ellipse(this._currentMeasure.left + this._currentMeasure.width / 2, this._currentMeasure.top + this._currentMeasure.height / 2,
  22. this._currentMeasure.width / 2 - this._thickness / 2, this._currentMeasure.height / 2 - this._thickness / 2, 0, 0, 2 * Math.PI);
  23. context.closePath();
  24. if (this._background) {
  25. context.fillStyle = this._background;
  26. context.fill();
  27. }
  28. if (this._thickness) {
  29. if (this.color) {
  30. context.strokeStyle = this.color;
  31. }
  32. context.lineWidth = this._thickness;
  33. context.stroke();
  34. }
  35. context.restore();
  36. }
  37. protected _additionalProcessing(parentMeasure: Measure, context: CanvasRenderingContext2D): void {
  38. super._additionalProcessing(parentMeasure, context);
  39. this._measureForChildren.width -= 2 * this._thickness;
  40. this._measureForChildren.height -= 2 * this._thickness;
  41. this._measureForChildren.left += this._thickness;
  42. this._measureForChildren.top += this._thickness;
  43. }
  44. protected _clipForChildren(context: CanvasRenderingContext2D) {
  45. context.beginPath();
  46. context.ellipse(this._currentMeasure.left + this._currentMeasure.width / 2, this._currentMeasure.top + this._currentMeasure.height / 2, this._currentMeasure.width / 2, this._currentMeasure.height / 2, 0, 0, 2 * Math.PI);
  47. context.clip();
  48. }
  49. }
  50. }