Offset.html 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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-util-Offset'>/**
  19. </span> * @private
  20. */
  21. Ext.define('Ext.util.Offset', {
  22. /* Begin Definitions */
  23. statics: {
  24. fromObject: function(obj) {
  25. return new this(obj.x, obj.y);
  26. }
  27. },
  28. /* End Definitions */
  29. constructor: function(x, y) {
  30. this.x = (x != null &amp;&amp; !isNaN(x)) ? x : 0;
  31. this.y = (y != null &amp;&amp; !isNaN(y)) ? y : 0;
  32. return this;
  33. },
  34. copy: function() {
  35. return new Ext.util.Offset(this.x, this.y);
  36. },
  37. copyFrom: function(p) {
  38. this.x = p.x;
  39. this.y = p.y;
  40. },
  41. toString: function() {
  42. return &quot;Offset[&quot; + this.x + &quot;,&quot; + this.y + &quot;]&quot;;
  43. },
  44. equals: function(offset) {
  45. //&lt;debug&gt;
  46. if(!(offset instanceof this.statics())) {
  47. Ext.Error.raise('Offset must be an instance of Ext.util.Offset');
  48. }
  49. //&lt;/debug&gt;
  50. return (this.x == offset.x &amp;&amp; this.y == offset.y);
  51. },
  52. round: function(to) {
  53. if (!isNaN(to)) {
  54. var factor = Math.pow(10, to);
  55. this.x = Math.round(this.x * factor) / factor;
  56. this.y = Math.round(this.y * factor) / factor;
  57. } else {
  58. this.x = Math.round(this.x);
  59. this.y = Math.round(this.y);
  60. }
  61. },
  62. isZero: function() {
  63. return this.x == 0 &amp;&amp; this.y == 0;
  64. }
  65. });
  66. </pre>
  67. </body>
  68. </html>