matf-rg-engine
1.0.0
Base for project for the Computer Graphics course at Faculty of Mathematics, University of Belgrade
engine
include
engine
platform
Input.hpp
Go to the documentation of this file.
1
6
#ifndef INPUT_HPP
7
#define INPUT_HPP
8
#include <string_view>
9
10
namespace
engine::platform
{
14
enum
KeyId
{
15
MOUSE_BUTTON_1
= 0,
16
MOUSE_BUTTON_2
,
17
MOUSE_BUTTON_3
,
18
MOUSE_BUTTON_4
,
19
MOUSE_BUTTON_5
,
20
MOUSE_BUTTON_6
,
21
MOUSE_BUTTON_7
,
22
MOUSE_BUTTON_8
,
23
MOUSE_BUTTON_LAST
,
24
MOUSE_BUTTON_LEFT
,
25
MOUSE_BUTTON_RIGHT
,
26
MOUSE_BUTTON_MIDDLE
,
27
KEY_SPACE
,
28
KEY_APOSTROPHE
,
29
KEY_COMMA
,
30
KEY_MINUS
,
31
KEY_PERIOD
,
32
KEY_SLASH
,
33
KEY_0
,
34
KEY_1
,
35
KEY_2
,
36
KEY_3
,
37
KEY_4
,
38
KEY_5
,
39
KEY_6
,
40
KEY_7
,
41
KEY_8
,
42
KEY_9
,
43
KEY_SEMICOLON
,
44
KEY_EQUAL
,
45
KEY_A
,
46
KEY_B
,
47
KEY_C
,
48
KEY_D
,
49
KEY_E
,
50
KEY_F
,
51
KEY_G
,
52
KEY_H
,
53
KEY_I
,
54
KEY_J
,
55
KEY_K
,
56
KEY_L
,
57
KEY_M
,
58
KEY_N
,
59
KEY_O
,
60
KEY_P
,
61
KEY_Q
,
62
KEY_R
,
63
KEY_S
,
64
KEY_T
,
65
KEY_U
,
66
KEY_V
,
67
KEY_W
,
68
KEY_X
,
69
KEY_Y
,
70
KEY_Z
,
71
KEY_LEFT_BRACKET
,
72
KEY_BACKSLASH
,
73
KEY_RIGHT_BRACKET
,
74
KEY_GRAVE_ACCENT
,
75
KEY_WORLD_1
,
76
KEY_WORLD_2
,
77
KEY_ESCAPE
,
78
KEY_ENTER
,
79
KEY_TAB
,
80
KEY_BACKSPACE
,
81
KEY_INSERT
,
82
KEY_DELETE
,
83
KEY_RIGHT
,
84
KEY_LEFT
,
85
KEY_DOWN
,
86
KEY_UP
,
87
KEY_PAGE_UP
,
88
KEY_PAGE_DOWN
,
89
KEY_HOME
,
90
KEY_END
,
91
KEY_CAPS_LOCK
,
92
KEY_SCROLL_LOCK
,
93
KEY_NUM_LOCK
,
94
KEY_PRINT_SCREEN
,
95
KEY_PAUSE
,
96
KEY_F1
,
97
KEY_F2
,
98
KEY_F3
,
99
KEY_F4
,
100
KEY_F5
,
101
KEY_F6
,
102
KEY_F7
,
103
KEY_F8
,
104
KEY_F9
,
105
KEY_F10
,
106
KEY_F11
,
107
KEY_F12
,
108
KEY_F13
,
109
KEY_F14
,
110
KEY_F15
,
111
KEY_F16
,
112
KEY_F17
,
113
KEY_F18
,
114
KEY_F19
,
115
KEY_F20
,
116
KEY_F21
,
117
KEY_F22
,
118
KEY_F23
,
119
KEY_F24
,
120
KEY_F25
,
121
KEY_KP_0
,
122
KEY_KP_1
,
123
KEY_KP_2
,
124
KEY_KP_3
,
125
KEY_KP_4
,
126
KEY_KP_5
,
127
KEY_KP_6
,
128
KEY_KP_7
,
129
KEY_KP_8
,
130
KEY_KP_9
,
131
KEY_KP_DECIMAL
,
132
KEY_KP_DIVIDE
,
133
KEY_KP_MULTIPLY
,
134
KEY_KP_SUBTRACT
,
135
KEY_KP_ADD
,
136
KEY_KP_ENTER
,
137
KEY_KP_EQUAL
,
138
KEY_LEFT_SHIFT
,
139
KEY_LEFT_CONTROL
,
140
KEY_LEFT_ALT
,
141
KEY_LEFT_SUPER
,
142
KEY_RIGHT_SHIFT
,
143
KEY_RIGHT_CONTROL
,
144
KEY_RIGHT_ALT
,
145
KEY_RIGHT_SUPER
,
146
KEY_MENU
,
147
KEY_COUNT
,
148
};
149
154
class
Key
final {
155
friend
class
PlatformController
;
156
157
public
:
161
enum class
State
{
165
Released
,
170
JustPressed
,
176
Pressed
,
181
JustReleased
182
};
183
187
State
&
state
() {
188
return
m_state
;
189
}
190
194
KeyId
id
()
const
{
195
return
m_key
;
196
}
197
201
std::string_view
name
();
202
203
State
state
()
const
{
204
return
m_state
;
205
}
206
210
std::string_view
state_str
()
const
;
211
216
bool
is_down
()
const
{
217
return
(
m_state
==
State::Pressed
||
m_state
==
State::JustPressed
);
218
}
219
224
bool
is_up
()
const
{
225
return
(
m_state
==
State::Released
||
m_state
==
State::JustReleased
);
226
}
227
228
private
:
229
KeyId
m_key
=
KEY_COUNT
;
230
State
m_state
=
State::Released
;
231
};
232
237
struct
MousePosition
{
241
float
x
;
245
float
y
;
249
float
dx
;
253
float
dy
;
254
258
float
scroll
;
259
};
260
}
261
#endif
//INPUT_HPP
engine::platform::Key
Represents the state of the key in a given frame.
Definition:
Input.hpp:154
engine::platform::Key::id
KeyId id() const
Definition:
Input.hpp:194
engine::platform::Key::is_up
bool is_up() const
Shorthand method for checking whether the key is up.
Definition:
Input.hpp:224
engine::platform::Key::m_key
KeyId m_key
Definition:
Input.hpp:229
engine::platform::Key::state
State state() const
Definition:
Input.hpp:203
engine::platform::Key::name
std::string_view name()
Definition:
PlatformController.cpp:159
engine::platform::Key::State
State
The state of the key with regard to whether it is pressed or not.
Definition:
Input.hpp:161
engine::platform::Key::State::JustReleased
@ JustReleased
Lasts only for the frame in which the key was released. In the next frame, if the key is not pressed ...
engine::platform::Key::State::JustPressed
@ JustPressed
The key has just been pressed in the current frame. This state only lasts for the frame in which the ...
engine::platform::Key::State::Pressed
@ Pressed
The key is being held down. If the key was JustPressed in the previous frame, and it is still down in...
engine::platform::Key::State::Released
@ Released
The key is up.
engine::platform::Key::state_str
std::string_view state_str() const
Definition:
PlatformController.cpp:163
engine::platform::Key::is_down
bool is_down() const
Shorthand method for checking whether the key is down.
Definition:
Input.hpp:216
engine::platform::Key::m_state
State m_state
Definition:
Input.hpp:230
engine::platform::Key::state
State & state()
Definition:
Input.hpp:187
engine::platform::PlatformController
Registers Platform events such as mouse movement, key press, window events...
Definition:
PlatformController.hpp:45
engine::platform
Definition:
Input.hpp:10
engine::platform::KeyId
KeyId
All the Keys that the engine can register.
Definition:
Input.hpp:14
engine::platform::MOUSE_BUTTON_LEFT
@ MOUSE_BUTTON_LEFT
Definition:
Input.hpp:24
engine::platform::KEY_KP_7
@ KEY_KP_7
Definition:
Input.hpp:128
engine::platform::KEY_F7
@ KEY_F7
Definition:
Input.hpp:102
engine::platform::KEY_DOWN
@ KEY_DOWN
Definition:
Input.hpp:85
engine::platform::KEY_LEFT_BRACKET
@ KEY_LEFT_BRACKET
Definition:
Input.hpp:71
engine::platform::KEY_F23
@ KEY_F23
Definition:
Input.hpp:118
engine::platform::KEY_Q
@ KEY_Q
Definition:
Input.hpp:61
engine::platform::KEY_F25
@ KEY_F25
Definition:
Input.hpp:120
engine::platform::KEY_D
@ KEY_D
Definition:
Input.hpp:48
engine::platform::KEY_KP_MULTIPLY
@ KEY_KP_MULTIPLY
Definition:
Input.hpp:133
engine::platform::KEY_F1
@ KEY_F1
Definition:
Input.hpp:96
engine::platform::KEY_R
@ KEY_R
Definition:
Input.hpp:62
engine::platform::KEY_F11
@ KEY_F11
Definition:
Input.hpp:106
engine::platform::KEY_ENTER
@ KEY_ENTER
Definition:
Input.hpp:78
engine::platform::KEY_X
@ KEY_X
Definition:
Input.hpp:68
engine::platform::KEY_KP_ADD
@ KEY_KP_ADD
Definition:
Input.hpp:135
engine::platform::KEY_KP_3
@ KEY_KP_3
Definition:
Input.hpp:124
engine::platform::KEY_PRINT_SCREEN
@ KEY_PRINT_SCREEN
Definition:
Input.hpp:94
engine::platform::KEY_KP_DECIMAL
@ KEY_KP_DECIMAL
Definition:
Input.hpp:131
engine::platform::KEY_KP_1
@ KEY_KP_1
Definition:
Input.hpp:122
engine::platform::MOUSE_BUTTON_MIDDLE
@ MOUSE_BUTTON_MIDDLE
Definition:
Input.hpp:26
engine::platform::KEY_PERIOD
@ KEY_PERIOD
Definition:
Input.hpp:31
engine::platform::KEY_F15
@ KEY_F15
Definition:
Input.hpp:110
engine::platform::KEY_W
@ KEY_W
Definition:
Input.hpp:67
engine::platform::KEY_F19
@ KEY_F19
Definition:
Input.hpp:114
engine::platform::KEY_F2
@ KEY_F2
Definition:
Input.hpp:97
engine::platform::KEY_RIGHT_ALT
@ KEY_RIGHT_ALT
Definition:
Input.hpp:144
engine::platform::KEY_7
@ KEY_7
Definition:
Input.hpp:40
engine::platform::KEY_4
@ KEY_4
Definition:
Input.hpp:37
engine::platform::KEY_F14
@ KEY_F14
Definition:
Input.hpp:109
engine::platform::KEY_LEFT
@ KEY_LEFT
Definition:
Input.hpp:84
engine::platform::KEY_WORLD_1
@ KEY_WORLD_1
Definition:
Input.hpp:75
engine::platform::KEY_PAUSE
@ KEY_PAUSE
Definition:
Input.hpp:95
engine::platform::KEY_RIGHT
@ KEY_RIGHT
Definition:
Input.hpp:83
engine::platform::KEY_KP_DIVIDE
@ KEY_KP_DIVIDE
Definition:
Input.hpp:132
engine::platform::KEY_RIGHT_SHIFT
@ KEY_RIGHT_SHIFT
Definition:
Input.hpp:142
engine::platform::MOUSE_BUTTON_1
@ MOUSE_BUTTON_1
Definition:
Input.hpp:15
engine::platform::KEY_HOME
@ KEY_HOME
Definition:
Input.hpp:89
engine::platform::MOUSE_BUTTON_RIGHT
@ MOUSE_BUTTON_RIGHT
Definition:
Input.hpp:25
engine::platform::KEY_DELETE
@ KEY_DELETE
Definition:
Input.hpp:82
engine::platform::KEY_LEFT_CONTROL
@ KEY_LEFT_CONTROL
Definition:
Input.hpp:139
engine::platform::KEY_WORLD_2
@ KEY_WORLD_2
Definition:
Input.hpp:76
engine::platform::KEY_SPACE
@ KEY_SPACE
Definition:
Input.hpp:27
engine::platform::KEY_APOSTROPHE
@ KEY_APOSTROPHE
Definition:
Input.hpp:28
engine::platform::KEY_F20
@ KEY_F20
Definition:
Input.hpp:115
engine::platform::KEY_KP_2
@ KEY_KP_2
Definition:
Input.hpp:123
engine::platform::KEY_KP_4
@ KEY_KP_4
Definition:
Input.hpp:125
engine::platform::KEY_8
@ KEY_8
Definition:
Input.hpp:41
engine::platform::KEY_S
@ KEY_S
Definition:
Input.hpp:63
engine::platform::KEY_B
@ KEY_B
Definition:
Input.hpp:46
engine::platform::KEY_F17
@ KEY_F17
Definition:
Input.hpp:112
engine::platform::KEY_F3
@ KEY_F3
Definition:
Input.hpp:98
engine::platform::KEY_K
@ KEY_K
Definition:
Input.hpp:55
engine::platform::KEY_KP_5
@ KEY_KP_5
Definition:
Input.hpp:126
engine::platform::KEY_F6
@ KEY_F6
Definition:
Input.hpp:101
engine::platform::KEY_KP_EQUAL
@ KEY_KP_EQUAL
Definition:
Input.hpp:137
engine::platform::KEY_LEFT_SUPER
@ KEY_LEFT_SUPER
Definition:
Input.hpp:141
engine::platform::KEY_RIGHT_SUPER
@ KEY_RIGHT_SUPER
Definition:
Input.hpp:145
engine::platform::KEY_J
@ KEY_J
Definition:
Input.hpp:54
engine::platform::KEY_F12
@ KEY_F12
Definition:
Input.hpp:107
engine::platform::KEY_F9
@ KEY_F9
Definition:
Input.hpp:104
engine::platform::KEY_Z
@ KEY_Z
Definition:
Input.hpp:70
engine::platform::KEY_SCROLL_LOCK
@ KEY_SCROLL_LOCK
Definition:
Input.hpp:92
engine::platform::MOUSE_BUTTON_7
@ MOUSE_BUTTON_7
Definition:
Input.hpp:21
engine::platform::KEY_MINUS
@ KEY_MINUS
Definition:
Input.hpp:30
engine::platform::KEY_CAPS_LOCK
@ KEY_CAPS_LOCK
Definition:
Input.hpp:91
engine::platform::KEY_T
@ KEY_T
Definition:
Input.hpp:64
engine::platform::KEY_PAGE_DOWN
@ KEY_PAGE_DOWN
Definition:
Input.hpp:88
engine::platform::KEY_EQUAL
@ KEY_EQUAL
Definition:
Input.hpp:44
engine::platform::MOUSE_BUTTON_3
@ MOUSE_BUTTON_3
Definition:
Input.hpp:17
engine::platform::KEY_COUNT
@ KEY_COUNT
Definition:
Input.hpp:147
engine::platform::KEY_F24
@ KEY_F24
Definition:
Input.hpp:119
engine::platform::KEY_KP_6
@ KEY_KP_6
Definition:
Input.hpp:127
engine::platform::KEY_A
@ KEY_A
Definition:
Input.hpp:45
engine::platform::KEY_LEFT_SHIFT
@ KEY_LEFT_SHIFT
Definition:
Input.hpp:138
engine::platform::KEY_E
@ KEY_E
Definition:
Input.hpp:49
engine::platform::KEY_F
@ KEY_F
Definition:
Input.hpp:50
engine::platform::KEY_V
@ KEY_V
Definition:
Input.hpp:66
engine::platform::KEY_F16
@ KEY_F16
Definition:
Input.hpp:111
engine::platform::KEY_P
@ KEY_P
Definition:
Input.hpp:60
engine::platform::KEY_L
@ KEY_L
Definition:
Input.hpp:56
engine::platform::KEY_INSERT
@ KEY_INSERT
Definition:
Input.hpp:81
engine::platform::KEY_COMMA
@ KEY_COMMA
Definition:
Input.hpp:29
engine::platform::KEY_ESCAPE
@ KEY_ESCAPE
Definition:
Input.hpp:77
engine::platform::KEY_N
@ KEY_N
Definition:
Input.hpp:58
engine::platform::KEY_M
@ KEY_M
Definition:
Input.hpp:57
engine::platform::KEY_NUM_LOCK
@ KEY_NUM_LOCK
Definition:
Input.hpp:93
engine::platform::KEY_UP
@ KEY_UP
Definition:
Input.hpp:86
engine::platform::KEY_9
@ KEY_9
Definition:
Input.hpp:42
engine::platform::MOUSE_BUTTON_4
@ MOUSE_BUTTON_4
Definition:
Input.hpp:18
engine::platform::KEY_KP_8
@ KEY_KP_8
Definition:
Input.hpp:129
engine::platform::KEY_KP_SUBTRACT
@ KEY_KP_SUBTRACT
Definition:
Input.hpp:134
engine::platform::KEY_SLASH
@ KEY_SLASH
Definition:
Input.hpp:32
engine::platform::KEY_C
@ KEY_C
Definition:
Input.hpp:47
engine::platform::KEY_GRAVE_ACCENT
@ KEY_GRAVE_ACCENT
Definition:
Input.hpp:74
engine::platform::KEY_F18
@ KEY_F18
Definition:
Input.hpp:113
engine::platform::KEY_KP_9
@ KEY_KP_9
Definition:
Input.hpp:130
engine::platform::KEY_BACKSPACE
@ KEY_BACKSPACE
Definition:
Input.hpp:80
engine::platform::KEY_3
@ KEY_3
Definition:
Input.hpp:36
engine::platform::KEY_1
@ KEY_1
Definition:
Input.hpp:34
engine::platform::MOUSE_BUTTON_6
@ MOUSE_BUTTON_6
Definition:
Input.hpp:20
engine::platform::KEY_2
@ KEY_2
Definition:
Input.hpp:35
engine::platform::KEY_5
@ KEY_5
Definition:
Input.hpp:38
engine::platform::KEY_BACKSLASH
@ KEY_BACKSLASH
Definition:
Input.hpp:72
engine::platform::MOUSE_BUTTON_8
@ MOUSE_BUTTON_8
Definition:
Input.hpp:22
engine::platform::KEY_RIGHT_CONTROL
@ KEY_RIGHT_CONTROL
Definition:
Input.hpp:143
engine::platform::KEY_G
@ KEY_G
Definition:
Input.hpp:51
engine::platform::KEY_O
@ KEY_O
Definition:
Input.hpp:59
engine::platform::KEY_MENU
@ KEY_MENU
Definition:
Input.hpp:146
engine::platform::KEY_TAB
@ KEY_TAB
Definition:
Input.hpp:79
engine::platform::KEY_6
@ KEY_6
Definition:
Input.hpp:39
engine::platform::KEY_PAGE_UP
@ KEY_PAGE_UP
Definition:
Input.hpp:87
engine::platform::KEY_SEMICOLON
@ KEY_SEMICOLON
Definition:
Input.hpp:43
engine::platform::KEY_0
@ KEY_0
Definition:
Input.hpp:33
engine::platform::KEY_U
@ KEY_U
Definition:
Input.hpp:65
engine::platform::KEY_KP_0
@ KEY_KP_0
Definition:
Input.hpp:121
engine::platform::KEY_I
@ KEY_I
Definition:
Input.hpp:53
engine::platform::KEY_F10
@ KEY_F10
Definition:
Input.hpp:105
engine::platform::KEY_Y
@ KEY_Y
Definition:
Input.hpp:69
engine::platform::KEY_F21
@ KEY_F21
Definition:
Input.hpp:116
engine::platform::KEY_END
@ KEY_END
Definition:
Input.hpp:90
engine::platform::KEY_F4
@ KEY_F4
Definition:
Input.hpp:99
engine::platform::MOUSE_BUTTON_2
@ MOUSE_BUTTON_2
Definition:
Input.hpp:16
engine::platform::KEY_KP_ENTER
@ KEY_KP_ENTER
Definition:
Input.hpp:136
engine::platform::MOUSE_BUTTON_5
@ MOUSE_BUTTON_5
Definition:
Input.hpp:19
engine::platform::KEY_F8
@ KEY_F8
Definition:
Input.hpp:103
engine::platform::KEY_LEFT_ALT
@ KEY_LEFT_ALT
Definition:
Input.hpp:140
engine::platform::KEY_F13
@ KEY_F13
Definition:
Input.hpp:108
engine::platform::KEY_F22
@ KEY_F22
Definition:
Input.hpp:117
engine::platform::KEY_F5
@ KEY_F5
Definition:
Input.hpp:100
engine::platform::KEY_RIGHT_BRACKET
@ KEY_RIGHT_BRACKET
Definition:
Input.hpp:73
engine::platform::MOUSE_BUTTON_LAST
@ MOUSE_BUTTON_LAST
Definition:
Input.hpp:23
engine::platform::KEY_H
@ KEY_H
Definition:
Input.hpp:52
engine::platform::MousePosition
Represents mouse position in a given frame relative to the top left corner of the screen.
Definition:
Input.hpp:237
engine::platform::MousePosition::dx
float dx
The change in the X coordinate from the previous frame.
Definition:
Input.hpp:249
engine::platform::MousePosition::y
float y
Y coordinate of the mouse position relative to the top left corner of the screen.
Definition:
Input.hpp:245
engine::platform::MousePosition::dy
float dy
The change in the Y coordinate from the previous frame.
Definition:
Input.hpp:253
engine::platform::MousePosition::x
float x
X coordinate of the mouse position relative to the top left corner of the screen.
Definition:
Input.hpp:241
engine::platform::MousePosition::scroll
float scroll
The rotation of the scroll button.
Definition:
Input.hpp:258
Generated by
1.9.1