Nebula
Loading...
Searching...
No Matches
inputevent.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
14#include "core/types.h"
15#include "input/key.h"
16#include "input/char.h"
17#include "input/mousebutton.h"
18#include "math/vec2.h"
19
20//------------------------------------------------------------------------------
21namespace Input
22{
24{
25public:
27 enum Type
28 {
30
31 AppObtainFocus, // application window obtained focus (or minimized, etc)
32 AppLoseFocus, // application window lost focus
33 AppClose, // application window closed
34 Reset, // InputServer::Reset() has been called
35 KeyDown, // a key has been pressed
36 KeyUp, // a key has been released
37 Character, // a translated character has been input
38 MouseMove, // mouse has been moved (limited by screen borders)
39 RawMouseMove, // raw mouse movement (not limited by screen borders)
40 MouseButtonDown, // a mouse button has been pressed
41 MouseButtonUp, // a mouse button has been released
42 MouseButtonDoubleClick, // a mouse button has been double-clicked
43 MouseWheelForward, // mouse wheel moved forward
44 MouseWheelBackward, // mouse wheel moved backward
45 BeginMouseCapture, // a mouse input handler begin to capture
46 EndMouseCapture, // a mouse input handler end his capture
47 BeginKeyboardCapture, // a keyboard input handler begin to capture
48 EndKeyboardCapture, // a keyboard input handler end his capture
49
50 GamePadButtonDown, // a game pad button has been pressed
51 GamePadButtonUp, // a game pad button has been released
52 };
53
55 InputEvent();
56
58 void SetType(Type t);
60 Type GetType() const;
62 void SetKey(Key::Code key);
64 Key::Code GetKey() const;
66 void SetChar(Char chr);
68 Char GetChar() const;
74 void SetDeviceIndex(IndexT i);
76 IndexT GetDeviceIndex() const;
78 void SetAbsMousePos(const Math::vec2& p);
80 const Math::vec2& GetAbsMousePos() const;
82 void SetNormMousePos(const Math::vec2& p);
84 const Math::vec2& GetNormMousePos() const;
86 static const char* TypeToString(Type t);
87
88private:
96};
97
98//------------------------------------------------------------------------------
101inline
104 keyCode(Key::InvalidKey),
105 character(0),
106 deviceIndex(0),
107 mouseButton(MouseButton::InvalidMouseButton)
108{
109 // empty
110}
111
112//------------------------------------------------------------------------------
115inline void
117{
118 this->type = t;
119}
120
121//------------------------------------------------------------------------------
124inline InputEvent::Type
126{
127 return this->type;
128}
129
130//------------------------------------------------------------------------------
133inline void
135{
136 this->keyCode = key;
137}
138
139//------------------------------------------------------------------------------
142inline Key::Code
144{
145 return this->keyCode;
146}
147
148//------------------------------------------------------------------------------
151inline void
153{
154 this->character = chr;
155}
156
157//------------------------------------------------------------------------------
160inline Char
162{
163 return this->character;
164}
165
166//------------------------------------------------------------------------------
169inline void
174
175//------------------------------------------------------------------------------
180{
181 return this->mouseButton;
182}
183
184//------------------------------------------------------------------------------
187inline void
189{
190 this->absMousePos = p;
191}
192
193//------------------------------------------------------------------------------
196inline const Math::vec2&
198{
199 return this->absMousePos;
200}
201
202//------------------------------------------------------------------------------
205inline void
207{
208 this->normMousePos = p;
209}
210
211//------------------------------------------------------------------------------
214inline const Math::vec2&
216{
217 return this->normMousePos;
218}
219
220//------------------------------------------------------------------------------
223inline void
228
229//------------------------------------------------------------------------------
232inline IndexT
234{
235 return this->deviceIndex;
236}
237
238//------------------------------------------------------------------------------
241inline const char*
243{
244 switch (t)
245 {
246 case InvalidType: return "InvalidTyp";
247 case AppObtainFocus: return "AppObtainFocus";
248 case AppLoseFocus: return "AppLoseFocus";
249 case AppClose: return "AppClose";
250 case Reset: return "Reset";
251 case KeyDown: return "KeyDown";
252 case KeyUp: return "KeyUp";
253 case Character: return "Character";
254 case MouseMove: return "MouseMove";
255 case RawMouseMove: return "RawMouseMove";
256 case MouseButtonDown: return "MouseButtonDown";
257 case MouseButtonUp: return "MouseButtonUp";
258 case MouseButtonDoubleClick: return "MouseButtonDoubleClick";
259 case MouseWheelForward: return "MouseWheelForward";
260 case MouseWheelBackward: return "MouseWheelBackward";
261 case BeginMouseCapture: return "BeginMouseCapture";
262 case EndMouseCapture: return "EndMouseCapture";
263 case BeginKeyboardCapture: return "BeginKeyboardCapture";
264 case EndKeyboardCapture: return "EndKeyboardCapture";
265 case GamePadButtonDown: return "GamePadButtonDown";
266 case GamePadButtonUp: return "GamePadButtonUp";
267 default:
268 n_error("InputEvent::TypeToString(): invalid type!\n");
269 return "<INVALID>";
270 }
271}
272
273} // namespace Input
274//------------------------------------------------------------------------------
275
A translated character code.
void SetDeviceIndex(IndexT i)
set optional device index (e.g. player index for game pads)
Definition inputevent.h:224
void SetKey(Key::Code key)
set key code
Definition inputevent.h:134
void SetAbsMousePos(const Math::vec2 &p)
set absolute pixel mouse position
Definition inputevent.h:188
Math::vec2 absMousePos
Definition inputevent.h:94
IndexT deviceIndex
Definition inputevent.h:92
static const char * TypeToString(Type t)
convert type to string
Definition inputevent.h:242
Math::vec2 normMousePos
Definition inputevent.h:95
const Math::vec2 & GetNormMousePos() const
get normalized mouse position
Definition inputevent.h:215
const Math::vec2 & GetAbsMousePos() const
get absolute pixel mouse position
Definition inputevent.h:197
void SetNormMousePos(const Math::vec2 &p)
set normalized mouse position
Definition inputevent.h:206
Char GetChar() const
get character code
Definition inputevent.h:161
Type
input event types
Definition inputevent.h:28
@ MouseButtonDown
Definition inputevent.h:40
@ InvalidType
Definition inputevent.h:29
@ KeyUp
Definition inputevent.h:36
@ AppLoseFocus
Definition inputevent.h:32
@ MouseMove
Definition inputevent.h:38
@ RawMouseMove
Definition inputevent.h:39
@ BeginKeyboardCapture
Definition inputevent.h:47
@ AppClose
Definition inputevent.h:33
@ BeginMouseCapture
Definition inputevent.h:45
@ MouseButtonUp
Definition inputevent.h:41
@ AppObtainFocus
Definition inputevent.h:31
@ Reset
Definition inputevent.h:34
@ MouseWheelForward
Definition inputevent.h:43
@ EndMouseCapture
Definition inputevent.h:46
@ Character
Definition inputevent.h:37
@ GamePadButtonDown
Definition inputevent.h:50
@ MouseButtonDoubleClick
Definition inputevent.h:42
@ GamePadButtonUp
Definition inputevent.h:51
@ MouseWheelBackward
Definition inputevent.h:44
@ KeyDown
Definition inputevent.h:35
@ EndKeyboardCapture
Definition inputevent.h:48
Char character
Definition inputevent.h:91
Key::Code GetKey() const
get key code
Definition inputevent.h:143
InputEvent()
default constructor
Definition inputevent.h:102
Type GetType() const
get event type
Definition inputevent.h:125
MouseButton::Code mouseButton
Definition inputevent.h:93
MouseButton::Code GetMouseButton() const
get button code
Definition inputevent.h:179
IndexT GetDeviceIndex() const
get device index
Definition inputevent.h:233
void SetChar(Char chr)
set character code
Definition inputevent.h:152
Type type
Definition inputevent.h:89
Key::Code keyCode
Definition inputevent.h:90
void SetType(Type t)
set event type
Definition inputevent.h:116
void SetMouseButton(MouseButton::Code button)
set button code
Definition inputevent.h:170
Define standard key codes.
Definition key.h:21
Code
key codes
Definition key.h:25
Mouse button codes and conversion from/to string.
Definition mousebutton.h:19
Code
code enums
Definition mousebutton.h:23
void __cdecl n_error(const char *msg,...)
This function is called when a serious situation is encountered which requires abortion of the applic...
Definition debug.cc:138
FIXME!
unsigned char Char
Definition char.h:16
A 2-component float vector class.
Definition vec2.h:21
int IndexT
Definition types.h:39