Update of /cvsroot/dynapi/dynapi2x/src/fx
In directory usw-pr-cvs1:/tmp/cvs-serv19326/src/fx

Added Files:
        bezier.js circleanim.js hoveranim.js imganim.js motionx.js 
        pathanim.js pathanim_glide.js pathanim_slide.js thread.js 
        timerx.js 
Log Message:
initial import


--- NEW FILE ---
// Bezier Algorithm Reference: http://astronomy.swin.edu.au/~pbourke/curves/bezier/

function Bezier(cp, n) {
        var l = cp.length;
        var p = [];
        for (var i=0; i<n; i++) p = p.concat(Bezier._plot(cp,i/n));
        return p.concat([cp[l-2],cp[l-1]]);
}

Bezier._plot = function (cp, mu) {
        var n = (cp.length/2)-1;
        var k,kn,nn,nkn;
        var blend;
        var b = [0,0];

        var muk = 1;
        var munk = Math.pow(1-mu, n);

        for (k=0;k<=n;k++) {
                nn = n;
                kn = k;
                nkn = n - k;
                blend = muk * munk;
                muk *= mu;
                munk /= (1-mu);
                while (nn >= 1) {
                        blend *= nn;
                        nn--;
                        if (kn > 1) {
                                blend /= kn;
                                kn--;
                        }
                        if (nkn > 1) {
                                blend /= nkn;
                                nkn--;
                        }
                }
                
                b[0] += cp[k*2] * blend;
                b[1] += cp[k*2+1] * blend;
        }
        b[0] = Math.round(b[0]);
        b[1] = Math.round(b[1]);
        return b;
}

/*function Bezier3(cp,mu) {
        var x1=cp[0],y1=cp[1],x2=cp[2],y2=cp[3],x3=cp[4],y3=cp[5];
        var mu2 = mu * mu;
        var mum1 = 1 - mu;
        var mum12 = mum1 * mum1;
        var x = Math.round(x1 * mum12 + 2 * x2 * mum1 * mu + x3 * mu2);
        var y = Math.round(y1 * mum12 + 2 * y2 * mum1 * mu + y3 * mu2);
        return [x,y];
}

function Bezier4(cp,mu) {
        var x1=cp[0],y1=cp[1],x2=cp[2],y2=cp[3],x3=cp[4],y3=cp[5],x4=cp[6],y4=cp[7];
        var mum1 = 1 - mu;
        var mum13 = mum1 * mum1 * mum1;
        var mu3 = mu * mu * mu;
        var x = Math.round(mum13*x1 + 3*mu*mum1*mum1*x2 + 3*mu*mu*mum1*x3 + mu3*x4);
        var y = Math.round(mum13*y1 + 3*mu*mum1*mum1*y2 + 3*mu*mu*mum1*y3 + mu3*y4);
        return [x,y];
}*/

--- NEW FILE ---
/*
        DynAPI Distribution
        CircleAnimation Class

        The DynAPI Distribution is distributed under the terms of the GNU LGPL license.

        requires: PathAnimation
*/

// You must add this to the DynAPI library if you want to include it via 
dynapi.library.include('CircleAnimation');
// 
dynapi.library.add('dynapi.fx.CircleAnimation','circleanim.js',['Thread','dynapi.functions']);

