/Extensions/CCSlider/CCSlider.h

https://github.com/aliHafizji/cocos2d-iphone-extensions · C Header · 126 lines · 22 code · 14 blank · 90 comment · 0 complexity · 88cd3d55d02d4e468489556aa0c42bb1 MD5 · raw file

  1. /*
  2. * CCSlider
  3. *
  4. * cocos2d-extensions
  5. * https://github.com/cocos2d/cocos2d-iphone-extensions
  6. *
  7. * Copyright (c) 2011 Israel Roth
  8. * http://srooltheknife.blogspot.com/
  9. * https://bitbucket.org/iroth_net/ccslider
  10. *
  11. * Copyright (c) 2011 Stepan Generalov
  12. *
  13. * Permission is hereby granted, free of charge, to any person obtaining a copy
  14. * of this software and associated documentation files (the "Software"), to deal
  15. * in the Software without restriction, including without limitation the rights
  16. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  17. * copies of the Software, and to permit persons to whom the Software is
  18. * furnished to do so, subject to the following conditions:
  19. *
  20. * The above copyright notice and this permission notice shall be included in
  21. * all copies or substantial portions of the Software.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  24. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  26. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  27. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  28. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  29. * THE SOFTWARE.
  30. *
  31. */
  32. #import "cocos2d.h"
  33. static const NSInteger kCCSliderPriority = kCCMenuTouchPriority - 2;
  34. /** @class CCSlider Slider control for Cocos2D. Designed with SFX/Music level options in mind. */
  35. @interface CCSlider : CCLayer
  36. {
  37. float value;
  38. float minX;
  39. float maxX;
  40. // weak links to children
  41. CCMenuItem *_thumb;
  42. CCSprite *_bg;
  43. CCSprite *_progress;
  44. CGSize _progressPadding;
  45. }
  46. /** Current chosen value, min is 0.0f, max is 1.0f. */
  47. @property (nonatomic, assign) float value;
  48. /** Creates slider with backround image filename & thumb image filename.
  49. *
  50. * @see initWithBackgroundFile:thumbFile:
  51. */
  52. + (id) sliderWithBackgroundFile: (NSString *) bgFile thumbFile: (NSString *) thumbFile;
  53. /** Creates slider with given bg sprite and menu item as a thumb.
  54. *
  55. * @see initWithBackgroundSprite: thumbMenuItem:
  56. */
  57. +(id) sliderWithBackgroundSprite: (CCSprite *) bgSprite thumbMenuItem: (CCMenuItem *) aThumb;
  58. /** Creates slider with given bg sprite, progress color and thumb.
  59. *
  60. * @see initWithBackgroundSprite: sliderProgressColor sliderPadding thumbMenuItem
  61. */
  62. +(id) sliderWithBackgroundSprite: (CCSprite *) bgSprite sliderProgressColor:(ccColor4F) progressColor sliderPadding:(CGSize) padding thumbMenuItem: (CCMenuItem *) aThumb;
  63. /* Creates a slider with background image filename, progress color & thumb image filename.
  64. *
  65. * @see initWithBackgroundFile: sliderProgressColor: sliderPadding: thumbFile:
  66. */
  67. + (id) sliderWithBackgroundFile:(NSString *)bgFile sliderProgressColor:(ccColor4F) progressColor sliderPadding:(CGSize) padding thumbFile:(NSString *)thumbFile;
  68. /** Easy init - filenames instead of CCSprite & CCMenuItem. Uses designated init inside.
  69. *
  70. * @param thumbFile Filename, that is used to create normal & selected images for
  71. * thumbMenuItem. Selected sprite is darker than normal sprite.
  72. *
  73. * @param bgFile Filename for background CCSprite.
  74. */
  75. - (id) initWithBackgroundFile: (NSString *) bgFile thumbFile: (NSString *) thumbFile;
  76. /** Designated init.
  77. *
  78. * @param bgSprite CCSprite, that is used as a background. It's bounding box is used
  79. * to determine max & min x position for a thumb menu item.
  80. *
  81. * @param aThumb MenuItem that is used as a thumb. Used without CCMenu, so CCMenuItem#activate
  82. * doesn't get called.
  83. */
  84. -(id) initWithBackgroundSprite: (CCSprite *) bgSprite thumbMenuItem: (CCMenuItem *) aThumb;
  85. /**
  86. * @param bgSprite CCSprite, that is used as a background. It's bounding box is used
  87. * to determine max & min x position for a thumb menu item.
  88. *
  89. * @param progressColor ccColor4F, this is used to create a sprite of a color. This will represent
  90. * the progress.
  91. *
  92. * @param padding CGSize, this represents the total internal padding to give for the progress. The padding
  93. * will be relative to the bgSprite
  94. *
  95. * @param aThumb MenuItem that is used as a thumb. Used without CCMenu, so CCMenuItem#activate
  96. * doesn't get called.
  97. */
  98. - (id) initWithBackgroundSprite: (CCSprite *) bgSprite sliderProgressColor:(ccColor4F) progressColor sliderPadding:(CGSize) padding thumbMenuItem: (CCMenuItem *) aThumb;
  99. /**
  100. * @param bgFile Filename for background CCSprite.
  101. *
  102. * @param progressColor ccColor4F, this is used to create a sprite of a color. This will represent
  103. * the progress.
  104. *
  105. * @param padding CGSize, this represents the total internal padding to give for the progress. The padding
  106. * will be relative to the bgSprite
  107. *
  108. * @param thumbFile Filename, that is used to create normal & selected images for
  109. * thumbMenuItem. Selected sprite is darker than normal sprite.
  110. */
  111. - (id) initWithBackgroundFile:(NSString *)bgFile sliderProgressColor:(ccColor4F) progressColor sliderPadding:(CGSize) padding thumbFile:(NSString *)thumbFile;
  112. @end