diff options
| author | 2021-11-01 19:49:14 -0600 | |
|---|---|---|
| committer | 2021-11-24 20:30:27 -0600 | |
| commit | 136eb9c4c2b2425c2dd45a79cf444dee7170714d (patch) | |
| tree | 74a055a08126fdd33b2071baa08125177847db6e /src/input_common | |
| parent | second commit lion review (diff) | |
| download | yuzu-136eb9c4c2b2425c2dd45a79cf444dee7170714d.tar.gz yuzu-136eb9c4c2b2425c2dd45a79cf444dee7170714d.tar.xz yuzu-136eb9c4c2b2425c2dd45a79cf444dee7170714d.zip | |
core/hid: Fully emulate motion from button
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: | |||
| 36 | left->SetCallback(button_left_callback); | 36 | left->SetCallback(button_left_callback); |
| 37 | right->SetCallback(button_right_callback); | 37 | right->SetCallback(button_right_callback); |
| 38 | modifier->SetCallback(button_modifier_callback); | 38 | modifier->SetCallback(button_modifier_callback); |
| 39 | last_x_axis_value = 0.0f; | ||
| 40 | last_y_axis_value = 0.0f; | ||
| 39 | } | 41 | } |
| 40 | 42 | ||
| 41 | bool IsAngleGreater(float old_angle, float new_angle) const { | 43 | bool IsAngleGreater(float old_angle, float new_angle) const { |
| @@ -199,6 +201,8 @@ public: | |||
| 199 | .type = Common::Input::InputType::Stick, | 201 | .type = Common::Input::InputType::Stick, |
| 200 | .stick_status = GetStatus(), | 202 | .stick_status = GetStatus(), |
| 201 | }; | 203 | }; |
| 204 | last_x_axis_value = status.stick_status.x.raw_value; | ||
| 205 | last_y_axis_value = status.stick_status.y.raw_value; | ||
| 202 | TriggerOnChange(status); | 206 | TriggerOnChange(status); |
| 203 | } | 207 | } |
| 204 | 208 | ||
| @@ -215,6 +219,12 @@ public: | |||
| 215 | .type = Common::Input::InputType::Stick, | 219 | .type = Common::Input::InputType::Stick, |
| 216 | .stick_status = GetStatus(), | 220 | .stick_status = GetStatus(), |
| 217 | }; | 221 | }; |
| 222 | if (last_x_axis_value == status.stick_status.x.raw_value && | ||
| 223 | last_y_axis_value == status.stick_status.y.raw_value) { | ||
| 224 | return; | ||
| 225 | } | ||
| 226 | last_x_axis_value = status.stick_status.x.raw_value; | ||
| 227 | last_y_axis_value = status.stick_status.y.raw_value; | ||
| 218 | TriggerOnChange(status); | 228 | TriggerOnChange(status); |
| 219 | } | 229 | } |
| 220 | 230 | ||
| @@ -265,6 +275,8 @@ private: | |||
| 265 | bool left_status; | 275 | bool left_status; |
| 266 | bool right_status; | 276 | bool right_status; |
| 267 | bool modifier_status; | 277 | bool modifier_status; |
| 278 | float last_x_axis_value; | ||
| 279 | float last_y_axis_value; | ||
| 268 | const Common::Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false}; | 280 | const Common::Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false}; |
| 269 | std::chrono::time_point<std::chrono::steady_clock> last_update; | 281 | std::chrono::time_point<std::chrono::steady_clock> last_update; |
| 270 | }; | 282 | }; |
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: | |||
| 16 | : button(std::move(button_)), touch_id(touch_id_), x(x_), y(y_) { | 16 | : button(std::move(button_)), touch_id(touch_id_), x(x_), y(y_) { |
| 17 | Common::Input::InputCallback button_up_callback{ | 17 | Common::Input::InputCallback button_up_callback{ |
| 18 | [this](Common::Input::CallbackStatus callback_) { UpdateButtonStatus(callback_); }}; | 18 | [this](Common::Input::CallbackStatus callback_) { UpdateButtonStatus(callback_); }}; |
| 19 | last_button_value = false; | ||
| 19 | button->SetCallback(button_up_callback); | 20 | button->SetCallback(button_up_callback); |
| 20 | button->ForceUpdate(); | 21 | button->ForceUpdate(); |
| 21 | } | 22 | } |
| 22 | 23 | ||
| 24 | void ForceUpdate() override { | ||
| 25 | button->ForceUpdate(); | ||
| 26 | } | ||
| 27 | |||
| 23 | Common::Input::TouchStatus GetStatus(bool pressed) const { | 28 | Common::Input::TouchStatus GetStatus(bool pressed) const { |
| 24 | const Common::Input::ButtonStatus button_status{ | 29 | const Common::Input::ButtonStatus button_status{ |
| 25 | .value = pressed, | 30 | .value = pressed, |
| @@ -47,11 +52,15 @@ public: | |||
| 47 | .type = Common::Input::InputType::Touch, | 52 | .type = Common::Input::InputType::Touch, |
| 48 | .touch_status = GetStatus(button_callback.button_status.value), | 53 | .touch_status = GetStatus(button_callback.button_status.value), |
| 49 | }; | 54 | }; |
| 50 | TriggerOnChange(status); | 55 | if (last_button_value != button_callback.button_status.value) { |
| 56 | last_button_value = button_callback.button_status.value; | ||
| 57 | TriggerOnChange(status); | ||
| 58 | } | ||
| 51 | } | 59 | } |
| 52 | 60 | ||
| 53 | private: | 61 | private: |
| 54 | Button button; | 62 | Button button; |
| 63 | bool last_button_value; | ||
| 55 | const int touch_id; | 64 | const int touch_id; |
| 56 | const float x; | 65 | const float x; |
| 57 | const float y; | 66 | const float y; |