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
17class IInput : public IInterface
18{
20public:
21 class CEvent
22 {
23 public:
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 };
37 {
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
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;
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
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 };
136 {
137 public:
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
203class IEngineInput : public IInput
204{
205 MACRO_INTERFACE("engineinput")
206public:
207 virtual void Init() = 0;
208 virtual void Shutdown() override = 0;
209 virtual int Update() = 0;
210};
211
213
214#endif
Definition: input.h:20
Definition: input.h:204
virtual void Shutdown() override=0
virtual int Update()=0
virtual void Init()=0
Definition: input.h:22
int m_Key
Definition: input.h:25
int m_Flags
Definition: input.h:24
uint32_t m_InputCount
Definition: input.h:26
Definition: input.h:136
std::chrono::nanoseconds m_PressTime
Definition: input.h:157
vec2 m_Delta
Definition: input.h:153
CTouchFinger m_Finger
Definition: input.h:141
vec2 m_Position
Definition: input.h:146
Definition: input.h:122
int64_t m_DeviceId
Definition: input.h:125
bool operator==(const CTouchFinger &Other) const
Definition: input.h:129
int64_t m_FingerId
Definition: input.h:126
bool operator!=(const CTouchFinger &Other) const
Definition: input.h:130
Definition: input.h:89
virtual int GetNumBalls() const =0
virtual const char * GetName() const =0
virtual int GetNumButtons() const =0
virtual bool Absolute(float *pX, float *pY)=0
virtual int GetNumAxes() const =0
virtual bool Relative(float *pX, float *pY)=0
virtual int GetIndex() const =0
virtual int GetNumHats() const =0
virtual void GetHatValue(int Hat, int(&HatKeys)[2])=0
virtual float GetAxisValue(int Axis)=0
Definition: input.h:18
ECursorType
Definition: input.h:37
@ CURSOR_MOUSE
Definition: input.h:39
@ CURSOR_NONE
Definition: input.h:38
@ CURSOR_JOYSTICK
Definition: input.h:40
virtual int GetCompositionLength() const =0
virtual void MouseModeAbsolute()=0
virtual void StopTextInput()=0
virtual int FindKeyByName(const char *pKeyName) const =0
virtual int GetCandidateSelectedIndex() const =0
virtual IJoystick * GetJoystick(size_t Index)=0
virtual int GetCompositionCursor() const =0
virtual int GetCandidateCount() const =0
virtual const char * GetCandidate(int Index) const =0
virtual std::string GetClipboardText()=0
@ FLAG_TEXT
Definition: input.h:34
@ FLAG_RELEASE
Definition: input.h:33
@ FLAG_PRESS
Definition: input.h:32
virtual bool NativeMousePressed(int Index) const =0
virtual vec2 NativeMousePos() const =0
virtual bool AltIsPressed() const =0
virtual bool ShiftIsPressed() const =0
virtual void SetActiveJoystick(size_t Index)=0
virtual void SetClipboardText(const char *pText)=0
virtual size_t NumJoysticks() const =0
virtual void MouseModeRelative()=0
virtual void SetCompositionWindowPosition(float X, float Y, float H)=0
virtual void StartTextInput()=0
virtual void ConsumeEvents(std::function< void(const CEvent &Event)> Consumer) const =0
virtual const std::vector< CTouchFingerState > & TouchFingerStates() const =0
ECursorType CursorRelative(float *pX, float *pY)
Definition: input.h:192
virtual bool KeyIsPressed(int Key) const =0
virtual void Clear()=0
virtual bool MouseRelative(float *pX, float *pY)=0
virtual bool ModifierIsPressed() const =0
virtual const char * GetComposition() const =0
virtual IJoystick * GetActiveJoystick()=0
virtual void ClearTouchDeltas()=0
virtual bool HasComposition() const =0
virtual bool KeyPress(int Key) const =0
virtual const char * KeyName(int Key) const =0
virtual bool GetDropFile(char *aBuf, int Len)=0
virtual float GetUpdateTime() const =0
Definition: kernel.h:10
IEngineInput * CreateEngineInput()
Definition: input.cpp:915
#define MACRO_INTERFACE(Name)
Definition: kernel.h:25