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 Reset, // InputServer::Reset() has been called
34 KeyDown, // a key has been pressed
35 KeyUp, // a key has been released
36 Character, // a translated character has been input
37 MouseMove, // mouse has been moved (limited by screen borders)
38 RawMouseMove, // raw mouse movement (not limited by screen borders)
39 MouseButtonDown, // a mouse button has been pressed
40 MouseButtonUp, // a mouse button has been released
41 MouseButtonDoubleClick, // a mouse button has been double-clicked
42 MouseWheelForward, // mouse wheel moved forward
43 MouseWheelBackward, // mouse wheel moved backward
44 BeginMouseCapture, // a mouse input handler begin to capture
45 EndMouseCapture, // a mouse input handler end his capture
46 BeginKeyboardCapture, // a keyboard input handler begin to capture
47 EndKeyboardCapture, // a keyboard input handler end his capture
48
49 GamePadButtonDown, // a game pad button has been pressed
50 GamePadButtonUp, // a game pad button has been released
51 };
52
54 InputEvent();
55
57 void SetType(Type t);
59 Type GetType() const;
61 void SetKey(Key::Code key);
63 Key::Code GetKey() const;
65 void SetChar(Char chr);
67 Char GetChar() const;
73 void SetDeviceIndex(IndexT i);
75 IndexT GetDeviceIndex() const;
77 void SetAbsMousePos(const Math::vec2& p);
79 const Math::vec2& GetAbsMousePos() const;
81 void SetNormMousePos(const Math::vec2& p);
83 const Math::vec2& GetNormMousePos() const;
85 static const char* TypeToString(Type t);
86
87private:
95};
96
97//------------------------------------------------------------------------------
100inline
102 type(InvalidType),
103 keyCode(Key::InvalidKey),
104 character(0),
105 deviceIndex(0),
106 mouseButton(MouseButton::InvalidMouseButton)
107{
108 // empty
109}
110
111//------------------------------------------------------------------------------
114inline void
116{
117 this->type = t;
118}
119
120//------------------------------------------------------------------------------
123inline InputEvent::Type
125{
126 return this->type;
127}
128
129//------------------------------------------------------------------------------
132inline void
134{
135 this->keyCode = key;
136}
137
138//------------------------------------------------------------------------------
141inline Key::Code
143{
144 return this->keyCode;
145}
146
147//------------------------------------------------------------------------------
150inline void
152{
153 this->character = chr;
154}
155
156//------------------------------------------------------------------------------
159inline Char
161{
162 return this->character;
163}
164
165//------------------------------------------------------------------------------
168inline void
173
174//------------------------------------------------------------------------------
179{
180 return this->mouseButton;
181}
182
183//------------------------------------------------------------------------------
186inline void
188{
189 this->absMousePos = p;
190}
191
192//------------------------------------------------------------------------------
195inline const Math::vec2&
197{
198 return this->absMousePos;
199}
200
201//------------------------------------------------------------------------------
204inline void
206{
207 this->normMousePos = p;
208}
209
210//------------------------------------------------------------------------------
213inline const Math::vec2&
215{
216 return this->normMousePos;
217}
218
219//------------------------------------------------------------------------------
222inline void
227
228//------------------------------------------------------------------------------
231inline IndexT
233{
234 return this->deviceIndex;
235}
236
237//------------------------------------------------------------------------------
240inline const char*
242{
243 switch (t)
244 {
245 case InvalidType: return "InvalidTyp";
246 case AppObtainFocus: return "AppObtainFocus";
247 case AppLoseFocus: return "AppLoseFocus";
248 case Reset: return "Reset";
249 case KeyDown: return "KeyDown";
250 case KeyUp: return "KeyUp";
251 case Character: return "Character";
252 case MouseMove: return "MouseMove";
253 case RawMouseMove: return "RawMouseMove";
254 case MouseButtonDown: return "MouseButtonDown";
255 case MouseButtonUp: return "MouseButtonUp";
256 case MouseButtonDoubleClick: return "MouseButtonDoubleClick";
257 case MouseWheelForward: return "MouseWheelForward";
258 case MouseWheelBackward: return "MouseWheelBackward";
259 case BeginMouseCapture: return "BeginMouseCapture";
260 case EndMouseCapture: return "EndMouseCapture";
261 case BeginKeyboardCapture: return "BeginKeyboardCapture";
262 case EndKeyboardCapture: return "EndKeyboardCapture";
263 case GamePadButtonDown: return "GamePadButtonDown";
264 case GamePadButtonUp: return "GamePadButtonUp";
265 default:
266 n_error("InputEvent::TypeToString(): invalid type!\n");
267 return "<INVALID>";
268 }
269}
270
271} // namespace Input
272//------------------------------------------------------------------------------
273
A translated character code.
The input events of the Input subsystems.
Definition inputevent.h:24
void SetDeviceIndex(IndexT i)
set optional device index (e.g. player index for game pads)
Definition inputevent.h:223
void SetKey(Key::Code key)
set key code
Definition inputevent.h:133
void SetAbsMousePos(const Math::vec2 &p)
set absolute pixel mouse position
Definition inputevent.h:187
Math::vec2 absMousePos
Definition inputevent.h:93
IndexT deviceIndex
Definition inputevent.h:91
static const char * TypeToString(Type t)
convert type to string
Definition inputevent.h:241
Math::vec2 normMousePos
Definition inputevent.h:94
const Math::vec2 & GetNormMousePos() const
get normalized mouse position
Definition inputevent.h:214
const Math::vec2 & GetAbsMousePos() const
get absolute pixel mouse position
Definition inputevent.h:196
void SetNormMousePos(const Math::vec2 &p)
set normalized mouse position
Definition inputevent.h:205
Char GetChar() const
get character code
Definition inputevent.h:160
Type
input event types
Definition inputevent.h:28
@ MouseButtonDown
Definition inputevent.h:39
@ InvalidType
Definition inputevent.h:29
@ KeyUp
Definition inputevent.h:35
@ AppLoseFocus
Definition inputevent.h:32
@ MouseMove
Definition inputevent.h:37
@ RawMouseMove
Definition inputevent.h:38
@ BeginKeyboardCapture
Definition inputevent.h:46
@ BeginMouseCapture
Definition inputevent.h:44
@ MouseButtonUp
Definition inputevent.h:40
@ AppObtainFocus
Definition inputevent.h:31
@ Reset
Definition inputevent.h:33
@ MouseWheelForward
Definition inputevent.h:42
@ EndMouseCapture
Definition inputevent.h:45
@ Character
Definition inputevent.h:36
@ GamePadButtonDown
Definition inputevent.h:49
@ MouseButtonDoubleClick
Definition inputevent.h:41
@ GamePadButtonUp
Definition inputevent.h:50
@ MouseWheelBackward
Definition inputevent.h:43
@ KeyDown
Definition inputevent.h:34
@ EndKeyboardCapture
Definition inputevent.h:47
Char character
Definition inputevent.h:90
Key::Code GetKey() const
get key code
Definition inputevent.h:142
InputEvent()
default constructor
Definition inputevent.h:101
Type GetType() const
get event type
Definition inputevent.h:124
MouseButton::Code mouseButton
Definition inputevent.h:92
MouseButton::Code GetMouseButton() const
get button code
Definition inputevent.h:178
IndexT GetDeviceIndex() const
get device index
Definition inputevent.h:232
void SetChar(Char chr)
set character code
Definition inputevent.h:151
Type type
Definition inputevent.h:88
Key::Code keyCode
Definition inputevent.h:89
void SetType(Type t)
set event type
Definition inputevent.h:115
void SetMouseButton(MouseButton::Code button)
set button code
Definition inputevent.h:169
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:48