guiScrollCtrl.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. // the scroll control uses a bitmap array to draw all its
  33. // graphics... these are the bitmaps it needs:
  34. enum BitmapIndices
  35. {
  36. BmpUp,
  37. BmpDown,
  38. BmpVThumbTopCap,
  39. BmpVThumb,
  40. BmpVThumbBottomCap,
  41. BmpVPage,
  42. BmpLeft,
  43. BmpRight,
  44. BmpHThumbLeftCap,
  45. BmpHThumb,
  46. BmpHThumbRightCap,
  47. BmpHPage,
  48. BmpResize,
  49. BmpCount
  50. };
  51. enum BitmapStates
  52. {
  53. BmpDefault = 0,
  54. BmpHilite,
  55. BmpDisabled,
  56. BmpStates
  57. };
  58. RectI *mBitmapBounds; //bmp is [3*n], bmpHL is [3*n + 1], bmpNA is [3*n + 2]
  59. TextureHandle mTextureHandle;
  60. S32 mBorderThickness; // this gets set per class in the constructor
  61. Point2I mChildMargin; // the thickeness of the margin around the child controls
  62. // note - it is implicit in the scroll view that the buttons all have the same
  63. // arrow length and that horizontal and vertical scroll bars have the
  64. // same thickness
  65. S32 mScrollBarThickness; // determined by the width of the vertical page bmp
  66. S32 mScrollBarArrowBtnLength; // determined by the height of the up arrow
  67. S32 mScrollBarDragTolerance; // maximal distance from scrollbar at which a scrollbar drag is still valid
  68. bool mHBarEnabled;
  69. bool mVBarEnabled;
  70. bool mHasHScrollBar;
  71. bool mHasVScrollBar;
  72. Point2I mContentPos; // the position of the content region in the control's coord system
  73. Point2I mContentExt; // the extent of the content region
  74. Point2I mChildPos; // the position of the upper left corner of the child control(s)
  75. Point2I mChildExt;
  76. Point2I mChildRelPos; // the relative position of the upper left content corner in
  77. // the child's coordinate system - 0,0 if scrolled all the way to upper left.
  78. //--------------------------------------
  79. // for mouse dragging the thumb
  80. Point2I mChildRelPosAnchor; // the original childRelPos when scrolling started
  81. S32 mThumbMouseDelta;
  82. S32 mLastUpdated;
  83. S32 mHThumbSize;
  84. S32 mHThumbPos;
  85. S32 mVThumbSize;
  86. S32 mVThumbPos;
  87. S32 mBaseThumbSize;
  88. RectI mUpArrowRect;
  89. RectI mDownArrowRect;
  90. RectI mLeftArrowRect;
  91. RectI mRightArrowRect;
  92. RectI mHTrackRect;
  93. RectI mVTrackRect;
  94. bool mUseScrollEvents; // produce onScroll callbacks
  95. //--------------------------------------
  96. // for determing hit area
  97. public: //called by the ComboPopUp class
  98. enum Region
  99. {
  100. UpArrow,
  101. DownArrow,
  102. LeftArrow,
  103. RightArrow,
  104. UpPage,
  105. DownPage,
  106. LeftPage,
  107. RightPage,
  108. VertThumb,
  109. HorizThumb,
  110. None
  111. };
  112. enum {
  113. ScrollBarAlwaysOn = 0,
  114. ScrollBarAlwaysOff = 1,
  115. ScrollBarDynamic = 2
  116. };
  117. bool stateDepressed;
  118. Region curHitRegion;
  119. bool disabled;
  120. S32 mForceHScrollBar;
  121. S32 mForceVScrollBar;
  122. bool mUseConstantHeightThumb;
  123. bool mWillFirstRespond; // for automatically handling arrow keys
  124. Region findHitRegion(const Point2I &);
  125. protected:
  126. virtual bool calcChildExtents();
  127. virtual void calcScrollRects(void);
  128. void calcThumbs();
  129. void scrollByRegion(Region reg);
  130. //--------------------------------------
  131. //--------------------------------------
  132. public:
  133. GuiScrollCtrl();
  134. DECLARE_CONOBJECT(GuiScrollCtrl);
  135. static void initPersistFields();
  136. void autoScroll(Region reg);
  137. void scrollTo(S32 x, S32 y);
  138. void scrollDelta(S32 x, S32 y);
  139. void scrollRectVisible(RectI rect);
  140. void computeSizes();
  141. // you can change the bitmap array dynamically.
  142. void loadBitmapArray();
  143. void addObject(SimObject *obj);
  144. void resize(const Point2I &newPosition, const Point2I &newExtent);
  145. void childResized(GuiControl *child);
  146. Point2I getChildPos() { return mChildPos; }
  147. Point2I getChildRelPos() { return mChildRelPos; };
  148. Point2I getChildExtent() { return mChildExt; }
  149. Point2I getContentExtent() { return mContentExt; }
  150. Point2I getChildMargin() { return mChildMargin; } // DAW: Added to aid in sizing calculations
  151. bool getUseScrollEvents() { return mUseScrollEvents; }
  152. void setUseScrollEvents(const bool &flag) { mUseScrollEvents = flag; }
  153. S32 getBorderThickness(void) { return mBorderThickness; }
  154. S32 scrollBarThickness() const { return(mScrollBarThickness); }
  155. S32 scrollBarArrowBtnLength() const { return(mScrollBarArrowBtnLength); }
  156. bool hasHScrollBar() const { return(mHasHScrollBar); }
  157. bool hasVScrollBar() const { return(mHasVScrollBar); }
  158. bool enabledHScrollBar() const { return(mHBarEnabled); }
  159. bool enabledVScrollBar() const { return(mVBarEnabled); }
  160. bool isScrolledToBottom() { return mChildPos.y + mChildExt.y <= mContentPos.y + mContentExt.y; }
  161. bool wantsTabListMembership();
  162. bool becomeFirstResponder();
  163. bool loseFirstResponder();
  164. Region getCurHitRegion(void) { return curHitRegion; }
  165. bool onKeyDown(const GuiEvent &event);
  166. void onMouseDown(const GuiEvent &event);
  167. void onMouseRepeat(const GuiEvent &event);
  168. void onMouseUp(const GuiEvent &event);
  169. void onMouseDragged(const GuiEvent &event);
  170. bool onMouseWheelUp(const GuiEvent &event);
  171. bool onMouseWheelDown(const GuiEvent &event);
  172. bool onWake();
  173. void onSleep();
  174. void onPreRender();
  175. void onRender(Point2I offset, const RectI &updateRect);
  176. virtual void drawBorder(const Point2I &offset, bool isFirstResponder);
  177. virtual void drawVScrollBar(const Point2I &offset);
  178. virtual void drawHScrollBar(const Point2I &offset);
  179. virtual void drawScrollCorner(const Point2I &offset);
  180. virtual GuiControl* findHitControl(const Point2I &pt, S32 initialLayer = -1);
  181. };
  182. #endif //_GUI_SCROLL_CTRL_H