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 "input/modifier.h"
19#include "math/vec2.h"
20
21//------------------------------------------------------------------------------
22namespace Input
23{
25{
26public:
28 enum Type
29 {
31
32 AppObtainFocus, // application window obtained focus (or minimized, etc)
33 AppLoseFocus, // application window lost focus
34 AppClose, // application window closed
35 Reset, // InputServer::Reset() has been called
36 KeyDown, // a key has been pressed
37 KeyUp, // a key has been released
38 Character, // a translated character has been input
39 MouseMove, // mouse has been moved (limited by screen borders)
40 RawMouseMove, // raw mouse movement (not limited by screen borders)
41 MouseButtonDown, // a mouse button has been pressed
42 MouseButtonUp, // a mouse button has been released
43 MouseButtonDoubleClick, // a mouse button has been double-clicked
44 MouseWheelForward, // mouse wheel moved forward
45 MouseWheelBackward, // mouse wheel moved backward
46 BeginMouseCapture, // a mouse input handler begin to capture
47 EndMouseCapture, // a mouse input handler end his capture
48 BeginKeyboardCapture, // a keyboard input handler begin to capture
49 EndKeyboardCapture, // a keyboard input handler end his capture
50
51 GamePadButtonDown, // a game pad button has been pressed
52 GamePadButtonUp, // a game pad button has been released
53 };
54
56 InputEvent();
57
63 void SetType(Type t);
65 Type GetType() const;
67 void SetKey(Key::Code key);
69 Key::Code GetKey() const;
71 void SetChar(Char chr);
73 Char GetChar() const;
79 void SetGamePadButton(IndexT button);
85 Modifier::Code GetMods() const;
87 void SetDeviceIndex(IndexT i);
89 IndexT GetDeviceIndex() const;
91 void SetAbsMousePos(const Math::vec2& p);
93 const Math::vec2& GetAbsMousePos() const;
95 void SetNormMousePos(const Math::vec2& p);
97 const Math::vec2& GetNormMousePos() const;
99 static const char* TypeToString(Type t);
100
101private:
109 //CoreGraphics::WindowId window;
112};
113
114//------------------------------------------------------------------------------
117inline
120 keyCode(Key::InvalidKey),
121 character(0),
122 deviceIndex(0),
123 mouseButton(MouseButton::InvalidMouseButton),
124 gamepadButton(InvalidIndex),
125 mods(Modifier::NoModifier),
126 absMousePos(0.0f, 0.0f),
127 normMousePos(0.0f, 0.0f)
128{
129 // empty
130}
131
149
150//------------------------------------------------------------------------------
153inline void
155{
156 this->type = t;
157}
158
159//------------------------------------------------------------------------------
162inline InputEvent::Type
164{
165 return this->type;
166}
167
168//------------------------------------------------------------------------------
171inline void
173{
174 this->keyCode = key;
175}
176
177//------------------------------------------------------------------------------
180inline Key::Code
182{
183 return this->keyCode;
184}
185
186//------------------------------------------------------------------------------
189inline void
191{
192 this->character = chr;
193}
194
195//------------------------------------------------------------------------------
198inline Char
200{
201 return this->character;
202}
203
204//------------------------------------------------------------------------------
207inline void
212
213//------------------------------------------------------------------------------
218{
219 return this->mouseButton;
220}
221
222//------------------------------------------------------------------------------
225inline void
227{
228 this->gamepadButton = btn;
229}
230
231//------------------------------------------------------------------------------
234inline IndexT
236{
237 return this->gamepadButton;
238}
239
240//------------------------------------------------------------------------------
243inline void
245{
246 this->mods = mods;
247}
248
249//------------------------------------------------------------------------------
252inline Modifier::Code
254{
255 return this->mods;
256}
257
258//------------------------------------------------------------------------------
261inline void
263{
264 this->absMousePos = p;
265}
266
267//------------------------------------------------------------------------------
270inline const Math::vec2&
272{
273 return this->absMousePos;
274}
275
276//------------------------------------------------------------------------------
279inline void
281{
282 this->normMousePos = p;
283}
284
285//------------------------------------------------------------------------------
288inline const Math::vec2&
290{
291 return this->normMousePos;
292}
293
294//------------------------------------------------------------------------------
297inline void
302
303//------------------------------------------------------------------------------
306inline IndexT
308{
309 return this->deviceIndex;
310}
311
312//------------------------------------------------------------------------------
315inline const char*
317{
318 switch (t)
319 {
320 case InvalidType: return "InvalidTyp";
321 case AppObtainFocus: return "AppObtainFocus";
322 case AppLoseFocus: return "AppLoseFocus";
323 case AppClose: return "AppClose";
324 case Reset: return "Reset";
325 case KeyDown: return "KeyDown";
326 case KeyUp: return "KeyUp";
327 case Character: return "Character";
328 case MouseMove: return "MouseMove";
329 case RawMouseMove: return "RawMouseMove";
330 case MouseButtonDown: return "MouseButtonDown";
331 case MouseButtonUp: return "MouseButtonUp";
332 case MouseButtonDoubleClick: return "MouseButtonDoubleClick";
333 case MouseWheelForward: return "MouseWheelForward";
334 case MouseWheelBackward: return "MouseWheelBackward";
335 case BeginMouseCapture: return "BeginMouseCapture";
336 case EndMouseCapture: return "EndMouseCapture";
337 case BeginKeyboardCapture: return "BeginKeyboardCapture";
338 case EndKeyboardCapture: return "EndKeyboardCapture";
339 case GamePadButtonDown: return "GamePadButtonDown";
340 case GamePadButtonUp: return "GamePadButtonUp";
341 default:
342 n_error("InputEvent::TypeToString(): invalid type!\n");
343 return "<INVALID>";
344 }
345}
346
347} // namespace Input
348//------------------------------------------------------------------------------
A translated character code.
void SetDeviceIndex(IndexT i)
set optional device index (e.g. player index for game pads)
Definition inputevent.h:298
void SetKey(Key::Code key)
set key code
Definition inputevent.h:172
void SetAbsMousePos(const Math::vec2 &p)
set absolute pixel mouse position
Definition inputevent.h:262
Math::vec2 absMousePos
Definition inputevent.h:110
IndexT deviceIndex
Definition inputevent.h:105
static const char * TypeToString(Type t)
convert type to string
Definition inputevent.h:316
Math::vec2 normMousePos
Definition inputevent.h:111
IndexT GetGamePadButton() const
get the game pad button
Definition inputevent.h:235
void SetType(Type t)
Set window void SetWindow(const CoreGraphics::WindowId window); Get window const CoreGraphics::Window...
Definition inputevent.h:154
const Math::vec2 & GetNormMousePos() const
get normalized mouse position
Definition inputevent.h:289
void SetMods(Modifier::Code mods)
set the modifiers held when the event happened
Definition inputevent.h:244
const Math::vec2 & GetAbsMousePos() const
get absolute pixel mouse position
Definition inputevent.h:271
void SetNormMousePos(const Math::vec2 &p)
set normalized mouse position
Definition inputevent.h:280
IndexT gamepadButton
Definition inputevent.h:107
Char GetChar() const
get character code
Definition inputevent.h:199
Type
input event types
Definition inputevent.h:29
@ MouseButtonDown
Definition inputevent.h:41
@ InvalidType
Definition inputevent.h:30
@ KeyUp
Definition inputevent.h:37
@ AppLoseFocus
Definition inputevent.h:33
@ MouseMove
Definition inputevent.h:39
@ RawMouseMove
Definition inputevent.h:40
@ BeginKeyboardCapture
Definition inputevent.h:48
@ AppClose
Definition inputevent.h:34
@ BeginMouseCapture
Definition inputevent.h:46
@ MouseButtonUp
Definition inputevent.h:42
@ AppObtainFocus
Definition inputevent.h:32
@ Reset
Definition inputevent.h:35
@ MouseWheelForward
Definition inputevent.h:44
@ EndMouseCapture
Definition inputevent.h:47
@ Character
Definition inputevent.h:38
@ GamePadButtonDown
Definition inputevent.h:51
@ MouseButtonDoubleClick
Definition inputevent.h:43
@ GamePadButtonUp
Definition inputevent.h:52
@ MouseWheelBackward
Definition inputevent.h:45
@ KeyDown
Definition inputevent.h:36
@ EndKeyboardCapture
Definition inputevent.h:49
Char character
Definition inputevent.h:104
Key::Code GetKey() const
get key code
Definition inputevent.h:181
InputEvent()
default constructor
Definition inputevent.h:118
Type GetType() const
get event type
Definition inputevent.h:163
Modifier::Code GetMods() const
get the modifiers held when the event happened
Definition inputevent.h:253
Modifier::Code mods
Definition inputevent.h:108
void SetGamePadButton(IndexT button)
set the game pad button
Definition inputevent.h:226
MouseButton::Code mouseButton
Definition inputevent.h:106
MouseButton::Code GetMouseButton() const
get button code
Definition inputevent.h:217
IndexT GetDeviceIndex() const
get device index
Definition inputevent.h:307
void SetChar(Char chr)
set character code
Definition inputevent.h:190
Type type
Definition inputevent.h:102
Key::Code keyCode
Definition inputevent.h:103
void SetMouseButton(MouseButton::Code button)
set button code
Definition inputevent.h:208
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
The modifier keys as a bitmask.
Definition modifier.cc:11
uint32_t Code
Definition modifier.h:21
FIXME!
unsigned char Char
Definition char.h:16
A 2-component float vector class.
Definition vec2.h:21
int IndexT
Definition types.h:49