diff options
Diffstat (limited to '')
| -rw-r--r-- | src/input_common/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/input_common/main.cpp | 9 | ||||
| -rw-r--r-- | src/input_common/main.h | 3 | ||||
| -rw-r--r-- | src/input_common/touch_from_button.cpp | 49 | ||||
| -rw-r--r-- | src/input_common/touch_from_button.h | 25 |
5 files changed, 88 insertions, 0 deletions
diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index 56267c8a8..32433df25 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt | |||
| @@ -9,6 +9,8 @@ add_library(input_common STATIC | |||
| 9 | motion_emu.h | 9 | motion_emu.h |
| 10 | settings.cpp | 10 | settings.cpp |
| 11 | settings.h | 11 | settings.h |
| 12 | touch_from_button.cpp | ||
| 13 | touch_from_button.h | ||
| 12 | gcadapter/gc_adapter.cpp | 14 | gcadapter/gc_adapter.cpp |
| 13 | gcadapter/gc_adapter.h | 15 | gcadapter/gc_adapter.h |
| 14 | gcadapter/gc_poller.cpp | 16 | gcadapter/gc_poller.cpp |
diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index 57e7a25fe..f9d7b408f 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/touch_from_button.h" | ||
| 14 | #include "input_common/udp/udp.h" | 15 | #include "input_common/udp/udp.h" |
| 15 | #ifdef HAVE_SDL2 | 16 | #ifdef HAVE_SDL2 |
| 16 | #include "input_common/sdl/sdl.h" | 17 | #include "input_common/sdl/sdl.h" |
| @@ -32,6 +33,8 @@ struct InputSubsystem::Impl { | |||
| 32 | std::make_shared<AnalogFromButton>()); | 33 | std::make_shared<AnalogFromButton>()); |
| 33 | motion_emu = std::make_shared<MotionEmu>(); | 34 | motion_emu = std::make_shared<MotionEmu>(); |
| 34 | Input::RegisterFactory<Input::MotionDevice>("motion_emu", motion_emu); | 35 | Input::RegisterFactory<Input::MotionDevice>("motion_emu", motion_emu); |
| 36 | Input::RegisterFactory<Input::TouchDevice>("touch_from_button", | ||
| 37 | std::make_shared<TouchFromButtonFactory>()); | ||
| 35 | 38 | ||
| 36 | #ifdef HAVE_SDL2 | 39 | #ifdef HAVE_SDL2 |
| 37 | sdl = SDL::Init(); | 40 | sdl = SDL::Init(); |
| @@ -46,6 +49,7 @@ struct InputSubsystem::Impl { | |||
| 46 | Input::UnregisterFactory<Input::AnalogDevice>("analog_from_button"); | 49 | Input::UnregisterFactory<Input::AnalogDevice>("analog_from_button"); |
| 47 | Input::UnregisterFactory<Input::MotionDevice>("motion_emu"); | 50 | Input::UnregisterFactory<Input::MotionDevice>("motion_emu"); |
| 48 | motion_emu.reset(); | 51 | motion_emu.reset(); |
| 52 | Input::UnregisterFactory<Input::TouchDevice>("touch_from_button"); | ||
| 49 | #ifdef HAVE_SDL2 | 53 | #ifdef HAVE_SDL2 |
| 50 | sdl.reset(); | 54 | sdl.reset(); |
| 51 | #endif | 55 | #endif |
| @@ -171,6 +175,11 @@ const GCButtonFactory* InputSubsystem::GetGCButtons() const { | |||
| 171 | return impl->gcbuttons.get(); | 175 | return impl->gcbuttons.get(); |
| 172 | } | 176 | } |
| 173 | 177 | ||
| 178 | void ReloadInputDevices() { | ||
| 179 | if (udp) | ||
| 180 | udp->ReloadUDPClient(); | ||
| 181 | } | ||
| 182 | |||
| 174 | std::vector<std::unique_ptr<Polling::DevicePoller>> InputSubsystem::GetPollers( | 183 | std::vector<std::unique_ptr<Polling::DevicePoller>> InputSubsystem::GetPollers( |
| 175 | Polling::DeviceType type) const { | 184 | Polling::DeviceType type) const { |
| 176 | #ifdef HAVE_SDL2 | 185 | #ifdef HAVE_SDL2 |
diff --git a/src/input_common/main.h b/src/input_common/main.h index 58e5dc250..269735c43 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h | |||
| @@ -21,6 +21,9 @@ namespace Settings::NativeButton { | |||
| 21 | enum Values : int; | 21 | enum Values : int; |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | /// Reloads the input devices | ||
| 25 | void ReloadInputDevices(); | ||
| 26 | |||
| 24 | namespace InputCommon { | 27 | namespace InputCommon { |
| 25 | namespace Polling { | 28 | namespace Polling { |
| 26 | 29 | ||
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 | ||
diff --git a/src/input_common/touch_from_button.h b/src/input_common/touch_from_button.h new file mode 100644 index 000000000..cfb82f108 --- /dev/null +++ b/src/input_common/touch_from_button.h | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | // Copyright 2020 Citra 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 <memory> | ||
| 8 | #include "core/frontend/framebuffer_layout.h" | ||
| 9 | #include "core/frontend/input.h" | ||
| 10 | |||
| 11 | namespace InputCommon { | ||
| 12 | |||
| 13 | /** | ||
| 14 | * A touch device factory that takes a list of button devices and combines them into a touch device. | ||
| 15 | */ | ||
| 16 | class TouchFromButtonFactory final : public Input::Factory<Input::TouchDevice> { | ||
| 17 | public: | ||
| 18 | /** | ||
| 19 | * Creates a touch device from a list of button devices | ||
| 20 | * @param unused | ||
| 21 | */ | ||
| 22 | std::unique_ptr<Input::TouchDevice> Create(const Common::ParamPackage& params) override; | ||
| 23 | }; | ||
| 24 | |||
| 25 | } // namespace InputCommon | ||