Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1372 Rev 1422
1
/*
1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
3
	All Rights Reserved.
4
 
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
9
*/
-
 
10
 
-
 
11
 
10
 
12
 
11
dojo.provide("dojo.animation.Animation");
13
dojo.provide("dojo.animation.Animation");
12
dojo.require("dojo.animation.AnimationEvent");
14
dojo.require("dojo.animation.AnimationEvent");
13
dojo.require("dojo.lang.func");
15
dojo.require("dojo.lang.func");
14
dojo.require("dojo.math");
16
dojo.require("dojo.math");
15
dojo.require("dojo.math.curves");
17
dojo.require("dojo.math.curves");
16
dojo.deprecated("dojo.animation.Animation is slated for removal in 0.5; use dojo.lfx.* instead.", "0.5");
18
dojo.deprecated("dojo.animation.Animation is slated for removal in 0.5; use dojo.lfx.* instead.", "0.5");
17
dojo.animation.Animation = function (curve, duration, accel, repeatCount, rate) {
19
dojo.animation.Animation = function (curve, duration, accel, repeatCount, rate) {
18
	if (dojo.lang.isArray(curve)) {
20
	if (dojo.lang.isArray(curve)) {
19
		curve = new dojo.math.curves.Line(curve[0], curve[1]);
21
		curve = new dojo.math.curves.Line(curve[0], curve[1]);
20
	}
22
	}
21
	this.curve = curve;
23
	this.curve = curve;
22
	this.duration = duration;
24
	this.duration = duration;
23
	this.repeatCount = repeatCount || 0;
25
	this.repeatCount = repeatCount || 0;
24
	this.rate = rate || 25;
26
	this.rate = rate || 25;
25
	if (accel) {
27
	if (accel) {
26
		if (dojo.lang.isFunction(accel.getValue)) {
28
		if (dojo.lang.isFunction(accel.getValue)) {
27
			this.accel = accel;
29
			this.accel = accel;
28
		} else {
30
		} else {
29
			var i = 0.35 * accel + 0.5;
31
			var i = 0.35 * accel + 0.5;
30
			this.accel = new dojo.math.curves.CatmullRom([[0], [i], [1]], 0.45);
32
			this.accel = new dojo.math.curves.CatmullRom([[0], [i], [1]], 0.45);
31
		}
33
		}
32
	}
34
	}
33
};
35
};
34
dojo.lang.extend(dojo.animation.Animation, {curve:null, duration:0, repeatCount:0, accel:null, onBegin:null, onAnimate:null, onEnd:null, onPlay:null, onPause:null, onStop:null, handler:null, _animSequence:null, _startTime:null, _endTime:null, _lastFrame:null, _timer:null, _percent:0, _active:false, _paused:false, _startRepeatCount:0, play:function (gotoStart) {
36
dojo.lang.extend(dojo.animation.Animation, {curve:null, duration:0, repeatCount:0, accel:null, onBegin:null, onAnimate:null, onEnd:null, onPlay:null, onPause:null, onStop:null, handler:null, _animSequence:null, _startTime:null, _endTime:null, _lastFrame:null, _timer:null, _percent:0, _active:false, _paused:false, _startRepeatCount:0, play:function (gotoStart) {
35
	if (gotoStart) {
37
	if (gotoStart) {
36
		clearTimeout(this._timer);
38
		clearTimeout(this._timer);
37
		this._active = false;
39
		this._active = false;
38
		this._paused = false;
40
		this._paused = false;
39
		this._percent = 0;
41
		this._percent = 0;
40
	} else {
42
	} else {
41
		if (this._active && !this._paused) {
43
		if (this._active && !this._paused) {
42
			return;
44
			return;
43
		}
45
		}
44
	}
46
	}
45
	this._startTime = new Date().valueOf();
47
	this._startTime = new Date().valueOf();
46
	if (this._paused) {
48
	if (this._paused) {
47
		this._startTime -= (this.duration * this._percent / 100);
49
		this._startTime -= (this.duration * this._percent / 100);
48
	}
50
	}
49
	this._endTime = this._startTime + this.duration;
51
	this._endTime = this._startTime + this.duration;
50
	this._lastFrame = this._startTime;
52
	this._lastFrame = this._startTime;
51
	var e = new dojo.animation.AnimationEvent(this, null, this.curve.getValue(this._percent), this._startTime, this._startTime, this._endTime, this.duration, this._percent, 0);
53
	var e = new dojo.animation.AnimationEvent(this, null, this.curve.getValue(this._percent), this._startTime, this._startTime, this._endTime, this.duration, this._percent, 0);
52
	this._active = true;
54
	this._active = true;
53
	this._paused = false;
55
	this._paused = false;
54
	if (this._percent == 0) {
56
	if (this._percent == 0) {
55
		if (!this._startRepeatCount) {
57
		if (!this._startRepeatCount) {
56
			this._startRepeatCount = this.repeatCount;
58
			this._startRepeatCount = this.repeatCount;
57
		}
59
		}
58
		e.type = "begin";
60
		e.type = "begin";
59
		if (typeof this.handler == "function") {
61
		if (typeof this.handler == "function") {
60
			this.handler(e);
62
			this.handler(e);
61
		}
63
		}
62
		if (typeof this.onBegin == "function") {
64
		if (typeof this.onBegin == "function") {
63
			this.onBegin(e);
65
			this.onBegin(e);
64
		}
66
		}
65
	}
67
	}
66
	e.type = "play";
68
	e.type = "play";
67
	if (typeof this.handler == "function") {
69
	if (typeof this.handler == "function") {
68
		this.handler(e);
70
		this.handler(e);
69
	}
71
	}
70
	if (typeof this.onPlay == "function") {
72
	if (typeof this.onPlay == "function") {
71
		this.onPlay(e);
73
		this.onPlay(e);
72
	}
74
	}
73
	if (this._animSequence) {
75
	if (this._animSequence) {
74
		this._animSequence._setCurrent(this);
76
		this._animSequence._setCurrent(this);
75
	}
77
	}
76
	this._cycle();
78
	this._cycle();
77
}, pause:function () {
79
}, pause:function () {
78
	clearTimeout(this._timer);
80
	clearTimeout(this._timer);
79
	if (!this._active) {
81
	if (!this._active) {
80
		return;
82
		return;
81
	}
83
	}
82
	this._paused = true;
84
	this._paused = true;
83
	var e = new dojo.animation.AnimationEvent(this, "pause", this.curve.getValue(this._percent), this._startTime, new Date().valueOf(), this._endTime, this.duration, this._percent, 0);
85
	var e = new dojo.animation.AnimationEvent(this, "pause", this.curve.getValue(this._percent), this._startTime, new Date().valueOf(), this._endTime, this.duration, this._percent, 0);
84
	if (typeof this.handler == "function") {
86
	if (typeof this.handler == "function") {
85
		this.handler(e);
87
		this.handler(e);
86
	}
88
	}
87
	if (typeof this.onPause == "function") {
89
	if (typeof this.onPause == "function") {
88
		this.onPause(e);
90
		this.onPause(e);
89
	}
91
	}
90
}, playPause:function () {
92
}, playPause:function () {
91
	if (!this._active || this._paused) {
93
	if (!this._active || this._paused) {
92
		this.play();
94
		this.play();
93
	} else {
95
	} else {
94
		this.pause();
96
		this.pause();
95
	}
97
	}
96
}, gotoPercent:function (pct, andPlay) {
98
}, gotoPercent:function (pct, andPlay) {
97
	clearTimeout(this._timer);
99
	clearTimeout(this._timer);
98
	this._active = true;
100
	this._active = true;
99
	this._paused = true;
101
	this._paused = true;
100
	this._percent = pct;
102
	this._percent = pct;
101
	if (andPlay) {
103
	if (andPlay) {
102
		this.play();
104
		this.play();
103
	}
105
	}
104
}, stop:function (gotoEnd) {
106
}, stop:function (gotoEnd) {
105
	clearTimeout(this._timer);
107
	clearTimeout(this._timer);
106
	var step = this._percent / 100;
108
	var step = this._percent / 100;
107
	if (gotoEnd) {
109
	if (gotoEnd) {
108
		step = 1;
110
		step = 1;
109
	}
111
	}
110
	var e = new dojo.animation.AnimationEvent(this, "stop", this.curve.getValue(step), this._startTime, new Date().valueOf(), this._endTime, this.duration, this._percent);
112
	var e = new dojo.animation.AnimationEvent(this, "stop", this.curve.getValue(step), this._startTime, new Date().valueOf(), this._endTime, this.duration, this._percent);
111
	if (typeof this.handler == "function") {
113
	if (typeof this.handler == "function") {
112
		this.handler(e);
114
		this.handler(e);
113
	}
115
	}
114
	if (typeof this.onStop == "function") {
116
	if (typeof this.onStop == "function") {
115
		this.onStop(e);
117
		this.onStop(e);
116
	}
118
	}
117
	this._active = false;
119
	this._active = false;
118
	this._paused = false;
120
	this._paused = false;
119
}, status:function () {
121
}, status:function () {
120
	if (this._active) {
122
	if (this._active) {
121
		return this._paused ? "paused" : "playing";
123
		return this._paused ? "paused" : "playing";
122
	} else {
124
	} else {
123
		return "stopped";
125
		return "stopped";
124
	}
126
	}
125
}, _cycle:function () {
127
}, _cycle:function () {
126
	clearTimeout(this._timer);
128
	clearTimeout(this._timer);
127
	if (this._active) {
129
	if (this._active) {
128
		var curr = new Date().valueOf();
130
		var curr = new Date().valueOf();
129
		var step = (curr - this._startTime) / (this._endTime - this._startTime);
131
		var step = (curr - this._startTime) / (this._endTime - this._startTime);
130
		var fps = 1000 / (curr - this._lastFrame);
132
		var fps = 1000 / (curr - this._lastFrame);
131
		this._lastFrame = curr;
133
		this._lastFrame = curr;
132
		if (step >= 1) {
134
		if (step >= 1) {
133
			step = 1;
135
			step = 1;
134
			this._percent = 100;
136
			this._percent = 100;
135
		} else {
137
		} else {
136
			this._percent = step * 100;
138
			this._percent = step * 100;
137
		}
139
		}
138
		if (this.accel && this.accel.getValue) {
140
		if (this.accel && this.accel.getValue) {
139
			step = this.accel.getValue(step);
141
			step = this.accel.getValue(step);
140
		}
142
		}
141
		var e = new dojo.animation.AnimationEvent(this, "animate", this.curve.getValue(step), this._startTime, curr, this._endTime, this.duration, this._percent, Math.round(fps));
143
		var e = new dojo.animation.AnimationEvent(this, "animate", this.curve.getValue(step), this._startTime, curr, this._endTime, this.duration, this._percent, Math.round(fps));
142
		if (typeof this.handler == "function") {
144
		if (typeof this.handler == "function") {
143
			this.handler(e);
145
			this.handler(e);
144
		}
146
		}
145
		if (typeof this.onAnimate == "function") {
147
		if (typeof this.onAnimate == "function") {
146
			this.onAnimate(e);
148
			this.onAnimate(e);
147
		}
149
		}
148
		if (step < 1) {
150
		if (step < 1) {
149
			this._timer = setTimeout(dojo.lang.hitch(this, "_cycle"), this.rate);
151
			this._timer = setTimeout(dojo.lang.hitch(this, "_cycle"), this.rate);
150
		} else {
152
		} else {
151
			e.type = "end";
153
			e.type = "end";
152
			this._active = false;
154
			this._active = false;
153
			if (typeof this.handler == "function") {
155
			if (typeof this.handler == "function") {
154
				this.handler(e);
156
				this.handler(e);
155
			}
157
			}
156
			if (typeof this.onEnd == "function") {
158
			if (typeof this.onEnd == "function") {
157
				this.onEnd(e);
159
				this.onEnd(e);
158
			}
160
			}
159
			if (this.repeatCount > 0) {
161
			if (this.repeatCount > 0) {
160
				this.repeatCount--;
162
				this.repeatCount--;
161
				this.play(true);
163
				this.play(true);
162
			} else {
164
			} else {
163
				if (this.repeatCount == -1) {
165
				if (this.repeatCount == -1) {
164
					this.play(true);
166
					this.play(true);
165
				} else {
167
				} else {
166
					if (this._startRepeatCount) {
168
					if (this._startRepeatCount) {
167
						this.repeatCount = this._startRepeatCount;
169
						this.repeatCount = this._startRepeatCount;
168
						this._startRepeatCount = 0;
170
						this._startRepeatCount = 0;
169
					}
171
					}
170
					if (this._animSequence) {
172
					if (this._animSequence) {
171
						this._animSequence._playNext();
173
						this._animSequence._playNext();
172
					}
174
					}
173
				}
175
				}
174
			}
176
			}
175
		}
177
		}
176
	}
178
	}
177
}});
179
}});
178
 
180