diff options
Diffstat (limited to 'src/input_common/helpers')
| -rw-r--r-- | src/input_common/helpers/stick_from_buttons.cpp | 75 | ||||
| -rw-r--r-- | src/input_common/helpers/touch_from_buttons.cpp | 11 |
2 files changed, 51 insertions, 35 deletions
diff --git a/src/input_common/helpers/stick_from_buttons.cpp b/src/input_common/helpers/stick_from_buttons.cpp index 77fcd655e..e23394f5f 100644 --- a/src/input_common/helpers/stick_from_buttons.cpp +++ b/src/input_common/helpers/stick_from_buttons.cpp | |||
| @@ -19,23 +19,36 @@ public: | |||
| 19 | : up(std::move(up_)), down(std::move(down_)), left(std::move(left_)), | 19 | : up(std::move(up_)), down(std::move(down_)), left(std::move(left_)), |
| 20 | right(std::move(right_)), modifier(std::move(modifier_)), modifier_scale(modifier_scale_), | 20 | right(std::move(right_)), modifier(std::move(modifier_)), modifier_scale(modifier_scale_), |
| 21 | modifier_angle(modifier_angle_) { | 21 | modifier_angle(modifier_angle_) { |
| 22 | Common::Input::InputCallback button_up_callback{ | 22 | up->SetCallback({ |
| 23 | [this](Common::Input::CallbackStatus callback_) { UpdateUpButtonStatus(callback_); }}; | 23 | .on_change = |
| 24 | Common::Input::InputCallback button_down_callback{ | 24 | [this](const Common::Input::CallbackStatus& callback_) { |
| 25 | [this](Common::Input::CallbackStatus callback_) { UpdateDownButtonStatus(callback_); }}; | 25 | UpdateUpButtonStatus(callback_); |
| 26 | Common::Input::InputCallback button_left_callback{ | 26 | }, |
| 27 | [this](Common::Input::CallbackStatus callback_) { UpdateLeftButtonStatus(callback_); }}; | 27 | }); |
| 28 | Common::Input::InputCallback button_right_callback{ | 28 | down->SetCallback({ |
| 29 | [this](Common::Input::CallbackStatus callback_) { | 29 | .on_change = |
| 30 | UpdateRightButtonStatus(callback_); | 30 | [this](const Common::Input::CallbackStatus& callback_) { |
| 31 | }}; | 31 | UpdateDownButtonStatus(callback_); |
| 32 | Common::Input::InputCallback button_modifier_callback{ | 32 | }, |
| 33 | [this](Common::Input::CallbackStatus callback_) { UpdateModButtonStatus(callback_); }}; | 33 | }); |
| 34 | up->SetCallback(button_up_callback); | 34 | left->SetCallback({ |
| 35 | down->SetCallback(button_down_callback); | 35 | .on_change = |
| 36 | left->SetCallback(button_left_callback); | 36 | [this](const Common::Input::CallbackStatus& callback_) { |
| 37 | right->SetCallback(button_right_callback); | 37 | UpdateLeftButtonStatus(callback_); |
| 38 | modifier->SetCallback(button_modifier_callback); | 38 | }, |
| 39 | }); | ||
| 40 | right->SetCallback({ | ||
| 41 | .on_change = | ||
| 42 | [this](const Common::Input::CallbackStatus& callback_) { | ||
| 43 | UpdateRightButtonStatus(callback_); | ||
| 44 | }, | ||
| 45 | }); | ||
| 46 | modifier->SetCallback({ | ||
| 47 | .on_change = | ||
| 48 | [this](const Common::Input::CallbackStatus& callback_) { | ||
| 49 | UpdateModButtonStatus(callback_); | ||
| 50 | }, | ||
| 51 | }); | ||
| 39 | last_x_axis_value = 0.0f; | 52 | last_x_axis_value = 0.0f; |
| 40 | last_y_axis_value = 0.0f; | 53 | last_y_axis_value = 0.0f; |
| 41 | } | 54 | } |
| @@ -133,27 +146,27 @@ public: | |||
| 133 | } | 146 | } |
| 134 | } | 147 | } |
| 135 | 148 | ||
| 136 | void UpdateUpButtonStatus(Common::Input::CallbackStatus button_callback) { | 149 | void UpdateUpButtonStatus(const Common::Input::CallbackStatus& button_callback) { |
| 137 | up_status = button_callback.button_status.value; | 150 | up_status = button_callback.button_status.value; |
| 138 | UpdateStatus(); | 151 | UpdateStatus(); |
| 139 | } | 152 | } |
| 140 | 153 | ||
| 141 | void UpdateDownButtonStatus(Common::Input::CallbackStatus button_callback) { | 154 | void UpdateDownButtonStatus(const Common::Input::CallbackStatus& button_callback) { |
| 142 | down_status = button_callback.button_status.value; | 155 | down_status = button_callback.button_status.value; |
| 143 | UpdateStatus(); | 156 | UpdateStatus(); |
| 144 | } | 157 | } |
| 145 | 158 | ||
| 146 | void UpdateLeftButtonStatus(Common::Input::CallbackStatus button_callback) { | 159 | void UpdateLeftButtonStatus(const Common::Input::CallbackStatus& button_callback) { |
| 147 | left_status = button_callback.button_status.value; | 160 | left_status = button_callback.button_status.value; |
| 148 | UpdateStatus(); | 161 | UpdateStatus(); |
| 149 | } | 162 | } |
| 150 | 163 | ||
| 151 | void UpdateRightButtonStatus(Common::Input::CallbackStatus button_callback) { | 164 | void UpdateRightButtonStatus(const Common::Input::CallbackStatus& button_callback) { |
| 152 | right_status = button_callback.button_status.value; | 165 | right_status = button_callback.button_status.value; |
| 153 | UpdateStatus(); | 166 | UpdateStatus(); |
| 154 | } | 167 | } |
| 155 | 168 | ||
| 156 | void UpdateModButtonStatus(Common::Input::CallbackStatus button_callback) { | 169 | void UpdateModButtonStatus(const Common::Input::CallbackStatus& button_callback) { |
| 157 | modifier_status = button_callback.button_status.value; | 170 | modifier_status = button_callback.button_status.value; |
| 158 | UpdateStatus(); | 171 | UpdateStatus(); |
| 159 | } | 172 | } |
| @@ -265,18 +278,18 @@ private: | |||
| 265 | Button left; | 278 | Button left; |
| 266 | Button right; | 279 | Button right; |
| 267 | Button modifier; | 280 | Button modifier; |
| 268 | float modifier_scale; | 281 | float modifier_scale{}; |
| 269 | float modifier_angle; | 282 | float modifier_angle{}; |
| 270 | float angle{}; | 283 | float angle{}; |
| 271 | float goal_angle{}; | 284 | float goal_angle{}; |
| 272 | float amplitude{}; | 285 | float amplitude{}; |
| 273 | bool up_status; | 286 | bool up_status{}; |
| 274 | bool down_status; | 287 | bool down_status{}; |
| 275 | bool left_status; | 288 | bool left_status{}; |
| 276 | bool right_status; | 289 | bool right_status{}; |
| 277 | bool modifier_status; | 290 | bool modifier_status{}; |
| 278 | float last_x_axis_value; | 291 | float last_x_axis_value{}; |
| 279 | float last_y_axis_value; | 292 | float last_y_axis_value{}; |
| 280 | const Common::Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false}; | 293 | const Common::Input::AnalogProperties properties{0.0f, 1.0f, 0.5f, 0.0f, false}; |
| 281 | std::chrono::time_point<std::chrono::steady_clock> last_update; | 294 | std::chrono::time_point<std::chrono::steady_clock> last_update; |
| 282 | }; | 295 | }; |
diff --git a/src/input_common/helpers/touch_from_buttons.cpp b/src/input_common/helpers/touch_from_buttons.cpp index 35d60bc90..ece1e3b32 100644 --- a/src/input_common/helpers/touch_from_buttons.cpp +++ b/src/input_common/helpers/touch_from_buttons.cpp | |||
| @@ -14,10 +14,13 @@ public: | |||
| 14 | using Button = std::unique_ptr<Common::Input::InputDevice>; | 14 | using Button = std::unique_ptr<Common::Input::InputDevice>; |
| 15 | TouchFromButtonDevice(Button button_, int touch_id_, float x_, float y_) | 15 | TouchFromButtonDevice(Button button_, int touch_id_, float x_, float y_) |
| 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{ | ||
| 18 | [this](Common::Input::CallbackStatus callback_) { UpdateButtonStatus(callback_); }}; | ||
| 19 | last_button_value = false; | 17 | last_button_value = false; |
| 20 | button->SetCallback(button_up_callback); | 18 | button->SetCallback({ |
| 19 | .on_change = | ||
| 20 | [this](const Common::Input::CallbackStatus& callback_) { | ||
| 21 | UpdateButtonStatus(callback_); | ||
| 22 | }, | ||
| 23 | }); | ||
| 21 | button->ForceUpdate(); | 24 | button->ForceUpdate(); |
| 22 | } | 25 | } |
| 23 | 26 | ||
| @@ -47,7 +50,7 @@ public: | |||
| 47 | return status; | 50 | return status; |
| 48 | } | 51 | } |
| 49 | 52 | ||
| 50 | void UpdateButtonStatus(Common::Input::CallbackStatus button_callback) { | 53 | void UpdateButtonStatus(const Common::Input::CallbackStatus& button_callback) { |
| 51 | const Common::Input::CallbackStatus status{ | 54 | const Common::Input::CallbackStatus status{ |
| 52 | .type = Common::Input::InputType::Touch, | 55 | .type = Common::Input::InputType::Touch, |
| 53 | .touch_status = GetStatus(button_callback.button_status.value), | 56 | .touch_status = GetStatus(button_callback.button_status.value), |