guiMenuBarCtrl.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 _GUIMENUBARCTRL_H_
  23. #define _GUIMENUBARCTRL_H_
  24. #ifndef _SIMBASE_H_
  25. #include "sim/simBase.h"
  26. #endif
  27. #ifndef _GUITYPES_H_
  28. #include "gui/guiTypes.h"
  29. #endif
  30. #ifndef _GUICONTROL_H_
  31. #include "gui/guiControl.h"
  32. #endif
  33. #ifndef _GUISCROLLCTRL_H_
  34. #include "gui/containers/guiScrollCtrl.h"
  35. #endif
  36. class GuiMenuItemCtrl;
  37. class GuiMenuBGCtrl;
  38. class GuiMenuListCtrl;
  39. class GuiMenuBarCtrl : public GuiControl
  40. {
  41. private:
  42. typedef GuiControl Parent;
  43. public:
  44. //creation methods
  45. DECLARE_CONOBJECT(GuiMenuBarCtrl);
  46. GuiMenuBarCtrl();
  47. static void initPersistFields();
  48. virtual void childResized(GuiControl *child);
  49. virtual void resize(const Point2I &newPosition, const Point2I &newExtent);
  50. virtual void inspectPostApply();
  51. virtual void onChildAdded(GuiControl *child);
  52. virtual void onChildRemoved(SimObject *child);
  53. virtual void calculateMenus();
  54. virtual GuiControl* findHitControl(const Point2I &pt, S32 initialLayer);
  55. virtual GuiMenuItemCtrl* findHitMenu(const Point2I &pt);
  56. virtual void onRender(Point2I offset, const RectI &updateRect);
  57. virtual void processHover(const GuiEvent &event);
  58. virtual void setHoverTarget(GuiMenuItemCtrl *ctrl);
  59. virtual void onTouchMove(const GuiEvent &event);
  60. virtual void onTouchEnter(const GuiEvent &event);
  61. virtual void onTouchLeave(const GuiEvent &event);
  62. virtual void onTouchDown(const GuiEvent &event);
  63. void openMenu();
  64. void closeMenu();
  65. void ApplyMenuSettings();
  66. void setMenuActive(const char* name, bool isActive);
  67. bool mUseKeyMode;
  68. virtual void acceleratorKeyPress(U32 index);
  69. virtual bool onKeyDown(const GuiEvent &event);
  70. GuiControlProfile *mMenuProfile;
  71. GuiControlProfile *mMenuContentProfile;
  72. GuiControlProfile *mMenuItemProfile;
  73. GuiControlProfile *mBackgroundProfile;
  74. GuiControlProfile *mThumbProfile;
  75. GuiControlProfile *mArrowProfile;
  76. GuiControlProfile *mTrackProfile;
  77. bool onWake();
  78. void onSleep();
  79. void setControlBackgroundProfile(GuiControlProfile* prof);
  80. void setControlMenuProfile(GuiControlProfile* prof);
  81. void setControlMenuItemProfile(GuiControlProfile* prof);
  82. void setControlMenuContentProfile(GuiControlProfile* prof);
  83. void setControlThumbProfile(GuiControlProfile* prof);
  84. void setControlArrowProfile(GuiControlProfile* prof);
  85. void setControlTrackProfile(GuiControlProfile* prof);
  86. S32 mScrollBarThickness;
  87. bool mShowArrowButtons;
  88. bool mUseConstantHeightThumb;
  89. GuiMenuItemCtrl *mHoverTarget;
  90. GuiMenuItemCtrl *mOpenMenu;
  91. GuiMenuBGCtrl *mBackground;
  92. };
  93. class GuiMenuItemCtrl : public GuiControl
  94. {
  95. private:
  96. typedef GuiControl Parent;
  97. public:
  98. //creation methods
  99. DECLARE_CONOBJECT(GuiMenuItemCtrl);
  100. GuiMenuItemCtrl();
  101. static void initPersistFields();
  102. enum DisplayType
  103. {
  104. TextCommand = 0,
  105. Toggle,
  106. Radio,
  107. Spacer,
  108. Menu
  109. };
  110. DisplayType mDisplayType;
  111. bool mIsOpen;
  112. bool mIsHover;
  113. bool mIsOn;
  114. bool mToggle;
  115. bool mRadio;
  116. bool mHasGoodChildren;
  117. static bool setToggle(void *obj, const char *data)
  118. {
  119. GuiMenuItemCtrl* pCastObject = static_cast<GuiMenuItemCtrl *>(obj);
  120. pCastObject->mToggle = dAtob(data);
  121. pCastObject->mDisplayType = pCastObject->mToggle ? Toggle : TextCommand;
  122. return false;
  123. }
  124. static bool writeToggle(void* obj, StringTableEntry pFieldName) { return static_cast<GuiMenuItemCtrl*>(obj)->mToggle; }
  125. static bool setRadio(void *obj, const char *data)
  126. {
  127. GuiMenuItemCtrl* pCastObject = static_cast<GuiMenuItemCtrl *>(obj);
  128. pCastObject->mRadio = dAtob(data);
  129. pCastObject->mDisplayType = pCastObject->mRadio ? Radio : TextCommand;
  130. return false;
  131. }
  132. static bool writeRadio(void* obj, StringTableEntry pFieldName) { return static_cast<GuiMenuItemCtrl*>(obj)->mRadio; }
  133. static bool writeIsOn(void* obj, StringTableEntry pFieldName) { GuiMenuItemCtrl* pCastObject = static_cast<GuiMenuItemCtrl *>(obj); return pCastObject->mToggle || pCastObject->mRadio; }
  134. GuiMenuBarCtrl *mMenuBar;
  135. GuiScrollCtrl *mScroll;
  136. GuiMenuListCtrl *mList;
  137. GuiMenuItemCtrl *mPrevItem;
  138. GuiMenuItemCtrl *mNextItem;
  139. GuiMenuItemCtrl *mOpenSubMenu;
  140. virtual void onAction();
  141. virtual void inspectPostApply();
  142. virtual void onChildAdded(GuiControl *child);
  143. virtual void onChildRemoved(SimObject *child);
  144. void checkForGoodChildren();
  145. virtual void closeMenu();
  146. void ApplyMenuSettings();
  147. virtual void onRender(Point2I offset, const RectI &updateRect);
  148. virtual const char* getHotKeyText();
  149. virtual void toggleControl();
  150. virtual void turnOffPrevRadio();
  151. virtual void turnOffNextRadio();
  152. virtual bool onKeyDown(const GuiEvent &event);
  153. void setMenuActive(StringTableEntry name, bool isActive);
  154. };
  155. class GuiMenuBGCtrl : public GuiControl
  156. {
  157. protected:
  158. typedef GuiControl Parent;
  159. GuiMenuBarCtrl *mMenuBarCtrl;
  160. public:
  161. GuiMenuBGCtrl(GuiMenuBarCtrl *ctrl);
  162. void openMenu();
  163. void closeMenu();
  164. void openSubMenu(GuiMenuItemCtrl *subMenu);
  165. virtual void onTouchMove(const GuiEvent &event);
  166. virtual void onTouchDragged(const GuiEvent &event);
  167. virtual void processHover(const GuiEvent &event);
  168. virtual void onTouchDown(const GuiEvent &event);
  169. private:
  170. void positionMenu(const GuiMenuItemCtrl *menu, const Point2I &topLeft);
  171. };
  172. class GuiMenuListCtrl : public GuiControl
  173. {
  174. protected:
  175. typedef GuiControl Parent;
  176. GuiMenuItemCtrl *mMenu;
  177. public:
  178. GuiMenuListCtrl(GuiMenuItemCtrl *ctrl);
  179. virtual void onTouchMove(const GuiEvent &event);
  180. GuiMenuItemCtrl* GetHitItem(const Point2I &pt);
  181. virtual void onPreRender();
  182. void onRender(Point2I offset, const RectI &updateRect);
  183. bool onRenderItem(RectI &itemRect, GuiMenuItemCtrl *item);
  184. void updateSize();
  185. Point2I mItemSize;
  186. Point2I mSpacerSize;
  187. S32 mItemCount;
  188. S32 mSpacerCount;
  189. U32 mEnterItemTime;
  190. U32 mSubMenuStallTime;
  191. GuiMenuItemCtrl *mHoveredItem;
  192. bool mArmSubMenu;
  193. inline void setHoveredItem(GuiMenuItemCtrl *item) { mEnterItemTime = Platform::getVirtualMilliseconds(); mHoveredItem = item; mArmSubMenu = true; }
  194. virtual void onTouchDown(const GuiEvent& event);
  195. virtual void onTouchUp(const GuiEvent& event);
  196. void processMenuItem(GuiMenuItemCtrl *ctrl);
  197. };
  198. #endif