function CircleAnimation(dlyr) {
        this.inherit('Thread',dlyr);

        this.offsetX = 0;
        this.offsetY = 0;
        this.playing = false;
        this.radius = 100;
        this.angle = 0;
        this.setAngleIncrement(10);
}
dynapi.setPrototype('CircleAnimation','Thread');
CircleAnimation.prototype.setRadius = function (r) {
        this.hradius = this.vradius = r;
};
CircleAnimation.prototype.setHRadius = function (r) {
        this.hradius = r;
};
CircleAnimation.prototype.setVRadius = function (r) {
        this.vradius = r;
};
CircleAnimation.prototype.setAngle = function (a) {
        this.angle = dynapi.functions.degreeToRadian(a);
};
CircleAnimation.prototype.setAngleIncrement = function (inc) {
        this.angleinc = dynapi.functions.degreeToRadian(inc);
};
CircleAnimation.prototype.playAnimation = function () {
        this.playing = true;
        if (this.dlyr!=null) {
                this.offsetX = this.hradius*Math.cos(this.angle);
                this.offsetY = -this.vradius*Math.sin(this.angle);
                this.baseX = this.dlyr.x-this.offsetX;
                this.baseY = this.dlyr.y+this.offsetY;
                this.dlyr.invokeEvent("circlestart");
        }
        this.start();
};
CircleAnimation.prototype.stopAnimation = function () {
        this.playing = false;
        this.stop();
        if (this.dlyr!=null) this.dlyr.invokeEvent("circlestop");
};
CircleAnimation.prototype.run = function () {
        if (!this.playing || this.dlyr==null) return;   
        this.angle += this.angleinc;
        this.offsetX = this.hradius*Math.cos(this.angle);
        this.offsetY = -this.vradius*Math.sin(this.angle);

        if (this.dlyr!=null) {
                this.dlyr.invokeEvent("circlerun");
                this.dlyr.moveTo(this.baseX+this.offsetX,this.baseY+this.offsetY);
        }
};
CircleAnimation.prototype.reset = function () {
        this.angle = this.offsetX = this.offsetY = 0;
};
CircleAnimation.prototype.generatePath = function(centerX,centerY) {
        if (centerX==null) centerX = this.dlyr!=null? this.dlyr.x : 0;
        if (centerY==null) centerY = this.dlyr!=null? this.dlyr.y : 0;
        var path = [];
        var i = 0;
/*      for (var a=this.angle;a<=this.angle+Math.PI*2;a+=this.angleinc) {
                path[i] = Math.round(centerX + this.hradius*Math.cos(a));
                path[i+1] = Math.round(centerY - this.vradius*Math.sin(a));
                i+=2;
        }*/

        if (this.angleinc>0)
                for (var a=this.angle;a<=this.angle+Math.PI*2;a+=this.angleinc) {
                        path[i] = Math.round(centerX + this.hradius*Math.cos(a));
                        path[i+1] = Math.round(centerY - this.vradius*Math.sin(a));
                        i+=2;
                }
        else
                for (var a=this.angle;a>=this.angle-Math.PI*2;a+=this.angleinc) {
                        path[i] = Math.round(centerX + this.hradius*Math.cos(a));
                        path[i+1] = Math.round(centerY - this.vradius*Math.sin(a));
                        i+=2;
                }
        return path;
};

--- NEW FILE ---
/*
        DynAPI Distribution
        HoverAnimation Class

        The DynAPI Distribution is distributed under the terms of the GNU LGPL license.

        requires: PathAnimation
*/

// You must add this to the DynAPI library if you want to include it via 
dynapi.library.include('HoverAnimation');
// dynapi.library.add('HoverAnimation','hoveranim.js','Thread','dynapi.fx');

function HoverAnimation(dlyr) {
        this.Thread = Thread;
        this.Thread(dlyr);

        this.offsetX = 0;
        this.offsetY = 0;
        this.playing = false;
        this.amplitude = 100;
        this.angle = 0;
        this.setAngleIncrement(10);
}
HoverAnimation.prototype = new Thread;
HoverAnimation.prototype.setAmplitude = function (amp) {
        this.amplitude = amp;
};
HoverAnimation.prototype.setAngle = function (a) {
        this.angle = PathAnimation.degreeToRadian(a);
};
HoverAnimation.prototype.setAngleIncrement = function (inc) {
        this.angleinc = PathAnimation.degreeToRadian(inc);
};
HoverAnimation.prototype.playAnimation = function () {
        this.playing = true;
        if (this.dlyr!=null) {
                this.offsetX = 0;
                this.offsetY = this.amplitude*Math.sin(this.angle);
                this.baseX = this.dlyr.x;
                this.baseY = this.dlyr.y+this.offsetY;
                this.dlyr.invokeEvent("hoverstart");
        }
        this.start();
};
HoverAnimation.prototype.stopAnimation = function () {
        this.playing = false;
        this.stop();
        if (this.dlyr!=null) this.dlyr.invokeEvent("hoverstop");
};
HoverAnimation.prototype.run = function () {
        if (!this.playing || this.dlyr==null) return;
        this.angle += this.angleinc;
        this.offsetX = 0;
        this.offsetY = this.amplitude*Math.sin(this.angle);
        if (this.dlyr!=null) {
                this.dlyr.invokeEvent("hoverrun");
                this.dlyr.moveTo(this.baseX+this.offsetX,this.baseY+this.offsetY);
        }
};
HoverAnimation.prototype.reset = function () {
        this.angle = this.offsetX = this.offsetY = 0;
};

