CCControlSlider.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (c) 2012 cocos2d-x.org
  3. * http://www.cocos2d-x.org
  4. *
  5. * Copyright 2011 Yannick Loriot. All rights reserved.
  6. * http://yannickloriot.com
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. * Converted to c++ / cocos2d-x by Angus C
  27. */
  28. #ifndef __CCCONTROL_SLIDER_H__
  29. #define __CCCONTROL_SLIDER_H__
  30. #include "CCControl.h"
  31. #include "CCInvocation.h"
  32. #include "extensions/ExtensionExport.h"
  33. NS_CC_EXT_BEGIN
  34. /**
  35. * @addtogroup GUI
  36. * @{
  37. * @addtogroup control_extension
  38. * @{
  39. */
  40. class CC_EX_DLL ControlSlider: public Control
  41. {
  42. public:
  43. /**
  44. * Creates slider with a background filename, a progress filename and a
  45. * thumb image filename.
  46. */
  47. static ControlSlider* create(const char* bgFile, const char* progressFile, const char* thumbFile);
  48. /**
  49. * Creates a slider with a given background sprite and a progress bar and a
  50. * thumb item.
  51. *
  52. * @see initWithSprites
  53. */
  54. static ControlSlider* create(Sprite * backgroundSprite, Sprite* pogressSprite, Sprite* thumbSprite);
  55. /**
  56. * Creates slider with a background filename, a progress filename, a thumb
  57. * and a selected thumb image filename.
  58. */
  59. static ControlSlider* create(const char* bgFile, const char* progressFile, const char* thumbFile,
  60. const char* selectedThumbSpriteFile);
  61. /**
  62. * Creates a slider with a given background sprite and a progress bar, a thumb
  63. * and a selected thumb .
  64. *
  65. * @see initWithSprites
  66. */
  67. static ControlSlider* create(Sprite * backgroundSprite, Sprite* pogressSprite, Sprite* thumbSprite,
  68. Sprite* selectedThumbSprite);
  69. /**
  70. * @js ctor
  71. * @lua new
  72. */
  73. ControlSlider();
  74. /**
  75. * @js NA
  76. * @lua NA
  77. */
  78. virtual ~ControlSlider();
  79. /**
  80. * Initializes a slider with a background sprite, a progress bar and a thumb
  81. * item.
  82. *
  83. * @param backgroundSprite Sprite, that is used as a background.
  84. * @param progressSprite Sprite, that is used as a progress bar.
  85. * @param thumbSprite Sprite, that is used as a thumb.
  86. */
  87. virtual bool initWithSprites(Sprite * backgroundSprite, Sprite* progressSprite, Sprite* thumbSprite);
  88. /**
  89. * Initializes a slider with a background sprite, a progress bar and a thumb
  90. * item.
  91. *
  92. * @param backgroundSprite Sprite, that is used as a background.
  93. * @param progressSprite Sprite, that is used as a progress bar.
  94. * @param thumbSprite Sprite, that is used as a thumb.
  95. * @param selectedThumbSprite Sprite, that is used as a selected thumb.
  96. */
  97. virtual bool initWithSprites(Sprite * backgroundSprite, Sprite* progressSprite, Sprite* thumbSprite,
  98. Sprite* selectedThumbSprite);
  99. virtual void needsLayout() override;
  100. virtual void setMaximumValue(float val);
  101. virtual void setEnabled(bool enabled) override;
  102. virtual bool isTouchInside(Touch * touch) override;
  103. Vec2 locationFromTouch(Touch* touch);
  104. virtual void setValue(float val);
  105. virtual void setMinimumValue(float val);
  106. protected:
  107. void sliderBegan(Vec2 location);
  108. void sliderMoved(Vec2 location);
  109. void sliderEnded(Vec2 location);
  110. virtual bool onTouchBegan(Touch* touch, Event* pEvent) override;
  111. virtual void onTouchMoved(Touch *pTouch, Event *pEvent) override;
  112. virtual void onTouchEnded(Touch *pTouch, Event *pEvent) override;
  113. /** Returns the value for the given location. */
  114. float valueForLocation(Vec2 location);
  115. //manually put in the setters
  116. /** Contains the receiver's current value. */
  117. CC_SYNTHESIZE_READONLY(float, _value, Value);
  118. /** Contains the minimum value of the receiver.
  119. * The default value of this property is 0.0. */
  120. CC_SYNTHESIZE_READONLY(float, _minimumValue, MinimumValue);
  121. /** Contains the maximum value of the receiver.
  122. * The default value of this property is 1.0. */
  123. CC_SYNTHESIZE_READONLY(float, _maximumValue, MaximumValue);
  124. CC_SYNTHESIZE(float, _minimumAllowedValue, MinimumAllowedValue);
  125. CC_SYNTHESIZE(float, _maximumAllowedValue, MaximumAllowedValue);
  126. // maybe this should be read-only
  127. CC_SYNTHESIZE_RETAIN(Sprite*, _thumbSprite, ThumbSprite);
  128. CC_SYNTHESIZE_RETAIN(Sprite*, _selectedThumbSprite, SelectedThumbSprite);
  129. CC_SYNTHESIZE_RETAIN(Sprite*, _progressSprite, ProgressSprite);
  130. CC_SYNTHESIZE_RETAIN(Sprite*, _backgroundSprite, BackgroundSprite);
  131. };
  132. // end of GUI group
  133. /// @}
  134. /// @}
  135. NS_CC_EXT_END
  136. #endif