WidgetSliderScroll.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #ifndef ROCKETCOREWIDGETSLIDERSCROLL_H
  28. #define ROCKETCOREWIDGETSLIDERSCROLL_H
  29. #include "WidgetSlider.h"
  30. namespace Rocket {
  31. namespace Core {
  32. /**
  33. @author Peter Curry
  34. */
  35. class WidgetSliderScroll : public WidgetSlider
  36. {
  37. public:
  38. WidgetSliderScroll(Element* parent);
  39. virtual ~WidgetSliderScroll();
  40. /// Sets the length of the entire track in scrollable units (usually lines or characters). This affects the
  41. /// length of the bar element and the speed of scrolling using the mouse-wheel or arrows.
  42. /// @param[in] track_length The length of the track.
  43. /// @param[in] force_resize True to resize the bar immediately, false to wait until the next format.
  44. void SetTrackLength(float track_length, bool force_resize = true);
  45. /// Sets the length the bar represents in scrollable units (usually lines or characters), relative to the track
  46. /// length. For example, for a scroll bar, this would represent how big each visible 'page' is compared to the
  47. /// whole document (which would be set as the track length).
  48. /// @param[in] bar_length The length of the slider's bar.
  49. /// @param[in] force_resize True to resize the bar immediately, false to wait until the next format.
  50. void SetBarLength(float bar_length, bool force_resize = true);
  51. /// Sets the line height of the parent element; this is used for scrolling speeds.
  52. /// @param[in] line_height The line height of the parent element.
  53. void SetLineHeight(float line_height);
  54. /// Lays out and resizes the internal elements.
  55. /// @param[in] containing_block The padded box containing the slider. This is used to resolve relative properties.
  56. /// @param[in] length The total length, in pixels, of the slider widget.
  57. void FormatElements(const Vector2f& containing_block, float slider_length);
  58. protected:
  59. /// Called when the slider's bar position is set or dragged.
  60. /// @param bar_position[in] The new position of the bar (0 representing the start of the track, 1 representing the end).
  61. /// @return The new position of the bar.
  62. virtual float OnBarChange(float bar_position);
  63. /// Called when the slider is incremented by one 'line', either by the down / right key or a mouse-click on the
  64. /// increment arrow.
  65. /// @return The new position of the bar.
  66. virtual float OnLineIncrement();
  67. /// Called when the slider is decremented by one 'line', either by the up / left key or a mouse-click on the
  68. /// decrement arrow.
  69. /// @return The new position of the bar.
  70. virtual float OnLineDecrement();
  71. /// Called when the slider is incremented by one 'page', either by the page-up key or a mouse-click on the
  72. /// track below / right of the bar.
  73. /// @return The new position of the bar.
  74. virtual float OnPageIncrement(float click_position);
  75. /// Called when the slider is incremented by one 'page', either by the page-down key or a mouse-click on the
  76. /// track above / left of the bar.
  77. /// @return The new position of the bar.
  78. virtual float OnPageDecrement(float click_position);
  79. private:
  80. // Returns the bar position after scrolling for a number of pixels.
  81. float Scroll(float distance);
  82. float track_length;
  83. float bar_length;
  84. float line_height;
  85. };
  86. }
  87. }
  88. #endif