From ad0f12c742f9da23209760378ddc496e55ca1d77 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Mon, 13 Jul 2020 18:30:59 +0200 Subject: [PATCH] Qt/input: add checkbox for emulated stick values --- rpcs3/rpcs3qt/game_list_frame.cpp | 2 +- rpcs3/rpcs3qt/gui_settings.h | 3 ++ rpcs3/rpcs3qt/main_window.cpp | 2 +- rpcs3/rpcs3qt/pad_settings_dialog.cpp | 73 +++++++++++++++++---------- rpcs3/rpcs3qt/pad_settings_dialog.h | 4 +- rpcs3/rpcs3qt/pad_settings_dialog.ui | 45 ++++++++++++++++- 6 files changed, 98 insertions(+), 31 deletions(-) diff --git a/rpcs3/rpcs3qt/game_list_frame.cpp b/rpcs3/rpcs3qt/game_list_frame.cpp index 79b2e3b7e1..7fae042e48 100644 --- a/rpcs3/rpcs3qt/game_list_frame.cpp +++ b/rpcs3/rpcs3qt/game_list_frame.cpp @@ -1007,7 +1007,7 @@ void game_list_frame::ShowContextMenu(const QPoint &pos) }); connect(pad_configure, &QAction::triggered, [=, this]() { - pad_settings_dialog dlg(this, ¤t_game); + pad_settings_dialog dlg(m_gui_settings, this, ¤t_game); if (dlg.exec() == QDialog::Accepted && !gameinfo->hasCustomPadConfig) { diff --git a/rpcs3/rpcs3qt/gui_settings.h b/rpcs3/rpcs3qt/gui_settings.h index 5023580b38..201039fb48 100644 --- a/rpcs3/rpcs3qt/gui_settings.h +++ b/rpcs3/rpcs3qt/gui_settings.h @@ -112,6 +112,7 @@ namespace gui const QString notes = "Notes"; const QString titles = "Titles"; const QString localization = "Localization"; + const QString pad_settings = "PadSettings"; const QColor gl_icon_color = QColor(240, 240, 240, 255); @@ -226,6 +227,8 @@ namespace gui const gui_save um_active_user = gui_save(users, "active_user", "00000001"); const gui_save loc_language = gui_save(localization, "language", "en"); + + const gui_save pads_show_emulated = gui_save(pad_settings, "show_emulated_values", false); } /** Class for GUI settings.. diff --git a/rpcs3/rpcs3qt/main_window.cpp b/rpcs3/rpcs3qt/main_window.cpp index 1e03a54978..460524fbd0 100644 --- a/rpcs3/rpcs3qt/main_window.cpp +++ b/rpcs3/rpcs3qt/main_window.cpp @@ -1530,7 +1530,7 @@ void main_window::CreateConnects() auto open_pad_settings = [this] { - pad_settings_dialog dlg(this); + pad_settings_dialog dlg(m_gui_settings, this); dlg.exec(); }; diff --git a/rpcs3/rpcs3qt/pad_settings_dialog.cpp b/rpcs3/rpcs3qt/pad_settings_dialog.cpp index a7dbee2f34..adc4598e8a 100644 --- a/rpcs3/rpcs3qt/pad_settings_dialog.cpp +++ b/rpcs3/rpcs3qt/pad_settings_dialog.cpp @@ -12,6 +12,7 @@ #include "pad_led_settings_dialog.h" #include "ui_pad_settings_dialog.h" #include "tooltips.h" +#include "gui_settings.h" #include "Emu/System.h" #include "Emu/Io/Null/NullPadHandler.h" @@ -55,8 +56,8 @@ inline bool CreateConfigFile(const QString& dir, const QString& name) return true; } -pad_settings_dialog::pad_settings_dialog(QWidget *parent, const GameInfo *game) - : QDialog(parent), ui(new Ui::pad_settings_dialog) +pad_settings_dialog::pad_settings_dialog(std::shared_ptr gui_settings, QWidget *parent, const GameInfo *game) + : QDialog(parent), ui(new Ui::pad_settings_dialog), m_gui_settings(gui_settings) { pad::set_enabled(false); @@ -204,6 +205,15 @@ pad_settings_dialog::pad_settings_dialog(QWidget *parent, const GameInfo *game) connect(ui->chooseClass, QOverload::of(&QComboBox::currentIndexChanged), this, &pad_settings_dialog::HandleDeviceClassChange); + ui->chb_show_emulated_values->setChecked(m_gui_settings->GetValue(gui::pads_show_emulated).toBool()); + + connect(ui->chb_show_emulated_values, &QCheckBox::clicked, [this](bool checked) + { + m_gui_settings->SetValue(gui::pads_show_emulated, checked); + RepaintPreviewLabel(ui->preview_stick_left, ui->slider_stick_left->value(), ui->slider_stick_left->size().width(), m_lx, m_ly, m_handler_cfg.lpadsquircling, m_handler_cfg.lstickmultiplier / 100.0); + RepaintPreviewLabel(ui->preview_stick_right, ui->slider_stick_right->value(), ui->slider_stick_right->size().width(), m_rx, m_ry, m_handler_cfg.rpadsquircling, m_handler_cfg.rstickmultiplier / 100.0); + }); + // Initialize configurable buttons InitButtons(); @@ -624,22 +634,10 @@ void pad_settings_dialog::RepaintPreviewLabel(QLabel* l, int deadzone, int desir const qreal stick_x = std::clamp(outer_circle_radius * x * multiplier / deadzone_max, -outer_circle_radius, outer_circle_radius); const qreal stick_y = std::clamp(outer_circle_radius * -y * multiplier / deadzone_max, -outer_circle_radius, outer_circle_radius); - u16 real_x = 0; - u16 real_y = 0; + const bool show_emulated_values = ui->chb_show_emulated_values->isChecked(); - if (m_handler) - { - const int m_in = multiplier * 100.0; - const u16 normal_x = m_handler->NormalizeStickInput(static_cast(std::abs(x)), deadzone, m_in, true); - const u16 normal_y = m_handler->NormalizeStickInput(static_cast(std::abs(y)), deadzone, m_in, true); - const s32 x_in = x >= 0 ? normal_x : 0 - normal_x; - const s32 y_in = y >= 0 ? normal_y : 0 - normal_y; - m_handler->convert_stick_values(real_x, real_y, x_in, y_in, deadzone, squircle); - } - - constexpr qreal real_max = 126; - const qreal ingame_x = std::clamp(outer_circle_radius * (static_cast(real_x) - real_max) / real_max, -outer_circle_radius, outer_circle_radius); - const qreal ingame_y = std::clamp(outer_circle_radius * -(static_cast(real_y) - real_max) / real_max, -outer_circle_radius, outer_circle_radius); + qreal ingame_x; + qreal ingame_y; // Set up the canvas for our work of art QPixmap pixmap(scaled_width, scaled_width); @@ -653,11 +651,31 @@ void pad_settings_dialog::RepaintPreviewLabel(QLabel* l, int deadzone, int desir painter.translate(origin, origin); painter.setBrush(QBrush(Qt::white)); - // Draw a black outer squircle that roughly represents the DS3's max values - QPainterPath path; - path.addRoundedRect(QRectF(-outer_circle_radius, -outer_circle_radius, outer_circle_diameter, outer_circle_diameter), 5, 5, Qt::SizeMode::RelativeSize); - painter.setPen(QPen(Qt::black, 1.0)); - painter.drawPath(path); + if (show_emulated_values) + { + u16 real_x = 0; + u16 real_y = 0; + + if (m_handler) + { + const int m_in = multiplier * 100.0; + const u16 normal_x = m_handler->NormalizeStickInput(static_cast(std::abs(x)), deadzone, m_in, true); + const u16 normal_y = m_handler->NormalizeStickInput(static_cast(std::abs(y)), deadzone, m_in, true); + const s32 x_in = x >= 0 ? normal_x : 0 - normal_x; + const s32 y_in = y >= 0 ? normal_y : 0 - normal_y; + m_handler->convert_stick_values(real_x, real_y, x_in, y_in, deadzone, squircle); + } + + constexpr qreal real_max = 126; + ingame_x = std::clamp(outer_circle_radius * (static_cast(real_x) - real_max) / real_max, -outer_circle_radius, outer_circle_radius); + ingame_y = std::clamp(outer_circle_radius * -(static_cast(real_y) - real_max) / real_max, -outer_circle_radius, outer_circle_radius); + + // Draw a black outer squircle that roughly represents the DS3's max values + QPainterPath path; + path.addRoundedRect(QRectF(-outer_circle_radius, -outer_circle_radius, outer_circle_diameter, outer_circle_diameter), 5, 5, Qt::SizeMode::RelativeSize); + painter.setPen(QPen(Qt::black, 1.0)); + painter.drawPath(path); + } // Draw a black outer circle that represents the maximum for the deadzone painter.setPen(QPen(Qt::black, 1.0)); @@ -669,11 +687,14 @@ void pad_settings_dialog::RepaintPreviewLabel(QLabel* l, int deadzone, int desir // Draw a blue dot that represents the current stick orientation painter.setPen(QPen(Qt::blue, 2.0)); - painter.drawEllipse(QRectF(stick_x - 1.0, stick_y - 1.0, 1.0, 1.0)); + painter.drawEllipse(QRectF(stick_x - 0.5, stick_y - 0.5, 1.0, 1.0)); - // Draw a red dot that represents the current ingame stick orientation - painter.setPen(QPen(Qt::red, 2.0)); - painter.drawEllipse(QRectF(ingame_x - 1.0, ingame_y - 1.0, 1.0, 1.0)); + if (show_emulated_values) + { + // Draw a red dot that represents the current ingame stick orientation + painter.setPen(QPen(Qt::red, 2.0)); + painter.drawEllipse(QRectF(ingame_x - 0.5, ingame_y - 0.5, 1.0, 1.0)); + } l->setPixmap(pixmap); } diff --git a/rpcs3/rpcs3qt/pad_settings_dialog.h b/rpcs3/rpcs3qt/pad_settings_dialog.h index 2709a42560..376d52f51e 100644 --- a/rpcs3/rpcs3qt/pad_settings_dialog.h +++ b/rpcs3/rpcs3qt/pad_settings_dialog.h @@ -9,6 +9,7 @@ #include "Emu/Io/pad_config.h" #include "Emu/GameInfo.h" +class gui_settings; class PadHandlerBase; namespace Ui @@ -87,7 +88,7 @@ class pad_settings_dialog : public QDialog const QString Disconnected_suffix = tr(" (disconnected)"); public: - explicit pad_settings_dialog(QWidget *parent = nullptr, const GameInfo *game = nullptr); + explicit pad_settings_dialog(std::shared_ptr gui_settings, QWidget *parent = nullptr, const GameInfo *game = nullptr); ~pad_settings_dialog(); public Q_SLOTS: @@ -105,6 +106,7 @@ private Q_SLOTS: private: Ui::pad_settings_dialog *ui; std::string m_title_id; + std::shared_ptr m_gui_settings; // Capabilities bool m_enable_buttons{ false }; diff --git a/rpcs3/rpcs3qt/pad_settings_dialog.ui b/rpcs3/rpcs3qt/pad_settings_dialog.ui index 485aa9e616..bad48356ec 100644 --- a/rpcs3/rpcs3qt/pad_settings_dialog.ui +++ b/rpcs3/rpcs3qt/pad_settings_dialog.ui @@ -736,13 +736,13 @@ 5 - 9 + 5 5 - 9 + 5 @@ -774,6 +774,47 @@ + + + + Stick Preview + + + + 5 + + + 5 + + + 5 + + + 5 + + + + + Show Emulated Values + + + + + + + + + + Qt::Vertical + + + + 0 + 0 + + + +