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.

136 lines
4.1 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "vgui_basebudgetpanel.h"
  7. #include "vgui_budgethistorypanel.h"
  8. #include <vgui/ISurface.h>
  9. #include "tier0/vprof.h"
  10. #include "convar.h"
  11. // memdbgon must be the last include file in a .cpp file!!!
  12. #include "tier0/memdbgon.h"
  13. ConVar budget_show_history( "budget_show_history", "1", FCVAR_ARCHIVE, "turn history graph off and on. . good to turn off on low end" );
  14. ConVar budget_history_numsamplesvisible( "budget_history_numsamplesvisible", "100", FCVAR_ARCHIVE, "number of samples to draw in the budget history window. The lower the better as far as rendering overhead of the budget panel" );
  15. CBudgetHistoryPanel::CBudgetHistoryPanel( CBaseBudgetPanel *pParent, const char *pPanelName ) :
  16. BaseClass( pParent, pPanelName )
  17. {
  18. m_pBudgetPanel = pParent;
  19. m_nSamplesPerGroup = 0;
  20. SetProportional( false );
  21. SetKeyBoardInputEnabled( false );
  22. SetMouseInputEnabled( false );
  23. SetVisible( true );
  24. SetPaintBackgroundEnabled( false );
  25. SetBgColor( Color( 0, 0, 0, 255 ) );
  26. // For some reason, vgui::Frame likes to set the minimum size to (128,66) and we may want to get smaller.
  27. SetMinimumSize( 0, 0 );
  28. }
  29. CBudgetHistoryPanel::~CBudgetHistoryPanel()
  30. {
  31. }
  32. void CBudgetHistoryPanel::Paint()
  33. {
  34. if( m_nSamplesPerGroup == 0 )
  35. {
  36. // SetData hasn't been called yet.
  37. return;
  38. }
  39. if( !budget_show_history.GetBool() )
  40. {
  41. return;
  42. }
  43. int width, height;
  44. GetSize( width, height );
  45. int startID = m_nSampleOffset - width;
  46. while( startID < 0 )
  47. {
  48. startID += m_nSamplesPerGroup;
  49. }
  50. int endID = startID + width;
  51. int numSamplesVisible = budget_history_numsamplesvisible.GetInt();
  52. int xOffset = 0;
  53. if( endID - startID > numSamplesVisible )
  54. {
  55. xOffset = ( endID - numSamplesVisible ) - startID;
  56. startID = endID - numSamplesVisible;
  57. }
  58. static CUtlVector<vgui::IntRect> s_Rects;
  59. static CUtlVector<float> s_CurrentHeight;
  60. s_Rects.EnsureCount( ( endID - startID ) );
  61. s_CurrentHeight.EnsureCount( endID - startID );
  62. memset( &s_CurrentHeight[0], 0, sizeof( float ) * ( endID - startID ) );
  63. int j;
  64. float ooRangeMaxMinusMin = 1.0f / ( m_fRangeMax - m_fRangeMin );
  65. for( j = 0; j < m_nGroups; j++ )
  66. {
  67. int i;
  68. for( i = startID; i < endID; i++ )
  69. {
  70. int sampleOffset = i % m_nSamplesPerGroup;
  71. int left = i - startID + xOffset;
  72. int right = left + 1;
  73. float &curHeight = s_CurrentHeight[i - startID];
  74. int bottom = ( curHeight - m_fRangeMin ) * ooRangeMaxMinusMin * height;
  75. curHeight += m_pData[sampleOffset + m_nSamplesPerGroup * j];
  76. int top = ( curHeight - m_fRangeMin ) * ooRangeMaxMinusMin * height;
  77. bottom = height - bottom - 1;
  78. top = height - top - 1;
  79. vgui::IntRect& rect = s_Rects[( i - startID )];
  80. rect.x0 = left;
  81. rect.x1 = right;
  82. rect.y0 = top;
  83. rect.y1 = bottom;
  84. }
  85. int red, green, blue, alpha;
  86. m_pBudgetPanel->GetConfigData().m_BudgetGroupInfo[j].m_Color.GetColor( red, green, blue, alpha );
  87. vgui::surface()->DrawSetColor( red, green, blue, alpha );
  88. vgui::surface()->DrawFilledRectArray( &s_Rects[0], endID - startID );
  89. }
  90. for ( int i=0; i < m_pBudgetPanel->GetConfigData().m_HistoryLabelValues.Count(); i++ )
  91. {
  92. DrawBudgetLine( m_pBudgetPanel->GetConfigData().m_HistoryLabelValues[i] );
  93. }
  94. }
  95. // Only call this from Paint!!!!!
  96. void CBudgetHistoryPanel::DrawBudgetLine( float val )
  97. {
  98. int width, height;
  99. GetSize( width, height );
  100. double y = ( val - m_fRangeMin ) * ( 1.0f / ( m_fRangeMax - m_fRangeMin ) ) * height;
  101. int bottom = ( int )( height - y - 1 + .5 );
  102. int top = ( int )( height - y - 1 - .5 );
  103. vgui::surface()->DrawSetColor( 0, 0, 0, 255 );
  104. vgui::surface()->DrawFilledRect( 0, top-1, width, bottom+1 );
  105. vgui::surface()->DrawSetColor( 255, 255, 255, 255 );
  106. vgui::surface()->DrawFilledRect( 0, top, width, bottom );
  107. }
  108. void CBudgetHistoryPanel::SetData( double *pData, int nGroups, int nSamplesPerGroup, int nSampleOffset )
  109. {
  110. m_pData = pData;
  111. m_nGroups = nGroups;
  112. m_nSamplesPerGroup = nSamplesPerGroup;
  113. m_nSampleOffset = nSampleOffset;
  114. }
  115. void CBudgetHistoryPanel::SetRange( float fMin, float fMax )
  116. {
  117. m_fRangeMin = fMin;
  118. m_fRangeMax = fMax;
  119. }