Slider.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // Copyright (c) 2008-2020 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../UI/BorderImage.h"
  24. namespace Urho3D
  25. {
  26. /// %Slider bar %UI element.
  27. class URHO3D_API Slider : public BorderImage
  28. {
  29. URHO3D_OBJECT(Slider, BorderImage);
  30. public:
  31. /// Construct.
  32. explicit Slider(Context* context);
  33. /// Destruct.
  34. ~Slider() override;
  35. /// Register object factory.
  36. static void RegisterObject(Context* context);
  37. /// Perform UI element update.
  38. void Update(float timeStep) override;
  39. /// React to mouse hover.
  40. void OnHover(const IntVector2& position, const IntVector2& screenPosition, MouseButtonFlags buttons, QualifierFlags qualifiers, Cursor* cursor) override;
  41. /// React to mouse click begin.
  42. void OnClickBegin
  43. (const IntVector2& position, const IntVector2& screenPosition, MouseButton button, MouseButtonFlags buttons, QualifierFlags qualifiers, Cursor* cursor) override;
  44. /// React to mouse click end.
  45. void OnClickEnd
  46. (const IntVector2& position, const IntVector2& screenPosition, MouseButton button, MouseButtonFlags buttons, QualifierFlags qualifiers, Cursor* cursor,
  47. UIElement* beginElement) override;
  48. /// React to mouse drag begin.
  49. void
  50. OnDragBegin(const IntVector2& position, const IntVector2& screenPosition, MouseButtonFlags buttons, QualifierFlags qualifiers, Cursor* cursor) override;
  51. /// React to mouse drag motion.
  52. void OnDragMove
  53. (const IntVector2& position, const IntVector2& screenPosition, const IntVector2& deltaPos, MouseButtonFlags buttons, QualifierFlags qualifiers,
  54. Cursor* cursor) override;
  55. /// React to mouse drag end.
  56. void
  57. OnDragEnd(const IntVector2& position, const IntVector2& screenPosition, MouseButtonFlags dragButtons, MouseButtonFlags releaseButtons, Cursor* cursor) override;
  58. /// React to resize.
  59. void OnResize(const IntVector2& newSize, const IntVector2& delta) override;
  60. /// Set orientation type.
  61. /// @property
  62. void SetOrientation(Orientation orientation);
  63. /// Set slider range maximum value (minimum value is always 0).
  64. /// @property
  65. void SetRange(float range);
  66. /// Set slider current value.
  67. /// @property
  68. void SetValue(float value);
  69. /// Change value by a delta.
  70. void ChangeValue(float delta);
  71. /// Set paging minimum repeat rate (number of events per second).
  72. /// @property
  73. void SetRepeatRate(float rate);
  74. /// Return orientation type.
  75. /// @property
  76. Orientation GetOrientation() const { return orientation_; }
  77. /// Return slider range.
  78. /// @property
  79. float GetRange() const { return range_; }
  80. /// Return slider current value.
  81. /// @property
  82. float GetValue() const { return value_; }
  83. /// Return knob element.
  84. /// @property
  85. BorderImage* GetKnob() const { return knob_; }
  86. /// Return paging minimum repeat rate (number of events per second).
  87. /// @property
  88. float GetRepeatRate() const { return repeatRate_; }
  89. protected:
  90. /// Filter implicit attributes in serialization process.
  91. bool FilterImplicitAttributes(XMLElement& dest) const override;
  92. /// Update slider knob position & size.
  93. void UpdateSlider();
  94. /// Send slider page event.
  95. void Page(const IntVector2& position, bool pressed);
  96. /// Slider knob.
  97. SharedPtr<BorderImage> knob_;
  98. /// Orientation.
  99. Orientation orientation_;
  100. /// Slider range.
  101. float range_;
  102. /// Slider current value.
  103. float value_;
  104. /// Internal flag of whether the slider is being dragged.
  105. bool dragSlider_;
  106. /// Original mouse cursor position at drag begin.
  107. IntVector2 dragBeginCursor_;
  108. /// Original slider position at drag begin.
  109. IntVector2 dragBeginPosition_;
  110. /// Paging repeat rate.
  111. float repeatRate_;
  112. /// Paging minimum repeat timer.
  113. Timer repeatTimer_;
  114. };
  115. }