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
119
120
121
122
123
124
125
126
127
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/BaseAttributeDoubleChoicePanel.h"
#include "tier1/KeyValues.h"
#include "vgui_controls/ComboBox.h"
#include "datamodel/dmelement.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
CDoubleComboBoxContainerPanel::CDoubleComboBoxContainerPanel( vgui::Panel *parent, char const *name ) :
BaseClass( parent, name )
{
m_pBoxes[ 0 ] = m_pBoxes[ 1 ] = NULL;
}
void CDoubleComboBoxContainerPanel::AddComboBox( int slot, vgui::ComboBox *box )
{
m_pBoxes[ slot ] = box;
}
void CDoubleComboBoxContainerPanel::PerformLayout()
{
BaseClass::PerformLayout();
int w, h;
GetSize( w, h );
if ( m_pBoxes[ 0 ] )
{
m_pBoxes[ 0 ]->SetBounds( 0, 0, w/2, h );
}
if ( m_pBoxes[ 1 ] )
{
m_pBoxes[ 1 ]->SetBounds( w/2, 0, w/2, h );
}
}
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CBaseAttributeDoubleChoicePanel::CBaseAttributeDoubleChoicePanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info )
{
SetDropEnabled( false );
m_pContainerPanel = new CDoubleComboBoxContainerPanel( this, "Container" );
m_pData[0] = new vgui::ComboBox( m_pContainerPanel, "AttributeValue", 10, false );
m_pData[0]->SetEnabled( !HasFlag( FATTRIB_READONLY ) );
m_pData[0]->AddActionSignalTarget( this );
m_pContainerPanel->AddComboBox( 0, m_pData[ 0 ] );
m_pData[1] = new vgui::ComboBox( m_pContainerPanel, "AttributeValue", 10, false );
m_pData[1]->SetEnabled( !HasFlag( FATTRIB_READONLY ) );
m_pData[1]->AddActionSignalTarget( this );
m_pContainerPanel->AddComboBox( 1, m_pData[ 1 ] );
}
//-----------------------------------------------------------------------------
// Called after the constructor is finished
//-----------------------------------------------------------------------------
void CBaseAttributeDoubleChoicePanel::PostConstructor()
{
BaseClass::PostConstructor();
PopulateComboBoxes( m_pData );
Refresh();
}
void CBaseAttributeDoubleChoicePanel::ApplySchemeSettings( IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
HFont font = pScheme->GetFont( "DmePropertyVerySmall", IsProportional() );
m_pData[0]->SetFont(font);
m_pData[1]->SetFont(font);
}
vgui::Panel *CBaseAttributeDoubleChoicePanel::GetDataPanel()
{
return static_cast< vgui::Panel * >( m_pContainerPanel );
}
//-----------------------------------------------------------------------------
// Called when it is time to set the attribute from the combo box state
//-----------------------------------------------------------------------------
void CBaseAttributeDoubleChoicePanel::Apply( )
{
Assert( m_pData[ 0 ] && m_pData[ 1 ] );
KeyValues *kv[ 2 ];
kv[ 0 ] = m_pData[ 0 ]->GetActiveItemUserData();
kv[ 1 ] = m_pData[ 1 ]->GetActiveItemUserData();
SetAttributeFromComboBoxes( m_pData, kv );
}
//-----------------------------------------------------------------------------
// Called when it is time to set the combo box from the attribute
//-----------------------------------------------------------------------------
void CBaseAttributeDoubleChoicePanel::Refresh()
{
SetComboBoxesFromAttribute( m_pData );
}
//-----------------------------------------------------------------------------
// Called when the text in the panel changes
//-----------------------------------------------------------------------------
void CBaseAttributeDoubleChoicePanel::OnTextChanged( Panel *panel )
{
SetDirty(true);
if ( IsAutoApply() )
{
Apply();
}
}
|