2012-03-07 13:45:48 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// Polygon
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
/**
|
|
|
|
* Polygon constructor. Polygons are defined by an array of points
|
|
|
|
* @constructor
|
|
|
|
* @augments Kinetic.Shape
|
|
|
|
* @param {Object} config
|
|
|
|
*/
|
|
|
|
Kinetic.Polygon = function(config) {
|
2012-04-29 03:55:18 +08:00
|
|
|
this.setDefaultAttrs({
|
2012-05-09 13:11:37 +08:00
|
|
|
points: []
|
2012-04-29 03:55:18 +08:00
|
|
|
});
|
2012-04-06 14:48:58 +08:00
|
|
|
|
|
|
|
this.shapeType = "Polygon";
|
2012-03-07 13:45:48 +08:00
|
|
|
config.drawFunc = function() {
|
|
|
|
var context = this.getContext();
|
|
|
|
context.beginPath();
|
2012-04-06 14:48:58 +08:00
|
|
|
context.moveTo(this.attrs.points[0].x, this.attrs.points[0].y);
|
|
|
|
for(var n = 1; n < this.attrs.points.length; n++) {
|
|
|
|
context.lineTo(this.attrs.points[n].x, this.attrs.points[n].y);
|
2012-03-07 13:45:48 +08:00
|
|
|
}
|
|
|
|
context.closePath();
|
2012-05-27 11:34:36 +08:00
|
|
|
this.fill();
|
|
|
|
this.stroke();
|
2012-03-07 13:45:48 +08:00
|
|
|
};
|
|
|
|
// call super constructor
|
|
|
|
Kinetic.Shape.apply(this, [config]);
|
|
|
|
};
|
|
|
|
// extend Shape
|
2012-03-18 05:35:34 +08:00
|
|
|
Kinetic.GlobalObject.extend(Kinetic.Polygon, Kinetic.Shape);
|
2012-06-11 04:07:09 +08:00
|
|
|
|
|
|
|
// add setters and getters
|
2012-06-24 09:09:10 +08:00
|
|
|
Kinetic.GlobalObject.addSettersGetters(Kinetic.Polygon, ['points']);
|
2012-06-11 04:07:09 +08:00
|
|
|
|
2012-06-15 05:56:13 +08:00
|
|
|
/**
|
|
|
|
* set points array
|
|
|
|
* @name setPoints
|
|
|
|
* @methodOf Kinetic.Polygon.prototype
|
|
|
|
* @param {Array} points can be an array of point objects or an array
|
|
|
|
* of Numbers. e.g. [{x:1,y:2},{x:3,y:4}] or [1,2,3,4]
|
|
|
|
*/
|
|
|
|
|
2012-06-11 04:07:09 +08:00
|
|
|
/**
|
|
|
|
* get points array
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name getPoints
|
|
|
|
* @methodOf Kinetic.Polygon.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
*/
|