mirror of
https://github.com/konvajs/konva.git
synced 2025-04-30 09:41:47 +08:00
85 lines
1.9 KiB
JavaScript
85 lines
1.9 KiB
JavaScript
![]() |
///////////////////////////////////////////////////////////////////////
|
||
|
// Image
|
||
|
///////////////////////////////////////////////////////////////////////
|
||
|
/**
|
||
|
* Image constructor
|
||
|
* @constructor
|
||
|
* @augments Kinetic.Shape
|
||
|
* @param {Object} config
|
||
|
*/
|
||
|
Kinetic.Image = function(config) {
|
||
|
// defaults
|
||
|
if(config.width === undefined) {
|
||
|
config.width = config.image.width;
|
||
|
}
|
||
|
if(config.height === undefined) {
|
||
|
config.height = config.image.height;
|
||
|
}
|
||
|
|
||
|
config.drawFunc = function() {
|
||
|
var canvas = this.getCanvas();
|
||
|
var context = this.getContext();
|
||
|
context.beginPath();
|
||
|
context.rect(0, 0, this.width, this.height);
|
||
|
context.closePath();
|
||
|
this.fillStroke();
|
||
|
context.drawImage(this.image, 0, 0, this.width, this.height);
|
||
|
};
|
||
|
// call super constructor
|
||
|
Kinetic.Shape.apply(this, [config]);
|
||
|
};
|
||
|
/*
|
||
|
* Image methods
|
||
|
*/
|
||
|
Kinetic.Image.prototype = {
|
||
|
/**
|
||
|
* set image
|
||
|
* @param {ImageObject} image
|
||
|
*/
|
||
|
setImage: function(image) {
|
||
|
this.image = image;
|
||
|
},
|
||
|
/**
|
||
|
* get image
|
||
|
*/
|
||
|
getImage: function(image) {
|
||
|
return this.image;
|
||
|
},
|
||
|
/**
|
||
|
* 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;
|
||
|
}
|
||
|
};
|
||
|
// extend Shape
|
||
|
Kinetic.GlobalObject.extend(Kinetic.Image, Kinetic.Shape);
|