ScrollBar.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2012 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include "UIElement.h"
  25. class Button;
  26. class Slider;
  27. /// Scroll bar %UI element with forward and back buttons.
  28. class ScrollBar : public UIElement
  29. {
  30. OBJECT(ScrollBar);
  31. using UIElement::SetStyle;
  32. public:
  33. /// Construct.
  34. ScrollBar(Context* context);
  35. /// Destruct.
  36. virtual ~ScrollBar();
  37. /// Register object factory.
  38. static void RegisterObject(Context* context);
  39. /// %Set UI element style from XML data.
  40. virtual void SetStyle(const XMLElement& element);
  41. /// React to resize.
  42. virtual void OnResize();
  43. /// %Set orientation type.
  44. void SetOrientation(Orientation orientation);
  45. /// %Set slider range maximum value (minimum value is always 0.)
  46. void SetRange(float range);
  47. /// %Set slider current value.
  48. void SetValue(float value);
  49. /// Change slider current value by a delta.
  50. void ChangeValue(float delta);
  51. /// %Set button scroll step.
  52. void SetScrollStep(float step);
  53. /// %Set button step factor, can be used to adjust the step for constant pixel size.
  54. void SetStepFactor(float factor);
  55. /// Scroll back one step.
  56. void StepBack();
  57. /// Scroll forward one step.
  58. void StepForward();
  59. /// Return scrollbar orientation.
  60. Orientation GetOrientation() const;
  61. /// Return slider range.
  62. float GetRange() const;
  63. /// Return slider current value.
  64. float GetValue() const;
  65. /// Return button scroll step.
  66. float GetScrollStep() const { return scrollStep_; }
  67. /// Return button step factor.
  68. float GetStepFactor() const { return stepFactor_; }
  69. /// Return scroll step multiplied by factor.
  70. float GetEffectiveScrollStep() const;
  71. /// Return back button element.
  72. Button* GetBackButton() const { return backButton_; }
  73. /// Return forward button element.
  74. Button* GetForwardButton() const { return forwardButton_; }
  75. /// Return slider element.
  76. Slider* GetSlider() const { return slider_; }
  77. protected:
  78. /// Back button.
  79. SharedPtr<Button> backButton_;
  80. /// Forward button.
  81. SharedPtr<Button> forwardButton_;
  82. /// Slider.
  83. SharedPtr<Slider> slider_;
  84. /// Scroll step.
  85. float scrollStep_;
  86. /// Step factor.
  87. float stepFactor_;
  88. /// Left button image rect.
  89. IntRect leftRect_;
  90. /// Right button image rect.
  91. IntRect rightRect_;
  92. /// Up button image rect.
  93. IntRect upRect_;
  94. /// Down button image rect.
  95. IntRect downRect_;
  96. private:
  97. /// Handle back button pressed.
  98. void HandleBackButtonPressed(StringHash eventType, VariantMap& eventData);
  99. /// Handle forward button pressed.
  100. void HandleForwardButtonPressed(StringHash eventType, VariantMap& eventData);
  101. /// Handle slider movement.
  102. void HandleSliderChanged(StringHash eventType, VariantMap& eventData);
  103. };