mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-22 10:42:36 +01:00
Add support for mousewheel movement
This commit is contained in:
parent
1b27ccecf8
commit
6cfcb7b4f3
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -8,10 +8,14 @@
|
||||
|
||||
enum mouse
|
||||
{
|
||||
move_left = 0x05555550,
|
||||
move_right = 0x05555551,
|
||||
move_up = 0x05555552,
|
||||
move_down = 0x05555553
|
||||
move_left = 0x05555550,
|
||||
move_right = 0x05555551,
|
||||
move_up = 0x05555552,
|
||||
move_down = 0x05555553,
|
||||
wheel_up = 0x05555554,
|
||||
wheel_down = 0x05555555,
|
||||
wheel_left = 0x05555556,
|
||||
wheel_right = 0x05555557
|
||||
};
|
||||
|
||||
class keyboard_pad_handler final : public QObject, public PadHandlerBase
|
||||
@ -52,6 +56,11 @@ class keyboard_pad_handler final : public QObject, public PadHandlerBase
|
||||
{ mouse::move_right , "Mouse MRight" },
|
||||
{ mouse::move_up , "Mouse MUp" },
|
||||
{ mouse::move_down , "Mouse MDown" },
|
||||
|
||||
{ mouse::wheel_up , "Wheel Up" },
|
||||
{ mouse::wheel_down , "Wheel Down" },
|
||||
{ mouse::wheel_left , "Wheel Left" },
|
||||
{ mouse::wheel_right , "Wheel Right" },
|
||||
};
|
||||
|
||||
public:
|
||||
@ -66,6 +75,7 @@ public:
|
||||
void mousePressEvent(QMouseEvent* event);
|
||||
void mouseReleaseEvent(QMouseEvent* event);
|
||||
void mouseMoveEvent(QMouseEvent* event);
|
||||
void mouseWheelEvent(QWheelEvent* event);
|
||||
|
||||
bool eventFilter(QObject* obj, QEvent* ev) override;
|
||||
|
||||
@ -108,4 +118,10 @@ private:
|
||||
int m_deadzone_y = 60;
|
||||
double m_multi_x = 2;
|
||||
double m_multi_y = 2.5;
|
||||
|
||||
// Mousewheel
|
||||
std::chrono::steady_clock::time_point m_last_wheel_move_up;
|
||||
std::chrono::steady_clock::time_point m_last_wheel_move_down;
|
||||
std::chrono::steady_clock::time_point m_last_wheel_move_left;
|
||||
std::chrono::steady_clock::time_point m_last_wheel_move_right;
|
||||
};
|
||||
|
@ -692,6 +692,61 @@ void pad_settings_dialog::mouseReleaseEvent(QMouseEvent* event)
|
||||
ReactivateButtons();
|
||||
}
|
||||
|
||||
void pad_settings_dialog::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
if (m_handler->m_type != pad_handler::keyboard)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_button_id == button_ids::id_pad_begin)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_button_id <= button_ids::id_pad_begin || m_button_id >= button_ids::id_pad_end)
|
||||
{
|
||||
LOG_NOTICE(HLE, "Pad Settings: Handler Type: %d, Unknown button ID: %d", static_cast<int>(m_handler->m_type), m_button_id);
|
||||
return;
|
||||
}
|
||||
|
||||
QPoint direction = event->angleDelta();
|
||||
if (direction.isNull())
|
||||
{
|
||||
// Scrolling started/ended event, no direction given
|
||||
return;
|
||||
}
|
||||
|
||||
u32 key;
|
||||
if (const int x = direction.x())
|
||||
{
|
||||
bool to_left = event->inverted() ? x < 0 : x > 0;
|
||||
if (to_left)
|
||||
{
|
||||
key = mouse::wheel_left;
|
||||
}
|
||||
else
|
||||
{
|
||||
key = mouse::wheel_right;
|
||||
}
|
||||
}
|
||||
if (const int y = direction.y())
|
||||
{
|
||||
bool to_up = event->inverted() ? y < 0 : y > 0;
|
||||
if (to_up)
|
||||
{
|
||||
key = mouse::wheel_up;
|
||||
}
|
||||
else
|
||||
{
|
||||
key = mouse::wheel_down;
|
||||
}
|
||||
}
|
||||
m_cfg_entries[m_button_id].key = (static_cast<keyboard_pad_handler*>(m_handler.get()))->GetMouseName(key);
|
||||
m_cfg_entries[m_button_id].text = qstr(m_cfg_entries[m_button_id].key);
|
||||
ReactivateButtons();
|
||||
}
|
||||
|
||||
void pad_settings_dialog::mouseMoveEvent(QMouseEvent* /*event*/)
|
||||
{
|
||||
if (m_handler->m_type != pad_handler::keyboard)
|
||||
|
@ -180,5 +180,6 @@ protected:
|
||||
void keyPressEvent(QKeyEvent *keyEvent) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
void wheelEvent(QWheelEvent *event) override;
|
||||
bool eventFilter(QObject* object, QEvent* event) override;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user