2012-11-30 12:15:01 +08:00
|
|
|
(function() {
|
|
|
|
/**
|
|
|
|
* Wedge constructor
|
|
|
|
* @constructor
|
|
|
|
* @augments Kinetic.Shape
|
|
|
|
* @param {Object} config
|
|
|
|
*/
|
|
|
|
Kinetic.Wedge = function(config) {
|
|
|
|
this._initWedge(config);
|
|
|
|
};
|
|
|
|
|
|
|
|
Kinetic.Wedge.prototype = {
|
|
|
|
_initWedge: function(config) {
|
|
|
|
this.setDefaultAttrs({
|
|
|
|
radius: 0,
|
|
|
|
angle: 0,
|
|
|
|
clickwise: true
|
|
|
|
});
|
|
|
|
|
|
|
|
this.shapeType = 'Wedge';
|
|
|
|
|
|
|
|
// call super constructor
|
|
|
|
Kinetic.Shape.call(this, config);
|
|
|
|
this._setDrawFuncs();
|
|
|
|
},
|
2012-12-10 01:52:33 +08:00
|
|
|
drawFunc: function(canvas) {
|
|
|
|
var context = canvas.getContext();
|
2012-11-30 12:15:01 +08:00
|
|
|
context.beginPath();
|
|
|
|
context.arc(0, 0, this.getRadius(), 0, this.getAngle(), this.getClockwise());
|
|
|
|
context.lineTo(0, 0);
|
|
|
|
context.closePath();
|
2012-12-10 01:52:33 +08:00
|
|
|
canvas.fillStroke(this);
|
2012-11-30 12:15:01 +08:00
|
|
|
},
|
|
|
|
setAngleDeg: function(deg) {
|
|
|
|
this.setAngle(Kinetic.Type._degToRad(deg));
|
|
|
|
},
|
|
|
|
getAngleDeg: function() {
|
|
|
|
return Kinetic.Type._radToDeg(this.getAngle());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Kinetic.Global.extend(Kinetic.Wedge, Kinetic.Shape);
|
|
|
|
|
|
|
|
// add getters setters
|
|
|
|
Kinetic.Node.addGettersSetters(Kinetic.Wedge, ['radius', 'angle', 'clockwise']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set radius
|
|
|
|
* @name setRadius
|
|
|
|
* @methodOf Kinetic.Wedge.prototype
|
|
|
|
* @param {Number} radius
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set angle
|
|
|
|
* @name setAngle
|
|
|
|
* @methodOf Kinetic.Wedge.prototype
|
|
|
|
* @param {Number} angle
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set clockwise draw direction. If set to true, the wedge will be drawn clockwise
|
|
|
|
* If set to false, the wedge will be drawn anti-clockwise. The default is true.
|
|
|
|
* @name setClockwise
|
|
|
|
* @methodOf Kinetic.Wedge.prototype
|
|
|
|
* @param {Boolean} clockwise
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get radius
|
|
|
|
* @name getRadius
|
|
|
|
* @methodOf Kinetic.Wedge.prototype
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get angle
|
|
|
|
* @name getAngle
|
|
|
|
* @methodOf Kinetic.Wedge.prototype
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get clockwise
|
|
|
|
* @name getClockwise
|
|
|
|
* @methodOf Kinetic.Wedge.prototype
|
|
|
|
*/
|
|
|
|
})();
|