Sprite.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/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. This class represents an animation target for a {@link Ext.draw.Sprite}. In general this class will not be
  21. created directly, the {@link Ext.draw.Sprite} will be passed to the animation and
  22. and the appropriate target will be created.
  23. * @markdown
  24. */
  25. Ext.define('Ext.fx.target.Sprite', {
  26. /* Begin Definitions */
  27. extend: 'Ext.fx.target.Target',
  28. /* End Definitions */
  29. type: 'draw',
  30. getFromPrim: function (sprite, attr) {
  31. var obj;
  32. switch (attr) {
  33. case 'rotate':
  34. case 'rotation':
  35. obj = sprite.attr.rotation;
  36. return {
  37. x: obj.x || 0,
  38. y: obj.y || 0,
  39. degrees: obj.degrees || 0
  40. };
  41. case 'scale':
  42. case 'scaling':
  43. obj = sprite.attr.scaling;
  44. return {
  45. x: obj.x || 1,
  46. y: obj.y || 1,
  47. cx: obj.cx || 0,
  48. cy: obj.cy || 0
  49. };
  50. case 'translate':
  51. case 'translation':
  52. obj = sprite.attr.translation;
  53. return {
  54. x: obj.x || 0,
  55. y: obj.y || 0
  56. };
  57. default:
  58. return sprite.attr[attr];
  59. }
  60. },
  61. getAttr: function (attr, val) {
  62. return [
  63. [this.target, val != undefined ? val : this.getFromPrim(this.target, attr)]
  64. ];
  65. },
  66. setAttr: function (targetData) {
  67. var ln = targetData.length,
  68. spriteArr = [],
  69. attrsConf, attr, attrArr, attrs, sprite, idx, value, i, j, x, y, ln2;
  70. for (i = 0; i &lt; ln; i++) {
  71. attrsConf = targetData[i].attrs;
  72. for (attr in attrsConf) {
  73. attrArr = attrsConf[attr];
  74. ln2 = attrArr.length;
  75. for (j = 0; j &lt; ln2; j++) {
  76. sprite = attrArr[j][0];
  77. attrs = attrArr[j][1];
  78. if (attr === 'translate' || attr === 'translation') {
  79. value = {
  80. x: attrs.x,
  81. y: attrs.y
  82. };
  83. }
  84. else if (attr === 'rotate' || attr === 'rotation') {
  85. x = attrs.x;
  86. if (isNaN(x)) {
  87. x = null;
  88. }
  89. y = attrs.y;
  90. if (isNaN(y)) {
  91. y = null;
  92. }
  93. value = {
  94. degrees: attrs.degrees,
  95. x: x,
  96. y: y
  97. };
  98. } else if (attr === 'scale' || attr === 'scaling') {
  99. x = attrs.x;
  100. if (isNaN(x)) {
  101. x = null;
  102. }
  103. y = attrs.y;
  104. if (isNaN(y)) {
  105. y = null;
  106. }
  107. value = {
  108. x: x,
  109. y: y,
  110. cx: attrs.cx,
  111. cy: attrs.cy
  112. };
  113. }
  114. else if (attr === 'width' || attr === 'height' || attr === 'x' || attr === 'y') {
  115. value = parseFloat(attrs);
  116. }
  117. else {
  118. value = attrs;
  119. }
  120. idx = Ext.Array.indexOf(spriteArr, sprite);
  121. if (idx == -1) {
  122. spriteArr.push([sprite, {}]);
  123. idx = spriteArr.length - 1;
  124. }
  125. spriteArr[idx][1][attr] = value;
  126. }
  127. }
  128. }
  129. ln = spriteArr.length;
  130. for (i = 0; i &lt; ln; i++) {
  131. spriteArr[i][0].setAttributes(spriteArr[i][1]);
  132. }
  133. this.target.redraw();
  134. }
  135. });
  136. </pre>
  137. </body>
  138. </html>