PolyUIScrollContainer.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. Copyright (C) 2012 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "PolyGlobals.h"
  21. #include "PolyUIVScrollBar.h"
  22. #include "PolyUIHScrollBar.h"
  23. #include "PolyUIElement.h"
  24. namespace Polycode {
  25. /**
  26. * A container for UI elements that adds scroll bars if necessary.
  27. *
  28. * Internally, this class simply moves the scrolled child, and uses scissorBox
  29. * to cut off the parts going over the edges.
  30. */
  31. class _PolyExport UIScrollContainer : public UIElement {
  32. public:
  33. /**
  34. * Create a scroll container.
  35. * @param scrolledEntity The ScreenEntity that should be scrolled using this element.
  36. * @param hScroll Whether the child should be scrolled horizontally.
  37. * @param vScroll Whether the child should be scrolled vertically.
  38. * @param width The width of the scroll container.
  39. * @param height The height of the scroll container.
  40. */
  41. UIScrollContainer(ScreenEntity *scrolledEntity, bool hScroll, bool vScroll, Number width, Number height);
  42. ~UIScrollContainer();
  43. /**
  44. * Update what size the content child is expected to have.
  45. *
  46. * This doesn't do anything to the child, it just updates scroll bar
  47. * positions etc.
  48. *
  49. * @param newContentWidth Width of the content.
  50. * @param newContentHeight Height of the content.
  51. */
  52. void setContentSize(Number newContentWidth, Number newContentHeight);
  53. void Resize(Number width, Number height);
  54. /**
  55. * Set how far the content child should be scrolled.
  56. *
  57. * @param xScroll New horizontal scroll position.
  58. * @param yScroll New vertical scroll position.
  59. */
  60. void setScrollValue(Number xScroll, Number yScroll);
  61. /**
  62. * Set how far the content child should be scrolled.
  63. *
  64. * @param amount New vertical scroll position.
  65. */
  66. void scrollVertical(Number amount);
  67. /**
  68. * Set how far the content child should be scrolled.
  69. *
  70. * @param amount New horizontal scroll position.
  71. */
  72. void scrollHorizontal(Number amount);
  73. void Update();
  74. /** Get the assumed size of the content.
  75. *
  76. * Note that this doesn't actually look at the contained
  77. * element, but rather just returns what was earlier set
  78. * by setContentSize()
  79. *
  80. * @return The currently assumed size of the content.
  81. */
  82. Vector2 getContentSize();
  83. void onMouseWheelDown(Number x, Number y);
  84. void onMouseWheelUp(Number x, Number y);
  85. void handleEvent(Event *event);
  86. /**
  87. * Get the width of the vertical scroll bar.
  88. */
  89. Number getVScrollWidth();
  90. private:
  91. Number defaultScrollSize;
  92. Number contentWidth;
  93. Number contentHeight;
  94. ScreenEntity *scrollChild;
  95. bool hasHScroll;
  96. bool hasVScroll;
  97. UIVScrollBar *vScrollBar;
  98. UIHScrollBar *hScrollBar;
  99. };
  100. }