HoverAnimation.prototype.generatePath = function(centerX,centerY) {
        // to do
};

--- NEW FILE ---
/*
        DynAPI Distribution
        ImageAnimation Class

        The DynAPI Distribution is distributed under the terms of the GNU LGPL license.

        requires: Thread
*/

function ImageAnimation(dynimage) {
        this.Thread = Thread;
        this.Thread(dynimage);

        this.imgAnim = new Array();
        this.imgAnim.playing = null;
}
ImageAnimation.prototype = new Thread;
ImageAnimation.prototype.addAnimation = function (imgArray) {
        var animNum = this.imgAnim.length;
        this.imgAnim[animNum] = imgArray;
        this.imgAnim[animNum].loops = false;
        this.imgAnim[animNum].resets = false;
        this.imgAnim[animNum].frame = 0;
        this.imgAnim[animNum].playing = true;
        this.imgAnim[animNum].direction = 0;
        this.imgAnim[animNum].alternates = false;
        return animNum;
};
ImageAnimation.prototype.getFrame = function (animNum,frameNum) {
        return this.imgAnim[animNum][frameNum];
};

ImageAnimation.prototype.setLoops = function (animNum,loop) {
        this.imgAnim[animNum].loops = loop;
};
ImageAnimation.prototype.setResets = function (animNum) {
        this.imgAnim[animNum].resets = true;
};
ImageAnimation.prototype.setAlternates = function (animNum,alt) {
        this.imgAnim[animNum].loops = true;
        this.imgAnim[animNum].alternates = alt;
};

ImageAnimation.prototype.playAnimation = function (animNum) {
        if (animNum!=null && this.imgAnim.playing!=animNum) {
                this.playing = true;
                this.imgAnim.playing = animNum;
                if (this.dlyr!=null) this.dlyr.invokeEvent("imgstart");
                this.start();
        }
};
ImageAnimation.prototype.stopAnimation = function () {
        this.imgAnim.playing = null;
        this.playing = false;
        this.stop();
        if (this.dlyr!=null) this.dlyr.invokeEvent("imgrun");
};
ImageAnimation.prototype.run = function () {
        if (!this.playing || this.imgAnim.playing==null || this.dlyr==null) return;
        
        var anim = this.imgAnim[this.imgAnim.playing];
        
        if (anim.frame==0 && this.img==anim[anim.frame]) {
                anim.frame++;   // skip 1st frame if same
        }
        if (this.dlyr!=null) this.dlyr.invokeEvent("imgrun");
        this.dlyr.setImage(anim[anim.frame]);
        
        if (anim.frame>=anim.length-1) {
                if (anim.loops) {
                        if (anim.alternates && anim.direction==0 && 
anim.frame==anim.length-1) {
                                anim.direction = 1; 
                                anim.frame = anim.length-2;
                        }
                        else anim.frame = 0;
                }
                else if (anim.resets) {
                        anim.frame = 0;
                        this.stop()
                }
                else {
                        this.stop()
                }
        }
        else {
                if (anim.alternates) {
                        if (anim.frame==0 && anim.direction==1) {
                                anim.direction = 0;
                                anim.frame = 1;
                        }
                        else if (anim.direction==0) {
                                anim.frame++;
                        }
                        else if (anim.direction==1) {
                                anim.frame--;
                        }
                }
                else {
                        anim.frame++;
                }
        }
};

--- NEW FILE ---
/*
        DynAPI Distribution
        MotionX Class by Raymond Irving ([EMAIL PROTECTED])

        The DynAPI Distribution is distributed under the terms of the GNU LGPL license.

        requires: Dynlayer
*/

