diff options
Diffstat (limited to '')
-rw-r--r-- | src/input_common/helpers/stick_from_buttons.cpp | 12 | ||||
-rw-r--r-- | src/input_common/helpers/touch_from_buttons.cpp | 11 |
2 files changed, 22 insertions, 1 deletions
diff --git a/src/input_common/helpers/stick_from_buttons.cpp b/src/input_common/helpers/stick_from_buttons.cpp index 1d5948f79..77fcd655e 100644 --- a/src/input_common/helpers/stick_from_buttons.cpp +++ b/src/input_common/helpers/stick_from_buttons.cpp @@ -36,6 +36,8 @@ public: left->SetCallback(button_left_callback); right->SetCallback(button_right_callback); modifier->SetCallback(button_modifier_callback); + last_x_axis_value = 0.0f; + last_y_axis_value = 0.0f; } bool IsAngleGreater(float old_angle, float new_angle) const { @@ -199,6 +201,8 @@ public: .type = Common::Input::InputType::Stick, .stick_status = GetStatus(), }; + last_x_axis_value = status.stick_status.x.raw_value; + last_y_axis_value = status.stick_status.y.raw_value; TriggerOnChange(status); } @@ -215,6 +219,12 @@ public: .type = Common::Input::InputType::Stick, .stick_status = GetStatus(), }; + if (last_x_axis_value == status.stick_status.x.raw_value && + last_y_axis_value == status.stick_status.y.raw_value) { + return; + } + last_x_axis_value = status.stick_status.x.raw_value; + last_y_axis_value = status.stick_status.y.raw_value; TriggerOnChange(status); } @@ -265,6 +275,8 @@ private: bool left_status; bool right_status; bool modifier_status; + float last_x_axis_value; + float last_y_axis_value; const Common::Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false}; std::chrono::time_point<std::chrono::steady_clock> last_update; }; diff --git a/src/input_common/helpers/touch_from_buttons.cpp b/src/input_common/helpers/touch_from_buttons.cpp index 024343715..35d60bc90 100644 --- a/src/input_common/helpers/touch_from_buttons.cpp +++ b/src/input_common/helpers/touch_from_buttons.cpp @@ -16,10 +16,15 @@ public: : button(std::move(button_)), touch_id(touch_id_), x(x_), y(y_) { Common::Input::InputCallback button_up_callback{ [this](Common::Input::CallbackStatus callback_) { UpdateButtonStatus(callback_); }}; + last_button_value = false; button->SetCallback(button_up_callback); button->ForceUpdate(); } + void ForceUpdate() override { + button->ForceUpdate(); + } + Common::Input::TouchStatus GetStatus(bool pressed) const { const Common::Input::ButtonStatus button_status{ .value = pressed, @@ -47,11 +52,15 @@ public: .type = Common::Input::InputType::Touch, .touch_status = GetStatus(button_callback.button_status.value), }; - TriggerOnChange(status); + if (last_button_value != button_callback.button_status.value) { + last_button_value = button_callback.button_status.value; + TriggerOnChange(status); + } } private: Button button; + bool last_button_value; const int touch_id; const float x; const float y; |