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.

175 lines
4.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "BudgetPanelContainer.h"
  7. #include "mathlib/mathlib.h"
  8. #include "vgui/vgui_budgetpanelshared.h"
  9. #include "AdminServer.h"
  10. #include "ivprofexport.h"
  11. #include "vgui/ilocalize.h"
  12. #include "vgui/ISurface.h"
  13. #include "vgui/vgui_BaseBudgetPanel.h"
  14. // -------------------------------------------------------------------------------------------------------------------- //
  15. // CBudgetPanelAdmin declaration.
  16. // -------------------------------------------------------------------------------------------------------------------- //
  17. class CBudgetPanelAdmin : public CBudgetPanelShared
  18. {
  19. typedef CBudgetPanelShared BaseClass;
  20. public:
  21. CBudgetPanelAdmin( vgui::Panel *pParent, const char *pElementName );
  22. virtual void SetupCustomConfigData( CBudgetPanelConfigData &data );
  23. virtual void PostChildPaint();
  24. virtual void OnTick();
  25. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  26. void DrawColoredText(
  27. vgui::HFont font,
  28. int x, int y,
  29. int r, int g, int b, int a,
  30. const char *pText,
  31. ... );
  32. private:
  33. Color m_budgetTextColor;
  34. };
  35. CBudgetPanelAdmin::CBudgetPanelAdmin( vgui::Panel *pParent, const char *pElementName ) :
  36. BaseClass( pParent, pElementName, BUDGETFLAG_SERVER )
  37. {
  38. MarkAsDedicatedServer();
  39. }
  40. void CBudgetPanelAdmin::SetupCustomConfigData( CBudgetPanelConfigData &data )
  41. {
  42. GetBounds( data.m_xCoord, data.m_yCoord, data.m_Width, data.m_Height );
  43. }
  44. void CBudgetPanelAdmin::DrawColoredText(
  45. vgui::HFont font,
  46. int x, int y,
  47. int r, int g, int b, int a,
  48. const char *pText,
  49. ... )
  50. {
  51. char msg[4096];
  52. va_list marker;
  53. va_start( marker, pText );
  54. _vsnprintf( msg, sizeof( msg ), pText, marker );
  55. va_end( marker );
  56. wchar_t unicodeStr[4096];
  57. int nChars = g_pVGuiLocalize->ConvertANSIToUnicode( msg, unicodeStr, sizeof( unicodeStr ) );
  58. vgui::surface()->DrawSetTextFont( font );
  59. vgui::surface()->DrawSetTextColor( r, g, b, a );
  60. vgui::surface()->DrawSetTextPos( x, y );
  61. vgui::surface()->DrawPrintText( unicodeStr, nChars-1 );
  62. }
  63. void CBudgetPanelAdmin::ApplySchemeSettings( vgui::IScheme *pScheme )
  64. {
  65. BaseClass::ApplySchemeSettings( pScheme );
  66. m_budgetTextColor = pScheme->GetColor( "BrightControlText", Color( 0, 255, 0, 255 ) );
  67. }
  68. void CBudgetPanelAdmin::PostChildPaint()
  69. {
  70. DrawColoredText( m_hFont, 0, 0, m_budgetTextColor[0], m_budgetTextColor[1], m_budgetTextColor[2], m_budgetTextColor[3], "%i fps (showbudget 3D driver time included)", RoundFloatToInt(g_fFrameRate) );
  71. DrawColoredText( m_hFont, 0, 16, m_budgetTextColor[0], m_budgetTextColor[1], m_budgetTextColor[2], m_budgetTextColor[3], "%.1f ms", g_fFrameTimeLessBudget*1000.0f );
  72. BaseClass::PostChildPaint();
  73. }
  74. void CBudgetPanelAdmin::OnTick()
  75. {
  76. // Don't do all the work if we're not being drawn.
  77. if ( IsVisible() )
  78. {
  79. SnapshotVProfHistory( 0 );
  80. MarkForFullRepaint();
  81. }
  82. BaseClass::OnTick();
  83. }
  84. // ------------------------------------------------------------------------------------------------------------------------------------------------ //
  85. // The budget panel container class. Just holds CBudgetPanelAdmin.
  86. // ------------------------------------------------------------------------------------------------------------------------------------------------ //
  87. CBudgetPanelContainer::CBudgetPanelContainer(vgui::Panel *parent, const char *name) : PropertyPage(parent, name)
  88. {
  89. LoadControlSettings("Admin/BudgetPanel.res", "PLATFORM");
  90. m_pBudgetPanelAdmin = new CBudgetPanelAdmin( this, "AdminBudgetPanel" );
  91. m_pBudgetPanelAdmin->SetVisible( false );
  92. InvalidateLayout();
  93. }
  94. CBudgetPanelContainer::~CBudgetPanelContainer()
  95. {
  96. }
  97. void CBudgetPanelContainer::OnServerDataResponse( const char *value, const char *response )
  98. {
  99. }
  100. void CBudgetPanelContainer::Paint()
  101. {
  102. }
  103. void CBudgetPanelContainer::PerformLayout()
  104. {
  105. BaseClass::PerformLayout();
  106. int x, y, wide, tall;
  107. GetBounds( x, y, wide, tall );
  108. m_pBudgetPanelAdmin->SetBounds( 12, 12, wide - 24, tall - 24 );
  109. m_pBudgetPanelAdmin->SendConfigDataToBase();
  110. }
  111. //-----------------------------------------------------------------------------
  112. // Purpose: Activates the page
  113. //-----------------------------------------------------------------------------
  114. void CBudgetPanelContainer::OnPageShow()
  115. {
  116. if ( g_pVProfExport )
  117. g_pVProfExport->AddListener();
  118. m_pBudgetPanelAdmin->SetVisible( true );
  119. BaseClass::OnPageShow();
  120. }
  121. //-----------------------------------------------------------------------------
  122. // Purpose: Hides the page
  123. //-----------------------------------------------------------------------------
  124. void CBudgetPanelContainer::OnPageHide()
  125. {
  126. if ( g_pVProfExport )
  127. g_pVProfExport->RemoveListener();
  128. m_pBudgetPanelAdmin->SetVisible( false );
  129. BaseClass::OnPageHide();
  130. }