Archived
1
Fork 0

Reformat input.cpp

This commit is contained in:
Joshua Goins 2022-02-20 23:41:40 -05:00
parent d76f9b12a5
commit d167471369

View file

@ -17,24 +17,25 @@ void input_system::update() {
const auto& [x, y] = platform::get_cursor_position(); const auto& [x, y] = platform::get_cursor_position();
auto& [oldX, oldY] = _last_cursor_position; auto& [oldX, oldY] = _last_cursor_position;
const auto [width, height] = platform::get_window_size(::engine->get_main_window()); const auto [width, height] =
platform::get_window_size(::engine->get_main_window());
float xDelta = (x - oldX) / (float)width; float xDelta = (x - oldX) / (float)width;
float yDelta = (y - oldY) / (float)height; float yDelta = (y - oldY) / (float)height;
if(is_in_range(x, width / 2, 3) && is_in_range(y, height / 2, 3)) { if (is_in_range(x, width / 2, 3) && is_in_range(y, height / 2, 3)) {
xDelta = 0.0f; xDelta = 0.0f;
yDelta = 0.0f; yDelta = 0.0f;
} }
_last_cursor_position = { x, y }; _last_cursor_position = {x, y};
for (auto& binding : _input_bindings) { for (auto& binding : _input_bindings) {
binding.value = 0.0f; binding.value = 0.0f;
for (auto& [key, value] : binding.buttons) { for (auto& [key, value] : binding.buttons) {
bool is_pressed = false; bool is_pressed = false;
switch(key) { switch (key) {
case InputButton::MouseLeft: case InputButton::MouseLeft:
is_pressed = platform::get_mouse_button_down(0); is_pressed = platform::get_mouse_button_down(0);
break; break;
@ -51,8 +52,7 @@ void input_system::update() {
if (binding.last_button == key) { if (binding.last_button == key) {
binding.repeat = true; binding.repeat = true;
} } else {
else {
binding.repeat = false; binding.repeat = false;
} }
@ -65,7 +65,7 @@ void input_system::update() {
binding.repeat = false; binding.repeat = false;
} }
for(auto& axis : binding.axises) { for (auto& axis : binding.axises) {
auto [lx, ly] = platform::get_left_stick_position(); auto [lx, ly] = platform::get_left_stick_position();
auto [rx, ry] = platform::get_right_stick_position(); auto [rx, ry] = platform::get_right_stick_position();
auto [sx, sy] = platform::get_wheel_delta(); auto [sx, sy] = platform::get_wheel_delta();
@ -99,7 +99,7 @@ void input_system::update() {
break; break;
} }
if(nextValue != 0.0f) if (nextValue != 0.0f)
binding.value = nextValue; binding.value = nextValue;
} }
} }
@ -112,7 +112,8 @@ void input_system::add_binding(const std::string& name) {
_input_bindings.push_back(data); _input_bindings.push_back(data);
} }
void input_system::add_binding_button(const std::string& name, InputButton key, float value) { void input_system::add_binding_button(const std::string& name, InputButton key,
float value) {
for (auto& binding : _input_bindings) { for (auto& binding : _input_bindings) {
if (binding.name == name) if (binding.name == name)
binding.buttons[key] = value; binding.buttons[key] = value;
@ -137,7 +138,7 @@ float input_system::get_value(const std::string& name) {
return 0.0f; return 0.0f;
} }
bool input_system::is_pressed(const std::string &name, bool repeating) { bool input_system::is_pressed(const std::string& name, bool repeating) {
return get_value(name) == 1.0 && (repeating || !is_repeating(name)); return get_value(name) == 1.0 && (repeating || !is_repeating(name));
} }
@ -165,15 +166,13 @@ void input_system::end_text_input() {
platform::end_text_input(); platform::end_text_input();
} }
bool input_system::is_text_input() const { bool input_system::is_text_input() const { return _in_text_input; }
return _in_text_input;
}
bool input_system::get_allowable_text_button(unsigned int keycode) const { bool input_system::get_allowable_text_button(unsigned int keycode) const {
if(platform::get_keycode(InputButton::Backspace) == keycode) if (platform::get_keycode(InputButton::Backspace) == keycode)
return true; return true;
if(platform::get_keycode(InputButton::Enter) == keycode) if (platform::get_keycode(InputButton::Enter) == keycode)
return true; return true;
return false; return false;