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.

91 lines
2.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "dme_controls/BaseAttributeChoicePanel.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. //-----------------------------------------------------------------------------
  16. // Constructor
  17. //-----------------------------------------------------------------------------
  18. CBaseAttributeChoicePanel::CBaseAttributeChoicePanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
  19. BaseClass( parent, info ), m_pData( 0 )
  20. {
  21. SetDropEnabled( false );
  22. m_pData = new vgui::ComboBox( this, "AttributeValue", 10, false );
  23. m_pData->SetEnabled( !HasFlag( FATTRIB_READONLY ) );
  24. m_pData->AddActionSignalTarget( this );
  25. }
  26. //-----------------------------------------------------------------------------
  27. // Called after the constructor is finished
  28. //-----------------------------------------------------------------------------
  29. void CBaseAttributeChoicePanel::PostConstructor()
  30. {
  31. BaseClass::PostConstructor();
  32. PopulateComboBox( m_pData );
  33. Refresh();
  34. }
  35. void CBaseAttributeChoicePanel::ApplySchemeSettings( IScheme *pScheme )
  36. {
  37. BaseClass::ApplySchemeSettings( pScheme );
  38. HFont font = pScheme->GetFont( "DmePropertyVerySmall", IsProportional() );
  39. m_pData->SetFont(font);
  40. }
  41. vgui::Panel *CBaseAttributeChoicePanel::GetDataPanel()
  42. {
  43. return static_cast< vgui::Panel * >( m_pData );
  44. }
  45. //-----------------------------------------------------------------------------
  46. // Called when it is time to set the attribute from the combo box state
  47. //-----------------------------------------------------------------------------
  48. void CBaseAttributeChoicePanel::Apply( )
  49. {
  50. KeyValues *kv = m_pData->GetActiveItemUserData();
  51. SetAttributeFromComboBox( m_pData, kv );
  52. }
  53. //-----------------------------------------------------------------------------
  54. // Called when it is time to set the combo box from the attribute
  55. //-----------------------------------------------------------------------------
  56. void CBaseAttributeChoicePanel::Refresh()
  57. {
  58. SetComboBoxFromAttribute( m_pData );
  59. }
  60. //-----------------------------------------------------------------------------
  61. // Called when the text in the panel changes
  62. //-----------------------------------------------------------------------------
  63. void CBaseAttributeChoicePanel::OnTextChanged( Panel *panel )
  64. {
  65. if ( IsAutoApply() )
  66. {
  67. Apply();
  68. }
  69. else
  70. {
  71. SetDirty(true);
  72. }
  73. }