blob: 1ca5c205d09afc35b429cd742de1bce29eea9103 [file] [log] [blame]
function CVImageElement(data, comp,globalData){
this.assetData = globalData.getAssetData(data.refId);
this.path = globalData.getPath();
this._parent.constructor.call(this,data, comp,globalData);
this.globalData.addPendingElement();
}
createElement(CVBaseElement, CVImageElement);
CVImageElement.prototype.createElements = function(){
var imageLoaded = function(){
this.globalData.elementLoaded();
}.bind(this);
var imageFailed = function(){
this.failed = true;
this.globalData.elementLoaded();
}.bind(this);
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.renderFrame = function(parentMatrix){
if(this.failed){
return;
}
if(this._parent.renderFrame.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);
if(this.firstFrame){
this.firstFrame = false;
}
};
CVImageElement.prototype.destroy = function(){
this.img = null;
this._parent.destroy.call();
};