CCControlStepper.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Copyright (c) 2012 cocos2d-x.org
  3. * http://www.cocos2d-x.org
  4. *
  5. * Copyright 2012 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. */
  27. #ifndef __CCCONTROLSTEPPER_H__
  28. #define __CCCONTROLSTEPPER_H__
  29. #include "CCControl.h"
  30. #include "2d/CCLabel.h"
  31. #include "extensions/ExtensionExport.h"
  32. NS_CC_EXT_BEGIN
  33. /**
  34. * @addtogroup GUI
  35. * @{
  36. * @addtogroup control_extension
  37. * @{
  38. */
  39. class CC_EX_DLL ControlStepper : public Control
  40. {
  41. public:
  42. enum class Part
  43. {
  44. MINUS,
  45. PLUS,
  46. NONE
  47. };
  48. static ControlStepper* create(Sprite *minusSprite, Sprite *plusSprite);
  49. /**
  50. * @js ctor
  51. * @lua new
  52. */
  53. ControlStepper();
  54. /**
  55. * @js NA
  56. * @lua NA
  57. */
  58. virtual ~ControlStepper();
  59. bool initWithMinusSpriteAndPlusSprite(Sprite *minusSprite, Sprite *plusSprite);
  60. virtual void setWraps(bool wraps);
  61. virtual void setMinimumValue(double minimumValue);
  62. virtual void setMaximumValue(double maximumValue);
  63. virtual void setValue(double value);
  64. virtual double getValue() const;
  65. virtual void setStepValue(double stepValue);
  66. /** Set the numeric value of the stepper. If send is true, the Control::EventType::VALUE_CHANGED is sent. */
  67. virtual void setValueWithSendingEvent(double value, bool send);
  68. virtual bool isContinuous() const;
  69. // Overrides
  70. virtual bool onTouchBegan(Touch *pTouch, Event *pEvent) override;
  71. virtual void onTouchMoved(Touch *pTouch, Event *pEvent) override;
  72. virtual void onTouchEnded(Touch *pTouch, Event *pEvent) override;
  73. void update(float dt) override;
  74. /** Update the layout of the stepper with the given touch location. */
  75. void updateLayoutUsingTouchLocation(Vec2 location);
  76. /** Start the autorepeat increment/decrement. */
  77. void startAutorepeat();
  78. /** Stop the autorepeat. */
  79. void stopAutorepeat();
  80. protected:
  81. /** The numeric value of the stepper. */
  82. double _value;
  83. /** The continuous vs. noncontinuous state of the stepper. */
  84. bool _continuous;
  85. /** The automatic vs. nonautomatic repeat state of the stepper. */
  86. bool _autorepeat;
  87. /** The wrap vs. no-wrap state of the stepper. */
  88. bool _wraps;
  89. /** The lowest possible numeric value for the stepper. */
  90. double _minimumValue;
  91. /** The highest possible numeric value for the stepper. */
  92. double _maximumValue;
  93. /** The step, or increment, value for the stepper. */
  94. double _stepValue;
  95. bool _touchInsideFlag;
  96. Part _touchedPart;
  97. int _autorepeatCount;
  98. // Weak links to children
  99. CC_SYNTHESIZE_RETAIN(Sprite*, _minusSprite, MinusSprite)
  100. CC_SYNTHESIZE_RETAIN(Sprite*, _plusSprite, PlusSprite)
  101. CC_SYNTHESIZE_RETAIN(Label*, _minusLabel, MinusLabel)
  102. CC_SYNTHESIZE_RETAIN(Label*, _plusLabel, PlusLabel)
  103. };
  104. // end of GUI group
  105. /// @}
  106. /// @}
  107. NS_CC_EXT_END
  108. #endif /* __CCCONTROLSTEPPER_H__ */