Slider.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../UI/BorderImage.h"
  5. namespace Urho3D
  6. {
  7. /// %Slider bar %UI element.
  8. class URHO3D_API Slider : public BorderImage
  9. {
  10. URHO3D_OBJECT(Slider, BorderImage);
  11. public:
  12. /// Construct.
  13. explicit Slider(Context* context);
  14. /// Destruct.
  15. ~Slider() override;
  16. /// Register object factory.
  17. /// @nobind
  18. static void RegisterObject(Context* context);
  19. /// Perform UI element update.
  20. void Update(float timeStep) override;
  21. /// React to mouse hover.
  22. void OnHover(const IntVector2& position, const IntVector2& screenPosition, MouseButtonFlags buttons, QualifierFlags qualifiers, Cursor* cursor) override;
  23. /// React to mouse click begin.
  24. void OnClickBegin
  25. (const IntVector2& position, const IntVector2& screenPosition, MouseButton button, MouseButtonFlags buttons, QualifierFlags qualifiers, Cursor* cursor) override;
  26. /// React to mouse click end.
  27. void OnClickEnd
  28. (const IntVector2& position, const IntVector2& screenPosition, MouseButton button, MouseButtonFlags buttons, QualifierFlags qualifiers, Cursor* cursor,
  29. UIElement* beginElement) override;
  30. /// React to mouse drag begin.
  31. void
  32. OnDragBegin(const IntVector2& position, const IntVector2& screenPosition, MouseButtonFlags buttons, QualifierFlags qualifiers, Cursor* cursor) override;
  33. /// React to mouse drag motion.
  34. void OnDragMove
  35. (const IntVector2& position, const IntVector2& screenPosition, const IntVector2& deltaPos, MouseButtonFlags buttons, QualifierFlags qualifiers,
  36. Cursor* cursor) override;
  37. /// React to mouse drag end.
  38. void
  39. OnDragEnd(const IntVector2& position, const IntVector2& screenPosition, MouseButtonFlags dragButtons, MouseButtonFlags releaseButtons, Cursor* cursor) override;
  40. /// React to resize.
  41. void OnResize(const IntVector2& newSize, const IntVector2& delta) override;
  42. /// Set orientation type.
  43. /// @property
  44. void SetOrientation(Orientation orientation);
  45. /// Set slider range maximum value (minimum value is always 0).
  46. /// @property
  47. void SetRange(float range);
  48. /// Set slider current value.
  49. /// @property
  50. void SetValue(float value);
  51. /// Change value by a delta.
  52. void ChangeValue(float delta);
  53. /// Set paging minimum repeat rate (number of events per second).
  54. /// @property
  55. void SetRepeatRate(float rate);
  56. /// Return orientation type.
  57. /// @property
  58. Orientation GetOrientation() const { return orientation_; }
  59. /// Return slider range.
  60. /// @property
  61. float GetRange() const { return range_; }
  62. /// Return slider current value.
  63. /// @property
  64. float GetValue() const { return value_; }
  65. /// Return knob element.
  66. /// @property
  67. BorderImage* GetKnob() const { return knob_; }
  68. /// Return paging minimum repeat rate (number of events per second).
  69. /// @property
  70. float GetRepeatRate() const { return repeatRate_; }
  71. protected:
  72. /// Filter implicit attributes in serialization process.
  73. bool FilterImplicitAttributes(XMLElement& dest) const override;
  74. /// Update slider knob position & size.
  75. void UpdateSlider();
  76. /// Send slider page event.
  77. void Page(const IntVector2& position, bool pressed);
  78. /// Slider knob.
  79. SharedPtr<BorderImage> knob_;
  80. /// Orientation.
  81. Orientation orientation_;
  82. /// Slider range.
  83. float range_;
  84. /// Slider current value.
  85. float value_;
  86. /// Internal flag of whether the slider is being dragged.
  87. bool dragSlider_;
  88. /// Original mouse cursor position at drag begin.
  89. IntVector2 dragBeginCursor_;
  90. /// Original slider position at drag begin.
  91. IntVector2 dragBeginPosition_;
  92. /// Paging repeat rate.
  93. float repeatRate_;
  94. /// Paging minimum repeat timer.
  95. Timer repeatTimer_;
  96. };
  97. }