blob: 222f8f49d03529b7bf3070d184684e98e70ffb5e [file] [log] [blame]
function CVImageElement(data,globalData){
this.animationItem = globalData.renderer.animationItem;
this.assetData = this.animationItem.getAssetData(data.id);
this.path = this.animationItem.getPath();
this.parent.constructor.call(this,data,globalData);
this.animationItem.pendingElements += 1;
}
createElement(CVBaseElement, CVImageElement);
CVImageElement.prototype.createElements = function(){
var self = this;
var imageLoaded = function(){
self.animationItem.elementLoaded();
};
var imageFailed = function(){
//console.log('imageFailed');
self.failed = true;
self.animationItem.elementLoaded();
};
this.img = new Image();
this.img.addEventListener('load', imageLoaded, false);
this.img.addEventListener('error', imageFailed, false);
this.img.src = this.path+this.assetData.p;
this.parent.createElements.call(this);
};
CVImageElement.prototype.draw = function(parentMatrix){
if(this.failed){
return;
}
if(this.parent.draw.call(this,parentMatrix)===false){
return;
}
var ctx = this.canvasContext;
this.globalData.renderer.save();
var finalMat = this.finalTransform.mat.props;
this.globalData.renderer.ctxTransform(finalMat);
this.globalData.renderer.ctxOpacity(this.finalTransform.opacity);
ctx.drawImage(this.img,0,0);
this.globalData.renderer.restore(this.data.hasMask);
};
CVImageElement.prototype.destroy = function(){
this.img = null;
this.animationItem = null;
this.parent.destroy.call();
};