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.left = margin.left;
 54         this._margin.top = margin.top;
 55         this._margin.right = margin.right;
 56         this._margin.bottom = margin.bottom;
 57     },
 58 
 59     /**
 60      * Gets Margin parameter of LayoutParameter.
 61      * @returns {ccs.Margin}
 62      */
 63     getMargin: function () {
 64         return this._margin;
 65     },
 66 
 67     /**
 68      * Gets LayoutParameterType of LayoutParameter.
 69      * @returns {ccs.UILayoutParameterType}
 70      */
 71     getLayoutType: function () {
 72         return this._layoutParameterType;
 73     },
 74 
 75     clone:function(){
 76         var parameter = this.createCloneInstance();
 77         parameter.copyProperties(this);
 78         return parameter;
 79     },
 80 
 81     /**
 82      * create clone instance.
 83      * @returns {ccs.LayoutParameter}
 84      */
 85     createCloneInstance:function(){
 86         return ccs.LayoutParameter.create();
 87     },
 88 
 89     /**
 90      * copy properties
 91      * @param {ccs.LayoutParameter} model
 92      */
 93     copyProperties:function(model){
 94         this._margin.left = model._margin.left;
 95         this._margin.top = model._margin.top;
 96         this._margin.right = model._margin.right;
 97         this._margin.bottom = model._margin.bottom;
 98     }
 99 });
100 
101 /**
102  * allocates and initializes a LayoutParameter.
103  * @constructs
104  * @return {ccs.LayoutParameter}
105  * @example
106  * // example
107  * var uiLayoutParameter = ccs.LayoutParameter.create();
108  */
109 ccs.LayoutParameter.create = function () {
110     var parameter = new ccs.LayoutParameter();
111     return parameter;
112 };
113 
114 /**
115  * Base class for ccs.LinearLayoutParameter
116  * @class
117  * @extends ccs.LayoutParameter
118  */
119 ccs.LinearLayoutParameter = ccs.LayoutParameter.extend(/** @lends ccs.LinearLayoutParameter# */{
120     _linearGravity: null,
121     ctor: function () {
122         ccs.LayoutParameter.prototype.ctor.call(this);
123         this._linearGravity = ccs.LinearGravity.none;
124         this._layoutParameterType = ccs.LayoutParameterType.linear;
125     },
126 
127     /**
128      * Sets LinearGravity parameter for LayoutParameter.
129      * @param {ccs.LinearGravity} gravity
130      */
131     setGravity: function (gravity) {
132         this._linearGravity = gravity;
133     },
134 
135     /**
136      * Gets LinearGravity parameter for LayoutParameter.
137      * @returns {ccs.LinearGravity}
138      */
139     getGravity: function () {
140         return this._linearGravity;
141     },
142 
143     /**
144      * create clone instance.
145      * @returns {ccs.LinearLayoutParameter}
146      */
147     createCloneInstance: function () {
148         return ccs.LinearLayoutParameter.create();
149     },
150 
151     /**
152      * copy properties
153      * @param {ccs.LinearLayoutParameter} model
154      */
155     copyProperties: function (model) {
156         ccs.LayoutParameter.prototype.copyProperties.call(this, model);
157         this.setGravity(model._linearGravity);
158     }
159 });
160 
161 /**
162  * allocates and initializes a LinearLayoutParameter.
163  * @constructs
164  * @return {ccs.LinearLayoutParameter}
165  * @example
166  * // example
167  * var uiLinearLayoutParameter = ccs.LinearLayoutParameter.create();
168  */
169 ccs.LinearLayoutParameter.create = function () {
170     var parameter = new ccs.LinearLayoutParameter();
171     return parameter;
172 };
173 
174 /**
175  * Base class for ccs.RelativeLayoutParameter
176  * @class
177  * @extends ccs.LayoutParameter
178  */
179 ccs.RelativeLayoutParameter = ccs.LayoutParameter.extend(/** @lends ccs.RelativeLayoutParameter# */{
180     _relativeAlign: null,
181     _relativeWidgetName: "",
182     _relativeLayoutName: "",
183     _put:false,
184     ctor: function () {
185         ccs.LayoutParameter.prototype.ctor.call(this);
186         this._relativeAlign = ccs.RelativeAlign.alignNone;
187         this._relativeWidgetName = "";
188         this._relativeLayoutName = "";
189         this._put = false;
190         this._layoutParameterType = ccs.LayoutParameterType.relative;
191     },
192 
193     /**
194      * Sets RelativeAlign parameter for LayoutParameter.
195      * @param {ccs.RelativeAlign} align
196      */
197     setAlign: function (align) {
198         this._relativeAlign = align;
199     },
200 
201     /**
202      * Gets RelativeAlign parameter for LayoutParameter.
203      * @returns {ccs.RelativeAlign}
204      */
205     getAlign: function () {
206         return this._relativeAlign;
207     },
208 
209     /**
210      * Sets a key for LayoutParameter. Witch widget named this is relative to.
211      * @param {String} name
212      */
213     setRelativeToWidgetName: function (name) {
214         this._relativeWidgetName = name;
215     },
216 
217     /**
218      * Gets the key of LayoutParameter. Witch widget named this is relative to.
219      * @returns {string}
220      */
221     getRelativeToWidgetName: function () {
222         return this._relativeWidgetName;
223     },
224 
225     /**
226      * Sets a name in Relative Layout for LayoutParameter.
227      * @param {String} name
228      */
229     setRelativeName: function (name) {
230         this._relativeLayoutName = name;
231     },
232 
233     /**
234      * Gets a name in Relative Layout of LayoutParameter.
235      * @returns {string}
236      */
237     getRelativeName: function () {
238         return this._relativeLayoutName;
239     },
240 
241     /**
242      * create clone instance.
243      * @returns {ccs.RelativeLayoutParameter}
244      */
245     createCloneInstance:function(){
246         return ccs.LinearLayoutParameter.create();
247     },
248 
249     /**
250      * copy properties
251      * @param {ccs.RelativeLayoutParameter} model
252      */
253     copyProperties:function(model){
254         ccs.LayoutParameter.prototype.copyProperties.call(this, model);
255         this.setAlign(model._relativeAlign);
256         this.setRelativeToWidgetName(model._relativeWidgetName);
257         this.setRelativeName(model._relativeLayoutName);
258     }
259 });
260 
261 /**
262  * allocates and initializes a RelativeLayoutParameter.
263  * @constructs
264  * @return {ccs.RelativeLayoutParameter}
265  * @example
266  * // example
267  * var uiRelativeLayoutParameter = ccs.RelativeLayoutParameter.create();
268  */
269 ccs.RelativeLayoutParameter.create = function () {
270     var parameter = new ccs.RelativeLayoutParameter();
271     return parameter;
272 };