guiScrollCtrl.h 6.8 KB

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