mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 13:50:03 +00:00 
			
		
		
		
	Backport review comments from yuzu-emu/yuzu#4382: "yuzu: Add motion and touch configuration from Citra" (#5543)
This commit is contained in:
		
							parent
							
								
									a93d7a8d3a
								
							
						
					
					
						commit
						14924e9db3
					
				
					 9 changed files with 127 additions and 108 deletions
				
			
		|  | @ -23,8 +23,9 @@ CalibrationConfigurationDialog::CalibrationConfigurationDialog(QWidget* parent, | |||
|     status_label = new QLabel(tr("Communicating with the server...")); | ||||
|     cancel_button = new QPushButton(tr("Cancel")); | ||||
|     connect(cancel_button, &QPushButton::clicked, this, [this] { | ||||
|         if (!completed) | ||||
|         if (!completed) { | ||||
|             job->Stop(); | ||||
|         } | ||||
|         accept(); | ||||
|     }); | ||||
|     layout->addWidget(status_label); | ||||
|  | @ -63,31 +64,33 @@ CalibrationConfigurationDialog::CalibrationConfigurationDialog(QWidget* parent, | |||
| 
 | ||||
| CalibrationConfigurationDialog::~CalibrationConfigurationDialog() = default; | ||||
| 
 | ||||
| void CalibrationConfigurationDialog::UpdateLabelText(QString text) { | ||||
| void CalibrationConfigurationDialog::UpdateLabelText(const QString& text) { | ||||
|     status_label->setText(text); | ||||
| } | ||||
| 
 | ||||
| void CalibrationConfigurationDialog::UpdateButtonText(QString text) { | ||||
| void CalibrationConfigurationDialog::UpdateButtonText(const QString& text) { | ||||
|     cancel_button->setText(text); | ||||
| } | ||||
| 
 | ||||
| const std::array<std::pair<const char*, const char*>, 3> MotionProviders = { | ||||
|     {{"motion_emu", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "Mouse (Right Click)")}, | ||||
|      {"cemuhookudp", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "CemuhookUDP")}, | ||||
|      {"sdl", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "SDL")}}}; | ||||
| constexpr std::array<std::pair<const char*, const char*>, 3> MotionProviders = {{ | ||||
|     {"motion_emu", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "Mouse (Right Click)")}, | ||||
|     {"cemuhookudp", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "CemuhookUDP")}, | ||||
|     {"sdl", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "SDL")}, | ||||
| }}; | ||||
| 
 | ||||
| const std::array<std::pair<const char*, const char*>, 2> TouchProviders = { | ||||
|     {{"emu_window", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "Emulator Window")}, | ||||
|      {"cemuhookudp", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "CemuhookUDP")}}}; | ||||
| constexpr std::array<std::pair<const char*, const char*>, 2> TouchProviders = {{ | ||||
|     {"emu_window", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "Emulator Window")}, | ||||
|     {"cemuhookudp", QT_TRANSLATE_NOOP("ConfigureMotionTouch", "CemuhookUDP")}, | ||||
| }}; | ||||
| 
 | ||||
