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