From 3bf9df6b2785fa6d951086978a3e66f49427166a Mon Sep 17 00:00:00 2001 From: FluorescentCIAAfricanAmerican <0934gj3049fk@protonmail.com> Date: Wed, 22 Apr 2020 12:56:21 -0400 Subject: 1 --- tools/toolutils/ToolSwitchMenuButton.cpp | 72 ++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tools/toolutils/ToolSwitchMenuButton.cpp (limited to 'tools/toolutils/ToolSwitchMenuButton.cpp') diff --git a/tools/toolutils/ToolSwitchMenuButton.cpp b/tools/toolutils/ToolSwitchMenuButton.cpp new file mode 100644 index 0000000..46f0c7c --- /dev/null +++ b/tools/toolutils/ToolSwitchMenuButton.cpp @@ -0,0 +1,72 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Core Movie Maker UI API +// +//============================================================================= + +#include "toolutils/toolswitchmenubutton.h" +#include "vgui_controls/panel.h" +#include "toolutils/toolmenubutton.h" +#include "toolutils/enginetools_int.h" +#include "tier1/KeyValues.h" +#include "vgui_controls/menu.h" +#include "toolframework/ienginetool.h" + +// memdbgon must be the last include file in a .cpp file!!! +#include "tier0/memdbgon.h" + + +//----------------------------------------------------------------------------- +// Menu to switch between tools +//----------------------------------------------------------------------------- +class CToolSwitchMenuButton : public CToolMenuButton +{ + DECLARE_CLASS_SIMPLE( CToolSwitchMenuButton, CToolMenuButton ); + +public: + CToolSwitchMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionTarget ); + virtual void OnShowMenu(vgui::Menu *menu); +}; + + +//----------------------------------------------------------------------------- +// Global function to create the switch menu +//----------------------------------------------------------------------------- +CToolMenuButton* CreateToolSwitchMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionTarget ) +{ + return new CToolSwitchMenuButton( parent, panelName, text, pActionTarget ); +} + + +//----------------------------------------------------------------------------- +// Constructor +//----------------------------------------------------------------------------- +CToolSwitchMenuButton::CToolSwitchMenuButton( vgui::Panel *parent, const char *panelName, const char *text, vgui::Panel *pActionTarget ) : + BaseClass( parent, panelName, text, pActionTarget ) +{ + SetMenu(m_pMenu); +} + + +//----------------------------------------------------------------------------- +// Is called when the menu is made visible +//----------------------------------------------------------------------------- +void CToolSwitchMenuButton::OnShowMenu(vgui::Menu *menu) +{ + BaseClass::OnShowMenu( menu ); + + Reset(); + + int c = enginetools->GetToolCount(); + for ( int i = 0 ; i < c; ++i ) + { + char const *toolname = enginetools->GetToolName( i ); + + char toolcmd[ 32 ]; + Q_snprintf( toolcmd, sizeof( toolcmd ), "OnTool%i", i ); + + int id = AddCheckableMenuItem( toolname, toolname, new KeyValues ( "Command", "command", toolcmd ), m_pActionTarget ); + m_pMenu->SetItemEnabled( id, true ); + m_pMenu->SetMenuItemChecked( id, enginetools->IsTopmostTool( enginetools->GetToolSystem( i ) ) ); + } +} -- cgit v1.2.3