guiWindowCtrl.h 5.4 KB

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