Counter Strike : Global Offensive Source Code
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.

116 lines
2.8 KiB

  1. //====== Copyright � 1996-2005, 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. m_bShowUniqueID = info.m_bShowUniqueID;
  27. }
  28. void CAttributeElementPanel::SetFont( HFont font )
  29. {
  30. BaseClass::SetFont( font );
  31. m_pData->SetFont( font );
  32. m_pType->SetFont( font );
  33. }
  34. void CAttributeElementPanel::Apply()
  35. {
  36. // FIXME: Implement when needed
  37. Assert( 0 );
  38. }
  39. vgui::Panel *CAttributeElementPanel::GetDataPanel()
  40. {
  41. return static_cast< vgui::Panel * >( m_pData );
  42. }
  43. void CAttributeElementPanel::OnCreateDragData( KeyValues *msg )
  44. {
  45. if ( GetPanelElement() )
  46. {
  47. char txt[ 256 ];
  48. m_pData->GetText( txt, sizeof( txt ) );
  49. msg->SetString( "text", txt );
  50. CDmElement *element = NULL;
  51. if ( GetPanelElement()->HasAttribute( GetAttributeName() ) )
  52. {
  53. element = GetElement<CDmElement>( GetAttributeValue<DmElementHandle_t>( ) );
  54. msg->SetInt( "dmeelement", element->GetHandle() );
  55. }
  56. }
  57. }
  58. void CAttributeElementPanel::Refresh()
  59. {
  60. char elemText[ 512 ];
  61. elemText[0] = 0;
  62. CDmElement *element = NULL;
  63. if ( !GetEditorInfo() || !GetEditorInfo()->GetValue<bool>( "hideText" ) )
  64. {
  65. if ( HasAttribute( ) )
  66. {
  67. element = GetAttributeValueElement( );
  68. }
  69. else
  70. {
  71. element = GetPanelElement();
  72. }
  73. }
  74. if ( element )
  75. {
  76. char idstr[ 37 ] = "";
  77. if( m_bShowUniqueID )
  78. {
  79. UniqueIdToString( element->GetId(), idstr, sizeof( idstr ) );
  80. }
  81. if ( m_bShowMemoryUsage )
  82. {
  83. Q_snprintf( elemText, sizeof( elemText ), "%s %s (%.3fMB total / %.3fKB self)", element->GetTypeString(),
  84. idstr, element->EstimateMemoryUsage( TD_DEEP ) / float( 1 << 20 ), element->EstimateMemoryUsage( TD_NONE ) / float( 1 << 10 ) );
  85. }
  86. else
  87. {
  88. Q_snprintf( elemText, sizeof( elemText ), "%s %s", element->GetTypeString(), idstr );
  89. }
  90. }
  91. m_pData->SetText( elemText );
  92. m_pData->SetEnabled(false);
  93. }
  94. void CAttributeElementPanel::PostConstructor()
  95. {
  96. Refresh();
  97. }
  98. // ----------------------------------------------------------------------------