Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
3.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "dme_controls/BaseAttributeDoubleChoicePanel.h"
  9. #include "tier1/KeyValues.h"
  10. #include "vgui_controls/ComboBox.h"
  11. #include "datamodel/dmelement.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. using namespace vgui;
  15. CDoubleComboBoxContainerPanel::CDoubleComboBoxContainerPanel( vgui::Panel *parent, char const *name ) :
  16. BaseClass( parent, name )
  17. {
  18. m_pBoxes[ 0 ] = m_pBoxes[ 1 ] = NULL;
  19. }
  20. void CDoubleComboBoxContainerPanel::AddComboBox( int slot, vgui::ComboBox *box )
  21. {
  22. m_pBoxes[ slot ] = box;
  23. }
  24. void CDoubleComboBoxContainerPanel::PerformLayout()
  25. {
  26. BaseClass::PerformLayout();
  27. int w, h;
  28. GetSize( w, h );
  29. if ( m_pBoxes[ 0 ] )
  30. {
  31. m_pBoxes[ 0 ]->SetBounds( 0, 0, w/2, h );
  32. }
  33. if ( m_pBoxes[ 1 ] )
  34. {
  35. m_pBoxes[ 1 ]->SetBounds( w/2, 0, w/2, h );
  36. }
  37. }
  38. //-----------------------------------------------------------------------------
  39. // Constructor
  40. //-----------------------------------------------------------------------------
  41. CBaseAttributeDoubleChoicePanel::CBaseAttributeDoubleChoicePanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
  42. BaseClass( parent, info )
  43. {
  44. SetDropEnabled( false );
  45. m_pContainerPanel = new CDoubleComboBoxContainerPanel( this, "Container" );
  46. m_pData[0] = new vgui::ComboBox( m_pContainerPanel, "AttributeValue", 10, false );
  47. m_pData[0]->SetEnabled( !HasFlag( FATTRIB_READONLY ) );
  48. m_pData[0]->AddActionSignalTarget( this );
  49. m_pContainerPanel->AddComboBox( 0, m_pData[ 0 ] );
  50. m_pData[1] = new vgui::ComboBox( m_pContainerPanel, "AttributeValue", 10, false );
  51. m_pData[1]->SetEnabled( !HasFlag( FATTRIB_READONLY ) );
  52. m_pData[1]->AddActionSignalTarget( this );
  53. m_pContainerPanel->AddComboBox( 1, m_pData[ 1 ] );
  54. }
  55. //-----------------------------------------------------------------------------
  56. // Called after the constructor is finished
  57. //-----------------------------------------------------------------------------
  58. void CBaseAttributeDoubleChoicePanel::PostConstructor()
  59. {
  60. BaseClass::PostConstructor();
  61. PopulateComboBoxes( m_pData );
  62. Refresh();
  63. }
  64. void CBaseAttributeDoubleChoicePanel::ApplySchemeSettings( IScheme *pScheme )
  65. {
  66. BaseClass::ApplySchemeSettings( pScheme );
  67. HFont font = pScheme->GetFont( "DmePropertyVerySmall", IsProportional() );
  68. m_pData[0]->SetFont(font);
  69. m_pData[1]->SetFont(font);
  70. }
  71. vgui::Panel *CBaseAttributeDoubleChoicePanel::GetDataPanel()
  72. {
  73. return static_cast< vgui::Panel * >( m_pContainerPanel );
  74. }
  75. //-----------------------------------------------------------------------------
  76. // Called when it is time to set the attribute from the combo box state
  77. //-----------------------------------------------------------------------------
  78. void CBaseAttributeDoubleChoicePanel::Apply( )
  79. {
  80. Assert( m_pData[ 0 ] && m_pData[ 1 ] );
  81. KeyValues *kv[ 2 ];
  82. kv[ 0 ] = m_pData[ 0 ]->GetActiveItemUserData();
  83. kv[ 1 ] = m_pData[ 1 ]->GetActiveItemUserData();
  84. SetAttributeFromComboBoxes( m_pData, kv );
  85. }
  86. //-----------------------------------------------------------------------------
  87. // Called when it is time to set the combo box from the attribute
  88. //-----------------------------------------------------------------------------
  89. void CBaseAttributeDoubleChoicePanel::Refresh()
  90. {
  91. SetComboBoxesFromAttribute( m_pData );
  92. }
  93. //-----------------------------------------------------------------------------
  94. // Called when the text in the panel changes
  95. //-----------------------------------------------------------------------------
  96. void CBaseAttributeDoubleChoicePanel::OnTextChanged( Panel *panel )
  97. {
  98. SetDirty(true);
  99. if ( IsAutoApply() )
  100. {
  101. Apply();
  102. }
  103. }