Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
3.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef MENUITEM_H
  8. #define MENUITEM_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include <vgui/VGUI.h>
  13. #include <vgui_controls/Button.h>
  14. #include <vgui_controls/Menu.h>
  15. namespace vgui
  16. {
  17. class IBorder;
  18. class TextImage;
  19. class Menu;
  20. class Image;
  21. //-----------------------------------------------------------------------------
  22. // Purpose: The items in a menu
  23. // MenuItems MUST have the Menu class as parents.
  24. //-----------------------------------------------------------------------------
  25. class MenuItem : public Button
  26. {
  27. DECLARE_CLASS_SIMPLE( MenuItem, Button );
  28. public:
  29. MenuItem(Menu *parent, const char *panelName, const char *text, Menu *cascadeMenu = NULL, bool checkable = false);
  30. MenuItem(Menu *parent, const char *panelName, const wchar_t *wszText, Menu *cascadeMenu = NULL, bool checkable = false);
  31. ~MenuItem();
  32. virtual void Paint();
  33. // Activate the menu item as if it had been selected by the user
  34. virtual void FireActionSignal();
  35. virtual bool CanBeDefaultButton(void);
  36. // Handle mouse cursor entering a MenuItem.
  37. void OnCursorEntered();
  38. // Handle mouse cursor exiting a MenuItem.
  39. void OnCursorExited();
  40. // Close the cascading menu if we have one.
  41. void CloseCascadeMenu();
  42. // Pass kill focus events up to parent on loss of focus
  43. MESSAGE_FUNC( OnKillFocus, "MenuClose" );
  44. // Return true if this item triggers a cascading menu
  45. bool HasMenu();
  46. // Set the size of the text portion of the label.
  47. void SetTextImageSize(int wide, int tall);
  48. //Return the size of the text portion of the label.
  49. void GetTextImageSize(int &wide, int &tall);
  50. // Return the size of the arrow portion of the label.
  51. void GetArrowImageSize(int &wide, int &tall);
  52. // Return the size of the check portion of the label.
  53. void GetCheckImageSize(int &wide, int &tall);
  54. // Return the menu that this menuItem contains
  55. Menu *GetMenu();
  56. virtual void PerformLayout();
  57. // Respond to cursor movement
  58. void OnCursorMoved(int x, int y);
  59. // Highlight item
  60. MESSAGE_FUNC( ArmItem, "ArmItem" );
  61. // Unhighlight item.
  62. MESSAGE_FUNC( DisarmItem, "DisarmItem" );
  63. // is the item highlighted?
  64. bool IsItemArmed();
  65. // Open cascading menu if there is one.
  66. void OpenCascadeMenu();
  67. bool IsCheckable();
  68. bool IsChecked();
  69. // Set a checkable menuItem checked or unchecked.
  70. void SetChecked(bool state);
  71. KeyValues *GetUserData();
  72. void SetUserData(const KeyValues *kv);
  73. int GetActiveItem() { if ( m_pCascadeMenu ) { return m_pCascadeMenu->GetActiveItem(); } else { return 0; }}
  74. Menu *GetParentMenu();
  75. void SetCurrentKeyBinding( char const *keyName );
  76. virtual void GetContentSize( int& cw, int &ch );
  77. protected:
  78. void OnKeyCodeReleased(KeyCode code);
  79. void OnMenuClose();
  80. MESSAGE_FUNC( OnKeyModeSet, "KeyModeSet" );
  81. // vgui overrides
  82. virtual void Init( void );
  83. virtual void ApplySchemeSettings(IScheme *pScheme);
  84. virtual IBorder *GetBorder(bool depressed, bool armed, bool selected, bool keyfocus);
  85. private:
  86. enum { CHECK_INSET = 6 };
  87. Menu *m_pCascadeMenu; // menu triggered to open upon selecting this menu item
  88. bool m_bCheckable; // can this menu item have a little check to the left of it when you select it?
  89. bool m_bChecked; // whether item is checked or not.
  90. TextImage *m_pCascadeArrow; // little arrow that appears to the right of menuitems that open a menu
  91. Image *m_pCheck; // the check that appears to the left of checked menu items
  92. TextImage *m_pBlankCheck; // a blank image same size as the check for when items are not checked.
  93. TextImage *m_pCurrentKeyBinding; // An optional indicator for the key currently bound to this menu item
  94. KeyValues *m_pUserData;
  95. };
  96. } // namespace vgui
  97. #endif // MENUITEM_H