fixed clipping on some machines
[twcon.git] / src / engine / input.h
blob7d28be101379c73042e0f4e3ceb827181d5a96da
1 /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2 /* If you are missing that file, acquire a complete release at teeworlds.com. */
3 #ifndef ENGINE_INPUT_H
4 #define ENGINE_INPUT_H
6 #include "kernel.h"
8 extern const char g_aaKeyStrings[512][16];
10 class IInput : public IInterface
12 MACRO_INTERFACE("input", 0)
13 public:
14 class CEvent
16 public:
17 int m_Flags;
18 int m_Unicode;
19 int m_Key;
22 protected:
23 enum
25 INPUT_BUFFER_SIZE=32
28 // quick access to events
29 int m_NumEvents;
30 IInput::CEvent m_aInputEvents[INPUT_BUFFER_SIZE];
32 //quick access to input
33 struct
35 unsigned char m_Presses;
36 unsigned char m_Releases;
37 } m_aInputCount[2][1024];
39 unsigned char m_aInputState[2][1024];
40 int m_InputCurrent;
42 int KeyWasPressed(int Key) { return m_aInputState[m_InputCurrent^1][Key]; }
44 public:
45 enum
47 FLAG_PRESS=1,
48 FLAG_RELEASE=2,
49 FLAG_REPEAT=4
52 // events
53 int NumEvents() const { return m_NumEvents; }
54 void ClearEvents() { m_NumEvents = 0; }
55 CEvent GetEvent(int Index) const
57 if(Index < 0 || Index >= m_NumEvents)
59 IInput::CEvent e = {0,0};
60 return e;
62 return m_aInputEvents[Index];
65 // keys
66 int KeyPressed(int Key) { return m_aInputState[m_InputCurrent][Key]; }
67 int KeyReleases(int Key) { return m_aInputCount[m_InputCurrent][Key].m_Releases; }
68 int KeyPresses(int Key) { return m_aInputCount[m_InputCurrent][Key].m_Presses; }
69 int KeyDown(int Key) { return KeyPressed(Key)&&!KeyWasPressed(Key); }
70 const char *KeyName(int Key) { return (Key >= 0 && Key < 512) ? g_aaKeyStrings[Key] : g_aaKeyStrings[0]; }
73 virtual void MouseModeRelative() = 0;
74 virtual void MouseModeAbsolute() = 0;
75 virtual int MouseDoubleClick() = 0;
77 virtual void MouseRelative(float *x, float *y) = 0;
81 class IEngineInput : public IInput
83 MACRO_INTERFACE("engineinput", 0)
84 public:
85 virtual void Init() = 0;
86 virtual int Update() = 0;
89 extern IEngineInput *CreateEngineInput();
91 #endif