Files
konva/src/shapes/Circle.js

85 lines
2.2 KiB
JavaScript
Raw Normal View History

(function() {
// the 0.0001 offset fixes a bug in Chrome 27
var PIx2 = (Math.PI * 2) - 0.0001,
CIRCLE = 'Circle';
/**
* Circle constructor
* @constructor
2013-05-16 00:28:49 -07:00
* @memberof Kinetic
* @augments Kinetic.Shape
* @param {Object} config
* @param {Number} config.radius
* @@shapeParams
* @@nodeParams
2013-05-17 15:09:57 -07:00
* @example
* // create simple circle
* var circle = new Kinetic.Circle({<br>
* radius: 40,<br>
2013-05-17 15:09:57 -07:00
* fill: 'red',<br>
* stroke: 'black'<br>
2013-05-17 15:35:21 -07:00
* strokeWidth: 5<br>
* });<br><br>
2013-05-17 15:09:57 -07:00
*
2013-05-17 15:35:21 -07:00
* // create ellipse<br>
2013-05-17 15:09:57 -07:00
* var circle = new Kinetic.Circle({<br>
* radius: 5,<br>
* fill: 'red',<br>
* stroke: 'black'<br>
* strokeWidth: 5,<br>
* scaleX: 2,<br>
2013-05-17 15:35:21 -07:00
* strokeScaleEnabled: false<br>
2013-05-17 15:09:57 -07:00
* });
*/
Kinetic.Circle = function(config) {
this.___init(config);
};
Kinetic.Circle.prototype = {
___init: function(config) {
// call super constructor
Kinetic.Shape.call(this, config);
this.className = CIRCLE;
},
drawFunc: function(canvas) {
var context = canvas.getContext();
context.beginPath();
context.arc(0, 0, this.getRadius(), 0, PIx2, false);
context.closePath();
canvas.fillStroke(this);
},
getWidth: function() {
return this.getRadius() * 2;
},
getHeight: function() {
return this.getRadius() * 2;
},
setWidth: function(width) {
Kinetic.Node.prototype.setWidth.call(this, width);
this.setRadius(width / 2);
},
setHeight: function(height) {
Kinetic.Node.prototype.setHeight.call(this, height);
this.setRadius(height / 2);
}
};
Kinetic.Util.extend(Kinetic.Circle, Kinetic.Shape);
// add getters setters
Kinetic.Node.addGetterSetter(Kinetic.Circle, 'radius', 0);
/**
* set radius
2013-05-16 00:28:49 -07:00
* @method
* @memberof Kinetic.Circle.prototype
* @param {Number} radius
*/
/**
* get radius
2013-05-16 00:28:49 -07:00
* @method
* @memberof Kinetic.Circle.prototype
*/
})();