2012-12-01 12:04:10 -08:00
|
|
|
(function() {
|
2013-06-06 21:56:40 -07:00
|
|
|
// the 0.0001 offset fixes a bug in Chrome 27
|
|
|
|
var PIx2 = (Math.PI * 2) - 0.0001,
|
2013-06-01 22:17:18 -07:00
|
|
|
CIRCLE = 'Circle';
|
|
|
|
|
2012-12-01 12:04:10 -08:00
|
|
|
/**
|
|
|
|
* Circle constructor
|
|
|
|
* @constructor
|
2013-05-16 00:28:49 -07:00
|
|
|
* @memberof Kinetic
|
2012-12-01 12:04:10 -08:00
|
|
|
* @augments Kinetic.Shape
|
|
|
|
* @param {Object} config
|
2012-12-22 23:08:03 -08:00
|
|
|
* @param {Number} config.radius
|
2013-06-01 10:27:44 -07:00
|
|
|
* @@shapeParams
|
|
|
|
* @@nodeParams
|
2013-05-17 15:09:57 -07:00
|
|
|
* @example
|
|
|
|
* // create simple circle
|
|
|
|
* var circle = new Kinetic.Circle({<br>
|
2013-05-17 20:56:24 -07:00
|
|
|
* 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
|
|
|
* });
|
2012-12-01 12:04:10 -08:00
|
|
|
*/
|
|
|
|
Kinetic.Circle = function(config) {
|
2013-07-22 21:41:41 -07:00
|
|
|
this.___init(config);
|
2012-12-01 12:04:10 -08:00
|
|
|
};
|
2012-08-25 23:56:39 -07:00
|
|
|
|
2012-12-01 12:04:10 -08:00
|
|
|
Kinetic.Circle.prototype = {
|
2013-07-22 21:41:41 -07:00
|
|
|
___init: function(config) {
|
2012-12-01 12:04:10 -08:00
|
|
|
// call super constructor
|
|
|
|
Kinetic.Shape.call(this, config);
|
2013-06-01 22:17:18 -07:00
|
|
|
this.className = CIRCLE;
|
2012-12-01 12:04:10 -08:00
|
|
|
},
|
2012-12-09 09:52:33 -08:00
|
|
|
drawFunc: function(canvas) {
|
2013-06-01 22:17:18 -07:00
|
|
|
var context = canvas.getContext();
|
|
|
|
|
2012-12-01 12:04:10 -08:00
|
|
|
context.beginPath();
|
2013-06-06 21:56:40 -07:00
|
|
|
context.arc(0, 0, this.getRadius(), 0, PIx2, false);
|
2012-12-01 12:04:10 -08:00
|
|
|
context.closePath();
|
2012-12-09 09:52:33 -08:00
|
|
|
canvas.fillStroke(this);
|
2012-12-01 12:04:10 -08:00
|
|
|
},
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
2013-05-07 23:51:02 -07:00
|
|
|
Kinetic.Util.extend(Kinetic.Circle, Kinetic.Shape);
|
2012-08-25 23:56:39 -07:00
|
|
|
|
2012-12-01 12:04:10 -08:00
|
|
|
// add getters setters
|
2013-03-15 08:33:05 -07:00
|
|
|
Kinetic.Node.addGetterSetter(Kinetic.Circle, 'radius', 0);
|
2012-08-25 23:56:39 -07:00
|
|
|
|
2012-12-01 12:04:10 -08:00
|
|
|
/**
|
|
|
|
* set radius
|
2013-05-16 00:28:49 -07:00
|
|
|
* @method
|
|
|
|
* @memberof Kinetic.Circle.prototype
|
2012-12-01 12:04:10 -08:00
|
|
|
* @param {Number} radius
|
|
|
|
*/
|
2012-08-25 23:56:39 -07:00
|
|
|
|
2012-12-01 12:04:10 -08:00
|
|
|
/**
|
|
|
|
* get radius
|
2013-05-16 00:28:49 -07:00
|
|
|
* @method
|
|
|
|
* @memberof Kinetic.Circle.prototype
|
2012-12-01 12:04:10 -08:00
|
|
|
*/
|
|
|
|
})();
|