guiMenuBarCtrl.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. bool mUseKeyMode;
  67. virtual void acceleratorKeyPress(U32 index);
  68. virtual bool onKeyDown(const GuiEvent &event);
  69. GuiControlProfile *mMenuProfile;
  70. GuiControlProfile *mMenuContentProfile;
  71. GuiControlProfile *mMenuItemProfile;
  72. GuiControlProfile *mBackgroundProfile;
  73. GuiControlProfile *mThumbProfile;
  74. GuiControlProfile *mArrowProfile;
  75. GuiControlProfile *mTrackProfile;
  76. bool onWake();
  77. void onSleep();
  78. void setControlBackgroundProfile(GuiControlProfile* prof);
  79. void setControlMenuProfile(GuiControlProfile* prof);
  80. void setControlMenuItemProfile(GuiControlProfile* prof);
  81. void setControlMenuContentProfile(GuiControlProfile* prof);
  82. void setControlThumbProfile(GuiControlProfile* prof);
  83. void setControlArrowProfile(GuiControlProfile* prof);
  84. void setControlTrackProfile(GuiControlProfile* prof);
  85. S32 mScrollBarThickness;
  86. bool mShowArrowButtons;
  87. bool mUseConstantHeightThumb;
  88. GuiMenuItemCtrl *mHoverTarget;
  89. GuiMenuItemCtrl *mOpenMenu;
  90. GuiMenuBGCtrl *mBackground;
  91. };
  92. class GuiMenuItemCtrl : public GuiControl
  93. {
  94. private:
  95. typedef GuiControl Parent;
  96. public:
  97. //creation methods
  98. DECLARE_CONOBJECT(GuiMenuItemCtrl);
  99. GuiMenuItemCtrl();
  100. static void initPersistFields();
  101. enum DisplayType
  102. {
  103. TextCommand = 0,
  104. Toggle,
  105. Radio,
  106. Spacer,
  107. Menu
  108. };
  109. DisplayType mDisplayType;
  110. bool mIsOpen;
  111. bool mIsHover;
  112. bool mIsOn;
  113. bool mToggle;
  114. bool mRadio;
  115. bool mHasGoodChildren;
  116. static bool setToggle(void *obj, const char *data)
  117. {
  118. GuiMenuItemCtrl* pCastObject = static_cast<GuiMenuItemCtrl *>(obj);
  119. pCastObject->mToggle = dAtob(data);
  120. pCastObject->mDisplayType = pCastObject->mToggle ? Toggle : TextCommand;
  121. return false;
  122. }
  123. static bool writeToggle(void* obj, StringTableEntry pFieldName) { return static_cast<GuiMenuItemCtrl*>(obj)->mToggle; }
  124. static bool setRadio(void *obj, const char *data)
  125. {
  126. GuiMenuItemCtrl* pCastObject = static_cast<GuiMenuItemCtrl *>(obj);
  127. pCastObject->mRadio = dAtob(data);
  128. pCastObject->mDisplayType = pCastObject->mRadio ? Radio : TextCommand;
  129. return false;
  130. }
  131. static bool writeRadio(void* obj, StringTableEntry pFieldName) { return static_cast<GuiMenuItemCtrl*>(obj)->mRadio; }
  132. static bool writeIsOn(void* obj, StringTableEntry pFieldName) { GuiMenuItemCtrl* pCastObject = static_cast<GuiMenuItemCtrl *>(obj); return pCastObject->mToggle || pCastObject->mRadio; }
  133. GuiMenuBarCtrl *mMenuBar;
  134. GuiScrollCtrl *mScroll;
  135. GuiMenuListCtrl *mList;
  136. GuiMenuItemCtrl *mPrevItem;
  137. GuiMenuItemCtrl *mNextItem;
  138. GuiMenuItemCtrl *mOpenSubMenu;
  139. virtual void onAction();
  140. virtual void inspectPostApply();
  141. virtual void onChildAdded(GuiControl *child);
  142. virtual void onChildRemoved(SimObject *child);
  143. void checkForGoodChildren();
  144. virtual void closeMenu();
  145. void ApplyMenuSettings();
  146. virtual void onRender(Point2I offset, const RectI &updateRect);
  147. virtual const char* getHotKeyText();
  148. virtual void toggleControl();
  149. virtual void turnOffPrevRadio();
  150. virtual void turnOffNextRadio();
  151. virtual bool onKeyDown(const GuiEvent &event);
  152. };
  153. class GuiMenuBGCtrl : public GuiControl
  154. {
  155. protected:
  156. typedef GuiControl Parent;
  157. GuiMenuBarCtrl *mMenuBarCtrl;
  158. public:
  159. GuiMenuBGCtrl(GuiMenuBarCtrl *ctrl);
  160. void openMenu();
  161. void closeMenu();
  162. void openSubMenu(GuiMenuItemCtrl *subMenu);
  163. virtual void onTouchMove(const GuiEvent &event);
  164. virtual void onTouchDragged(const GuiEvent &event);
  165. virtual void processHover(const GuiEvent &event);
  166. virtual void onTouchDown(const GuiEvent &event);
  167. private:
  168. void positionMenu(const GuiMenuItemCtrl *menu, const Point2I &topLeft);
  169. };
  170. class GuiMenuListCtrl : public GuiControl
  171. {
  172. protected:
  173. typedef GuiControl Parent;
  174. GuiMenuItemCtrl *mMenu;
  175. public:
  176. GuiMenuListCtrl(GuiMenuItemCtrl *ctrl);
  177. virtual void onTouchMove(const GuiEvent &event);
  178. GuiMenuItemCtrl* GetHitItem(const Point2I &pt);
  179. virtual void onPreRender();
  180. void onRender(Point2I offset, const RectI &updateRect);
  181. bool onRenderItem(RectI &itemRect, GuiMenuItemCtrl *item);
  182. void updateSize();
  183. Point2I mItemSize;
  184. Point2I mSpacerSize;
  185. S32 mItemCount;
  186. S32 mSpacerCount;
  187. U32 mEnterItemTime;
  188. U32 mSubMenuStallTime;
  189. GuiMenuItemCtrl *mHoveredItem;
  190. bool mArmSubMenu;
  191. inline void setHoveredItem(GuiMenuItemCtrl *item) { mEnterItemTime = Platform::getVirtualMilliseconds(); mHoveredItem = item; mArmSubMenu = true; }
  192. virtual void onTouchDown(const GuiEvent& event);
  193. virtual void onTouchUp(const GuiEvent& event);
  194. void processMenuItem(GuiMenuItemCtrl *ctrl);
  195. };
  196. #endif