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.

72 lines
2.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Core Movie Maker UI API
  4. //
  5. //=============================================================================
  6. #include "toolutils/toolswitchmenubutton.h"
  7. #include "vgui_controls/panel.h"
  8. #include "toolutils/toolmenubutton.h"
  9. #include "toolutils/enginetools_int.h"
  10. #include "tier1/KeyValues.h"
  11. #include "vgui_controls/menu.h"
  12. #include "toolframework/ienginetool.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. //-----------------------------------------------------------------------------
  16. // Menu to switch between tools
  17. //-----------------------------------------------------------------------------
  18. class CToolSwitchMenuButton : public CToolMenuButton
  19. {
  20. DECLARE_CLASS_SIMPLE( CToolSwitchMenuButton, CToolMenuButton );
  21. public:
  22. CToolSwitchMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionTarget );
  23. virtual void OnShowMenu(vgui::Menu *menu);
  24. };
  25. //-----------------------------------------------------------------------------
  26. // Global function to create the switch menu
  27. //-----------------------------------------------------------------------------
  28. CToolMenuButton* CreateToolSwitchMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionTarget )
  29. {
  30. return new CToolSwitchMenuButton( parent, panelName, text, pActionTarget );
  31. }
  32. //-----------------------------------------------------------------------------
  33. // Constructor
  34. //-----------------------------------------------------------------------------
  35. CToolSwitchMenuButton::CToolSwitchMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionTarget ) :
  36. BaseClass( parent, panelName, text, pActionTarget )
  37. {
  38. SetMenu(m_pMenu);
  39. }
  40. //-----------------------------------------------------------------------------
  41. // Is called when the menu is made visible
  42. //-----------------------------------------------------------------------------
  43. void CToolSwitchMenuButton::OnShowMenu(vgui::Menu *menu)
  44. {
  45. BaseClass::OnShowMenu( menu );
  46. Reset();
  47. int c = enginetools->GetToolCount();
  48. for ( int i = 0 ; i < c; ++i )
  49. {
  50. char const *toolname = enginetools->GetToolName( i );
  51. char toolcmd[ 32 ];
  52. Q_snprintf( toolcmd, sizeof( toolcmd ), "OnTool%i", i );
  53. int id = AddCheckableMenuItem( toolname, toolname, new KeyValues ( "Command", "command", toolcmd ), m_pActionTarget );
  54. m_pMenu->SetItemEnabled( id, true );
  55. m_pMenu->SetMenuItemChecked( id, enginetools->IsTopmostTool( enginetools->GetToolSystem( i ) ) );
  56. }
  57. }