ElementScroll.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 ROCKETCOREELEMENTSCROLL_H
  28. #define ROCKETCOREELEMENTSCROLL_H
  29. #include <Rocket/Core/Header.h>
  30. #include <Rocket/Core/EventListener.h>
  31. namespace Rocket {
  32. namespace Core {
  33. class Element;
  34. class WidgetSliderScroll;
  35. /**
  36. Manages an element's scrollbars and scrolling state.
  37. @author Peter Curry
  38. */
  39. class ROCKETCORE_API ElementScroll : public EventListener
  40. {
  41. public:
  42. enum Orientation
  43. {
  44. VERTICAL = 0,
  45. HORIZONTAL = 1
  46. };
  47. ElementScroll(Element* element);
  48. virtual ~ElementScroll();
  49. /// Updates the increment / decrement arrows.
  50. void Update();
  51. /// Enables and sizes one of the scrollbars.
  52. /// @param[in] orientation Which scrollbar (vertical or horizontal) to enable.
  53. /// @param[in] element_width The current computed width of the element, used only to resolve percentage properties.
  54. void EnableScrollbar(Orientation orientation, float element_width);
  55. /// Disables and hides one of the scrollbars.
  56. /// @param[in] orientation Which scrollbar (vertical or horizontal) to disable.
  57. void DisableScrollbar(Orientation orientation);
  58. /// Updates the position of the scrollbar.
  59. /// @param[in] orientation Which scrollbar (vertical or horizontal) to update).
  60. void UpdateScrollbar(Orientation orientation);
  61. /// Returns one of the scrollbar elements.
  62. /// @param[in] orientation Which scrollbar to return.
  63. /// @return The requested scrollbar, or NULL if it does not exist.
  64. Element* GetScrollbar(Orientation orientation);
  65. /// Returns the size, in pixels, of one of the scrollbars; for a vertical scrollbar, this is width, for a horizontal scrollbar, this is height.
  66. /// @param[in] orientation Which scrollbar (vertical or horizontal) to query.
  67. /// @return The size of the scrollbar, or 0 if the scrollbar is disabled.
  68. float GetScrollbarSize(Orientation orientation);
  69. /// Formats the enabled scrollbars based on the current size of the host element.
  70. void FormatScrollbars();
  71. protected:
  72. /// Handles the 'onchange' events for the scrollbars.
  73. void ProcessEvent(Event& event);
  74. private:
  75. struct Scrollbar
  76. {
  77. Scrollbar();
  78. ~Scrollbar();
  79. Element* element;
  80. WidgetSliderScroll* widget;
  81. bool enabled;
  82. float size;
  83. };
  84. // Creates one of the scroll component's scrollbar.
  85. bool CreateScrollbar(Orientation orientation);
  86. // Creates the scrollbar corner.
  87. bool CreateCorner();
  88. Element* element;
  89. Scrollbar scrollbars[2];
  90. Element* corner;
  91. };
  92. }
  93. }
  94. #endif