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
62 void SetType(Type t);
64 Type GetType() const;
66 void SetKey(Key::Code key);
68 Key::Code GetKey() const;
70 void SetChar(Char chr);
72 Char GetChar() const;
78 void SetDeviceIndex(IndexT i);
80 IndexT GetDeviceIndex() const;
82 void SetAbsMousePos(const Math::vec2& p);
84 const Math::vec2& GetAbsMousePos() const;
86 void SetNormMousePos(const Math::vec2& p);
88 const Math::vec2& GetNormMousePos() const;
90 static const char* TypeToString(Type t);
91
92private:
98 //CoreGraphics::WindowId window;
101};
102
103//------------------------------------------------------------------------------
106inline
109 keyCode(Key::InvalidKey),
110 character(0),
111 deviceIndex(0),
112 mouseButton(MouseButton::InvalidMouseButton),
113 absMousePos(0.0f, 0.0f),
114 normMousePos(0.0f, 0.0f)
115{
116 // empty
117}
118
136
137//------------------------------------------------------------------------------
140inline void
142{
143 this->type = t;
144}
145
146//------------------------------------------------------------------------------
149inline InputEvent::Type
151{
152 return this->type;
153}
154
155//------------------------------------------------------------------------------
158inline void
160{
161 this->keyCode = key;
162}
163
164//------------------------------------------------------------------------------
167inline Key::Code
169{
170 return this->keyCode;
171}
172
173//------------------------------------------------------------------------------
176inline void
178{
179 this->character = chr;
180}
181
182//------------------------------------------------------------------------------
185inline Char
187{
188 return this->character;
189}
190
191//------------------------------------------------------------------------------
194inline void
199
200//------------------------------------------------------------------------------
205{
206 return this->mouseButton;
207}
208
209//------------------------------------------------------------------------------
212inline void
214{
215 this->absMousePos = p;
216}
217
218//------------------------------------------------------------------------------
221inline const Math::vec2&
223{
224 return this->absMousePos;
225}
226
227//------------------------------------------------------------------------------
230inline void
232{
233 this->normMousePos = p;
234}
235
236//------------------------------------------------------------------------------
239inline const Math::vec2&
241{
242 return this->normMousePos;
243}
244
245//------------------------------------------------------------------------------
248inline void
253
254//------------------------------------------------------------------------------
257inline IndexT
259{
260 return this->deviceIndex;
261}
262
263//------------------------------------------------------------------------------
266inline const char*
268{
269 switch (t)
270 {
271 case InvalidType: return "InvalidTyp";
272 case AppObtainFocus: return "AppObtainFocus";
273 case AppLoseFocus: return "AppLoseFocus";
274 case AppClose: return "AppClose";
275 case Reset: return "Reset";
276 case KeyDown: return "KeyDown";
277 case KeyUp: return "KeyUp";
278 case Character: return "Character";
279 case MouseMove: return "MouseMove";
280 case RawMouseMove: return "RawMouseMove";
281 case MouseButtonDown: return "MouseButtonDown";
282 case MouseButtonUp: return "MouseButtonUp";
283 case MouseButtonDoubleClick: return "MouseButtonDoubleClick";
284 case MouseWheelForward: return "MouseWheelForward";
285 case MouseWheelBackward: return "MouseWheelBackward";
286 case BeginMouseCapture: return "BeginMouseCapture";
287 case EndMouseCapture: return "EndMouseCapture";
288 case BeginKeyboardCapture: return "BeginKeyboardCapture";
289 case EndKeyboardCapture: return "EndKeyboardCapture";
290 case GamePadButtonDown: return "GamePadButtonDown";
291 case GamePadButtonUp: return "GamePadButtonUp";
292 default:
293 n_error("InputEvent::TypeToString(): invalid type!\n");
294 return "<INVALID>";
295 }
296}
297
298} // namespace Input
299//------------------------------------------------------------------------------
A translated character code.
void SetDeviceIndex(IndexT i)
set optional device index (e.g. player index for game pads)
Definition inputevent.h:249
void SetKey(Key::Code key)
set key code
Definition inputevent.h:159
void SetAbsMousePos(const Math::vec2 &p)
set absolute pixel mouse position
Definition inputevent.h:213
Math::vec2 absMousePos
Definition inputevent.h:99
IndexT deviceIndex
Definition inputevent.h:96
static const char * TypeToString(Type t)
convert type to string
Definition inputevent.h:267
Math::vec2 normMousePos
Definition inputevent.h:100
void SetType(Type t)
Set window void SetWindow(const CoreGraphics::WindowId window); Get window const CoreGraphics::Window...
Definition inputevent.h:141
const Math::vec2 & GetNormMousePos() const
get normalized mouse position
Definition inputevent.h:240
const Math::vec2 & GetAbsMousePos() const
get absolute pixel mouse position
Definition inputevent.h:222
void SetNormMousePos(const Math::vec2 &p)
set normalized mouse position
Definition inputevent.h:231
Char GetChar() const
get character code
Definition inputevent.h:186
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:95
Key::Code GetKey() const
get key code
Definition inputevent.h:168
InputEvent()
default constructor
Definition inputevent.h:107
Type GetType() const
get event type
Definition inputevent.h:150
MouseButton::Code mouseButton
Definition inputevent.h:97
MouseButton::Code GetMouseButton() const
get button code
Definition inputevent.h:204
IndexT GetDeviceIndex() const
get device index
Definition inputevent.h:258
void SetChar(Char chr)
set character code
Definition inputevent.h:177
Type type
Definition inputevent.h:93
Key::Code keyCode
Definition inputevent.h:94
void SetMouseButton(MouseButton::Code button)
set button code
Definition inputevent.h:195
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:41