DDraceNetwork Docs
input.h
Go to the documentation of this file.
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
5
6
#include "
kernel.h
"
7
8
#include <
base/types.h
>
9
#include <
base/vmath.h
>
10
11
#include <chrono>
12
#include <cstdint>
13
#include <functional>
14
#include <string>
15
#include <vector>
16
17
class
IInput
:
public
IInterface
18
{
19
MACRO_INTERFACE
(
"input"
)
20
public:
21
class
CEvent
22
{
23
public
:
24
int
m_Flags
;
25
int
m_Key
;
26
uint32_t
m_InputCount
;
27
char
m_aText[32];
// SDL_TEXTINPUTEVENT_TEXT_SIZE
28
};
29
30
enum
31
{
32
FLAG_PRESS
= 1 << 0,
33
FLAG_RELEASE
= 1 << 1,
34
FLAG_TEXT
= 1 << 2,
35
};
36
enum
ECursorType
37
{
38
CURSOR_NONE
,
39
CURSOR_MOUSE
,
40
CURSOR_JOYSTICK
,
41
};
42
43
// events
44
virtual
void
ConsumeEvents
(std::function<
void
(
const
CEvent
&Event)> Consumer)
const
= 0;
48
virtual
void
Clear
() = 0;
49
54
virtual
float
GetUpdateTime
()
const
= 0;
55
56
// keys
57
virtual
bool
ModifierIsPressed
()
const
= 0;
58
virtual
bool
ShiftIsPressed
()
const
= 0;
59
virtual
bool
AltIsPressed
()
const
= 0;
71
virtual
bool
KeyIsPressed
(
int
Key)
const
= 0;
83
virtual
bool
KeyPress
(
int
Key)
const
= 0;
84
virtual
const
char
*
KeyName
(
int
Key)
const
= 0;
85
virtual
int
FindKeyByName
(
const
char
*pKeyName)
const
= 0;
86
87
// joystick
88
class
IJoystick
89
{
90
public
:
91
virtual
int
GetIndex
()
const
= 0;
92
virtual
const
char
*
GetName
()
const
= 0;
93
virtual
int
GetNumAxes
()
const
= 0;
94
virtual
int
GetNumButtons
()
const
= 0;
95
virtual
int
GetNumBalls
()
const
= 0;
96
virtual
int
GetNumHats
()
const
= 0;
97
virtual
float
GetAxisValue
(
int
Axis) = 0;
98
virtual
void
GetHatValue
(
int
Hat,
int
(&HatKeys)[2]) = 0;
99
virtual
bool
Relative
(
float
*pX,
float
*pY) = 0;
100
virtual
bool
Absolute
(
float
*pX,
float
*pY) = 0;
101
};
102
virtual
size_t
NumJoysticks
()
const
= 0;
103
virtual
IJoystick
*
GetJoystick
(
size_t
Index) = 0;
104
virtual
IJoystick
*
GetActiveJoystick
() = 0;
105
virtual
void
SetActiveJoystick
(
size_t
Index) = 0;
106
107
// mouse
108
virtual
vec2
NativeMousePos
()
const
= 0;
109
virtual
bool
NativeMousePressed
(
int
Index)
const
= 0;
110
virtual
void
MouseModeRelative
() = 0;
111
virtual
void
MouseModeAbsolute
() = 0;
112
virtual
bool
MouseRelative
(
float
*pX,
float
*pY) = 0;
113
114
// touch
121
class
CTouchFinger
122
{
123
friend
class
CInput
;
124
125
int64_t
m_DeviceId
;
126
int64_t
m_FingerId
;
127
128
public
:
129
bool
operator==
(
const
CTouchFinger
&Other)
const
{
return
m_DeviceId
== Other.
m_DeviceId
&&
m_FingerId
== Other.
m_FingerId
; }
130
bool
operator!=
(
const
CTouchFinger
&Other)
const
{
return
!(*
this
== Other); }
131
};
135
class
CTouchFingerState
136
{
137
public
:
141
CTouchFinger
m_Finger
;
146
vec2
m_Position
;
153
vec2
m_Delta
;
157
std::chrono::nanoseconds
m_PressTime
;
158
};
166
virtual
const
std::vector<CTouchFingerState> &
TouchFingerStates
()
const
= 0;
172
virtual
void
ClearTouchDeltas
() = 0;
173
174
// clipboard
175
virtual
std::string
GetClipboardText
() = 0;
176
virtual
void
SetClipboardText
(
const
char
*pText) = 0;
177
178
// text editing
179
virtual
void
StartTextInput
() = 0;
180
virtual
void
StopTextInput
() = 0;
181
virtual
const
char
*
GetComposition
()
const
= 0;
182
virtual
bool
HasComposition
()
const
= 0;
183
virtual
int
GetCompositionCursor
()
const
= 0;
184
virtual
int
GetCompositionLength
()
const
= 0;
185
virtual
const
char
*
GetCandidate
(
int
Index)
const
= 0;
186
virtual
int
GetCandidateCount
()
const
= 0;
187
virtual
int
GetCandidateSelectedIndex
()
const
= 0;
188
virtual
void
SetCompositionWindowPosition
(
float
X,
float
Y,
float
H) = 0;
189
190
virtual
bool
GetDropFile
(
char
*aBuf,
int
Len) = 0;
191
192
ECursorType
CursorRelative
(
float
*pX,
float
*pY)
193
{
194
if
(
MouseRelative
(pX, pY))
195
return
CURSOR_MOUSE
;
196
IJoystick
*pJoystick =
GetActiveJoystick
();
197
if
(pJoystick && pJoystick->
Relative
(pX, pY))
198
return
CURSOR_JOYSTICK
;
199
return
CURSOR_NONE
;
200
}
201
};
202
203
class
IEngineInput
:
public
IInput
204
{
205
MACRO_INTERFACE
(
"engineinput"
)
206
public:
207
virtual
void
Init
() = 0;
208
virtual
void
Shutdown
() override = 0;
209
virtual
int
Update
() = 0;
210
};
211
212
extern
IEngineInput
*
CreateEngineInput
();
213
214
#endif
CInput
Definition:
input.h:20
IEngineInput
Definition:
input.h:204
IEngineInput::Shutdown
virtual void Shutdown() override=0
IEngineInput::Update
virtual int Update()=0
IEngineInput::Init
virtual void Init()=0
IInput::CEvent
Definition:
input.h:22
IInput::CEvent::m_Key
int m_Key
Definition:
input.h:25
IInput::CEvent::m_Flags
int m_Flags
Definition:
input.h:24
IInput::CEvent::m_InputCount
uint32_t m_InputCount
Definition:
input.h:26
IInput::CTouchFingerState
Definition:
input.h:136
IInput::CTouchFingerState::m_PressTime
std::chrono::nanoseconds m_PressTime
Definition:
input.h:157
IInput::CTouchFingerState::m_Delta
vec2 m_Delta
Definition:
input.h:153
IInput::CTouchFingerState::m_Finger
CTouchFinger m_Finger
Definition:
input.h:141
IInput::CTouchFingerState::m_Position
vec2 m_Position
Definition:
input.h:146
IInput::CTouchFinger
Definition:
input.h:122
IInput::CTouchFinger::m_DeviceId
int64_t m_DeviceId
Definition:
input.h:125
IInput::CTouchFinger::operator==
bool operator==(const CTouchFinger &Other) const
Definition:
input.h:129
IInput::CTouchFinger::m_FingerId
int64_t m_FingerId
Definition:
input.h:126
IInput::CTouchFinger::operator!=
bool operator!=(const CTouchFinger &Other) const
Definition:
input.h:130
IInput::IJoystick
Definition:
input.h:89
IInput::IJoystick::GetNumBalls
virtual int GetNumBalls() const =0
IInput::IJoystick::GetName
virtual const char * GetName() const =0
IInput::IJoystick::GetNumButtons
virtual int GetNumButtons() const =0
IInput::IJoystick::Absolute
virtual bool Absolute(float *pX, float *pY)=0
IInput::IJoystick::GetNumAxes
virtual int GetNumAxes() const =0
IInput::IJoystick::Relative
virtual bool Relative(float *pX, float *pY)=0
IInput::IJoystick::GetIndex
virtual int GetIndex() const =0
IInput::IJoystick::GetNumHats
virtual int GetNumHats() const =0
IInput::IJoystick::GetHatValue
virtual void GetHatValue(int Hat, int(&HatKeys)[2])=0
IInput::IJoystick::GetAxisValue
virtual float GetAxisValue(int Axis)=0
IInput
Definition:
input.h:18
IInput::ECursorType
ECursorType
Definition:
input.h:37
IInput::CURSOR_MOUSE
@ CURSOR_MOUSE
Definition:
input.h:39
IInput::CURSOR_NONE
@ CURSOR_NONE
Definition:
input.h:38
IInput::CURSOR_JOYSTICK
@ CURSOR_JOYSTICK
Definition:
input.h:40
IInput::GetCompositionLength
virtual int GetCompositionLength() const =0
IInput::MouseModeAbsolute
virtual void MouseModeAbsolute()=0
IInput::StopTextInput
virtual void StopTextInput()=0
IInput::FindKeyByName
virtual int FindKeyByName(const char *pKeyName) const =0
IInput::GetCandidateSelectedIndex
virtual int GetCandidateSelectedIndex() const =0
IInput::GetJoystick
virtual IJoystick * GetJoystick(size_t Index)=0
IInput::GetCompositionCursor
virtual int GetCompositionCursor() const =0
IInput::GetCandidateCount
virtual int GetCandidateCount() const =0
IInput::GetCandidate
virtual const char * GetCandidate(int Index) const =0
IInput::GetClipboardText
virtual std::string GetClipboardText()=0
IInput::FLAG_TEXT
@ FLAG_TEXT
Definition:
input.h:34
IInput::FLAG_RELEASE
@ FLAG_RELEASE
Definition:
input.h:33
IInput::FLAG_PRESS
@ FLAG_PRESS
Definition:
input.h:32
IInput::NativeMousePressed
virtual bool NativeMousePressed(int Index) const =0
IInput::NativeMousePos
virtual vec2 NativeMousePos() const =0
IInput::AltIsPressed
virtual bool AltIsPressed() const =0
IInput::ShiftIsPressed
virtual bool ShiftIsPressed() const =0
IInput::SetActiveJoystick
virtual void SetActiveJoystick(size_t Index)=0
IInput::SetClipboardText
virtual void SetClipboardText(const char *pText)=0
IInput::NumJoysticks
virtual size_t NumJoysticks() const =0
IInput::MouseModeRelative
virtual void MouseModeRelative()=0
IInput::SetCompositionWindowPosition
virtual void SetCompositionWindowPosition(float X, float Y, float H)=0
IInput::StartTextInput
virtual void StartTextInput()=0
IInput::ConsumeEvents
virtual void ConsumeEvents(std::function< void(const CEvent &Event)> Consumer) const =0
IInput::TouchFingerStates
virtual const std::vector< CTouchFingerState > & TouchFingerStates() const =0
IInput::CursorRelative
ECursorType CursorRelative(float *pX, float *pY)
Definition:
input.h:192
IInput::KeyIsPressed
virtual bool KeyIsPressed(int Key) const =0
IInput::Clear
virtual void Clear()=0
IInput::MouseRelative
virtual bool MouseRelative(float *pX, float *pY)=0
IInput::ModifierIsPressed
virtual bool ModifierIsPressed() const =0
IInput::GetComposition
virtual const char * GetComposition() const =0
IInput::GetActiveJoystick
virtual IJoystick * GetActiveJoystick()=0
IInput::ClearTouchDeltas
virtual void ClearTouchDeltas()=0
IInput::HasComposition
virtual bool HasComposition() const =0
IInput::KeyPress
virtual bool KeyPress(int Key) const =0
IInput::KeyName
virtual const char * KeyName(int Key) const =0
IInput::GetDropFile
virtual bool GetDropFile(char *aBuf, int Len)=0
IInput::GetUpdateTime
virtual float GetUpdateTime() const =0
IInterface
Definition:
kernel.h:10
vector2_base< float >
CreateEngineInput
IEngineInput * CreateEngineInput()
Definition:
input.cpp:915
kernel.h
MACRO_INTERFACE
#define MACRO_INTERFACE(Name)
Definition:
kernel.h:25
types.h
vmath.h
src
engine
input.h
Generated by
1.9.4