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 ENGINE_INPUT_H
|
|
|
|
#define ENGINE_INPUT_H
|
|
|
|
|
|
|
|
#include "kernel.h"
|
|
|
|
|
2016-04-30 18:11:26 +00:00
|
|
|
const int g_MaxKeys = 512;
|
|
|
|
extern const char g_aaKeyStrings[g_MaxKeys][20];
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2021-09-15 21:52:09 +00:00
|
|
|
enum EInputMouseMode
|
|
|
|
{
|
|
|
|
// Use absolute mouse mode, doesn't grab the mouse inside the window and uses desktop cursor coordinates
|
|
|
|
INPUT_MOUSE_MODE_ABSOLUTE = 0,
|
|
|
|
// Use relative mouse mode, does grab the mouse inside the window and uses mouse driver coordinates(except if mouse old)
|
|
|
|
INPUT_MOUSE_MODE_RELATIVE,
|
|
|
|
// Use ingame mouse mode, does grab the mouse inside the window, but uses uses desktop cursor coordinates
|
|
|
|
INPUT_MOUSE_MODE_INGAME,
|
|
|
|
// Use ingame mouse mode, does grab the mouse inside the window, but uses uses desktop cursor coordinates, but is relative
|
|
|
|
INPUT_MOUSE_MODE_INGAME_RELATIVE,
|
|
|
|
};
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
class IInput : public IInterface
|
|
|
|
{
|
|
|
|
MACRO_INTERFACE("input", 0)
|
|
|
|
public:
|
2020-10-25 15:48:12 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
INPUT_TEXT_SIZE = 128
|
|
|
|
};
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
class CEvent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int m_Flags;
|
|
|
|
int m_Key;
|
2020-10-25 15:48:12 +00:00
|
|
|
char m_aText[INPUT_TEXT_SIZE];
|
2016-04-30 18:11:26 +00:00
|
|
|
int m_InputCount;
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
enum
|
|
|
|
{
|
2020-09-22 16:02:03 +00:00
|
|
|
INPUT_BUFFER_SIZE = 32
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// quick access to events
|
|
|
|
int m_NumEvents;
|
|
|
|
IInput::CEvent m_aInputEvents[INPUT_BUFFER_SIZE];
|
|
|
|
|
2021-09-15 21:52:09 +00:00
|
|
|
EInputMouseMode m_MouseMode = INPUT_MOUSE_MODE_ABSOLUTE;
|
|
|
|
|
2011-04-13 18:37:12 +00:00
|
|
|
public:
|
2010-05-29 07:25:38 +00:00
|
|
|
enum
|
|
|
|
{
|
2020-09-22 16:02:03 +00:00
|
|
|
FLAG_PRESS = 1,
|
|
|
|
FLAG_RELEASE = 2,
|
|
|
|
FLAG_REPEAT = 4,
|
|
|
|
FLAG_TEXT = 8,
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
2021-09-15 21:52:09 +00:00
|
|
|
EInputMouseMode GetMouseMode() { return m_MouseMode; };
|
|
|
|
void SetMouseMode(EInputMouseMode NewMode) { m_MouseMode = NewMode; };
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// events
|
|
|
|
int NumEvents() const { return m_NumEvents; }
|
2016-04-30 18:11:26 +00:00
|
|
|
virtual bool IsEventValid(CEvent *pEvent) const = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
CEvent GetEvent(int Index) const
|
2011-04-13 18:37:12 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(Index < 0 || Index >= m_NumEvents)
|
|
|
|
{
|
2020-09-22 16:02:03 +00:00
|
|
|
IInput::CEvent e = {0, 0};
|
2010-05-29 07:25:38 +00:00
|
|
|
return e;
|
|
|
|
}
|
|
|
|
return m_aInputEvents[Index];
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2021-05-31 09:43:02 +00:00
|
|
|
CEvent *GetEventsRaw() { return m_aInputEvents; }
|
|
|
|
int *GetEventCountRaw() { return &m_NumEvents; }
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// keys
|
2016-04-30 18:11:26 +00:00
|
|
|
virtual bool KeyIsPressed(int Key) const = 0;
|
2020-09-22 16:02:03 +00:00
|
|
|
virtual bool KeyPress(int Key, bool CheckCounter = false) const = 0;
|
2016-04-30 18:11:26 +00:00
|
|
|
const char *KeyName(int Key) const { return (Key >= 0 && Key < g_MaxKeys) ? g_aaKeyStrings[Key] : g_aaKeyStrings[0]; }
|
|
|
|
virtual void Clear() = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
//
|
2021-09-15 21:52:09 +00:00
|
|
|
virtual void NativeMousePos(int *x, int *y) const = 0;
|
2021-09-12 17:32:00 +00:00
|
|
|
virtual bool NativeMousePressed(int index) = 0;
|
2021-09-15 21:52:09 +00:00
|
|
|
// return true if the mode was changed
|
|
|
|
virtual bool MouseModeRelative() = 0;
|
|
|
|
virtual bool MouseModeAbsolute() = 0;
|
|
|
|
virtual bool MouseModeInGame(int *pDesiredX = NULL, int *pDesiredY = NULL) = 0;
|
|
|
|
virtual bool MouseModeInGameRelative() = 0;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual int MouseDoubleClick() = 0;
|
2020-09-22 16:02:03 +00:00
|
|
|
virtual const char *GetClipboardText() = 0;
|
2015-08-25 12:24:46 +00:00
|
|
|
virtual void SetClipboardText(const char *Text) = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2021-09-15 21:52:09 +00:00
|
|
|
// return true if there was a mouse input
|
|
|
|
virtual bool MouseAbsolute(int *x, int *y) = 0;
|
|
|
|
virtual bool MouseDesktopRelative(int *x, int *y) = 0;
|
|
|
|
virtual bool MouseRelative(float *x, float *y) = 0;
|
2016-08-15 04:01:31 +00:00
|
|
|
|
2016-08-15 05:16:06 +00:00
|
|
|
virtual bool GetIMEState() = 0;
|
2017-07-15 13:25:36 +00:00
|
|
|
virtual void SetIMEState(bool Activate) = 0;
|
2020-10-25 17:44:10 +00:00
|
|
|
virtual int GetIMEEditingTextLength() const = 0;
|
2020-10-25 15:48:12 +00:00
|
|
|
virtual const char *GetIMEEditingText() = 0;
|
2016-08-15 04:01:31 +00:00
|
|
|
virtual int GetEditingCursor() = 0;
|
2020-09-22 16:01:13 +00:00
|
|
|
virtual void SetEditingPosition(float X, float Y) = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class IEngineInput : public IInput
|
|
|
|
{
|
|
|
|
MACRO_INTERFACE("engineinput", 0)
|
|
|
|
public:
|
|
|
|
virtual void Init() = 0;
|
2010-12-11 21:04:50 +00:00
|
|
|
virtual int Update() = 0;
|
2016-04-30 22:18:25 +00:00
|
|
|
virtual void NextFrame() = 0;
|
2014-06-16 11:29:18 +00:00
|
|
|
virtual int VideoRestartNeeded() = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern IEngineInput *CreateEngineInput();
|
|
|
|
|
|
|
|
#endif
|