| ConfigureMotionTouch::ConfigureMotionTouch(QWidget* parent) | ||||
|     : QDialog(parent), ui(std::make_unique<Ui::ConfigureMotionTouch>()), | ||||
|       timeout_timer(std::make_unique<QTimer>()), poll_timer(std::make_unique<QTimer>()) { | ||||
|     ui->setupUi(this); | ||||
|     for (auto [provider, name] : MotionProviders) { | ||||
|     for (const auto& [provider, name] : MotionProviders) { | ||||
|         ui->motion_provider->addItem(tr(name), QString::fromUtf8(provider)); | ||||
|     } | ||||
|     for (auto [provider, name] : TouchProviders) { | ||||
|     for (const auto& [provider, name] : TouchProviders) { | ||||
|         ui->touch_provider->addItem(tr(name), QString::fromUtf8(provider)); | ||||
|     } | ||||
| 
 | ||||
|  | @ -122,10 +125,10 @@ ConfigureMotionTouch::ConfigureMotionTouch(QWidget* parent) | |||
| ConfigureMotionTouch::~ConfigureMotionTouch() = default; | ||||
| 
 | ||||
| void ConfigureMotionTouch::SetConfiguration() { | ||||
|     Common::ParamPackage motion_param(Settings::values.current_input_profile.motion_device); | ||||
|     Common::ParamPackage touch_param(Settings::values.current_input_profile.touch_device); | ||||
|     std::string motion_engine = motion_param.Get("engine", "motion_emu"); | ||||
|     std::string touch_engine = touch_param.Get("engine", "emu_window"); | ||||
|     const Common::ParamPackage motion_param(Settings::values.current_input_profile.motion_device); | ||||
|     const Common::ParamPackage touch_param(Settings::values.current_input_profile.touch_device); | ||||
|     const std::string motion_engine = motion_param.Get("engine", "motion_emu"); | ||||
|     const std::string touch_engine = touch_param.Get("engine", "emu_window"); | ||||
| 
 | ||||
|     ui->motion_provider->setCurrentIndex( | ||||
|         ui->motion_provider->findData(QString::fromStdString(motion_engine))); | ||||
|  | @ -156,8 +159,8 @@ void ConfigureMotionTouch::SetConfiguration() { | |||
| } | ||||
| 
 | ||||
| void ConfigureMotionTouch::UpdateUiDisplay() { | ||||
|     std::string motion_engine = ui->motion_provider->currentData().toString().toStdString(); | ||||
|     std::string touch_engine = ui->touch_provider->currentData().toString().toStdString(); | ||||
|     const std::string motion_engine = ui->motion_provider->currentData().toString().toStdString(); | ||||
|     const std::string touch_engine = ui->touch_provider->currentData().toString().toStdString(); | ||||
| 
 | ||||
|     if (motion_engine == "motion_emu") { | ||||
|         ui->motion_sensitivity_label->setVisible(true); | ||||
|  | @ -179,9 +182,8 @@ void ConfigureMotionTouch::UpdateUiDisplay() { | |||
|         ui->touch_calibration->setVisible(true); | ||||
|         ui->touch_calibration_config->setVisible(true); | ||||
|         ui->touch_calibration_label->setVisible(true); | ||||
|         ui->touch_calibration->setText(QStringLiteral("(%1, %2) - (%3, %4)") | ||||
|                                            .arg(QString::number(min_x), QString::number(min_y), | ||||
|                                                 QString::number(max_x), QString::number(max_y))); | ||||
|         ui->touch_calibration->setText( | ||||
|             QStringLiteral("(%1, %2) - (%3, %4)").arg(min_x).arg(min_y).arg(max_x).arg(max_y)); | ||||
|     } else { | ||||
|         ui->touch_calibration->setVisible(false); | ||||
|         ui->touch_calibration_config->setVisible(false); | ||||
|  | @ -196,11 +198,9 @@ void ConfigureMotionTouch::UpdateUiDisplay() { | |||
| } | ||||
| 
 | ||||
| void ConfigureMotionTouch::ConnectEvents() { | ||||
|     connect(ui->motion_provider, | ||||
|             static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, | ||||
|     connect(ui->motion_provider, qOverload<int>(&QComboBox::currentIndexChanged), this, | ||||
|             [this]([[maybe_unused]] int index) { UpdateUiDisplay(); }); | ||||
|     connect(ui->touch_provider, | ||||
|             static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, | ||||
|     connect(ui->touch_provider, qOverload<int>(&QComboBox::currentIndexChanged), this, | ||||
|             [this]([[maybe_unused]] int index) { UpdateUiDisplay(); }); | ||||
|     connect(ui->motion_controller_button, &QPushButton::clicked, [=]() { | ||||
|         if (QMessageBox::information(this, tr("Information"), | ||||
|  | @ -232,8 +232,9 @@ void ConfigureMotionTouch::ConnectEvents() { | |||
|     connect(ui->touch_from_button_config_btn, &QPushButton::clicked, this, | ||||
|             &ConfigureMotionTouch::OnConfigureTouchFromButton); | ||||
|     connect(ui->buttonBox, &QDialogButtonBox::rejected, this, [this] { | ||||
|         if (CanCloseDialog()) | ||||
|         if (CanCloseDialog()) { | ||||
|             reject(); | ||||
|         } | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
|  | @ -272,15 +273,15 @@ void ConfigureMotionTouch::OnCemuhookUDPTest() { | |||
| void ConfigureMotionTouch::OnConfigureTouchCalibration() { | ||||
|     ui->touch_calibration_config->setEnabled(false); | ||||
|     ui->touch_calibration_config->setText(tr("Configuring")); | ||||
|     CalibrationConfigurationDialog* dialog = new CalibrationConfigurationDialog( | ||||
|     CalibrationConfigurationDialog dialog( | ||||
|         this, ui->udp_server->text().toStdString(), static_cast<u16>(ui->udp_port->text().toUInt()), | ||||
|         static_cast<u8>(ui->udp_pad_index->currentIndex()), 24872); | ||||
|     dialog->exec(); | ||||
|     if (dialog->completed) { | ||||
|         min_x = dialog->min_x; | ||||
|         min_y = dialog->min_y; | ||||
|         max_x = dialog->max_x; | ||||
|         max_y = dialog->max_y; | ||||
|     dialog.exec(); | ||||
|     if (dialog.completed) { | ||||
|         min_x = dialog.min_x; | ||||
|         min_y = dialog.min_y; | ||||
|         max_x = dialog.max_x; | ||||
|         max_y = dialog.max_y; | ||||
|         LOG_INFO(Frontend, | ||||
|                  "UDP touchpad calibration config success: min_x={}, min_y={}, max_x={}, max_y={}", | ||||
|                  min_x, min_y, max_x, max_y); | ||||
|  | @ -293,10 +294,11 @@ void ConfigureMotionTouch::OnConfigureTouchCalibration() { | |||
| } | ||||
| 
 | ||||
| void ConfigureMotionTouch::closeEvent(QCloseEvent* event) { | ||||
|     if (CanCloseDialog()) | ||||
|     if (CanCloseDialog()) { | ||||
|         event->accept(); | ||||
|     else | ||||
|     } else { | ||||
|         event->ignore(); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void ConfigureMotionTouch::ShowUDPTestResult(bool result) { | ||||
|  | @ -342,15 +344,16 @@ bool ConfigureMotionTouch::CanCloseDialog() { | |||
| } | ||||
| 
 | ||||
| void ConfigureMotionTouch::ApplyConfiguration() { | ||||
|     if (!CanCloseDialog()) | ||||
|     if (!CanCloseDialog()) { | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     std::string motion_engine = ui->motion_provider->currentData().toString().toStdString(); | ||||
|     std::string touch_engine = ui->touch_provider->currentData().toString().toStdString(); | ||||
| 
 | ||||
|     Common::ParamPackage motion_param{}, touch_param{}; | ||||
|     motion_param.Set("engine", motion_engine); | ||||
|     touch_param.Set("engine", touch_engine); | ||||
|     motion_param.Set("engine", std::move(motion_engine)); | ||||
|     touch_param.Set("engine", std::move(touch_engine)); | ||||
| 
 | ||||
|     if (motion_engine == "motion_emu") { | ||||
|         motion_param.Set("sensitivity", static_cast<float>(ui->motion_sensitivity->value())); | ||||
|  |  | |||
|  | @ -26,11 +26,11 @@ class CalibrationConfigurationDialog : public QDialog { | |||
| public: | ||||
|     explicit CalibrationConfigurationDialog(QWidget* parent, const std::string& host, u16 port, | ||||
|                                             u8 pad_index, u16 client_id); | ||||
|     ~CalibrationConfigurationDialog(); | ||||
|     ~CalibrationConfigurationDialog() override; | ||||
| 
 | ||||
| private: | ||||
|     Q_INVOKABLE void UpdateLabelText(QString text); | ||||
|     Q_INVOKABLE void UpdateButtonText(QString text); | ||||
|     Q_INVOKABLE void UpdateLabelText(const QString& text); | ||||
|     Q_INVOKABLE void UpdateButtonText(const QString& text); | ||||
| 
 | ||||
|     QVBoxLayout* layout; | ||||
|     QLabel* status_label; | ||||
|  | @ -39,7 +39,10 @@ private: | |||
| 
 | ||||
|     // Configuration results
 | ||||
|     bool completed{}; | ||||
|     u16 min_x, min_y, max_x, max_y; | ||||
|     u16 min_x{}; | ||||
|     u16 min_y{}; | ||||
|     u16 max_x{}; | ||||
|     u16 max_y{}; | ||||
| 
 | ||||
|     friend class ConfigureMotionTouch; | ||||
| }; | ||||
|  | @ -81,7 +84,10 @@ private: | |||
|     std::optional<std::function<void(const Common::ParamPackage&)>> input_setter; | ||||
| 
 | ||||
|     // Coordinate system of the CemuhookUDP touch provider
 | ||||
|     int min_x, min_y, max_x, max_y; | ||||
|     int min_x{}; | ||||
|     int min_y{}; | ||||
|     int max_x{}; | ||||
|     int max_y{}; | ||||
| 
 | ||||
|     bool udp_test_in_progress{}; | ||||
| 
 | ||||
|  |  | |||
|  | @ -73,11 +73,11 @@ ConfigureTouchFromButton::ConfigureTouchFromButton( | |||
|     : QDialog(parent), ui(std::make_unique<Ui::ConfigureTouchFromButton>()), touch_maps(touch_maps), | ||||
|       selected_index(default_index), timeout_timer(std::make_unique<QTimer>()), | ||||
|       poll_timer(std::make_unique<QTimer>()) { | ||||
| 
 | ||||
|     ui->setupUi(this); | ||||
|     binding_list_model = std::make_unique<QStandardItemModel>(0, 3, this); | ||||
|     binding_list_model->setHorizontalHeaderLabels({tr("Button"), tr("X"), tr("Y")}); | ||||
|     ui->binding_list->setModel(binding_list_model.get()); | ||||
|     binding_list_model = new QStandardItemModel(0, 3, this); | ||||
|     binding_list_model->setHorizontalHeaderLabels( | ||||
|         {tr("Button"), tr("X", "X axis"), tr("Y", "Y axis")}); | ||||
|     ui->binding_list->setModel(binding_list_model); | ||||
|     ui->bottom_screen->SetCoordLabel(ui->coord_label); | ||||
| 
 | ||||
|     SetConfiguration(); | ||||
|  | @ -93,11 +93,12 @@ void ConfigureTouchFromButton::showEvent(QShowEvent* ev) { | |||
|     // width values are not valid in the constructor
 | ||||
|     const int w = | ||||
|         ui->binding_list->viewport()->contentsRect().width() / binding_list_model->columnCount(); | ||||
|     if (w > 0) { | ||||
|         ui->binding_list->setColumnWidth(0, w); | ||||
|         ui->binding_list->setColumnWidth(1, w); | ||||
|         ui->binding_list->setColumnWidth(2, w); | ||||
|     if (w <= 0) { | ||||
|         return; | ||||
|     } | ||||
|     ui->binding_list->setColumnWidth(0, w); | ||||
|     ui->binding_list->setColumnWidth(1, w); | ||||
|     ui->binding_list->setColumnWidth(2, w); | ||||
| } | ||||
| 
 | ||||
| void ConfigureTouchFromButton::SetConfiguration() { | ||||
|  | @ -123,7 +124,7 @@ void ConfigureTouchFromButton::UpdateUiDisplay() { | |||
|         QStandardItem* ycoord = new QStandardItem(QString::number(package.Get("y", 0))); | ||||
|         binding_list_model->appendRow({button, xcoord, ycoord}); | ||||
| 
 | ||||
|         int dot = ui->bottom_screen->AddDot(package.Get("x", 0), package.Get("y", 0)); | ||||
|         const int dot = ui->bottom_screen->AddDot(package.Get("x", 0), package.Get("y", 0)); | ||||
|         button->setData(dot, DataRoleDot); | ||||
|     } | ||||
| } | ||||
|  | @ -145,7 +146,7 @@ void ConfigureTouchFromButton::ConnectEvents() { | |||
|             &ConfigureTouchFromButton::EditBinding); | ||||
|     connect(ui->binding_list->selectionModel(), &QItemSelectionModel::selectionChanged, this, | ||||
|             &ConfigureTouchFromButton::OnBindingSelection); | ||||
|     connect(binding_list_model.get(), &QStandardItemModel::itemChanged, this, | ||||
|     connect(binding_list_model, &QStandardItemModel::itemChanged, this, | ||||
|             &ConfigureTouchFromButton::OnBindingChanged); | ||||
|     connect(ui->binding_list->model(), &QStandardItemModel::rowsAboutToBeRemoved, this, | ||||
|             &ConfigureTouchFromButton::OnBindingDeleted); | ||||
|  | @ -232,7 +233,7 @@ void ConfigureTouchFromButton::GetButtonInput(const int row_index, const bool is | |||
| 
 | ||||
|     input_setter = [this, row_index, is_new](const Common::ParamPackage& params, | ||||
|                                              const bool cancel) { | ||||
|         auto cell = binding_list_model->item(row_index, 0); | ||||
|         auto* cell = binding_list_model->item(row_index, 0); | ||||
|         if (cancel) { | ||||
|             if (is_new) { | ||||
|                 binding_list_model->removeRow(row_index); | ||||
|  | @ -260,15 +261,15 @@ void ConfigureTouchFromButton::GetButtonInput(const int row_index, const bool is | |||
| } | ||||
| 
 | ||||
| void ConfigureTouchFromButton::NewBinding(const QPoint& pos) { | ||||
|     QStandardItem* button = new QStandardItem(); | ||||
|     auto* button = new QStandardItem(); | ||||
|     button->setEditable(false); | ||||
|     QStandardItem* xcoord = new QStandardItem(QString::number(pos.x())); | ||||
|     QStandardItem* ycoord = new QStandardItem(QString::number(pos.y())); | ||||
|     auto* x_coord = new QStandardItem(QString::number(pos.x())); | ||||
|     auto* y_coord = new QStandardItem(QString::number(pos.y())); | ||||
| 
 | ||||
|     const int dot_id = ui->bottom_screen->AddDot(pos.x(), pos.y()); | ||||
|     button->setData(dot_id, DataRoleDot); | ||||
| 
 | ||||
|     binding_list_model->appendRow({button, xcoord, ycoord}); | ||||
|     binding_list_model->appendRow({button, x_coord, y_coord}); | ||||
|     ui->binding_list->setFocus(); | ||||
|     ui->binding_list->setCurrentIndex(button->index()); | ||||
| 
 | ||||
|  | @ -283,11 +284,11 @@ void ConfigureTouchFromButton::EditBinding(const QModelIndex& qi) { | |||
| 
 | ||||
| void ConfigureTouchFromButton::DeleteBinding() { | ||||
|     const int row_index = ui->binding_list->currentIndex().row(); | ||||
|     if (row_index >= 0) { | ||||
|         ui->bottom_screen->RemoveDot( | ||||
|             binding_list_model->index(row_index, 0).data(DataRoleDot).toInt()); | ||||
|         binding_list_model->removeRow(row_index); | ||||
|     if (row_index < 0) { | ||||
|         return; | ||||
|     } | ||||
|     ui->bottom_screen->RemoveDot(binding_list_model->index(row_index, 0).data(DataRoleDot).toInt()); | ||||
|     binding_list_model->removeRow(row_index); | ||||
| } | ||||
| 
 | ||||
| void ConfigureTouchFromButton::OnBindingSelection(const QItemSelection& selected, | ||||
|  | @ -329,7 +330,7 @@ void ConfigureTouchFromButton::OnBindingChanged(QStandardItem* item) { | |||
| void ConfigureTouchFromButton::OnBindingDeleted([[maybe_unused]] const QModelIndex& parent, | ||||
|                                                 int first, int last) { | ||||
|     for (int i = first; i <= last; ++i) { | ||||
|         auto ix = binding_list_model->index(i, 0); | ||||
|         const auto ix = binding_list_model->index(i, 0); | ||||
|         if (!ix.isValid()) { | ||||
|             return; | ||||
|         } | ||||
|  | @ -422,7 +423,7 @@ int TouchScreenPreview::AddDot(const int device_x, const int device_y) { | |||
|     dot_font.setStyleHint(QFont::Monospace); | ||||
|     dot_font.setPointSize(20); | ||||
| 
 | ||||
|     QLabel* dot = new QLabel(this); | ||||
|     auto* dot = new QLabel(this); | ||||
|     dot->setAttribute(Qt::WA_TranslucentBackground); | ||||
|     dot->setFont(dot_font); | ||||
|     dot->setText(QChar(0xD7)); // U+00D7 Multiplication Sign
 | ||||
|  | @ -440,13 +441,14 @@ int TouchScreenPreview::AddDot(const int device_x, const int device_y) { | |||
| } | ||||
| 
 | ||||
| void TouchScreenPreview::RemoveDot(const int id) { | ||||
|     for (auto dot_it = dots.begin(); dot_it != dots.end(); ++dot_it) { | ||||
|         if (dot_it->first == id) { | ||||
|             dot_it->second->deleteLater(); | ||||
|             dots.erase(dot_it); | ||||
|             return; | ||||
|         } | ||||
|     const auto iter = std::find_if(dots.begin(), dots.end(), | ||||
|                                    [id](const auto& entry) { return entry.first == id; }); | ||||
|     if (iter == dots.cend()) { | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     iter->second->deleteLater(); | ||||
|     dots.erase(iter); | ||||
| } | ||||
| 
 | ||||
| void TouchScreenPreview::HighlightDot(const int id, const bool active) const { | ||||
|  | @ -470,14 +472,15 @@ void TouchScreenPreview::HighlightDot(const int id, const bool active) const { | |||
| } | ||||
| 
 | ||||
| void TouchScreenPreview::MoveDot(const int id, const int device_x, const int device_y) const { | ||||
|     for (const auto& dot : dots) { | ||||
|         if (dot.first == id) { | ||||
|             dot.second->setProperty(PropX, device_x); | ||||
|             dot.second->setProperty(PropY, device_y); | ||||
|             PositionDot(dot.second, device_x, device_y); | ||||
|             return; | ||||
|         } | ||||
|     const auto iter = std::find_if(dots.begin(), dots.end(), | ||||
|                                    [id](const auto& entry) { return entry.first == id; }); | ||||
|     if (iter == dots.cend()) { | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     iter->second->setProperty(PropX, device_x); | ||||
|     iter->second->setProperty(PropY, device_y); | ||||
|     PositionDot(iter->second, device_x, device_y); | ||||
| } | ||||
| 
 | ||||
| void TouchScreenPreview::resizeEvent(QResizeEvent* event) { | ||||
|  | @ -521,11 +524,12 @@ void TouchScreenPreview::leaveEvent([[maybe_unused]] QEvent* event) { | |||
| } | ||||
| 
 | ||||
| void TouchScreenPreview::mousePressEvent(QMouseEvent* event) { | ||||
|     if (event->button() == Qt::MouseButton::LeftButton) { | ||||
|         const auto pos = MapToDeviceCoords(event->x(), event->y()); | ||||
|         if (pos) { | ||||
|             emit DotAdded(*pos); | ||||
|         } | ||||
|     if (event->button() != Qt::MouseButton::LeftButton) { | ||||
|         return; | ||||
|     } | ||||
|     const auto pos = MapToDeviceCoords(event->x(), event->y()); | ||||
|     if (pos) { | ||||
|         emit DotAdded(*pos); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  | @ -600,12 +604,17 @@ std::optional<QPoint> TouchScreenPreview::MapToDeviceCoords(const int screen_x, | |||
| 
 | ||||
| void TouchScreenPreview::PositionDot(QLabel* const dot, const int device_x, | ||||
|                                      const int device_y) const { | ||||
|     dot->move(static_cast<int>( | ||||
|                   static_cast<float>(device_x >= 0 ? device_x : dot->property(PropX).toInt()) * | ||||
|                       (contentsRect().width() - 1) / (Core::kScreenBottomWidth - 1) + | ||||
|                   contentsMargins().left() - static_cast<float>(dot->width()) / 2 + 0.5f), | ||||
|               static_cast<int>( | ||||
|                   static_cast<float>(device_y >= 0 ? device_y : dot->property(PropY).toInt()) * | ||||
|                       (contentsRect().height() - 1) / (Core::kScreenBottomHeight - 1) + | ||||
|                   contentsMargins().top() - static_cast<float>(dot->height()) / 2 + 0.5f)); | ||||
|     const float device_coord_x = | ||||
|         static_cast<float>(device_x >= 0 ? device_x : dot->property(PropX).toInt()); | ||||
|     const int x_coord = static_cast<int>( | ||||
|         device_coord_x * (contentsRect().width() - 1) / (Core::kScreenBottomWidth - 1) + | ||||
|         contentsMargins().left() - static_cast<float>(dot->width()) / 2 + 0.5f); | ||||
| 
 | ||||
|     const float device_coord_y = | ||||
|         static_cast<float>(device_y >= 0 ? device_y : dot->property(PropY).toInt()); | ||||
|     const int y_coord = static_cast<int>( | ||||
|         device_coord_y * (contentsRect().height() - 1) / (Core::kScreenBottomHeight - 1) + | ||||
|         contentsMargins().top() - static_cast<float>(dot->height()) / 2 + 0.5f); | ||||
| 
 | ||||
|     dot->move(x_coord, y_coord); | ||||
| } | ||||
|  |  | |||
|  | @ -50,8 +50,8 @@ public slots: | |||
|     void SetCoordinates(int dot_id, const QPoint& pos); | ||||
| 
 | ||||
| protected: | ||||
|     virtual void showEvent(QShowEvent* ev) override; | ||||
|     virtual void keyPressEvent(QKeyEvent* event) override; | ||||
|     void showEvent(QShowEvent* ev) override; | ||||
|     void keyPressEvent(QKeyEvent* event) override; | ||||
| 
 | ||||
| private slots: | ||||
|     void NewMapping(); | ||||
|  | @ -72,7 +72,7 @@ private: | |||
|     void SaveCurrentMapping(); | ||||
| 
 | ||||
|     std::unique_ptr<Ui::ConfigureTouchFromButton> ui; | ||||
|     std::unique_ptr<QStandardItemModel> binding_list_model; | ||||
|     QStandardItemModel* binding_list_model; | ||||
|     std::vector<Settings::TouchFromButtonMap> touch_maps; | ||||
|     int selected_index; | ||||
| 
 | ||||
|  |  | |||
|  | @ -33,11 +33,11 @@ signals: | |||
|     void DotMoved(int dot_id, const QPoint& pos); | ||||
| 
 | ||||
| protected: | ||||
|     virtual void resizeEvent(QResizeEvent*) override; | ||||
|     virtual void mouseMoveEvent(QMouseEvent*) override; | ||||
|     virtual void leaveEvent(QEvent*) override; | ||||
|     virtual void mousePressEvent(QMouseEvent*) override; | ||||
|     virtual bool eventFilter(QObject*, QEvent*) override; | ||||
|     void resizeEvent(QResizeEvent*) override; | ||||
|     void mouseMoveEvent(QMouseEvent*) override; | ||||
|     void leaveEvent(QEvent*) override; | ||||
|     void mousePressEvent(QMouseEvent*) override; | ||||
|     bool eventFilter(QObject*, QEvent*) override; | ||||
| 
 | ||||
| private: | ||||
|     std::optional<QPoint> MapToDeviceCoords(int screen_x, int screen_y) const; | ||||
|  | @ -53,9 +53,10 @@ private: | |||
|     static constexpr char PropX[] = "device_x"; | ||||
|     static constexpr char PropY[] = "device_y"; | ||||
| 
 | ||||
|     struct { | ||||
|     struct DragState { | ||||
|         bool active = false; | ||||
|         QPointer<QLabel> dot; | ||||
|         QPoint start_pos; | ||||
|     } drag_state; | ||||
|     }; | ||||
|     DragState drag_state; | ||||
| }; | ||||
|  |  | |||
|  | @ -118,8 +118,10 @@ Common::ParamPackage GetControllerAnalogBinds(const Common::ParamPackage& params | |||
| } | ||||
| 
 | ||||
| void ReloadInputDevices() { | ||||
|     if (udp) | ||||
|         udp->ReloadUDPClient(); | ||||
|     if (!udp) { | ||||
|         return; | ||||
|     } | ||||
|     udp->ReloadUDPClient(); | ||||
| } | ||||
| 
 | ||||
| namespace Polling { | ||||
|  |  | |||
|  | @ -30,19 +30,19 @@ public: | |||
|             if (state) { | ||||
|                 const float x = static_cast<float>(std::get<1>(m)) / Core::kScreenBottomWidth; | ||||
|                 const float y = static_cast<float>(std::get<2>(m)) / Core::kScreenBottomHeight; | ||||
|                 return std::make_tuple(x, y, true); | ||||
|                 return {x, y, true}; | ||||
|             } | ||||
|         } | ||||
|         return std::make_tuple(0.0f, 0.0f, false); | ||||
|         return {}; | ||||
|     } | ||||
| 
 | ||||
| private: | ||||
|     std::vector<std::tuple<std::unique_ptr<Input::ButtonDevice>, int, int>> map; // button, x, y
 | ||||
|     // A vector of the mapped button, its x and its y-coordinate
 | ||||
|     std::vector<std::tuple<std::unique_ptr<Input::ButtonDevice>, int, int>> map; | ||||
| }; | ||||
| 
 | ||||
| std::unique_ptr<Input::TouchDevice> TouchFromButtonFactory::Create( | ||||
|     const Common::ParamPackage& params) { | ||||
| 
 | ||||
|     return std::make_unique<TouchFromButtonDevice>(); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -16,7 +16,6 @@ class TouchFromButtonFactory final : public Input::Factory<Input::TouchDevice> { | |||
| public: | ||||
|     /**
 | ||||
|      * Creates a touch device from a list of button devices | ||||
|      * @param unused | ||||
|      */ | ||||
|     std::unique_ptr<Input::TouchDevice> Create(const Common::ParamPackage& params) override; | ||||
| }; | ||||
|  |  | |||
|  | @ -9,7 +9,6 @@ | |||
| #include <functional> | ||||
| #include <thread> | ||||
| #include <boost/asio.hpp> | ||||
| #include <boost/bind.hpp> | ||||
| #include "common/logging/log.h" | ||||
| #include "input_common/udp/client.h" | ||||
| #include "input_common/udp/protocol.h" | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue