mirror of https://github.com/PCSX2/pcsx2.git
Qt: Implement mouse wheel binding
This commit is contained in:
parent
f5e3d79cc7
commit
6e706b3a8c
|
@ -330,15 +330,12 @@ bool DisplayWidget::event(QEvent* event)
|
|||
|
||||
case QEvent::Wheel:
|
||||
{
|
||||
// wheel delta is 120 as in winapi
|
||||
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()) / DELTA, -1.0f, 1.0f);
|
||||
const float dx = std::clamp(static_cast<float>(delta_angle.x()) / QtUtils::MOUSE_WHEEL_DELTA, -1.0f, 1.0f);
|
||||
if (dx != 0.0f)
|
||||
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)
|
||||
InputManager::UpdatePointerRelativeDelta(0, InputPointerAxis::WheelY, dy);
|
||||
|
||||
|
|
|
@ -36,6 +36,9 @@ class QUrl;
|
|||
|
||||
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.
|
||||
void MarkActionAsDefault(QAction* action);
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <QtCore/QTimer>
|
||||
#include <QtGui/QKeyEvent>
|
||||
#include <QtGui/QMouseEvent>
|
||||
#include <QtGui/QWheelEvent>
|
||||
|
||||
// _BitScanForward()
|
||||
#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));
|
||||
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)
|
||||
{
|
||||
// if we've moved more than a decent distance from the center of the widget, bind it.
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <QtCore/QTimer>
|
||||
#include <QtGui/QKeyEvent>
|
||||
#include <QtGui/QMouseEvent>
|
||||
#include <QtGui/QWheelEvent>
|
||||
#include <QtWidgets/QInputDialog>
|
||||
#include <QtWidgets/QMessageBox>
|
||||
#include <cmath>
|
||||
|
@ -131,6 +132,33 @@ bool InputBindingWidget::eventFilter(QObject* watched, QEvent* event)
|
|||
m_new_bindings.push_back(InputManager::MakePointerButtonKey(0, button_index));
|
||||
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)
|
||||
{
|
||||
// if we've moved more than a decent distance from the center of the widget, bind it.
|
||||
|
|
Loading…
Reference in New Issue