]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | /**\r |
2 | * @private\r | |
3 | */\r | |
4 | Ext.define('Ext.util.Offset', {\r | |
5 | \r | |
6 | /* Begin Definitions */\r | |
7 | \r | |
8 | statics: {\r | |
9 | fromObject: function(obj) {\r | |
10 | return new this(obj.x, obj.y);\r | |
11 | }\r | |
12 | },\r | |
13 | \r | |
14 | /* End Definitions */\r | |
15 | \r | |
16 | constructor: function(x, y) {\r | |
17 | this.x = (x != null && !isNaN(x)) ? x : 0;\r | |
18 | this.y = (y != null && !isNaN(y)) ? y : 0;\r | |
19 | \r | |
20 | return this;\r | |
21 | },\r | |
22 | \r | |
23 | copy: function() {\r | |
24 | return new Ext.util.Offset(this.x, this.y);\r | |
25 | },\r | |
26 | \r | |
27 | copyFrom: function(p) {\r | |
28 | this.x = p.x;\r | |
29 | this.y = p.y;\r | |
30 | },\r | |
31 | \r | |
32 | toString: function() {\r | |
33 | return "Offset[" + this.x + "," + this.y + "]";\r | |
34 | },\r | |
35 | \r | |
36 | equals: function(offset) {\r | |
37 | //<debug>\r | |
38 | if(!(offset instanceof this.statics())) {\r | |
39 | Ext.raise('Offset must be an instance of Ext.util.Offset');\r | |
40 | }\r | |
41 | //</debug>\r | |
42 | \r | |
43 | return (this.x == offset.x && this.y == offset.y);\r | |
44 | },\r | |
45 | \r | |
46 | round: function(to) {\r | |
47 | if (!isNaN(to)) {\r | |
48 | var factor = Math.pow(10, to);\r | |
49 | this.x = Math.round(this.x * factor) / factor;\r | |
50 | this.y = Math.round(this.y * factor) / factor;\r | |
51 | } else {\r | |
52 | this.x = Math.round(this.x);\r | |
53 | this.y = Math.round(this.y);\r | |
54 | }\r | |
55 | },\r | |
56 | \r | |
57 | isZero: function() {\r | |
58 | return this.x == 0 && this.y == 0;\r | |
59 | }\r | |
60 | });\r |