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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//===========================================================================//
#ifndef CONSOLEDIALOG_H
#define CONSOLEDIALOG_H
#ifdef _WIN32
#pragma once
#endif
#include <Color.h>
#include "tier1/utlvector.h"
#include "vgui_controls/EditablePanel.h"
#include "vgui_controls/Frame.h"
#include "icvar.h"
class ConCommandBase;
namespace vgui
{
// Things the user typed in and hit submit/return with
class CHistoryItem
{
public:
CHistoryItem( void );
CHistoryItem( const char *text, const char *extra = NULL );
CHistoryItem( const CHistoryItem& src );
~CHistoryItem( void );
const char *GetText() const;
const char *GetExtra() const;
void SetText( const char *text, const char *extra );
bool HasExtra() { return m_bHasExtra; }
private:
char *m_text;
char *m_extraText;
bool m_bHasExtra;
};
//-----------------------------------------------------------------------------
// Purpose: Game/dev console dialog
//-----------------------------------------------------------------------------
class CConsolePanel : public vgui::EditablePanel, public IConsoleDisplayFunc
{
DECLARE_CLASS_SIMPLE( CConsolePanel, vgui::EditablePanel );
public:
CConsolePanel( Panel *pParent, const char *pName, bool bStatusVersion );
~CConsolePanel();
// Inherited from IConsoleDisplayFunc
virtual void ColorPrint( const Color& clr, const char *pMessage );
virtual void Print( const char *pMessage );
virtual void DPrint( const char *pMessage );
virtual void GetConsoleText( char *pchText, size_t bufSize ) const;
// clears the console
void Clear();
// writes console to a file
void DumpConsoleTextToFile();
// Hides the console
void Hide();
bool TextEntryHasFocus() const;
void TextEntryRequestFocus();
private:
enum
{
MAX_HISTORY_ITEMS = 100,
};
class CompletionItem
{
public:
CompletionItem( void );
CompletionItem( const CompletionItem& src );
CompletionItem& operator =( const CompletionItem& src );
~CompletionItem( void );
const char *GetItemText( void );
const char *GetCommand( void ) const;
const char *GetName() const;
bool m_bIsCommand;
ConCommandBase *m_pCommand;
CHistoryItem *m_pText;
};
protected:
// methods
void OnAutoComplete(bool reverse);
MESSAGE_FUNC_PTR( OnTextChanged, "TextChanged", panel );
void RebuildCompletionList(const char *partialText);
void UpdateCompletionListPosition();
MESSAGE_FUNC( CloseCompletionList, "CloseCompletionList" );
MESSAGE_FUNC_CHARPTR( OnMenuItemSelected, "CompletionCommand", command );
void ClearCompletionList();
void AddToHistory( const char *commandText, const char *extraText );
// vgui overrides
virtual void PerformLayout();
virtual void ApplySchemeSettings(vgui::IScheme *pScheme);
virtual void OnCommand(const char *command);
virtual void OnKeyCodeTyped(vgui::KeyCode code);
virtual void OnThink();
vgui::RichText *m_pHistory;
vgui::TextEntry *m_pEntry;
vgui::Button *m_pSubmit;
vgui::Menu *m_pCompletionList;
Color m_PrintColor;
Color m_DPrintColor;
int m_iNextCompletion; // the completion that we'll next go to
char m_szPartialText[256];
char m_szPreviousPartialText[256];
bool m_bAutoCompleteMode; // true if the user is currently tabbing through completion options
bool m_bWasBackspacing;
bool m_bStatusVersion;
CUtlVector< CompletionItem * > m_CompletionList;
CUtlVector< CHistoryItem > m_CommandHistory;
friend class CConsoleDialog;
};
class CConsoleDialog : public vgui::Frame
{
DECLARE_CLASS_SIMPLE( CConsoleDialog, vgui::Frame );
public:
CConsoleDialog( vgui::Panel *pParent, const char *pName, bool bStatusVersion );
virtual void OnScreenSizeChanged( int iOldWide, int iOldTall );
virtual void Close();
virtual void PerformLayout();
// brings dialog to the fore
MESSAGE_FUNC( Activate, "Activate" );
MESSAGE_FUNC_CHARPTR( OnCommandSubmitted, "CommandSubmitted", command );
// hides the console
void Hide();
// Chain to the page
void Print( const char *msg );
void DPrint( const char *msg );
void ColorPrint( const Color& clr, const char *msg );
void Clear();
void DumpConsoleTextToFile();
virtual void OnKeyCodePressed( vgui::KeyCode code );
protected:
CConsolePanel *m_pConsolePanel;
};
} // end namespace vgui
#endif // CONSOLEDIALOG_H
|