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