diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /vgui2/dme_controls/BaseAttributeDoubleChoicePanel.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'vgui2/dme_controls/BaseAttributeDoubleChoicePanel.cpp')
| -rw-r--r-- | vgui2/dme_controls/BaseAttributeDoubleChoicePanel.cpp | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/vgui2/dme_controls/BaseAttributeDoubleChoicePanel.cpp b/vgui2/dme_controls/BaseAttributeDoubleChoicePanel.cpp new file mode 100644 index 0000000..40dc9e8 --- /dev/null +++ b/vgui2/dme_controls/BaseAttributeDoubleChoicePanel.cpp @@ -0,0 +1,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(); + } +} + |