DynLayer.prototype.makeSolid=function(){
        this.isHard=true
        this._collideX=this.x
        this._collideY=this.x
        this.collideEvent ={
                onmove:function(e) {
                        var me=e.getSource()
                        var dirX='',dirY=''
                        // get direction
                        if (me._collideX!=me.x) {
                                if (me._collideX<me.x){dirX="E"}else{dirX="W"}
                        }
                        if (me._collideY!=me.y){
                                if (me._collideY<me.y){dirY="S"}else{dirY="N"}
                        }
                        // get angle direction
                        
me._setCollideAngleDirection(me._collideX,me._collideY,me.x,me.y)
                        me._collideX=me.x;
                        me._collideY=me.y;
                        me._collideDirection=dirY+dirX;
                        me._checkForCollision();
                }
        }
        this.addEventListener(this.collideEvent)
}
DynLayer.prototype._setLocation=DynLayer.prototype.setLocation;
DynLayer.prototype.setLocation=function(x,y) {
        this._setLocation(x,y);
        this.invokeEvent('move');
}
DynLayer.prototype._setCollideAngleDirection = function(x1,y1,x2,y2) {
        var distx = (x2-x1),disty = (y1-y2),angle;
        //if (distx==0 && disty==0) return 0;
        var rad=Math.abs(Math.atan2(disty,distx))
        if (disty>=0) {
                if (distx>=0) angle = 90-(rad*180/Math.PI)
                else angle = 270+(180-(rad*180/Math.PI));
        }else{
                angle = 90+(rad*180/Math.PI)
        }
        this._collideAngle=Math.ceil(angle);
};
DynLayer.prototype._checkForCollision=function(){
        if (!this.parent.children.length>0) return false;
        var ch,chX,sX,sY,colX1,colX2,colY1,colY2,n1,n2;
        this.collideObject==null
        for (var i in this.parent.children) {
                ch=this.parent.children[i];
                if (ch!=this && ch.isHard==true) {
                        chX=ch.x;
                        chY=ch.y;
                        sX=this.x;
                        sY=this.y;
                        colX1=(sX>=chX && sX<=chX+ch.w)
                        colX2=(chX>=sX && chX<=sX+this.w)
                        colY1=(sY>=chY && sY<=chY+ch.h)
                        colY2=(chY>=sY && chY<=sY+this.h)
                        if ((colX1 || colX2) && (colY1 || colY2)) {
                                if (this._collideDirection=='NE') {
                                        n1=((chY+ch.h)-this.y);n2=((sX+this.w)-chX)
                                        if (n1<n2) {face="S"}else{face="W"}
                                }else if (this._collideDirection=='NW') {
                                        n1=((chY+ch.h)-this.y);n2=((chX+ch.w)-sX)
                                        if (n1<n2) {face="S"}else{face="E"}
                                }else if (this._collideDirection=='SE') {
                                        n1=((sY+this.h)-ch.y);n2=((sX+this.w)-chX)
                                        if (n1<n2) {face="N"}else{face="W"}
                                }else if (this._collideDirection=='SW') {
                                        n1=((sY+this.h)-ch.y);n2=((chX+ch.w)-sX)
                                        if (n1<n2) {face="N"}else{face="E"}
                                }else if (this._collideDirection=='E') {
                                        face="W"
                                }else if (this._collideDirection=='W') {
                                        face="E"
                                }else if (this._collideDirection=='N') {
                                        face="S"
                                }else if (this._collideDirection=='S') {
                                        face="N"
                                }

                                ch._impactSide=face
                                if (face=="W"){this._impactSide="E"}
                                if (face=="E"){this._impactSide="W"}
                                if (face=="N"){this._impactSide="S"}
                                if (face=="S"){this._impactSide="N"}

                                this._collideObject=ch
                                this.invokeEvent("collide");
                                ch._collideObject=this
                                ch.invokeEvent("collide");
                        }
                }
        }
        return false;
};
DynLayer.prototype.getImpactSide=function(){
        return this._impactSide;
}
DynLayer.prototype.getObstacle=function(){
        return this._collideObject;
}
DynLayer.prototype.getDirection=function(){
        return this._collideDirection;
}
DynLayer.prototype.getDirectionAngle=function(){
        return this._collideAngle;
}

--- NEW FILE ---
/*
        DynAPI Distribution
        PathAnimation Class

        The DynAPI Distribution is distributed under the terms of the GNU LGPL license.

        requires: dynapi.fx.Thread
*/

function PathAnimation(dlyr) {
        this.inherit('Thread',dlyr);
        this.paths = new Array();
        this.pathPlaying = null;
}
var p = dynapi.setPrototype('PathAnimation','Thread');

