guiScrollCtrl.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  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
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell 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
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GUISCROLLCTRL_H_
  23. #define _GUISCROLLCTRL_H_
  24. #ifndef _GUICONTROL_H_
  25. #include "gui/guiControl.h"
  26. #endif
  27. class GuiScrollCtrl : public GuiControl
  28. {
  29. private:
  30. typedef GuiControl Parent;
  31. protected:
  32. // note - it is implicit in the scroll view that the buttons all have the same
  33. // arrow length and that horizontal and vertical scroll bars have the
  34. // same thickness
  35. S32 mScrollBarDragTolerance; // maximal distance from scrollbar at which a scrollbar drag is still valid
  36. bool mHBarEnabled; //True if the children extent is greater than the content area.
  37. bool mVBarEnabled;
  38. bool mHasHScrollBar; //The final word on if the bar should be shown. Adjusted internally.
  39. bool mHasVScrollBar;
  40. Point2I mChildExt; //The furthest reaches of the child controls.
  41. Point2I mContentExt; //The content area length and width in pixels.
  42. RectI mChildArea; //The scrren space to which children were most recently rendered.
  43. //--------------------------------------
  44. // for mouse dragging the thumb
  45. Point2I mScrollOffsetAnchor; // the original scrollOffset when scrolling started
  46. S32 mThumbMouseDelta;
  47. S32 mLastUpdated;
  48. S32 mHThumbSize;
  49. S32 mHThumbPos;
  50. S32 mVThumbSize;
  51. S32 mVThumbPos;
  52. S32 mBaseThumbSize;
  53. RectI mUpArrowRect;
  54. RectI mDownArrowRect;
  55. RectI mLeftArrowRect;
  56. RectI mRightArrowRect;
  57. RectI mHTrackRect;
  58. RectI mVTrackRect;
  59. public:
  60. enum Region
  61. {
  62. UpArrow,
  63. DownArrow,
  64. LeftArrow,
  65. RightArrow,
  66. UpPage,
  67. DownPage,
  68. LeftPage,
  69. RightPage,
  70. VertThumb,
  71. HorizThumb,
  72. None
  73. };
  74. enum {
  75. ScrollBarAlwaysOn = 0,
  76. ScrollBarAlwaysOff = 1,
  77. ScrollBarDynamic = 2
  78. };
  79. bool mDepressed;
  80. Region curHitRegion;
  81. bool disabled;
  82. S32 mForceHScrollBar;
  83. S32 mForceVScrollBar;
  84. bool mUseConstantHeightThumb;
  85. Point2I mScrollOffset; //The offset of the children
  86. S32 mScrollBarThickness; // determined by the width of the vertical page bmp
  87. bool mShowArrowButtons; //True if the arrow buttons should appear
  88. Region findHitRegion(const Point2I &);
  89. GuiControlProfile *mThumbProfile; //Used to render the thumb and arrow buttons
  90. GuiControlProfile *mTrackProfile; //Used to render the tracks
  91. GuiControlProfile *mArrowProfile; //Used to render the arrow buttons
  92. protected:
  93. virtual void calcContentExtents();
  94. virtual bool calcChildExtents();
  95. virtual void calcScrollRects(RectI &fillRect);
  96. virtual void calcThumbs();
  97. virtual void calcScrollOffset();
  98. //--------------------------------------
  99. //--------------------------------------
  100. public:
  101. GuiScrollCtrl();
  102. DECLARE_CONOBJECT(GuiScrollCtrl);
  103. static void initPersistFields();
  104. virtual void scrollTo(S32 x, S32 y);
  105. virtual void scrollDelta(S32 x, S32 y);
  106. virtual void scrollRectVisible(RectI rect);
  107. virtual void scrollByRegion(Region reg);
  108. virtual void computeSizes();
  109. virtual void addObject(SimObject *obj);
  110. virtual void resize(const Point2I &newPosition, const Point2I &newExtent);
  111. virtual void childResized(GuiControl *child);
  112. virtual S32 scrollBarThickness() const { return(mScrollBarThickness); }
  113. virtual bool hasHScrollBar() const { return(mHasHScrollBar); }
  114. virtual bool hasVScrollBar() const { return(mHasVScrollBar); }
  115. virtual bool enabledHScrollBar() const { return(mHBarEnabled); }
  116. virtual bool enabledVScrollBar() const { return(mVBarEnabled); }
  117. virtual bool isScrolledToBottom() { return mChildExt.y <= mScrollOffset.y + mContentExt.y; }
  118. virtual Region getCurHitRegion(void) { return curHitRegion; }
  119. virtual void onTouchMove(const GuiEvent &event);
  120. virtual bool onKeyDown(const GuiEvent &event);
  121. virtual void onTouchDown(const GuiEvent &event);
  122. virtual void onTouchUp(const GuiEvent &event);
  123. virtual void onTouchDragged(const GuiEvent &event);
  124. virtual void onTouchLeave(const GuiEvent &event);
  125. virtual bool onMouseWheelUp(const GuiEvent &event);
  126. virtual bool onMouseWheelDown(const GuiEvent &event);
  127. virtual bool onWake();
  128. virtual void onSleep();
  129. virtual void setControlThumbProfile(GuiControlProfile* prof);
  130. virtual void setControlTrackProfile(GuiControlProfile* prof);
  131. virtual void setControlArrowProfile(GuiControlProfile* prof);
  132. virtual void onPreRender();
  133. virtual void onRender(Point2I offset, const RectI &updateRect);
  134. virtual RectI applyScrollBarSpacing(Point2I offset, Point2I extent);
  135. virtual GuiControlState getRegionCurrentState(GuiScrollCtrl::Region region);
  136. virtual void renderBorderedRectWithArrow(RectI& bounds, GuiControlProfile* profile, GuiControlState state, GuiDirection direction);
  137. virtual void renderVScrollBar(const Point2I& offset);
  138. virtual void renderHScrollBar(const Point2I& offset);
  139. virtual GuiControl* findHitControl(const Point2I &pt, S32 initialLayer = -1);
  140. virtual void renderChildControls(Point2I offset, RectI content, const RectI& updateRect);
  141. };
  142. #endif //_GUI_SCROLL_CTRL_H