From e6bd1fd1b8487e421f71d43b6073ee56de1a043d Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Tue, 14 Jul 2020 19:01:36 +0200 Subject: yuzu: Add motion and touch configuration --- src/input_common/CMakeLists.txt | 2 ++ src/input_common/main.cpp | 9 +++++++ src/input_common/main.h | 3 +++ src/input_common/touch_from_button.cpp | 49 ++++++++++++++++++++++++++++++++++ src/input_common/touch_from_button.h | 25 +++++++++++++++++ 5 files changed, 88 insertions(+) create mode 100644 src/input_common/touch_from_button.cpp create mode 100644 src/input_common/touch_from_button.h (limited to 'src/input_common') 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 motion_emu.h settings.cpp settings.h + touch_from_button.cpp + touch_from_button.h gcadapter/gc_adapter.cpp gcadapter/gc_adapter.h 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 @@ #include "input_common/keyboard.h" #include "input_common/main.h" #include "input_common/motion_emu.h" +#include "input_common/touch_from_button.h" #include "input_common/udp/udp.h" #ifdef HAVE_SDL2 #include "input_common/sdl/sdl.h" @@ -32,6 +33,8 @@ struct InputSubsystem::Impl { std::make_shared()); motion_emu = std::make_shared(); Input::RegisterFactory("motion_emu", motion_emu); + Input::RegisterFactory("touch_from_button", + std::make_shared()); #ifdef HAVE_SDL2 sdl = SDL::Init(); @@ -46,6 +49,7 @@ struct InputSubsystem::Impl { Input::UnregisterFactory("analog_from_button"); Input::UnregisterFactory("motion_emu"); motion_emu.reset(); + Input::UnregisterFactory("touch_from_button"); #ifdef HAVE_SDL2 sdl.reset(); #endif @@ -171,6 +175,11 @@ const GCButtonFactory* InputSubsystem::GetGCButtons() const { return impl->gcbuttons.get(); } +void ReloadInputDevices() { + if (udp) + udp->ReloadUDPClient(); +} + std::vector> InputSubsystem::GetPollers( Polling::DeviceType type) const { #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 { enum Values : int; } +/// Reloads the input devices +void ReloadInputDevices(); + namespace InputCommon { namespace Polling { 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 @@ +// Copyright 2020 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "core/settings.h" +#include "input_common/touch_from_button.h" + +namespace InputCommon { + +class TouchFromButtonDevice final : public Input::TouchDevice { +public: + TouchFromButtonDevice() { + for (const auto& config_entry : + Settings::values.touch_from_button_maps[Settings::values.touch_from_button_map_index] + .buttons) { + const Common::ParamPackage package{config_entry}; + map.emplace_back( + Input::CreateDevice(config_entry), + std::clamp(package.Get("x", 0), 0, static_cast(Layout::ScreenUndocked::Width)), + std::clamp(package.Get("y", 0), 0, + static_cast(Layout::ScreenUndocked::Height))); + } + } + + std::tuple GetStatus() const override { + for (const auto& m : map) { + const bool state = std::get<0>(m)->GetStatus(); + if (state) { + const float x = static_cast(std::get<1>(m)) / + static_cast(Layout::ScreenUndocked::Width); + const float y = static_cast(std::get<2>(m)) / + static_cast(Layout::ScreenUndocked::Height); + return std::make_tuple(x, y, true); + } + } + return std::make_tuple(0.0f, 0.0f, false); + } + +private: + std::vector, int, int>> map; // button, x, y +}; + +std::unique_ptr TouchFromButtonFactory::Create( + const Common::ParamPackage& params) { + + return std::make_unique(); +} + +} // 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 @@ +// Copyright 2020 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include "core/frontend/framebuffer_layout.h" +#include "core/frontend/input.h" + +namespace InputCommon { + +/** + * A touch device factory that takes a list of button devices and combines them into a touch device. + */ +class TouchFromButtonFactory final : public Input::Factory { +public: + /** + * Creates a touch device from a list of button devices + * @param unused + */ + std::unique_ptr Create(const Common::ParamPackage& params) override; +}; + +} // namespace InputCommon -- cgit v1.2.3 From d176feffad824bce20b694432ade28fe8273c8e4 Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Sat, 29 Aug 2020 20:56:51 +0200 Subject: Address review comments and fix code compilation --- src/input_common/main.cpp | 8 +++++--- src/input_common/main.h | 2 ++ src/input_common/touch_from_button.cpp | 7 ++++--- 3 files changed, 11 insertions(+), 6 deletions(-) (limited to 'src/input_common') diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index f9d7b408f..ea1a1cee6 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp @@ -175,9 +175,11 @@ const GCButtonFactory* InputSubsystem::GetGCButtons() const { return impl->gcbuttons.get(); } -void ReloadInputDevices() { - if (udp) - udp->ReloadUDPClient(); +void InputSubsystem::ReloadInputDevices() { + if (!impl->udp) { + return; + } + impl->udp->ReloadUDPClient(); } std::vector> InputSubsystem::GetPollers( diff --git a/src/input_common/main.h b/src/input_common/main.h index 269735c43..512215e7e 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h @@ -118,6 +118,8 @@ public: /// Retrieves the underlying GameCube button handler. [[nodiscard]] const GCButtonFactory* GetGCButtons() const; + void ReloadInputDevices(); + /// Get all DevicePoller from all backends for a specific device type [[nodiscard]] std::vector> GetPollers( Polling::DeviceType type) const; diff --git a/src/input_common/touch_from_button.cpp b/src/input_common/touch_from_button.cpp index 8e7f90253..d028dfa0d 100644 --- a/src/input_common/touch_from_button.cpp +++ b/src/input_common/touch_from_button.cpp @@ -30,14 +30,15 @@ public: static_cast(Layout::ScreenUndocked::Width); const float y = static_cast(std::get<2>(m)) / static_cast(Layout::ScreenUndocked::Height); - return std::make_tuple(x, y, true); + return {x, y, true}; } } - return std::make_tuple(0.0f, 0.0f, false); + return {}; } private: - std::vector, int, int>> map; // button, x, y + // A vector of the mapped button, its x and its y-coordinate + std::vector, int, int>> map; }; std::unique_ptr TouchFromButtonFactory::Create( -- cgit v1.2.3 From d1e1ea0fef0ddfe914f14a2d547b922b71081695 Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Sun, 30 Aug 2020 00:07:38 +0200 Subject: Address second batch of reviews --- src/input_common/main.h | 4 +--- src/input_common/touch_from_button.cpp | 2 +- src/input_common/touch_from_button.h | 2 -- 3 files changed, 2 insertions(+), 6 deletions(-) (limited to 'src/input_common') diff --git a/src/input_common/main.h b/src/input_common/main.h index 512215e7e..f3fbf696e 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h @@ -21,9 +21,6 @@ namespace Settings::NativeButton { enum Values : int; } -/// Reloads the input devices -void ReloadInputDevices(); - namespace InputCommon { namespace Polling { @@ -118,6 +115,7 @@ public: /// Retrieves the underlying GameCube button handler. [[nodiscard]] const GCButtonFactory* GetGCButtons() const; + /// Reloads the input devices void ReloadInputDevices(); /// Get all DevicePoller from all backends for a specific device type diff --git a/src/input_common/touch_from_button.cpp b/src/input_common/touch_from_button.cpp index d028dfa0d..98da0ef1a 100644 --- a/src/input_common/touch_from_button.cpp +++ b/src/input_common/touch_from_button.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include "core/frontend/framebuffer_layout.h" #include "core/settings.h" #include "input_common/touch_from_button.h" @@ -43,7 +44,6 @@ private: std::unique_ptr TouchFromButtonFactory::Create( const Common::ParamPackage& params) { - return std::make_unique(); } diff --git a/src/input_common/touch_from_button.h b/src/input_common/touch_from_button.h index cfb82f108..8b4d1aa96 100644 --- a/src/input_common/touch_from_button.h +++ b/src/input_common/touch_from_button.h @@ -5,7 +5,6 @@ #pragma once #include -#include "core/frontend/framebuffer_layout.h" #include "core/frontend/input.h" namespace InputCommon { @@ -17,7 +16,6 @@ class TouchFromButtonFactory final : public Input::Factory { public: /** * Creates a touch device from a list of button devices - * @param unused */ std::unique_ptr Create(const Common::ParamPackage& params) override; }; -- cgit v1.2.3