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.Slider
 28  * @class
 29  * @extends ccui.Widget
 30  *
 31  * @property {Number}   percent     - The current progress of loadingbar
 32  */
 33 ccui.Slider = ccui.Widget.extend(/** @lends ccui.Slider# */{
 34     _barRenderer: null,
 35     _progressBarRenderer: null,
 36     _progressBarTextureSize: null,
 37     _slidBallNormalRenderer: null,
 38     _slidBallPressedRenderer: null,
 39     _slidBallDisabledRenderer: null,
 40     _slidBallRenderer: null,
 41     _barLength: 0,
 42     _percent: 0,
 43     _scale9Enabled: false,
 44     _prevIgnoreSize: true,
 45     _textureFile: "",
 46     _progressBarTextureFile: "",
 47     _slidBallNormalTextureFile: "",
 48     _slidBallPressedTextureFile: "",
 49     _slidBallDisabledTextureFile: "",
 50     _capInsetsBarRenderer: null,
 51     _capInsetsProgressBarRenderer: null,
 52     _sliderEventListener: null,
 53     _sliderEventSelector: null,
 54     _barTexType: ccui.Widget.LOCAL_TEXTURE,
 55     _progressBarTexType: ccui.Widget.LOCAL_TEXTURE,
 56     _ballNTexType: ccui.Widget.LOCAL_TEXTURE,
 57     _ballPTexType: ccui.Widget.LOCAL_TEXTURE,
 58     _ballDTexType: ccui.Widget.LOCAL_TEXTURE,
 59     _isTextureLoaded: false,
 60     _className: "Slider",
 61     _barRendererAdaptDirty: true,
 62     _progressBarRendererDirty: true,
 63     /**
 64      * allocates and initializes a UISlider.
 65      * Constructor of ccui.Slider
 66      * @example
 67      * // example
 68      * var uiSlider = new ccui.Slider();
 69      */
 70     ctor: function () {
 71         this._progressBarTextureSize = cc.size(0, 0);
 72         this._capInsetsBarRenderer = cc.rect(0, 0, 0, 0);
 73         this._capInsetsProgressBarRenderer = cc.rect(0, 0, 0, 0);
 74         ccui.Widget.prototype.ctor.call(this);
 75     },
 76 
 77     init: function () {
 78         if (ccui.Widget.prototype.init.call(this)) {
 79 //            this.setTouchEnabled(true);
 80             return true;
 81         }
 82         return false;
 83     },
 84 
 85     initRenderer: function () {
 86         this._barRenderer = cc.Sprite.create();
 87         this._progressBarRenderer = cc.Sprite.create();
 88         this._progressBarRenderer.setAnchorPoint(0.0, 0.5);
 89         this.addProtectedChild(this._barRenderer, ccui.Slider.BASEBAR_RENDERER_ZORDER, -1);
 90         this.addProtectedChild(this._progressBarRenderer, ccui.Slider.PROGRESSBAR_RENDERER_ZORDER, -1);
 91         this._slidBallNormalRenderer = cc.Sprite.create();
 92         this._slidBallPressedRenderer = cc.Sprite.create();
 93         this._slidBallPressedRenderer.setVisible(false);
 94         this._slidBallDisabledRenderer = cc.Sprite.create();
 95         this._slidBallDisabledRenderer.setVisible(false);
 96         this._slidBallRenderer = cc.Node.create();
 97         this._slidBallRenderer.addChild(this._slidBallNormalRenderer);
 98         this._slidBallRenderer.addChild(this._slidBallPressedRenderer);
 99         this._slidBallRenderer.addChild(this._slidBallDisabledRenderer);
100         this.addProtectedChild(this._slidBallRenderer, ccui.Slider.BALL_RENDERER_ZORDER, -1);
101     },
102 
103     /**
104      * Load texture for slider bar.
105      * @param {String} fileName
106      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
107      */
108     loadBarTexture: function (fileName, texType) {
109         if (!fileName) {
110             return;
111         }
112         texType = texType || ccui.Widget.LOCAL_TEXTURE;
113         this._textureFile = fileName;
114         this._barTexType = texType;
115         var barRenderer = this._barRenderer;
116         switch (this._barTexType) {
117             case ccui.Widget.LOCAL_TEXTURE:
118                 if (this._scale9Enabled)
119                 {
120                     barRenderer.initWithFile(fileName);
121                 }
122                 else
123                 {
124                     barRenderer.setTexture(fileName);
125                 }
126                 break;
127             case ccui.Widget.PLIST_TEXTURE:
128                 if (this._scale9Enabled)
129                 {
130                     barRenderer.initWithSpriteFrameName(fileName);
131                 }
132                 else
133                 {
134                     barRenderer.setSpriteFrame(fileName);
135                 }
136 
137                 break;
138             default:
139                 break;
140         }
141         barRenderer.setColor(this.getColor());
142         barRenderer.setOpacity(this.getOpacity());
143 
144 
145         this._barRendererAdaptDirty = true;
146         this._progressBarRendererDirty = true;
147         this._updateContentSizeWithTextureSize(this._barRenderer.getContentSize());
148     },
149 
150     /**
151      * Load dark state texture for slider progress bar.
152      * @param {String} fileName
153      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
154      */
155     loadProgressBarTexture: function (fileName, texType) {
156         if (!fileName) {
157             return;
158         }
159         texType = texType || ccui.Widget.LOCAL_TEXTURE;
160         this._progressBarTextureFile = fileName;
161         this._progressBarTexType = texType;
162         var progressBarRenderer = this._progressBarRenderer;
163         switch (this._progressBarTexType) {
164             case ccui.Widget.LOCAL_TEXTURE:
165                 if (this._scale9Enabled)
166                 {
167                     progressBarRenderer.initWithFile(fileName);
168                 }
169                 else
170                 {
171                     progressBarRenderer.setTexture(fileName);
172                 }
173                 break;
174             case ccui.Widget.PLIST_TEXTURE:
175                 if (this._scale9Enabled)
176                 {
177                     progressBarRenderer.initWithSpriteFrameName(fileName);
178                 }
179                 else
180                 {
181                     progressBarRenderer.setSpriteFrame(fileName);
182                 }
183                 break;
184             default:
185                 break;
186         }
187         this._progressBarRenderer.setColor(this.getColor());
188         this._progressBarRenderer.setOpacity(this.getOpacity());
189 
190         this._progressBarRenderer.setAnchorPoint(cc.p(0, 0.5));
191         var tz = this._progressBarRenderer.getContentSize();
192         this._progressBarTextureSize = {width: tz.width, height: tz.height};
193         this._progressBarRendererDirty = true;
194     },
195 
196     /**
197      * Sets if slider is using scale9 renderer.
198      * @param {Boolean} able
199      */
200     setScale9Enabled: function (able) {
201         if (this._scale9Enabled == able) {
202             return;
203         }
204 
205         this._scale9Enabled = able;
206         this.removeProtectedChild(this._barRenderer, true);
207         this.removeProtectedChild(this._progressBarRenderer, true);
208         this._barRenderer = null;
209         this._progressBarRenderer = null;
210         if (this._scale9Enabled) {
211             this._barRenderer = cc.Scale9Sprite.create();
212             this._progressBarRenderer = cc.Scale9Sprite.create();
213         }
214         else {
215             this._barRenderer = cc.Sprite.create();
216             this._progressBarRenderer = cc.Sprite.create();
217         }
218         this.loadBarTexture(this._textureFile, this._barTexType);
219         this.loadProgressBarTexture(this._progressBarTextureFile, this._progressBarTexType);
220         this.addProtectedChild(this._barRenderer, ccui.Slider.BASEBAR_RENDERER_ZORDER, -1);
221         this.addProtectedChild(this._progressBarRenderer, ccui.Slider.PROGRESSBAR_RENDERER_ZORDER, -1);
222         if (this._scale9Enabled) {
223             var ignoreBefore = this._ignoreSize;
224             this.ignoreContentAdaptWithSize(false);
225             this._prevIgnoreSize = ignoreBefore;
226         }
227         else {
228             this.ignoreContentAdaptWithSize(this._prevIgnoreSize);
229         }
230         this.setCapInsetsBarRenderer(this._capInsetsBarRenderer);
231         this.setCapInsetProgressBarRenderer(this._capInsetsProgressBarRenderer);
232     },
233 
234     /**
235      * Get  slider is using scale9 renderer or not.
236      * @returns {Boolean}
237      */
238     isScale9Enabled: function () {
239         return this._scale9Enabled;
240     },
241 
242     /**
243      * override "ignoreContentAdaptWithSize" method of widget.
244      * @param {Boolean} ignore
245      */
246     ignoreContentAdaptWithSize: function (ignore) {
247         if (!this._scale9Enabled || (this._scale9Enabled && !ignore)) {
248             ccui.Widget.prototype.ignoreContentAdaptWithSize.call(this, ignore);
249             this._prevIgnoreSize = ignore;
250         }
251     },
252 
253     /**
254      * Sets capinsets for slider, if slider is using scale9 renderer.
255      * @param {cc.Rect} capInsets
256      */
257     setCapInsets: function (capInsets) {
258         this.setCapInsetsBarRenderer(capInsets);
259         this.setCapInsetProgressBarRenderer(capInsets);
260     },
261 
262     /**
263      * Sets capinsets for slider, if slider is using scale9 renderer.
264      * @param {cc.Rect} capInsets
265      */
266     setCapInsetsBarRenderer: function (capInsets) {
267         this._capInsetsBarRenderer = capInsets;
268         if (!this._scale9Enabled) {
269             return;
270         }
271         this._barRenderer.setCapInsets(capInsets);
272     },
273 
274     /**
275      * Get cap insets for slider.
276      * @returns {cc.Rect}
277      */
278     getCapInsetsBarRenderer: function () {
279         return this._capInsetsBarRenderer;
280     },
281 
282     /**
283      * Sets capinsets for slider, if slider is using scale9 renderer.
284      * @param {cc.Rect} capInsets
285      */
286     setCapInsetProgressBarRenderer: function (capInsets) {
287         this._capInsetsProgressBarRenderer = capInsets;
288         if (!this._scale9Enabled) {
289             return;
290         }
291         this._progressBarRenderer.setCapInsets(capInsets);
292     },
293 
294     /**
295      * Get cap insets for slider.
296      * @returns {cc.Rect}
297      */
298     getCapInsetsProgressBarRebderer: function () {
299         return this._capInsetsProgressBarRenderer;
300     },
301 
302     /**
303      * Load textures for slider ball.
304      * @param {String} normal
305      * @param {String} pressed
306      * @param {String} disabled
307      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
308      */
309     loadSlidBallTextures: function (normal, pressed, disabled, texType) {
310         this.loadSlidBallTextureNormal(normal, texType);
311         this.loadSlidBallTexturePressed(pressed, texType);
312         this.loadSlidBallTextureDisabled(disabled, texType);
313     },
314 
315     /**
316      * Load normal state texture for slider ball.
317      * @param {String} normal
318      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
319      */
320     loadSlidBallTextureNormal: function (normal, texType) {
321         if (!normal) {
322             return;
323         }
324         texType = texType || ccui.Widget.LOCAL_TEXTURE;
325         this._slidBallNormalTextureFile = normal;
326         this._ballNTexType = texType;
327         switch (this._ballNTexType) {
328             case ccui.Widget.LOCAL_TEXTURE:
329 //                this._slidBallNormalRenderer.initWithFile(normal);
330                 this._slidBallNormalRenderer.setTexture(normal);
331                 break;
332             case ccui.Widget.PLIST_TEXTURE:
333 //                this._slidBallNormalRenderer.initWithSpriteFrameName(normal);
334                 this._slidBallNormalRenderer.setSpriteFrame(normal);
335                 break;
336             default:
337                 break;
338         }
339 //        this.updateColorToRenderer(this._slidBallNormalRenderer);
340         this._slidBallNormalRenderer.setColor(this.getColor());
341         this._slidBallNormalRenderer.setOpacity(this.getOpacity());
342     },
343 
344     /**
345      * Load selected state texture for slider ball.
346      * @param {String} pressed
347      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
348      */
349     loadSlidBallTexturePressed: function (pressed, texType) {
350         if (!pressed) {
351             return;
352         }
353         texType = texType || ccui.Widget.LOCAL_TEXTURE;
354         this._slidBallPressedTextureFile = pressed;
355         this._ballPTexType = texType;
356         switch (this._ballPTexType) {
357             case ccui.Widget.LOCAL_TEXTURE:
358 //                this._slidBallPressedRenderer.initWithFile(pressed);
359                 this._slidBallPressedRenderer.setTexture(pressed);
360                 break;
361             case ccui.Widget.PLIST_TEXTURE:
362 //                this._slidBallPressedRenderer.initWithSpriteFrameName(pressed);
363                 this._slidBallPressedRenderer.setSpriteFrame(pressed);
364                 break;
365             default:
366                 break;
367         }
368 //        this.updateColorToRenderer(this._slidBallPressedRenderer);
369         this._slidBallPressedRenderer.setColor(this.getColor());
370         this._slidBallPressedRenderer.setOpacity(this.getOpacity());
371     },
372 
373     /**
374      * Load dark state texture for slider ball.
375      * @param {String} disabled
376      * @param {ccui.Widget.LOCAL_TEXTURE|ccui.Widget.PLIST_TEXTURE} texType
377      */
378     loadSlidBallTextureDisabled: function (disabled, texType) {
379         if (!disabled) {
380             return;
381         }
382         texType = texType || ccui.Widget.LOCAL_TEXTURE;
383         this._slidBallDisabledTextureFile = disabled;
384         this._ballDTexType = texType;
385         switch (this._ballDTexType) {
386             case ccui.Widget.LOCAL_TEXTURE:
387 //                this._slidBallDisabledRenderer.initWithFile(disabled);
388                 this._slidBallDisabledRenderer.setTexture(disabled);
389                 break;
390             case ccui.Widget.PLIST_TEXTURE:
391 //                this._slidBallDisabledRenderer.initWithSpriteFrameName(disabled);
392                 this._slidBallDisabledRenderer.setSpriteFrame(disabled);
393                 break;
394             default:
395                 break;
396         }
397 //        this.updateColorToRenderer(this._slidBallDisabledRenderer);
398         this._slidBallDisabledRenderer.setColor(this.getColor());
399         this._slidBallDisabledRenderer.setOpacity(this.getOpacity());
400     },
401 
402     /**
403      * Changes the progress direction of slider.
404      * @param {number} percent
405      */
406     setPercent: function (percent) {
407         if (percent > 100) {
408             percent = 100;
409         }
410         if (percent < 0) {
411             percent = 0;
412         }
413         this._percent = percent;
414         var res = percent / 100.0;
415         var dis = this._barLength * res;
416 //        this._slidBallRenderer.setPosition(-this._barLength / 2.0 + dis, 0.0);
417         this._slidBallRenderer.setPosition(cc.p(dis, this._contentSize.height / 2));
418         if (this._scale9Enabled) {
419             this._progressBarRenderer.setPreferredSize(cc.size(dis, this._progressBarTextureSize.height));
420         }
421         else {
422             var spriteRenderer = this._progressBarRenderer;
423             var rect = spriteRenderer.getTextureRect();
424             spriteRenderer.setTextureRect(
425                 cc.rect(rect.x, rect.y, dis, rect.height),
426                 spriteRenderer.isTextureRectRotated()
427             );
428         }
429     },
430 
431     hitTest: function(pt){
432         var nsp = this._slidBallNormalRenderer.convertToNodeSpace(pt);
433         var ballSize = this._slidBallNormalRenderer.getContentSize();
434         var ballRect = cc.rect(0,0, ballSize.width, ballSize.height);
435         return cc.rectContainsPoint(ballRect, nsp);
436     },
437 
438     onTouchBegan: function (touch, event) {
439         var pass = ccui.Widget.prototype.onTouchBegan.call(this, touch, event);
440         if (this._hitted) {
441             var nsp = this.convertToNodeSpace(this._touchBeganPosition);
442             this.setPercent(this.getPercentWithBallPos(nsp.x));
443             this.percentChangedEvent();
444         }
445         return pass;
446     },
447 
448     onTouchMoved: function (touch, event) {
449         var touchPoint = touch.getLocation();
450 //        this._touchMovePosition.x = touchPoint.x;
451 //        this._touchMovePosition.y = touchPoint.y;
452         var nsp = this.convertToNodeSpace(touchPoint);
453 //        this._slidBallRenderer.setPosition(nsp.x, 0);
454         this.setPercent(this.getPercentWithBallPos(nsp.x));
455         this.percentChangedEvent();
456     },
457 
458     onTouchEnded: function (touch, event) {
459         ccui.Widget.prototype.onTouchEnded.call(this, touch, event);
460     },
461 
462     onTouchCancelled: function (touch, event) {
463         ccui.Widget.prototype.onTouchCancelled.call(this, touch, event);
464     },
465 
466     /**
467      * get percent with ballPos
468      * @param {cc.Point} px
469      * @returns {number}
470      */
471     getPercentWithBallPos: function (px) {
472         return ((px/this._barLength)*100);
473     },
474 
475     /**
476      * add event listener
477      * @param {Function} selector
478      * @param {Object} target
479      */
480     addEventListenerSlider: function (selector, target) {
481         this._sliderEventSelector = selector;
482         this._sliderEventListener = target;
483     },
484 
485     addEventListener: function(callback){
486         this._eventCallback = callback;
487     },
488 
489     percentChangedEvent: function () {
490         if (this._sliderEventListener && this._sliderEventSelector) {
491             this._sliderEventSelector.call(this._sliderEventListener, this, ccui.Slider.EVENT_PERCENT_CHANGED);
492         }
493         if (this._eventCallback) {
494             this._eventCallback(ccui.Slider.EVENT_PERCENT_CHANGED);
495         }
496     },
497 
498     /**
499      * Gets the progress direction of slider.
500      * @returns {number}
501      */
502     getPercent: function () {
503         return this._percent;
504     },
505 
506     onSizeChanged: function () {
507         ccui.Widget.prototype.onSizeChanged.call(this);
508 //        this.barRendererScaleChangedWithSize();
509 //        this.progressBarRendererScaleChangedWithSize();
510         this._barRendererAdaptDirty = true;
511         this._progressBarRendererDirty = true;
512     },
513 
514     adaptRenderers: function(){
515         if (this._barRendererAdaptDirty)
516         {
517             this.barRendererScaleChangedWithSize();
518             this._barRendererAdaptDirty = false;
519         }
520         if (this._progressBarRendererDirty)
521         {
522             this.progressBarRendererScaleChangedWithSize();
523             this._progressBarRendererDirty = false;
524         }
525 
526     },
527 
528     getVirtualRendererSize: function(){
529         return this._barRenderer.getContentSize();
530     },
531 
532     /**
533      * override "getContentSize" method of widget.
534      * @returns {cc.Node}
535      */
536     getVirtualRenderer: function () {
537         return this._barRenderer;
538     },
539 
540     barRendererScaleChangedWithSize: function () {
541         if (this._ignoreSize) {
542             this._barRenderer.setScale(1.0);
543 //            var locSize = this._barRenderer.getContentSize();
544 //            this._size.width = locSize.width;
545 //            this._size.height = locSize.height;
546             this._barLength = this._contentSize.width;
547         }
548         else {
549 //            this._barLength = this._size.width;
550             this._barLength = this._contentSize.width;
551             if (this._scale9Enabled) {
552 //                this._barRenderer.setPreferredSize(cc.size(this._size.width, this._size.height));
553                 this._barRenderer.setPreferredSize(this._contentSize);
554             }
555             else {
556                 var btextureSize = this._barRenderer.getContentSize();
557                 if (btextureSize.width <= 0.0 || btextureSize.height <= 0.0) {
558                     this._barRenderer.setScale(1.0);
559                     return;
560                 }
561                 var bscaleX = this._contentSize.width / btextureSize.width;
562                 var bscaleY = this._contentSize.height / btextureSize.height;
563                 this._barRenderer.setScaleX(bscaleX);
564                 this._barRenderer.setScaleY(bscaleY);
565             }
566         }
567         this._barRenderer.setPosition(this._contentSize.width / 2.0, this._contentSize.height / 2.0);
568         this.setPercent(this._percent);
569     },
570 
571     progressBarRendererScaleChangedWithSize: function () {
572         if (this._ignoreSize) {
573             if (!this._scale9Enabled) {
574                 var ptextureSize = this._progressBarTextureSize;
575                 var pscaleX = this._contentSize.width / ptextureSize.width;
576                 var pscaleY = this._contentSize.height / ptextureSize.height;
577                 this._progressBarRenderer.setScaleX(pscaleX);
578                 this._progressBarRenderer.setScaleY(pscaleY);
579             }
580         }
581         else {
582             if (this._scale9Enabled) {
583 //                this._progressBarRenderer.setPreferredSize(cc.size(this._size.width, this._size.height));
584                 this._progressBarRenderer.setPreferredSize(this._contentSize);
585                 this._progressBarTextureSize = this._progressBarRenderer.getContentSize();
586             }
587             else {
588                 var ptextureSize = this._progressBarTextureSize;
589                 if (ptextureSize.width <= 0.0 || ptextureSize.height <= 0.0) {
590                     this._progressBarRenderer.setScale(1.0);
591                     return;
592                 }
593                 var pscaleX = this._contentSize.width / ptextureSize.width;
594                 var pscaleY = this._contentSize.height / ptextureSize.height;
595                 this._progressBarRenderer.setScaleX(pscaleX);
596                 this._progressBarRenderer.setScaleY(pscaleY);
597             }
598         }
599         this._progressBarRenderer.setPosition(0.0, this._contentSize.height / 2.0);
600         this.setPercent(this._percent);
601     },
602 
603     /**
604      * override "getContentSize" method of widget.
605      * @returns {cc.Size}
606      */
607     getContentSize: function () {
608         var locContentSize = this._barRenderer.getContentSize();
609         return cc.size(locContentSize.width, locContentSize.height);
610     },
611     _getWidth: function () {
612         return this._barRenderer._getWidth();
613     },
614     _getHeight: function () {
615         return this._barRenderer._getHeight();
616     },
617 
618     onPressStateChangedToNormal: function () {
619         this._slidBallNormalRenderer.setVisible(true);
620         this._slidBallPressedRenderer.setVisible(false);
621         this._slidBallDisabledRenderer.setVisible(false);
622     },
623 
624     onPressStateChangedToPressed: function () {
625         this._slidBallNormalRenderer.setVisible(false);
626         this._slidBallPressedRenderer.setVisible(true);
627         this._slidBallDisabledRenderer.setVisible(false);
628     },
629 
630     onPressStateChangedToDisabled: function () {
631         this._slidBallNormalRenderer.setVisible(false);
632         this._slidBallPressedRenderer.setVisible(false);
633         this._slidBallDisabledRenderer.setVisible(true);
634     },
635 
636     /**
637      * Returns the "class name" of widget.
638      * @returns {string}
639      */
640     getDescription: function () {
641         return "Slider";
642     },
643 
644     createCloneInstance: function () {
645         return ccui.Slider.create();
646     },
647 
648     copySpecialProperties: function (slider) {
649         this._prevIgnoreSize = slider._prevIgnoreSize;
650         this.setScale9Enabled(slider._scale9Enabled);
651         this.loadBarTexture(slider._textureFile, slider._barTexType);
652         this.loadProgressBarTexture(slider._progressBarTextureFile, slider._progressBarTexType);
653         this.loadSlidBallTextureNormal(slider._slidBallNormalTextureFile, slider._ballNTexType);
654         this.loadSlidBallTexturePressed(slider._slidBallPressedTextureFile, slider._ballPTexType);
655         this.loadSlidBallTextureDisabled(slider._slidBallDisabledTextureFile, slider._ballDTexType);
656         this.setPercent(slider.getPercent());
657         this._sliderEventListener = slider._sliderEventListener;
658         this._sliderEventSelector = slider._sliderEventSelector;
659         this._eventCallback = slider._eventCallback;
660 
661     },
662 
663     updateTextureColor: function () {
664         this.updateColorToRenderer(this._barRenderer);
665         this.updateColorToRenderer(this._progressBarRenderer);
666         this.updateColorToRenderer(this._slidBallNormalRenderer);
667         this.updateColorToRenderer(this._slidBallPressedRenderer);
668         this.updateColorToRenderer(this._slidBallDisabledRenderer);
669     },
670 
671     updateTextureOpacity: function () {
672         this.updateOpacityToRenderer(this._barRenderer);
673         this.updateOpacityToRenderer(this._progressBarRenderer);
674         this.updateOpacityToRenderer(this._slidBallNormalRenderer);
675         this.updateOpacityToRenderer(this._slidBallPressedRenderer);
676         this.updateOpacityToRenderer(this._slidBallDisabledRenderer);
677     }
678 });
679 
680 var _p = ccui.Slider.prototype;
681 
682 // Extended properties
683 /** @expose */
684 _p.percent;
685 cc.defineGetterSetter(_p, "percent", _p.getPercent, _p.setPercent);
686 
687 _p = null;
688 
689 /**
690  * allocates and initializes a UISlider.
691  * @constructs
692  * @return {ccui.Slider}
693  * @example
694  * // example
695  * var uiSlider = ccui.Slider.create();
696  */
697 ccui.Slider.create = function () {
698     var widget = new ccui.Slider();
699     if (widget && widget.init())
700     {
701         return widget;
702     }
703     return null;
704 };
705 
706 // Constant
707 //Slider event type
708 ccui.Slider.EVENT_PERCENT_CHANGED = 0;
709 
710 //Render zorder
711 ccui.Slider.BASEBAR_RENDERER_ZORDER = -3;
712 ccui.Slider.PROGRESSBAR_RENDERER_ZORDER = -2;
713 ccui.Slider.BALL_RENDERER_ZORDER = -1;