ScrollBar.h 4.5 KB

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