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  * layout parameter type
 27  * @type {Object}
 28  */
 29 ccs.LayoutParameterType = {
 30     none: 0,
 31     linear: 1,
 32     relative: 2
 33 };
 34 
 35 /**
 36  * Base class for ccs.LayoutParameter
 37  * @class
 38  * @extends ccs.Class
 39  */
 40 ccs.LayoutParameter = ccs.Class.extend(/** @lends ccs.LayoutParameter# */{
 41     _margin: null,
 42     _layoutParameterType: null,
 43     ctor: function () {
 44         this._margin = new ccs.Margin();
 45         this._layoutParameterType = ccs.LayoutParameterType.none;
 46     },
 47 
 48     /**
 49      * Sets Margin parameter for LayoutParameter.
 50      * @param {ccs.Margin} margin
 51      */
 52     setMargin: function (margin) {
 53         this._margin = margin;
 54     },
 55 
 56     /**
 57      * Gets Margin parameter of LayoutParameter.
 58      * @returns {ccs.Margin}
 59      */
 60     getMargin: function () {
 61         return this._margin;
 62     },
 63 
 64     /**
 65      * Gets LayoutParameterType of LayoutParameter.
 66      * @returns {ccs.UILayoutParameterType}
 67      */
 68     getLayoutType: function () {
 69         return this._layoutParameterType;
 70     }
 71 });
 72 
 73 /**
 74  * allocates and initializes a LayoutParameter.
 75  * @constructs
 76  * @return {ccs.LayoutParameter}
 77  * @example
 78  * // example
 79  * var uiLayoutParameter = ccs.LayoutParameter.create();
 80  */
 81 ccs.LayoutParameter.create = function () {
 82     var parameter = new ccs.LayoutParameter();
 83     return parameter;
 84 };
 85 
 86 /**
 87  * Base class for ccs.LinearLayoutParameter
 88  * @class
 89  * @extends ccs.LayoutParameter
 90  */
 91 ccs.LinearLayoutParameter = ccs.LayoutParameter.extend(/** @lends ccs.LinearLayoutParameter# */{
 92     _linearGravity: null,
 93     ctor: function () {
 94         ccs.LayoutParameter.prototype.ctor.call(this);
 95         this._linearGravity = ccs.LinearGravity.none;
 96         this._layoutParameterType = ccs.LayoutParameterType.linear;
 97     },
 98 
 99     /**
100      * Sets LinearGravity parameter for LayoutParameter.
101      * @param {ccs.LinearGravity} gravity
102      */
103     setGravity: function (gravity) {
104         this._linearGravity = gravity;
105     },
106 
107     /**
108      * Gets LinearGravity parameter for LayoutParameter.
109      * @returns {ccs.LinearGravity}
110      */
111     getGravity: function () {
112         return this._linearGravity;
113     }
114 });
115 
116 /**
117  * allocates and initializes a LinearLayoutParameter.
118  * @constructs
119  * @return {ccs.LinearLayoutParameter}
120  * @example
121  * // example
122  * var uiLinearLayoutParameter = ccs.LinearLayoutParameter.create();
123  */
124 ccs.LinearLayoutParameter.create = function () {
125     var parameter = new ccs.LinearLayoutParameter();
126     return parameter;
127 };
128 
129 /**
130  * Base class for ccs.RelativeLayoutParameter
131  * @class
132  * @extends ccs.LayoutParameter
133  */
134 ccs.RelativeLayoutParameter = ccs.LayoutParameter.extend(/** @lends ccs.RelativeLayoutParameter# */{
135     _relativeAlign: null,
136     _relativeWidgetName: "",
137     _relativeLayoutName: "",
138     _put:false,
139     ctor: function () {
140         ccs.LayoutParameter.prototype.ctor.call(this);
141         this._relativeAlign = ccs.RelativeAlign.alignNone;
142         this._relativeWidgetName = "";
143         this._relativeLayoutName = "";
144         this._put = false;
145         this._layoutParameterType = ccs.LayoutParameterType.relative;
146     },
147 
148     /**
149      * Sets RelativeAlign parameter for LayoutParameter.
150      * @param {ccs.RelativeAlign} align
151      */
152     setAlign: function (align) {
153         this._relativeAlign = align;
154     },
155 
156     /**
157      * Gets RelativeAlign parameter for LayoutParameter.
158      * @returns {ccs.RelativeAlign}
159      */
160     getAlign: function () {
161         return this._relativeAlign;
162     },
163 
164     /**
165      * Sets a key for LayoutParameter. Witch widget named this is relative to.
166      * @param {String} name
167      */
168     setRelativeToWidgetName: function (name) {
169         this._relativeWidgetName = name;
170     },
171 
172     /**
173      * Gets the key of LayoutParameter. Witch widget named this is relative to.
174      * @returns {string}
175      */
176     getRelativeToWidgetName: function () {
177         return this._relativeWidgetName;
178     },
179 
180     /**
181      * Sets a name in Relative Layout for LayoutParameter.
182      * @param {String} name
183      */
184     setRelativeName: function (name) {
185         this._relativeLayoutName = name;
186     },
187 
188     /**
189      * Gets a name in Relative Layout of LayoutParameter.
190      * @returns {string}
191      */
192     getRelativeName: function () {
193         return this._relativeLayoutName;
194     }
195 });
196 
197 /**
198  * allocates and initializes a RelativeLayoutParameter.
199  * @constructs
200  * @return {ccs.RelativeLayoutParameter}
201  * @example
202  * // example
203  * var uiRelativeLayoutParameter = ccs.RelativeLayoutParameter.create();
204  */
205 ccs.RelativeLayoutParameter.create = function () {
206     var parameter = new ccs.RelativeLayoutParameter();
207     return parameter;
208 };