Files
konva/src/shapes/Ellipse.js
Лаврёнов Антон eb16e29197 only lint errors fixes
2014-02-27 08:49:18 +08:00

131 lines
3.4 KiB
JavaScript

(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 {Object} config.radius defines x and y radius
* @@ShapeParams
* @@NodeParams
* @example
* var ellipse = new Kinetic.Ellipse({<br>
* radius : {<br>
* x : 50,<br>
* y : 50<br>
* },<br>
* fill: 'red'<br>
* });
*/
Kinetic.Ellipse = function(config) {
this.___init(config);
};
Kinetic.Ellipse.prototype = {
___init: function(config) {
// call super constructor
Kinetic.Shape.call(this, config);
this.className = ELLIPSE;
this.sceneFunc(this._sceneFunc);
},
_sceneFunc: function(context) {
var r = this.getRadius(),
rx = r.x,
ry = r.y;
context.beginPath();
context.save();
if(rx !== ry) {
context.scale(1, ry / rx);
}
context.arc(0, 0, rx, 0, PIx2, false);
context.restore();
context.closePath();
context.fillStrokeShape(this);
},
// implements Shape.prototype.getWidth()
getWidth: function() {
return this.getRadius().x * 2;
},
// implements Shape.prototype.getHeight()
getHeight: function() {
return this.getRadius().y * 2;
},
// implements Shape.prototype.setWidth()
setWidth: function(width) {
Kinetic.Node.prototype.setWidth.call(this, width);
this.setRadius({
x: width / 2
});
},
// implements Shape.prototype.setHeight()
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.addComponentsGetterSetter(Kinetic.Ellipse, 'radius', ['x', 'y']);
/**
* get/set radius
* @name radius
* @method
* @memberof Kinetic.Ellipse.prototype
* @param {Object} radius
* @param {Number} radius.x
* @param {Number} radius.y
* @returns {Object}
* @example
* // get radius<br>
* var radius = ellipse.radius();<br><br>
*
* // set radius<br>
* ellipse.radius({<br>
* x: 200,<br>
* y: 100<br>
* });
*/
Kinetic.Factory.addGetterSetter(Kinetic.Ellipse, 'radiusX', 0);
/**
* get/set radius x
* @name radiusX
* @method
* @memberof Kinetic.Ellipse.prototype
* @param {Number} x
* @returns {Number}
* @example
* // get radius x<br>
* var radiusX = ellipse.radiusX();<br><br>
*
* // set radius x<br>
* ellipse.radiusX(200);
*/
Kinetic.Factory.addGetterSetter(Kinetic.Ellipse, 'radiusY', 0);
/**
* get/set radius y
* @name radiusY
* @method
* @memberof Kinetic.Ellipse.prototype
* @param {Number} y
* @returns {Number}
* @example
* // get radius y<br>
* var radiusY = ellipse.radiusY();<br><br>
*
* // set radius y<br>
* ellipse.radiusY(200);
*/
Kinetic.Collection.mapMethods(Kinetic.Ellipse);
})();