p.add = function (path, loops, resets) {
        var n = this.paths.length;
        this.paths[n] = path;
        this.setLoops(n,loops);
        this.setResets(n,resets);
        this.setFrame(n,0);
        return n;
};
p.setLoops = function (n, loops) {
        this.paths[n].loops = (loops);
};
p.setResets = function (n, resets) {
        this.paths[n].resets = (resets);
};
p.setFrame = function (n, frame) {
        this.paths[n].frame = frame;
};
p.play = function (noevt) {
        if (!this.playing) {
                this.pathPlaying = null;
                if (arguments[0]==null) arguments[0] = 0;
                if (typeof(arguments[0]) == "number") {
                        this.pathPlaying = this.paths[arguments[0]];
                }
                else if (typeof(arguments[0]) == "object") {  
                        this.pathPlaying = arguments[0];
                        this.pathPlaying.loops = arguments[1]||false;
                        this.pathPlaying.resets = arguments[2]||false;
                        this.pathPlaying.frame = 0;
                }
                this.playing = true;
                if (this.dlyr!=null && noevt!=false) 
this.dlyr.invokeEvent("pathstart");
                this.start();
        }
};
p._Thread_stop = Thread.prototype.stop;
p.stop = function (noevt) {
        if (this.pathPlaying && this.pathPlaying.resets && !this.cancelThread && 
this.dlyr!=null) this.dlyr.setLocation(this.pathPlaying[0],this.pathPlaying[1]);
        this._Thread_stop();
        this.pathPlaying = null;
        this.playing = false;
        if (this.dlyr!=null && noevt!=false) this.dlyr.invokeEvent("pathcancel");
};
p.run = function () {
        if (!this.playing || this.pathPlaying==null) return;
        var anim = this.pathPlaying;
        if (anim.frame>=anim.length/2) {
                if (anim.loops) {
                        anim.frame = 0;
                }
                else if (anim.resets) {
                        anim.frame = 0;
                        if (this.dlyr!=null) this.dlyr.setLocation(anim[0],anim[1]);
                        this.stop();
                        this.dlyr.invokeEvent("pathfinish");
                        return;
                }
                else {
                        anim.frame = 0;
                        this.stop();
                        this.dlyr.invokeEvent("pathfinish");
                        return;
                }
        }
        if (anim.frame==0 && (this.dlyr!=null && this.dlyr.x==anim[0] && 
this.dlyr.y==anim[1])) {
                anim.frame += 1;
        }
        this.newX = anim[anim.frame*2];
        this.newY = anim[anim.frame*2+1];
        
        if (this.dlyr!=null) {
                this.dlyr.invokeEvent("pathrun");
                this.dlyr.setLocation(this.newX,this.newY);
        }
        anim.frame++;
};

// Path Functions

// Combines separate [x1,x2],[y1,y2] arrays into a path array [x1,y1,x2,y2]
/*PathAnimation.interlace = function(x,y) {
        var l = Math.max(x.length,y.length);
        var a = new Array(l*2);
        for (var i=0; i<l; i++) {
                a[i*2] = x[i];
                a[i*2+1] = y[i];
        }
        return a;
};

// Returns correct angle in radians between 2 points
PathAnimation.getNormalizedAngle = function(x1,y1,x2,y2) {
        var distx = Math.abs(x1-x2);
        var disty = Math.abs(y1-y2);
        if (distx==0 && disty==0) angle = 0;
        else if (distx==0) angle = Math.PI/2;
        else angle = Math.atan(disty/distx);
        if (x1<x2) {
                if (y1<y2) angle = Math.PI*2-angle;
        }
        else {
                if (y1<y2) angle = Math.PI+angle;
                else angle = Math.PI-angle;
        }
        return angle;
};
*/

--- NEW FILE ---
/*
        DynAPI Distribution
        Glide Animation Extension

        The DynAPI Distribution is distributed under the terms of the GNU LGPL license.

        requires: PathAnimation
*/

// To use on a DynLayer:
// dlyr.addMethod("glideTo",PathAnimation.glideTo);
// dlyr.addMethod("glideStop",PathAnimation.glideStop);
// dlyr.glideTo(x,y,"slow","slow",5,10);
// dlyr.glideStop();

// Or attach to all DynLayers or another class like this:
// DynLayer.prototype.glideTo = PathAnimation.glideTo;
// DynLayer.prototype.glideStop = PathAnimation.glideStop;

