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