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
|
|
|
|
2022-03-31 10:44:27 +00:00
|
|
|
char m_aDisplayStr[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:
|
2021-09-16 14:50:17 +00:00
|
|
|
enum ELineInputChanges
|
|
|
|
{
|
|
|
|
// string was changed
|
|
|
|
LINE_INPUT_CHANGE_STRING = 1 << 0,
|
|
|
|
// characters were removed from the string
|
|
|
|
LINE_INPUT_CHANGE_CHARACTERS_DELETE = 1 << 1,
|
|
|
|
// cursor was changed or tried to change(e.g. pressing right at the last char in the string)
|
|
|
|
LINE_INPUT_CHANGE_CURSOR = 1 << 2,
|
|
|
|
LINE_INPUT_CHANGE_WARP_CURSOR = 1 << 3,
|
|
|
|
};
|
|
|
|
enum ELineInputModifyFlags
|
|
|
|
{
|
|
|
|
// don't delete characters
|
|
|
|
LINE_INPUT_MODIFY_DONT_DELETE = 1 << 0,
|
|
|
|
};
|
|
|
|
static int32_t Manipulate(IInput::CEvent e, char *pStr, int StrMaxSize, int StrMaxChars, int *pStrLenPtr, int *pCursorPosPtr, int *pNumCharsPtr, int32_t ModifyFlags, int ModifierKey);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
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);
|
2021-11-24 23:00:20 +00:00
|
|
|
void SetRange(const char *pString, int Begin, int End);
|
2021-11-24 23:04:59 +00:00
|
|
|
void Insert(const char *pString, int Begin);
|
2021-11-24 23:03:35 +00:00
|
|
|
void Append(const char *pString);
|
2022-03-31 10:44:27 +00:00
|
|
|
const char *GetString(bool Editing = false) const { return Editing ? m_aDisplayStr : 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; }
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|