2010-10-14 21:42:39 +00:00
|
|
|
(function() {
|
2010-07-24 05:03:28 +00:00
|
|
|
|
|
|
|
|
var fabric = this.fabric || (this.fabric = { });
|
|
|
|
|
|
2010-10-14 21:42:39 +00:00
|
|
|
if (fabric.Triangle) {
|
|
|
|
|
fabric.warn('fabric.Triangle is already defined');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-07-24 05:03:28 +00:00
|
|
|
|
2010-10-14 21:42:39 +00:00
|
|
|
/**
|
|
|
|
|
* @class Triangle
|
|
|
|
|
* @extends fabric.Object
|
|
|
|
|
*/
|
|
|
|
|
fabric.Triangle = fabric.util.createClass(fabric.Object, /** @scope fabric.Triangle.prototype */ {
|
2010-07-24 05:03:28 +00:00
|
|
|
|
2010-10-14 21:42:39 +00:00
|
|
|
/** @property */
|
2010-07-24 05:03:28 +00:00
|
|
|
type: 'triangle',
|
|
|
|
|
|
|
|
|
|
/**
|
2010-10-14 21:42:39 +00:00
|
|
|
* Constructor
|
2010-07-24 05:03:28 +00:00
|
|
|
* @method initialize
|
|
|
|
|
* @param options {Object} options object
|
|
|
|
|
* @return {Object} thisArg
|
|
|
|
|
*/
|
|
|
|
|
initialize: function(options) {
|
|
|
|
|
options = options || { };
|
|
|
|
|
|
|
|
|
|
this.callSuper('initialize', options);
|
|
|
|
|
|
|
|
|
|
this.set('width', options.width || 100)
|
|
|
|
|
.set('height', options.height || 100);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @private
|
|
|
|
|
* @method _render
|
2010-10-14 21:42:39 +00:00
|
|
|
* @param ctx {CanvasRenderingContext2D} Context to render on
|
2010-07-24 05:03:28 +00:00
|
|
|
*/
|
2010-08-02 18:50:07 +00:00
|
|
|
_render: function(ctx) {
|
|
|
|
|
var widthBy2 = this.width / 2,
|
|
|
|
|
heightBy2 = this.height / 2;
|
2010-07-24 05:03:28 +00:00
|
|
|
|
2010-08-02 18:50:07 +00:00
|
|
|
ctx.beginPath();
|
|
|
|
|
ctx.moveTo(-widthBy2, heightBy2);
|
|
|
|
|
ctx.lineTo(0, -heightBy2);
|
|
|
|
|
ctx.lineTo(widthBy2, heightBy2);
|
|
|
|
|
ctx.closePath();
|
2010-07-24 05:03:28 +00:00
|
|
|
|
|
|
|
|
if (this.fill) {
|
|
|
|
|
ctx.fill();
|
|
|
|
|
}
|
|
|
|
|
if (this.stroke) {
|
|
|
|
|
ctx.stroke();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns complexity of an instance
|
|
|
|
|
* @method complexity
|
|
|
|
|
* @return {Number} complexity of this instance
|
|
|
|
|
*/
|
|
|
|
|
complexity: function() {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
2010-10-14 21:42:39 +00:00
|
|
|
* Returns fabric.Triangle instance from an object representation
|
2010-07-24 05:03:28 +00:00
|
|
|
* @static
|
|
|
|
|
* @method Canvas.Trangle.fromObject
|
|
|
|
|
* @param object {Object} object to create an instance from
|
|
|
|
|
* @return {Object} instance of Canvas.Triangle
|
|
|
|
|
*/
|
|
|
|
|
fabric.Triangle.fromObject = function(object) {
|
|
|
|
|
return new fabric.Triangle(object);
|
|
|
|
|
};
|
|
|
|
|
})();
|