// These will invoke "pathstart", "pathrun", "pathfinish" and "pathcancel" events on 
the dynlayer

PathAnimation.glideTo = function(x2,y2,angleinc,ms,startSpeed,endSpeed) {
        if (!this._pathanim) this._pathanim = new PathAnimation(this);
        if (!ms) ms = 20;
        if (x2==null) x2 = this.x;
        if (y2==null) y2 = this.y;
        if (this.x==x2 && this.y==y2) return;
        this._pathanim.sleep(ms);
        this._pathanim.play( 
GlideAnimation(this.x,this.y,x2,y2,angleinc,startSpeed,endSpeed) );
};
PathAnimation.glideStop = function () {
        if (this._pathanim) this._pathanim.stop();
};

function GlideAnimation(x1,y1,x2,y2,angleinc,startSpeed,endSpeed) {
        var normAngle = PathAnimation.getNormalizedAngle(x1,y1,x2,y2);
        var distx = x2-x1;
        var disty = y2-y1;
        var distance = Math.sqrt(Math.pow(distx,2) + Math.pow(disty,2));
        angleinc = (angleinc==null)? 7 : Math.abs(angleinc);
        
        // a terrible mess but it works
        var r = 1;
        if (startSpeed == "fast") {
                var centerX = x1;
                var centerY = y1;
                var centerX2 = x2;
                var centerY2 = y2;
                startAngle = 0;
                endAngle = 90;
                if (endSpeed=="fast") distance = distance/2;
        }
        else {
                startAngle = -90;
                endAngle = 0;
                if (endSpeed == "fast") {
                        var centerX = x1+distx;
                        var centerY = y1+disty;
                }
                else {  // default slow,slow
                        var centerX2 = x2-distx/2;
                        var centerY2 = y2-disty/2;
                        distance = distance/2;
                        var centerX = x1+distx/2;
                        var centerY = y1+disty/2;
                        r = -1;
                }
        }

        var i,d,x,y,dx,dy,path=[];
        for (var a=startAngle; a<endAngle; a+=angleinc) {
                i = path.length;
                d = distance*Math.sin(a*Math.PI/180);
                path[i] = Math.round(centerX + d*Math.cos(normAngle));
                path[i+1] = Math.round(centerY - d*Math.sin(normAngle));
        }
        if (startSpeed==endSpeed) {
                for (var a=endAngle; a<endAngle+90; a+=angleinc) {
                        i = path.length;
                        d = distance*Math.sin(a*Math.PI/180);
                        path[i] = Math.round(centerX2 - r*d*Math.cos(normAngle));
                        path[i+1] = Math.round(centerY2 + r*d*Math.sin(normAngle));
                }
        }
        
        var l = path.length;
        if (path[l-2] != x2 && path[l-1]!=y2) {
                path[l] = x2;
                path[l+1] = y2;
        }
        return path;
};

PathAnimation.glide = GlideAnimation;

--- NEW FILE ---
/*
        DynAPI Distribution
        Slide Animation Extension

        The DynAPI Distribution is distributed under the terms of the GNU LGPL license.

        requires: PathAnimation
*/

// To use on a DynLayer:
// dlyr.setMethod("slideTo",PathAnimation.slideTo);  // will overwrite the built in 
DynLayer.slideTo()
// dlyr.setMethod("slideStop",PathAnimation.slideStop);
// dlyr.slideTo(x,y,5,10);
// dlyr.slideStop();

// Or attach to all DynLayers or another class like this:
// DynLayer.prototype.glideTo = PathAnimation.glideTo;
// DynLayer.prototype.glideStop = PathAnimation.glideStop;

// These will invoke "pathstart", "pathrun", "pathfinish" and "pathcancel" events on 
the dynlayer

PathAnimation.slideTo = function(x,y,inc,ms) {
        if (!this._pathanim) this._pathanim = new PathAnimation(this);
        if (!ms) ms = 20;
        if (!inc) inc = 10;
        if (x==null) x = this.x;
        if (y==null) y = this.y;
        this._pathanim.sleep(ms);
        this._pathanim.play( SlideAnimation(this.x,this.y, x,y, inc) );
};
PathAnimation.slideStop = function () {
        if (this._pathanim) this._pathanim.stop();
};

