diff options
Diffstat (limited to 'src/input_common')
| -rw-r--r-- | src/input_common/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/input_common/main.cpp | 4 | ||||
| -rw-r--r-- | src/input_common/motion_from_button.cpp | 34 | ||||
| -rw-r--r-- | src/input_common/motion_from_button.h | 25 |
4 files changed, 65 insertions, 0 deletions
diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index 09361e37e..c84685214 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt | |||
| @@ -7,6 +7,8 @@ add_library(input_common STATIC | |||
| 7 | main.h | 7 | main.h |
| 8 | motion_emu.cpp | 8 | motion_emu.cpp |
| 9 | motion_emu.h | 9 | motion_emu.h |
| 10 | motion_from_button.cpp | ||
| 11 | motion_from_button.h | ||
| 10 | motion_input.cpp | 12 | motion_input.cpp |
| 11 | motion_input.h | 13 | motion_input.h |
| 12 | settings.cpp | 14 | settings.cpp |
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index 8da829132..3d97d95f7 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | #include "input_common/keyboard.h" | 11 | #include "input_common/keyboard.h" |
| 12 | #include "input_common/main.h" | 12 | #include "input_common/main.h" |
| 13 | #include "input_common/motion_emu.h" | 13 | #include "input_common/motion_emu.h" |
| 14 | #include "input_common/motion_from_button.h" | ||
| 14 | #include "input_common/touch_from_button.h" | 15 | #include "input_common/touch_from_button.h" |
| 15 | #include "input_common/udp/client.h" | 16 | #include "input_common/udp/client.h" |
| 16 | #include "input_common/udp/udp.h" | 17 | #include "input_common/udp/udp.h" |
| @@ -32,6 +33,8 @@ struct InputSubsystem::Impl { | |||
| 32 | Input::RegisterFactory<Input::ButtonDevice>("keyboard", keyboard); | 33 | Input::RegisterFactory<Input::ButtonDevice>("keyboard", keyboard); |
| 33 | Input::RegisterFactory<Input::AnalogDevice>("analog_from_button", | 34 | Input::RegisterFactory<Input::AnalogDevice>("analog_from_button", |
| 34 | std::make_shared<AnalogFromButton>()); | 35 | std::make_shared<AnalogFromButton>()); |
| 36 | Input::RegisterFactory<Input::MotionDevice>("keyboard", | ||
| 37 | std::make_shared<MotionFromButton>()); | ||
| 35 | motion_emu = std::make_shared<MotionEmu>(); | 38 | motion_emu = std::make_shared<MotionEmu>(); |
| 36 | Input::RegisterFactory<Input::MotionDevice>("motion_emu", motion_emu); | 39 | Input::RegisterFactory<Input::MotionDevice>("motion_emu", motion_emu); |
| 37 | Input::RegisterFactory<Input::TouchDevice>("touch_from_button", | 40 | Input::RegisterFactory<Input::TouchDevice>("touch_from_button", |
| @@ -50,6 +53,7 @@ struct InputSubsystem::Impl { | |||
| 50 | 53 | ||
| 51 | void Shutdown() { | 54 | void Shutdown() { |
| 52 | Input::UnregisterFactory<Input::ButtonDevice>("keyboard"); | 55 | Input::UnregisterFactory<Input::ButtonDevice>("keyboard"); |
| 56 | Input::UnregisterFactory<Input::MotionDevice>("keyboard"); | ||
| 53 | keyboard.reset(); | 57 | keyboard.reset(); |
| 54 | Input::UnregisterFactory<Input::AnalogDevice>("analog_from_button"); | 58 | Input::UnregisterFactory<Input::AnalogDevice>("analog_from_button"); |
| 55 | Input::UnregisterFactory<Input::MotionDevice>("motion_emu"); | 59 | Input::UnregisterFactory<Input::MotionDevice>("motion_emu"); |
diff --git a/src/input_common/motion_from_button.cpp b/src/input_common/motion_from_button.cpp new file mode 100644 index 000000000..9d459f963 --- /dev/null +++ b/src/input_common/motion_from_button.cpp | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | // Copyright 2020 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "input_common/motion_from_button.h" | ||
| 6 | #include "input_common/motion_input.h" | ||
| 7 | |||
| 8 | namespace InputCommon { | ||
| 9 | |||
| 10 | class MotionKey final : public Input::MotionDevice { | ||
| 11 | public: | ||
| 12 | using Button = std::unique_ptr<Input::ButtonDevice>; | ||
| 13 | |||
| 14 | MotionKey(Button key_) : key(std::move(key_)) {} | ||
| 15 | |||
| 16 | Input::MotionStatus GetStatus() const override { | ||
| 17 | |||
| 18 | if (key->GetStatus()) { | ||
| 19 | return motion.GetRandomMotion(2, 6); | ||
| 20 | } | ||
| 21 | return motion.GetRandomMotion(0, 0); | ||
| 22 | } | ||
| 23 | |||
| 24 | private: | ||
| 25 | Button key; | ||
| 26 | InputCommon::MotionInput motion{0.0f, 0.0f, 0.0f}; | ||
| 27 | }; | ||
| 28 | |||
| 29 | std::unique_ptr<Input::MotionDevice> MotionFromButton::Create(const Common::ParamPackage& params) { | ||
| 30 | auto key = Input::CreateDevice<Input::ButtonDevice>(params.Serialize()); | ||
| 31 | return std::make_unique<MotionKey>(std::move(key)); | ||
| 32 | } | ||
| 33 | |||
| 34 | } // namespace InputCommon | ||
diff --git a/src/input_common/motion_from_button.h b/src/input_common/motion_from_button.h new file mode 100644 index 000000000..a959046fb --- /dev/null +++ b/src/input_common/motion_from_button.h | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | // Copyright 2020 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "core/frontend/input.h" | ||
| 8 | |||
| 9 | namespace InputCommon { | ||
| 10 | |||
| 11 | /** | ||
| 12 | * An motion device factory that takes a keyboard button and uses it as a random | ||
| 13 | * motion device. | ||
| 14 | */ | ||
| 15 | class MotionFromButton final : public Input::Factory<Input::MotionDevice> { | ||
| 16 | public: | ||
| 17 | /** | ||
| 18 | * Creates an motion device from button devices | ||
| 19 | * @param params contains parameters for creating the device: | ||
| 20 | * - "key": a serialized ParamPackage for creating a button device | ||
| 21 | */ | ||
| 22 | std::unique_ptr<Input::MotionDevice> Create(const Common::ParamPackage& params) override; | ||
| 23 | }; | ||
| 24 | |||
| 25 | } // namespace InputCommon | ||