mirror of
https://github.com/PabloMK7/citra.git
synced 2024-12-29 11:06:12 +00:00
input_common: add TouchFromButtonDevice
This commit is contained in:
parent
36809b2e2e
commit
41facaece3
|
@ -69,6 +69,9 @@ add_executable(citra-qt
|
||||||
configuration/configure_system.cpp
|
configuration/configure_system.cpp
|
||||||
configuration/configure_system.h
|
configuration/configure_system.h
|
||||||
configuration/configure_system.ui
|
configuration/configure_system.ui
|
||||||
|
configuration/configure_touch_from_button.cpp
|
||||||
|
configuration/configure_touch_from_button.h
|
||||||
|
configuration/configure_touch_from_button.ui
|
||||||
configuration/configure_ui.cpp
|
configuration/configure_ui.cpp
|
||||||
configuration/configure_ui.h
|
configuration/configure_ui.h
|
||||||
configuration/configure_ui.ui
|
configuration/configure_ui.ui
|
||||||
|
|
|
@ -164,10 +164,42 @@ void Config::ReadCameraValues() {
|
||||||
void Config::ReadControlValues() {
|
void Config::ReadControlValues() {
|
||||||
qt_config->beginGroup(QStringLiteral("Controls"));
|
qt_config->beginGroup(QStringLiteral("Controls"));
|
||||||
|
|
||||||
|
int num_touch_from_button_maps =
|
||||||
|
qt_config->beginReadArray(QStringLiteral("touch_from_button_maps"));
|
||||||
|
|
||||||
|
if (num_touch_from_button_maps > 0) {
|
||||||
|
const auto& append_touch_from_button_map = [this] {
|
||||||
|
Settings::TouchFromButtonMap map;
|
||||||
|
map.name = ReadSetting(QStringLiteral("name"), QStringLiteral("default"))
|
||||||
|
.toString()
|
||||||
|
.toStdString();
|
||||||
|
const std::size_t num_touch_maps = qt_config->beginReadArray(QStringLiteral("entries"));
|
||||||
|
map.buttons.reserve(num_touch_maps);
|
||||||
|
for (int i = 0; i < num_touch_maps; i++) {
|
||||||
|
qt_config->setArrayIndex(i);
|
||||||
|
std::string touch_mapping =
|
||||||
|
ReadSetting(QStringLiteral("bind")).toString().toStdString();
|
||||||
|
map.buttons.emplace_back(std::move(touch_mapping));
|
||||||
|
}
|
||||||
|
qt_config->endArray(); // entries
|
||||||
|
Settings::values.touch_from_button_maps.emplace_back(std::move(map));
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int i = 0; i < num_touch_from_button_maps; ++i) {
|
||||||
|
qt_config->setArrayIndex(i);
|
||||||
|
append_touch_from_button_map();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Settings::values.touch_from_button_maps.emplace_back(
|
||||||
|
Settings::TouchFromButtonMap{"default", {}});
|
||||||
|
num_touch_from_button_maps = 1;
|
||||||
|
}
|
||||||
|
qt_config->endArray();
|
||||||
|
|
||||||
Settings::values.current_input_profile_index =
|
Settings::values.current_input_profile_index =
|
||||||
ReadSetting(QStringLiteral("profile"), 0).toInt();
|
ReadSetting(QStringLiteral("profile"), 0).toInt();
|
||||||
|
|
||||||
const auto append_profile = [this] {
|
const auto append_profile = [this, num_touch_from_button_maps] {
|
||||||
Settings::InputProfile profile;
|
Settings::InputProfile profile;
|
||||||
profile.name =
|
profile.name =
|
||||||
ReadSetting(QStringLiteral("name"), QStringLiteral("default")).toString().toStdString();
|
ReadSetting(QStringLiteral("name"), QStringLiteral("default")).toString().toStdString();
|
||||||
|
@ -201,6 +233,12 @@ void Config::ReadControlValues() {
|
||||||
ReadSetting(QStringLiteral("touch_device"), QStringLiteral("engine:emu_window"))
|
ReadSetting(QStringLiteral("touch_device"), QStringLiteral("engine:emu_window"))
|
||||||
.toString()
|
.toString()
|
||||||
.toStdString();
|
.toStdString();
|
||||||
|
profile.use_touch_from_button =
|
||||||
|
ReadSetting(QStringLiteral("use_touch_from_button"), false).toBool();
|
||||||
|
profile.touch_from_button_map_index =
|
||||||
|
ReadSetting(QStringLiteral("touch_from_button_map"), 0).toInt();
|
||||||
|
profile.touch_from_button_map_index =
|
||||||
|
std::clamp(profile.touch_from_button_map_index, 0, num_touch_from_button_maps - 1);
|
||||||
profile.udp_input_address =
|
profile.udp_input_address =
|
||||||
ReadSetting(QStringLiteral("udp_input_address"),
|
ReadSetting(QStringLiteral("udp_input_address"),
|
||||||
QString::fromUtf8(InputCommon::CemuhookUDP::DEFAULT_ADDR))
|
QString::fromUtf8(InputCommon::CemuhookUDP::DEFAULT_ADDR))
|
||||||
|
@ -758,6 +796,9 @@ void Config::SaveControlValues() {
|
||||||
QStringLiteral("engine:motion_emu,update_period:100,sensitivity:0.01,tilt_clamp:90.0"));
|
QStringLiteral("engine:motion_emu,update_period:100,sensitivity:0.01,tilt_clamp:90.0"));
|
||||||
WriteSetting(QStringLiteral("touch_device"), QString::fromStdString(profile.touch_device),
|
WriteSetting(QStringLiteral("touch_device"), QString::fromStdString(profile.touch_device),
|
||||||
QStringLiteral("engine:emu_window"));
|
QStringLiteral("engine:emu_window"));
|
||||||
|
WriteSetting(QStringLiteral("use_touch_from_button"), profile.use_touch_from_button, false);
|
||||||
|
WriteSetting(QStringLiteral("touch_from_button_map"), profile.touch_from_button_map_index,
|
||||||
|
0);
|
||||||
WriteSetting(QStringLiteral("udp_input_address"),
|
WriteSetting(QStringLiteral("udp_input_address"),
|
||||||
QString::fromStdString(profile.udp_input_address),
|
QString::fromStdString(profile.udp_input_address),
|
||||||
QString::fromUtf8(InputCommon::CemuhookUDP::DEFAULT_ADDR));
|
QString::fromUtf8(InputCommon::CemuhookUDP::DEFAULT_ADDR));
|
||||||
|
@ -767,6 +808,21 @@ void Config::SaveControlValues() {
|
||||||
}
|
}
|
||||||
qt_config->endArray();
|
qt_config->endArray();
|
||||||
|
|
||||||
|
qt_config->beginWriteArray(QStringLiteral("touch_from_button_maps"));
|
||||||
|
for (std::size_t p = 0; p < Settings::values.touch_from_button_maps.size(); ++p) {
|
||||||
|
qt_config->setArrayIndex(static_cast<int>(p));
|
||||||
|
const auto& map = Settings::values.touch_from_button_maps[p];
|
||||||
|
WriteSetting(QStringLiteral("name"), QString::fromStdString(map.name),
|
||||||
|
QStringLiteral("default"));
|
||||||
|
qt_config->beginWriteArray(QStringLiteral("entries"));
|
||||||
|
for (std::size_t q = 0; q < map.buttons.size(); ++q) {
|
||||||
|
qt_config->setArrayIndex(static_cast<int>(q));
|
||||||
|
WriteSetting(QStringLiteral("bind"), QString::fromStdString(map.buttons[q]));
|
||||||
|
}
|
||||||
|
qt_config->endArray();
|
||||||
|
}
|
||||||
|
qt_config->endArray();
|
||||||
|
|
||||||
qt_config->endGroup();
|
qt_config->endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include "citra_qt/configuration/configure_motion_touch.h"
|
#include "citra_qt/configuration/configure_motion_touch.h"
|
||||||
#include "core/settings.h"
|
#include "citra_qt/configuration/configure_touch_from_button.h"
|
||||||
#include "input_common/main.h"
|
#include "input_common/main.h"
|
||||||
#include "ui_configure_motion_touch.h"
|
#include "ui_configure_motion_touch.h"
|
||||||
|
|
||||||
|
@ -111,6 +111,14 @@ void ConfigureMotionTouch::SetConfiguration() {
|
||||||
ui->motion_provider->findData(QString::fromStdString(motion_engine)));
|
ui->motion_provider->findData(QString::fromStdString(motion_engine)));
|
||||||
ui->touch_provider->setCurrentIndex(
|
ui->touch_provider->setCurrentIndex(
|
||||||
ui->touch_provider->findData(QString::fromStdString(touch_engine)));
|
ui->touch_provider->findData(QString::fromStdString(touch_engine)));
|
||||||
|
ui->touch_from_button_checkbox->setChecked(
|
||||||
|
Settings::values.current_input_profile.use_touch_from_button);
|
||||||
|
touch_from_button_maps = Settings::values.touch_from_button_maps;
|
||||||
|
for (const auto& touch_map : touch_from_button_maps) {
|
||||||
|
ui->touch_from_button_map->addItem(QString::fromStdString(touch_map.name));
|
||||||
|
}
|
||||||
|
ui->touch_from_button_map->setCurrentIndex(
|
||||||
|
Settings::values.current_input_profile.touch_from_button_map_index);
|
||||||
ui->motion_sensitivity->setValue(motion_param.Get("sensitivity", 0.01f));
|
ui->motion_sensitivity->setValue(motion_param.Get("sensitivity", 0.01f));
|
||||||
|
|
||||||
min_x = touch_param.Get("min_x", 100);
|
min_x = touch_param.Get("min_x", 100);
|
||||||
|
@ -166,6 +174,8 @@ void ConfigureMotionTouch::ConnectEvents() {
|
||||||
connect(ui->udp_test, &QPushButton::clicked, this, &ConfigureMotionTouch::OnCemuhookUDPTest);
|
connect(ui->udp_test, &QPushButton::clicked, this, &ConfigureMotionTouch::OnCemuhookUDPTest);
|
||||||
connect(ui->touch_calibration_config, &QPushButton::clicked, this,
|
connect(ui->touch_calibration_config, &QPushButton::clicked, this,
|
||||||
&ConfigureMotionTouch::OnConfigureTouchCalibration);
|
&ConfigureMotionTouch::OnConfigureTouchCalibration);
|
||||||
|
connect(ui->touch_from_button_config_btn, &QPushButton::clicked, this,
|
||||||
|
&ConfigureMotionTouch::OnConfigureTouchFromButton);
|
||||||
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, [this] {
|
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, [this] {
|
||||||
if (CanCloseDialog())
|
if (CanCloseDialog())
|
||||||
reject();
|
reject();
|
||||||
|
@ -234,6 +244,23 @@ void ConfigureMotionTouch::ShowUDPTestResult(bool result) {
|
||||||
ui->udp_test->setText(tr("Test"));
|
ui->udp_test->setText(tr("Test"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConfigureMotionTouch::OnConfigureTouchFromButton() {
|
||||||
|
ConfigureTouchFromButton dialog{this, touch_from_button_maps,
|
||||||
|
ui->touch_from_button_map->currentIndex()};
|
||||||
|
if (dialog.exec() != QDialog::Accepted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
touch_from_button_maps = dialog.GetMaps();
|
||||||
|
|
||||||
|
while (ui->touch_from_button_map->count() > 0) {
|
||||||
|
ui->touch_from_button_map->removeItem(0);
|
||||||
|
}
|
||||||
|
for (const auto& touch_map : touch_from_button_maps) {
|
||||||
|
ui->touch_from_button_map->addItem(QString::fromStdString(touch_map.name));
|
||||||
|
}
|
||||||
|
ui->touch_from_button_map->setCurrentIndex(dialog.GetSelectedIndex());
|
||||||
|
}
|
||||||
|
|
||||||
bool ConfigureMotionTouch::CanCloseDialog() {
|
bool ConfigureMotionTouch::CanCloseDialog() {
|
||||||
if (udp_test_in_progress) {
|
if (udp_test_in_progress) {
|
||||||
QMessageBox::warning(this, tr("Citra"),
|
QMessageBox::warning(this, tr("Citra"),
|
||||||
|
@ -268,6 +295,11 @@ void ConfigureMotionTouch::ApplyConfiguration() {
|
||||||
|
|
||||||
Settings::values.current_input_profile.motion_device = motion_param.Serialize();
|
Settings::values.current_input_profile.motion_device = motion_param.Serialize();
|
||||||
Settings::values.current_input_profile.touch_device = touch_param.Serialize();
|
Settings::values.current_input_profile.touch_device = touch_param.Serialize();
|
||||||
|
Settings::values.current_input_profile.use_touch_from_button =
|
||||||
|
ui->touch_from_button_checkbox->isChecked();
|
||||||
|
Settings::values.current_input_profile.touch_from_button_map_index =
|
||||||
|
ui->touch_from_button_map->currentIndex();
|
||||||
|
Settings::values.touch_from_button_maps = touch_from_button_maps;
|
||||||
Settings::values.current_input_profile.udp_input_address = ui->udp_server->text().toStdString();
|
Settings::values.current_input_profile.udp_input_address = ui->udp_server->text().toStdString();
|
||||||
Settings::values.current_input_profile.udp_input_port =
|
Settings::values.current_input_profile.udp_input_port =
|
||||||
static_cast<u16>(ui->udp_port->text().toInt());
|
static_cast<u16>(ui->udp_port->text().toInt());
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include "common/param_package.h"
|
#include "common/param_package.h"
|
||||||
|
#include "core/settings.h"
|
||||||
#include "input_common/udp/udp.h"
|
#include "input_common/udp/udp.h"
|
||||||
|
|
||||||
class QVBoxLayout;
|
class QVBoxLayout;
|
||||||
|
@ -54,6 +55,7 @@ public slots:
|
||||||
private slots:
|
private slots:
|
||||||
void OnCemuhookUDPTest();
|
void OnCemuhookUDPTest();
|
||||||
void OnConfigureTouchCalibration();
|
void OnConfigureTouchCalibration();
|
||||||
|
void OnConfigureTouchFromButton();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void closeEvent(QCloseEvent* event) override;
|
void closeEvent(QCloseEvent* event) override;
|
||||||
|
@ -69,4 +71,6 @@ private:
|
||||||
int min_x, min_y, max_x, max_y;
|
int min_x, min_y, max_x, max_y;
|
||||||
|
|
||||||
bool udp_test_in_progress{};
|
bool udp_test_in_progress{};
|
||||||
|
|
||||||
|
std::vector<Settings::TouchFromButtonMap> touch_from_button_maps;
|
||||||
};
|
};
|
||||||
|
|
|
@ -124,6 +124,39 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="touch_from_button_checkbox">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Use button mapping:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="touch_from_button_map"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="touch_from_button_config_btn">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Configure</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
321
src/citra_qt/configuration/configure_touch_from_button.cpp
Normal file
321
src/citra_qt/configuration/configure_touch_from_button.cpp
Normal file
|
@ -0,0 +1,321 @@
|
||||||
|
// Copyright 2020 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include <QInputDialog>
|
||||||
|
#include <QKeyEvent>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QStandardItemModel>
|
||||||
|
#include <QTimer>
|
||||||
|
#include "citra_qt/configuration/configure_touch_from_button.h"
|
||||||
|
#include "common/param_package.h"
|
||||||
|
#include "input_common/main.h"
|
||||||
|
#include "ui_configure_touch_from_button.h"
|
||||||
|
|
||||||
|
static QString GetKeyName(int key_code) {
|
||||||
|
switch (key_code) {
|
||||||
|
case Qt::Key_Shift:
|
||||||
|
return QObject::tr("Shift");
|
||||||
|
case Qt::Key_Control:
|
||||||
|
return QObject::tr("Ctrl");
|
||||||
|
case Qt::Key_Alt:
|
||||||
|
return QObject::tr("Alt");
|
||||||
|
case Qt::Key_Meta:
|
||||||
|
return QString{};
|
||||||
|
default:
|
||||||
|
return QKeySequence(key_code).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static QString ButtonToText(const Common::ParamPackage& param) {
|
||||||
|
if (!param.Has("engine")) {
|
||||||
|
return QObject::tr("[not set]");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param.Get("engine", "") == "keyboard") {
|
||||||
|
return GetKeyName(param.Get("code", 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param.Get("engine", "") == "sdl") {
|
||||||
|
if (param.Has("hat")) {
|
||||||
|
const QString hat_str = QString::fromStdString(param.Get("hat", ""));
|
||||||
|
const QString direction_str = QString::fromStdString(param.Get("direction", ""));
|
||||||
|
|
||||||
|
return QObject::tr("Hat %1 %2").arg(hat_str, direction_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param.Has("axis")) {
|
||||||
|
const QString axis_str = QString::fromStdString(param.Get("axis", ""));
|
||||||
|
const QString direction_str = QString::fromStdString(param.Get("direction", ""));
|
||||||
|
|
||||||
|
return QObject::tr("Axis %1%2").arg(axis_str, direction_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (param.Has("button")) {
|
||||||
|
const QString button_str = QString::fromStdString(param.Get("button", ""));
|
||||||
|
|
||||||
|
return QObject::tr("Button %1").arg(button_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return QObject::tr("[unknown]");
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigureTouchFromButton::ConfigureTouchFromButton(
|
||||||
|
QWidget* parent, std::vector<Settings::TouchFromButtonMap> touch_maps, int default_index)
|
||||||
|
: QDialog(parent), touch_maps(touch_maps), selected_index(default_index),
|
||||||
|
ui(std::make_unique<Ui::ConfigureTouchFromButton>()),
|
||||||
|
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());
|
||||||
|
|
||||||
|
SetConfiguration();
|
||||||
|
UpdateUiDisplay();
|
||||||
|
ConnectEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
ConfigureTouchFromButton::~ConfigureTouchFromButton() = default;
|
||||||
|
|
||||||
|
void ConfigureTouchFromButton::showEvent(QShowEvent* ev) {
|
||||||
|
QWidget::showEvent(ev);
|
||||||
|
|
||||||
|
// width values are not valid in the constructor
|
||||||
|
const int w = ui->binding_list->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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigureTouchFromButton::SetConfiguration() {
|
||||||
|
for (const auto& touch_map : touch_maps) {
|
||||||
|
ui->mapping->addItem(QString::fromStdString(touch_map.name));
|
||||||
|
}
|
||||||
|
|
||||||
|
ui->mapping->setCurrentIndex(selected_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigureTouchFromButton::UpdateUiDisplay() {
|
||||||
|
const bool have_maps = !touch_maps.empty();
|
||||||
|
|
||||||
|
ui->button_delete->setEnabled(touch_maps.size() > 1);
|
||||||
|
ui->button_rename->setEnabled(have_maps);
|
||||||
|
ui->binding_list->setEnabled(have_maps);
|
||||||
|
ui->button_add_bind->setEnabled(have_maps);
|
||||||
|
ui->button_delete_bind->setEnabled(false);
|
||||||
|
|
||||||
|
binding_list_model->removeRows(0, binding_list_model->rowCount());
|
||||||
|
|
||||||
|
if (!have_maps) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& button_str : touch_maps[selected_index].buttons) {
|
||||||
|
Common::ParamPackage package{button_str};
|
||||||
|
QStandardItem* button = new QStandardItem(ButtonToText(package));
|
||||||
|
button->setData(QString::fromStdString(button_str));
|
||||||
|
button->setEditable(false);
|
||||||
|
QStandardItem* xcoord = new QStandardItem(QString::number(package.Get("x", 0)));
|
||||||
|
QStandardItem* ycoord = new QStandardItem(QString::number(package.Get("y", 0)));
|
||||||
|
binding_list_model->appendRow({button, xcoord, ycoord});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigureTouchFromButton::ConnectEvents() {
|
||||||
|
connect(ui->mapping, qOverload<int>(&QComboBox::activated), this, [this](int index) {
|
||||||
|
SaveCurrentMapping();
|
||||||
|
selected_index = index;
|
||||||
|
UpdateUiDisplay();
|
||||||
|
});
|
||||||
|
connect(ui->button_new, &QPushButton::clicked, this, &ConfigureTouchFromButton::NewMapping);
|
||||||
|
connect(ui->button_delete, &QPushButton::clicked, this,
|
||||||
|
&ConfigureTouchFromButton::DeleteMapping);
|
||||||
|
connect(ui->button_rename, &QPushButton::clicked, this,
|
||||||
|
&ConfigureTouchFromButton::RenameMapping);
|
||||||
|
connect(ui->button_add_bind, &QPushButton::clicked, this,
|
||||||
|
&ConfigureTouchFromButton::NewBinding);
|
||||||
|
connect(ui->button_delete_bind, &QPushButton::clicked, this,
|
||||||
|
&ConfigureTouchFromButton::DeleteBinding);
|
||||||
|
connect(ui->binding_list, &QTreeView::doubleClicked, this,
|
||||||
|
&ConfigureTouchFromButton::EditBinding);
|
||||||
|
connect(ui->binding_list->selectionModel(), &QItemSelectionModel::selectionChanged, this,
|
||||||
|
[this](const QItemSelection& selected, const QItemSelection& deselected) {
|
||||||
|
ui->button_delete_bind->setEnabled(!selected.indexes().isEmpty());
|
||||||
|
});
|
||||||
|
connect(ui->buttonBox, &QDialogButtonBox::accepted, this,
|
||||||
|
&ConfigureTouchFromButton::ApplyConfiguration);
|
||||||
|
|
||||||
|
connect(timeout_timer.get(), &QTimer::timeout, [this]() { SetPollingResult({}, true); });
|
||||||
|
|
||||||
|
connect(poll_timer.get(), &QTimer::timeout, [this]() {
|
||||||
|
Common::ParamPackage params;
|
||||||
|
for (auto& poller : device_pollers) {
|
||||||
|
params = poller->GetNextInput();
|
||||||
|
if (params.Has("engine")) {
|
||||||
|
SetPollingResult(params, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigureTouchFromButton::SaveCurrentMapping() {
|
||||||
|
auto& map = touch_maps[selected_index];
|
||||||
|
map.buttons.clear();
|
||||||
|
for (int i = 0, rc = binding_list_model->rowCount(); i < rc; ++i) {
|
||||||
|
auto bind_str = binding_list_model->index(i, 0)
|
||||||
|
.data(Qt::ItemDataRole::UserRole + 1)
|
||||||
|
.toString()
|
||||||
|
.toStdString();
|
||||||
|
if (bind_str.empty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Common::ParamPackage params{bind_str};
|
||||||
|
if (!params.Has("engine")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
params.Set("x", binding_list_model->index(i, 1).data().toInt());
|
||||||
|
params.Set("y", binding_list_model->index(i, 2).data().toInt());
|
||||||
|
map.buttons.emplace_back(params.Serialize());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigureTouchFromButton::NewMapping() {
|
||||||
|
const QString name =
|
||||||
|
QInputDialog::getText(this, tr("New Profile"), tr("Enter the name for the new profile."));
|
||||||
|
if (name.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selected_index > 0) {
|
||||||
|
SaveCurrentMapping();
|
||||||
|
}
|
||||||
|
touch_maps.emplace_back(Settings::TouchFromButtonMap{name.toStdString(), {}});
|
||||||
|
selected_index = touch_maps.size() - 1;
|
||||||
|
|
||||||
|
ui->mapping->addItem(name);
|
||||||
|
ui->mapping->setCurrentIndex(selected_index);
|
||||||
|
UpdateUiDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigureTouchFromButton::DeleteMapping() {
|
||||||
|
const auto answer = QMessageBox::question(
|
||||||
|
this, tr("Delete Profile"), tr("Delete profile %1?").arg(ui->mapping->currentText()));
|
||||||
|
if (answer != QMessageBox::Yes) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ui->mapping->removeItem(selected_index);
|
||||||
|
ui->mapping->setCurrentIndex(0);
|
||||||
|
touch_maps.erase(touch_maps.begin() + selected_index);
|
||||||
|
selected_index = touch_maps.size() ? 0 : -1;
|
||||||
|
UpdateUiDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigureTouchFromButton::RenameMapping() {
|
||||||
|
const QString new_name = QInputDialog::getText(this, tr("Rename Profile"), tr("New name:"));
|
||||||
|
if (new_name.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ui->mapping->setItemText(selected_index, new_name);
|
||||||
|
touch_maps[selected_index].name = new_name.toStdString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigureTouchFromButton::GetButtonInput(int row_index, bool is_new) {
|
||||||
|
binding_list_model->item(row_index, 0)->setText(tr("[press key]"));
|
||||||
|
|
||||||
|
input_setter = [this, row_index, is_new](const Common::ParamPackage& params,
|
||||||
|
const bool cancel) {
|
||||||
|
auto cell = binding_list_model->item(row_index, 0);
|
||||||
|
if (!cancel) {
|
||||||
|
cell->setText(ButtonToText(params));
|
||||||
|
cell->setData(QString::fromStdString(params.Serialize()));
|
||||||
|
} else {
|
||||||
|
if (is_new) {
|
||||||
|
binding_list_model->removeRow(row_index);
|
||||||
|
} else {
|
||||||
|
cell->setText(
|
||||||
|
ButtonToText(Common::ParamPackage{cell->data().toString().toStdString()}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
device_pollers = InputCommon::Polling::GetPollers(InputCommon::Polling::DeviceType::Button);
|
||||||
|
|
||||||
|
for (auto& poller : device_pollers) {
|
||||||
|
poller->Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
grabKeyboard();
|
||||||
|
grabMouse();
|
||||||
|
timeout_timer->start(5000); // Cancel after 5 seconds
|
||||||
|
poll_timer->start(200); // Check for new inputs every 200ms
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigureTouchFromButton::NewBinding() {
|
||||||
|
QStandardItem* button = new QStandardItem();
|
||||||
|
button->setEditable(false);
|
||||||
|
binding_list_model->appendRow(
|
||||||
|
{button, new QStandardItem(QStringLiteral("0")), new QStandardItem(QStringLiteral("0"))});
|
||||||
|
ui->binding_list->setFocus();
|
||||||
|
ui->binding_list->setCurrentIndex(button->index());
|
||||||
|
|
||||||
|
GetButtonInput(binding_list_model->rowCount() - 1, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigureTouchFromButton::EditBinding(const QModelIndex& qi) {
|
||||||
|
if (qi.row() >= 0 && qi.column() == 0) {
|
||||||
|
GetButtonInput(qi.row(), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigureTouchFromButton::DeleteBinding() {
|
||||||
|
const int row_index = ui->binding_list->currentIndex().row();
|
||||||
|
if (row_index >= 0) {
|
||||||
|
binding_list_model->removeRow(row_index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigureTouchFromButton::SetPollingResult(const Common::ParamPackage& params, bool cancel) {
|
||||||
|
releaseKeyboard();
|
||||||
|
releaseMouse();
|
||||||
|
timeout_timer->stop();
|
||||||
|
poll_timer->stop();
|
||||||
|
for (auto& poller : device_pollers) {
|
||||||
|
poller->Stop();
|
||||||
|
}
|
||||||
|
if (input_setter) {
|
||||||
|
(*input_setter)(params, cancel);
|
||||||
|
input_setter.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigureTouchFromButton::keyPressEvent(QKeyEvent* event) {
|
||||||
|
if (!input_setter || !event)
|
||||||
|
return QDialog::keyPressEvent(event);
|
||||||
|
|
||||||
|
if (event->key() != Qt::Key_Escape) {
|
||||||
|
SetPollingResult(Common::ParamPackage{InputCommon::GenerateKeyboardParam(event->key())},
|
||||||
|
false);
|
||||||
|
} else {
|
||||||
|
SetPollingResult({}, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigureTouchFromButton::ApplyConfiguration() {
|
||||||
|
SaveCurrentMapping();
|
||||||
|
accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
const int ConfigureTouchFromButton::GetSelectedIndex() {
|
||||||
|
return selected_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<Settings::TouchFromButtonMap> ConfigureTouchFromButton::GetMaps() {
|
||||||
|
return touch_maps;
|
||||||
|
};
|
74
src/citra_qt/configuration/configure_touch_from_button.h
Normal file
74
src/citra_qt/configuration/configure_touch_from_button.h
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
// Copyright 2020 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
|
#include <QDialog>
|
||||||
|
#include "core/settings.h"
|
||||||
|
|
||||||
|
class QKeyEvent;
|
||||||
|
class QModelIndex;
|
||||||
|
class QStandardItemModel;
|
||||||
|
class QTimer;
|
||||||
|
|
||||||
|
namespace Common {
|
||||||
|
class ParamPackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace InputCommon {
|
||||||
|
namespace Polling {
|
||||||
|
class DevicePoller;
|
||||||
|
}
|
||||||
|
} // namespace InputCommon
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class ConfigureTouchFromButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ConfigureTouchFromButton : public QDialog {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ConfigureTouchFromButton(QWidget* parent,
|
||||||
|
std::vector<Settings::TouchFromButtonMap> touch_maps,
|
||||||
|
int default_index = 0);
|
||||||
|
~ConfigureTouchFromButton() override;
|
||||||
|
|
||||||
|
const int GetSelectedIndex();
|
||||||
|
const std::vector<Settings::TouchFromButtonMap> GetMaps();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void ApplyConfiguration();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void showEvent(QShowEvent* ev);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void SetConfiguration();
|
||||||
|
void UpdateUiDisplay();
|
||||||
|
void ConnectEvents();
|
||||||
|
void NewMapping();
|
||||||
|
void DeleteMapping();
|
||||||
|
void RenameMapping();
|
||||||
|
void NewBinding();
|
||||||
|
void EditBinding(const QModelIndex& qi);
|
||||||
|
void DeleteBinding();
|
||||||
|
void GetButtonInput(int row_index, bool is_new);
|
||||||
|
void SetPollingResult(const Common::ParamPackage& params, bool cancel);
|
||||||
|
void SaveCurrentMapping();
|
||||||
|
void keyPressEvent(QKeyEvent* event) override;
|
||||||
|
|
||||||
|
std::unique_ptr<Ui::ConfigureTouchFromButton> ui;
|
||||||
|
std::unique_ptr<QStandardItemModel> binding_list_model;
|
||||||
|
std::vector<Settings::TouchFromButtonMap> touch_maps;
|
||||||
|
int selected_index;
|
||||||
|
|
||||||
|
std::unique_ptr<QTimer> timeout_timer;
|
||||||
|
std::unique_ptr<QTimer> poll_timer;
|
||||||
|
std::vector<std::unique_ptr<InputCommon::Polling::DevicePoller>> device_pollers;
|
||||||
|
std::optional<std::function<void(const Common::ParamPackage&, const bool)>> input_setter;
|
||||||
|
};
|
169
src/citra_qt/configuration/configure_touch_from_button.ui
Normal file
169
src/citra_qt/configuration/configure_touch_from_button.ui
Normal file
|
@ -0,0 +1,169 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>ConfigureTouchFromButton</class>
|
||||||
|
<widget class="QDialog" name="ConfigureTouchFromButton">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>500</width>
|
||||||
|
<height>450</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Configure Touchscreen Mappings</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Mapping:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="mapping">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="button_new">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>New</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="button_delete">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Delete</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="button_rename">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Rename</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="Line" name="line">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Double-click to change a field.</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="button_add_bind">
|
||||||
|
<property name="text">
|
||||||
|
<string>Add</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="button_delete_bind">
|
||||||
|
<property name="text">
|
||||||
|
<string>Delete</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QTreeView" name="binding_list">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="rootIsDecorated">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="uniformRowHeights">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="itemsExpandable">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>ConfigureTouchFromButton</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>249</x>
|
||||||
|
<y>428</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>249</x>
|
||||||
|
<y>224</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
|
@ -1693,6 +1693,7 @@ void GMainWindow::OnConfigure() {
|
||||||
auto old_theme = UISettings::values.theme;
|
auto old_theme = UISettings::values.theme;
|
||||||
const int old_input_profile_index = Settings::values.current_input_profile_index;
|
const int old_input_profile_index = Settings::values.current_input_profile_index;
|
||||||
const auto old_input_profiles = Settings::values.input_profiles;
|
const auto old_input_profiles = Settings::values.input_profiles;
|
||||||
|
const auto old_touch_from_button_maps = Settings::values.touch_from_button_maps;
|
||||||
const bool old_discord_presence = UISettings::values.enable_discord_presence;
|
const bool old_discord_presence = UISettings::values.enable_discord_presence;
|
||||||
auto result = configureDialog.exec();
|
auto result = configureDialog.exec();
|
||||||
if (result == QDialog::Accepted) {
|
if (result == QDialog::Accepted) {
|
||||||
|
@ -1718,6 +1719,7 @@ void GMainWindow::OnConfigure() {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Settings::values.input_profiles = old_input_profiles;
|
Settings::values.input_profiles = old_input_profiles;
|
||||||
|
Settings::values.touch_from_button_maps = old_touch_from_button_maps;
|
||||||
Settings::LoadProfile(old_input_profile_index);
|
Settings::LoadProfile(old_input_profile_index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,6 +103,11 @@ void Module::LoadInputDevices() {
|
||||||
Settings::values.current_input_profile.motion_device);
|
Settings::values.current_input_profile.motion_device);
|
||||||
touch_device = Input::CreateDevice<Input::TouchDevice>(
|
touch_device = Input::CreateDevice<Input::TouchDevice>(
|
||||||
Settings::values.current_input_profile.touch_device);
|
Settings::values.current_input_profile.touch_device);
|
||||||
|
if (Settings::values.current_input_profile.use_touch_from_button) {
|
||||||
|
touch_btn_device = Input::CreateDevice<Input::TouchDevice>("engine:touch_from_button");
|
||||||
|
} else {
|
||||||
|
touch_btn_device.reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::UpdatePadCallback(u64 userdata, s64 cycles_late) {
|
void Module::UpdatePadCallback(u64 userdata, s64 cycles_late) {
|
||||||
|
@ -177,6 +182,9 @@ void Module::UpdatePadCallback(u64 userdata, s64 cycles_late) {
|
||||||
bool pressed = false;
|
bool pressed = false;
|
||||||
float x, y;
|
float x, y;
|
||||||
std::tie(x, y, pressed) = touch_device->GetStatus();
|
std::tie(x, y, pressed) = touch_device->GetStatus();
|
||||||
|
if (!pressed && touch_btn_device) {
|
||||||
|
std::tie(x, y, pressed) = touch_btn_device->GetStatus();
|
||||||
|
}
|
||||||
touch_entry.x = static_cast<u16>(x * Core::kScreenBottomWidth);
|
touch_entry.x = static_cast<u16>(x * Core::kScreenBottomWidth);
|
||||||
touch_entry.y = static_cast<u16>(y * Core::kScreenBottomHeight);
|
touch_entry.y = static_cast<u16>(y * Core::kScreenBottomHeight);
|
||||||
touch_entry.valid.Assign(pressed ? 1 : 0);
|
touch_entry.valid.Assign(pressed ? 1 : 0);
|
||||||
|
|
|
@ -336,6 +336,7 @@ private:
|
||||||
std::unique_ptr<Input::AnalogDevice> circle_pad;
|
std::unique_ptr<Input::AnalogDevice> circle_pad;
|
||||||
std::unique_ptr<Input::MotionDevice> motion_device;
|
std::unique_ptr<Input::MotionDevice> motion_device;
|
||||||
std::unique_ptr<Input::TouchDevice> touch_device;
|
std::unique_ptr<Input::TouchDevice> touch_device;
|
||||||
|
std::unique_ptr<Input::TouchDevice> touch_btn_device;
|
||||||
|
|
||||||
template <class Archive>
|
template <class Archive>
|
||||||
void serialize(Archive& ar, const unsigned int);
|
void serialize(Archive& ar, const unsigned int);
|
||||||
|
|
|
@ -112,11 +112,18 @@ struct InputProfile {
|
||||||
std::array<std::string, NativeAnalog::NumAnalogs> analogs;
|
std::array<std::string, NativeAnalog::NumAnalogs> analogs;
|
||||||
std::string motion_device;
|
std::string motion_device;
|
||||||
std::string touch_device;
|
std::string touch_device;
|
||||||
|
bool use_touch_from_button;
|
||||||
|
int touch_from_button_map_index;
|
||||||
std::string udp_input_address;
|
std::string udp_input_address;
|
||||||
u16 udp_input_port;
|
u16 udp_input_port;
|
||||||
u8 udp_pad_index;
|
u8 udp_pad_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct TouchFromButtonMap {
|
||||||
|
std::string name;
|
||||||
|
std::vector<std::string> buttons;
|
||||||
|
};
|
||||||
|
|
||||||
struct Values {
|
struct Values {
|
||||||
// CheckNew3DS
|
// CheckNew3DS
|
||||||
bool is_new_3ds;
|
bool is_new_3ds;
|
||||||
|
@ -125,6 +132,7 @@ struct Values {
|
||||||
InputProfile current_input_profile; ///< The current input profile
|
InputProfile current_input_profile; ///< The current input profile
|
||||||
int current_input_profile_index; ///< The current input profile index
|
int current_input_profile_index; ///< The current input profile index
|
||||||
std::vector<InputProfile> input_profiles; ///< The list of input profiles
|
std::vector<InputProfile> input_profiles; ///< The list of input profiles
|
||||||
|
std::vector<TouchFromButtonMap> touch_from_button_maps;
|
||||||
|
|
||||||
// Core
|
// Core
|
||||||
bool use_cpu_jit;
|
bool use_cpu_jit;
|
||||||
|
|
|
@ -7,6 +7,8 @@ add_library(input_common STATIC
|
||||||
main.h
|
main.h
|
||||||
motion_emu.cpp
|
motion_emu.cpp
|
||||||
motion_emu.h
|
motion_emu.h
|
||||||
|
touch_from_button.cpp
|
||||||
|
touch_from_button.h
|
||||||
sdl/sdl.cpp
|
sdl/sdl.cpp
|
||||||
sdl/sdl.h
|
sdl/sdl.h
|
||||||
udp/client.cpp
|
udp/client.cpp
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "input_common/main.h"
|
#include "input_common/main.h"
|
||||||
#include "input_common/motion_emu.h"
|
#include "input_common/motion_emu.h"
|
||||||
#include "input_common/sdl/sdl.h"
|
#include "input_common/sdl/sdl.h"
|
||||||
|
#include "input_common/touch_from_button.h"
|
||||||
#include "input_common/udp/udp.h"
|
#include "input_common/udp/udp.h"
|
||||||
|
|
||||||
namespace InputCommon {
|
namespace InputCommon {
|
||||||
|
@ -26,6 +27,8 @@ void Init() {
|
||||||
std::make_shared<AnalogFromButton>());
|
std::make_shared<AnalogFromButton>());
|
||||||
motion_emu = std::make_shared<MotionEmu>();
|
motion_emu = std::make_shared<MotionEmu>();
|
||||||
Input::RegisterFactory<Input::MotionDevice>("motion_emu", motion_emu);
|
Input::RegisterFactory<Input::MotionDevice>("motion_emu", motion_emu);
|
||||||
|
Input::RegisterFactory<Input::TouchDevice>("touch_from_button",
|
||||||
|
std::make_shared<TouchFromButtonFactory>());
|
||||||
|
|
||||||
sdl = SDL::Init();
|
sdl = SDL::Init();
|
||||||
|
|
||||||
|
@ -38,6 +41,7 @@ void Shutdown() {
|
||||||
Input::UnregisterFactory<Input::AnalogDevice>("analog_from_button");
|
Input::UnregisterFactory<Input::AnalogDevice>("analog_from_button");
|
||||||
Input::UnregisterFactory<Input::MotionDevice>("motion_emu");
|
Input::UnregisterFactory<Input::MotionDevice>("motion_emu");
|
||||||
motion_emu.reset();
|
motion_emu.reset();
|
||||||
|
Input::UnregisterFactory<Input::TouchDevice>("touch_from_button");
|
||||||
sdl.reset();
|
sdl.reset();
|
||||||
udp.reset();
|
udp.reset();
|
||||||
}
|
}
|
||||||
|
|
49
src/input_common/touch_from_button.cpp
Normal file
49
src/input_common/touch_from_button.cpp
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
// Copyright 2020 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include "core/3ds.h"
|
||||||
|
#include "core/settings.h"
|
||||||
|
#include "input_common/touch_from_button.h"
|
||||||
|
|
||||||
|
namespace InputCommon {
|
||||||
|
|
||||||
|
class TouchFromButtonDevice final : public Input::TouchDevice {
|
||||||
|
public:
|
||||||
|
TouchFromButtonDevice() {
|
||||||
|
for (const auto& config_entry :
|
||||||
|
Settings::values
|
||||||
|
.touch_from_button_maps[Settings::values.current_input_profile
|
||||||
|
.touch_from_button_map_index]
|
||||||
|
.buttons) {
|
||||||
|
|
||||||
|
const Common::ParamPackage package{config_entry};
|
||||||
|
map.emplace_back(Input::CreateDevice<Input::ButtonDevice>(config_entry),
|
||||||
|
std::clamp(package.Get("x", 0), 0, Core::kScreenBottomWidth),
|
||||||
|
std::clamp(package.Get("y", 0), 0, Core::kScreenBottomHeight));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::tuple<float, float, bool> GetStatus() const override {
|
||||||
|
for (const auto& m : map) {
|
||||||
|
const bool state = std::get<0>(m)->GetStatus();
|
||||||
|
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 std::make_tuple(0.0f, 0.0f, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<std::tuple<std::unique_ptr<Input::ButtonDevice>, int, int>> map; // button, x, y
|
||||||
|
};
|
||||||
|
|
||||||
|
std::unique_ptr<Input::TouchDevice> TouchFromButtonFactory::Create(
|
||||||
|
const Common::ParamPackage& params) {
|
||||||
|
|
||||||
|
return std::make_unique<TouchFromButtonDevice>();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace InputCommon
|
24
src/input_common/touch_from_button.h
Normal file
24
src/input_common/touch_from_button.h
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
// Copyright 2020 Citra Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include "core/frontend/input.h"
|
||||||
|
|
||||||
|
namespace InputCommon {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A touch device factory that takes a list of button devices and combines them into a touch device.
|
||||||
|
*/
|
||||||
|
class TouchFromButtonFactory final : public Input::Factory<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;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace InputCommon
|
Loading…
Reference in a new issue