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.

153 lines
4.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================
  7. #ifndef GRAPHPANEL_H
  8. #define GRAPHPANEL_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include <KeyValues.h>
  13. #include <vgui_controls/Frame.h>
  14. #include <vgui_controls/PHandle.h>
  15. #include <vgui_controls/ListPanel.h>
  16. #include <vgui_controls/PropertyPage.h>
  17. #include <vgui_controls/Image.h>
  18. #include <vgui_controls/ImagePanel.h>
  19. #include <vgui/IScheme.h>
  20. #include "RemoteServer.h"
  21. //-----------------------------------------------------------------------------
  22. // Purpose: Dialog for displaying information about a game server
  23. //-----------------------------------------------------------------------------
  24. class CGraphPanel : public vgui::PropertyPage, public IServerDataResponse
  25. {
  26. DECLARE_CLASS_SIMPLE( CGraphPanel, vgui::PropertyPage );
  27. public:
  28. CGraphPanel(vgui::Panel *parent, const char *name);
  29. ~CGraphPanel();
  30. // property page handlers
  31. virtual void OnPageShow();
  32. virtual void OnPageHide();
  33. void PerformLayout();
  34. protected:
  35. // callback for receiving server data
  36. virtual void OnServerDataResponse(const char *value, const char *response);
  37. // called every frame to update stats page
  38. virtual void OnTick();
  39. private:
  40. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  41. typedef enum { SECONDS, MINUTES, HOURS } intervals;
  42. struct Points_t
  43. {
  44. float cpu; // the percent CPU usage
  45. float in; // the ingoing bandwidth in kB/sec
  46. float out; // the outgoing bandwidth in kB/sec
  47. float time; // the time this was recorded
  48. float fps; // the FPS of the server
  49. float ping; // the ping of the server
  50. float players; // the number of players currently on the server
  51. };
  52. // internal class for holding the graph picture
  53. class CGraphsImage: public vgui::Image
  54. {
  55. public:
  56. CGraphsImage();
  57. using Image::DrawLine;
  58. using Image::SetPos;
  59. bool AddPoint(Points_t p);
  60. void RemovePoints() { points.RemoveAll(); }
  61. void SaveSize(int x1,int y1) { x=x1;y=y1; SetSize(x1,y1);}
  62. void SetDraw(bool cpu_in,bool fps_in,bool net_in,bool net_out,bool ping_in,bool players_in);
  63. void SetScale(intervals time);
  64. void SetBgColor(Color col) { bgColor=col; }
  65. void SetAxisColor(Color col) { lineColor=col; }
  66. // return the pre-defined colors of each graph type
  67. Color GetCPUColor() { return CPUColor; }
  68. Color GetFPSColor() { return FPSColor; }
  69. Color GetInColor() { return NetInColor; }
  70. Color GetOutColor() { return NetOutColor; }
  71. Color GetPlayersColor() { return PlayersColor; }
  72. Color GetPingColor() { return PingColor; }
  73. // return the limits of various graphs
  74. void GetFPSLimits(float &max, float &min) { min=minFPS; max=maxFPS; }
  75. void GetInLimits(float &max, float &min) { min=minIn; max=maxIn; }
  76. void GetOutLimits(float &max, float &min) { min=minOut; max=maxOut; }
  77. void GetPingLimits(float &max, float &min) { min=minPing; max=maxPing; }
  78. void GetPlayerLimits(float &max, float &min) { min=minPlayers; max=maxPlayers; }
  79. virtual void Paint();
  80. private:
  81. void AvgPoint(Points_t p);
  82. void CheckBounds(Points_t p);
  83. CUtlVector<Points_t> points;
  84. int x,y; // the size
  85. float maxIn,minIn,maxOut,minOut; // max and min bandwidths
  86. float maxFPS,minFPS;
  87. float minPing,maxPing;
  88. float maxPlayers,minPlayers;
  89. bool cpu,fps,net_i,ping,net_o,players;
  90. intervals timeBetween;
  91. Points_t avgPoint;
  92. int numAvgs;
  93. Color bgColor,lineColor;
  94. // colors for the various graphs, set in graphpanel.cpp
  95. static Color CPUColor;
  96. static Color FPSColor;
  97. static Color NetInColor;
  98. static Color NetOutColor;
  99. static Color PlayersColor;
  100. static Color PingColor;
  101. };
  102. friend CGraphsImage; // so it can use the intervals enum
  103. vgui::Label *GetLabel(const char *name);
  104. void SetAxisLabels(Color c,char *max,char *mid,char *min);
  105. // msg handlers
  106. MESSAGE_FUNC( OnCheckButton, "CheckButtonChecked" );
  107. MESSAGE_FUNC_PTR_CHARPTR( OnTextChanged, "TextChanged", panel, text );
  108. MESSAGE_FUNC( OnClearButton, "clear" );
  109. // GUI elements
  110. CGraphsImage *m_pGraphs;
  111. vgui::ImagePanel *m_pGraphsPanel;
  112. vgui::Button *m_pClearButton;
  113. vgui::CheckButton *m_pInButton;
  114. vgui::CheckButton *m_pOutButton;
  115. vgui::CheckButton *m_pFPSButton;
  116. vgui::CheckButton *m_pCPUButton;
  117. vgui::CheckButton *m_pPINGButton;
  118. vgui::CheckButton *m_pPlayerButton;
  119. vgui::ComboBox *m_pTimeCombo;
  120. vgui::ComboBox *m_pVertCombo;
  121. float m_flNextStatsUpdateTime;
  122. };
  123. #endif // GRAPHPANEL_H