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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "KeyToggleCheckButton.h"
#include "EngineInterface.h"
#include <vgui/IVGui.h>
#include "IGameUIFuncs.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
using namespace vgui;
CKeyToggleCheckButton::CKeyToggleCheckButton( Panel *parent, const char *panelName, const char *text,
char const *key, char const *cmdname )
: CheckButton( parent, panelName, text )
{
m_pszKeyName = key ? strdup( key ) : NULL;
m_pszCmdName = cmdname ? strdup( cmdname ) : NULL;
if (m_pszKeyName)
{
Reset();
}
//m_bNoCommand = false;
}
CKeyToggleCheckButton::~CKeyToggleCheckButton()
{
free( m_pszKeyName );
free( m_pszCmdName );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CKeyToggleCheckButton::Paint()
{
BaseClass::Paint();
if ( !m_pszKeyName )
return;
// Fixme, look up key state
bool isdown;
if ( gameuifuncs->IsKeyDown( m_pszKeyName, isdown ) )
{
// if someone changed the value using the consoel
if ( m_bStartValue != isdown )
{
SetSelected( isdown );
m_bStartValue = isdown;
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *panel -
//-----------------------------------------------------------------------------
/*
void CKeyToggleCheckButton::SetSelected( bool state )
{
BaseClass::SetSelected( state );
if ( !m_pszCmdName || !m_pszCmdName[ 0 ] )
return;
if ( m_bNoCommand )
return;
char szCommand[ 256 ];
Q_snprintf( szCommand, sizeof( szCommand ), "%c%s\n", IsSelected() ? '+' : '-',
m_pszCmdName );
engine->pfnClientCmd( szCommand );
}*/
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CKeyToggleCheckButton::Reset()
{
gameuifuncs->IsKeyDown( m_pszKeyName, m_bStartValue );
if ( IsSelected() != m_bStartValue)
{
SetSelected( m_bStartValue );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CKeyToggleCheckButton::ApplyChanges()
{
if ( !m_pszCmdName || !m_pszCmdName[ 0 ] )
return;
char szCommand[ 256 ];
Q_snprintf( szCommand, sizeof( szCommand ), "%c%s\n", IsSelected() ? '+' : '-',
m_pszCmdName );
engine->ClientCmd_Unrestricted( szCommand );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CKeyToggleCheckButton::HasBeenModified()
{
return IsSelected() != m_bStartValue;
}
|