summaryrefslogtreecommitdiff
path: root/tracker/AdminServer/BudgetPanelContainer.cpp
blob: 8070a7cc9f295a8cb7fe7329e89f15d0ac16c051 (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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================

#include "BudgetPanelContainer.h"
#include "mathlib/mathlib.h"
#include "vgui/vgui_budgetpanelshared.h"
#include "AdminServer.h"
#include "ivprofexport.h"
#include "vgui/ilocalize.h"
#include "vgui/ISurface.h"
#include "vgui/vgui_BaseBudgetPanel.h"


// -------------------------------------------------------------------------------------------------------------------- //
// CBudgetPanelAdmin declaration.
// -------------------------------------------------------------------------------------------------------------------- //

class CBudgetPanelAdmin : public CBudgetPanelShared
{
	typedef CBudgetPanelShared BaseClass;

public:

	CBudgetPanelAdmin( vgui::Panel *pParent, const char *pElementName );

	virtual void SetupCustomConfigData( CBudgetPanelConfigData &data );
	virtual void PostChildPaint();
	virtual void OnTick();
	virtual void ApplySchemeSettings( vgui::IScheme *pScheme );

	void DrawColoredText( 
		vgui::HFont font, 
		int x, int y, 
		int r, int g, int b, int a,
		const char *pText,
		... );

private:
	Color m_budgetTextColor;
};



CBudgetPanelAdmin::CBudgetPanelAdmin( vgui::Panel *pParent, const char *pElementName ) : 
	BaseClass( pParent, pElementName, BUDGETFLAG_SERVER )
{
	MarkAsDedicatedServer();
}


void CBudgetPanelAdmin::SetupCustomConfigData( CBudgetPanelConfigData &data )
{
	GetBounds( data.m_xCoord, data.m_yCoord, data.m_Width, data.m_Height );
}


void CBudgetPanelAdmin::DrawColoredText( 
	vgui::HFont font, 
	int x, int y, 
	int r, int g, int b, int a,
	const char *pText,
	... )
{
	char msg[4096];
	va_list marker;
	va_start( marker, pText );
	_vsnprintf( msg, sizeof( msg ), pText, marker );
	va_end( marker );

	wchar_t unicodeStr[4096];
	int nChars = g_pVGuiLocalize->ConvertANSIToUnicode( msg, unicodeStr, sizeof( unicodeStr ) );

	vgui::surface()->DrawSetTextFont( font );
	vgui::surface()->DrawSetTextColor( r, g, b, a );
	vgui::surface()->DrawSetTextPos( x, y );
	vgui::surface()->DrawPrintText( unicodeStr, nChars-1 );
}


void CBudgetPanelAdmin::ApplySchemeSettings( vgui::IScheme *pScheme )
{
	BaseClass::ApplySchemeSettings( pScheme );
	m_budgetTextColor = pScheme->GetColor( "BrightControlText", Color( 0, 255, 0, 255 ) );
}


void CBudgetPanelAdmin::PostChildPaint()
{
	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) );
	DrawColoredText( m_hFont, 0, 16, m_budgetTextColor[0], m_budgetTextColor[1], m_budgetTextColor[2], m_budgetTextColor[3], "%.1f ms", g_fFrameTimeLessBudget*1000.0f );

	BaseClass::PostChildPaint();
}


void CBudgetPanelAdmin::OnTick()
{
	// Don't do all the work if we're not being drawn.
	if ( IsVisible() )
	{
		SnapshotVProfHistory( 0 );
		MarkForFullRepaint();
	}
	
	BaseClass::OnTick();
}



// ------------------------------------------------------------------------------------------------------------------------------------------------ //
// The budget panel container class. Just holds CBudgetPanelAdmin.
// ------------------------------------------------------------------------------------------------------------------------------------------------ //

CBudgetPanelContainer::CBudgetPanelContainer(vgui::Panel *parent, const char *name) : PropertyPage(parent, name)
{
	LoadControlSettings("Admin/BudgetPanel.res", "PLATFORM");
	m_pBudgetPanelAdmin = new CBudgetPanelAdmin( this, "AdminBudgetPanel" );
	m_pBudgetPanelAdmin->SetVisible( false );
	InvalidateLayout();
}


CBudgetPanelContainer::~CBudgetPanelContainer()
{
}


void CBudgetPanelContainer::OnServerDataResponse( const char *value, const char *response )
{
}


void CBudgetPanelContainer::Paint()
{
	
}


void CBudgetPanelContainer::PerformLayout()
{
	BaseClass::PerformLayout();
	int x, y, wide, tall;
	GetBounds( x, y, wide, tall );
	m_pBudgetPanelAdmin->SetBounds( 12, 12, wide - 24, tall - 24 );
	m_pBudgetPanelAdmin->SendConfigDataToBase();
}


//-----------------------------------------------------------------------------
// Purpose: Activates the page
//-----------------------------------------------------------------------------
void CBudgetPanelContainer::OnPageShow()
{
	if ( g_pVProfExport )
		g_pVProfExport->AddListener();

	m_pBudgetPanelAdmin->SetVisible( true );
	BaseClass::OnPageShow();
}


//-----------------------------------------------------------------------------
// Purpose: Hides the page
//-----------------------------------------------------------------------------
void CBudgetPanelContainer::OnPageHide()
{
	if ( g_pVProfExport )
		g_pVProfExport->RemoveListener();

	m_pBudgetPanelAdmin->SetVisible( false );
	BaseClass::OnPageHide();
}