diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/input_common/main.cpp | 8 | ||||
| -rw-r--r-- | src/input_common/main.h | 2 | ||||
| -rw-r--r-- | src/input_common/touch_from_button.cpp | 7 | ||||
| -rw-r--r-- | src/yuzu/configuration/config.cpp | 77 | ||||
| -rw-r--r-- | src/yuzu/configuration/config.h | 2 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input.cpp | 9 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_advanced.cpp | 2 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_advanced.h | 1 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_motion_touch.cpp | 88 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_motion_touch.h | 29 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_touch_from_button.cpp | 114 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_touch_from_button.h | 19 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_touch_widget.h | 15 |
13 files changed, 218 insertions, 155 deletions
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 { | |||
| 175 | return impl->gcbuttons.get(); | 175 | return impl->gcbuttons.get(); |
| 176 | } | 176 | } |
| 177 | 177 | ||
| 178 | void ReloadInputDevices() { | 178 | void InputSubsystem::ReloadInputDevices() { |
| 179 | if (udp) | 179 | if (!impl->udp) { |
| 180 | udp->ReloadUDPClient(); | 180 | return; |
| 181 | } | ||
| 182 | impl->udp->ReloadUDPClient(); | ||
| 181 | } | 183 | } |
| 182 | 184 | ||
| 183 | std::vector<std::unique_ptr<Polling::DevicePoller>> InputSubsystem::GetPollers( | 185 | std::vector<std::unique_ptr<Polling::DevicePoller>> 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: | |||
| 118 | /// Retrieves the underlying GameCube button handler. | 118 | /// Retrieves the underlying GameCube button handler. |
| 119 | [[nodiscard]] const GCButtonFactory* GetGCButtons() const; | 119 | [[nodiscard]] const GCButtonFactory* GetGCButtons() const; |
| 120 | 120 | ||
| 121 | void ReloadInputDevices(); | ||
| 122 | |||
| 121 | /// Get all DevicePoller from all backends for a specific device type | 123 | /// Get all DevicePoller from all backends for a specific device type |
| 122 | [[nodiscard]] std::vector<std::unique_ptr<Polling::DevicePoller>> GetPollers( | 124 | [[nodiscard]] std::vector<std::unique_ptr<Polling::DevicePoller>> GetPollers( |
| 123 | Polling::DeviceType type) const; | 125 | 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: | |||
| 30 | static_cast<int>(Layout::ScreenUndocked::Width); | 30 | static_cast<int>(Layout::ScreenUndocked::Width); |
| 31 | const float y = static_cast<float>(std::get<2>(m)) / | 31 | const float y = static_cast<float>(std::get<2>(m)) / |
| 32 | static_cast<int>(Layout::ScreenUndocked::Height); | 32 | static_cast<int>(Layout::ScreenUndocked::Height); |
| 33 | return std::make_tuple(x, y, true); | 33 | return {x, y, true}; |
| 34 | } | 34 | } |
| 35 | } | 35 | } |
| 36 | return std::make_tuple(0.0f, 0.0f, false); | 36 | return {}; |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | private: | 39 | private: |
| 40 | std::vector<std::tuple<std::unique_ptr<Input::ButtonDevice>, int, int>> map; // button, x, y | 40 | // A vector of the mapped button, its x and its y-coordinate |
| 41 | std::vector<std::tuple<std::unique_ptr<Input::ButtonDevice>, int, int>> map; | ||
| 41 | }; | 42 | }; |
| 42 | 43 | ||
| 43 | std::unique_ptr<Input::TouchDevice> TouchFromButtonFactory::Create( | 44 | std::unique_ptr<Input::TouchDevice> TouchFromButtonFactory::Create( |
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index ead19a870..2bc55a26a 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp | |||
| @@ -420,10 +420,17 @@ void Config::ReadControlValues() { | |||
| 420 | ReadKeyboardValues(); | 420 | ReadKeyboardValues(); |
| 421 | ReadMouseValues(); | 421 | ReadMouseValues(); |
| 422 | ReadTouchscreenValues(); | 422 | ReadTouchscreenValues(); |
| 423 | ReadMotionTouchValues(); | ||
| 423 | 424 | ||
| 424 | Settings::values.vibration_enabled = | 425 | Settings::values.vibration_enabled = |
| 425 | ReadSetting(QStringLiteral("vibration_enabled"), true).toBool(); | 426 | ReadSetting(QStringLiteral("vibration_enabled"), true).toBool(); |
| 427 | Settings::values.use_docked_mode = | ||
| 428 | ReadSetting(QStringLiteral("use_docked_mode"), false).toBool(); | ||
| 429 | |||
| 430 | qt_config->endGroup(); | ||
| 431 | } | ||
| 426 | 432 | ||
| 433 | void Config::ReadMotionTouchValues() { | ||
| 427 | int num_touch_from_button_maps = | 434 | int num_touch_from_button_maps = |
| 428 | qt_config->beginReadArray(QStringLiteral("touch_from_button_maps")); | 435 | qt_config->beginReadArray(QStringLiteral("touch_from_button_maps")); |
| 429 | 436 | ||
| @@ -481,10 +488,6 @@ void Config::ReadControlValues() { | |||
| 481 | .toInt()); | 488 | .toInt()); |
| 482 | Settings::values.udp_pad_index = | 489 | Settings::values.udp_pad_index = |
| 483 | static_cast<u8>(ReadSetting(QStringLiteral("udp_pad_index"), 0).toUInt()); | 490 | static_cast<u8>(ReadSetting(QStringLiteral("udp_pad_index"), 0).toUInt()); |
| 484 | Settings::values.use_docked_mode = | ||
| 485 | ReadSetting(QStringLiteral("use_docked_mode"), false).toBool(); | ||
| 486 | |||
| 487 | qt_config->endGroup(); | ||
| 488 | } | 491 | } |
| 489 | 492 | ||
| 490 | void Config::ReadCoreValues() { | 493 | void Config::ReadCoreValues() { |
| @@ -977,6 +980,43 @@ void Config::SaveTouchscreenValues() { | |||
| 977 | WriteSetting(QStringLiteral("touchscreen_diameter_y"), touchscreen.diameter_y, 15); | 980 | WriteSetting(QStringLiteral("touchscreen_diameter_y"), touchscreen.diameter_y, 15); |
| 978 | } | 981 | } |
| 979 | 982 | ||
| 983 | void Config::SaveMotionTouchValues() { | ||
| 984 | WriteSetting(QStringLiteral("motion_device"), | ||
| 985 | QString::fromStdString(Settings::values.motion_device), | ||
| 986 | QStringLiteral("engine:motion_emu,update_period:100,sensitivity:0.01")); | ||
| 987 | WriteSetting(QStringLiteral("touch_device"), | ||
| 988 | QString::fromStdString(Settings::values.touch_device), | ||
| 989 | QStringLiteral("engine:emu_window")); | ||
| 990 | WriteSetting(QStringLiteral("use_touch_from_button"), Settings::values.use_touch_from_button, | ||
| 991 | false); | ||
| 992 | WriteSetting(QStringLiteral("touch_from_button_map"), | ||
| 993 | Settings::values.touch_from_button_map_index, 0); | ||
| 994 | WriteSetting(QStringLiteral("udp_input_address"), | ||
| 995 | QString::fromStdString(Settings::values.udp_input_address), | ||
| 996 | QString::fromUtf8(InputCommon::CemuhookUDP::DEFAULT_ADDR)); | ||
| 997 | WriteSetting(QStringLiteral("udp_input_port"), Settings::values.udp_input_port, | ||
| 998 | InputCommon::CemuhookUDP::DEFAULT_PORT); | ||
| 999 | WriteSetting(QStringLiteral("udp_pad_index"), Settings::values.udp_pad_index, 0); | ||
| 1000 | |||
| 1001 | qt_config->beginWriteArray(QStringLiteral("touch_from_button_maps")); | ||
| 1002 | for (std::size_t p = 0; p < Settings::values.touch_from_button_maps.size(); ++p) { | ||
| 1003 | qt_config->setArrayIndex(static_cast<int>(p)); | ||
| 1004 | WriteSetting(QStringLiteral("name"), | ||
| 1005 | QString::fromStdString(Settings::values.touch_from_button_maps[p].name), | ||
| 1006 | QStringLiteral("default")); | ||
| 1007 | qt_config->beginWriteArray(QStringLiteral("entries")); | ||
| 1008 | for (std::size_t q = 0; q < Settings::values.touch_from_button_maps[p].buttons.size(); | ||
| 1009 | ++q) { | ||
| 1010 | qt_config->setArrayIndex(static_cast<int>(q)); | ||
| 1011 | WriteSetting( | ||
| 1012 | QStringLiteral("bind"), | ||
| 1013 | QString::fromStdString(Settings::values.touch_from_button_maps[p].buttons[q])); | ||
| 1014 | } | ||
| 1015 | qt_config->endArray(); | ||
| 1016 | } | ||
| 1017 | qt_config->endArray(); | ||
| 1018 | } | ||
| 1019 | |||
| 980 | void Config::SaveValues() { | 1020 | void Config::SaveValues() { |
| 981 | if (global) { | 1021 | if (global) { |
| 982 | SaveControlValues(); | 1022 | SaveControlValues(); |
| @@ -1019,6 +1059,7 @@ void Config::SaveControlValues() { | |||
| 1019 | SaveDebugValues(); | 1059 | SaveDebugValues(); |
| 1020 | SaveMouseValues(); | 1060 | SaveMouseValues(); |
| 1021 | SaveTouchscreenValues(); | 1061 | SaveTouchscreenValues(); |
| 1062 | SaveMotionTouchValues(); | ||
| 1022 | 1063 | ||
| 1023 | WriteSetting(QStringLiteral("vibration_enabled"), Settings::values.vibration_enabled, true); | 1064 | WriteSetting(QStringLiteral("vibration_enabled"), Settings::values.vibration_enabled, true); |
| 1024 | WriteSetting(QStringLiteral("motion_device"), | 1065 | WriteSetting(QStringLiteral("motion_device"), |
| @@ -1028,36 +1069,8 @@ void Config::SaveControlValues() { | |||
| 1028 | QString::fromStdString(Settings::values.touch_device), | 1069 | QString::fromStdString(Settings::values.touch_device), |
| 1029 | QStringLiteral("engine:emu_window")); | 1070 | QStringLiteral("engine:emu_window")); |
| 1030 | WriteSetting(QStringLiteral("keyboard_enabled"), Settings::values.keyboard_enabled, false); | 1071 | WriteSetting(QStringLiteral("keyboard_enabled"), Settings::values.keyboard_enabled, false); |
| 1031 | WriteSetting(QStringLiteral("use_touch_from_button"), Settings::values.use_touch_from_button, | ||
| 1032 | false); | ||
| 1033 | WriteSetting(QStringLiteral("touch_from_button_map"), | ||
| 1034 | Settings::values.touch_from_button_map_index, 0); | ||
| 1035 | WriteSetting(QStringLiteral("udp_input_address"), | ||
| 1036 | QString::fromStdString(Settings::values.udp_input_address), | ||
| 1037 | QString::fromUtf8(InputCommon::CemuhookUDP::DEFAULT_ADDR)); | ||
| 1038 | WriteSetting(QStringLiteral("udp_input_port"), Settings::values.udp_input_port, | ||
| 1039 | InputCommon::CemuhookUDP::DEFAULT_PORT); | ||
| 1040 | WriteSetting(QStringLiteral("udp_pad_index"), Settings::values.udp_pad_index, 0); | ||
| 1041 | WriteSetting(QStringLiteral("use_docked_mode"), Settings::values.use_docked_mode, false); | 1072 | WriteSetting(QStringLiteral("use_docked_mode"), Settings::values.use_docked_mode, false); |
| 1042 | 1073 | ||
| 1043 | qt_config->beginWriteArray(QStringLiteral("touch_from_button_maps")); | ||
| 1044 | for (std::size_t p = 0; p < Settings::values.touch_from_button_maps.size(); ++p) { | ||
| 1045 | qt_config->setArrayIndex(static_cast<int>(p)); | ||
| 1046 | WriteSetting(QStringLiteral("name"), | ||
| 1047 | QString::fromStdString(Settings::values.touch_from_button_maps[p].name), | ||
| 1048 | QStringLiteral("default")); | ||
| 1049 | qt_config->beginWriteArray(QStringLiteral("entries")); | ||
| 1050 | for (std::size_t q = 0; q < Settings::values.touch_from_button_maps[p].buttons.size(); | ||
| 1051 | ++q) { | ||
| 1052 | qt_config->setArrayIndex(static_cast<int>(q)); | ||
| 1053 | WriteSetting( | ||
| 1054 | QStringLiteral("bind"), | ||
| 1055 | QString::fromStdString(Settings::values.touch_from_button_maps[p].buttons[q])); | ||
| 1056 | } | ||
| 1057 | qt_config->endArray(); | ||
| 1058 | } | ||
| 1059 | qt_config->endArray(); | ||
| 1060 | |||
| 1061 | qt_config->endGroup(); | 1074 | qt_config->endGroup(); |
| 1062 | } | 1075 | } |
| 1063 | 1076 | ||
diff --git a/src/yuzu/configuration/config.h b/src/yuzu/configuration/config.h index aa929d134..ca0d29c6c 100644 --- a/src/yuzu/configuration/config.h +++ b/src/yuzu/configuration/config.h | |||
| @@ -38,6 +38,7 @@ private: | |||
| 38 | void ReadKeyboardValues(); | 38 | void ReadKeyboardValues(); |
| 39 | void ReadMouseValues(); | 39 | void ReadMouseValues(); |
| 40 | void ReadTouchscreenValues(); | 40 | void ReadTouchscreenValues(); |
| 41 | void ReadMotionTouchValues(); | ||
| 41 | 42 | ||
| 42 | // Read functions bases off the respective config section names. | 43 | // Read functions bases off the respective config section names. |
| 43 | void ReadAudioValues(); | 44 | void ReadAudioValues(); |
| @@ -64,6 +65,7 @@ private: | |||
| 64 | void SaveDebugValues(); | 65 | void SaveDebugValues(); |
| 65 | void SaveMouseValues(); | 66 | void SaveMouseValues(); |
| 66 | void SaveTouchscreenValues(); | 67 | void SaveTouchscreenValues(); |
| 68 | void SaveMotionTouchValues(); | ||
| 67 | 69 | ||
| 68 | // Save functions based off the respective config section names. | 70 | // Save functions based off the respective config section names. |
| 69 | void SaveAudioValues(); | 71 | void SaveAudioValues(); |
diff --git a/src/yuzu/configuration/configure_input.cpp b/src/yuzu/configuration/configure_input.cpp index 62c504286..ae3e31762 100644 --- a/src/yuzu/configuration/configure_input.cpp +++ b/src/yuzu/configuration/configure_input.cpp | |||
| @@ -128,15 +128,14 @@ void ConfigureInput::Initialize(InputCommon::InputSubsystem* input_subsystem) { | |||
| 128 | }); | 128 | }); |
| 129 | connect(advanced, &ConfigureInputAdvanced::CallTouchscreenConfigDialog, | 129 | connect(advanced, &ConfigureInputAdvanced::CallTouchscreenConfigDialog, |
| 130 | [this] { CallConfigureDialog<ConfigureTouchscreenAdvanced>(*this); }); | 130 | [this] { CallConfigureDialog<ConfigureTouchscreenAdvanced>(*this); }); |
| 131 | connect(advanced, &ConfigureInputAdvanced::CallMotionTouchConfigDialog, | ||
| 132 | [this, input_subsystem] { | ||
| 133 | CallConfigureDialog<ConfigureMotionTouch>(*this, input_subsystem); | ||
| 134 | }); | ||
| 131 | 135 | ||
| 132 | connect(ui->buttonClearAll, &QPushButton::clicked, [this] { ClearAll(); }); | 136 | connect(ui->buttonClearAll, &QPushButton::clicked, [this] { ClearAll(); }); |
| 133 | connect(ui->buttonRestoreDefaults, &QPushButton::clicked, [this] { RestoreDefaults(); }); | 137 | connect(ui->buttonRestoreDefaults, &QPushButton::clicked, [this] { RestoreDefaults(); }); |
| 134 | 138 | ||
| 135 | connect(ui->buttonMotionTouch, &QPushButton::clicked, [this] { | ||
| 136 | QDialog* motion_touch_dialog = new ConfigureMotionTouch(this); | ||
| 137 | return motion_touch_dialog->exec(); | ||
| 138 | }); | ||
| 139 | |||
| 140 | RetranslateUI(); | 139 | RetranslateUI(); |
| 141 | LoadConfiguration(); | 140 | LoadConfiguration(); |
| 142 | } | 141 | } |
diff --git a/src/yuzu/configuration/configure_input_advanced.cpp b/src/yuzu/configuration/configure_input_advanced.cpp index db42b826b..c00e3faab 100644 --- a/src/yuzu/configuration/configure_input_advanced.cpp +++ b/src/yuzu/configuration/configure_input_advanced.cpp | |||
| @@ -86,6 +86,8 @@ ConfigureInputAdvanced::ConfigureInputAdvanced(QWidget* parent) | |||
| 86 | connect(ui->mouse_advanced, &QPushButton::clicked, this, [this] { CallMouseConfigDialog(); }); | 86 | connect(ui->mouse_advanced, &QPushButton::clicked, this, [this] { CallMouseConfigDialog(); }); |
| 87 | connect(ui->touchscreen_advanced, &QPushButton::clicked, this, | 87 | connect(ui->touchscreen_advanced, &QPushButton::clicked, this, |
| 88 | [this] { CallTouchscreenConfigDialog(); }); | 88 | [this] { CallTouchscreenConfigDialog(); }); |
| 89 | connect(ui->buttonMotionTouch, &QPushButton::clicked, this, | ||
| 90 | [this] { CallMotionTouchConfigDialog(); }); | ||
| 89 | 91 | ||
| 90 | LoadConfiguration(); | 92 | LoadConfiguration(); |
| 91 | } | 93 | } |
diff --git a/src/yuzu/configuration/configure_input_advanced.h b/src/yuzu/configuration/configure_input_advanced.h index d8fcec52d..50bb87768 100644 --- a/src/yuzu/configuration/configure_input_advanced.h +++ b/src/yuzu/configuration/configure_input_advanced.h | |||
| @@ -28,6 +28,7 @@ signals: | |||
| 28 | void CallDebugControllerDialog(); | 28 | void CallDebugControllerDialog(); |
| 29 | void CallMouseConfigDialog(); | 29 | void CallMouseConfigDialog(); |
| 30 | void CallTouchscreenConfigDialog(); | 30 | void CallTouchscreenConfigDialog(); |
| 31 | void CallMotionTouchConfigDialog(); | ||
| 31 | 32 | ||
| 32 | private: | 33 | private: |
| 33 | void changeEvent(QEvent* event) override; | 34 | void changeEvent(QEvent* event) override; |
diff --git a/src/yuzu/configuration/configure_motion_touch.cpp b/src/yuzu/configuration/configure_motion_touch.cpp index cb79e47ce..1a4b3c996 100644 --- a/src/yuzu/configuration/configure_motion_touch.cpp +++ b/src/yuzu/configuration/configure_motion_touch.cpp | |||
| @@ -8,7 +8,11 @@ | |||
| 8 | #include <QMessageBox> | 8 | #include <QMessageBox> |
| 9 | #include <QPushButton> | 9 | #include <QPushButton> |
| 10 | #include <QVBoxLayout> | 10 | #include <QVBoxLayout> |
| 11 | #include "common/logging/log.h" | ||
| 12 | #include "core/settings.h" | ||
| 11 | #include "input_common/main.h" | 13 | #include "input_common/main.h" |
| 14 | #include "input_common/udp/client.h" | ||
| 15 | #include "input_common/udp/udp.h" | ||
| 12 | #include "ui_configure_motion_touch.h" | 16 | #include "ui_configure_motion_touch.h" |
| 13 | #include "yuzu/configuration/configure_motion_touch.h" | 17 | #include "yuzu/configuration/configure_motion_touch.h" |
| 14 | #include "yuzu/configuration/configure_touch_from_button.h" | 18 | #include "yuzu/configuration/configure_touch_from_button.h" |
| @@ -21,8 +25,9 @@ CalibrationConfigurationDialog::CalibrationConfigurationDialog(QWidget* parent, | |||
| 21 | status_label = new QLabel(tr("Communicating with the server...")); | 25 | status_label = new QLabel(tr("Communicating with the server...")); |
| 22 | cancel_button = new QPushButton(tr("Cancel")); | 26 | cancel_button = new QPushButton(tr("Cancel")); |
| 23 | connect(cancel_button, &QPushButton::clicked, this, [this] { | 27 | connect(cancel_button, &QPushButton::clicked, this, [this] { |
| 24 | if (!completed) | 28 | if (!completed) { |
| 25 | job->Stop(); | 29 | job->Stop(); |
| 30 | } | ||
| 26 | accept(); | 31 | accept(); |
| 27 | }); | 32 | }); |
| 28 | layout->addWidget(status_label); | 33 | layout->addWidget(status_label); |
| @@ -61,36 +66,40 @@ CalibrationConfigurationDialog::CalibrationConfigurationDialog(QWidget* parent, | |||
| 61 | 66 | ||
| 62 | CalibrationConfigurationDialog::~CalibrationConfigurationDialog() = default; | 67 | CalibrationConfigurationDialog::~CalibrationConfigurationDialog() = default; |
| 63 | 68 | ||
| 64 | void CalibrationConfigurationDialog::UpdateLabelText(QString text) { | 69 | void CalibrationConfigurationDialog::UpdateLabelText(const QString& text) { |
| 65 | status_label->setText(text); | 70 | status_label->setText(text); |
| 66 | } | 71 | } |
| 67 | 72 | ||
| 68 | void CalibrationConfigurationDialog::UpdateButtonText(QString text) { | 73 | void CalibrationConfigurationDialog::UpdateButtonText(const QString& text) { |
| 69 | cancel_button->setText(text); | 74 | cancel_button->setText(text); |
| 70 | } | 75 | } |
| 71 | 76 | ||
| 72 | const std::array<std::pair<const char*, const char*>, 2> MotionProviders = { | 77 | constexpr std::array<std::pair<const char*, const char*>, 2> MotionProviders = {{ |
| 73 | {{"motion_emu", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "Mouse (Right Click)")}, | 78 | {"motion_emu", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "Mouse (Right Click)")}, |
| 74 | {"cemuhookudp", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "CemuhookUDP")}}}; | 79 | {"cemuhookudp", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "CemuhookUDP")}, |
| 80 | }}; | ||
| 75 | 81 | ||
| 76 | const std::array<std::pair<const char*, const char*>, 2> TouchProviders = { | 82 | constexpr std::array<std::pair<const char*, const char*>, 2> TouchProviders = {{ |
| 77 | {{"emu_window", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "Emulator Window")}, | 83 | {"emu_window", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "Emulator Window")}, |
| 78 | {"cemuhookudp", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "CemuhookUDP")}}}; | 84 | {"cemuhookudp", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "CemuhookUDP")}, |
| 85 | }}; | ||
| 79 | 86 | ||
| 80 | ConfigureMotionTouch::ConfigureMotionTouch(QWidget* parent) | 87 | ConfigureMotionTouch::ConfigureMotionTouch(QWidget* parent, |
| 81 | : QDialog(parent), ui(std::make_unique<Ui::ConfigureMotionTouch>()) { | 88 | InputCommon::InputSubsystem* input_subsystem_) |
| 89 | : QDialog(parent), input_subsystem{input_subsystem_}, | ||
| 90 | ui(std::make_unique<Ui::ConfigureMotionTouch>()) { | ||
| 82 | ui->setupUi(this); | 91 | ui->setupUi(this); |
| 83 | for (auto [provider, name] : MotionProviders) { | 92 | for (const auto [provider, name] : MotionProviders) { |
| 84 | ui->motion_provider->addItem(tr(name), QString::fromUtf8(provider)); | 93 | ui->motion_provider->addItem(tr(name), QString::fromUtf8(provider)); |
| 85 | } | 94 | } |
| 86 | for (auto [provider, name] : TouchProviders) { | 95 | for (const auto [provider, name] : TouchProviders) { |
| 87 | ui->touch_provider->addItem(tr(name), QString::fromUtf8(provider)); | 96 | ui->touch_provider->addItem(tr(name), QString::fromUtf8(provider)); |
| 88 | } | 97 | } |
| 89 | 98 | ||
| 90 | ui->udp_learn_more->setOpenExternalLinks(true); | 99 | ui->udp_learn_more->setOpenExternalLinks(true); |
| 91 | ui->udp_learn_more->setText( | 100 | ui->udp_learn_more->setText( |
| 92 | tr("<a " | 101 | tr("<a " |
| 93 | "href='https://citra-emu.org/wiki/" | 102 | "href='https://yuzu-emu.org/wiki/" |
| 94 | "using-a-controller-or-android-phone-for-motion-or-touch-input'><span " | 103 | "using-a-controller-or-android-phone-for-motion-or-touch-input'><span " |
| 95 | "style=\"text-decoration: underline; color:#039be5;\">Learn More</span></a>")); | 104 | "style=\"text-decoration: underline; color:#039be5;\">Learn More</span></a>")); |
| 96 | 105 | ||
| @@ -130,10 +139,11 @@ void ConfigureMotionTouch::SetConfiguration() { | |||
| 130 | } | 139 | } |
| 131 | 140 | ||
| 132 | void ConfigureMotionTouch::UpdateUiDisplay() { | 141 | void ConfigureMotionTouch::UpdateUiDisplay() { |
| 133 | std::string motion_engine = ui->motion_provider->currentData().toString().toStdString(); | 142 | const QString motion_engine = ui->motion_provider->currentData().toString(); |
| 134 | std::string touch_engine = ui->touch_provider->currentData().toString().toStdString(); | 143 | const QString touch_engine = ui->touch_provider->currentData().toString(); |
| 144 | QString cemuhook_udp = QStringLiteral("cemuhookudp"); | ||
| 135 | 145 | ||
| 136 | if (motion_engine == "motion_emu") { | 146 | if (motion_engine == QStringLiteral("motion_emu")) { |
| 137 | ui->motion_sensitivity_label->setVisible(true); | 147 | ui->motion_sensitivity_label->setVisible(true); |
| 138 | ui->motion_sensitivity->setVisible(true); | 148 | ui->motion_sensitivity->setVisible(true); |
| 139 | } else { | 149 | } else { |
| @@ -141,20 +151,19 @@ void ConfigureMotionTouch::UpdateUiDisplay() { | |||
| 141 | ui->motion_sensitivity->setVisible(false); | 151 | ui->motion_sensitivity->setVisible(false); |
| 142 | } | 152 | } |
| 143 | 153 | ||
| 144 | if (touch_engine == "cemuhookudp") { | 154 | if (touch_engine == cemuhook_udp) { |
| 145 | ui->touch_calibration->setVisible(true); | 155 | ui->touch_calibration->setVisible(true); |
| 146 | ui->touch_calibration_config->setVisible(true); | 156 | ui->touch_calibration_config->setVisible(true); |
| 147 | ui->touch_calibration_label->setVisible(true); | 157 | ui->touch_calibration_label->setVisible(true); |
| 148 | ui->touch_calibration->setText(QStringLiteral("(%1, %2) - (%3, %4)") | 158 | ui->touch_calibration->setText( |
| 149 | .arg(QString::number(min_x), QString::number(min_y), | 159 | QStringLiteral("(%1, %2) - (%3, %4)").arg(min_x).arg(min_y).arg(max_x).arg(max_y)); |
| 150 | QString::number(max_x), QString::number(max_y))); | ||
| 151 | } else { | 160 | } else { |
| 152 | ui->touch_calibration->setVisible(false); | 161 | ui->touch_calibration->setVisible(false); |
| 153 | ui->touch_calibration_config->setVisible(false); | 162 | ui->touch_calibration_config->setVisible(false); |
| 154 | ui->touch_calibration_label->setVisible(false); | 163 | ui->touch_calibration_label->setVisible(false); |
| 155 | } | 164 | } |
| 156 | 165 | ||
| 157 | if (motion_engine == "cemuhookudp" || touch_engine == "cemuhookudp") { | 166 | if (motion_engine == cemuhook_udp || touch_engine == cemuhook_udp) { |
| 158 | ui->udp_config_group_box->setVisible(true); | 167 | ui->udp_config_group_box->setVisible(true); |
| 159 | } else { | 168 | } else { |
| 160 | ui->udp_config_group_box->setVisible(false); | 169 | ui->udp_config_group_box->setVisible(false); |
| @@ -162,11 +171,9 @@ void ConfigureMotionTouch::UpdateUiDisplay() { | |||
| 162 | } | 171 | } |
| 163 | 172 | ||
| 164 | void ConfigureMotionTouch::ConnectEvents() { | 173 | void ConfigureMotionTouch::ConnectEvents() { |
| 165 | connect(ui->motion_provider, | 174 | connect(ui->motion_provider, qOverload<int>(&QComboBox::currentIndexChanged), this, |
| 166 | static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, | ||
| 167 | [this](int index) { UpdateUiDisplay(); }); | 175 | [this](int index) { UpdateUiDisplay(); }); |
| 168 | connect(ui->touch_provider, | 176 | connect(ui->touch_provider, qOverload<int>(&QComboBox::currentIndexChanged), this, |
| 169 | static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, | ||
| 170 | [this](int index) { UpdateUiDisplay(); }); | 177 | [this](int index) { UpdateUiDisplay(); }); |
| 171 | connect(ui->udp_test, &QPushButton::clicked, this, &ConfigureMotionTouch::OnCemuhookUDPTest); | 178 | connect(ui->udp_test, &QPushButton::clicked, this, &ConfigureMotionTouch::OnCemuhookUDPTest); |
| 172 | connect(ui->touch_calibration_config, &QPushButton::clicked, this, | 179 | connect(ui->touch_calibration_config, &QPushButton::clicked, this, |
| @@ -174,8 +181,9 @@ void ConfigureMotionTouch::ConnectEvents() { | |||
| 174 | connect(ui->touch_from_button_config_btn, &QPushButton::clicked, this, | 181 | connect(ui->touch_from_button_config_btn, &QPushButton::clicked, this, |
| 175 | &ConfigureMotionTouch::OnConfigureTouchFromButton); | 182 | &ConfigureMotionTouch::OnConfigureTouchFromButton); |
| 176 | connect(ui->buttonBox, &QDialogButtonBox::rejected, this, [this] { | 183 | connect(ui->buttonBox, &QDialogButtonBox::rejected, this, [this] { |
| 177 | if (CanCloseDialog()) | 184 | if (CanCloseDialog()) { |
| 178 | reject(); | 185 | reject(); |
| 186 | } | ||
| 179 | }); | 187 | }); |
| 180 | } | 188 | } |
| 181 | 189 | ||
| @@ -199,15 +207,15 @@ void ConfigureMotionTouch::OnCemuhookUDPTest() { | |||
| 199 | void ConfigureMotionTouch::OnConfigureTouchCalibration() { | 207 | void ConfigureMotionTouch::OnConfigureTouchCalibration() { |
| 200 | ui->touch_calibration_config->setEnabled(false); | 208 | ui->touch_calibration_config->setEnabled(false); |
| 201 | ui->touch_calibration_config->setText(tr("Configuring")); | 209 | ui->touch_calibration_config->setText(tr("Configuring")); |
| 202 | CalibrationConfigurationDialog* dialog = new CalibrationConfigurationDialog( | 210 | CalibrationConfigurationDialog dialog( |
| 203 | this, ui->udp_server->text().toStdString(), static_cast<u16>(ui->udp_port->text().toUInt()), | 211 | this, ui->udp_server->text().toStdString(), static_cast<u16>(ui->udp_port->text().toUInt()), |
| 204 | static_cast<u8>(ui->udp_pad_index->currentIndex()), 24872); | 212 | static_cast<u8>(ui->udp_pad_index->currentIndex()), 24872); |
| 205 | dialog->exec(); | 213 | dialog.exec(); |
| 206 | if (dialog->completed) { | 214 | if (dialog.completed) { |
| 207 | min_x = dialog->min_x; | 215 | min_x = dialog.min_x; |
| 208 | min_y = dialog->min_y; | 216 | min_y = dialog.min_y; |
| 209 | max_x = dialog->max_x; | 217 | max_x = dialog.max_x; |
| 210 | max_y = dialog->max_y; | 218 | max_y = dialog.max_y; |
| 211 | LOG_INFO(Frontend, | 219 | LOG_INFO(Frontend, |
| 212 | "UDP touchpad calibration config success: min_x={}, min_y={}, max_x={}, max_y={}", | 220 | "UDP touchpad calibration config success: min_x={}, min_y={}, max_x={}, max_y={}", |
| 213 | min_x, min_y, max_x, max_y); | 221 | min_x, min_y, max_x, max_y); |
| @@ -220,10 +228,11 @@ void ConfigureMotionTouch::OnConfigureTouchCalibration() { | |||
| 220 | } | 228 | } |
| 221 | 229 | ||
| 222 | void ConfigureMotionTouch::closeEvent(QCloseEvent* event) { | 230 | void ConfigureMotionTouch::closeEvent(QCloseEvent* event) { |
| 223 | if (CanCloseDialog()) | 231 | if (CanCloseDialog()) { |
| 224 | event->accept(); | 232 | event->accept(); |
| 225 | else | 233 | } else { |
| 226 | event->ignore(); | 234 | event->ignore(); |
| 235 | } | ||
| 227 | } | 236 | } |
| 228 | 237 | ||
| 229 | void ConfigureMotionTouch::ShowUDPTestResult(bool result) { | 238 | void ConfigureMotionTouch::ShowUDPTestResult(bool result) { |
| @@ -242,7 +251,7 @@ void ConfigureMotionTouch::ShowUDPTestResult(bool result) { | |||
| 242 | } | 251 | } |
| 243 | 252 | ||
| 244 | void ConfigureMotionTouch::OnConfigureTouchFromButton() { | 253 | void ConfigureMotionTouch::OnConfigureTouchFromButton() { |
| 245 | ConfigureTouchFromButton dialog{this, touch_from_button_maps, | 254 | ConfigureTouchFromButton dialog{this, touch_from_button_maps, input_subsystem, |
| 246 | ui->touch_from_button_map->currentIndex()}; | 255 | ui->touch_from_button_map->currentIndex()}; |
| 247 | if (dialog.exec() != QDialog::Accepted) { | 256 | if (dialog.exec() != QDialog::Accepted) { |
| 248 | return; | 257 | return; |
| @@ -269,8 +278,9 @@ bool ConfigureMotionTouch::CanCloseDialog() { | |||
| 269 | } | 278 | } |
| 270 | 279 | ||
| 271 | void ConfigureMotionTouch::ApplyConfiguration() { | 280 | void ConfigureMotionTouch::ApplyConfiguration() { |
| 272 | if (!CanCloseDialog()) | 281 | if (!CanCloseDialog()) { |
| 273 | return; | 282 | return; |
| 283 | } | ||
| 274 | 284 | ||
| 275 | std::string motion_engine = ui->motion_provider->currentData().toString().toStdString(); | 285 | std::string motion_engine = ui->motion_provider->currentData().toString().toStdString(); |
| 276 | std::string touch_engine = ui->touch_provider->currentData().toString().toStdString(); | 286 | std::string touch_engine = ui->touch_provider->currentData().toString().toStdString(); |
| @@ -298,7 +308,7 @@ void ConfigureMotionTouch::ApplyConfiguration() { | |||
| 298 | Settings::values.udp_input_address = ui->udp_server->text().toStdString(); | 308 | Settings::values.udp_input_address = ui->udp_server->text().toStdString(); |
| 299 | Settings::values.udp_input_port = static_cast<u16>(ui->udp_port->text().toInt()); | 309 | Settings::values.udp_input_port = static_cast<u16>(ui->udp_port->text().toInt()); |
| 300 | Settings::values.udp_pad_index = static_cast<u8>(ui->udp_pad_index->currentIndex()); | 310 | Settings::values.udp_pad_index = static_cast<u8>(ui->udp_pad_index->currentIndex()); |
| 301 | InputCommon::ReloadInputDevices(); | 311 | input_subsystem->ReloadInputDevices(); |
| 302 | 312 | ||
| 303 | accept(); | 313 | accept(); |
| 304 | } | 314 | } |
diff --git a/src/yuzu/configuration/configure_motion_touch.h b/src/yuzu/configuration/configure_motion_touch.h index 1a4f50022..2a7cdfed7 100644 --- a/src/yuzu/configuration/configure_motion_touch.h +++ b/src/yuzu/configuration/configure_motion_touch.h | |||
| @@ -7,29 +7,30 @@ | |||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | #include <QDialog> | 8 | #include <QDialog> |
| 9 | #include "common/param_package.h" | 9 | #include "common/param_package.h" |
| 10 | #include "core/settings.h" | ||
| 11 | #include "input_common/udp/client.h" | ||
| 12 | #include "input_common/udp/udp.h" | ||
| 13 | 10 | ||
| 14 | class QVBoxLayout; | ||
| 15 | class QLabel; | 11 | class QLabel; |
| 16 | class QPushButton; | 12 | class QPushButton; |
| 13 | class QVBoxLayout; | ||
| 17 | 14 | ||
| 18 | namespace Ui { | 15 | namespace Ui { |
| 19 | class ConfigureMotionTouch; | 16 | class ConfigureMotionTouch; |
| 20 | } | 17 | } |
| 21 | 18 | ||
| 19 | namespace InputCommon::CemuhookUDP { | ||
| 20 | class CalibrationConfigurationJob; | ||
| 21 | } | ||
| 22 | |||
| 22 | /// A dialog for touchpad calibration configuration. | 23 | /// A dialog for touchpad calibration configuration. |
| 23 | class CalibrationConfigurationDialog : public QDialog { | 24 | class CalibrationConfigurationDialog : public QDialog { |
| 24 | Q_OBJECT | 25 | Q_OBJECT |
| 25 | public: | 26 | public: |
| 26 | explicit CalibrationConfigurationDialog(QWidget* parent, const std::string& host, u16 port, | 27 | explicit CalibrationConfigurationDialog(QWidget* parent, const std::string& host, u16 port, |
| 27 | u8 pad_index, u16 client_id); | 28 | u8 pad_index, u16 client_id); |
| 28 | ~CalibrationConfigurationDialog(); | 29 | ~CalibrationConfigurationDialog() override; |
| 29 | 30 | ||
| 30 | private: | 31 | private: |
| 31 | Q_INVOKABLE void UpdateLabelText(QString text); | 32 | Q_INVOKABLE void UpdateLabelText(const QString& text); |
| 32 | Q_INVOKABLE void UpdateButtonText(QString text); | 33 | Q_INVOKABLE void UpdateButtonText(const QString& text); |
| 33 | 34 | ||
| 34 | QVBoxLayout* layout; | 35 | QVBoxLayout* layout; |
| 35 | QLabel* status_label; | 36 | QLabel* status_label; |
| @@ -38,7 +39,10 @@ private: | |||
| 38 | 39 | ||
| 39 | // Configuration results | 40 | // Configuration results |
| 40 | bool completed{}; | 41 | bool completed{}; |
| 41 | u16 min_x, min_y, max_x, max_y; | 42 | u16 min_x{}; |
| 43 | u16 min_y{}; | ||
| 44 | u16 max_x{}; | ||
| 45 | u16 max_y{}; | ||
| 42 | 46 | ||
| 43 | friend class ConfigureMotionTouch; | 47 | friend class ConfigureMotionTouch; |
| 44 | }; | 48 | }; |
| @@ -47,7 +51,7 @@ class ConfigureMotionTouch : public QDialog { | |||
| 47 | Q_OBJECT | 51 | Q_OBJECT |
| 48 | 52 | ||
| 49 | public: | 53 | public: |
| 50 | explicit ConfigureMotionTouch(QWidget* parent = nullptr); | 54 | explicit ConfigureMotionTouch(QWidget* parent, InputCommon::InputSubsystem* input_subsystem_); |
| 51 | ~ConfigureMotionTouch() override; | 55 | ~ConfigureMotionTouch() override; |
| 52 | 56 | ||
| 53 | public slots: | 57 | public slots: |
| @@ -69,9 +73,14 @@ private: | |||
| 69 | std::unique_ptr<Ui::ConfigureMotionTouch> ui; | 73 | std::unique_ptr<Ui::ConfigureMotionTouch> ui; |
| 70 | 74 | ||
| 71 | // Coordinate system of the CemuhookUDP touch provider | 75 | // Coordinate system of the CemuhookUDP touch provider |
| 72 | int min_x, min_y, max_x, max_y; | 76 | int min_x{}; |
| 77 | int min_y{}; | ||
| 78 | int max_x{}; | ||
| 79 | int max_y{}; | ||
| 73 | 80 | ||
| 74 | bool udp_test_in_progress{}; | 81 | bool udp_test_in_progress{}; |
| 75 | 82 | ||
| 83 | InputCommon::InputSubsystem* input_subsystem; | ||
| 84 | |||
| 76 | std::vector<Settings::TouchFromButtonMap> touch_from_button_maps; | 85 | std::vector<Settings::TouchFromButtonMap> touch_from_button_maps; |
| 77 | }; | 86 | }; |
diff --git a/src/yuzu/configuration/configure_touch_from_button.cpp b/src/yuzu/configuration/configure_touch_from_button.cpp index 0a0448cea..0147e2ac3 100644 --- a/src/yuzu/configuration/configure_touch_from_button.cpp +++ b/src/yuzu/configuration/configure_touch_from_button.cpp | |||
| @@ -10,6 +10,8 @@ | |||
| 10 | #include <QStandardItemModel> | 10 | #include <QStandardItemModel> |
| 11 | #include <QTimer> | 11 | #include <QTimer> |
| 12 | #include "common/param_package.h" | 12 | #include "common/param_package.h" |
| 13 | #include "core/frontend/framebuffer_layout.h" | ||
| 14 | #include "core/settings.h" | ||
| 13 | #include "input_common/main.h" | 15 | #include "input_common/main.h" |
| 14 | #include "ui_configure_touch_from_button.h" | 16 | #include "ui_configure_touch_from_button.h" |
| 15 | #include "yuzu/configuration/configure_touch_from_button.h" | 17 | #include "yuzu/configuration/configure_touch_from_button.h" |
| @@ -68,15 +70,16 @@ static QString ButtonToText(const Common::ParamPackage& param) { | |||
| 68 | 70 | ||
| 69 | ConfigureTouchFromButton::ConfigureTouchFromButton( | 71 | ConfigureTouchFromButton::ConfigureTouchFromButton( |
| 70 | QWidget* parent, const std::vector<Settings::TouchFromButtonMap>& touch_maps, | 72 | QWidget* parent, const std::vector<Settings::TouchFromButtonMap>& touch_maps, |
| 71 | const int default_index) | 73 | InputCommon::InputSubsystem* input_subsystem_, const int default_index) |
| 72 | : QDialog(parent), ui(std::make_unique<Ui::ConfigureTouchFromButton>()), touch_maps(touch_maps), | 74 | : QDialog(parent), ui(std::make_unique<Ui::ConfigureTouchFromButton>()), |
| 73 | selected_index(default_index), timeout_timer(std::make_unique<QTimer>()), | 75 | touch_maps(touch_maps), input_subsystem{input_subsystem_}, selected_index(default_index), |
| 74 | poll_timer(std::make_unique<QTimer>()) { | 76 | timeout_timer(std::make_unique<QTimer>()), poll_timer(std::make_unique<QTimer>()) { |
| 75 | 77 | ||
| 76 | ui->setupUi(this); | 78 | ui->setupUi(this); |
| 77 | binding_list_model = std::make_unique<QStandardItemModel>(0, 3, this); | 79 | binding_list_model = new QStandardItemModel(0, 3, this); |
| 78 | binding_list_model->setHorizontalHeaderLabels({tr("Button"), tr("X"), tr("Y")}); | 80 | binding_list_model->setHorizontalHeaderLabels( |
| 79 | ui->binding_list->setModel(binding_list_model.get()); | 81 | {tr("Button"), tr("X", "X axis"), tr("Y", "Y axis")}); |
| 82 | ui->binding_list->setModel(binding_list_model); | ||
| 80 | ui->bottom_screen->SetCoordLabel(ui->coord_label); | 83 | ui->bottom_screen->SetCoordLabel(ui->coord_label); |
| 81 | 84 | ||
| 82 | SetConfiguration(); | 85 | SetConfiguration(); |
| @@ -92,11 +95,12 @@ void ConfigureTouchFromButton::showEvent(QShowEvent* ev) { | |||
| 92 | // width values are not valid in the constructor | 95 | // width values are not valid in the constructor |
| 93 | const int w = | 96 | const int w = |
| 94 | ui->binding_list->viewport()->contentsRect().width() / binding_list_model->columnCount(); | 97 | ui->binding_list->viewport()->contentsRect().width() / binding_list_model->columnCount(); |
| 95 | if (w > 0) { | 98 | if (w <= 0) { |
| 96 | ui->binding_list->setColumnWidth(0, w); | 99 | return; |
| 97 | ui->binding_list->setColumnWidth(1, w); | ||
| 98 | ui->binding_list->setColumnWidth(2, w); | ||
| 99 | } | 100 | } |
| 101 | ui->binding_list->setColumnWidth(0, w); | ||
| 102 | ui->binding_list->setColumnWidth(1, w); | ||
| 103 | ui->binding_list->setColumnWidth(2, w); | ||
| 100 | } | 104 | } |
| 101 | 105 | ||
| 102 | void ConfigureTouchFromButton::SetConfiguration() { | 106 | void ConfigureTouchFromButton::SetConfiguration() { |
| @@ -122,7 +126,7 @@ void ConfigureTouchFromButton::UpdateUiDisplay() { | |||
| 122 | QStandardItem* ycoord = new QStandardItem(QString::number(package.Get("y", 0))); | 126 | QStandardItem* ycoord = new QStandardItem(QString::number(package.Get("y", 0))); |
| 123 | binding_list_model->appendRow({button, xcoord, ycoord}); | 127 | binding_list_model->appendRow({button, xcoord, ycoord}); |
| 124 | 128 | ||
| 125 | int dot = ui->bottom_screen->AddDot(package.Get("x", 0), package.Get("y", 0)); | 129 | const int dot = ui->bottom_screen->AddDot(package.Get("x", 0), package.Get("y", 0)); |
| 126 | button->setData(dot, DataRoleDot); | 130 | button->setData(dot, DataRoleDot); |
| 127 | } | 131 | } |
| 128 | } | 132 | } |
| @@ -144,7 +148,7 @@ void ConfigureTouchFromButton::ConnectEvents() { | |||
| 144 | &ConfigureTouchFromButton::EditBinding); | 148 | &ConfigureTouchFromButton::EditBinding); |
| 145 | connect(ui->binding_list->selectionModel(), &QItemSelectionModel::selectionChanged, this, | 149 | connect(ui->binding_list->selectionModel(), &QItemSelectionModel::selectionChanged, this, |
| 146 | &ConfigureTouchFromButton::OnBindingSelection); | 150 | &ConfigureTouchFromButton::OnBindingSelection); |
| 147 | connect(binding_list_model.get(), &QStandardItemModel::itemChanged, this, | 151 | connect(binding_list_model, &QStandardItemModel::itemChanged, this, |
| 148 | &ConfigureTouchFromButton::OnBindingChanged); | 152 | &ConfigureTouchFromButton::OnBindingChanged); |
| 149 | connect(ui->binding_list->model(), &QStandardItemModel::rowsAboutToBeRemoved, this, | 153 | connect(ui->binding_list->model(), &QStandardItemModel::rowsAboutToBeRemoved, this, |
| 150 | &ConfigureTouchFromButton::OnBindingDeleted); | 154 | &ConfigureTouchFromButton::OnBindingDeleted); |
| @@ -231,7 +235,7 @@ void ConfigureTouchFromButton::GetButtonInput(const int row_index, const bool is | |||
| 231 | 235 | ||
| 232 | input_setter = [this, row_index, is_new](const Common::ParamPackage& params, | 236 | input_setter = [this, row_index, is_new](const Common::ParamPackage& params, |
| 233 | const bool cancel) { | 237 | const bool cancel) { |
| 234 | auto cell = binding_list_model->item(row_index, 0); | 238 | auto* cell = binding_list_model->item(row_index, 0); |
| 235 | if (cancel) { | 239 | if (cancel) { |
| 236 | if (is_new) { | 240 | if (is_new) { |
| 237 | binding_list_model->removeRow(row_index); | 241 | binding_list_model->removeRow(row_index); |
| @@ -245,7 +249,7 @@ void ConfigureTouchFromButton::GetButtonInput(const int row_index, const bool is | |||
| 245 | } | 249 | } |
| 246 | }; | 250 | }; |
| 247 | 251 | ||
| 248 | device_pollers = InputCommon::Polling::GetPollers(InputCommon::Polling::DeviceType::Button); | 252 | device_pollers = input_subsystem->GetPollers(InputCommon::Polling::DeviceType::Button); |
| 249 | 253 | ||
| 250 | for (auto& poller : device_pollers) { | 254 | for (auto& poller : device_pollers) { |
| 251 | poller->Start(); | 255 | poller->Start(); |
| @@ -259,15 +263,15 @@ void ConfigureTouchFromButton::GetButtonInput(const int row_index, const bool is | |||
| 259 | } | 263 | } |
| 260 | 264 | ||
| 261 | void ConfigureTouchFromButton::NewBinding(const QPoint& pos) { | 265 | void ConfigureTouchFromButton::NewBinding(const QPoint& pos) { |
| 262 | QStandardItem* button = new QStandardItem(); | 266 | auto* button = new QStandardItem(); |
| 263 | button->setEditable(false); | 267 | button->setEditable(false); |
| 264 | QStandardItem* xcoord = new QStandardItem(QString::number(pos.x())); | 268 | auto* x_coord = new QStandardItem(QString::number(pos.x())); |
| 265 | QStandardItem* ycoord = new QStandardItem(QString::number(pos.y())); | 269 | auto* y_coord = new QStandardItem(QString::number(pos.y())); |
| 266 | 270 | ||
| 267 | const int dot_id = ui->bottom_screen->AddDot(pos.x(), pos.y()); | 271 | const int dot_id = ui->bottom_screen->AddDot(pos.x(), pos.y()); |
| 268 | button->setData(dot_id, DataRoleDot); | 272 | button->setData(dot_id, DataRoleDot); |
| 269 | 273 | ||
| 270 | binding_list_model->appendRow({button, xcoord, ycoord}); | 274 | binding_list_model->appendRow({button, x_coord, y_coord}); |
| 271 | ui->binding_list->setFocus(); | 275 | ui->binding_list->setFocus(); |
| 272 | ui->binding_list->setCurrentIndex(button->index()); | 276 | ui->binding_list->setCurrentIndex(button->index()); |
| 273 | 277 | ||
| @@ -282,11 +286,11 @@ void ConfigureTouchFromButton::EditBinding(const QModelIndex& qi) { | |||
| 282 | 286 | ||
| 283 | void ConfigureTouchFromButton::DeleteBinding() { | 287 | void ConfigureTouchFromButton::DeleteBinding() { |
| 284 | const int row_index = ui->binding_list->currentIndex().row(); | 288 | const int row_index = ui->binding_list->currentIndex().row(); |
| 285 | if (row_index >= 0) { | 289 | if (row_index < 0) { |
| 286 | ui->bottom_screen->RemoveDot( | 290 | return; |
| 287 | binding_list_model->index(row_index, 0).data(DataRoleDot).toInt()); | ||
| 288 | binding_list_model->removeRow(row_index); | ||
| 289 | } | 291 | } |
| 292 | ui->bottom_screen->RemoveDot(binding_list_model->index(row_index, 0).data(DataRoleDot).toInt()); | ||
| 293 | binding_list_model->removeRow(row_index); | ||
| 290 | } | 294 | } |
| 291 | 295 | ||
| 292 | void ConfigureTouchFromButton::OnBindingSelection(const QItemSelection& selected, | 296 | void ConfigureTouchFromButton::OnBindingSelection(const QItemSelection& selected, |
| @@ -329,7 +333,7 @@ void ConfigureTouchFromButton::OnBindingChanged(QStandardItem* item) { | |||
| 329 | 333 | ||
| 330 | void ConfigureTouchFromButton::OnBindingDeleted(const QModelIndex& parent, int first, int last) { | 334 | void ConfigureTouchFromButton::OnBindingDeleted(const QModelIndex& parent, int first, int last) { |
| 331 | for (int i = first; i <= last; ++i) { | 335 | for (int i = first; i <= last; ++i) { |
| 332 | auto ix = binding_list_model->index(i, 0); | 336 | const auto ix = binding_list_model->index(i, 0); |
| 333 | if (!ix.isValid()) { | 337 | if (!ix.isValid()) { |
| 334 | return; | 338 | return; |
| 335 | } | 339 | } |
| @@ -422,7 +426,7 @@ int TouchScreenPreview::AddDot(const int device_x, const int device_y) { | |||
| 422 | dot_font.setStyleHint(QFont::Monospace); | 426 | dot_font.setStyleHint(QFont::Monospace); |
| 423 | dot_font.setPointSize(20); | 427 | dot_font.setPointSize(20); |
| 424 | 428 | ||
| 425 | QLabel* dot = new QLabel(this); | 429 | auto* dot = new QLabel(this); |
| 426 | dot->setAttribute(Qt::WA_TranslucentBackground); | 430 | dot->setAttribute(Qt::WA_TranslucentBackground); |
| 427 | dot->setFont(dot_font); | 431 | dot->setFont(dot_font); |
| 428 | dot->setText(QChar(0xD7)); // U+00D7 Multiplication Sign | 432 | dot->setText(QChar(0xD7)); // U+00D7 Multiplication Sign |
| @@ -440,13 +444,14 @@ int TouchScreenPreview::AddDot(const int device_x, const int device_y) { | |||
| 440 | } | 444 | } |
| 441 | 445 | ||
| 442 | void TouchScreenPreview::RemoveDot(const int id) { | 446 | void TouchScreenPreview::RemoveDot(const int id) { |
| 443 | for (auto dot_it = dots.begin(); dot_it != dots.end(); ++dot_it) { | 447 | const auto iter = std::find_if(dots.begin(), dots.end(), |
| 444 | if (dot_it->first == id) { | 448 | [id](const auto& entry) { return entry.first == id; }); |
| 445 | dot_it->second->deleteLater(); | 449 | if (iter == dots.cend()) { |
| 446 | dots.erase(dot_it); | 450 | return; |
| 447 | return; | ||
| 448 | } | ||
| 449 | } | 451 | } |
| 452 | |||
| 453 | iter->second->deleteLater(); | ||
| 454 | dots.erase(iter); | ||
| 450 | } | 455 | } |
| 451 | 456 | ||
| 452 | void TouchScreenPreview::HighlightDot(const int id, const bool active) const { | 457 | void TouchScreenPreview::HighlightDot(const int id, const bool active) const { |
| @@ -470,14 +475,15 @@ void TouchScreenPreview::HighlightDot(const int id, const bool active) const { | |||
| 470 | } | 475 | } |
| 471 | 476 | ||
| 472 | void TouchScreenPreview::MoveDot(const int id, const int device_x, const int device_y) const { | 477 | void TouchScreenPreview::MoveDot(const int id, const int device_x, const int device_y) const { |
| 473 | for (const auto& dot : dots) { | 478 | const auto iter = std::find_if(dots.begin(), dots.end(), |
| 474 | if (dot.first == id) { | 479 | [id](const auto& entry) { return entry.first == id; }); |
| 475 | dot.second->setProperty(PropX, device_x); | 480 | if (iter == dots.cend()) { |
| 476 | dot.second->setProperty(PropY, device_y); | 481 | return; |
| 477 | PositionDot(dot.second, device_x, device_y); | ||
| 478 | return; | ||
| 479 | } | ||
| 480 | } | 482 | } |
| 483 | |||
| 484 | iter->second->setProperty(PropX, device_x); | ||
| 485 | iter->second->setProperty(PropY, device_y); | ||
| 486 | PositionDot(iter->second, device_x, device_y); | ||
| 481 | } | 487 | } |
| 482 | 488 | ||
| 483 | void TouchScreenPreview::resizeEvent(QResizeEvent* event) { | 489 | void TouchScreenPreview::resizeEvent(QResizeEvent* event) { |
| @@ -521,11 +527,12 @@ void TouchScreenPreview::leaveEvent(QEvent* event) { | |||
| 521 | } | 527 | } |
| 522 | 528 | ||
| 523 | void TouchScreenPreview::mousePressEvent(QMouseEvent* event) { | 529 | void TouchScreenPreview::mousePressEvent(QMouseEvent* event) { |
| 524 | if (event->button() == Qt::MouseButton::LeftButton) { | 530 | if (event->button() != Qt::MouseButton::LeftButton) { |
| 525 | const auto pos = MapToDeviceCoords(event->x(), event->y()); | 531 | return; |
| 526 | if (pos) { | 532 | } |
| 527 | emit DotAdded(*pos); | 533 | const auto pos = MapToDeviceCoords(event->x(), event->y()); |
| 528 | } | 534 | if (pos) { |
| 535 | emit DotAdded(*pos); | ||
| 529 | } | 536 | } |
| 530 | } | 537 | } |
| 531 | 538 | ||
| @@ -601,12 +608,17 @@ std::optional<QPoint> TouchScreenPreview::MapToDeviceCoords(const int screen_x, | |||
| 601 | 608 | ||
| 602 | void TouchScreenPreview::PositionDot(QLabel* const dot, const int device_x, | 609 | void TouchScreenPreview::PositionDot(QLabel* const dot, const int device_x, |
| 603 | const int device_y) const { | 610 | const int device_y) const { |
| 604 | dot->move(static_cast<int>( | 611 | const float device_coord_x = |
| 605 | static_cast<float>(device_x >= 0 ? device_x : dot->property(PropX).toInt()) * | 612 | static_cast<float>(device_x >= 0 ? device_x : dot->property(PropX).toInt()); |
| 606 | (contentsRect().width() - 1) / (Layout::ScreenUndocked::Width - 1) + | 613 | int x_coord = static_cast<int>( |
| 607 | contentsMargins().left() - static_cast<float>(dot->width()) / 2 + 0.5f), | 614 | device_coord_x * (contentsRect().width() - 1) / (Layout::ScreenUndocked::Width - 1) + |
| 608 | static_cast<int>( | 615 | contentsMargins().left() - static_cast<float>(dot->width()) / 2 + 0.5f); |
| 609 | static_cast<float>(device_y >= 0 ? device_y : dot->property(PropY).toInt()) * | 616 | |
| 610 | (contentsRect().height() - 1) / (Layout::ScreenUndocked::Height - 1) + | 617 | const float device_coord_y = |
| 611 | contentsMargins().top() - static_cast<float>(dot->height()) / 2 + 0.5f)); | 618 | static_cast<float>(device_y >= 0 ? device_y : dot->property(PropY).toInt()); |
| 619 | const int y_coord = static_cast<int>( | ||
| 620 | device_coord_y * (contentsRect().height() - 1) / (Layout::ScreenUndocked::Height - 1) + | ||
| 621 | contentsMargins().top() - static_cast<float>(dot->height()) / 2 + 0.5f); | ||
| 622 | |||
| 623 | dot->move(x_coord, y_coord); | ||
| 612 | } | 624 | } |
diff --git a/src/yuzu/configuration/configure_touch_from_button.h b/src/yuzu/configuration/configure_touch_from_button.h index c926db012..0ddc54268 100644 --- a/src/yuzu/configuration/configure_touch_from_button.h +++ b/src/yuzu/configuration/configure_touch_from_button.h | |||
| @@ -9,8 +9,6 @@ | |||
| 9 | #include <optional> | 9 | #include <optional> |
| 10 | #include <vector> | 10 | #include <vector> |
| 11 | #include <QDialog> | 11 | #include <QDialog> |
| 12 | #include "core/frontend/framebuffer_layout.h" | ||
| 13 | #include "core/settings.h" | ||
| 14 | 12 | ||
| 15 | class QItemSelection; | 13 | class QItemSelection; |
| 16 | class QModelIndex; | 14 | class QModelIndex; |
| @@ -18,6 +16,10 @@ class QStandardItemModel; | |||
| 18 | class QStandardItem; | 16 | class QStandardItem; |
| 19 | class QTimer; | 17 | class QTimer; |
| 20 | 18 | ||
| 19 | namespace InputCommon { | ||
| 20 | class InputSubsystem; | ||
| 21 | } | ||
| 22 | |||
| 21 | namespace Common { | 23 | namespace Common { |
| 22 | class ParamPackage; | 24 | class ParamPackage; |
| 23 | } | 25 | } |
| @@ -32,12 +34,17 @@ namespace Ui { | |||
| 32 | class ConfigureTouchFromButton; | 34 | class ConfigureTouchFromButton; |
| 33 | } | 35 | } |
| 34 | 36 | ||
| 37 | namespace Settings { | ||
| 38 | struct TouchFromButtonMap; | ||
| 39 | } | ||
| 40 | |||
| 35 | class ConfigureTouchFromButton : public QDialog { | 41 | class ConfigureTouchFromButton : public QDialog { |
| 36 | Q_OBJECT | 42 | Q_OBJECT |
| 37 | 43 | ||
| 38 | public: | 44 | public: |
| 39 | explicit ConfigureTouchFromButton(QWidget* parent, | 45 | explicit ConfigureTouchFromButton(QWidget* parent, |
| 40 | const std::vector<Settings::TouchFromButtonMap>& touch_maps, | 46 | const std::vector<Settings::TouchFromButtonMap>& touch_maps, |
| 47 | InputCommon::InputSubsystem* input_subsystem_, | ||
| 41 | int default_index = 0); | 48 | int default_index = 0); |
| 42 | ~ConfigureTouchFromButton() override; | 49 | ~ConfigureTouchFromButton() override; |
| 43 | 50 | ||
| @@ -51,8 +58,8 @@ public slots: | |||
| 51 | void SetCoordinates(int dot_id, const QPoint& pos); | 58 | void SetCoordinates(int dot_id, const QPoint& pos); |
| 52 | 59 | ||
| 53 | protected: | 60 | protected: |
| 54 | virtual void showEvent(QShowEvent* ev) override; | 61 | void showEvent(QShowEvent* ev) override; |
| 55 | virtual void keyPressEvent(QKeyEvent* event) override; | 62 | void keyPressEvent(QKeyEvent* event) override; |
| 56 | 63 | ||
| 57 | private slots: | 64 | private slots: |
| 58 | void NewMapping(); | 65 | void NewMapping(); |
| @@ -73,10 +80,12 @@ private: | |||
| 73 | void SaveCurrentMapping(); | 80 | void SaveCurrentMapping(); |
| 74 | 81 | ||
| 75 | std::unique_ptr<Ui::ConfigureTouchFromButton> ui; | 82 | std::unique_ptr<Ui::ConfigureTouchFromButton> ui; |
| 76 | std::unique_ptr<QStandardItemModel> binding_list_model; | ||
| 77 | std::vector<Settings::TouchFromButtonMap> touch_maps; | 83 | std::vector<Settings::TouchFromButtonMap> touch_maps; |
| 84 | QStandardItemModel* binding_list_model; | ||
| 78 | int selected_index; | 85 | int selected_index; |
| 79 | 86 | ||
| 87 | InputCommon::InputSubsystem* input_subsystem; | ||
| 88 | |||
| 80 | std::unique_ptr<QTimer> timeout_timer; | 89 | std::unique_ptr<QTimer> timeout_timer; |
| 81 | std::unique_ptr<QTimer> poll_timer; | 90 | std::unique_ptr<QTimer> poll_timer; |
| 82 | std::vector<std::unique_ptr<InputCommon::Polling::DevicePoller>> device_pollers; | 91 | std::vector<std::unique_ptr<InputCommon::Polling::DevicePoller>> device_pollers; |
diff --git a/src/yuzu/configuration/configure_touch_widget.h b/src/yuzu/configuration/configure_touch_widget.h index c85960f82..347b46583 100644 --- a/src/yuzu/configuration/configure_touch_widget.h +++ b/src/yuzu/configuration/configure_touch_widget.h | |||
| @@ -33,11 +33,11 @@ signals: | |||
| 33 | void DotMoved(int dot_id, const QPoint& pos); | 33 | void DotMoved(int dot_id, const QPoint& pos); |
| 34 | 34 | ||
| 35 | protected: | 35 | protected: |
| 36 | virtual void resizeEvent(QResizeEvent*) override; | 36 | void resizeEvent(QResizeEvent*) override; |
| 37 | virtual void mouseMoveEvent(QMouseEvent*) override; | 37 | void mouseMoveEvent(QMouseEvent*) override; |
| 38 | virtual void leaveEvent(QEvent*) override; | 38 | void leaveEvent(QEvent*) override; |
| 39 | virtual void mousePressEvent(QMouseEvent*) override; | 39 | void mousePressEvent(QMouseEvent*) override; |
| 40 | virtual bool eventFilter(QObject*, QEvent*) override; | 40 | bool eventFilter(QObject*, QEvent*) override; |
| 41 | 41 | ||
| 42 | private: | 42 | private: |
| 43 | std::optional<QPoint> MapToDeviceCoords(int screen_x, int screen_y) const; | 43 | std::optional<QPoint> MapToDeviceCoords(int screen_x, int screen_y) const; |
| @@ -53,9 +53,10 @@ private: | |||
| 53 | static constexpr char PropX[] = "device_x"; | 53 | static constexpr char PropX[] = "device_x"; |
| 54 | static constexpr char PropY[] = "device_y"; | 54 | static constexpr char PropY[] = "device_y"; |
| 55 | 55 | ||
| 56 | struct { | 56 | struct DragState { |
| 57 | bool active = false; | 57 | bool active = false; |
| 58 | QPointer<QLabel> dot; | 58 | QPointer<QLabel> dot; |
| 59 | QPoint start_pos; | 59 | QPoint start_pos; |
| 60 | } drag_state; | 60 | }; |
| 61 | DragState drag_state; | ||
| 61 | }; | 62 | }; |