blob: 8b2893231b20ba4d68dec05ec195fb63fa71eec1 [file] [log] [blame]
function BaseElement(){
};
BaseElement.prototype.checkMasks = function(){
if(!this.data.hasMask){
return false;
}
var i = 0, len = this.data.masksProperties.length;
while(i<len) {
if((this.data.masksProperties[i].mode !== 'n' && this.data.masksProperties[i].cl !== false)) {
return true;
}
i += 1;
}
return false;
}
BaseElement.prototype.checkParenting = function(){
if(this.data.parent !== undefined){
this.comp.buildElementParenting(this, this.data.parent);
}
}
BaseElement.prototype.prepareFrame = function(num){
if(this.data.ip - this.data.st <= num && this.data.op - this.data.st > num)
{
if(this.isVisible !== true){
this.elemMdf = true;
this.globalData.mdf = true;
this.isVisible = true;
this.firstFrame = true;
if(this.data.hasMask){
this.maskManager.firstFrame = true;
}
}
}else{
if(this.isVisible !== false){
this.elemMdf = true;
this.globalData.mdf = true;
this.isVisible = false;
}
}
var i, len = this.dynamicProperties.length;
for(i=0;i<len;i+=1){
if(this.isVisible || (this._isParent && this.dynamicProperties[i].type === 'transform')){
this.dynamicProperties[i].getValue();
if(this.dynamicProperties[i].mdf){
this.elemMdf = true;
this.globalData.mdf = true;
}
}
}
if(this.data.hasMask && this.isVisible){
this.maskManager.prepareFrame(num*this.data.sr);
}
/* TODO check this
if(this.data.sy){
if(this.data.sy[0].renderedData[num]){
if(this.data.sy[0].renderedData[num].c){
this.feFlood.setAttribute('flood-color','rgb('+Math.round(this.data.sy[0].renderedData[num].c[0])+','+Math.round(this.data.sy[0].renderedData[num].c[1])+','+Math.round(this.data.sy[0].renderedData[num].c[2])+')');
}
if(this.data.sy[0].renderedData[num].s){
this.feMorph.setAttribute('radius',this.data.sy[0].renderedData[num].s);
}
}
}
*/
this.currentFrameNum = num*this.data.sr;
return this.isVisible;
};
BaseElement.prototype.localToGlobal = function(pt, extraTransforms){
var transforms = [];
var i, len;
transforms.push(this.finalTransform);
if(this.hierarchy){
i = 0;
len = this.hierarchy.length;
while(i < len) {
transforms.push(this.hierarchy[i].finalTransform);
i += 1;
}
}
var flag = true;
var comp = this.comp;
while(flag){
if(comp){
transforms.push(comp.finalTransform);
if(comp.hierarchy){
i = 0;
len = comp.hierarchy.length;
while(i < len) {
transforms.push(comp.hierarchy[i].finalTransform);
i += 1;
}
}
comp = comp.comp;
} else {
flag = false;
}
}
if(extraTransforms){
len = extraTransforms.length;
for(i = len - 1;i >= 0; i -= 1){
pt = extraTransforms[i].mProps.v.applyToPointArray(pt[0],pt[1],0,2);
}
}
len = transforms.length;
for(i=0;i<len;i+=1){
pt = transforms[i].mProp.v.applyToPointArray(pt[0],pt[1],0,2);
}
return pt;
};
BaseElement.prototype.globalToLocal = function(pt, extraTransforms){
var transforms = [];
var i, len;
if(this.hierarchy){
i = this.hierarchy.length - 1;
while(i >= 0) {
transforms.push(this.hierarchy[i].finalTransform);
i -= 1;
}
}
transforms.push(this.finalTransform);
var flag = true;
var comp = this.comp;
while(flag){
if(comp){
transforms.splice(0,0,comp.finalTransform);
if(comp.hierarchy){
len = comp.hierarchy.length;
i = 0;
while(i < len) {
transforms.splice(0,0,comp.hierarchy[i].finalTransform);
i += 1;
}
}
comp = comp.comp;
} else {
flag = false;
}
}
len = transforms.length;
for(i=0;i<len;i+=1){
pt = transforms[i].mProp.v.inversePoint(pt);
}
if(extraTransforms){
len = extraTransforms.length;
for(i = 0;i < len; i += 1){
pt = extraTransforms[i].mProps.v.inversePoint(pt);
}
}
return pt;
};
BaseElement.prototype.initExpressions = function(){
this.layerInterface = LayerExpressionInterface(this);
if(this.data.hasMask){
this.layerInterface.registerMaskInterface(this.maskManager);
}
var effectsInterface = EffectsExpressionInterface.createEffectsInterface(this,this.layerInterface);
this.layerInterface.registerEffectsInterface(effectsInterface);
if(this.data.ty === 0 || this.data.xt){
this.compInterface = CompExpressionInterface(this);
} else if(this.data.ty === 4){
this.layerInterface.shapeInterface = ShapeExpressionInterface.createShapeInterface(this.shapesData,this.itemsData,this.layerInterface);
} else if(this.data.ty === 5){
this.layerInterface.textInterface = TextExpressionInterface(this);
}
}
BaseElement.prototype.setBlendMode = function(){
var blendModeValue = '';
switch(this.data.bm){
case 1:
blendModeValue = 'multiply';
break;
case 2:
blendModeValue = 'screen';
break;
case 3:
blendModeValue = 'overlay';
break;
case 4:
blendModeValue = 'darken';
break;
case 5:
blendModeValue = 'lighten';
break;
case 6:
blendModeValue = 'color-dodge';
break;
case 7:
blendModeValue = 'color-burn';
break;
case 8:
blendModeValue = 'hard-light';
break;
case 9:
blendModeValue = 'soft-light';
break;
case 10:
blendModeValue = 'difference';
break;
case 11:
blendModeValue = 'exclusion';
break;
case 12:
blendModeValue = 'hue';
break;
case 13:
blendModeValue = 'saturation';
break;
case 14:
blendModeValue = 'color';
break;
case 15:
blendModeValue = 'luminosity';
break;
}
var elem = this.baseElement || this.layerElement;
elem.style['mix-blend-mode'] = blendModeValue;
}
BaseElement.prototype.init = function(){
if(!this.data.sr){
this.data.sr = 1;
}
this.dynamicProperties = [];
if(this.data.ef){
this.effects = new EffectsManager(this.data,this,this.dynamicProperties);
//this.effect = this.effectsManager.bind(this.effectsManager);
}
//this.elemInterface = buildLayerExpressionInterface(this);
this.hidden = false;
this.firstFrame = true;
this.isVisible = false;
this._isParent = false;
this.currentFrameNum = -99999;
this.lastNum = -99999;
if(this.data.ks){
this.finalTransform = {
mProp: PropertyFactory.getProp(this,this.data.ks,2,null,this.dynamicProperties),
matMdf: false,
opMdf: false,
mat: new Matrix(),
opacity: 1
};
if(this.data.ao){
this.finalTransform.mProp.autoOriented = true;
}
this.finalTransform.op = this.finalTransform.mProp.o;
this.transform = this.finalTransform.mProp;
if(this.data.ty !== 11){
this.createElements();
}
if(this.data.hasMask){
this.addMasks(this.data);
}
}
this.elemMdf = false;
};
BaseElement.prototype.getType = function(){
return this.type;
};
BaseElement.prototype.resetHierarchy = function(){
if(!this.hierarchy){
this.hierarchy = [];
}else{
this.hierarchy.length = 0;
}
};
BaseElement.prototype.getHierarchy = function(){
if(!this.hierarchy){
this.hierarchy = [];
}
return this.hierarchy;
};
BaseElement.prototype.setHierarchy = function(hierarchy){
this.hierarchy = hierarchy;
};
BaseElement.prototype.getLayerSize = function(){
if(this.data.ty === 5){
return {w:this.data.textData.width,h:this.data.textData.height};
}else{
return {w:this.data.width,h:this.data.height};
}
};
BaseElement.prototype.hide = function(){
};
BaseElement.prototype.mHelper = new Matrix();