Qt: Implement mouse wheel binding

This commit is contained in:
Connor McLaughlin 2022-07-02 21:51:23 +10:00 committed by refractionpcsx2
parent f5e3d79cc7
commit 6e706b3a8c
4 changed files with 61 additions and 5 deletions

View File

@ -330,15 +330,12 @@ bool DisplayWidget::event(QEvent* event)
case QEvent::Wheel: case QEvent::Wheel:
{ {
// wheel delta is 120 as in winapi
const QPoint delta_angle(static_cast<QWheelEvent*>(event)->angleDelta()); const QPoint delta_angle(static_cast<QWheelEvent*>(event)->angleDelta());
constexpr float DELTA = 120.0f; const float dx = std::clamp(static_cast<float>(delta_angle.x()) / QtUtils::MOUSE_WHEEL_DELTA, -1.0f, 1.0f);
const float dx = std::clamp(static_cast<float>(delta_angle.x()) / DELTA, -1.0f, 1.0f);
if (dx != 0.0f) if (dx != 0.0f)
InputManager::UpdatePointerRelativeDelta(0, InputPointerAxis::WheelX, dx); InputManager::UpdatePointerRelativeDelta(0, InputPointerAxis::WheelX, dx);
const float dy = std::clamp(static_cast<float>(delta_angle.y()) / DELTA, -1.0f, 1.0f); const float dy = std::clamp(static_cast<float>(delta_angle.y()) / QtUtils::MOUSE_WHEEL_DELTA, -1.0f, 1.0f);
if (dy != 0.0f) if (dy != 0.0f)
InputManager::UpdatePointerRelativeDelta(0, InputPointerAxis::WheelY, dy); InputManager::UpdatePointerRelativeDelta(0, InputPointerAxis::WheelY, dy);

View File

@ -36,6 +36,9 @@ class QUrl;
namespace QtUtils namespace QtUtils
{ {
/// Wheel delta is 120 as in winapi.
static constexpr float MOUSE_WHEEL_DELTA = 120.0f;
/// Marks an action as the "default" - i.e. makes the text bold. /// Marks an action as the "default" - i.e. makes the text bold.
void MarkActionAsDefault(QAction* action); void MarkActionAsDefault(QAction* action);

View File

@ -23,6 +23,7 @@
#include <QtCore/QTimer> #include <QtCore/QTimer>
#include <QtGui/QKeyEvent> #include <QtGui/QKeyEvent>
#include <QtGui/QMouseEvent> #include <QtGui/QMouseEvent>
#include <QtGui/QWheelEvent>
// _BitScanForward() // _BitScanForward()
#include "pcsx2/GS/GSIntrin.h" #include "pcsx2/GS/GSIntrin.h"
@ -77,6 +78,33 @@ bool InputBindingDialog::eventFilter(QObject* watched, QEvent* event)
m_new_bindings.push_back(InputManager::MakePointerButtonKey(0, button_index)); m_new_bindings.push_back(InputManager::MakePointerButtonKey(0, button_index));
return true; return true;
} }
else if (event_type == QEvent::Wheel)
{
const QPoint delta_angle(static_cast<QWheelEvent*>(event)->angleDelta());
const float dx = std::clamp(static_cast<float>(delta_angle.x()) / QtUtils::MOUSE_WHEEL_DELTA, -1.0f, 1.0f);
if (dx != 0.0f)
{
InputBindingKey key(InputManager::MakePointerAxisKey(0, InputPointerAxis::WheelX));
key.negative = (dx < 0.0f);
m_new_bindings.push_back(key);
}
const float dy = std::clamp(static_cast<float>(delta_angle.y()) / QtUtils::MOUSE_WHEEL_DELTA, -1.0f, 1.0f);
if (dy != 0.0f)
{
InputBindingKey key(InputManager::MakePointerAxisKey(0, InputPointerAxis::WheelY));
key.negative = (dy < 0.0f);
m_new_bindings.push_back(key);
}
if (dx != 0.0f || dy != 0.0f)
{
addNewBinding();
stopListeningForInput();
}
return true;
}
else if (event_type == QEvent::MouseMove && m_mouse_mapping_enabled) else if (event_type == QEvent::MouseMove && m_mouse_mapping_enabled)
{ {
// if we've moved more than a decent distance from the center of the widget, bind it. // if we've moved more than a decent distance from the center of the widget, bind it.

View File

@ -18,6 +18,7 @@
#include <QtCore/QTimer> #include <QtCore/QTimer>
#include <QtGui/QKeyEvent> #include <QtGui/QKeyEvent>
#include <QtGui/QMouseEvent> #include <QtGui/QMouseEvent>
#include <QtGui/QWheelEvent>
#include <QtWidgets/QInputDialog> #include <QtWidgets/QInputDialog>
#include <QtWidgets/QMessageBox> #include <QtWidgets/QMessageBox>
#include <cmath> #include <cmath>
@ -131,6 +132,33 @@ bool InputBindingWidget::eventFilter(QObject* watched, QEvent* event)
m_new_bindings.push_back(InputManager::MakePointerButtonKey(0, button_index)); m_new_bindings.push_back(InputManager::MakePointerButtonKey(0, button_index));
return true; return true;
} }
else if (event_type == QEvent::Wheel)
{
const QPoint delta_angle(static_cast<QWheelEvent*>(event)->angleDelta());
const float dx = std::clamp(static_cast<float>(delta_angle.x()) / QtUtils::MOUSE_WHEEL_DELTA, -1.0f, 1.0f);
if (dx != 0.0f)
{
InputBindingKey key(InputManager::MakePointerAxisKey(0, InputPointerAxis::WheelX));
key.negative = (dx < 0.0f);
m_new_bindings.push_back(key);
}
const float dy = std::clamp(static_cast<float>(delta_angle.y()) / QtUtils::MOUSE_WHEEL_DELTA, -1.0f, 1.0f);
if (dy != 0.0f)
{
InputBindingKey key(InputManager::MakePointerAxisKey(0, InputPointerAxis::WheelY));
key.negative = (dy < 0.0f);
m_new_bindings.push_back(key);
}
if (dx != 0.0f || dy != 0.0f)
{
setNewBinding();
stopListeningForInput();
}
return true;
}
else if (event_type == QEvent::MouseMove && m_mouse_mapping_enabled) else if (event_type == QEvent::MouseMove && m_mouse_mapping_enabled)
{ {
// if we've moved more than a decent distance from the center of the widget, bind it. // if we've moved more than a decent distance from the center of the widget, bind it.