2
0

guiWindowCtrl.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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 _GUIWINDOWCTRL_H_
  23. #define _GUIWINDOWCTRL_H_
  24. #ifndef _GUICONTAINER_H_
  25. #include "gui/containers/guiContainer.h"
  26. #endif
  27. /// @addtogroup gui_container_group Containers
  28. ///
  29. /// @ingroup gui_group Gui System
  30. /// @{
  31. class GuiWindowCtrl : public GuiContainer
  32. {
  33. public:
  34. typedef GuiContainer Parent;
  35. protected:
  36. enum
  37. {
  38. /// Pixel distance across which snapping takes effect.
  39. SnapDistance = 12
  40. };
  41. /// Base indices for the button bitmap rects. Each button
  42. /// bitmap is defined in each of the BitmapStates.
  43. enum BitmapIndices
  44. {
  45. BmpClose,
  46. BmpMaximize,
  47. BmpNormal,
  48. BmpMinimize,
  49. BmpCount
  50. };
  51. /// Button bitmap states.
  52. enum BitmapStates
  53. {
  54. BmpDefault = 0,
  55. BmpHilite,
  56. BmpDown,
  57. BmpStates
  58. };
  59. /// Indices for non-button bitmap rects.
  60. enum
  61. {
  62. BorderTopLeftKey = 12,
  63. BorderTopRightKey,
  64. BorderTopKey,
  65. BorderTopLeftNoKey,
  66. BorderTopRightNoKey,
  67. BorderTopNoKey,
  68. BorderLeft,
  69. BorderRight,
  70. BorderBottomLeft,
  71. BorderBottom,
  72. BorderBottomRight,
  73. NumBitmaps
  74. };
  75. /// Window Edge Bit Masks
  76. ///
  77. /// Edges can be combined to create a mask of multiple edges.
  78. /// This is used for hit detection throughout this class.
  79. enum Edges
  80. {
  81. edgeNone = 0, ///< No Edge
  82. edgeTop = BIT(1), ///< Top Edge
  83. edgeLeft = BIT(2), ///< Left Edge
  84. edgeRight = BIT(3), ///< Right Edge
  85. edgeBottom = BIT(4) ///< Bottom Edge
  86. };
  87. /// @name Flags
  88. /// @{
  89. /// Allow resizing width of window.
  90. bool mResizeWidth;
  91. /// Allow resizing height of window.
  92. bool mResizeHeight;
  93. /// Allow moving window.
  94. bool mCanMove;
  95. /// Display close button.
  96. bool mCanClose;
  97. /// Display minimize button.
  98. bool mCanMinimize;
  99. /// Display maximize button.
  100. bool mCanMaximize;
  101. ///
  102. bool mCanCollapse;
  103. bool mCanDock; ///< Show a docking button on the title bar?
  104. bool mEdgeSnap; ///< Should this window snap to other windows edges?
  105. /// @}
  106. bool mCloseButtonPressed;
  107. bool mMinimizeButtonPressed;
  108. bool mMaximizeButtonPressed;
  109. bool mRepositionWindow;
  110. bool mResizeWindow;
  111. bool mSnapSignal;
  112. StringTableEntry mCloseCommand;
  113. /// Window title string.
  114. String mText;
  115. S32 mResizeEdge; ///< Resizing Edges Mask (See Edges Enumeration)
  116. S32 mTitleHeight;
  117. F32 mResizeMargin;
  118. bool mMouseMovingWin;
  119. bool mMouseResizeWidth;
  120. bool mMouseResizeHeight;
  121. bool mMinimized;
  122. bool mMaximized;
  123. Point2I mMousePosition;
  124. Point2I mMouseDownPosition;
  125. RectI mOrigBounds;
  126. RectI mStandardBounds;
  127. RectI mCloseButton;
  128. RectI mMinimizeButton;
  129. RectI mMaximizeButton;
  130. S32 mMinimizeIndex;
  131. S32 mTabIndex;
  132. void positionButtons(void);
  133. RectI *mBitmapBounds; //bmp is [3*n], bmpHL is [3*n + 1], bmpNA is [3*n + 2]
  134. GFXTexHandle mTextureObject;
  135. /// @name Collapsing
  136. /// @{
  137. typedef Vector< GuiWindowCtrl *> CollapseGroupNumVec;
  138. S32 mCollapseGroup;
  139. S32 mCollapseGroupNum;
  140. S32 mPreCollapsedYExtent;
  141. S32 mPreCollapsedYMinExtent;
  142. bool mIsCollapsed;
  143. bool mIsMouseResizing;
  144. S32 getCollapseGroupNum() { return mCollapseGroupNum; }
  145. void moveFromCollapseGroup();
  146. void moveWithCollapseGroup(Point2I windowPosition);
  147. bool resizeCollapseGroup(bool resizeX, bool resizeY, Point2I resizePos, Point2I resizeWidth);
  148. void refreshCollapseGroups();
  149. void handleCollapseGroup();
  150. /// @}
  151. /// @name Callbacks
  152. /// @{
  153. DECLARE_CALLBACK( void, onClose, () );
  154. DECLARE_CALLBACK( void, onMinimize, () );
  155. DECLARE_CALLBACK( void, onMaximize, () );
  156. DECLARE_CALLBACK( void, onCollapse, () );
  157. DECLARE_CALLBACK( void, onRestore, () );
  158. DECLARE_CALLBACK(void, onResize, (S32 posX, S32 posY, S32 width, S32 height));
  159. /// @}
  160. public:
  161. GuiWindowCtrl();
  162. bool isMinimized(S32 &index);
  163. virtual void getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent);
  164. void setFont(S32 fntTag);
  165. void setCloseCommand(const char *newCmd);
  166. GuiControl* findHitControl (const Point2I &pt, S32 initialLayer = -1 );
  167. S32 findHitEdges( const Point2I &globalPoint );
  168. void getSnappableWindows( Vector<GuiWindowCtrl*> &windowOutVector, bool canCollapse = false );
  169. bool resize( const Point2I &newPosition, const Point2I &newExtent );
  170. //only cycle tabs through the current window, so overwrite the method
  171. GuiControl* findNextTabable(GuiControl *curResponder, bool firstCall = true);
  172. GuiControl* findPrevTabable(GuiControl *curResponder, bool firstCall = true);
  173. S32 getTabIndex(void) { return mTabIndex; }
  174. void selectWindow(void);
  175. ////
  176. const RectI getClientRect();
  177. /// Mutators for window properties from code.
  178. /// Using setDataField is a bit overkill.
  179. void setMobility( bool canMove, bool canClose, bool canMinimize, bool canMaximize, bool canDock, bool edgeSnap )
  180. {
  181. mCanMove = canMove;
  182. mCanClose = canClose;
  183. mCanMinimize = canMinimize;
  184. mCanMaximize = canMaximize;
  185. mCanDock = canDock;
  186. mEdgeSnap = edgeSnap;
  187. }
  188. /// Mutators for window properties from code.
  189. /// Using setDataField is a bit overkill.
  190. void setCanResize( bool canResizeWidth, bool canResizeHeight )
  191. {
  192. mResizeWidth = canResizeWidth;
  193. mResizeHeight = canResizeHeight;
  194. }
  195. /// Set the text on the window title bar.
  196. void setText( const String& text )
  197. {
  198. mText = text;
  199. }
  200. /// @name Collapsing
  201. /// @{
  202. void setCollapseGroup( bool state );
  203. void toggleCollapseGroup();
  204. void moveToCollapseGroup( GuiWindowCtrl* hitWindow, bool orientation );
  205. /// @}
  206. // GuiContainer.
  207. virtual bool onWake();
  208. virtual void onSleep();
  209. virtual void parentResized(const RectI &oldParentRect, const RectI &newParentRect);
  210. virtual void onMouseDown(const GuiEvent &event);
  211. virtual void onMouseDragged(const GuiEvent &event);
  212. virtual void onMouseUp(const GuiEvent &event);
  213. virtual void onMouseMove(const GuiEvent &event);
  214. virtual bool onKeyDown(const GuiEvent &event);
  215. virtual void onRender(Point2I offset, const RectI &updateRect);
  216. DECLARE_CONOBJECT( GuiWindowCtrl );
  217. DECLARE_DESCRIPTION( "A control that shows an independent window inside the canvas." );
  218. static void initPersistFields();
  219. };
  220. /// @}
  221. #endif //_GUI_WINDOW_CTRL_H