diff options
| author | 2020-07-14 19:01:36 +0200 | |
|---|---|---|
| committer | 2020-08-29 18:56:34 +0200 | |
| commit | e6bd1fd1b8487e421f71d43b6073ee56de1a043d (patch) | |
| tree | 53b383906fae814a67ae270b9b510a60f1b5df9d /src/input_common/touch_from_button.cpp | |
| parent | Merge pull request #4604 from lioncash/lifetime (diff) | |
| download | yuzu-e6bd1fd1b8487e421f71d43b6073ee56de1a043d.tar.gz yuzu-e6bd1fd1b8487e421f71d43b6073ee56de1a043d.tar.xz yuzu-e6bd1fd1b8487e421f71d43b6073ee56de1a043d.zip | |
yuzu: Add motion and touch configuration
Diffstat (limited to 'src/input_common/touch_from_button.cpp')
| -rw-r--r-- | src/input_common/touch_from_button.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/input_common/touch_from_button.cpp b/src/input_common/touch_from_button.cpp new file mode 100644 index 000000000..8e7f90253 --- /dev/null +++ b/src/input_common/touch_from_button.cpp | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | // Copyright 2020 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "core/settings.h" | ||
| 6 | #include "input_common/touch_from_button.h" | ||
| 7 | |||
| 8 | namespace InputCommon { | ||
| 9 | |||
| 10 | class TouchFromButtonDevice final : public Input::TouchDevice { | ||
| 11 | public: | ||
| 12 | TouchFromButtonDevice() { | ||
| 13 | for (const auto& config_entry : | ||
| 14 | Settings::values.touch_from_button_maps[Settings::values.touch_from_button_map_index] | ||
| 15 | .buttons) { | ||
| 16 | const Common::ParamPackage package{config_entry}; | ||
| 17 | map.emplace_back( | ||
| 18 | Input::CreateDevice<Input::ButtonDevice>(config_entry), | ||
| 19 | std::clamp(package.Get("x", 0), 0, static_cast<int>(Layout::ScreenUndocked::Width)), | ||
| 20 | std::clamp(package.Get("y", 0), 0, | ||
| 21 | static_cast<int>(Layout::ScreenUndocked::Height))); | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | std::tuple<float, float, bool> GetStatus() const override { | ||
| 26 | for (const auto& m : map) { | ||
| 27 | const bool state = std::get<0>(m)->GetStatus(); | ||
| 28 | if (state) { | ||
| 29 | const float x = static_cast<float>(std::get<1>(m)) / | ||
| 30 | static_cast<int>(Layout::ScreenUndocked::Width); | ||
| 31 | const float y = static_cast<float>(std::get<2>(m)) / | ||
| 32 | static_cast<int>(Layout::ScreenUndocked::Height); | ||
| 33 | return std::make_tuple(x, y, true); | ||
| 34 | } | ||
| 35 | } | ||
| 36 | return std::make_tuple(0.0f, 0.0f, false); | ||
| 37 | } | ||
| 38 | |||
| 39 | private: | ||
| 40 | std::vector<std::tuple<std::unique_ptr<Input::ButtonDevice>, int, int>> map; // button, x, y | ||
| 41 | }; | ||
| 42 | |||
| 43 | std::unique_ptr<Input::TouchDevice> TouchFromButtonFactory::Create( | ||
| 44 | const Common::ParamPackage& params) { | ||
| 45 | |||
| 46 | return std::make_unique<TouchFromButtonDevice>(); | ||
| 47 | } | ||
| 48 | |||
| 49 | } // namespace InputCommon | ||