guiWindowCtrl.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. Region findHitRegion(const Point2I &);
  92. GuiControlState getRegionCurrentState(GuiWindowCtrl::Region region);
  93. GuiWindowCtrl();
  94. DECLARE_CONOBJECT(GuiWindowCtrl);
  95. static void initPersistFields();
  96. bool onWake();
  97. void onSleep();
  98. bool isMinimized(S32 &index);
  99. virtual void getCursor(GuiCursor *&cursor, bool &showCursor, const GuiEvent &lastGuiEvent);
  100. GuiControl* findHitControl(const Point2I &pt, S32 initialLayer = -1);
  101. void resize(const Point2I &newPosition, const Point2I &newExtent);
  102. void onTouchMove(const GuiEvent &event);
  103. void onTouchDown(const GuiEvent &event);
  104. void onTouchDragged(const GuiEvent &event);
  105. void onTouchUp(const GuiEvent &event);
  106. void onTouchLeave(const GuiEvent &event);
  107. virtual void onFocus();
  108. //only cycle tabs through the current window, so overwrite the method
  109. GuiControl* findNextTabable(GuiControl *curResponder, bool firstCall = true);
  110. GuiControl* findPrevTabable(GuiControl *curResponder, bool firstCall = true);
  111. bool onKeyDown(const GuiEvent &event);
  112. S32 getTabIndex(void) { return mTabIndex; }
  113. void selectWindow(void);
  114. void onRender(Point2I offset, const RectI &updateRect);
  115. RectI renderButtons(const Point2I &offset, const RectI &contentRect);
  116. RectI renderButton(const RectI &contentRect, S32 distanceFromEdge, GuiControlState buttonState, GuiControlProfile *profile, Icon defaultIcon);
  117. void setControlContentProfile(GuiControlProfile* prof);
  118. void setControlCloseButtonProfile(GuiControlProfile* prof);
  119. void setControlMinButtonProfile(GuiControlProfile* prof);
  120. void setControlMaxButtonProfile(GuiControlProfile* prof);
  121. void setControlLeftRightCursor(GuiCursor* cursor);
  122. void setControlUpDownCursor(GuiCursor* cursor);
  123. void setControlNWSECursor(GuiCursor* cursor);
  124. };
  125. /// @}
  126. #endif //_GUI_WINDOW_CTRL_H