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     _isSelected: true,
 40     _checkBoxEventListener: null,
 41     _checkBoxEventSelector:null,
 42     _checkBoxEventCallback: null,
 43     _backGroundTexType: ccui.Widget.LOCAL_TEXTURE,
 44     _backGroundSelectedTexType: ccui.Widget.LOCAL_TEXTURE,
 45     _frontCrossTexType: ccui.Widget.LOCAL_TEXTURE,
 46     _backGroundDisabledTexType: ccui.Widget.LOCAL_TEXTURE,
 47     _frontCrossDisabledTexType: ccui.Widget.LOCAL_TEXTURE,
 48     _backGroundFileName: "",
 49     _backGroundSelectedFileName: "",
 50     _frontCrossFileName: "",
 51     _backGroundDisabledFileName: "",
 52     _frontCrossDisabledFileName: "",
 53     _className: "CheckBox",
 54 
 55     _backGroundBoxRendererAdaptDirty:true,
 56     _backGroundSelectedBoxRendererAdaptDirty:true,
 57     _frontCrossRendererAdaptDirty: true,
 58     _backGroundBoxDisabledRendererAdaptDirty: true,
 59     _frontCrossDisabledRendererAdaptDirty: true,
 60 
 61     /**
 62      * allocates and initializes a UICheckBox.
 63      * Constructor of ccui.CheckBox
 64      * @example
 65      * // example
 66      * var uiCheckBox = new ccui.CheckBox();
 67      */
 68     ctor: function () {
 69         ccui.Widget.prototype.ctor.call(this);
 70     },
 71     init: function (backGround, backGroundSeleted, cross, backGroundDisabled, frontCrossDisabled, texType) {
 72         if (ccui.Widget.prototype.init.call(this)) {
 73             this._isSelected = true;
 74             this.setTouchEnabled(true);
 75 //            this.setSelectedState(false);
 76             if(backGround === undefined)
 77                 this.loadTextures(backGround, backGroundSeleted, cross, backGroundDisabled, frontCrossDisabled, texType);
 78             return true;
 79         }
 80         return false;
 81     },
 82 
 83     initRenderer: function () {
 84         this._backGroundBoxRenderer = cc.Sprite.create();
 85         this._backGroundSelectedBoxRenderer = cc.Sprite.create();
 86         this._frontCrossRenderer = cc.Sprite.create();
 87         this._backGroundBoxDisabledRenderer = cc.Sprite.create();
 88         this._frontCrossDisabledRenderer = cc.Sprite.create();
 89         this.addProtectedChild(this._backGroundBoxRenderer, ccui.CheckBox.BOX_RENDERER_ZORDER, -1);
 90         this.addProtectedChild(this._backGroundSelectedBoxRenderer, ccui.CheckBox.BOX_SELECTED_RENDERER_ZORDER, -1);
 91         this.addProtectedChild(this._frontCrossRenderer, ccui.CheckBox.FRONT_CROSS_RENDERER_ZORDER, -1);
 92         this.addProtectedChild(this._backGroundBoxDisabledRenderer, ccui.CheckBox.BOX_DISABLED_RENDERER_ZORDER, -1);
 93         this.addProtectedChild(this._frontCrossDisabledRenderer, ccui.CheckBox.FRONT_CROSS_DISABLED_RENDERER_ZORDER, -1);
 94 
 95         window.test = [
 96             this._backGroundBoxRenderer,
 97             this._backGroundSelectedBoxRenderer,
 98             this._frontCrossRenderer,
 99             this._backGroundBoxDisabledRenderer,
100             this._frontCrossDisabledRenderer
101         ];
102 
103         window.a = this;
104     },
105 
106     /**
107      * Load textures for checkbox.
108      * @param {String} backGround
109      * @param {String} backGroundSelected
110      * @param {String} cross
111      * @param {String} backGroundDisabled
112      * @param {String} frontCrossDisabled
113      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
114      */
115     loadTextures: function (backGround, backGroundSelected, cross, backGroundDisabled, frontCrossDisabled, texType) {
116         this.loadTextureBackGround(backGround, texType);
117         this.loadTextureBackGroundSelected(backGroundSelected, texType);
118         this.loadTextureFrontCross(cross, texType);
119         this.loadTextureBackGroundDisabled(backGroundDisabled, texType);
120         this.loadTextureFrontCrossDisabled(frontCrossDisabled, texType);
121     },
122 
123     /**
124      * Load backGround texture for checkbox.
125      * @param {String} backGround
126      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
127      */
128     loadTextureBackGround: function (backGround, texType) {
129         if (!backGround)
130             return;
131 
132         texType = texType || ccui.Widget.LOCAL_TEXTURE;
133         this._backGroundFileName = backGround;
134         this._backGroundTexType = texType;
135         var bgBoxRenderer = this._backGroundBoxRenderer;
136         switch (this._backGroundTexType) {
137             case ccui.Widget.LOCAL_TEXTURE:
138                 bgBoxRenderer.setTexture(backGround);
139                 break;
140             case ccui.Widget.PLIST_TEXTURE:
141                 bgBoxRenderer.setSpriteFrame(backGround);
142                 break;
143             default:
144                 break;
145         }
146 
147         this.backGroundTextureScaleChangedWithSize();       //TODO need test
148         if (!bgBoxRenderer.textureLoaded()) {
149             this._backGroundBoxRenderer.setContentSize(this._customSize);
150             bgBoxRenderer.addLoadedEventListener(function () {
151                 this.backGroundTextureScaleChangedWithSize();
152             }, this);
153         }
154         this.updateFlippedX();
155         this.updateFlippedY();
156         this._backGroundBoxRenderer.setColor(this.getColor());
157         this._backGroundBoxRenderer.setOpacity(this.getOpacity());
158 
159         this._updateContentSizeWithTextureSize(this._backGroundBoxRenderer.getContentSize());
160         this._backGroundBoxRendererAdaptDirty = true;
161     },
162     /**
163      * Load backGroundSelected texture for checkbox.
164      * @param {String} backGroundSelected
165      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
166      */
167     loadTextureBackGroundSelected: function (backGroundSelected, texType) {
168         if (!backGroundSelected)
169             return;
170 
171         texType = texType || ccui.Widget.LOCAL_TEXTURE;
172         this._backGroundSelectedFileName = backGroundSelected;
173         this._backGroundSelectedTexType = texType;
174         switch (this._backGroundSelectedTexType) {
175             case ccui.Widget.LOCAL_TEXTURE:
176                 this._backGroundSelectedBoxRenderer.setTexture(backGroundSelected);
177                 break;
178             case ccui.Widget.PLIST_TEXTURE:
179                 this._backGroundSelectedBoxRenderer.setSpriteFrame(backGroundSelected);
180                 break;
181             default:
182                 break;
183         }
184 
185         this.updateFlippedX();
186         this.updateFlippedY();
187         this._backGroundSelectedBoxRenderer.setColor(this.getColor());
188         this._backGroundSelectedBoxRenderer.setOpacity(this.getOpacity());
189         this._backGroundSelectedBoxRendererAdaptDirty = true;
190     },
191 
192     /**
193      * Load cross texture for checkbox.
194      * @param {String} cross
195      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
196      */
197     loadTextureFrontCross: function (cross, texType) {
198         if (!cross)
199             return;
200         texType = texType || ccui.Widget.LOCAL_TEXTURE;
201         this._frontCrossFileName = cross;
202         this._frontCrossTexType = texType;
203         switch (this._frontCrossTexType) {
204             case ccui.Widget.LOCAL_TEXTURE:
205                 this._frontCrossRenderer.setTexture(cross);
206                 break;
207             case ccui.Widget.PLIST_TEXTURE:
208                 this._frontCrossRenderer.setSpriteFrame(cross);
209                 break;
210             default:
211                 break;
212         }
213         this.updateFlippedX();
214         this.updateFlippedY();
215         this._frontCrossRenderer.setColor(this.getColor());
216         this._frontCrossRenderer.setOpacity(this.getOpacity());
217         this._frontCrossRendererAdaptDirty = true;
218     },
219 
220     /**
221      * Load backGroundDisabled texture for checkbox.
222      * @param {String} backGroundDisabled
223      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
224      */
225     loadTextureBackGroundDisabled: function (backGroundDisabled, texType) {
226         if (!backGroundDisabled)
227             return;
228         texType = texType || ccui.Widget.LOCAL_TEXTURE;
229         this._backGroundDisabledFileName = backGroundDisabled;
230         this._backGroundDisabledTexType = texType;
231         switch (this._backGroundDisabledTexType) {
232             case ccui.Widget.LOCAL_TEXTURE:
233                 this._backGroundBoxDisabledRenderer.setTexture(backGroundDisabled);
234                 break;
235             case ccui.Widget.PLIST_TEXTURE:
236                 this._backGroundBoxDisabledRenderer.setSpriteFrame(backGroundDisabled);
237                 break;
238             default:
239                 break;
240         }
241         this.updateFlippedX();
242         this.updateFlippedY();
243         this._backGroundBoxDisabledRenderer.setColor(this.getColor());
244         this._backGroundBoxDisabledRenderer.setOpacity(this.getOpacity());
245         this._backGroundBoxDisabledRendererAdaptDirty = true;
246     },
247 
248     /**
249      * Load frontCrossDisabled texture for checkbox.
250      * @param {String} frontCrossDisabled
251      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
252      */
253     loadTextureFrontCrossDisabled: function (frontCrossDisabled, texType) {
254         if (!frontCrossDisabled)
255             return;
256         texType = texType || ccui.Widget.LOCAL_TEXTURE;
257         this._frontCrossDisabledFileName = frontCrossDisabled;
258         this._frontCrossDisabledTexType = texType;
259         switch (this._frontCrossDisabledTexType) {
260             case ccui.Widget.LOCAL_TEXTURE:
261                 this._frontCrossDisabledRenderer.setTexture(frontCrossDisabled);
262                 break;
263             case ccui.Widget.PLIST_TEXTURE:
264                 this._frontCrossDisabledRenderer.setSpriteFrame(frontCrossDisabled);
265                 break;
266             default:
267                 break;
268         }
269         this.updateFlippedX();
270         this.updateFlippedY();
271         this._frontCrossDisabledRenderer.setColor(this.getColor());
272         this._frontCrossDisabledRenderer.setOpacity(this.getOpacity());
273         this._frontCrossDisabledRendererAdaptDirty = true;
274     },
275 
276     onPressStateChangedToNormal: function () {
277         this._backGroundBoxRenderer.setVisible(true);
278         this._backGroundSelectedBoxRenderer.setVisible(false);
279         this._backGroundBoxDisabledRenderer.setVisible(false);
280         this._frontCrossDisabledRenderer.setVisible(false);
281     },
282 
283     onPressStateChangedToPressed: function () {
284         this._backGroundBoxRenderer.setVisible(false);
285         this._backGroundSelectedBoxRenderer.setVisible(true);
286         this._backGroundBoxDisabledRenderer.setVisible(false);
287         this._frontCrossDisabledRenderer.setVisible(false);
288     },
289 
290     onPressStateChangedToDisabled: function () {
291         this._backGroundBoxRenderer.setVisible(false);
292         this._backGroundSelectedBoxRenderer.setVisible(false);
293         this._backGroundBoxDisabledRenderer.setVisible(true);
294         this._frontCrossRenderer.setVisible(false);
295         if (this._isSelected) {
296             this._frontCrossDisabledRenderer.setVisible(true);
297         }
298     },
299 
300     setSelectedState: function (selected) {
301         if (selected == this._isSelected)
302             return;
303         this._isSelected = selected;
304         this._frontCrossRenderer.setVisible(this._isSelected);
305     },
306 
307     getSelectedState: function () {
308         return this._isSelected;
309     },
310 
311     selectedEvent: function () {
312         if(this._checkBoxEventCallback)
313             this._checkBoxEventCallback(this, ccui.CheckBox.EVENT_SELECTED);
314         if (this._checkBoxEventListener && this._checkBoxEventSelector)
315             this._checkBoxEventSelector.call(this._checkBoxEventListener, this, ccui.CheckBox.EVENT_SELECTED);
316     },
317 
318     unSelectedEvent: function () {
319         if(this._checkBoxEventCallback)
320             this._checkBoxEventCallback(this, ccui.CheckBox.EVENT_UNSELECTED);
321         if (this._checkBoxEventListener && this._checkBoxEventSelector)
322             this._checkBoxEventSelector.call(this._checkBoxEventListener, this, ccui.CheckBox.EVENT_UNSELECTED);
323     },
324 
325     releaseUpEvent: function(){
326         ccui.Widget.prototype.releaseUpEvent.call(this);
327 
328         if (this._isSelected){
329             this.setSelectedState(false);
330             this.unSelectedEvent();
331         } else {
332             this.setSelectedState(true);
333             this.selectedEvent();
334         }
335     },
336 
337     /**
338      * add event listener
339      * @param {Function} selector
340      * @param {Object} target
341      */
342     addEventListenerCheckBox: function (selector, target) {
343         this._checkBoxEventSelector = selector;
344         this._checkBoxEventListener = target;
345     },
346 
347     addEventListener: function(callback){
348         this._checkBoxEventCallback = callback;
349     },
350 
351     getVirtualRendererSize: function(){
352         return this._backGroundBoxRenderer.getContentSize();
353     },
354 
355     updateFlippedX: function () {
356         this._backGroundBoxRenderer.setFlippedX(this._flippedX);
357         this._backGroundSelectedBoxRenderer.setFlippedX(this._flippedX);
358         this._frontCrossRenderer.setFlippedX(this._flippedX);
359         this._backGroundBoxDisabledRenderer.setFlippedX(this._flippedX);
360         this._frontCrossDisabledRenderer.setFlippedX(this._flippedX);
361     },
362 
363     updateFlippedY: function () {
364         this._backGroundBoxRenderer.setFlippedY(this._flippedY);
365         this._backGroundSelectedBoxRenderer.setFlippedY(this._flippedY);
366         this._frontCrossRenderer.setFlippedY(this._flippedY);
367         this._backGroundBoxDisabledRenderer.setFlippedY(this._flippedY);
368         this._frontCrossDisabledRenderer.setFlippedY(this._flippedY);
369     },
370 
371     /**
372      * override "setAnchorPoint" of widget.
373      * @param {cc.Point|Number} point The anchor point of UICheckBox or The anchor point.x of UICheckBox.
374      * @param {Number} [y] The anchor point.y of UICheckBox.
375      */
376     setAnchorPoint: function (point, y) {
377         if (y === undefined) {
378             ccui.Widget.prototype.setAnchorPoint.call(this, point);
379             this._backGroundBoxRenderer.setAnchorPoint(point);
380             this._backGroundSelectedBoxRenderer.setAnchorPoint(point);
381             this._backGroundBoxDisabledRenderer.setAnchorPoint(point);
382             this._frontCrossRenderer.setAnchorPoint(point);
383             this._frontCrossDisabledRenderer.setAnchorPoint(point);
384         } else {
385             ccui.Widget.prototype.setAnchorPoint.call(this, point, y);
386             this._backGroundBoxRenderer.setAnchorPoint(point, y);
387             this._backGroundSelectedBoxRenderer.setAnchorPoint(point, y);
388             this._backGroundBoxDisabledRenderer.setAnchorPoint(point, y);
389             this._frontCrossRenderer.setAnchorPoint(point, y);
390             this._frontCrossDisabledRenderer.setAnchorPoint(point, y);
391         }
392     },
393     _setAnchorX: function (value) {
394         ccui.Widget.prototype._setAnchorX.call(this, value);
395         this._backGroundBoxRenderer._setAnchorX(value);
396         this._backGroundSelectedBoxRenderer._setAnchorX(value);
397         this._backGroundBoxDisabledRenderer._setAnchorX(value);
398         this._frontCrossRenderer._setAnchorX(value);
399         this._frontCrossDisabledRenderer._setAnchorX(value);
400     },
401     _setAnchorY: function (value) {
402         ccui.Widget.prototype._setAnchorY.call(this, value);
403         this._backGroundBoxRenderer._setAnchorY(value);
404         this._backGroundSelectedBoxRenderer._setAnchorY(value);
405         this._backGroundBoxDisabledRenderer._setAnchorY(value);
406         this._frontCrossRenderer._setAnchorY(value);
407         this._frontCrossDisabledRenderer._setAnchorY(value);
408     },
409 
410     onSizeChanged: function () {
411         ccui.Widget.prototype.onSizeChanged.call(this);
412         this._backGroundBoxRendererAdaptDirty = true;
413         this._backGroundSelectedBoxRendererAdaptDirty = true;
414         this._frontCrossRendererAdaptDirty = true;
415         this._backGroundBoxDisabledRendererAdaptDirty = true;
416         this._frontCrossDisabledRendererAdaptDirty = true;
417     },
418 
419     /**
420      * override "getContentSize" method of widget.
421      * @returns {cc.Size}
422      */
423     getContentSize: function () {
424         return this._backGroundBoxRenderer.getContentSize();
425     },
426     _getWidth: function () {
427         return this._backGroundBoxRenderer._getWidth();
428     },
429     _getHeight: function () {
430         return this._backGroundBoxRenderer._getHeight();
431     },
432 
433     /**
434      * override "getVirtualRenderer" method of widget.
435      * @returns {cc.Node}
436      */
437     getVirtualRenderer: function () {
438         return this._backGroundBoxRenderer;
439     },
440 
441     backGroundTextureScaleChangedWithSize: function () {
442         if (this._ignoreSize)
443             this._backGroundBoxRenderer.setScale(1.0);
444         else{
445             var textureSize = this._backGroundBoxRenderer.getContentSize();
446             if (textureSize.width <= 0.0 || textureSize.height <= 0.0){
447                 this._backGroundBoxRenderer.setScale(1.0);
448                 return;
449             }
450             var scaleX = this._size.width / textureSize.width;
451             var scaleY = this._size.height / textureSize.height;
452             this._backGroundBoxRenderer.setScaleX(scaleX);
453             this._backGroundBoxRenderer.setScaleY(scaleY);
454         }
455 
456         var x = this._contentSize.width / 2;
457         var y = this._contentSize.height / 2;
458         this._backGroundBoxRenderer.setPosition(x, y);
459         this._backGroundSelectedBoxRenderer.setPosition(x, y);
460         this._frontCrossRenderer.setPosition(x, y);
461         this._backGroundBoxDisabledRenderer.setPosition(x, y);
462         this._frontCrossDisabledRenderer.setPosition(x, y);
463     },
464 
465     backGroundSelectedTextureScaleChangedWithSize: function () {
466         if (this._ignoreSize) {
467             this._backGroundSelectedBoxRenderer.setScale(1.0);
468         } else {
469             var textureSize = this._backGroundSelectedBoxRenderer.getContentSize();
470             if (textureSize.width <= 0.0 || textureSize.height <= 0.0) {
471                 this._backGroundSelectedBoxRenderer.setScale(1.0);
472                 return;
473             }
474             var scaleX = this._size.width / textureSize.width;
475             var scaleY = this._size.height / textureSize.height;
476             this._backGroundSelectedBoxRenderer.setScaleX(scaleX);
477             this._backGroundSelectedBoxRenderer.setScaleY(scaleY);
478         }
479     },
480 
481     frontCrossTextureScaleChangedWithSize: function () {
482         if (this._ignoreSize) {
483             this._frontCrossRenderer.setScale(1.0);
484         } else {
485             var textureSize = this._frontCrossRenderer.getContentSize();
486             if (textureSize.width <= 0.0 || textureSize.height <= 0.0) {
487                 this._frontCrossRenderer.setScale(1.0);
488                 return;
489             }
490             var scaleX = this._size.width / textureSize.width;
491             var scaleY = this._size.height / textureSize.height;
492             this._frontCrossRenderer.setScaleX(scaleX);
493             this._frontCrossRenderer.setScaleY(scaleY);
494         }
495     },
496 
497     backGroundDisabledTextureScaleChangedWithSize: function () {
498         if (this._ignoreSize) {
499             this._backGroundBoxDisabledRenderer.setScale(1.0);
500         }else {
501             var textureSize = this._backGroundBoxDisabledRenderer.getContentSize();
502             if (textureSize.width <= 0.0 || textureSize.height <= 0.0) {
503                 this._backGroundBoxDisabledRenderer.setScale(1.0);
504                 return;
505             }
506             var scaleX = this._size.width / textureSize.width;
507             var scaleY = this._size.height / textureSize.height;
508             this._backGroundBoxDisabledRenderer.setScaleX(scaleX);
509             this._backGroundBoxDisabledRenderer.setScaleY(scaleY);
510         }
511     },
512 
513     frontCrossDisabledTextureScaleChangedWithSize: function () {
514         if (this._ignoreSize) {
515             this._frontCrossDisabledRenderer.setScale(1.0);
516         } else {
517             var textureSize = this._frontCrossDisabledRenderer.getContentSize();
518             if (textureSize.width <= 0.0 || textureSize.height <= 0.0) {
519                 this._frontCrossDisabledRenderer.setScale(1.0);
520                 return;
521             }
522             var scaleX = this._size.width / textureSize.width;
523             var scaleY = this._size.height / textureSize.height;
524             this._frontCrossDisabledRenderer.setScaleX(scaleX);
525             this._frontCrossDisabledRenderer.setScaleY(scaleY);
526         }
527     },
528 
529     updateTextureColor: function () {
530         this.updateColorToRenderer(this._backGroundBoxRenderer);
531         this.updateColorToRenderer(this._backGroundSelectedBoxRenderer);
532         this.updateColorToRenderer(this._frontCrossRenderer);
533         this.updateColorToRenderer(this._backGroundBoxDisabledRenderer);
534         this.updateColorToRenderer(this._frontCrossDisabledRenderer);
535     },
536 
537     updateTextureOpacity: function () {
538         this.updateOpacityToRenderer(this._backGroundBoxRenderer);
539         this.updateOpacityToRenderer(this._backGroundSelectedBoxRenderer);
540         this.updateOpacityToRenderer(this._frontCrossRenderer);
541         this.updateOpacityToRenderer(this._backGroundBoxDisabledRenderer);
542         this.updateOpacityToRenderer(this._frontCrossDisabledRenderer);
543     },
544 
545     /**
546      * Returns the "class name" of widget.
547      * @returns {string}
548      */
549     getDescription: function () {
550         return "CheckBox";
551     },
552 
553     createCloneInstance: function () {
554         return ccui.CheckBox.create();
555     },
556 
557     copySpecialProperties: function (uiCheckBox) {
558         if (uiCheckBox instanceof ccui.CheckBox) {
559             this.loadTextureBackGround(uiCheckBox._backGroundFileName, uiCheckBox._backGroundTexType);
560             this.loadTextureBackGroundSelected(uiCheckBox._backGroundSelectedFileName, uiCheckBox._backGroundSelectedTexType);
561             this.loadTextureFrontCross(uiCheckBox._frontCrossFileName, uiCheckBox._frontCrossTexType);
562             this.loadTextureBackGroundDisabled(uiCheckBox._backGroundDisabledFileName, uiCheckBox._backGroundDisabledTexType);
563             this.loadTextureFrontCrossDisabled(uiCheckBox._frontCrossDisabledFileName, uiCheckBox._frontCrossDisabledTexType);
564             this.setSelectedState(uiCheckBox._isSelected);
565             this._checkBoxEventListener = uiCheckBox._checkBoxEventListener;
566             this._checkBoxEventSelector = uiCheckBox._checkBoxEventSelector;
567             this._checkBoxEventCallback = uiCheckBox._checkBoxEventCallback;
568         }
569     },
570 
571     adaptRenderers: function(){
572         if (this._backGroundBoxRendererAdaptDirty){
573             this.backGroundTextureScaleChangedWithSize();
574             this._backGroundBoxRendererAdaptDirty = false;
575         }
576         if (this._backGroundSelectedBoxRendererAdaptDirty) {
577             this.backGroundSelectedTextureScaleChangedWithSize();
578             this._backGroundSelectedBoxRendererAdaptDirty = false;
579         }
580         if (this._frontCrossRendererAdaptDirty){
581             this.frontCrossTextureScaleChangedWithSize();
582             this._frontCrossRendererAdaptDirty = false;
583         }
584         if (this._backGroundBoxDisabledRendererAdaptDirty) {
585             this.backGroundDisabledTextureScaleChangedWithSize();
586             this._backGroundBoxDisabledRendererAdaptDirty = false;
587         }
588         if (this._frontCrossDisabledRendererAdaptDirty) {
589             this.frontCrossDisabledTextureScaleChangedWithSize();
590             this._frontCrossDisabledRendererAdaptDirty = false;
591         }
592     }
593 });
594 
595 var _p = ccui.CheckBox.prototype;
596 
597 // Extended properties
598 /** @expose */
599 _p.selected;
600 cc.defineGetterSetter(_p, "selected", _p.getSelectedState, _p.setSelectedState);
601 
602 _p = null;
603 
604 /**
605  * allocates and initializes a UICheckBox.
606  * @param {string} [backGround]     backGround texture.
607  * @param {string} [backGroundSeleted]  backGround selected state texture.
608  * @param {string} [cross]  cross texture.
609  * @param {string} [backGroundDisabled]   cross dark state texture.
610  * @param {string} [frontCrossDisabled]   cross dark state texture.
611  * @param {Number} [texType]
612  * @return {ccui.CheckBox}
613  * @example
614  * // example
615  * var uiCheckBox = ccui.CheckBox.create();
616  */
617 ccui.CheckBox.create = function (backGround, backGroundSeleted, cross, backGroundDisabled, frontCrossDisabled, texType) {
618     var widget = new ccui.CheckBox();
619     if(backGround === undefined)
620         widget.init();
621     else
622         widget.init(backGround, backGroundSeleted,cross,backGroundDisabled,frontCrossDisabled,texType);
623     return widget;
624 };
625 
626 // Constants
627 //CheckBoxEvent type
628 ccui.CheckBox.EVENT_SELECTED = 0;
629 ccui.CheckBox.EVENT_UNSELECTED = 1;
630 
631 //Render zorder
632 ccui.CheckBox.BOX_RENDERER_ZORDER = -1;
633 ccui.CheckBox.BOX_SELECTED_RENDERER_ZORDER = -1;
634 ccui.CheckBox.BOX_DISABLED_RENDERER_ZORDER = -1;
635 ccui.CheckBox.FRONT_CROSS_RENDERER_ZORDER = -1;
636 ccui.CheckBox.FRONT_CROSS_DISABLED_RENDERER_ZORDER = -1;
637