2013-06-06 22:07:53 -07:00
|
|
|
(function() {
|
|
|
|
|
// the 0.0001 offset fixes a bug in Chrome 27
|
|
|
|
|
var PIx2 = (Math.PI * 2) - 0.0001,
|
|
|
|
|
ELLIPSE = 'Ellipse';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Ellipse constructor
|
|
|
|
|
* @constructor
|
|
|
|
|
* @augments Kinetic.Shape
|
|
|
|
|
* @param {Object} config
|
|
|
|
|
* @param {Number|Array|Object} config.radius defines x and y radius
|
2013-07-28 17:28:56 -07:00
|
|
|
* @@ShapeParams
|
|
|
|
|
* @@NodeParams
|
2013-06-06 22:07:53 -07:00
|
|
|
*/
|
|
|
|
|
Kinetic.Ellipse = function(config) {
|
2013-07-22 21:41:41 -07:00
|
|
|
this.___init(config);
|
2013-06-06 22:07:53 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Kinetic.Ellipse.prototype = {
|
2013-07-22 21:41:41 -07:00
|
|
|
___init: function(config) {
|
2013-06-06 22:07:53 -07:00
|
|
|
// call super constructor
|
|
|
|
|
Kinetic.Shape.call(this, config);
|
|
|
|
|
this.className = ELLIPSE;
|
|
|
|
|
},
|
2013-08-31 21:49:18 -07:00
|
|
|
drawFunc: function(context) {
|
2013-09-07 20:55:03 -07:00
|
|
|
var r = this.getRadius();
|
2013-08-31 21:49:18 -07:00
|
|
|
|
2013-09-02 21:16:26 -07:00
|
|
|
context.beginPath();
|
|
|
|
|
context.save();
|
2013-06-06 22:07:53 -07:00
|
|
|
if(r.x !== r.y) {
|
2013-09-02 21:16:26 -07:00
|
|
|
context.scale(1, r.y / r.x);
|
2013-06-06 22:07:53 -07:00
|
|
|
}
|
2013-09-02 21:16:26 -07:00
|
|
|
context.arc(0, 0, r.x, 0, PIx2, false);
|
|
|
|
|
context.restore();
|
|
|
|
|
context.closePath();
|
2013-09-02 11:09:30 -07:00
|
|
|
context.fillStrokeShape(this);
|
2013-06-06 22:07:53 -07:00
|
|
|
},
|
|
|
|
|
getWidth: function() {
|
|
|
|
|
return this.getRadius().x * 2;
|
|
|
|
|
},
|
|
|
|
|
getHeight: function() {
|
|
|
|
|
return this.getRadius().y * 2;
|
|
|
|
|
},
|
|
|
|
|
setWidth: function(width) {
|
|
|
|
|
Kinetic.Node.prototype.setWidth.call(this, width);
|
|
|
|
|
this.setRadius({
|
|
|
|
|
x: width / 2
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
setHeight: function(height) {
|
|
|
|
|
Kinetic.Node.prototype.setHeight.call(this, height);
|
|
|
|
|
this.setRadius({
|
|
|
|
|
y: height / 2
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
Kinetic.Util.extend(Kinetic.Ellipse, Kinetic.Shape);
|
|
|
|
|
|
|
|
|
|
// add getters setters
|
2013-08-10 21:11:34 -07:00
|
|
|
Kinetic.Factory.addPointGetterSetter(Kinetic.Ellipse, 'radius', 0);
|
2013-06-06 22:07:53 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* set radius
|
|
|
|
|
* @name setRadius
|
|
|
|
|
* @methodOf Kinetic.Ellipse.prototype
|
|
|
|
|
* @param {Object|Array} radius
|
|
|
|
|
* radius can be a number, in which the ellipse becomes a circle,
|
|
|
|
|
* it can be an object with an x and y component, or it
|
|
|
|
|
* can be an array in which the first element is the x component
|
|
|
|
|
* and the second element is the y component. The x component
|
|
|
|
|
* defines the horizontal radius and the y component
|
|
|
|
|
* defines the vertical radius
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* get radius
|
|
|
|
|
* @name getRadius
|
|
|
|
|
* @methodOf Kinetic.Ellipse.prototype
|
|
|
|
|
*/
|
|
|
|
|
})();
|