mirror of
https://github.com/konvajs/konva.git
synced 2026-03-03 16:58:33 +08:00
82 lines
2.3 KiB
JavaScript
82 lines
2.3 KiB
JavaScript
(function() {
|
|
// the 0.0001 offset fixes a bug in Chrome 27
|
|
var PIx2 = (Math.PI * 2) - 0.0001,
|
|
CIRCLE = 'Circle';
|
|
|
|
/**
|
|
* Circle constructor
|
|
* @constructor
|
|
* @memberof Kinetic
|
|
* @augments Kinetic.Shape
|
|
* @param {Object} config
|
|
* @param {Number} config.radius
|
|
* @@shapeParams
|
|
* @@nodeParams
|
|
* @example
|
|
* // create circle
|
|
* var circle = new Kinetic.Circle({<br>
|
|
* radius: 40,<br>
|
|
* fill: 'red',<br>
|
|
* stroke: 'black'<br>
|
|
* strokeWidth: 5<br>
|
|
* });
|
|
*/
|
|
Kinetic.Circle = function(config) {
|
|
this.___init(config);
|
|
};
|
|
|
|
Kinetic.Circle.prototype = {
|
|
___init: function(config) {
|
|
// call super constructor
|
|
Kinetic.Shape.call(this, config);
|
|
this.className = CIRCLE;
|
|
this.sceneFunc(this._sceneFunc);
|
|
},
|
|
_sceneFunc: function(context) {
|
|
context.beginPath();
|
|
context.arc(0, 0, this.getRadius(), 0, PIx2, false);
|
|
context.closePath();
|
|
context.fillStrokeShape(this);
|
|
},
|
|
// implements Shape.prototype.getWidth()
|
|
getWidth: function() {
|
|
return this.getRadius() * 2;
|
|
},
|
|
// implements Shape.prototype.getHeight()
|
|
getHeight: function() {
|
|
return this.getRadius() * 2;
|
|
},
|
|
// implements Shape.prototype.setWidth()
|
|
setWidth: function(width) {
|
|
Kinetic.Node.prototype.setWidth.call(this, width);
|
|
this.setRadius(width / 2);
|
|
},
|
|
// implements Shape.prototype.setHeight()
|
|
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.Factory.addGetterSetter(Kinetic.Circle, 'radius', 0);
|
|
|
|
/**
|
|
* get/set radius
|
|
* @name radius
|
|
* @method
|
|
* @memberof Kinetic.Circle.prototype
|
|
* @param {Number} radius
|
|
* @returns {Number}
|
|
* @example
|
|
* // get radius<br>
|
|
* var radius = circle.radius();<br><br>
|
|
*
|
|
* // set radius<br>
|
|
* circle.radius(10);<br>
|
|
*/
|
|
|
|
Kinetic.Collection.mapMethods(Kinetic.Circle);
|
|
})();
|