blob: 052e76e4b3f2ee363a050b7eb65a53e2c75a7e17 [file] [log] [blame]
function IImageElement(data, animationItem,parentContainer,globalData){
this.animationItem = animationItem;
this.assetData = this.animationItem.getAssetData(data.id);
this.path = this.animationItem.getPath();
this.parent.constructor.call(this,data, animationItem,parentContainer,globalData);
}
createElement(BaseElement, IImageElement);
IImageElement.prototype.createElements = function(){
var self = this;
var imageLoaded = function(){
self.image.setAttributeNS('http://www.w3.org/1999/xlink','href',self.path+self.assetData.p);
self.maskedElement = self.image;
self.animationItem.elementLoaded();
};
var img = new Image();
img.addEventListener('load', imageLoaded, false);
img.addEventListener('error', imageLoaded, false);
img.src = this.path+this.assetData.p;
this.parent.createElements.call(this);
this.image = document.createElementNS(svgNS,'image');
this.image.setAttribute('width',this.assetData.w+"px");
this.image.setAttribute('height',this.assetData.h+"px");
this.layerElement.appendChild(this.image);
};
IImageElement.prototype.hide = function(){
if(!this.hidden){
this.image.setAttribute('opacity','0');
this.hidden = true;
}
};
IImageElement.prototype.renderFrame = function(num,parentMatrix){
var renderParent = this.parent.renderFrame.call(this,num,parentMatrix);
if(renderParent===false){
this.hide();
return;
}
if(this.hidden){
this.lastData.o = -1;
this.hidden = false;
this.image.setAttribute('opacity', '1');
}
if(!this.data.hasMask){
if(!this.renderedFrames[this.globalData.frameNum]){
this.renderedFrames[this.globalData.frameNum] = {
tr: 'matrix('+this.finalTransform.mat.props.join(',')+')',
o: this.finalTransform.opacity
};
}
var renderedFrameData = this.renderedFrames[this.globalData.frameNum];
if(this.lastData.tr != renderedFrameData.tr){
this.lastData.tr = renderedFrameData.tr;
this.image.setAttribute('transform',renderedFrameData.tr);
}
if(this.lastData.o !== renderedFrameData.o){
this.lastData.o = renderedFrameData.o;
this.image.setAttribute('opacity',renderedFrameData.o);
}
}
};