Nui Engine
A game engine framework
Loading...
Searching...
No Matches
InputDevice.h
1#pragma once
2#include "Core/Input/KeyCode.h"
3#include <array>
4
5namespace Nui::Input
6{
7 struct Mouse
8 {
9 constexpr Mouse();
10
11 enum class Button : U32
12 {
13 None = 0,
14
15 Left = MK_LBUTTON, // Can be referenced using 0
16 Right = MK_RBUTTON, // Can be referenced using 1
17 Middle = MK_MBUTTON, // Can be referenced using 2
18 MouseX1 = MK_XBUTTON1, // Can be referenced using 3
19 MouseX2 = MK_XBUTTON2, // Can be referenced using 4
20 };
21
22 static constexpr U32 ConvertMouseButtonToArrayIndex(Mouse::Button btn)
23 {
24 switch (btn)
25 {
26 case Mouse::Button::Left: return 0;
27 case Mouse::Button::Right: return 1;
28 case Mouse::Button::Middle: return 2;
29 case Mouse::Button::MouseX1: return 3;
30 case Mouse::Button::MouseX2: return 4;
31 }
32
33 // Return out of array bounds index
34 return 5;
35 }
36
37 struct Point
38 {
39 constexpr Point(I32 x = 0, I32 y = 0) : X(x), Y(y) {}
40
41 I32 X{ 0 };
42 I32 Y{ 0 };
43 };
44
45 struct WheelInfo
46 {
47 constexpr WheelInfo()
48 : Delta(0)
49 , Modifier(Modifier::MOD_None)
50 , Position()
51 {}
52
53 I32 Delta;
54 Modifier Modifier;
55 Point Position;
56 };
57
59 {
60 constexpr ButtonState(Mouse::Button btn = Mouse::Button::None)
61 : Btn(btn)
62 , Modifier(Modifier::MOD_None)
63 , IsHeld(false)
64 , IsPressed(false)
65 , IsReleased(false)
66 {}
67
68 Button Btn;
69 Modifier Modifier;
70 bool IsHeld;
71 bool IsPressed;
72 bool IsReleased;
73 };
74
75 Point Position;
76 Point RawDelta;
77 WheelInfo WheelH;
78 WheelInfo WheelV;
79 std::array<ButtonState, 5> ButtonStates;
80 };
81
82 struct Keyboard
83 {
84 constexpr Keyboard();
85
86 struct KeyState
87 {
88 constexpr KeyState(KeyCode key = KeyCode::None)
89 : Key(key)
90 , Modifier(Modifier::MOD_None)
91 , IsPressed(false)
92 , IsReleased(false)
93 , IsHeld(false)
94 {}
95
96 KeyCode Key;
97 Modifier Modifier;
98 bool IsPressed;
99 bool IsReleased;
100 bool IsHeld;
101 };
102
103 std::array<KeyState, ConvertKeyCodeToArrayIndex(KeyCode::KEYCODE_COUNT)> KeyStates;
104 };
105
106 // Alias for Mouse::Button
107 using MouseButton = Mouse::Button;
108}
Definition InputDevice.h:87
Definition InputDevice.h:83
Definition InputDevice.h:59
Definition InputDevice.h:38
Definition InputDevice.h:46
Definition InputDevice.h:8