guiTabBookCtrl.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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 _GUI_TABBOOKCTRL_H_
  23. #define _GUI_TABBOOKCTRL_H_
  24. #ifndef _GUICONTROL_H_
  25. #include "gui/guiControl.h"
  26. #endif
  27. #ifndef _GUITABPAGECTRL_H_
  28. #include "gui/containers/guiTabPageCtrl.h"
  29. #endif
  30. /// Tab Book Control for creation of tabbed dialogs
  31. ///
  32. /// @see GUI for an overview of the Torque GUI system.
  33. ///
  34. /// @section GuiTabBookCtrl_Intro Introduction
  35. ///
  36. /// GuiTabBookCtrl is a container class that holds children of type GuiTabPageCtrl
  37. ///
  38. /// GuiTabBookCtrl creates an easy to work with system for creating tabbed dialogs
  39. /// allowing for creation of dialogs that store alot of information in a small area
  40. /// by seperating the information into pages which are changeable by clicking their
  41. /// page title on top or bottom of the control
  42. ///
  43. /// tabs may be aligned to be on top or bottom of the book and are changeable while
  44. /// the GUI editor is open for quick switching between pages allowing multipage dialogs
  45. /// to be edited quickly and easily.
  46. ///
  47. /// The control may only contain children of type GuiTabPageCtrl.
  48. /// If a control is added to the Book that is not of type GuiTabPageCtrl, it will be
  49. /// removed and relocated to the currently active page of the control.
  50. /// If there is no active page in the book, the child control will be relocated to the
  51. /// parent of the book.
  52. ///
  53. /// @ref GUI has an overview of the GUI system.
  54. ///
  55. /// @nosubgrouping
  56. class GuiTabBookCtrl : public GuiControl
  57. {
  58. public:
  59. enum TabPosition
  60. {
  61. AlignTop, ///< Align the tabs on the top of the tab book control
  62. AlignBottom,///< Align the tabs on the bottom of the tab book control
  63. AlignLeft, ///< Align the tabs on the left of the tab book control
  64. AlignRight ///< Align the tabs on the right of the tab book control
  65. };
  66. struct TabHeaderInfo
  67. {
  68. GuiTabPageCtrl *Page;
  69. S32 TextWidth;
  70. S32 TabRow;
  71. S32 TabColumn;
  72. RectI TabRect;
  73. };
  74. GuiControlProfile *mTabProfile; //Used to render the tabs
  75. private:
  76. typedef GuiControl Parent; ///< typedef for parent class access
  77. RectI mPageRect; ///< Rectangle of the tab page portion of the control
  78. RectI mTabRect; ///< Rectangle of the tab portion of the control
  79. Vector<TabHeaderInfo> mPages; ///< Vector of pages contained by the control
  80. GuiTabPageCtrl* mActivePage; ///< Pointer to the active (selected) tab page child control
  81. GuiTabPageCtrl* mHoverTab; ///< Pointer to the tab page that currently has the mouse positioned ontop of its tab
  82. S32 mMinTabWidth; ///< Minimum Width a tab will display as.
  83. TabPosition mTabPosition; ///< Current tab position (see alignment)
  84. TabPosition mLastTabPosition; ///< Last known tab position, stored to compare to tabPosition to know when to resize children
  85. S32 mFontHeight; ///< Last known font height
  86. S32 mTabWidth; ///< Current tab width of the first tab
  87. Point2I mTabDownPosition;
  88. bool mDepressed;
  89. enum
  90. {
  91. TabSelected = 0, ///< Index of selected tab texture
  92. TabNormal, ///< Index of normal tab texture
  93. TabHover, ///< Index of hover tab texture
  94. TabSelectedVertical, ///< Index of selected tab texture
  95. TabNormalVertical, ///< Index of normal tab texture
  96. TabHoverVertical, ///< Index of hover tab texture
  97. TabBackground = 19, ///< Index of background texture (tiled)
  98. NumBitmaps ///< Number of bitmaps in this array
  99. };
  100. bool mHasTexture; ///< Indicates whether we have a texture to render the tabs with
  101. RectI *mBitmapBounds;///< Array of rectangles identifying textures for tab book
  102. public:
  103. GuiTabBookCtrl();
  104. DECLARE_CONOBJECT(GuiTabBookCtrl);
  105. static void initPersistFields();
  106. bool mIsFrameSetGenerated;
  107. /// @name Control Events
  108. /// @{
  109. bool onAdd();
  110. void onRemove();
  111. bool onWake();
  112. void onSleep();
  113. void setControlTabProfile(GuiControlProfile* prof);
  114. void onPreRender();
  115. void onRender( Point2I offset, const RectI &updateRect );
  116. /// @}
  117. /// @name Child events
  118. /// @{
  119. void onChildRemoved( GuiControl* child );
  120. void onChildAdded( GuiControl *child );
  121. /// @}
  122. /// @name Rendering methods
  123. /// @{
  124. /// Tab rendering routine, iterates through all tabs rendering one at a time
  125. /// @param offset the render offset to accomodate global coords
  126. void renderTabs( const Point2I &offset );
  127. /// Tab rendering subroutine, renders one tab with specified options
  128. /// @param tabRect the rectangle to render the tab into
  129. /// @param tab pointer to the tab page control for which to render the tab
  130. void renderTab( RectI tabRect, GuiTabPageCtrl* tab );
  131. /// @}
  132. /// @name Page Management
  133. /// @{
  134. /// Create a new tab page child in the book
  135. ///
  136. /// Pages created are not titled and appear with no text on their tab when created.
  137. /// This may change in the future.
  138. void addNewPage();
  139. U32 getSelectedPage();
  140. /// Select a tab page based on an index
  141. /// @param index The index in the list that specifies which page to select
  142. void selectPage( S32 index );
  143. /// Select a tab page by a pointer to that page
  144. /// @param page A pointer to the GuiTabPageCtrl to select. This page must be a child of the tab book.
  145. void selectPage( GuiTabPageCtrl *page );
  146. /// Select a tab page by it's name in the book
  147. /// @param pageName A string represeting the 'Text' of the GuiTabPage to be shown
  148. void selectPage( const char* pageName );
  149. /// Select the Next page in the tab book
  150. void selectNextPage();
  151. /// Select the Previous page in the tab book
  152. void selectPrevPage();
  153. /// @}
  154. /// @name Internal Utility Functions
  155. /// @{
  156. /// Update ourselves by hooking common GuiControl functionality.
  157. void setUpdate();
  158. /// Balance a top/bottom tab row
  159. void balanceRow( S32 row, S32 totalTabWidth );
  160. /// Balance a left/right tab column
  161. void balanceColumn( S32 row, S32 totalTabWidth );
  162. /// Checks to see if a tab option has changed and we need to resize children, resizes if necessary
  163. void solveDirty();
  164. /// Calculate the tab width of a page, given it's caption
  165. S32 calculatePageTabWidth( GuiTabPageCtrl *page );
  166. /// Calculate Page Header Information
  167. void calculatePageTabs();
  168. /// Find the tab that was hit by the current event, if any
  169. /// @param event The GuiEvent that caused this function call
  170. GuiTabPageCtrl *findHitTab( const GuiEvent &event );
  171. /// Find the tab that was hit, based on a point
  172. /// @param hitPoint A Point2I that specifies where to search for a tab hit
  173. GuiTabPageCtrl *findHitTab( Point2I hitPoint );
  174. /// Changes a local point to a point in the inner rect of the tab section.
  175. Point2I getTabLocalCoord(const Point2I &src);
  176. /// @}
  177. /// @name Sizing
  178. /// @{
  179. /// Rezize our control
  180. /// This method is overridden so that we may handle resizing of our child tab
  181. /// pages when we are resized.
  182. /// This ensures we keep our sizing in sync when we are moved or sized.
  183. ///
  184. /// @param newPosition The new position of the control
  185. /// @param newExtent The new extent of the control
  186. void resize(const Point2I &newPosition, const Point2I &newExtent);
  187. /// Called when a child page is resized
  188. /// This method is overridden so that we may handle resizing of our child tab
  189. /// pages when one of them is resized.
  190. /// This ensures we keep our sizing in sync when our children are sized or moved.
  191. ///
  192. /// @param child A pointer to the child control that has been resized
  193. void childResized(GuiControl *child);
  194. /// @}
  195. virtual bool onKeyDown(const GuiEvent &event);
  196. /// @name Mouse Events
  197. /// @{
  198. void onTouchDown(const GuiEvent &event);
  199. void onTouchMove(const GuiEvent &event);
  200. void onTouchLeave(const GuiEvent &event);
  201. void onTouchDragged(const GuiEvent& event);
  202. void onTouchUp(const GuiEvent& event);
  203. bool onMouseDownEditor(const GuiEvent &event, const Point2I& offset);
  204. /// @}
  205. };
  206. #endif //_GUI_TABBOOKCTRL_H_