Counter Strike : Global Offensive Source Code
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.

138 lines
3.9 KiB

  1. //========= Copyright � 1996-2005, 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. virtual void RepositionTextImage( int &x, int &y, TextImage *pTextImage );
  86. private:
  87. enum { CHECK_INSET = 6 };
  88. Menu *m_pCascadeMenu; // menu triggered to open upon selecting this menu item
  89. bool m_bCheckable; // can this menu item have a little check to the left of it when you select it?
  90. bool m_bChecked; // whether item is checked or not.
  91. TextImage *m_pCascadeArrow; // little arrow that appears to the right of menuitems that open a menu
  92. TextImage *m_pCheck; // the check that appears to the left of checked menu items
  93. TextImage *m_pBlankCheck; // a blank image same size as the check for when items are not checked.
  94. TextImage *m_pCurrentKeyBinding; // An optional indicator for the key currently bound to this menu item
  95. KeyValues *m_pUserData;
  96. };
  97. } // namespace vgui
  98. #endif // MENUITEM_H