blob: ab8e7f081e19d8046938a7d5a8a7dc0ad0fd0cb4 [file] [edit]
function CVImageElement(data,globalData){
this.animationItem = globalData.renderer.animationItem;
this.assets = this.animationItem.getAssets();
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.assets[this.data.assetId].path;
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);
};