ddnet/src/game/client/lineinput.h

58 lines
1.8 KiB
C
Raw Normal View History

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
{
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;
char m_DisplayStr[MAX_SIZE + IInput::INPUT_TEXT_SIZE + 2];
int m_FakeLen;
int m_FakeCursorPos;
2010-05-29 07:25:38 +00:00
public:
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);
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);
void Append(const char *pString);
2021-09-13 09:47:47 +00:00
const char *GetString(bool Editing = false) const { return Editing ? m_DisplayStr : m_aStr; }
int GetLength(bool Editing = false) const { return Editing ? m_FakeLen : m_Len; }
int GetCursorOffset(bool Editing = false) const { return Editing ? m_FakeCursorPos : m_CursorPos; }
void SetCursorOffset(int Offset) { m_CursorPos = Offset > m_Len ? m_Len : Offset < 0 ? 0 : Offset; }
2010-05-29 07:25:38 +00:00
};
#endif