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