CCControlPotentiometer.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 __CCCONTROLPOTENTIOMETER_H__
  28. #define __CCCONTROLPOTENTIOMETER_H__
  29. #include "CCControl.h"
  30. #include "2d/CCProgressTimer.h"
  31. #include "extensions/ExtensionExport.h"
  32. NS_CC_EXT_BEGIN
  33. /**
  34. * @addtogroup GUI
  35. * @{
  36. * @addtogroup control_extension
  37. * @{
  38. */
  39. /** @class ControlPotentiometer Potentiometer control for Cocos2D. */
  40. class CC_EX_DLL ControlPotentiometer : public Control
  41. {
  42. public:
  43. /**
  44. * Creates potentiometer with a track filename and a progress filename.
  45. */
  46. static ControlPotentiometer* create(const char* backgroundFile, const char* progressFile, const char* thumbFile);
  47. /**
  48. * @js ctor
  49. * @lua new
  50. */
  51. ControlPotentiometer();
  52. /**
  53. * @js NA
  54. * @lua NA
  55. */
  56. virtual ~ControlPotentiometer();
  57. /**
  58. * Initializes a potentiometer with a track sprite and a progress bar.
  59. *
  60. * @param trackSprite Sprite, that is used as a background.
  61. * @param progressTimer ProgressTimer, that is used as a progress bar.
  62. */
  63. bool initWithTrackSprite_ProgressTimer_ThumbSprite(Sprite* trackSprite, ProgressTimer* progressTimer, Sprite* thumbSprite);
  64. void setValue(float value);
  65. float getValue();
  66. void setMinimumValue(float minimumValue);
  67. float getMinimumValue();
  68. void setMaximumValue(float maximumValue);
  69. float getMaximumValue();
  70. // Overrides
  71. virtual bool isTouchInside(Touch * touch) override;
  72. void setEnabled(bool enabled) override;
  73. virtual bool onTouchBegan(Touch *pTouch, Event *pEvent) override;
  74. virtual void onTouchMoved(Touch *pTouch, Event *pEvent) override;
  75. virtual void onTouchEnded(Touch *pTouch, Event *pEvent) override;
  76. /** Factorize the event dispatch into these methods. */
  77. void potentiometerBegan(Vec2 location);
  78. void potentiometerMoved(Vec2 location);
  79. void potentiometerEnded(Vec2 location);
  80. /** Returns the distance between the point1 and point2. */
  81. float distanceBetweenPointAndPoint(Vec2 point1, Vec2 point2);
  82. /** Returns the angle in degree between line1 and line2. */
  83. float angleInDegreesBetweenLineFromPoint_toPoint_toLineFromPoint_toPoint(
  84. Vec2 beginLineA,
  85. Vec2 endLineA,
  86. Vec2 beginLineB,
  87. Vec2 endLineB);
  88. protected:
  89. /** Contains the receiver’s current value. */
  90. float _value;
  91. /** Contains the minimum value of the receiver.
  92. * The default value of this property is 0.0. */
  93. float _minimumValue;
  94. /** Contains the maximum value of the receiver.
  95. * The default value of this property is 1.0. */
  96. float _maximumValue;
  97. CC_SYNTHESIZE_RETAIN(Sprite*, _thumbSprite, ThumbSprite)
  98. CC_SYNTHESIZE_RETAIN(ProgressTimer*, _progressTimer, ProgressTimer)
  99. CC_SYNTHESIZE(Vec2, _previousLocation, PreviousLocation)
  100. };
  101. // end of GUI group
  102. /// @}
  103. /// @}
  104. NS_CC_EXT_END
  105. #endif /* __CCCONTROLPOTENTIOMETER_H__ */