ddnet/src/engine/input.h

99 lines
1.9 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 ENGINE_INPUT_H
#define ENGINE_INPUT_H
#include "kernel.h"
2015-08-24 20:46:28 +00:00
extern const char g_aaKeyStrings[512][20];
2010-05-29 07:25:38 +00:00
class IInput : public IInterface
{
MACRO_INTERFACE("input", 0)
public:
class CEvent
{
public:
int m_Flags;
int m_Key;
2016-04-30 02:02:32 +00:00
char m_aText[32];
2010-05-29 07:25:38 +00:00
};
protected:
enum
{
INPUT_BUFFER_SIZE=32
};
// quick access to events
int m_NumEvents;
IInput::CEvent m_aInputEvents[INPUT_BUFFER_SIZE];
//quick access to input
struct
{
unsigned char m_Presses;
unsigned char m_Releases;
} m_aInputCount[2][1024];
unsigned char m_aInputState[2][1024];
int m_InputCurrent;
2012-05-02 11:53:28 +00:00
bool m_InputDispatched;
2010-05-29 07:25:38 +00:00
public:
2010-05-29 07:25:38 +00:00
enum
{
FLAG_PRESS=1,
FLAG_RELEASE=2,
2016-04-30 02:02:32 +00:00
FLAG_REPEAT=4,
FLAG_TEXT=8,
2010-05-29 07:25:38 +00:00
};
// events
int NumEvents() const { return m_NumEvents; }
2015-07-09 00:08:14 +00:00
void ClearEvents()
{
2012-05-02 11:53:28 +00:00
m_NumEvents = 0;
m_InputDispatched = true;
}
2010-05-29 07:25:38 +00:00
CEvent GetEvent(int Index) const
{
2010-05-29 07:25:38 +00:00
if(Index < 0 || Index >= m_NumEvents)
{
IInput::CEvent e = {0,0};
return e;
}
return m_aInputEvents[Index];
}
2010-05-29 07:25:38 +00:00
// keys
virtual int KeyPressed(int Key) const = 0;
virtual int KeyReleases(int Key) const = 0;
virtual int KeyPresses(int Key) const = 0;
virtual int KeyDown(int Key) const = 0;
2010-05-29 07:25:38 +00:00
const char *KeyName(int Key) { return (Key >= 0 && Key < 512) ? g_aaKeyStrings[Key] : g_aaKeyStrings[0]; }
2010-05-29 07:25:38 +00:00
//
virtual void MouseModeRelative() = 0;
virtual void MouseModeAbsolute() = 0;
virtual int MouseDoubleClick() = 0;
virtual const char* GetClipboardText() = 0;
virtual void SetClipboardText(const char *Text) = 0;
virtual void MouseRelative(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;
virtual int Update() = 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