ScrollBar.h 4.5 KB

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