summaryrefslogtreecommitdiff
path: root/engine/vgui_vprofpanel.h
blob: 9eb3d2985a99010da61918e696dcdb5c14d7f384 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//

#ifndef VGUI_VPROFPANEL_H
#define VGUI_VPROFPANEL_H

#ifdef _WIN32
#pragma once
#endif

#include <vgui_controls/TreeViewListControl.h>
#include <vgui_controls/Frame.h>
#include <vgui/IScheme.h>


//-----------------------------------------------------------------------------
// Forward declarations 
//-----------------------------------------------------------------------------
class CVProfNode;
class CVProfile;

class CProfileHierarchyPanel : public vgui::CTreeViewListControl 
{
	DECLARE_CLASS_SIMPLE( CProfileHierarchyPanel, vgui::CTreeViewListControl );

public:

	CProfileHierarchyPanel(vgui::Panel *parent, const char *panelName);
	~CProfileHierarchyPanel();

struct PanelEntry_t
	{
		PanelEntry_t() :
			label( 0 ),
			dataname( UTL_INVAL_SYMBOL )
		{
		}

		vgui::Label		*label;
		CUtlSymbol	dataname;
	};

	struct ColumnPanels_t
	{
		ColumnPanels_t();
		ColumnPanels_t( const ColumnPanels_t& src );
		void AddColumn( int index, char const *name, vgui::Label *label );
		void Refresh( KeyValues *kv );

		int							treeViewItem;
		CUtlVector< PanelEntry_t >	m_Columns;
	};

	virtual void ApplySchemeSettings( vgui::IScheme *pScheme );

	virtual int AddItem( KeyValues *data, int parentItemIndex, ColumnPanels_t& columnPanels );
	virtual void ModifyItem( KeyValues *data, int itemIndex );
	virtual void SetItemColors( int id, const Color& fg, const Color& bg );
	virtual void SetItemColumnColors( int id, int col, const Color& fg, const Color& bg );

	virtual void PerformLayout();

	virtual void RemoveAll();

	virtual void	PostChildPaint();

    virtual void ExpandItem(int itemIndex, bool bExpand);
	virtual bool IsItemExpanded( int itemIndex );

	virtual KeyValues *GetItemData(int itemIndex);

public:

	void	 HideAll();

	

	static bool PanelsLessFunc( const ColumnPanels_t& lhs, const ColumnPanels_t& rhs )
	{
		return lhs.treeViewItem < rhs.treeViewItem;
	}

	CUtlRBTree< ColumnPanels_t, int >	m_Panels;

	vgui::HFont			m_itemFont;
};

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
class CVProfPanel : public vgui::Frame
{
	DECLARE_CLASS_SIMPLE( CVProfPanel, vgui::Frame );

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

	void UpdateProfile( float filteredtime );
	
	// Command handlers
	void UserCmd_ShowVProf( void );
	void UserCmd_HideVProf( void );

	// Inherited from vgui::Frame
	virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
	virtual void Close();
	virtual void Paint();
	virtual void OnTick( void );
	virtual void OnCommand( const char *command );

	void ExpandAll( void );
	void CollapseAll( void );
	void ExpandGroup( const char *pGroupName );
	void Reset();

protected:

	virtual void PerformLayout();

private:
	MESSAGE_FUNC_PARAMS( OnTextChanged, "TextChanged", data );
	MESSAGE_FUNC_PTR( OnCheckButtonChecked, "CheckButtonChecked", panel );

private:
	void AddColumns( CProfileHierarchyPanel::ColumnPanels_t& cp );

	void ExpandGroupRecursive( int nBudgetGroupID, CVProfNode *pNode );
	void FillTree( KeyValues *pKeyValues, CVProfNode *pNode, int parent );
	int UpdateVProfTreeEntry( KeyValues *pKeyValues, CVProfNode *pNode, int parent );

	// Populates the budget group combo box
	void PopulateBudgetGroupComboBox();

private:
	int m_fShowVprofHeld;
	CProfileHierarchyPanel *m_pHierarchy;
	int		m_RootItem;
	vgui::ComboBox *m_pVProfCategory;
	vgui::ComboBox *m_pVProfSort;
	vgui::CheckButton *m_pHierarchicalView;
	vgui::CheckButton *m_pVerbose;
	int m_nLastBudgetGroupCount;
	int m_nCurrentBudgetGroup;
	bool m_bHierarchicalView;


	vgui::Button *m_pStepForward;
	vgui::Button *m_pStepBack;
	vgui::Button *m_pGotoButton;
	vgui::Label *m_pPlaybackLabel;
	vgui::Button	*m_pRedoSort;
	vgui::ScrollBar *m_pPlaybackScroll;

	int m_iLastPlaybackTick;

	CVProfile *m_pVProfile;
};


//-----------------------------------------------------------------------------
// Global accessor
//-----------------------------------------------------------------------------
CVProfPanel *GetVProfPanel();

#endif // VGUI_VPROFPANEL_H