Source: core/drawing/engine/vml/vmlEllipse.js

  1. /**
  2. * @fileoverview VML rendering class representing an ellipse.
  3. * @private
  4. */
  5. goog.provide('xrx.vml.Ellipse');
  6. goog.require('xrx.vml.Stylable');
  7. /**
  8. * VML rendering class representing an ellipse.
  9. * @param {HTMLElement} The HTML element.
  10. * @constructor
  11. * @extends xrx.vml.Stylable
  12. * @private
  13. */
  14. xrx.vml.Ellipse = function(element) {
  15. goog.base(this, element);
  16. this.rx_;
  17. this.ry_;
  18. };
  19. goog.inherits(xrx.vml.Ellipse, xrx.vml.Stylable);
  20. /**
  21. * Sets the center point of this ellipse.
  22. * @param {number} cx The X coordinate of the centre point.
  23. * @param {number} cy The Y coordinate of the centre point.
  24. */
  25. xrx.vml.Ellipse.prototype.setCenter = function(cx, cy) {
  26. var offsetX = cx - this.rx_;
  27. var offsetY = cy - this.ry_;
  28. if (cx !== undefined) this.element_.style['left'] = offsetX + 'px';
  29. if (cy !== undefined) this.element_.style['top'] = offsetY + 'px';
  30. };
  31. /**
  32. * Sets the ellipse's major-axis radius.
  33. * @param {number} rx The radius.
  34. */
  35. xrx.vml.Ellipse.prototype.setRadiusX = function(rx) {
  36. this.rx_ = rx;
  37. this.element_.style['width'] = this.rx_ * 2 + 'px';
  38. };
  39. /**
  40. * Sets the ellipse's minor-axis radius.
  41. * @param {number} ry The radius.
  42. */
  43. xrx.vml.Ellipse.prototype.setRadiusY = function(ry) {
  44. this.ry_ = ry;
  45. this.element_.style['height'] = this.ry_ * 2 + 'px';
  46. };
  47. /**
  48. * Draws this ellipse on the canvas.
  49. * @param {number} cx X-coordinate of the ellipse's center point.
  50. * @param {number} cy Y-coordinate of the ellipse's center point.
  51. * @param {number} rx Major-radius of the ellipse.
  52. * @param {number} ry Minor-radius of the ellipse.
  53. * @param {string} fillColor The fill color.
  54. * @param {number} fillOpacity Opacity of the fill color.
  55. * @param {string} strokeColor The stroke color.
  56. * @param {number} strokeWidth The stroke width.
  57. */
  58. xrx.vml.Ellipse.prototype.draw = function(cx, cy, rx, ry, fillColor,
  59. fillOpacity, strokeColor, strokeWidth) {
  60. if (rx !== undefined) this.setRadiusX(rx);
  61. if (ry !== undefined) this.setRadiusY(ry);
  62. this.setCenter(cx, cy);
  63. this.strokeAndFill_(fillColor, fillOpacity, strokeColor, strokeWidth);
  64. };
  65. /**
  66. * Creates a new ellipse.
  67. * @param {xrx.vml.Canvas} canvas The parent canvas object.
  68. */
  69. xrx.vml.Ellipse.create = function(canvas) {
  70. var element = xrx.vml.createElement('oval');
  71. element.style['position'] = 'absolute';
  72. return new xrx.vml.Ellipse(element);
  73. };