DDraceNetwork Docs
console.h
Go to the documentation of this file.
1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#ifndef GAME_CLIENT_COMPONENTS_CONSOLE_H
4#define GAME_CLIENT_COMPONENTS_CONSOLE_H
5
6#include <base/lock.h>
7
8#include <engine/console.h>
10
13#include <game/client/ui.h>
14
15enum
16{
21};
22
23class CConsoleLogger;
24
26{
27 friend class CConsoleLogger;
29 {
30 public:
32 {
33 float m_YOffset;
36 size_t m_Length;
37 char m_aText[1];
38 };
44
46 const char *m_pName;
47 int m_Type;
51
52 STextBoundingBox m_BoundingBox = {0.0f, 0.0f, 0.0f, 0.0f};
53 float m_LastInputHeight = 0.0f;
54
55 bool m_MouseIsPress = false;
56 vec2 m_MousePress = vec2(0.0f, 0.0f);
57 vec2 m_MouseRelease = vec2(0.0f, 0.0f);
59 int m_CurSelEnd = 0;
60 bool m_HasSelection = false;
62
64
75
76 char m_aUser[32];
79
81 const char *m_pCommandName;
82 const char *m_pCommandHelp;
83 const char *m_pCommandParams;
84
85 bool m_Searching = false;
87 {
88 int m_Pos;
92
93 SSearchMatch(int Pos, int StartLine, int EndLine, int EntryLine) :
94 m_Pos(Pos), m_StartLine(StartLine), m_EndLine(EndLine), m_EntryLine(EntryLine) {}
95 };
98 std::vector<SSearchMatch> m_vSearchMatches;
99
100 CInstance(int t);
101 void Init(CGameConsole *pGameConsole);
102
106 void ClearHistory();
107 void Reset();
108
109 void ExecuteLine(const char *pLine);
110
111 bool OnInput(const IInput::CEvent &Event);
112 void PrintLine(const char *pLine, int Len, ColorRGBA PrintColor) REQUIRES(!m_BacklogPendingLock);
113 int GetLinesToScroll(int Direction, int LinesToScroll);
114 void ScrollToCenter(int StartLine, int EndLine);
115 void ClearSearch();
117
118 const char *GetString() const { return m_Input.GetString(); }
131 void GetCommand(const char *pInput, char (&aCmd)[IConsole::CMDLINE_LENGTH]);
132 static void PossibleCommandsCompleteCallback(int Index, const char *pStr, void *pUser);
133 static void PossibleArgumentsCompleteCallback(int Index, const char *pStr, void *pUser);
134
135 void UpdateEntryTextAttributes(CBacklogEntry *pEntry) const;
136
137 private:
138 void UpdateSearch();
139
140 friend class CGameConsole;
141 };
142
145
148
149 CInstance *ConsoleForType(int ConsoleType);
151
156
159
162
163 static void PossibleCommandsRenderCallback(int Index, const char *pStr, void *pUser);
164 static void ConToggleLocalConsole(IConsole::IResult *pResult, void *pUserData);
165 static void ConToggleRemoteConsole(IConsole::IResult *pResult, void *pUserData);
166 static void ConClearLocalConsole(IConsole::IResult *pResult, void *pUserData);
167 static void ConClearRemoteConsole(IConsole::IResult *pResult, void *pUserData);
168 static void ConDumpLocalConsole(IConsole::IResult *pResult, void *pUserData);
169 static void ConDumpRemoteConsole(IConsole::IResult *pResult, void *pUserData);
170 static void ConConsolePageUp(IConsole::IResult *pResult, void *pUserData);
171 static void ConConsolePageDown(IConsole::IResult *pResult, void *pUserData);
172 static void ConchainConsoleOutputLevel(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
173
174public:
175 enum
176 {
179 };
180
181 CGameConsole();
183 virtual int Sizeof() const override { return sizeof(*this); }
184
185 void PrintLine(int Type, const char *pLine);
186 void RequireUsername(bool UsernameReq);
187
188 virtual void OnStateChange(int NewState, int OldState) override;
189 virtual void OnConsoleInit() override;
190 virtual void OnInit() override;
191 virtual void OnReset() override;
192 virtual void OnRender() override;
193 virtual void OnMessage(int MsgType, void *pRawMsg) override;
194 virtual bool OnInput(const IInput::CEvent &Event) override;
195 void Prompt(char (&aPrompt)[32]);
196
197 void Toggle(int Type);
199};
200#endif
Definition: component.h:20
Definition: console.cpp:35
Definition: console.h:29
int m_BacklogCurLine
Definition: console.h:48
bool m_HasSelection
Definition: console.h:60
int m_CompletionCommandEnd
Definition: console.h:74
int m_CurSelEnd
Definition: console.h:59
const char * m_pCommandHelp
Definition: console.h:82
void ExecuteLine(const char *pLine)
Definition: console.cpp:296
CGameConsole * m_pGameConsole
Definition: console.h:63
void GetCommand(const char *pInput, char(&aCmd)[IConsole::CMDLINE_LENGTH])
Definition: console.cpp:334
bool m_IsCommand
Definition: console.h:80
void UpdateBacklogTextAttributes()
Definition: console.cpp:243
void Dump() REQUIRES(!m_BacklogPendingLock)
Definition: console.cpp:841
void Init(CGameConsole *pGameConsole)
Definition: console.cpp:224
bool m_MouseIsPress
Definition: console.h:55
char m_aCompletionBufferArgument[IConsole::CMDLINE_LENGTH]
Definition: console.h:67
int m_CompletionChosen
Definition: console.h:66
bool m_Searching
Definition: console.h:85
static void PossibleArgumentsCompleteCallback(int Index, const char *pStr, void *pUser)
Definition: console.cpp:360
int m_CompletionChosenArgument
Definition: console.h:68
CStaticRingBuffer< CBacklogEntry, 1024 *1024, CRingBufferBase::FLAG_RECYCLE > m_Backlog
Definition: console.h:39
bool m_UsernameReq
Definition: console.h:78
const char * m_pCommandName
Definition: console.h:81
void UpdateEntryTextAttributes(CBacklogEntry *pEntry) const
Definition: console.cpp:716
const char * m_pCommandParams
Definition: console.h:83
void ClearHistory()
Definition: console.cpp:280
std::vector< SSearchMatch > m_vSearchMatches
Definition: console.h:98
char m_aCompletionBuffer[IConsole::CMDLINE_LENGTH]
Definition: console.h:65
int m_CompletionFlagmask
Definition: console.h:69
int m_CurSelStart
Definition: console.h:58
STextBoundingBox m_BoundingBox
Definition: console.h:52
int m_Type
Definition: console.h:47
int m_NewLineCounter
Definition: console.h:61
const char * m_pName
Definition: console.h:46
CLock m_BacklogPendingLock
Definition: console.h:40
float m_LastInputHeight
Definition: console.h:53
CInstance(int t)
Definition: console.cpp:181
CStaticRingBuffer< char, 64 *1024, CRingBufferBase::FLAG_RECYCLE > m_History
Definition: console.h:42
static void PossibleCommandsCompleteCallback(int Index, const char *pStr, void *pUser)
Definition: console.cpp:320
CStaticRingBuffer< CBacklogEntry, 1024 *1024, CRingBufferBase::FLAG_RECYCLE > m_BacklogPending GUARDED_BY(m_BacklogPendingLock)
bool OnInput(const IInput::CEvent &Event)
Definition: console.cpp:376
void Reset()
Definition: console.cpp:286
void ScrollToCenter(int StartLine, int EndLine)
Definition: console.cpp:696
int m_BacklogLastActiveLine
Definition: console.h:49
vec2 m_MousePress
Definition: console.h:56
char m_aUser[32]
Definition: console.h:76
int m_CurrentMatchIndex
Definition: console.h:96
const char * GetString() const
Definition: console.h:118
int m_CompletionCommandStart
Definition: console.h:73
float m_CompletionRenderOffsetChange
Definition: console.h:71
void UpdateSearch()
Definition: console.cpp:736
char * m_pHistoryEntry
Definition: console.h:43
float m_CompletionRenderOffset
Definition: console.h:70
int GetLinesToScroll(int Direction, int LinesToScroll)
Definition: console.cpp:671
void ClearSearch()
Definition: console.cpp:728
int m_CompletionArgumentPosition
Definition: console.h:72
bool m_UserGot
Definition: console.h:77
vec2 m_MouseRelease
Definition: console.h:57
void PrintLine(const char *pLine, int Len, ColorRGBA PrintColor) REQUIRES(!m_BacklogPendingLock)
Definition: console.cpp:658
void PumpBacklogPending() REQUIRES(!m_BacklogPendingLock)
Definition: console.cpp:252
int m_LinesRendered
Definition: console.h:50
char m_aCurrentSearchString[IConsole::CMDLINE_LENGTH]
Definition: console.h:97
void ClearBacklog() REQUIRES(!m_BacklogPendingLock)
Definition: console.cpp:229
CLineInputBuffered< IConsole::CMDLINE_LENGTH > m_Input
Definition: console.h:45
Definition: console.h:26
void Prompt(char(&aPrompt)[32])
Definition: console.cpp:962
virtual void OnRender() override
Definition: console.cpp:989
virtual void OnInit() override
Definition: console.cpp:1598
static void ConConsolePageDown(IConsole::IResult *pResult, void *pUserData)
Definition: console.cpp:1542
void Toggle(int Type)
Definition: console.cpp:1468
static const ColorRGBA ms_SearchHighlightColor
Definition: console.h:160
virtual bool OnInput(const IInput::CEvent &Event) override
Definition: console.cpp:1449
int m_ConsoleType
Definition: console.h:152
CUi::CTouchState m_TouchState
Definition: console.h:158
virtual int Sizeof() const override
Definition: console.h:183
float m_StateChangeDuration
Definition: console.h:155
CInstance m_RemoteConsole
Definition: console.h:147
CConsoleLogger * m_pConsoleLogger
Definition: console.h:144
~CGameConsole()
Definition: console.cpp:876
static void PossibleCommandsRenderCallback(int Index, const char *pStr, void *pUser)
Definition: console.cpp:917
static void ConClearLocalConsole(IConsole::IResult *pResult, void *pUserData)
Definition: console.cpp:1515
int m_ConsoleState
Definition: console.h:153
static void ConchainConsoleOutputLevel(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
Definition: console.cpp:1551
void PrintLine(int Type, const char *pLine)
Definition: console.cpp:1570
bool IsClosed()
Definition: console.h:198
static void ConToggleRemoteConsole(IConsole::IResult *pResult, void *pUserData)
Definition: console.cpp:1510
@ CONSOLETYPE_LOCAL
Definition: console.h:177
@ CONSOLETYPE_REMOTE
Definition: console.h:178
static const ColorRGBA ms_SearchSelectedColor
Definition: console.h:161
CInstance * ConsoleForType(int ConsoleType)
Definition: console.cpp:882
static void ConDumpLocalConsole(IConsole::IResult *pResult, void *pUserData)
Definition: console.cpp:1525
bool m_WantsSelectionCopy
Definition: console.h:157
float m_StateChangeEnd
Definition: console.h:154
virtual void OnMessage(int MsgType, void *pRawMsg) override
Definition: console.cpp:1445
static void ConConsolePageUp(IConsole::IResult *pResult, void *pUserData)
Definition: console.cpp:1535
CGameConsole()
Definition: console.cpp:865
static void ConDumpRemoteConsole(IConsole::IResult *pResult, void *pUserData)
Definition: console.cpp:1530
class IConsole * m_pConsole
Definition: console.h:143
virtual void OnReset() override
Definition: console.cpp:894
virtual void OnStateChange(int NewState, int OldState) override
Definition: console.cpp:1610
static void ConToggleLocalConsole(IConsole::IResult *pResult, void *pUserData)
Definition: console.cpp:1505
CInstance * CurrentConsole()
Definition: console.cpp:889
CInstance m_LocalConsole
Definition: console.h:146
void RequireUsername(bool UsernameReq)
Definition: console.cpp:1561
virtual void OnConsoleInit() override
Definition: console.cpp:1578
static void ConClearRemoteConsole(IConsole::IResult *pResult, void *pUserData)
Definition: console.cpp:1520
const char * GetString() const
Definition: lineinput.h:133
Definition: lock.h:88
Definition: ringbuffer.h:78
Definition: ui.h:327
Definition: color.h:210
Definition: console.h:45
Definition: console.h:18
void(* FCommandCallback)(IResult *pResult, void *pUserData)
Definition: console.h:92
@ CMDLINE_LENGTH
Definition: console.h:37
Definition: input.h:24
Definition: input.h:20
@ CONSOLE_OPEN
Definition: console.h:19
@ CONSOLE_OPENING
Definition: console.h:18
@ CONSOLE_CLOSING
Definition: console.h:20
@ CONSOLE_CLOSED
Definition: console.h:17
#define REQUIRES(...)
Definition: lock.h:32
float m_YOffset
Definition: console.h:33
int m_LineCount
Definition: console.h:34
size_t m_Length
Definition: console.h:36
ColorRGBA m_PrintColor
Definition: console.h:35
char m_aText[1]
Definition: console.h:37
int m_Pos
Definition: console.h:88
int m_EndLine
Definition: console.h:90
int m_EntryLine
Definition: console.h:91
SSearchMatch(int Pos, int StartLine, int EndLine, int EntryLine)
Definition: console.h:93
int m_StartLine
Definition: console.h:89
Definition: textrender.h:175
vector2_base< float > vec2
Definition: vmath.h:158