Subversion Repositories wimsdev

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
20 reyssat 1
/*
2
        DynAPI Distribution
3
        Slide Animation Extension
4
 
5
        The DynAPI Distribution is distributed under the terms of the GNU LGPL license.
6
 
7
        requires: dynapi.fx.Thread
8
*/
9
 
10
// Generates a path between 2 points, stepping inc pixels at a time
11
function SlideAnimation(x1,y1,x2,y2,inc) {
12
        var n,dx,dy,lx,ly,p=[];
13
        if (x2==null) x2 = x1;
14
        if (y2==null) y2 = y1;
15
 
16
        lx = x2-x1;
17
        ly = y2-y1;
18
        n = Math.sqrt(Math.pow(lx,2) + Math.pow(ly,2))/(inc||10);
19
        dx = lx/n;
20
        dy = ly/n;
21
        for (var i=0;i<n;i++) {
22
                p[i*2] = x1 + Math.round(dx*i);
23
                p[i*2+1] = y1 + Math.round(dy*i);
24
        }
25
        if (p[i*2-2] != x2 || p[i*2-1] != y2) {
26
                p[i*2] = x2;
27
                p[i*2+1] = y2;
28
        }
29
        return p;
30
};
31
 
32
 
33
DynLayer.prototype.slideTo = function(x2,y2,inc,ms) {
34
        if (this.x!=x2 || this.y!=y2) {
35
                if (!this._thread) this._thread = new Thread(this);
36
                if (ms) this._thread.interval = ms;
37
                this._thread.play(SlideAnimation(this.x,this.y,x2,y2,inc));
38
        }
39
};
40
DynLayer.prototype.slideStop = function () {
41
        if (this._thread) this._thread.stop();
42
};