-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputSystem.cpp
More file actions
231 lines (189 loc) · 4.42 KB
/
Copy pathInputSystem.cpp
File metadata and controls
231 lines (189 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/**
*
* @file InputSystem.cpp
* @author Gaspard Kirira
*
* Copyright 2026, Gaspard Kirira.
* All rights reserved.
* https://github.com/vixcpp/game
*
* Use of this source code is governed by a MIT license
* that can be found in the LICENSE file.
*
* Vix.cpp
*
*/
#include <vix/game/InputSystem.hpp>
#include <utility>
namespace vix::game
{
void InputSystem::begin_frame()
{
state_.begin_frame();
}
void InputSystem::handle_window_event(const WindowEvent &event)
{
switch (event.type)
{
case WindowEventType::KeyPressed:
press_key(event.key);
break;
case WindowEventType::KeyReleased:
release_key(event.key);
break;
case WindowEventType::ButtonPressed:
press_button(event.button);
break;
case WindowEventType::ButtonReleased:
release_button(event.button);
break;
case WindowEventType::PointerMoved:
set_pointer_position(event.x, event.y);
add_pointer_delta(event.dx, event.dy);
break;
case WindowEventType::WheelMoved:
add_wheel_delta(event.dx, event.dy);
break;
case WindowEventType::Unknown:
case WindowEventType::CloseRequested:
case WindowEventType::Resized:
case WindowEventType::FocusGained:
case WindowEventType::FocusLost:
break;
}
}
void InputSystem::press_key(InputKey key)
{
state_.press_key(key);
}
void InputSystem::release_key(InputKey key)
{
state_.release_key(key);
}
void InputSystem::press_button(InputButton button)
{
state_.press_button(button);
}
void InputSystem::release_button(InputButton button)
{
state_.release_button(button);
}
void InputSystem::set_pointer_position(double x, double y) noexcept
{
state_.set_pointer_position(x, y);
}
void InputSystem::add_pointer_delta(double dx, double dy) noexcept
{
state_.add_pointer_delta(dx, dy);
}
void InputSystem::add_wheel_delta(double dx, double dy) noexcept
{
state_.add_wheel_delta(dx, dy);
}
GameBoolResult InputSystem::bind_key(
std::string name,
InputKey key)
{
return map_.bind_key(std::move(name), key);
}
GameBoolResult InputSystem::bind_button(
std::string name,
InputButton button)
{
return map_.bind_button(std::move(name), button);
}
GameBoolResult InputSystem::add_key(
const std::string &name,
InputKey key)
{
return map_.add_key(name, key);
}
GameBoolResult InputSystem::add_button(
const std::string &name,
InputButton button)
{
return map_.add_button(name, button);
}
GameBoolResult InputSystem::unbind(
const std::string &name)
{
return map_.unbind(name);
}
bool InputSystem::key_down(InputKey key) const
{
return state_.key_down(key);
}
bool InputSystem::key_pressed(InputKey key) const
{
return state_.key_pressed(key);
}
bool InputSystem::key_released(InputKey key) const
{
return state_.key_released(key);
}
bool InputSystem::button_down(InputButton button) const
{
return state_.button_down(button);
}
bool InputSystem::button_pressed(InputButton button) const
{
return state_.button_pressed(button);
}
bool InputSystem::button_released(InputButton button) const
{
return state_.button_released(button);
}
bool InputSystem::action_down(const std::string &name) const
{
return map_.down(name, state_);
}
bool InputSystem::action_pressed(const std::string &name) const
{
return map_.pressed(name, state_);
}
bool InputSystem::action_released(const std::string &name) const
{
return map_.released(name, state_);
}
PointerPosition InputSystem::pointer_position() const noexcept
{
return state_.pointer_position();
}
PointerDelta InputSystem::pointer_delta() const noexcept
{
return state_.pointer_delta();
}
PointerDelta InputSystem::wheel_delta() const noexcept
{
return state_.wheel_delta();
}
InputState &InputSystem::state() noexcept
{
return state_;
}
const InputState &InputSystem::state() const noexcept
{
return state_;
}
InputMap &InputSystem::map() noexcept
{
return map_;
}
const InputMap &InputSystem::map() const noexcept
{
return map_;
}
void InputSystem::clear()
{
state_.clear();
map_.clear();
}
void InputSystem::clear_state()
{
state_.clear();
}
void InputSystem::clear_bindings()
{
map_.clear();
}
} // namespace vix::game