1 | /*! |
---|
2 | * Ext JS Library 3.0.0 |
---|
3 | * Copyright(c) 2006-2009 Ext JS, LLC |
---|
4 | * licensing@extjs.com |
---|
5 | * http://www.extjs.com/license |
---|
6 | */ |
---|
7 | Ext.lib.Region = function(t, r, b, l) { |
---|
8 | var me = this; |
---|
9 | me.top = t; |
---|
10 | me[1] = t; |
---|
11 | me.right = r; |
---|
12 | me.bottom = b; |
---|
13 | me.left = l; |
---|
14 | me[0] = l; |
---|
15 | }; |
---|
16 | |
---|
17 | Ext.lib.Region.prototype = { |
---|
18 | contains : function(region) { |
---|
19 | var me = this; |
---|
20 | return ( region.left >= me.left && |
---|
21 | region.right <= me.right && |
---|
22 | region.top >= me.top && |
---|
23 | region.bottom <= me.bottom ); |
---|
24 | |
---|
25 | }, |
---|
26 | |
---|
27 | getArea : function() { |
---|
28 | var me = this; |
---|
29 | return ( (me.bottom - me.top) * (me.right - me.left) ); |
---|
30 | }, |
---|
31 | |
---|
32 | intersect : function(region) { |
---|
33 | var me = this, |
---|
34 | t = Math.max(me.top, region.top), |
---|
35 | r = Math.min(me.right, region.right), |
---|
36 | b = Math.min(me.bottom, region.bottom), |
---|
37 | l = Math.max(me.left, region.left); |
---|
38 | |
---|
39 | if (b >= t && r >= l) { |
---|
40 | return new Ext.lib.Region(t, r, b, l); |
---|
41 | } |
---|
42 | }, |
---|
43 | |
---|
44 | union : function(region) { |
---|
45 | var me = this, |
---|
46 | t = Math.min(me.top, region.top), |
---|
47 | r = Math.max(me.right, region.right), |
---|
48 | b = Math.max(me.bottom, region.bottom), |
---|
49 | l = Math.min(me.left, region.left); |
---|
50 | |
---|
51 | return new Ext.lib.Region(t, r, b, l); |
---|
52 | }, |
---|
53 | |
---|
54 | constrainTo : function(r) { |
---|
55 | var me = this; |
---|
56 | me.top = me.top.constrain(r.top, r.bottom); |
---|
57 | me.bottom = me.bottom.constrain(r.top, r.bottom); |
---|
58 | me.left = me.left.constrain(r.left, r.right); |
---|
59 | me.right = me.right.constrain(r.left, r.right); |
---|
60 | return me; |
---|
61 | }, |
---|
62 | |
---|
63 | adjust : function(t, l, b, r) { |
---|
64 | var me = this; |
---|
65 | me.top += t; |
---|
66 | me.left += l; |
---|
67 | me.right += r; |
---|
68 | me.bottom += b; |
---|
69 | return me; |
---|
70 | } |
---|
71 | }; |
---|
72 | |
---|
73 | Ext.lib.Region.getRegion = function(el) { |
---|
74 | var p = Ext.lib.Dom.getXY(el), |
---|
75 | t = p[1], |
---|
76 | r = p[0] + el.offsetWidth, |
---|
77 | b = p[1] + el.offsetHeight, |
---|
78 | l = p[0]; |
---|
79 | |
---|
80 | return new Ext.lib.Region(t, r, b, l); |
---|
81 | }; |
---|