Files
konva/src/shapes/Ellipse.js

80 lines
2.3 KiB
JavaScript
Raw Normal View History

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) {
this.___init(config);
2013-06-06 22:07:53 -07:00
};
Kinetic.Ellipse.prototype = {
___init: function(config) {
2013-06-06 22:07:53 -07:00
// call super constructor
Kinetic.Shape.call(this, config);
this.className = ELLIPSE;
},
drawFunc: function(context) {
var r = this.getRadius();
context.beginPath();
context.save();
2013-06-06 22:07:53 -07:00
if(r.x !== r.y) {
context.scale(1, r.y / r.x);
2013-06-06 22:07:53 -07:00
}
context.arc(0, 0, r.x, 0, PIx2, false);
context.restore();
context.closePath();
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
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
*/
})();