1 /****************************************************************************
  2  Copyright (c) 2010-2012 cocos2d-x.org
  3 
  4  http://www.cocos2d-x.org
  5 
  6  Permission is hereby granted, free of charge, to any person obtaining a copy
  7  of this software and associated documentation files (the "Software"), to deal
  8  in the Software without restriction, including without limitation the rights
  9  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 10  copies of the Software, and to permit persons to whom the Software is
 11  furnished to do so, subject to the following conditions:
 12 
 13  The above copyright notice and this permission notice shall be included in
 14  all copies or substantial portions of the Software.
 15 
 16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 21  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 22  THE SOFTWARE.
 23  ****************************************************************************/
 24 
 25 /**
 26  * LinearGravity
 27  * @type {Object}
 28  */
 29 ccs.LinearGravity = {
 30     none: 0,
 31     left: 1,
 32     top: 2,
 33     right: 3,
 34     bottom: 4,
 35     centerVertical: 5,
 36     centerHorizontal: 6
 37 };
 38 
 39 /**
 40  * RelativeAlign
 41  * @type {Object}
 42  */
 43 ccs.RelativeAlign = {
 44     alignNone: 0,
 45     alignParentTopLeft: 1,
 46     alignParentTopCenterHorizontal: 2,
 47     alignParentTopRight: 3,
 48     alignParentLeftCenterVertical: 4,
 49     centerInParent: 5,
 50     alignParentRightCenterVertical: 6,
 51     alignParentLeftBottom: 7,
 52     alignParentBottomCenterHorizontal: 8,
 53     alignParentRightBottom: 9,
 54     locationAboveLeftAlign: 10,
 55     locationAboveCenter: 11,
 56     locationAboveRightAlign: 12,
 57     locationLeftOfTopAlign: 13,
 58     locationLeftOfCenter: 14,
 59     locationLeftOfBottomAlign: 15,
 60     locationRightOfTopAlign: 16,
 61     locationRightOfCenter: 17,
 62     locationRightOfBottomAlign: 18,
 63     locationBelowLeftAlign: 19,
 64     locationBelowCenter: 20,
 65     locationBelowRightAlign: 21
 66 };
 67 
 68 /**
 69  * Base class for ccs.Margin
 70  * @class
 71  * @extends ccs.Class
 72  */
 73 ccs.Margin = ccs.Class.extend(/** @lends ccs.Margin# */{
 74     left: 0,
 75     top: 0,
 76     right: 0,
 77     bottom: 0,
 78     ctor: function (margin, top, right, bottom) {
 79         if (margin && top === undefined) {
 80             this.left = margin.left;
 81             this.top = margin.top;
 82             this.right = margin.right;
 83             this.bottom = margin.bottom;
 84         }
 85         if (bottom !== undefined) {
 86             this.left = margin;
 87             this.top = top;
 88             this.right = right;
 89             this.bottom = bottom;
 90         }
 91     },
 92     /**
 93      *  set margin
 94      * @param {Number} l
 95      * @param {Number} t
 96      * @param {Number} r
 97      * @param {Number} b
 98      */
 99     setMargin: function (l, t, r, b) {
100         this.left = l;
101         this.top = t;
102         this.right = r;
103         this.bottom = b;
104     },
105     /**
106      *  check is equals
107      * @param {ccs.Margin} target
108      * @returns {boolean}
109      */
110     equals: function (target) {
111         return (this.left == target.left && this.top == target.top && this.right == target.right && this.bottom == target.bottom);
112     }
113 });
114 
115 ccs.MarginZero = function(){
116    return new ccs.Margin(0,0,0,0);
117 };