2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2010-05-29 07:25:38 +00:00
|
|
|
#ifndef GAME_CLIENT_LINEINPUT_H
|
|
|
|
#define GAME_CLIENT_LINEINPUT_H
|
|
|
|
|
|
|
|
#include <engine/input.h>
|
|
|
|
|
2019-06-01 13:58:13 +00:00
|
|
|
// line input helper
|
2010-05-29 07:25:38 +00:00
|
|
|
class CLineInput
|
|
|
|
{
|
2013-04-01 18:30:58 +00:00
|
|
|
enum
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
MAX_SIZE = 512,
|
|
|
|
MAX_CHARS = MAX_SIZE / 2,
|
2013-04-01 18:30:58 +00:00
|
|
|
};
|
2021-09-13 09:47:47 +00:00
|
|
|
char m_aStr[MAX_SIZE];
|
2010-05-29 07:25:38 +00:00
|
|
|
int m_Len;
|
|
|
|
int m_CursorPos;
|
2013-04-01 18:30:58 +00:00
|
|
|
int m_NumChars;
|
2016-08-15 05:16:06 +00:00
|
|
|
|
2020-10-25 15:48:12 +00:00
|
|
|
char m_DisplayStr[MAX_SIZE + IInput::INPUT_TEXT_SIZE + 2];
|
2016-08-15 05:16:06 +00:00
|
|
|
int m_FakeLen;
|
|
|
|
int m_FakeCursorPos;
|
2020-09-26 19:41:58 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
public:
|
2013-04-01 18:30:58 +00:00
|
|
|
static bool Manipulate(IInput::CEvent e, char *pStr, int StrMaxSize, int StrMaxChars, int *pStrLenPtr, int *pCursorPosPtr, int *pNumCharsPtr);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
class CCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~CCallback() {}
|
|
|
|
virtual bool Event(IInput::CEvent e) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
CLineInput();
|
|
|
|
void Clear();
|
|
|
|
void ProcessInput(IInput::CEvent e);
|
2016-08-15 05:16:06 +00:00
|
|
|
void Editing(const char *pString, int Cursor);
|
2010-05-29 07:25:38 +00:00
|
|
|
void Set(const char *pString);
|
2015-08-25 12:24:46 +00:00
|
|
|
void Add(const char *pString);
|
2021-09-13 09:47:47 +00:00
|
|
|
const char *GetString(bool Editing = false) const { return Editing ? m_DisplayStr : m_aStr; }
|
2016-08-15 05:16:06 +00:00
|
|
|
int GetLength(bool Editing = false) const { return Editing ? m_FakeLen : m_Len; }
|
|
|
|
int GetCursorOffset(bool Editing = false) const { return Editing ? m_FakeCursorPos : m_CursorPos; }
|
2010-12-16 01:31:12 +00:00
|
|
|
void SetCursorOffset(int Offset) { m_CursorPos = Offset > m_Len ? m_Len : Offset < 0 ? 0 : Offset; }
|
2019-06-01 15:41:40 +00:00
|
|
|
void DeleteUntilCursor();
|
2019-06-18 17:58:59 +00:00
|
|
|
void DeleteFromCursor();
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|