konva/src/shapes/Rect.js

76 lines
1.6 KiB
JavaScript

///////////////////////////////////////////////////////////////////////
// Rect
///////////////////////////////////////////////////////////////////////
/**
* Rect constructor
* @constructor
* @augments Kinetic.Shape
* @param {Object} config
*/
Kinetic.Rect = function(config) {
this.shapeType = "Rect";
config.drawFunc = function() {
var context = this.getContext();
context.beginPath();
this.applyLineJoin();
context.rect(0, 0, this.width, this.height);
context.closePath();
this.fillStroke();
};
// call super constructor
Kinetic.Shape.apply(this, [config]);
};
/*
* Rect methods
*/
Kinetic.Rect.prototype = {
/**
* set width
* @param {Number} width
*/
setWidth: function(width) {
this.width = width;
},
/**
* get width
*/
getWidth: function() {
return this.width;
},
/**
* set height
* @param {Number} height
*/
setHeight: function(height) {
this.height = height;
},
/**
* get height
*/
getHeight: function() {
return this.height;
},
/**
* set width and height
* @param {Number} width
* @param {Number} height
*/
setSize: function(width, height) {
this.width = width;
this.height = height;
},
/**
* return rect size
*/
getSize: function() {
return {
width: this.width,
height: this.height
};
}
};
// extend Shape
Kinetic.GlobalObject.extend(Kinetic.Rect, Kinetic.Shape);