annotate nodejs/animate.js @ 870:512204bcafba

Export the function to create a runtime for an existed window for X. For some application, we need to create and associate a runtime with an existed window, and free it the runtime without close the window, later.
author Thinker K.F. Li <thinker@codemud.net>
date Fri, 24 Sep 2010 11:19:53 +0800
parents 3c48a77b75d3
children eff2f580b536 23dffb564ace
rev   line source
794
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*-
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 808
diff changeset
2 // vim: sw=4:ts=8:sts=4
727
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
3 var sys=require("sys");
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
4
795
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
5 /*
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
6 * This is configuration for animate module. For slower or speeder
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
7 * machines, ffs can be decreased or increased respective.
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
8 */
844
3c48a77b75d3 USe obj.x and obj.y to implement the linear animation
wycc
parents: 831
diff changeset
9 var ffs = 12;
795
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
10 var frame_interval = 1000 / ffs;
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
11
727
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
12 function linear_draw() {
795
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
13 var percent;
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
14
806
bf54c0408d35 Use wall time to compute percentage of an animation action
Thinker K.F. Li <thinker@codemud.net>
parents: 805
diff changeset
15 percent = (Date.now() - this._start_tm) / this.duration;
bf54c0408d35 Use wall time to compute percentage of an animation action
Thinker K.F. Li <thinker@codemud.net>
parents: 805
diff changeset
16 if(percent >= 1) {
bf54c0408d35 Use wall time to compute percentage of an animation action
Thinker K.F. Li <thinker@codemud.net>
parents: 805
diff changeset
17 percent = 1;
844
3c48a77b75d3 USe obj.x and obj.y to implement the linear animation
wycc
parents: 831
diff changeset
18 if (this.obj.timer) {
3c48a77b75d3 USe obj.x and obj.y to implement the linear animation
wycc
parents: 831
diff changeset
19 this.obj.timer.stop();
3c48a77b75d3 USe obj.x and obj.y to implement the linear animation
wycc
parents: 831
diff changeset
20 delete this.obj.timer;
3c48a77b75d3 USe obj.x and obj.y to implement the linear animation
wycc
parents: 831
diff changeset
21 }
795
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
22 }
844
3c48a77b75d3 USe obj.x and obj.y to implement the linear animation
wycc
parents: 831
diff changeset
23 this.obj.x = (this.targetx-this.startposx)*percent+this.startposx;
3c48a77b75d3 USe obj.x and obj.y to implement the linear animation
wycc
parents: 831
diff changeset
24 this.obj.y = (this.targety-this.startposy)*percent+this.startposy;
795
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
25 this.app.refresh();
727
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
26 }
795
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
27
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
28 function linear_draw_start() {
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
29 var obj = this.obj;
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
30 var self = this;
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
31
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
32 if(obj.timer)
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
33 obj.timer.stop();
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
34
804
55875133fa60 Compare performance of setInterval() and setTimeout()
Thinker K.F. Li <thinker@codemud.net>
parents: 798
diff changeset
35 this._start_tm = Date.now();
806
bf54c0408d35 Use wall time to compute percentage of an animation action
Thinker K.F. Li <thinker@codemud.net>
parents: 805
diff changeset
36 obj.timer = setInterval(function() { self.draw(); }, frame_interval);
795
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
37 }
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
38
798
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
39 function linear(app,obj,shiftx,shifty,duration) {
794
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
40 obj.animated_linear = this;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
41 this.app = app;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
42 this.obj = obj;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
43 this.end = 0;
844
3c48a77b75d3 USe obj.x and obj.y to implement the linear animation
wycc
parents: 831
diff changeset
44 this.targetx = shiftx + obj.x;
3c48a77b75d3 USe obj.x and obj.y to implement the linear animation
wycc
parents: 831
diff changeset
45 this.targety = shifty + obj.y;
3c48a77b75d3 USe obj.x and obj.y to implement the linear animation
wycc
parents: 831
diff changeset
46 this.startposx = obj.x;
3c48a77b75d3 USe obj.x and obj.y to implement the linear animation
wycc
parents: 831
diff changeset
47 this.startposy = obj.y;
794
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
48 this.duration = duration*1000;
727
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
49 }
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
50
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
51 exports.linear = linear;
795
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
52 linear.prototype.start = linear_draw_start;
727
468cd504800c Rewrite the animation as a module.
wycc
parents:
diff changeset
53 linear.prototype.draw = linear_draw;
758
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
54
798
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
55 /* ------------------------------------------------------------ */
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
56 function rotate(app, obj, ang, duration) {
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
57 this._app = app;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
58 this._obj = obj;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
59 this._ang = ang;
806
bf54c0408d35 Use wall time to compute percentage of an animation action
Thinker K.F. Li <thinker@codemud.net>
parents: 805
diff changeset
60 this._duration = duration * 1000;
798
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
61 }
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
62
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
63 function rotate_start() {
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
64 var obj = this._obj;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
65 var self = this;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
66
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
67 this._start_mtx = [obj[0], obj[1], obj[2], obj[3], obj[4], obj[5]];
806
bf54c0408d35 Use wall time to compute percentage of an animation action
Thinker K.F. Li <thinker@codemud.net>
parents: 805
diff changeset
68 this._start_tm = Date.now();
798
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
69 obj.timer = setInterval(function() { self.draw(); }, frame_interval);
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
70 }
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
71
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
72 function rotate_draw() {
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
73 var percent;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
74 var ang;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
75 var sv, cv;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
76 var obj = this._obj;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
77 var mtx, shift;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
78
806
bf54c0408d35 Use wall time to compute percentage of an animation action
Thinker K.F. Li <thinker@codemud.net>
parents: 805
diff changeset
79 percent = (Date.now() - this._start_tm) / this._duration;
bf54c0408d35 Use wall time to compute percentage of an animation action
Thinker K.F. Li <thinker@codemud.net>
parents: 805
diff changeset
80 if(percent >= 1) {
798
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
81 percent = 1;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
82 obj.timer.stop();
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
83 }
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
84
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
85 ang = percent * this._ang;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
86 sv = Math.sin(ang);
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
87 cv = Math.cos(ang);
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
88 mtx = [cv, -sv, 0, sv, cv, 0];
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
89
808
9b6c26cf9102 Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents: 806
diff changeset
90 shift = [1, 0, -obj.center.x, 0, 1, -obj.center.y];
798
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
91 mtx = multiply(mtx, shift);
808
9b6c26cf9102 Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents: 806
diff changeset
92 shift = [1, 0, obj.center.x, 0, 1, obj.center.y];
798
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
93 mtx = multiply(shift, mtx);
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
94 mtx = multiply(mtx, this._start_mtx);
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
95
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
96 obj[0] = mtx[0];
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
97 obj[1] = mtx[1];
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
98 obj[2] = mtx[2];
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
99 obj[3] = mtx[3];
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
100 obj[4] = mtx[4];
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
101 obj[5] = mtx[5];
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
102
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
103 this._app.refresh();
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
104 }
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
105
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
106 rotate.prototype.start = rotate_start;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
107 rotate.prototype.draw = rotate_draw;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
108 exports.rotate = rotate;
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
109
758
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
110 function multiply(s,d) {
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
111 var m=[];
794
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
112 m[0] = s[0]*d[0]+s[1]*d[3];
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
113 m[1] = s[0]*d[1]+s[1]*d[4];
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
114 m[2] = s[0]*d[2]+s[1]*d[5]+s[2];
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
115 m[3] = s[3]*d[0]+s[4]*d[3];
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
116 m[4] = s[3]*d[1]+s[4]*d[4];
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
117 m[5] = s[3]*d[2]+s[4]*d[5]+s[5];
798
210e4d24a3ba Change linear to relative location shifting and add rotate
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
118 return m;
758
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
119 }
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
120
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
121
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
122 function scale_draw() {
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
123 if (this.end == 1) return;
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
124 var percent = (Date.now() - this.starttime)/this.duration;
794
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
125 if (percent > 1) percent = 1;
758
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
126 var sx = (this.targetx-this.startsx)*percent+this.startsx;
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
127 var sy = (this.targety-this.startsy)*percent+this.startsy;
794
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
128 var t=[sx,0,0,0,sy,0];
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
129 this.obj[0] = sx;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
130 this.obj[4] = sy;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
131 this.obj[2] = this.origin_offset_x - (sx-this.startsx)*this.obj.center.x;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
132 this.obj[5] = this.origin_offset_y - (sy-this.startsy)*this.obj.center.y;
758
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
133
794
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
134 this.app.refresh();
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
135 var self = this;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
136 if (percent < 1) {
844
3c48a77b75d3 USe obj.x and obj.y to implement the linear animation
wycc
parents: 831
diff changeset
137 this.obj.timer=setTimeout(function() { self.draw();}, frame_interval);
794
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
138 return;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
139 }
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
140 this.app.refresh();
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
141 this.obj.animated_scale = null;
758
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
142 }
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
143
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
144 function scale(app,obj,targetx,targety, duration) {
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
145 try {
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
146 if (obj.animated_scale) {
794
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
147 //obj[0] = obj.animated_scale.targetx;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
148 //obj[4] = obj.animated_scale.targety;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
149 //obj[2] = obj.animated_scale.final_offset_x;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
150 //obj[5] = obj.aninated_scale.final_offset_y;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
151 obj.animated_scale.end = 1;
758
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
152 }
794
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
153 } catch(e) {
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
154
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
155 }
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
156 obj.animated_scale = this;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
157 this.app = app;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
158 this.obj = obj;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
159 this.end = 0;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
160 this.starttime = Date.now();
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
161 this.startsx = obj[0];
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
162 this.startsy = obj[4];
758
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
163 this.targetx = targetx;
794
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
164 this.targety = targety;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
165 this.duration = duration*1000;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
166 this.origin_offset_x = obj[2];
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
167 this.origin_offset_y = obj[5];
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
168 this.final_offset_x = this.origin_offset_x-(targetx-this.startsx)*obj.center.x;
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 788
diff changeset
169 this.final_offset_y = this.origin_offset_y-(targety-this.startsy)*obj.center.y;
758
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
170 }
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
171
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
172
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
173 exports.scale = scale;
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
174 scale.prototype.start = scale_draw;
d11b0900f03c Check in the dynamic menu example. Currently, it illustarte a bug in the renderer.
wycc
parents: 728
diff changeset
175 scale.prototype.draw = scale_draw;
788
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
176
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
177 function holder(app, coord) {
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
178 var mtx = [coord[0], coord[1], coord[2], coord[3], coord[4], coord[5]];
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
179
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
180 this._mtx = mtx;
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
181 this._coord = coord;
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
182 this._app = app;
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
183 }
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
184
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
185 holder.prototype = {
808
9b6c26cf9102 Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents: 806
diff changeset
186 go: function(pos) {
788
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
187 var sx, sy;
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
188
808
9b6c26cf9102 Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents: 806
diff changeset
189 sx = pos.x - this._coord.center.x;
9b6c26cf9102 Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents: 806
diff changeset
190 sy = pos.y - this._coord.center.y;
788
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
191 this.shift(sx, sy);
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
192 },
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
193
808
9b6c26cf9102 Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents: 806
diff changeset
194 go_center: function(o) {
9b6c26cf9102 Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents: 806
diff changeset
195 this.go(o.center);
9b6c26cf9102 Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents: 806
diff changeset
196 },
9b6c26cf9102 Move bounding box and center back to an object
Thinker K.F. Li <thinker@codemud.net>
parents: 806
diff changeset
197
788
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
198 home: function() {
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
199 this._coord[2] = this._mtx[2];
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
200 this._coord[5] = this._mtx[5];
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
201 this._app.refresh();
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
202 },
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
203
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
204 shift: function(sx, sy) {
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
205 this._coord[2] = this._mtx[2] + sx;
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
206 this._coord[5] = this._mtx[5] + sy;
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
207 this._app.refresh();
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
208 }
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
209 };
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
210
7ec13634c97d Add holder for animate
Thinker K.F. Li <thinker@codemud.net>
parents: 776
diff changeset
211 exports.holder = holder;
831
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
212
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
213
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
214
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
215 function alpha_draw() {
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
216
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
217 if (this.end == 1) return;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
218 var percent = (Date.now() - this.starttime)/this.duration;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
219 if (percent > 1) percent = 1;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
220 var sx = (this.targetalpha-this.startalpha)*percent+this.startalpha;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
221 this.obj.opacity=sx;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
222
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
223 this.app.refresh();
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
224 var self = this;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
225 if (percent < 1) {
844
3c48a77b75d3 USe obj.x and obj.y to implement the linear animation
wycc
parents: 831
diff changeset
226 this.obj.timer=setTimeout(function() { self.draw();}, frame_interval);
831
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
227 return;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
228 }
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
229 this.app.refresh();
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
230 this.obj.animated_alpha = null;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
231 }
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
232
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
233 function alpha(app,obj,alpha, duration) {
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
234 try {
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
235 if (obj.animated_alpha) {
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
236 obj.animated_alpha.end = 1;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
237 }
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
238 } catch(e) {
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
239
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
240 }
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
241 obj.animated_alpha = this;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
242 this.app = app;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
243 this.obj = obj;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
244 this.end = 0;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
245 this.starttime = Date.now();
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
246 this.startalpha = obj.opacity;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
247 this.targetalpha = alpha;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
248 this.duration = duration*1000;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
249 }
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
250
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
251 alpha.prototype.start = alpha_draw;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
252 alpha.prototype.draw = alpha_draw;
904b6928f727 Add animation.alpha
wycc
parents: 822
diff changeset
253 exports.alpha = alpha;