guiWindowCtrl.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 _GUIWINDOWCTRL_H_
  23. #define _GUIWINDOWCTRL_H_
  24. /// @addtogroup gui_container_group Containers
  25. ///
  26. /// @ingroup gui_group Gui System
  27. /// @{
  28. class GuiWindowCtrl : public GuiControl
  29. {
  30. private:
  31. typedef GuiControl Parent;
  32. //Allow these behaviors.
  33. bool mResizeWidth;
  34. bool mResizeHeight;
  35. bool mCanMove;
  36. bool mCanClose;
  37. bool mCanMinimize;
  38. bool mCanMaximize;
  39. //Did the touch down happen inside these buttons?
  40. bool mPressClose;
  41. bool mPressMinimize;
  42. bool mPressMaximize;
  43. //Window settings.
  44. S32 mTitleHeight; //The height of the title bar before appling margin/border/padding.
  45. S32 mResizeRightWidth; //The size of the area inset from the right edge that can be clicked to resize horizontally.
  46. S32 mResizeBottomHeight; //The size of the area inset from the bottom edge that can be clicked to resize vertically.
  47. //Current State
  48. bool mMouseMovingWin;
  49. bool mMouseResizeWidth;
  50. bool mMouseResizeHeight;
  51. bool mMinimized;
  52. bool mMaximized;
  53. Point2I mMouseDownPosition;
  54. RectI mOrigBounds;
  55. RectI mStandardBounds;
  56. //The location of the window parts.
  57. RectI mCloseButton;
  58. RectI mMinimizeButton;
  59. RectI mMaximizeButton;
  60. RectI mTitleBar;
  61. S32 mMinimizeIndex;
  62. S32 mTabIndex;
  63. //Additional profiles used by the window.
  64. GuiControlProfile *mContentProfile; //Used to render the content section of the window.
  65. GuiControlProfile *mCloseButtonProfile; //Used to render the close button.
  66. GuiControlProfile *mMinButtonProfile; //Used to render the close button.
  67. GuiControlProfile *mMaxButtonProfile; //Used to render the close button.
  68. // Sizing Cursors
  69. GuiCursor* mLeftRightCursor;
  70. GuiCursor* mUpDownCursor;
  71. GuiCursor* mNWSECursor;
  72. void ResizeComplete();
  73. void MoveComplete();
  74. public:
  75. enum Region
  76. {
  77. TitleBar,
  78. CloseButton,
  79. MinButton,
  80. MaxButton,
  81. None
  82. };
  83. enum Icon
  84. {
  85. Close,
  86. Min,
  87. Max
  88. };
  89. bool mDepressed;
  90. Region curHitRegion;
  91. bool mPageDocked; //True when docked in a GuiTabPageCtrl.
  92. void dockToPage();
  93. void undockFromPage();
  94. S32 getTitleHeight() { return mTitleHeight; }
  95. Region findHitRegion(const Point2I &);
  96. GuiControlState getRegionCurrentState(GuiWindowCtrl::Region region);
  97. GuiWindowCtrl();
  98. DECLARE_CONOBJECT(GuiWindowCtrl);
  99. static void initPersistFields();
  100. bool onWake();
  101. void onSleep();
  102. bool isMinimized(S32 &index);
  103. virtual void getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent);
  104. GuiControl* findHitControl(const Point2I &pt, S32 initialLayer = -1);
  105. void resize(const Point2I &newPosition, const Point2I &newExtent);
  106. void restore();
  107. void onTouchMove(const GuiEvent &event);
  108. void onTouchDown(const GuiEvent &event);
  109. void onTouchDragged(const GuiEvent &event);
  110. void onTouchUp(const GuiEvent &event);
  111. void onTouchLeave(const GuiEvent &event);
  112. virtual void onFocus(bool foundFirstResponder);
  113. //only cycle tabs through the current window, so overwrite the method
  114. GuiControl* findNextTabable(GuiControl *curResponder, bool firstCall = true);
  115. GuiControl* findPrevTabable(GuiControl *curResponder, bool firstCall = true);
  116. bool onKeyDown(const GuiEvent &event);
  117. S32 getTabIndex(void) { return mTabIndex; }
  118. void selectWindow(void);
  119. void onRender(Point2I offset, const RectI &updateRect);
  120. RectI renderButtons(const Point2I &offset, const RectI &contentRect);
  121. RectI renderButton(const RectI &contentRect, S32 distanceFromEdge, GuiControlState buttonState, GuiControlProfile *profile, Icon defaultIcon);
  122. RectI getInnerRect(Point2I& offset, Point2I& extent, GuiControlState currentState, GuiControlProfile* profile);
  123. void setControlContentProfile(GuiControlProfile* prof);
  124. void setControlCloseButtonProfile(GuiControlProfile* prof);
  125. void setControlMinButtonProfile(GuiControlProfile* prof);
  126. void setControlMaxButtonProfile(GuiControlProfile* prof);
  127. void setControlLeftRightCursor(GuiCursor* cursor);
  128. void setControlUpDownCursor(GuiCursor* cursor);
  129. void setControlNWSECursor(GuiCursor* cursor);
  130. };
  131. /// @}
  132. #endif //_GUI_WINDOW_CTRL_H