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{
114 // empty
115}
116
134
135//------------------------------------------------------------------------------
138inline void
140{
141 this->type = t;
142}
143
144//------------------------------------------------------------------------------
147inline InputEvent::Type
149{
150 return this->type;
151}
152
153//------------------------------------------------------------------------------
156inline void
158{
159 this->keyCode = key;
160}
161
162//------------------------------------------------------------------------------
165inline Key::Code
167{
168 return this->keyCode;
169}
170
171//------------------------------------------------------------------------------
174inline void
176{
177 this->character = chr;
178}
179
180//------------------------------------------------------------------------------
183inline Char
185{
186 return this->character;
187}
188
189//------------------------------------------------------------------------------
192inline void
197
198//------------------------------------------------------------------------------
203{
204 return this->mouseButton;
205}
206
207//------------------------------------------------------------------------------
210inline void
212{
213 this->absMousePos = p;
214}
215
216//------------------------------------------------------------------------------
219inline const Math::vec2&
221{
222 return this->absMousePos;
223}
224
225//------------------------------------------------------------------------------
228inline void
230{
231 this->normMousePos = p;
232}
233
234//------------------------------------------------------------------------------
237inline const Math::vec2&
239{
240 return this->normMousePos;
241}
242
243//------------------------------------------------------------------------------
246inline void
251
252//------------------------------------------------------------------------------
255inline IndexT
257{
258 return this->deviceIndex;
259}
260
261//------------------------------------------------------------------------------
264inline const char*
266{
267 switch (t)
268 {
269 case InvalidType: return "InvalidTyp";
270 case AppObtainFocus: return "AppObtainFocus";
271 case AppLoseFocus: return "AppLoseFocus";
272 case AppClose: return "AppClose";
273 case Reset: return "Reset";
274 case KeyDown: return "KeyDown";
275 case KeyUp: return "KeyUp";
276 case Character: return "Character";
277 case MouseMove: return "MouseMove";
278 case RawMouseMove: return "RawMouseMove";
279 case MouseButtonDown: return "MouseButtonDown";
280 case MouseButtonUp: return "MouseButtonUp";
281 case MouseButtonDoubleClick: return "MouseButtonDoubleClick";
282 case MouseWheelForward: return "MouseWheelForward";
283 case MouseWheelBackward: return "MouseWheelBackward";
284 case BeginMouseCapture: return "BeginMouseCapture";
285 case EndMouseCapture: return "EndMouseCapture";
286 case BeginKeyboardCapture: return "BeginKeyboardCapture";
287 case EndKeyboardCapture: return "EndKeyboardCapture";
288 case GamePadButtonDown: return "GamePadButtonDown";
289 case GamePadButtonUp: return "GamePadButtonUp";
290 default:
291 n_error("InputEvent::TypeToString(): invalid type!\n");
292 return "<INVALID>";
293 }
294}
295
296} // namespace Input
297//------------------------------------------------------------------------------
298
A translated character code.
void SetDeviceIndex(IndexT i)
set optional device index (e.g. player index for game pads)
Definition inputevent.h:247
void SetKey(Key::Code key)
set key code
Definition inputevent.h:157
void SetAbsMousePos(const Math::vec2 &p)
set absolute pixel mouse position
Definition inputevent.h:211
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:265
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:139
const Math::vec2 & GetNormMousePos() const
get normalized mouse position
Definition inputevent.h:238
const Math::vec2 & GetAbsMousePos() const
get absolute pixel mouse position
Definition inputevent.h:220
void SetNormMousePos(const Math::vec2 &p)
set normalized mouse position
Definition inputevent.h:229
Char GetChar() const
get character code
Definition inputevent.h:184
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:166
InputEvent()
default constructor
Definition inputevent.h:107
Type GetType() const
get event type
Definition inputevent.h:148
MouseButton::Code mouseButton
Definition inputevent.h:97
MouseButton::Code GetMouseButton() const
get button code
Definition inputevent.h:202
IndexT GetDeviceIndex() const
get device index
Definition inputevent.h:256
void SetChar(Char chr)
set character code
Definition inputevent.h:175
Type type
Definition inputevent.h:93
Key::Code keyCode
Definition inputevent.h:94
void SetMouseButton(MouseButton::Code button)
set button code
Definition inputevent.h:193
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