1 /****************************************************************************
  2  Copyright (c) 2011-2012 cocos2d-x.org
  3  Copyright (c) 2013-2014 Chukong Technologies Inc.
  4 
  5  http://www.cocos2d-x.org
  6 
  7  Permission is hereby granted, free of charge, to any person obtaining a copy
  8  of this software and associated documentation files (the "Software"), to deal
  9  in the Software without restriction, including without limitation the rights
 10  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 11  copies of the Software, and to permit persons to whom the Software is
 12  furnished to do so, subject to the following conditions:
 13 
 14  The above copyright notice and this permission notice shall be included in
 15  all copies or substantial portions of the Software.
 16 
 17  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 20  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 21  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 22  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 23  THE SOFTWARE.
 24  ****************************************************************************/
 25 
 26 /**
 27  * Base class for ccui.CheckBox
 28  * @class
 29  * @extends ccui.Widget
 30  *
 31  * @property {Boolean}  selected    - Indicate whether the check box has been selected
 32  */
 33 ccui.CheckBox = ccui.Widget.extend(/** @lends ccui.CheckBox# */{
 34     _backGroundBoxRenderer: null,
 35     _backGroundSelectedBoxRenderer: null,
 36     _frontCrossRenderer: null,
 37     _backGroundBoxDisabledRenderer: null,
 38     _frontCrossDisabledRenderer: null,
 39 
 40     _isSelected: true,
 41 
 42     _checkBoxEventListener: null,
 43     _checkBoxEventSelector:null,
 44     _checkBoxEventCallback: null,
 45 
 46     _backGroundTexType: ccui.Widget.LOCAL_TEXTURE,
 47     _backGroundSelectedTexType: ccui.Widget.LOCAL_TEXTURE,
 48     _frontCrossTexType: ccui.Widget.LOCAL_TEXTURE,
 49     _backGroundDisabledTexType: ccui.Widget.LOCAL_TEXTURE,
 50     _frontCrossDisabledTexType: ccui.Widget.LOCAL_TEXTURE,
 51 
 52     _backGroundFileName: "",
 53     _backGroundSelectedFileName: "",
 54     _frontCrossFileName: "",
 55     _backGroundDisabledFileName: "",
 56     _frontCrossDisabledFileName: "",
 57     _className: "CheckBox",
 58 
 59     _backGroundBoxRendererAdaptDirty:true,
 60     _backGroundSelectedBoxRendererAdaptDirty:true,
 61     _frontCrossRendererAdaptDirty: true,
 62     _backGroundBoxDisabledRendererAdaptDirty: true,
 63     _frontCrossDisabledRendererAdaptDirty: true,
 64 
 65     /**
 66      * allocates and initializes a UICheckBox.
 67      * Constructor of ccui.CheckBox
 68      * @constructor
 69      * @example
 70      * // example
 71      * var uiCheckBox = new ccui.CheckBox();
 72      */
 73     ctor: function (backGround, backGroundSeleted,cross,backGroundDisabled,frontCrossDisabled,texType) {
 74         ccui.Widget.prototype.ctor.call(this);
 75         this.setTouchEnabled(true);
 76 
 77         texType && this.init(backGround, backGroundSeleted,cross,backGroundDisabled,frontCrossDisabled,texType);
 78     },
 79     init: function (backGround, backGroundSeleted, cross, backGroundDisabled, frontCrossDisabled, texType) {
 80         if (ccui.Widget.prototype.init.call(this)) {
 81             this._isSelected = true;
 82             this.setSelectedState(false);                                     //TODO need test
 83             if(backGround === undefined)
 84                 this.loadTextures(backGround, backGroundSeleted, cross, backGroundDisabled, frontCrossDisabled, texType);
 85             return true;
 86         }
 87         return false;
 88     },
 89 
 90     _initRenderer: function () {
 91         this._backGroundBoxRenderer = cc.Sprite.create();
 92         this._backGroundSelectedBoxRenderer = cc.Sprite.create();
 93         this._frontCrossRenderer = cc.Sprite.create();
 94         this._backGroundBoxDisabledRenderer = cc.Sprite.create();
 95         this._frontCrossDisabledRenderer = cc.Sprite.create();
 96 
 97         this.addProtectedChild(this._backGroundBoxRenderer, ccui.CheckBox.BOX_RENDERER_ZORDER, -1);
 98         this.addProtectedChild(this._backGroundSelectedBoxRenderer, ccui.CheckBox.BOX_SELECTED_RENDERER_ZORDER, -1);
 99         this.addProtectedChild(this._frontCrossRenderer, ccui.CheckBox.FRONT_CROSS_RENDERER_ZORDER, -1);
100         this.addProtectedChild(this._backGroundBoxDisabledRenderer, ccui.CheckBox.BOX_DISABLED_RENDERER_ZORDER, -1);
101         this.addProtectedChild(this._frontCrossDisabledRenderer, ccui.CheckBox.FRONT_CROSS_DISABLED_RENDERER_ZORDER, -1);
102     },
103 
104     /**
105      * Load textures for checkbox.
106      * @param {String} backGround
107      * @param {String} backGroundSelected
108      * @param {String} cross
109      * @param {String} backGroundDisabled
110      * @param {String} frontCrossDisabled
111      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
112      */
113     loadTextures: function (backGround, backGroundSelected, cross, backGroundDisabled, frontCrossDisabled, texType) {
114         this.loadTextureBackGround(backGround, texType);
115         this.loadTextureBackGroundSelected(backGroundSelected, texType);
116         this.loadTextureFrontCross(cross, texType);
117         this.loadTextureBackGroundDisabled(backGroundDisabled, texType);
118         this.loadTextureFrontCrossDisabled(frontCrossDisabled, texType);
119     },
120 
121     /**
122      * Load backGround texture for checkbox.
123      * @param {String} backGround
124      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
125      */
126     loadTextureBackGround: function (backGround, texType) {
127         if (!backGround)
128             return;
129 
130         texType = texType || ccui.Widget.LOCAL_TEXTURE;
131         this._backGroundFileName = backGround;
132         this._backGroundTexType = texType;
133         var bgBoxRenderer = this._backGroundBoxRenderer;
134 
135         var self = this;
136         if(!bgBoxRenderer.texture || !bgBoxRenderer.texture.isLoaded()){
137             bgBoxRenderer.addLoadedEventListener(function(){
138 
139                 self._findLayout();
140 
141                 self._updateFlippedX();
142                 self._updateFlippedY();
143 
144                 self._updateContentSizeWithTextureSize(self._backGroundBoxRenderer.getContentSize());
145                 self._backGroundBoxRendererAdaptDirty = true;
146             });
147         }
148 
149         switch (this._backGroundTexType) {
150             case ccui.Widget.LOCAL_TEXTURE:
151                 //SetTexture cannot load resource
152                 bgBoxRenderer.initWithFile(backGround);
153                 break;
154             case ccui.Widget.PLIST_TEXTURE:
155                 //SetTexture cannot load resource
156                 bgBoxRenderer.initWithSpriteFrameName(backGround);
157                 break;
158             default:
159                 break;
160         }
161 
162         if (!bgBoxRenderer.textureLoaded()) {
163             this._backGroundBoxRenderer.setContentSize(this._customSize);
164             bgBoxRenderer.addLoadedEventListener(function () {
165                 this._updateContentSizeWithTextureSize(this._backGroundBoxRenderer.getContentSize());
166             }, this);
167         }
168         this._updateFlippedX();
169         this._updateFlippedY();
170 
171         this._updateContentSizeWithTextureSize(this._backGroundBoxRenderer.getContentSize());
172         this._backGroundBoxRendererAdaptDirty = true;
173     },
174 
175     /**
176      * Load backGroundSelected texture for checkbox.
177      * @param {String} backGroundSelected
178      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
179      */
180     loadTextureBackGroundSelected: function (backGroundSelected, texType) {
181         if (!backGroundSelected)
182             return;
183 
184         texType = texType || ccui.Widget.LOCAL_TEXTURE;
185         this._backGroundSelectedFileName = backGroundSelected;
186         this._backGroundSelectedTexType = texType;
187 
188         var self = this;
189         if(!this._backGroundSelectedBoxRenderer.texture || !this._backGroundSelectedBoxRenderer.texture.isLoaded()){
190             this._backGroundSelectedBoxRenderer.addLoadedEventListener(function(){
191 
192                 self._findLayout();
193 
194                 self._updateFlippedX();
195                 self._updateFlippedY();
196                 self._backGroundSelectedBoxRendererAdaptDirty = true;
197             });
198         }
199 
200         switch (this._backGroundSelectedTexType) {
201             case ccui.Widget.LOCAL_TEXTURE:
202                 //SetTexture cannot load resource
203                 this._backGroundSelectedBoxRenderer.initWithFile(backGroundSelected);
204                 break;
205             case ccui.Widget.PLIST_TEXTURE:
206                 //SetTexture cannot load resource
207                 this._backGroundSelectedBoxRenderer.initWithSpriteFrameName(backGroundSelected);
208                 break;
209             default:
210                 break;
211         }
212 
213         this._updateFlippedX();
214         this._updateFlippedY();
215         this._backGroundSelectedBoxRendererAdaptDirty = true;
216     },
217 
218     /**
219      * Load cross texture for checkbox.
220      * @param {String} cross
221      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
222      */
223     loadTextureFrontCross: function (cross, texType) {
224         if (!cross)
225             return;
226         texType = texType || ccui.Widget.LOCAL_TEXTURE;
227         this._frontCrossFileName = cross;
228         this._frontCrossTexType = texType;
229 
230         var self = this;
231         if(!this._frontCrossRenderer.texture || !this._frontCrossRenderer.texture.isLoaded()){
232             this._frontCrossRenderer.addLoadedEventListener(function(){
233 
234                 self._findLayout();
235 
236                 self._updateFlippedX();
237                 self._updateFlippedY();
238                 self._frontCrossRendererAdaptDirty = true;
239             });
240         }
241 
242         switch (this._frontCrossTexType) {
243             case ccui.Widget.LOCAL_TEXTURE:
244                 //SetTexture cannot load resource
245                 this._frontCrossRenderer.initWithFile(cross);
246                 break;
247             case ccui.Widget.PLIST_TEXTURE:
248                 //SetTexture cannot load resource
249                 this._frontCrossRenderer.initWithSpriteFrameName(cross);
250                 break;
251             default:
252                 break;
253         }
254         this._updateFlippedX();
255         this._updateFlippedY();
256         this._frontCrossRendererAdaptDirty = true;
257     },
258 
259     /**
260      * Load backGroundDisabled texture for checkbox.
261      * @param {String} backGroundDisabled
262      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
263      */
264     loadTextureBackGroundDisabled: function (backGroundDisabled, texType) {
265         if (!backGroundDisabled)
266             return;
267         texType = texType || ccui.Widget.LOCAL_TEXTURE;
268         this._backGroundDisabledFileName = backGroundDisabled;
269         this._backGroundDisabledTexType = texType;
270 
271         var self = this;
272         if(!this._backGroundBoxDisabledRenderer.texture || !this._backGroundBoxDisabledRenderer.texture.isLoaded()){
273             this._backGroundBoxDisabledRenderer.addLoadedEventListener(function(){
274 
275                 self._findLayout();
276 
277                 self._updateFlippedX();
278                 self._updateFlippedY();
279                 self._backGroundBoxDisabledRendererAdaptDirty = true;
280             });
281         }
282 
283         switch (this._backGroundDisabledTexType) {
284             case ccui.Widget.LOCAL_TEXTURE:
285                 //SetTexture cannot load resource
286                 this._backGroundBoxDisabledRenderer.initWithFile(backGroundDisabled);
287                 break;
288             case ccui.Widget.PLIST_TEXTURE:
289                 //SetTexture cannot load resource
290                 this._backGroundBoxDisabledRenderer.initWithSpriteFrameName(backGroundDisabled);
291                 break;
292             default:
293                 break;
294         }
295         this._updateFlippedX();
296         this._updateFlippedY();
297         this._backGroundBoxDisabledRendererAdaptDirty = true;
298     },
299 
300     /**
301      * Load frontCrossDisabled texture for checkbox.
302      * @param {String} frontCrossDisabled
303      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
304      */
305     loadTextureFrontCrossDisabled: function (frontCrossDisabled, texType) {
306         if (!frontCrossDisabled)
307             return;
308         texType = texType || ccui.Widget.LOCAL_TEXTURE;
309         this._frontCrossDisabledFileName = frontCrossDisabled;
310         this._frontCrossDisabledTexType = texType;
311 
312         var self = this;
313         if(!this._frontCrossDisabledRenderer.texture || !this._frontCrossDisabledRenderer.texture.isLoaded()){
314             this._frontCrossDisabledRenderer.addLoadedEventListener(function(){
315 
316                 self._findLayout();
317 
318                 self._updateFlippedX();
319                 self._updateFlippedY();
320                 self._frontCrossDisabledRendererAdaptDirty = true;
321             });
322         }
323 
324         switch (this._frontCrossDisabledTexType) {
325             case ccui.Widget.LOCAL_TEXTURE:
326                 //SetTexture cannot load resource
327                 this._frontCrossDisabledRenderer.initWithFile(frontCrossDisabled);
328                 break;
329             case ccui.Widget.PLIST_TEXTURE:
330                 //SetTexture cannot load resource
331                 this._frontCrossDisabledRenderer.initWithSpriteFrameName(frontCrossDisabled);
332                 break;
333             default:
334                 break;
335         }
336         this._updateFlippedX();
337         this._updateFlippedY();
338         this._frontCrossDisabledRendererAdaptDirty = true;
339     },
340 
341     onPressStateChangedToNormal: function () {
342         this._backGroundBoxRenderer.setVisible(true);
343         this._backGroundSelectedBoxRenderer.setVisible(false);
344         this._backGroundBoxDisabledRenderer.setVisible(false);
345         this._frontCrossDisabledRenderer.setVisible(false);
346     },
347 
348     onPressStateChangedToPressed: function () {
349         this._backGroundBoxRenderer.setVisible(false);
350         this._backGroundSelectedBoxRenderer.setVisible(true);
351         this._backGroundBoxDisabledRenderer.setVisible(false);
352         this._frontCrossDisabledRenderer.setVisible(false);
353     },
354 
355     onPressStateChangedToDisabled: function () {
356         this._backGroundBoxRenderer.setVisible(false);
357         this._backGroundSelectedBoxRenderer.setVisible(false);
358         this._backGroundBoxDisabledRenderer.setVisible(true);
359         this._frontCrossRenderer.setVisible(false);
360         if (this._isSelected) {
361             this._frontCrossDisabledRenderer.setVisible(true);
362         }
363     },
364 
365     setSelectedState: function (selected) {
366         if (selected == this._isSelected)
367             return;
368         this._isSelected = selected;
369         this._frontCrossRenderer.setVisible(this._isSelected);
370     },
371 
372     getSelectedState: function () {
373         return this._isSelected;
374     },
375 
376     _selectedEvent: function () {
377         if(this._checkBoxEventCallback)
378             this._checkBoxEventCallback(this, ccui.CheckBox.EVENT_SELECTED);
379         if (this._checkBoxEventListener && this._checkBoxEventSelector)
380             this._checkBoxEventSelector.call(this._checkBoxEventListener, this, ccui.CheckBox.EVENT_SELECTED);
381     },
382 
383     _unSelectedEvent: function () {
384         if(this._checkBoxEventCallback)
385             this._checkBoxEventCallback(this, ccui.CheckBox.EVENT_UNSELECTED);
386         if (this._checkBoxEventListener && this._checkBoxEventSelector)
387             this._checkBoxEventSelector.call(this._checkBoxEventListener, this, ccui.CheckBox.EVENT_UNSELECTED);
388     },
389 
390     _releaseUpEvent: function(){
391         ccui.Widget.prototype._releaseUpEvent.call(this);
392         if (this._isSelected){
393             this.setSelectedState(false);
394             this._unSelectedEvent();
395         } else {
396             this.setSelectedState(true);
397             this._selectedEvent();
398         }
399     },
400 
401     /**
402      * add event listener
403      * @param {Function} selector
404      * @param {Object} target
405      * @deprecated
406      */
407     addEventListenerCheckBox: function (selector, target) {
408         this._checkBoxEventSelector = selector;
409         this._checkBoxEventListener = target;
410     },
411 
412     /**
413      * add a call back function would called when checkbox is selected or unselected.
414      * @param {function} callback
415      */
416     addEventListener: function(callback){
417         this._checkBoxEventCallback = callback;
418     },
419 
420     getVirtualRendererSize: function(){
421         return this._backGroundBoxRenderer.getContentSize();
422     },
423 
424     _updateFlippedX: function () {
425         this._backGroundBoxRenderer.setFlippedX(this._flippedX);
426         this._backGroundSelectedBoxRenderer.setFlippedX(this._flippedX);
427         this._frontCrossRenderer.setFlippedX(this._flippedX);
428         this._backGroundBoxDisabledRenderer.setFlippedX(this._flippedX);
429         this._frontCrossDisabledRenderer.setFlippedX(this._flippedX);
430     },
431 
432     _updateFlippedY: function () {
433         this._backGroundBoxRenderer.setFlippedY(this._flippedY);
434         this._backGroundSelectedBoxRenderer.setFlippedY(this._flippedY);
435         this._frontCrossRenderer.setFlippedY(this._flippedY);
436         this._backGroundBoxDisabledRenderer.setFlippedY(this._flippedY);
437         this._frontCrossDisabledRenderer.setFlippedY(this._flippedY);
438     },
439 
440     _onSizeChanged: function () {
441         ccui.Widget.prototype._onSizeChanged.call(this);
442         this._backGroundBoxRendererAdaptDirty = true;
443         this._backGroundSelectedBoxRendererAdaptDirty = true;
444         this._frontCrossRendererAdaptDirty = true;
445         this._backGroundBoxDisabledRendererAdaptDirty = true;
446         this._frontCrossDisabledRendererAdaptDirty = true;
447     },
448 
449     /**
450      * override "getVirtualRenderer" method of widget.
451      * @returns {cc.Node}
452      */
453     getVirtualRenderer: function () {
454         return this._backGroundBoxRenderer;
455     },
456 
457     _backGroundTextureScaleChangedWithSize: function () {
458         var locRenderer = this._backGroundBoxRenderer, locContentSize = this._contentSize;
459         if (this._ignoreSize)
460             locRenderer.setScale(1.0);
461         else{
462             var textureSize = locRenderer.getContentSize();
463             if (textureSize.width <= 0.0 || textureSize.height <= 0.0){
464                 locRenderer.setScale(1.0);
465                 return;
466             }
467             var scaleX = locContentSize.width / textureSize.width;
468             var scaleY = locContentSize.height / textureSize.height;
469             locRenderer.setScaleX(scaleX);
470             locRenderer.setScaleY(scaleY);
471         }
472         locRenderer.setPosition(locContentSize.width * 0.5, locContentSize.height * 0.5);
473     },
474 
475     _backGroundSelectedTextureScaleChangedWithSize: function () {
476         var locRenderer = this._backGroundSelectedBoxRenderer, locContentSize = this._contentSize;
477         if (this._ignoreSize)
478             locRenderer.setScale(1.0);
479         else {
480             var textureSize = locRenderer.getContentSize();
481             if (textureSize.width <= 0.0 || textureSize.height <= 0.0) {
482                 locRenderer.setScale(1.0);
483                 return;
484             }
485             var scaleX = locContentSize.width / textureSize.width;
486             var scaleY = locContentSize.height / textureSize.height;
487             locRenderer.setScaleX(scaleX);
488             locRenderer.setScaleY(scaleY);
489         }
490         locRenderer.setPosition(locContentSize.width * 0.5, locContentSize.height * 0.5);
491     },
492 
493     _frontCrossTextureScaleChangedWithSize: function () {
494         var locRenderer = this._frontCrossRenderer, locContentSize = this._contentSize;
495         if (this._ignoreSize)
496             locRenderer.setScale(1.0);
497         else {
498             var textureSize = locRenderer.getContentSize();
499             if (textureSize.width <= 0.0 || textureSize.height <= 0.0) {
500                 locRenderer.setScale(1.0);
501                 return;
502             }
503             var scaleX = locContentSize.width / textureSize.width;
504             var scaleY = locContentSize.height / textureSize.height;
505             locRenderer.setScaleX(scaleX);
506             locRenderer.setScaleY(scaleY);
507         }
508         locRenderer.setPosition(locContentSize.width * 0.5, locContentSize.height * 0.5);
509     },
510 
511     _backGroundDisabledTextureScaleChangedWithSize: function () {
512         var locRenderer = this._backGroundBoxDisabledRenderer, locContentSize = this._contentSize;
513         if (this._ignoreSize)
514             locRenderer.setScale(1.0);
515         else {
516             var textureSize = locRenderer.getContentSize();
517             if (textureSize.width <= 0.0 || textureSize.height <= 0.0) {
518                 locRenderer.setScale(1.0);
519                 return;
520             }
521             var scaleX = locContentSize.width / textureSize.width;
522             var scaleY = locContentSize.height / textureSize.height;
523             locRenderer.setScaleX(scaleX);
524             locRenderer.setScaleY(scaleY);
525         }
526         locRenderer.setPosition(locContentSize.width * 0.5, locContentSize.height * 0.5);
527     },
528 
529     _frontCrossDisabledTextureScaleChangedWithSize: function () {
530         var locRenderer = this._frontCrossDisabledRenderer, locContentSize = this._contentSize;
531         if (this._ignoreSize) {
532             locRenderer.setScale(1.0);
533         } else {
534             var textureSize = locRenderer.getContentSize();
535             if (textureSize.width <= 0.0 || textureSize.height <= 0.0) {
536                 locRenderer.setScale(1.0);
537                 return;
538             }
539             var scaleX = locContentSize.width / textureSize.width;
540             var scaleY = locContentSize.height / textureSize.height;
541             locRenderer.setScaleX(scaleX);
542             locRenderer.setScaleY(scaleY);
543         }
544         locRenderer.setPosition(locContentSize.width * 0.5, locContentSize.height * 0.5);
545     },
546 
547     /**
548      * Returns the "class name" of widget.
549      * @returns {string}
550      */
551     getDescription: function () {
552         return "CheckBox";
553     },
554 
555     _createCloneInstance: function () {
556         return ccui.CheckBox.create();
557     },
558 
559     _copySpecialProperties: function (uiCheckBox) {
560         if (uiCheckBox instanceof ccui.CheckBox) {
561             this.loadTextureBackGround(uiCheckBox._backGroundFileName, uiCheckBox._backGroundTexType);
562             this.loadTextureBackGroundSelected(uiCheckBox._backGroundSelectedFileName, uiCheckBox._backGroundSelectedTexType);
563             this.loadTextureFrontCross(uiCheckBox._frontCrossFileName, uiCheckBox._frontCrossTexType);
564             this.loadTextureBackGroundDisabled(uiCheckBox._backGroundDisabledFileName, uiCheckBox._backGroundDisabledTexType);
565             this.loadTextureFrontCrossDisabled(uiCheckBox._frontCrossDisabledFileName, uiCheckBox._frontCrossDisabledTexType);
566             this.setSelectedState(uiCheckBox._isSelected);
567             this._checkBoxEventListener = uiCheckBox._checkBoxEventListener;
568             this._checkBoxEventSelector = uiCheckBox._checkBoxEventSelector;
569             this._checkBoxEventCallback = uiCheckBox._checkBoxEventCallback;
570         }
571     },
572 
573     _adaptRenderers: function(){
574         if (this._backGroundBoxRendererAdaptDirty){
575             this._backGroundTextureScaleChangedWithSize();
576             this._backGroundBoxRendererAdaptDirty = false;
577         }
578         if (this._backGroundSelectedBoxRendererAdaptDirty) {
579             this._backGroundSelectedTextureScaleChangedWithSize();
580             this._backGroundSelectedBoxRendererAdaptDirty = false;
581         }
582         if (this._frontCrossRendererAdaptDirty){
583             this._frontCrossTextureScaleChangedWithSize();
584             this._frontCrossRendererAdaptDirty = false;
585         }
586         if (this._backGroundBoxDisabledRendererAdaptDirty) {
587             this._backGroundDisabledTextureScaleChangedWithSize();
588             this._backGroundBoxDisabledRendererAdaptDirty = false;
589         }
590         if (this._frontCrossDisabledRendererAdaptDirty) {
591             this._frontCrossDisabledTextureScaleChangedWithSize();
592             this._frontCrossDisabledRendererAdaptDirty = false;
593         }
594     }
595 });
596 
597 var _p = ccui.CheckBox.prototype;
598 
599 // Extended properties
600 /** @expose */
601 _p.selected;
602 cc.defineGetterSetter(_p, "selected", _p.getSelectedState, _p.setSelectedState);
603 
604 _p = null;
605 
606 /**
607  * allocates and initializes a UICheckBox.
608  * @deprecated
609  * @param {string} [backGround]     backGround texture.
610  * @param {string} [backGroundSeleted]  backGround selected state texture.
611  * @param {string} [cross]  cross texture.
612  * @param {string} [backGroundDisabled]   cross dark state texture.
613  * @param {string} [frontCrossDisabled]   cross dark state texture.
614  * @param {Number} [texType]
615  * @return {ccui.CheckBox}
616  * @example
617  * // example
618  * var uiCheckBox = ccui.CheckBox.create();
619  */
620 ccui.CheckBox.create = function (backGround, backGroundSeleted, cross, backGroundDisabled, frontCrossDisabled, texType) {
621     return new ccui.CheckBox(backGround, backGroundSeleted,cross,backGroundDisabled,frontCrossDisabled,texType);
622 };
623 
624 // Constants
625 //CheckBoxEvent type
626 ccui.CheckBox.EVENT_SELECTED = 0;
627 ccui.CheckBox.EVENT_UNSELECTED = 1;
628 
629 //Render zorder
630 ccui.CheckBox.BOX_RENDERER_ZORDER = -1;
631 ccui.CheckBox.BOX_SELECTED_RENDERER_ZORDER = -1;
632 ccui.CheckBox.BOX_DISABLED_RENDERER_ZORDER = -1;
633 ccui.CheckBox.FRONT_CROSS_RENDERER_ZORDER = -1;
634 ccui.CheckBox.FRONT_CROSS_DISABLED_RENDERER_ZORDER = -1;
635