mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-04 05:51:27 +12:00
Add support for mousewheel movement
This commit is contained in:
parent
1b27ccecf8
commit
6cfcb7b4f3
4 changed files with 145 additions and 4 deletions
|
@ -156,6 +156,9 @@ bool keyboard_pad_handler::eventFilter(QObject* target, QEvent* ev)
|
|||
case QEvent::MouseMove:
|
||||
mouseMoveEvent(static_cast<QMouseEvent*>(ev));
|
||||
break;
|
||||
case QEvent::Wheel:
|
||||
mouseWheelEvent(static_cast<QWheelEvent*>(ev));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -378,6 +381,46 @@ void keyboard_pad_handler::mouseMoveEvent(QMouseEvent* event)
|
|||
event->ignore();
|
||||
}
|
||||
|
||||
void keyboard_pad_handler::mouseWheelEvent(QWheelEvent* event)
|
||||
{
|
||||
QPoint direction = event->angleDelta();
|
||||
|
||||
if (direction.isNull())
|
||||
{
|
||||
// Scrolling started/ended event, no direction given
|
||||
return;
|
||||
}
|
||||
|
||||
if (const int x = direction.x())
|
||||
{
|
||||
bool to_left = event->inverted() ? x < 0 : x > 0;
|
||||
if (to_left)
|
||||
{
|
||||
Key(mouse::wheel_left, true);
|
||||
m_last_wheel_move_left = std::chrono::steady_clock::now();
|
||||
}
|
||||
else
|
||||
{
|
||||
Key(mouse::wheel_right, true);
|
||||
m_last_wheel_move_right = std::chrono::steady_clock::now();
|
||||
}
|
||||
}
|
||||
if (const int y = direction.y())
|
||||
{
|
||||
bool to_up = event->inverted() ? y < 0 : y > 0;
|
||||
if (to_up)
|
||||
{
|
||||
Key(mouse::wheel_up, true);
|
||||
m_last_wheel_move_up = std::chrono::steady_clock::now();
|
||||
}
|
||||
else
|
||||
{
|
||||
Key(mouse::wheel_down, true);
|
||||
m_last_wheel_move_down = std::chrono::steady_clock::now();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> keyboard_pad_handler::ListDevices()
|
||||
{
|
||||
std::vector<std::string> list_devices;
|
||||
|
@ -659,4 +702,30 @@ void keyboard_pad_handler::ThreadProc()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Releases the wheel buttons 0,1 sec after they've been triggered
|
||||
// Next activation is set to distant future to avoid activating this on every proc
|
||||
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
|
||||
const auto update_treshold = std::chrono::milliseconds(100);
|
||||
const auto delay = std::chrono::hours(24);
|
||||
if (now >= m_last_wheel_move_up + update_treshold)
|
||||
{
|
||||
Key(mouse::wheel_up, false);
|
||||
m_last_wheel_move_up = now + delay;
|
||||
}
|
||||
if (now >= m_last_wheel_move_down + update_treshold)
|
||||
{
|
||||
Key(mouse::wheel_down, false);
|
||||
m_last_wheel_move_down = now + delay;
|
||||
}
|
||||
if (now >= m_last_wheel_move_left + update_treshold)
|
||||
{
|
||||
Key(mouse::wheel_left, false);
|
||||
m_last_wheel_move_left = now + delay;
|
||||
}
|
||||
if (now >= m_last_wheel_move_right + update_treshold)
|
||||
{
|
||||
Key(mouse::wheel_right, false);
|
||||
m_last_wheel_move_right = now + delay;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue