Slider.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // Copyright (c) 2008-2013 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 "BorderImage.h"
  24. namespace Urho3D
  25. {
  26. /// %Slider bar %UI element.
  27. class Slider : public BorderImage
  28. {
  29. OBJECT(Slider);
  30. public:
  31. /// Construct.
  32. Slider(Context* context);
  33. /// Destruct.
  34. virtual ~Slider();
  35. /// Register object factory.
  36. static void RegisterObject(Context* context);
  37. /// Perform UI element update.
  38. virtual void Update(float timeStep);
  39. /// React to mouse hover.
  40. virtual void OnHover(const IntVector2& position, const IntVector2& screenPosition, int buttons, int qualifiers, Cursor* cursor);
  41. /// React to mouse click.
  42. virtual void OnClick(const IntVector2& position, const IntVector2& screenPosition, int buttons, int qualifiers, Cursor* cursor);
  43. /// React to mouse drag begin.
  44. virtual void OnDragBegin(const IntVector2& position, const IntVector2& screenPosition, int buttons, int qualifiers, Cursor* cursor);
  45. /// React to mouse drag motion.
  46. virtual void OnDragMove(const IntVector2& position, const IntVector2& screenPosition, int buttons, int qualifiers, Cursor* cursor);
  47. /// React to mouse drag end.
  48. virtual void OnDragEnd(const IntVector2& position, const IntVector2& screenPosition, Cursor* cursor);
  49. /// React to resize.
  50. virtual void OnResize();
  51. /// Set orientation type.
  52. void SetOrientation(Orientation orientation);
  53. /// Set slider range maximum value (minimum value is always 0.)
  54. void SetRange(float range);
  55. /// Set slider current value.
  56. void SetValue(float value);
  57. /// Change value by a delta.
  58. void ChangeValue(float delta);
  59. /// Set paging minimum repeat rate (number of events per second).
  60. void SetRepeatRate(float rate);
  61. /// Return orientation type.
  62. Orientation GetOrientation() const { return orientation_; }
  63. /// Return slider range.
  64. float GetRange() const { return range_; }
  65. /// Return slider current value.
  66. float GetValue() const { return value_; }
  67. /// Return knob element.
  68. BorderImage* GetKnob() const { return knob_; }
  69. /// Return paging minimum repeat rate (number of events per second).
  70. float GetRepeatRate() const { return repeatRate_; }
  71. protected:
  72. /// Update slider knob position & size.
  73. void UpdateSlider();
  74. /// Send slider page event.
  75. void Page(const IntVector2& position, int buttons, int qualifiers);
  76. /// Slider knob.
  77. SharedPtr<BorderImage> knob_;
  78. /// Orientation.
  79. Orientation orientation_;
  80. /// Slider range.
  81. float range_;
  82. /// Slider current value.
  83. float value_;
  84. /// Internal flag of whether the slider is being dragged.
  85. bool dragSlider_;
  86. /// Original mouse cursor position at drag begin.
  87. IntVector2 dragBeginCursor_;
  88. /// Original slider position at drag begin.
  89. IntVector2 dragBeginPosition_;
  90. /// Paging repeat rate.
  91. float repeatRate_;
  92. /// Paging minimum repeat timer.
  93. Timer repeatTimer_;
  94. };
  95. }