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.

104 lines
2.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "dme_controls/AttributeElementPanel.h"
  9. #include "dme_controls/AttributeTextEntry.h"
  10. #include "dme_controls/AttributeWidgetFactory.h"
  11. #include "tier1/KeyValues.h"
  12. #include "datamodel/dmelement.h"
  13. #include "movieobjects/dmeeditortypedictionary.h"
  14. // memdbgon must be the last include file in a .cpp file!!!
  15. #include "tier0/memdbgon.h"
  16. using namespace vgui;
  17. // ----------------------------------------------------------------------------
  18. CAttributeElementPanel::CAttributeElementPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
  19. BaseClass( parent, info ), m_pData( 0 )
  20. {
  21. m_pData = new CAttributeTextEntry( this, "AttributeValue" );
  22. m_pData->SetEnabled( !HasFlag( READONLY ) );
  23. m_pData->AddActionSignalTarget(this);
  24. m_pType->SetText( "element" );
  25. m_bShowMemoryUsage = info.m_bShowMemoryUsage;
  26. }
  27. void CAttributeElementPanel::Apply()
  28. {
  29. // FIXME: Implement when needed
  30. Assert( 0 );
  31. }
  32. vgui::Panel *CAttributeElementPanel::GetDataPanel()
  33. {
  34. return static_cast< vgui::Panel * >( m_pData );
  35. }
  36. void CAttributeElementPanel::OnCreateDragData( KeyValues *msg )
  37. {
  38. if ( GetPanelElement() )
  39. {
  40. char txt[ 256 ];
  41. m_pData->GetText( txt, sizeof( txt ) );
  42. msg->SetString( "text", txt );
  43. CDmElement *element = NULL;
  44. if ( GetPanelElement()->HasAttribute( GetAttributeName() ) )
  45. {
  46. element = GetElement<CDmElement>( GetAttributeValue<DmElementHandle_t>( ) );
  47. msg->SetInt( "dmeelement", element->GetHandle() );
  48. }
  49. }
  50. }
  51. void CAttributeElementPanel::Refresh()
  52. {
  53. char elemText[ 512 ];
  54. elemText[0] = 0;
  55. CDmElement *element = NULL;
  56. if ( !GetEditorInfo() || !GetEditorInfo()->GetValue<bool>( "hideText" ) )
  57. {
  58. if ( HasAttribute( ) )
  59. {
  60. element = GetAttributeValueElement( );
  61. }
  62. else
  63. {
  64. element = GetPanelElement();
  65. }
  66. }
  67. if ( element )
  68. {
  69. char idstr[ 37 ];
  70. UniqueIdToString( element->GetId(), idstr, sizeof( idstr ) );
  71. if ( m_bShowMemoryUsage )
  72. {
  73. Q_snprintf( elemText, sizeof( elemText ), "%s %s %.3fMB", element->GetTypeString(), idstr, element->EstimateMemoryUsage() / float( 1 << 20 ) );
  74. }
  75. else
  76. {
  77. Q_snprintf( elemText, sizeof( elemText ), "%s %s", element->GetTypeString(), idstr );
  78. }
  79. }
  80. m_pData->SetText( elemText );
  81. m_pData->SetEnabled(false);
  82. }
  83. void CAttributeElementPanel::PostConstructor()
  84. {
  85. Refresh();
  86. }
  87. // ----------------------------------------------------------------------------