summaryrefslogtreecommitdiff
path: root/common/vgui/vgui_basebudgetpanel.h
blob: 27115bc612b2bb025c752c74cbd5c39fb9ca1fa8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================//

#ifndef VGUI_BASEBUDGETPANEL_H
#define VGUI_BASEBUDGETPANEL_H

#ifdef _WIN32
#pragma once
#endif


#include <vgui_controls/Frame.h>
#include <vgui/IScheme.h>
#include "vgui_budgethistorypanel.h"
#include "vgui_budgetbargraphpanel.h"
#include "utlsymbol.h"
//#include "hudelement.h"


#define BUDGET_HISTORY_COUNT 1024

class CBudgetGroupInfo
{
public:
	CUtlSymbol m_Name;
	Color m_Color;
};

// Derived classes supply this configuration data with OnConfigDataChanged.
class CBudgetPanelConfigData
{
public:
	// NOTE: nothing can ever be removed from this list once you've called 
	// OnConfigDataChanged. Elements can only be added to it.
	CUtlVector<CBudgetGroupInfo> m_BudgetGroupInfo;

	float m_flHistoryRange;
	float m_flBottomOfHistoryFraction;
	CUtlVector<float> m_HistoryLabelValues;	// A label will be placed at each of these values.

	// How much range the bar graph represents.
	float m_flBarGraphRange;

	// Controls how many labels are shown.
	float m_flTimeLabelInterval;
	int m_nLinesPerTimeLabel;	// How many vertical lines per time label?

	// How translucent is the background.
	float m_flBackgroundAlpha; 

	// Where to position it on the screen.
	int m_xCoord;
	int m_yCoord;
	int m_Width;
	int m_Height;
};


class CBaseBudgetPanel : public vgui::Panel
{
	typedef vgui::Panel BaseClass;

public:
	CBaseBudgetPanel( vgui::Panel *pParent, const char *pElementName );
	~CBaseBudgetPanel();

	// This should be called when starting up and whenever this data changes.
	void OnConfigDataChanged( const CBudgetPanelConfigData &data );

	// Call this to reset everything.
	virtual void ResetAll();

	// The derived class should implement this and set the text in the time labels.
	virtual void SetTimeLabelText() {}
	virtual void SetHistoryLabelText() {}

	virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
	virtual void Paint();
	virtual void PaintBackground();
	virtual void PerformLayout();
	void MarkAsDedicatedServer() { m_bDedicated = true; } // plays nicer as part of a vgui window setup
	bool IsDedicated() const { return m_bDedicated; }

	const double *GetBudgetGroupData( int &nGroups, int &nSamplesPerGroup, int &nSampleOffset ) const;
	
	void GetGraphLabelScreenSpaceTopAndBottom( int id, int &top, int &bottom );

	// What percentage is the specified value of the (bargraph) range?
	float GetBudgetGroupPercent( float value );

	// Get the current config data.
	const CBudgetPanelConfigData& GetConfigData() const;

	// Returns the number of budget groups in the last OnConfigDataChanged call.
	int GetNumCachedBudgetGroups() const;

	// (Used by dedicated server, mark everything for a repaint).
	void MarkForFullRepaint();

protected:
	void UpdateWindowGeometry();
	void ClearTimesForAllGroupsForThisFrame( void );
	void ClearAllTimesForGroup( int groupID );
	void Rebuild( const CBudgetPanelConfigData &data );
	
protected:
	int m_BudgetHistoryOffset;

	// This defines all the positioning, label names, etc.
	CBudgetPanelConfigData m_ConfigData;
	
	CUtlVector<vgui::Label *> m_GraphLabels;
	CUtlVector<vgui::Label *> m_TimeLabels;
	CUtlVector<vgui::Label *> m_HistoryLabels;
	
	CBudgetHistoryPanel *m_pBudgetHistoryPanel;
	CBudgetBarGraphPanel *m_pBudgetBarGraphPanel;

	struct BudgetGroupTimeData_t
	{
		double m_Time[BUDGET_HISTORY_COUNT];
	};
	CUtlVector<BudgetGroupTimeData_t> m_BudgetGroupTimes; // [m_CachedNumBudgetGroups][BUDGET_HISTORY_COUNT]
	int m_CachedNumTimeLabels;
	vgui::HFont		m_hFont;

	bool m_bDedicated;
};


inline const CBudgetPanelConfigData& CBaseBudgetPanel::GetConfigData() const
{
	return m_ConfigData;
}

inline int CBaseBudgetPanel::GetNumCachedBudgetGroups() const
{
	return m_ConfigData.m_BudgetGroupInfo.Count();
}


#endif // VGUI_BASEBUDGETPANEL_H