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 var NORMAL_RENDERER_ZORDER = 0;
 26 var PRESSED_RENDERER_ZORDER = 0;
 27 var DISABLED_RENDERER_ZORDER = 0;
 28 var TITLE_RENDERER_ZORDER = 1;
 29 
 30 /**
 31  * Base class for ccs.UIButton
 32  * @class
 33  * @extends ccs.UIWidget
 34  */
 35 ccs.UIButton = ccs.UIWidget.extend(/** @lends ccs.UIButton# */{
 36     _buttonNormalRenderer: null,
 37     _buttonClickedRenderer: null,
 38     _buttonDisableRenderer: null,
 39     _titleRenderer: null,
 40     _normalFileName: "",
 41     _clickedFileName: "",
 42     _disabledFileName: "",
 43     _prevIgnoreSize: true,
 44     _scale9Enabled: false,
 45 //    CCRect _capInsets:null,
 46     _capInsetsNormal: null,
 47     _capInsetsPressed: null,
 48     _capInsetsDisabled: null,
 49     _normalTexType: null,
 50     _pressedTexType: null,
 51     _disabledTexType: null,
 52     _normalTextureSize: null,
 53     _pressedTextureSize: null,
 54     _disabledTextureSize: null,
 55     _pressedActionEnabled: false,
 56     _titleColor: null,
 57     ctor: function () {
 58         ccs.UIWidget.prototype.ctor.call(this);
 59         this._buttonNormalRenderer = null;
 60         this._buttonClickedRenderer = null;
 61         this._buttonDisableRenderer = null;
 62         this._titleRenderer = null;
 63         this._normalFileName = "";
 64         this._clickedFileName = "";
 65         this._disabledFileName = "";
 66         this._prevIgnoreSize = true;
 67         this._scale9Enabled = false;
 68         this._capInsetsNormal = cc.RectZero();
 69         this._capInsetsPressed = cc.RectZero();
 70         this._capInsetsDisabled = cc.RectZero();
 71         this._normalTexType = ccs.TextureResType.local;
 72         this._pressedTexType = ccs.TextureResType.local;
 73         this._disabledTexType = ccs.TextureResType.local;
 74         var locSize = this._size;
 75         this._normalTextureSize = cc.size(locSize.width, locSize.height);
 76         this._pressedTextureSize = cc.size(locSize.width, locSize.height);
 77         this._disabledTextureSize = cc.size(locSize.width, locSize.height);
 78         this._pressedActionEnabled = false;
 79         this._titleColor = cc.white();
 80     },
 81 
 82     init: function () {
 83         if (ccs.UIWidget.prototype.init.call(this))
 84             return true;
 85         return false;
 86     },
 87 
 88     initRenderer: function () {
 89         ccs.UIWidget.prototype.initRenderer.call(this);
 90         this._buttonNormalRenderer = cc.Sprite.create();
 91         this._buttonClickedRenderer = cc.Sprite.create();
 92         this._buttonDisableRenderer = cc.Sprite.create();
 93         this._titleRenderer = cc.LabelTTF.create("");
 94         this._renderer.addChild(this._buttonNormalRenderer, NORMAL_RENDERER_ZORDER);
 95         this._renderer.addChild(this._buttonClickedRenderer, PRESSED_RENDERER_ZORDER);
 96         this._renderer.addChild(this._buttonDisableRenderer, DISABLED_RENDERER_ZORDER);
 97         this._renderer.addChild(this._titleRenderer, TITLE_RENDERER_ZORDER);
 98     },
 99 
100     /**
101      * Sets if button is using scale9 renderer.
102      * @param {Boolean} able
103      */
104     setScale9Enabled: function (able) {
105         if (this._scale9Enabled == able) {
106             return;
107         }
108         this._brightStyle = ccs.BrightStyle.none;
109         this._scale9Enabled = able;
110 
111         this._renderer.removeChild(this._buttonNormalRenderer, true);
112         this._renderer.removeChild(this._buttonClickedRenderer, true);
113         this._renderer.removeChild(this._buttonDisableRenderer, true);
114 
115         if (this._scale9Enabled) {
116             this._buttonNormalRenderer = cc.Scale9Sprite.create();
117             this._buttonClickedRenderer = cc.Scale9Sprite.create();
118             this._buttonDisableRenderer = cc.Scale9Sprite.create();
119         }
120         else {
121             this._buttonNormalRenderer = cc.Sprite.create();
122             this._buttonClickedRenderer = cc.Sprite.create();
123             this._buttonDisableRenderer = cc.Sprite.create();
124         }
125 
126         this.loadTextureNormal(this._normalFileName, this._normalTexType);
127         this.loadTexturePressed(this._clickedFileName, this._pressedTexType);
128         this.loadTextureDisabled(this._disabledFileName, this._disabledTexType);
129         this._renderer.addChild(this._buttonNormalRenderer, NORMAL_RENDERER_ZORDER);
130         this._renderer.addChild(this._buttonClickedRenderer, PRESSED_RENDERER_ZORDER);
131         this._renderer.addChild(this._buttonDisableRenderer, DISABLED_RENDERER_ZORDER);
132         if (this._scale9Enabled) {
133             var ignoreBefore = this._ignoreSize;
134             this.ignoreContentAdaptWithSize(false);
135             this._prevIgnoreSize = ignoreBefore;
136         }
137         else {
138             this.ignoreContentAdaptWithSize(this._prevIgnoreSize);
139         }
140         this.setCapInsetsNormalRenderer(this._capInsetsNormal);
141         this.setCapInsetsPressedRenderer(this._capInsetsPressed);
142         this.setCapInsetsDisabledRenderer(this._capInsetsDisabled);
143         this.setBright(this._bright);
144     },
145 
146     /**
147      * ignoreContentAdaptWithSize
148      * @param {Boolean} ignore
149      */
150     ignoreContentAdaptWithSize: function (ignore) {
151         if (!this._scale9Enabled || (this._scale9Enabled && !ignore)) {
152             ccs.UIWidget.prototype.ignoreContentAdaptWithSize.call(this, ignore);
153             this._prevIgnoreSize = ignore;
154         }
155     },
156 
157     /**
158      * Load textures for button.
159      * @param {String} normal
160      * @param {String} selected
161      * @param {String} disabled
162      * @param {ccs.TextureResType} texType
163      */
164     loadTextures: function (normal, selected, disabled, texType) {
165         this.loadTextureNormal(normal, texType);
166         this.loadTexturePressed(selected, texType);
167         this.loadTextureDisabled(disabled, texType);
168     },
169 
170     /**
171      * Load normal state texture for button.
172      * @param {String} normal
173      * @param {ccs.TextureResType} texType
174      */
175     loadTextureNormal: function (normal, texType) {
176         if (!normal) {
177             return;
178         }
179         texType = texType||ccs.TextureResType.local;
180         this._normalFileName = normal;
181         this._normalTexType = texType;
182         if (this._scale9Enabled) {
183             switch (this._normalTexType) {
184                 case ccs.TextureResType.local:
185                     this._buttonNormalRenderer.initWithFile(normal);
186                     break;
187                 case ccs.TextureResType.plist:
188                     this._buttonNormalRenderer.initWithSpriteFrameName(normal);
189                     break;
190                 default:
191                     break;
192             }
193             this._buttonNormalRenderer.setColor(this.getColor());
194             this._buttonNormalRenderer.setOpacity(this.getOpacity());
195             this._buttonNormalRenderer.setCapInsets(this._capInsetsNormal);
196         }
197         else {
198             switch (this._normalTexType) {
199                 case ccs.TextureResType.local:
200                     this._buttonNormalRenderer.initWithFile(normal);
201                     break;
202                 case ccs.TextureResType.plist:
203                     this._buttonNormalRenderer.initWithSpriteFrameName(normal);
204                     break;
205                 default:
206                     break;
207             }
208             this._buttonNormalRenderer.setColor(this.getColor());
209             this._buttonNormalRenderer.setOpacity(this.getOpacity());
210         }
211         this._normalTextureSize = this._buttonNormalRenderer.getContentSize();
212         this.updateAnchorPoint();
213         this.normalTextureScaleChangedWithSize();
214     },
215 
216     /**
217      * Load selected state texture for button.
218      * @param {String} selected
219      * @param {ccs.TextureResType} texType
220      */
221     loadTexturePressed: function (selected, texType) {
222         if (!selected) {
223             return;
224         }
225         texType = texType || ccs.TextureResType.local;
226         this._clickedFileName = selected;
227         this._pressedTexType = texType;
228         if (this._scale9Enabled) {
229             switch (this._pressedTexType) {
230                 case ccs.TextureResType.local:
231                     this._buttonClickedRenderer.initWithFile(selected);
232                     break;
233                 case ccs.TextureResType.plist:
234                     this._buttonClickedRenderer.initWithSpriteFrameName(selected);
235                     break;
236                 default:
237                     break;
238             }
239             this._buttonClickedRenderer.setColor(this.getColor());
240             this._buttonClickedRenderer.setOpacity(this.getOpacity());
241             this._buttonClickedRenderer.setCapInsets(this._capInsetsNormal);
242         }
243         else {
244             switch (this._pressedTexType) {
245                 case ccs.TextureResType.local:
246                     this._buttonClickedRenderer.initWithFile(selected);
247                     break;
248                 case ccs.TextureResType.plist:
249                     this._buttonClickedRenderer.initWithSpriteFrameName(selected);
250                     break;
251                 default:
252                     break;
253             }
254             this._buttonClickedRenderer.setColor(this.getColor());
255             this._buttonClickedRenderer.setOpacity(this.getOpacity());
256         }
257         this._pressedTextureSize = this._buttonClickedRenderer.getContentSize();
258         this.updateAnchorPoint();
259         this.pressedTextureScaleChangedWithSize();
260     },
261 
262     /**
263      * Load dark state texture for button.
264      * @param {String} disabled
265      * @param {ccs.TextureResType} texType
266      */
267     loadTextureDisabled: function (disabled, texType) {
268         if (!disabled) {
269             return;
270         }
271         texType = texType || ccs.TextureResType.local;
272         this._disabledFileName = disabled;
273         this._disabledTexType = texType;
274         if (this._scale9Enabled) {
275             switch (this._disabledTexType) {
276                 case ccs.TextureResType.local:
277                     this._buttonDisableRenderer.initWithFile(disabled);
278                     break;
279                 case ccs.TextureResType.plist:
280                     this._buttonDisableRenderer.initWithSpriteFrameName(disabled);
281                     break;
282                 default:
283                     break;
284             }
285             this._buttonDisableRenderer.setColor(this.getColor());
286             this._buttonDisableRenderer.setOpacity(this.getOpacity());
287             this._buttonDisableRenderer.setCapInsets(this._capInsetsNormal);
288         }
289         else {
290             switch (this._disabledTexType) {
291                 case ccs.TextureResType.local:
292                     this._buttonDisableRenderer.initWithFile(disabled);
293                     break;
294                 case ccs.TextureResType.plist:
295                     this._buttonDisableRenderer.initWithSpriteFrameName(disabled);
296                     break;
297                 default:
298                     break;
299             }
300             this._buttonDisableRenderer.setColor(this.getColor());
301             this._buttonDisableRenderer.setOpacity(this.getOpacity());
302         }
303         this._disabledTextureSize = this._buttonDisableRenderer.getContentSize();
304         this.updateAnchorPoint();
305         this.disabledTextureScaleChangedWithSize();
306     },
307 
308     /**
309      * Sets capinsets for button, if button is using scale9 renderer.
310      * @param {cc.Rect} capInsets
311      */
312     setCapInsets: function (capInsets) {
313         this.setCapInsetsNormalRenderer(capInsets);
314         this.setCapInsetsPressedRenderer(capInsets);
315         this.setCapInsetsDisabledRenderer(capInsets);
316     },
317 
318     /**
319      * Sets capinsets for button, if button is using scale9 renderer.
320      * @param {cc.Rect} capInsets
321      */
322     setCapInsetsNormalRenderer: function (capInsets) {
323         this._capInsetsNormal = capInsets;
324         if (!this._scale9Enabled) {
325             return;
326         }
327         this._buttonNormalRenderer.setCapInsets(capInsets);
328     },
329 
330     /**
331      * Sets capinsets for button, if button is using scale9 renderer.
332      * @param {cc.Rect} capInsets
333      */
334     setCapInsetsPressedRenderer: function (capInsets) {
335         this._capInsetsPressed = capInsets;
336         if (!this._scale9Enabled) {
337             return;
338         }
339         this._buttonClickedRenderer.setCapInsets(capInsets);
340     },
341 
342     /**
343      * Sets capinsets for button, if button is using scale9 renderer.
344      * @param {cc.Rect} capInsets
345      */
346     setCapInsetsDisabledRenderer: function (capInsets) {
347         this._capInsetsDisabled = capInsets;
348         if (!this._scale9Enabled) {
349             return;
350         }
351         this._buttonDisableRenderer.setCapInsets(capInsets);
352     },
353 
354     onPressStateChangedToNormal: function () {
355         this._buttonNormalRenderer.setVisible(true);
356         this._buttonClickedRenderer.setVisible(false);
357         this._buttonDisableRenderer.setVisible(false);
358         if (this._pressedActionEnabled) {
359             this._buttonNormalRenderer.stopAllActions();
360             this._buttonClickedRenderer.stopAllActions();
361             this._buttonDisableRenderer.stopAllActions();
362             var zoomAction = cc.ScaleTo.create(0.05, 1.0);
363             var zoomAction1 = cc.ScaleTo.create(0.05, 1.0);
364             var zoomAction2 = cc.ScaleTo.create(0.05, 1.0);
365             this._buttonNormalRenderer.runAction(zoomAction);
366             this._buttonClickedRenderer.runAction(zoomAction1);
367             this._buttonDisableRenderer.runAction(zoomAction2);
368         }
369     },
370 
371     onPressStateChangedToPressed: function () {
372         this._buttonNormalRenderer.setVisible(false);
373         this._buttonClickedRenderer.setVisible(true);
374         this._buttonDisableRenderer.setVisible(false);
375         if (this._pressedActionEnabled) {
376             this._buttonNormalRenderer.stopAllActions();
377             this._buttonClickedRenderer.stopAllActions();
378             this._buttonDisableRenderer.stopAllActions();
379             var zoomAction = cc.ScaleTo.create(0.05, 1.1);
380             var zoomAction1 = cc.ScaleTo.create(0.05, 1.1);
381             var zoomAction2 = cc.ScaleTo.create(0.05, 1.1);
382             this._buttonNormalRenderer.runAction(zoomAction);
383             this._buttonClickedRenderer.runAction(zoomAction1);
384             this._buttonDisableRenderer.runAction(zoomAction2);
385         }
386     },
387 
388     onPressStateChangedToDisabled: function () {
389         this._buttonNormalRenderer.setVisible(false);
390         this._buttonClickedRenderer.setVisible(false);
391         this._buttonDisableRenderer.setVisible(true);
392     },
393 
394     /**
395      * override "setFlippedX" of widget.
396      * @param {Boolean} flipX
397      */
398     setFlippedX: function (flipX) {
399         this._titleRenderer.setFlippedX(flipX);
400         if (this._scale9Enabled) {
401             return;
402         }
403         this._buttonNormalRenderer.setFlippedX(flipX);
404         this._buttonClickedRenderer.setFlippedX(flipX);
405         this._buttonDisableRenderer.setFlippedX(flipX);
406     },
407 
408     /**
409      * override "setFlippedY" of widget.
410      * @param {Boolean} flipY
411      */
412     setFlippedY: function (flipY) {
413         this._titleRenderer.setFlippedY(flipY);
414         if (this._scale9Enabled) {
415             return;
416         }
417         this._buttonNormalRenderer.setFlippedY(flipY);
418         this._buttonClickedRenderer.setFlippedY(flipY);
419         this._buttonDisableRenderer.setFlippedY(flipY);
420     },
421 
422     /**
423      * override "isFlippedX" of widget.
424      * @returns {Boolean}
425      */
426     isFlippedX: function () {
427         if (this._scale9Enabled) {
428             return false;
429         }
430         return this._buttonNormalRenderer.isFlippedX();
431     },
432 
433     /**
434      * override "isFlippedY" of widget.
435      * @returns {Boolean}
436      */
437     isFlippedY: function () {
438         if (this._scale9Enabled) {
439             return false;
440         }
441         return this._buttonNormalRenderer.isFlippedY();
442     },
443 
444     /**
445      * override "setAnchorPoint" of widget.
446      * @param {cc.Point} pt
447      */
448     setAnchorPoint: function (pt) {
449         ccs.UIWidget.prototype.setAnchorPoint.call(this,pt);
450         this._buttonNormalRenderer.setAnchorPoint(pt);
451         this._buttonClickedRenderer.setAnchorPoint(pt);
452         this._buttonDisableRenderer.setAnchorPoint(pt);
453         this._titleRenderer.setPosition(cc.p(this._size.width * (0.5 - this._anchorPoint.x), this._size.height * (0.5 - this._anchorPoint.y)));
454     },
455 
456     onSizeChanged: function () {
457         this.normalTextureScaleChangedWithSize();
458         this.pressedTextureScaleChangedWithSize();
459         this.disabledTextureScaleChangedWithSize();
460     },
461 
462     /**
463      * override "getContentSize" method of widget.
464      * @returns {cc.Size}
465      */
466     getContentSize: function () {
467         return this._normalTextureSize;
468     },
469 
470     /**
471      * override "getContentSize" method of widget.
472      * @returns {cc.Node}
473      */
474     getVirtualRenderer: function () {
475         if (this._bright) {
476             switch (this._brightStyle) {
477                 case ccs.BrightStyle.normal:
478                     return this._buttonNormalRenderer;
479                 case ccs.BrightStyle.highlight:
480                     return this._buttonClickedRenderer;
481                 default:
482                     return null;
483             }
484         }
485         else {
486             return this._buttonDisableRenderer;
487         }
488     },
489 
490     normalTextureScaleChangedWithSize: function () {
491         if (this._ignoreSize) {
492             if (!this._scale9Enabled) {
493                 this._buttonNormalRenderer.setScale(1.0);
494                 this._size = this._normalTextureSize;
495             }
496         }
497         else {
498             if (this._scale9Enabled) {
499                 this._buttonNormalRenderer.setPreferredSize(this._size);
500             }
501             else {
502                 var textureSize = this._normalTextureSize;
503                 if (textureSize.width <= 0.0 || textureSize.height <= 0.0) {
504                     this._buttonNormalRenderer.setScale(1.0);
505                     return;
506                 }
507                 var scaleX = this._size.width / textureSize.width;
508                 var scaleY = this._size.height / textureSize.height;
509                 this._buttonNormalRenderer.setScaleX(scaleX);
510                 this._buttonNormalRenderer.setScaleY(scaleY);
511             }
512         }
513     },
514 
515     pressedTextureScaleChangedWithSize: function () {
516         if (this._ignoreSize) {
517             if (!this._scale9Enabled) {
518                 this._buttonClickedRenderer.setScale(1.0);
519             }
520         }
521         else {
522             if (this._scale9Enabled) {
523                 this._buttonClickedRenderer.setPreferredSize(this._size);
524             }
525             else {
526                 var textureSize = this._pressedTextureSize;
527                 if (textureSize.width <= 0.0 || textureSize.height <= 0.0) {
528                     this._buttonClickedRenderer.setScale(1.0);
529                     return;
530                 }
531                 var scaleX = this._size.width / this._pressedTextureSize.width;
532                 var scaleY = this._size.height / this._pressedTextureSize.height;
533                 this._buttonClickedRenderer.setScaleX(scaleX);
534                 this._buttonClickedRenderer.setScaleY(scaleY);
535             }
536         }
537     },
538 
539     disabledTextureScaleChangedWithSize: function () {
540         if (this._ignoreSize) {
541             if (!this._scale9Enabled) {
542                 this._buttonDisableRenderer.setScale(1.0);
543             }
544         }
545         else {
546             if (this._scale9Enabled) {
547                 this._buttonDisableRenderer.setPreferredSize(this._size);
548             }
549             else {
550                 var textureSize = this._disabledTextureSize;
551                 if (textureSize.width <= 0.0 || textureSize.height <= 0.0) {
552                     this._buttonDisableRenderer.setScale(1.0);
553                     return;
554                 }
555                 var scaleX = this._size.width / this._disabledTextureSize.width;
556                 var scaleY = this._size.height / this._disabledTextureSize.height;
557                 this._buttonDisableRenderer.setScaleX(scaleX);
558                 this._buttonDisableRenderer.setScaleY(scaleY);
559             }
560         }
561     },
562 
563     /**
564      * Changes if button can be clicked zoom effect.
565      * @param {Boolean} enabled
566      */
567     setPressedActionEnabled: function (enabled) {
568         this._pressedActionEnabled = enabled;
569     },
570 
571     /**
572      * set title text
573      * @param {String} text
574      */
575     setTitleText: function (text) {
576         this._titleRenderer.setString(text);
577     },
578 
579     /**
580      * get title text
581      * @returns {String} text
582      */
583     getTitleText: function () {
584         return this._titleRenderer.getString();
585     },
586 
587     /**
588      * set title color
589      * @param {cc.c3b} color
590      */
591     setTitleColor: function (color) {
592         this._titleColor = color;
593         this._titleRenderer.setColor(color);
594     },
595 
596     /**
597      * get title color
598      * @returns {cc.c3b}
599      */
600     getTitleColor: function () {
601         return this._titleRenderer.getColor();
602     },
603 
604     /**
605      * set title fontSize
606      * @param {cc.Size} size
607      */
608     setTitleFontSize: function (size) {
609         this._titleRenderer.setFontSize(size);
610     },
611 
612     /**
613      * get title fontSize
614      * @returns {cc.Size}
615      */
616     getTitleFontSize: function () {
617         return this._titleRenderer.getFontSize();
618     },
619 
620     /**
621      * set title fontName
622      * @param {String} fontName
623      */
624     setTitleFontName: function (fontName) {
625         this._titleRenderer.setFontName(fontName);
626     },
627 
628     /**
629      * get title fontName
630      * @returns {String}
631      */
632     getTitleFontName: function () {
633         return this._titleRenderer.getFontName();
634     },
635 
636     /**
637      * Sets color to widget
638      * It default change the color of widget's children.
639      * @param color
640      */
641     setColor: function (color) {
642         ccs.UIWidget.prototype.setColor.call(this,color);
643         this.setTitleColor(this._titleColor);
644     },
645 
646     /**
647      * Returns the "class name" of widget.
648      * @returns {string}
649      */
650     getDescription: function () {
651         return "Button";
652     },
653 
654     createCloneInstance:function(){
655         return ccs.UIButton.create();
656     },
657 
658     copySpecialProperties:function(uiButton){
659         this._prevIgnoreSize = uiButton._prevIgnoreSize;
660         this.setScale9Enabled(uiButton._scale9Enabled);
661         this.loadTextureNormal(uiButton._normalFileName, uiButton._normalTexType);
662         this.loadTexturePressed(uiButton._clickedFileName, uiButton._pressedTexType);
663         this.loadTextureDisabled(uiButton._disabledFileName, uiButton._disabledTexType);
664         this.setCapInsetsNormalRenderer(uiButton._capInsetsNormal);
665         this.setCapInsetsPressedRenderer(uiButton._capInsetsPressed);
666         this.setCapInsetsDisabledRenderer(uiButton._capInsetsDisabled);
667         this.setTitleText(uiButton.getTitleText());
668         this.setTitleFontName(uiButton.getTitleFontName());
669         this.setTitleFontSize(uiButton.getTitleFontSize());
670         this.setTitleColor(uiButton.getTitleColor());
671         this.setPressedActionEnabled(uiButton._pressedActionEnabled);
672     }
673 
674 });
675 /**
676  * allocates and initializes a UIButton.
677  * @constructs
678  * @return {ccs.UIButton}
679  * @example
680  * // example
681  * var uiButton = ccs.UIButton.create();
682  */
683 ccs.UIButton.create = function () {
684     var uiButton = new ccs.UIButton();
685     if (uiButton && uiButton.init()) {
686         return uiButton;
687     }
688     return null;
689 };