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
3.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "dme_controls/AttributeInterpolatorChoicePanel.h"
  9. #include "tier1/KeyValues.h"
  10. #include "vgui_controls/ComboBox.h"
  11. #include "datamodel/dmelement.h"
  12. #include "movieobjects/dmeeditortypedictionary.h"
  13. #include "datamodel/dmelementfactoryhelper.h"
  14. #include "dme_controls/inotifyui.h"
  15. #include "interpolatortypes.h"
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include "tier0/memdbgon.h"
  18. using namespace vgui;
  19. //-----------------------------------------------------------------------------
  20. //
  21. // Constructor
  22. //
  23. //-----------------------------------------------------------------------------
  24. CAttributeInterpolatorChoicePanel::CAttributeInterpolatorChoicePanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
  25. BaseClass( parent, info )
  26. {
  27. }
  28. //-----------------------------------------------------------------------------
  29. // Derived classes can re-implement this to fill the combo box however they like
  30. //-----------------------------------------------------------------------------
  31. void CAttributeInterpolatorChoicePanel::PopulateComboBoxes( vgui::ComboBox *pComboBox[ 2 ] )
  32. {
  33. pComboBox[ 0 ]->DeleteAllItems();
  34. pComboBox[ 1 ]->DeleteAllItems();
  35. // Fill in the choices
  36. int c = NUM_INTERPOLATE_TYPES;
  37. for ( int i = 0; i < c; ++i )
  38. {
  39. KeyValues *kv = new KeyValues( "entry" );
  40. kv->SetInt( "value", i );
  41. pComboBox[ 0 ]->AddItem( Interpolator_NameForInterpolator( i, true ) , kv );
  42. kv = new KeyValues( "entry" );
  43. kv->SetInt( "value", i );
  44. pComboBox[ 1 ]->AddItem( Interpolator_NameForInterpolator( i, true ) , kv );
  45. }
  46. }
  47. //-----------------------------------------------------------------------------
  48. // Sets the attribute based on the combo box
  49. //-----------------------------------------------------------------------------
  50. void CAttributeInterpolatorChoicePanel::SetAttributeFromComboBoxes( vgui::ComboBox *pComboBox[ 2 ], KeyValues *pKeyValues[ 2 ] )
  51. {
  52. int nOldValue = GetAttributeValue<int>();
  53. int nValueLeft = pKeyValues[ 0 ]->GetInt( "value", 0 );
  54. int nValueRight= pKeyValues[ 1 ]->GetInt( "value" , 0 );
  55. int nValue = MAKE_CURVE_TYPE( nValueLeft, nValueRight );
  56. // No change
  57. if ( nOldValue == nValue )
  58. return;
  59. CElementTreeUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, GetNotify(), "Set Attribute Value", "Set Attribute Value" );
  60. SetAttributeValue( nValue );
  61. }
  62. //-----------------------------------------------------------------------------
  63. // Sets the combo box from the attribute
  64. //-----------------------------------------------------------------------------
  65. void CAttributeInterpolatorChoicePanel::SetComboBoxesFromAttribute( vgui::ComboBox *pComboBox[ 2 ] )
  66. {
  67. int nValue = GetAttributeValue<int>();
  68. // Decompose
  69. int leftPart = GET_LEFT_CURVE( nValue );
  70. int rightPart = GET_RIGHT_CURVE( nValue );
  71. pComboBox[ 0 ]->SetText( Interpolator_NameForInterpolator( leftPart, true ) );
  72. pComboBox[ 1 ]->SetText( Interpolator_NameForInterpolator( rightPart, true ) );
  73. }