-
Notifications
You must be signed in to change notification settings - Fork 722
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Qt: Add per-bind sensitivity/deadzone controls (shift-click)
- Loading branch information
Showing
5 changed files
with
209 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <[email protected]> | ||
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <[email protected]> | ||
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) | ||
|
||
#include "inputbindingdialog.h" | ||
#include "common/bitutils.h" | ||
#include "controllersettingwidgetbinder.h" | ||
#include "inputbindingwidgets.h" | ||
#include "qthost.h" | ||
#include "qtutils.h" | ||
|
||
#include "common/bitutils.h" | ||
|
||
#include <QtCore/QTimer> | ||
#include <QtGui/QKeyEvent> | ||
#include <QtGui/QMouseEvent> | ||
|
@@ -27,6 +30,28 @@ InputBindingDialog::InputBindingDialog(SettingsInterface* sif, InputBindingInfo: | |
connect(m_ui.clearBindings, &QPushButton::clicked, this, &InputBindingDialog::onClearBindingsButtonClicked); | ||
connect(m_ui.buttonBox, &QDialogButtonBox::rejected, [this]() { done(0); }); | ||
updateList(); | ||
|
||
// Only show the sensitivity controls for binds where it's applicable. | ||
if (bind_type == InputBindingInfo::Type::Button || bind_type == InputBindingInfo::Type::Axis || | ||
bind_type == InputBindingInfo::Type::HalfAxis) | ||
{ | ||
ControllerSettingWidgetBinder::BindWidgetToInputProfileNormalized(sif, m_ui.sensitivity, m_section_name, | ||
fmt::format("{}Scale", m_key_name), 100.0f, 1.0f); | ||
ControllerSettingWidgetBinder::BindWidgetToInputProfileNormalized( | ||
sif, m_ui.deadzone, m_section_name, fmt::format("{}Deadzone", m_key_name), 100.0f, 0.0f); | ||
|
||
connect(m_ui.sensitivity, &QSlider::valueChanged, this, &InputBindingDialog::onSensitivityChanged); | ||
connect(m_ui.resetSensitivity, &QToolButton::clicked, this, &InputBindingDialog::onResetSensitivityClicked); | ||
connect(m_ui.deadzone, &QSlider::valueChanged, this, &InputBindingDialog::onDeadzoneChanged); | ||
connect(m_ui.resetDeadzone, &QToolButton::clicked, this, &InputBindingDialog::onResetDeadzoneClicked); | ||
|
||
onSensitivityChanged(m_ui.sensitivity->value()); | ||
onDeadzoneChanged(m_ui.deadzone->value()); | ||
} | ||
else | ||
{ | ||
m_ui.verticalLayout->removeWidget(m_ui.sensitivityWidget); | ||
} | ||
} | ||
|
||
InputBindingDialog::~InputBindingDialog() | ||
|
@@ -302,6 +327,56 @@ void InputBindingDialog::inputManagerHookCallback(InputBindingKey key, float val | |
} | ||
} | ||
|
||
void InputBindingDialog::onSensitivityChanged(int value) | ||
{ | ||
m_ui.sensitivityValue->setText(tr("%1%").arg(value)); | ||
} | ||
|
||
void InputBindingDialog::onResetDeadzoneClicked() | ||
{ | ||
m_ui.deadzone->setValue(0); | ||
|
||
// May as well remove from the config completely, since it's the default. | ||
const TinyString key = TinyString::from_format("{}Deadzone", m_key_name); | ||
if (m_sif) | ||
{ | ||
m_sif->DeleteValue(m_section_name.c_str(), key); | ||
QtHost::SaveGameSettings(m_sif, false); | ||
g_emu_thread->reloadGameSettings(false); | ||
} | ||
else | ||
{ | ||
Host::DeleteBaseSettingValue(m_section_name.c_str(), key); | ||
Host::CommitBaseSettingChanges(); | ||
g_emu_thread->applySettings(false); | ||
} | ||
} | ||
|
||
void InputBindingDialog::onDeadzoneChanged(int value) | ||
{ | ||
m_ui.deadzoneValue->setText(tr("%1%").arg(value)); | ||
} | ||
|
||
void InputBindingDialog::onResetSensitivityClicked() | ||
{ | ||
m_ui.sensitivity->setValue(100); | ||
|
||
// May as well remove from the config completely, since it's the default. | ||
const TinyString key = TinyString::from_format("{}Scale", m_key_name); | ||
if (m_sif) | ||
{ | ||
m_sif->DeleteValue(m_section_name.c_str(), key); | ||
QtHost::SaveGameSettings(m_sif, false); | ||
g_emu_thread->reloadGameSettings(false); | ||
} | ||
else | ||
{ | ||
Host::DeleteBaseSettingValue(m_section_name.c_str(), key); | ||
Host::CommitBaseSettingChanges(); | ||
g_emu_thread->applySettings(false); | ||
} | ||
} | ||
|
||
void InputBindingDialog::hookInputManager() | ||
{ | ||
InputManager::SetHook([this](InputBindingKey key, float value) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <[email protected]> | ||
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <[email protected]> | ||
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) | ||
|
||
#pragma once | ||
#include "common/types.h" | ||
#include "util/input_manager.h" | ||
#include "ui_inputbindingdialog.h" | ||
#include "util/input_manager.h" | ||
#include <QtWidgets/QDialog> | ||
#include <optional> | ||
#include <string> | ||
|
@@ -48,6 +48,11 @@ protected Q_SLOTS: | |
void hookInputManager(); | ||
void unhookInputManager(); | ||
|
||
void onSensitivityChanged(int value); | ||
void onResetDeadzoneClicked(); | ||
void onDeadzoneChanged(int value); | ||
void onResetSensitivityClicked(); | ||
|
||
Ui::InputBindingDialog m_ui; | ||
|
||
SettingsInterface* m_sif; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters