summaryrefslogtreecommitdiff
path: root/gameui/CommandCheckButton.cpp
blob: 1ea98ce3467fb77c775d0f41559128b2cbb3da33 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//

#include "CommandCheckButton.h"
#include "EngineInterface.h"

// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>

using namespace vgui;

CCommandCheckButton::CCommandCheckButton( Panel *parent, const char *panelName, const char *text, const char *downcmd, const char *upcmd )
 : CheckButton( parent, panelName, text )
{
	m_pszDown = downcmd ? strdup( downcmd ) : NULL;
	m_pszUp = upcmd ? strdup( upcmd ) : NULL;
}

CCommandCheckButton::~CCommandCheckButton()
{
	free( m_pszDown );
	free( m_pszUp );
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *panel - 
//-----------------------------------------------------------------------------
void CCommandCheckButton::SetSelected( bool state )
{
	BaseClass::SetSelected( state );

	if ( IsSelected() && m_pszDown )
	{
		engine->ClientCmd_Unrestricted( m_pszDown );
		engine->ClientCmd_Unrestricted( "\n" );
	}
	else if ( !IsSelected() && m_pszUp )
	{
		engine->ClientCmd_Unrestricted( m_pszUp );
		engine->ClientCmd_Unrestricted( "\n" );
	}
}