/*
Abstract:
Biblicoteca de classes e funcoes para funcionalidade
do produto "Crie seu Cartão".
Funcionalidade basica: arrasto de images e criacao de
imagens de texto dinamicos pela junção de imagens de cada letra.
Criação: 03/2002
Autor: Pedro Furlanetto
Empresa: ocarteiro.com
Requistos: DynAPI 2.5.7 impressindivel
*/
zindex=10;
DynList=new Array();
// Adiciona um elemento e retorna seu indice
DynList.add=function (layer) {
DynList[DynList.length]=layer.id;
return(DynList.length-1);
}
DynList.remove=function (index){
//DynList.splice(index,1);
//while(typeof(DynList[index])!='undefined') DynObject.all[DynList[index++]].myDynListIndex-=1;
DynList[index]=-1;
}
// funcao para verificar se um DynLayer esta sobre o outro
function isDynLayerOver(dlayerup,dlayerdown,nomodif)
{
//alert(dlayerdown);
if(!nomodif) {
dx=DynAPI.document.all["mainlayer"].getX();
dy=DynAPI.document.all["mainlayer"].getY();
} else {dx=0;dy=0; }
if( (dlayerup.getX()) >=(dlayerdown.getX()+dx)&&
(dlayerup.getX()+dlayerup.getWidth()) <= (dlayerdown.getX()+dx+dlayerdown.getWidth())&&
(dlayerup.getY()) >= (dlayerdown.getY()+dy)&&
(dlayerup.getY()+dlayerup.getHeight()) <= (dlayerdown.getY()+dy+dlayerdown.getHeight())) return(true);
return(false);
//DynAPI.document.addChild(new DynLayer("",dlayerdown.getX()+dx,dlayerdown.getY()+dy,dlayerdown.getWidth(),dlayerdown.getHeight(),"Green",1,100000));
//DynAPI.document.addChild(new DynLayer("",dlayerup.getX(),dlayerup.getY(),dlayerup.getWidth(),dlayerup.getHeight(),"Blue",1,1001000));
}
function layerReload(l)
{
tmp=l.getHTML();
l.setHTML('');
l.setHTML(tmp,false);
}
// ************************************************************
// ******************** Construtor newDynLayer ********************
// ************************************************************
// Base class for all layerers operations and common behavior. This classe has limited funcionality.
// ^^^^^^^^^^^^^^^^^^^
var newDynLayer = function (b,c,j,parent,autoload) {
this.base=DynLayer;
this.savedX=b;
this.savedY=c;
//tmp=(name || "newdynlayer");
//alert(tmp);
this.base(this.getnewname(),b,c,null,null,null,true,zindex++,"/newimages/pixel.gif",j);
//alert(this.basename+" -- "+this.Count);
if (autoload) this.makeHTML();
// Habilita o drag
//DragEvent.parentChanging=true;
DragEvent.enableDragEvents(this);
DragEvent.setDragBoundary(top);
// Vincula eventos
c=new EventListener(this);
c.ondragend=this.ondragend;
c.ondragmove=this.ondragmove;
c.ondragstart=this.ondragstart;
c.onclick=this.higherzindex;
/*c.onmouseover=function (e) {
t=e.target;
t.setBgColor("green");
//alert(t.getWidth()+' '+t.getContentWidth()+" "+t.css);
//t.setWidth(t.getContentWidth());
}*/
this.addEventListener(c);
// Adiciona o Layer ao documento
tmp=parent||DynAPI.document;
//tmp=DynAPI.document;
//if(autocreate) {
tmp.addChild(this);
//}
this.parent=tmp;
//alert(this.parent);
}
// ************************************************************
// ******************** Declarações básicas e metodos ********************
// ************************************************************
newDynLayer.prototype=new DynLayer;
//Novo número para a criacao do identificador, usando uma constante própria
//unico para cada classe descendente dessa
newDynLayer.Count=0; // variável estática
newDynLayer.prototype.basename="newdynlayer";
newDynLayer.prototype.loaded=false;
newDynLayer.prototype.mycreated=false;
newDynLayer.prototype.out=false;
newDynLayer.prototype.savedX=0;
newDynLayer.prototype.savedY=0;
newDynLayer.prototype.DynListIndex=-1; // o numero do objeto dentro da lista DynList
newDynLayer.prototype.naimagem=false;
newDynLayer.prototype.getWidth=function () { return(this.getContentWidth());}
newDynLayer.prototype.setWidthHeight=function(W,H) { setWidth(W);setHeight(H); }
newDynLayer.prototype.setXY=function(xx,yy) { setX(xx); setY(yy); }
newDynLayer.prototype.makeHTML=function(){
this.loaded=true;
} // Methodo abstrato
newDynLayer.prototype.getnewname=function () {
// Monta o identificador do layer... a variável de refencia para o dynobject
//alert(this.id+" "+this.basename);
return(this.basename+this.getidnumber());
}
newDynLayer.prototype.getidnumber=function () {
return(newDynLayer.Count++);
}
newDynLayer.prototype.newme=function() {
// Faz uma cópia de si
//alert(source.id);
return( new newDynLayer(this.savedX,this.savedY,this.getHTML()) );
}
// ************************************************************
// ******************** EVENTOS ********************
// ************************************************************
newDynLayer.prototype.ondragstart=function(e) {
if(!e.target.naimagem) { // Já esta na imagem?
e.target.newme();
DynAPI.document.addChild(e.target);
DragEvent.dragevent.x-=pagelistX+mainlayer.getX();
DragEvent.dragevent.y-=pagelistY+mainlayer.getY()+15;
//DragEvent.dragevent.pageX-=pagelistX+mainlayer.getX();
//DragEvent.dragevent.pagey-=pagelistY+mainlayer.getY()+30;
//DynAPI.document.all["mainlayer"].addChild(e.target);
e.target.savedX=e.target.getX();
e.target.savedY=e.target.getY();
//nid=basename+(++j);
}
//e.target.setZIndex(++zindex);
}
newDynLayer.prototype.ondragmove=function(e){
}
newDynLayer.prototype.ondragend=function(e) {
if(!e.target.naimagem) { // nao esta na imagem?
if(!isDynLayerOver(e.target,DynObject.all.foto)) { // se ainda esta sobre a imagem
e.target.naimagem=false; // caso nao esteja só para garantir faz naimage=false;
// se o objeto nao for destruido
e.target.removeFromParent();
delete e.target;
}
else // caso agora esteja sobre a imagem
{
t=e.target;
f=DynAPI.document.all["mainlayer"];
t.naimagem=true;
t.moveTo(t.getX()-f.getX(),t.getY()-f.getY());
f.addChild(e.target);
t.DynListIndex=DynList.add(e.target);
}
}
else // esta sobre na imagem
{
if(!isDynLayerOver(e.target,DynObject.all.foto,true)) { // se agora nao esta sobre a imagem
DynList.remove(e.target.DynListIndex);
e.target.naimagem=false;
e.target.del();
delete e.target;
}
}
}
newDynLayer.prototype.onpathstop = function(ev) {
}
// esse aqui é o onclick
newDynLayer.prototype.higherzindex=function(e)
{
zindex=zindex+10;
e.target.setZIndex(zindex);
//alert(show_props(e.target.css,'','pos'));
//alert(e.target.getWidth()+' '+e.target.getContentWidth()+' x:'+(0+e.target.getX())+' y:'+(0+e.target.getY())+' '+e.target.getHTML());
}
//************************************************************
// ************************************************************
// ******************** Construtor ImageLayer********************
// ************************************************************
// Extende newDynLayer e adiciona alguma funcionalidade específica para
// Layers com uma única imagem
ImageLayer=function(xx,yy,filename,parent,autoload)
{
// alert(Count);
this.setFilename(filename);
this.base=newDynLayer;
this.base(xx,yy,"",parent,autoload);
}
// ************************************************************
// ******************** Declarações básicas e metodos ********************
// ************************************************************
ImageLayer.prototype=new newDynLayer;
ImageLayer.CountImageLayer=0; // estática
ImageLayer.prototype.basename="imagelayer";
ImageLayer.prototype.filename=false;
//Novo número para a criacao do identificador, usando uma constante própria
ImageLayer.prototype.getidnumber=function () {
//alert(ImageLayer.CountImageLayer);
return(++ImageLayer.CountImageLayer);
}
ImageLayer.prototype.setFilename=function(filename) { this.filename=filename; }
ImageLayer.prototype.getFilename=function() { return(this.filename); }
ImageLayer.prototype.makeIcon=function() {
//DynImage.getImage(this.getFilename());
this.setHTML(''); }
ImageLayer.prototype.makeHTML=function() {
//this.base.makeHTML();
this.makeIcon();
this.loaded=true;
}
ImageLayer.prototype.newme=function()
{
return(new ImageLayer(this.savedX,this.savedY,this.getFilename(),this.parent,true));
}
// ************************************************************
// ************************************************************
// ******************** Construtor TextImageLayer********************
// ************************************************************
// Extende newDynLayer.
// O mesmo que ImageLayer, porem recebe um string, faz o html ser uma imagem para cada letra do string.
// Leva em considerao tamanho, fonte e cor.
// Haveram 3 cores e 3 tamanhos: 0,1,2.
// As imagens estarão dispostas em pastas diferentes para cada font,cor,tamanho.
TextImageLayer=function(xx,yy,texto,cor,tamanho,parent,autoload)
{
// alert(Count);
this.setText(texto);
this.setColor(cor);
this.setSize(tamanho);
this.setFont(0);
this.makeFontPath();
this.base=newDynLayer;
this.base(xx,yy,"",parent,autoload);
c=new EventListener(this);
c.onload=this.onload;
this.addEventListener(c);
}
// ************************************************************
// ******************** Declarações básicas e metodos ********************
// ************************************************************
TextImageLayer.prototype=new newDynLayer;
TextImageLayer.prototype.alternatewidth=0;
TextImageLayer.prototype.imageIndex=0;
TextImageLayer.CountTextImageLayer=0; // estáticas
TextImageLayer.BasePath="http://www.ocarteiro.com.br/images/letras/";
TextImageLayer.TransparentWidthList=new Array(4,4,4);
TextImageLayer.prototype.basename="textimagelayer";
//TextImageLayer.prototype.naimagem=false;
//Novo número para a criacao do identificador, usando uma constante própria
TextImageLayer.prototype.getidnumber=function () {
//alert(TextImageLayer.CountTextImageLayer);
return(++TextImageLayer.CountTextImageLayer);
}
TextImageLayer.prototype.getTransparentWidth=function() { return TextImageLayer.TransparentWidthList[this.font] }
TextImageLayer.prototype.setColor=function(color) { this.color=color; }
TextImageLayer.prototype.getColor=function() { return(this.color); }
TextImageLayer.prototype.setSize=function(size) { this.size=size; }
TextImageLayer.prototype.getSize=function() { return(this.size); }
TextImageLayer.prototype.setFont=function(font) { this.font=font; }
TextImageLayer.prototype.getFont=function() { return(this.font); }
TextImageLayer.prototype.setText=function(text) { this.text=text; }
TextImageLayer.prototype.getText=function() { return(this.text); }
TextImageLayer.prototype.makeFontPath=function() {
this.fontpath=TextImageLayer.BasePath+"font"+this.getFont()+"/size"+this.getSize()+"/color"+this.getColor()+"/";
}
TextImageLayer.prototype.spellLetter=function(ch) {
/*switch(ch) {
case ' ': ch='spc'; break;
default: break;
}*///alert(ch);
result='';
if(ch==' ') result='
+'.gif)