Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / docs / source / Sprite.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5   <title>The source code</title>
6   <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7   <script type="text/javascript" src="../prettify/prettify.js"></script>
8   <style type="text/css">
9     .highlight { display: block; background-color: #ddd; }
10   </style>
11   <script type="text/javascript">
12     function highlight() {
13       document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
14     }
15   </script>
16 </head>
17 <body onload="prettyPrint(); highlight();">
18   <pre class="prettyprint lang-js"><span id='Ext-fx-target-Sprite'>/**
19 </span> * @class Ext.fx.target.Sprite
20  * @extends Ext.fx.target.Target
21
22 This class represents a animation target for a {@link Ext.draw.Sprite}. In general this class will not be
23 created directly, the {@link Ext.draw.Sprite} will be passed to the animation and
24 and the appropriate target will be created.
25
26  * @markdown
27  */
28
29 Ext.define('Ext.fx.target.Sprite', {
30
31     /* Begin Definitions */
32
33     extend: 'Ext.fx.target.Target',
34
35     /* End Definitions */
36
37     type: 'draw',
38
39     getFromPrim: function(sprite, attr) {
40         var o;
41         if (attr == 'translate') {
42             o = {
43                 x: sprite.attr.translation.x || 0,
44                 y: sprite.attr.translation.y || 0
45             };
46         }
47         else if (attr == 'rotate') {
48             o = {
49                 degrees: sprite.attr.rotation.degrees || 0,
50                 x: sprite.attr.rotation.x,
51                 y: sprite.attr.rotation.y
52             };
53         }
54         else {
55             o = sprite.attr[attr];
56         }
57         return o;
58     },
59
60     getAttr: function(attr, val) {
61         return [[this.target, val != undefined ? val : this.getFromPrim(this.target, attr)]];
62     },
63
64     setAttr: function(targetData) {
65         var ln = targetData.length,
66             spriteArr = [],
67             attrs, attr, attrArr, attPtr, spritePtr, idx, value, i, j, x, y, ln2;
68         for (i = 0; i &lt; ln; i++) {
69             attrs = targetData[i].attrs;
70             for (attr in attrs) {
71                 attrArr = attrs[attr];
72                 ln2 = attrArr.length;
73                 for (j = 0; j &lt; ln2; j++) {
74                     spritePtr = attrArr[j][0];
75                     attPtr = attrArr[j][1];
76                     if (attr === 'translate') {
77                         value = {
78                             x: attPtr.x,
79                             y: attPtr.y
80                         };
81                     }
82                     else if (attr === 'rotate') {
83                         x = attPtr.x;
84                         if (isNaN(x)) {
85                             x = null;
86                         }
87                         y = attPtr.y;
88                         if (isNaN(y)) {
89                             y = null;
90                         }
91                         value = {
92                             degrees: attPtr.degrees,
93                             x: x,
94                             y: y
95                         };
96                     }
97                     else if (attr === 'width' || attr === 'height' || attr === 'x' || attr === 'y') {
98                         value = parseFloat(attPtr);
99                     }
100                     else {
101                         value = attPtr;
102                     }
103                     idx = Ext.Array.indexOf(spriteArr, spritePtr);
104                     if (idx == -1) {
105                         spriteArr.push([spritePtr, {}]);
106                         idx = spriteArr.length - 1;
107                     }
108                     spriteArr[idx][1][attr] = value;
109                 }
110             }
111         }
112         ln = spriteArr.length;
113         for (i = 0; i &lt; ln; i++) {
114             spritePtr = spriteArr[i];
115             spritePtr[0].setAttributes(spritePtr[1]);
116         }
117         this.target.redraw();
118     }
119 });
120 </pre>
121 </body>
122 </html>