// Generates a path between 2 points, stepping inc pixels at a time
function SlideAnimation(x1,y1,x2,y2,inc) {
        if (x2==null) x2 = x1;
        if (y2==null) y2 = y1;
        var distx = x2-x1;
        var disty = y2-y1;
        if (x1==x2 && y1==y2) return;
        var num = Math.sqrt(Math.pow(distx,2) + Math.pow(disty,2))/(inc||10)-1;
        var dx = distx/num;
        var dy = disty/num;
        var path = [];
        var x = x1;
        var y = y1;
        for (var i=0;i<=num;i++) {
                x += dx;
                y += dy;
                path[i*2] = Math.round(x);
                path[i*2+1] = Math.round(y);
        }
        if (path[i*2-2] != x2 || path[i*2-1] != y2) {
                path[i*2] = x2;
                path[i*2+1] = y2;
        }
        return path;
};
PathAnimation.line = SlideAnimation;

// a useful functions in some cases but not needed for slide

// Generates a path between 2 points in N steps
/*PathAnimation.lineN = function(x1,y1,x2,y2,N) {
        if (N==0) return [];
        var dx = (x2 == x1)? 0 : (x2 - x1)/N;
        var dy = (y2 == y1)? 0 : (y2 - y1)/N;
        var path = new Array();
        for (var i=0;i<=N;i++) {
                path[i*2] = Math.round(x1 + i*dx);
                path[i*2+1] = Math.round(y1 + i*dy);
        }
        return path;
};*/


--- NEW FILE ---
/*
        DynAPI Distribution
        Thread class

        The DynAPI Distribution is distributed under the terms of the GNU LGPL license.

        requires: dynapi.api.DynLayer
*/

function Thread(dlyr) {
        // Inherit from object. Provides unique ID
        this.inherit('DynObject');
        this.setDynLayer(dlyr);
}
var p = dynapi.setPrototype('Thread','DynObject');
p.active = false;
p.interval = 50;
p.cancelThread = false;
p.sleep = function (ms) {
        this.interval = Math.abs(parseInt(ms));
        if (this.active) {
                this.stop();
                setTimeout(this+'.start()',this.interval+1);
        }
};
p.setFPS = function (fps) {
        this.sleep(Math.floor(1000/fps));
};
p.cancel = function () {
        this.cancelThread = true;
        this.stop();
};
p.start = function () {
        if (!this.active) {
                this.active = true;
                if (!this.cancelThread) this.timer = 
setInterval(this+'.run()',this.interval);
        }
};
p.run = dynapi.functions.Null; // overwrite run
p.stop = function () {
        this.active = false;
        if (!this.cancelThread && this.timer) {
                clearInterval(this.timer);
                delete this.timer;
        }
};
p.setDynLayer = function (dlyr) {
        this.dlyr = dlyr;
};
p.getDynLayer = function () {
        return this.dlyr;
};

--- NEW FILE ---
/*
        DynAPI Distribution
        TimerX Class by Raymond Irving ([EMAIL PROTECTED])

        The DynAPI Distribution is distributed under the terms of the GNU LGPL license.

        requires: Dynlayer
*/

DynLayer.prototype.startTimer=function(interval) {
        if (this.tickTimer>0) this.stopTimer()
        this._timerInterval=interval||5
        this._timerTickCount=0
        this._timerStoped=false
        this._tickTimer=setTimeout(this+'.tickLoop()',this._timerInterval)
}
DynLayer.prototype.tickLoop=function() {
        if (this._timerStoped==true||this._timerStoped==null) return
        this._timerTickCount++;
        this.invokeEvent("timer")
        this._tickTimer=setTimeout(this+'.tickLoop()',this._timerInterval)
}
DynLayer.prototype.stopTimer=function() {
        this._timerStoped=true
        clearTimeout(this._tickTimer)
        status="stop"
}
DynLayer.prototype.setTimerInterval=function(interval) {
        this._timerInterval=interval||this._timerInterval
}
DynLayer.prototype.getTimerInterval=function() {
        return this._timerInterval
}
DynLayer.prototype.getTickCount=function() {
        return this._timerTickCount
}
DynLayer.prototype.resetTickCount=function() {
        this._timerTickCount=0
}





_______________________________________________
Dynapi-CVS mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dynapi-cvs

Reply via email to