Upgrade to ExtJS 3.3.0 - Released 10/06/2010
[extjs.git] / docs / source / ext-base-region.html
1 <html>
2 <head>
3   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
4   <title>The source code</title>
5     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 </head>
8 <body  onload="prettyPrint();">
9     <pre class="prettyprint lang-js">/*!
10  * Ext JS Library 3.3.0
11  * Copyright(c) 2006-2010 Ext JS, Inc.
12  * licensing@extjs.com
13  * http://www.extjs.com/license
14  */
15         Ext.lib.Region = function(t, r, b, l) {
16                 var me = this;
17         me.top = t;
18         me[1] = t;
19         me.right = r;
20         me.bottom = b;
21         me.left = l;
22         me[0] = l;
23     };
24
25     Ext.lib.Region.prototype = {
26         contains : function(region) {
27                 var me = this;
28             return ( region.left >= me.left &&
29                      region.right <= me.right &&
30                      region.top >= me.top &&
31                      region.bottom <= me.bottom );
32
33         },
34
35         getArea : function() {
36                 var me = this;
37             return ( (me.bottom - me.top) * (me.right - me.left) );
38         },
39
40         intersect : function(region) {
41             var me = this,
42                 t = Math.max(me.top, region.top),
43                 r = Math.min(me.right, region.right),
44                 b = Math.min(me.bottom, region.bottom),
45                 l = Math.max(me.left, region.left);
46
47             if (b >= t && r >= l) {
48                 return new Ext.lib.Region(t, r, b, l);
49             }
50         },
51         
52         union : function(region) {
53                 var me = this,
54                 t = Math.min(me.top, region.top),
55                 r = Math.max(me.right, region.right),
56                 b = Math.max(me.bottom, region.bottom),
57                 l = Math.min(me.left, region.left);
58
59             return new Ext.lib.Region(t, r, b, l);
60         },
61
62         constrainTo : function(r) {
63                 var me = this;
64             me.top = me.top.constrain(r.top, r.bottom);
65             me.bottom = me.bottom.constrain(r.top, r.bottom);
66             me.left = me.left.constrain(r.left, r.right);
67             me.right = me.right.constrain(r.left, r.right);
68             return me;
69         },
70
71         adjust : function(t, l, b, r) {
72                 var me = this;
73             me.top += t;
74             me.left += l;
75             me.right += r;
76             me.bottom += b;
77             return me;
78         }
79     };
80
81     Ext.lib.Region.getRegion = function(el) {
82         var p = Ext.lib.Dom.getXY(el),
83                 t = p[1],
84                 r = p[0] + el.offsetWidth,
85                 b = p[1] + el.offsetHeight,
86                 l = p[0];
87
88         return new Ext.lib.Region(t, r, b, l);
89     };</pre>    
90 </body>
91 </html>