ScrollBar.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. class Button;
  27. class Slider;
  28. /// Scroll bar %UI element with forward and back buttons.
  29. class URHO3D_API ScrollBar : public BorderImage
  30. {
  31. URHO3D_OBJECT(ScrollBar, BorderImage);
  32. public:
  33. /// Construct.
  34. explicit ScrollBar(Context* context);
  35. /// Destruct.
  36. ~ScrollBar() override;
  37. /// Register object factory.
  38. static void RegisterObject(Context* context);
  39. /// Apply attribute changes that can not be applied immediately.
  40. void ApplyAttributes() override;
  41. /// React to resize.
  42. void OnResize(const IntVector2& newSize, const IntVector2& delta) override;
  43. /// React to editable status change.
  44. void OnSetEditable() override;
  45. /// Set orientation type.
  46. /// @property
  47. void SetOrientation(Orientation orientation);
  48. /// Set slider range maximum value (minimum value is always 0).
  49. /// @property
  50. void SetRange(float range);
  51. /// Set slider current value.
  52. /// @property
  53. void SetValue(float value);
  54. /// Change slider current value by a delta.
  55. void ChangeValue(float delta);
  56. /// Set button scroll step.
  57. /// @property
  58. void SetScrollStep(float step);
  59. /// Set button step factor, can be used to adjust the step for constant pixel size.
  60. /// @property
  61. void SetStepFactor(float factor);
  62. /// Scroll back one step.
  63. void StepBack();
  64. /// Scroll forward one step.
  65. void StepForward();
  66. /// Return scrollbar orientation.
  67. /// @property
  68. Orientation GetOrientation() const;
  69. /// Return slider range.
  70. /// @property
  71. float GetRange() const;
  72. /// Return slider current value.
  73. /// @property
  74. float GetValue() const;
  75. /// Return button scroll step.
  76. /// @property
  77. float GetScrollStep() const { return scrollStep_; }
  78. /// Return button step factor.
  79. /// @property
  80. float GetStepFactor() const { return stepFactor_; }
  81. /// Return scroll step multiplied by factor.
  82. /// @property
  83. float GetEffectiveScrollStep() const;
  84. /// Return back button element.
  85. /// @property
  86. Button* GetBackButton() const { return backButton_; }
  87. /// Return forward button element.
  88. /// @property
  89. Button* GetForwardButton() const { return forwardButton_; }
  90. /// Return slider element.
  91. /// @property
  92. Slider* GetSlider() const { return slider_; }
  93. protected:
  94. /// Filter implicit attributes in serialization process.
  95. bool FilterImplicitAttributes(XMLElement& dest) const override;
  96. /// Filter implicit attributes in serialization process for internal button.
  97. bool FilterButtonImplicitAttributes(XMLElement& dest, const String& name) const;
  98. /// Back button.
  99. SharedPtr<Button> backButton_;
  100. /// Forward button.
  101. SharedPtr<Button> forwardButton_;
  102. /// Slider.
  103. SharedPtr<Slider> slider_;
  104. /// Scroll step.
  105. float scrollStep_;
  106. /// Step factor.
  107. float stepFactor_;
  108. /// Left button image rect.
  109. IntRect leftRect_;
  110. /// Right button image rect.
  111. IntRect rightRect_;
  112. /// Up button image rect.
  113. IntRect upRect_;
  114. /// Down button image rect.
  115. IntRect downRect_;
  116. private:
  117. /// Handle back button pressed.
  118. void HandleBackButtonPressed(StringHash eventType, VariantMap& eventData);
  119. /// Handle forward button pressed.
  120. void HandleForwardButtonPressed(StringHash eventType, VariantMap& eventData);
  121. /// Handle slider movement.
  122. void HandleSliderChanged(StringHash eventType, VariantMap& eventData);
  123. /// Handle slider touch and click on "paging" area.
  124. void HandleSliderPaged(StringHash eventType, VariantMap& eventData);
  125. };
  126. }