guiScrollCtrl.h 6.5 KB

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