input: Add some logging to mouse_gyro_handler
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
#include "stdafx.h"
|
||||||
#include "mouse_gyro_handler.h"
|
#include "mouse_gyro_handler.h"
|
||||||
|
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
@@ -7,53 +8,57 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
LOG_CHANNEL(gui_log, "GUI");
|
||||||
|
|
||||||
void mouse_gyro_handler::clear()
|
void mouse_gyro_handler::clear()
|
||||||
{
|
{
|
||||||
active = false;
|
m_active = false;
|
||||||
reset = false;
|
m_reset = false;
|
||||||
gyro_x = DEFAULT_MOTION_X;
|
m_gyro_x = DEFAULT_MOTION_X;
|
||||||
gyro_y = DEFAULT_MOTION_Y;
|
m_gyro_y = DEFAULT_MOTION_Y;
|
||||||
gyro_z = DEFAULT_MOTION_Z;
|
m_gyro_z = DEFAULT_MOTION_Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mouse_gyro_handler::toggle_enabled()
|
bool mouse_gyro_handler::toggle_enabled()
|
||||||
{
|
{
|
||||||
enabled = !enabled;
|
m_enabled = !m_enabled;
|
||||||
clear();
|
clear();
|
||||||
return enabled;
|
return m_enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouse_gyro_handler::set_gyro_active()
|
void mouse_gyro_handler::set_gyro_active()
|
||||||
{
|
{
|
||||||
active = true;
|
gui_log.notice("Mouse-based gyro activated");
|
||||||
|
m_active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouse_gyro_handler::set_gyro_reset()
|
void mouse_gyro_handler::set_gyro_reset()
|
||||||
{
|
{
|
||||||
active = false;
|
gui_log.notice("Mouse-based gyro deactivated");
|
||||||
reset = true;
|
m_active = false;
|
||||||
|
m_reset = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouse_gyro_handler::set_gyro_xz(s32 off_x, s32 off_y)
|
void mouse_gyro_handler::set_gyro_xz(s32 off_x, s32 off_y)
|
||||||
{
|
{
|
||||||
if (!active)
|
if (!m_active)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
gyro_x = static_cast<u16>(std::clamp(off_x, 0, DEFAULT_MOTION_X * 2 - 1));
|
m_gyro_x = static_cast<u16>(std::clamp(off_x, 0, DEFAULT_MOTION_X * 2 - 1));
|
||||||
gyro_z = static_cast<u16>(std::clamp(off_y, 0, DEFAULT_MOTION_Z * 2 - 1));
|
m_gyro_z = static_cast<u16>(std::clamp(off_y, 0, DEFAULT_MOTION_Z * 2 - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouse_gyro_handler::set_gyro_y(s32 steps)
|
void mouse_gyro_handler::set_gyro_y(s32 steps)
|
||||||
{
|
{
|
||||||
if (!active)
|
if (!m_active)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
gyro_y = static_cast<u16>(std::clamp(gyro_y + steps, 0, DEFAULT_MOTION_Y * 2 - 1));
|
m_gyro_y = static_cast<u16>(std::clamp(m_gyro_y + steps, 0, DEFAULT_MOTION_Y * 2 - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouse_gyro_handler::handle_event(QEvent* ev, const QWindow& win)
|
void mouse_gyro_handler::handle_event(QEvent* ev, const QWindow& win)
|
||||||
{
|
{
|
||||||
if (!enabled)
|
if (!m_enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Mouse-based motion input.
|
// Mouse-based motion input.
|
||||||
@@ -119,15 +124,12 @@ void mouse_gyro_handler::handle_event(QEvent* ev, const QWindow& win)
|
|||||||
|
|
||||||
void mouse_gyro_handler::apply_gyro(const std::shared_ptr<Pad>& pad)
|
void mouse_gyro_handler::apply_gyro(const std::shared_ptr<Pad>& pad)
|
||||||
{
|
{
|
||||||
if (!enabled)
|
if (!m_enabled || !pad || !pad->is_connected())
|
||||||
return;
|
|
||||||
|
|
||||||
if (!pad || !pad->is_connected())
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Inject mouse-based motion sensor values into pad sensors for gyro emulation.
|
// Inject mouse-based motion sensor values into pad sensors for gyro emulation.
|
||||||
// The Qt frontend maps cursor offset and wheel input to absolute motion values while RMB is held.
|
// The Qt frontend maps cursor offset and wheel input to absolute motion values while RMB is held.
|
||||||
if (reset)
|
if (m_reset)
|
||||||
{
|
{
|
||||||
// RMB released → reset motion
|
// RMB released → reset motion
|
||||||
pad->m_sensors[0].m_value = DEFAULT_MOTION_X;
|
pad->m_sensors[0].m_value = DEFAULT_MOTION_X;
|
||||||
@@ -139,8 +141,8 @@ void mouse_gyro_handler::apply_gyro(const std::shared_ptr<Pad>& pad)
|
|||||||
{
|
{
|
||||||
// RMB held → accumulate motion
|
// RMB held → accumulate motion
|
||||||
// Axes have been chosen as tested in Sly 4 minigames. Top-down view motion uses X/Z axes.
|
// Axes have been chosen as tested in Sly 4 minigames. Top-down view motion uses X/Z axes.
|
||||||
pad->m_sensors[0].m_value = gyro_x; // Mouse X → Motion X
|
pad->m_sensors[0].m_value = m_gyro_x; // Mouse X → Motion X
|
||||||
pad->m_sensors[1].m_value = gyro_y; // Mouse Wheel → Motion Y
|
pad->m_sensors[1].m_value = m_gyro_y; // Mouse Wheel → Motion Y
|
||||||
pad->m_sensors[2].m_value = gyro_z; // Mouse Y → Motion Z
|
pad->m_sensors[2].m_value = m_gyro_z; // Mouse Y → Motion Z
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,24 +10,23 @@ class QWindow;
|
|||||||
// Mouse-based motion sensor emulation state.
|
// Mouse-based motion sensor emulation state.
|
||||||
class mouse_gyro_handler
|
class mouse_gyro_handler
|
||||||
{
|
{
|
||||||
private:
|
|
||||||
atomic_t<bool> enabled = false; // Whether mouse-based gyro emulation mode has been enabled by using the associated hotkey
|
|
||||||
|
|
||||||
atomic_t<bool> active = false; // Whether right mouse button is currently held (gyro active)
|
|
||||||
atomic_t<bool> reset = false; // One-shot reset request on right mouse button release
|
|
||||||
atomic_t<s32> gyro_x = DEFAULT_MOTION_X; // Accumulated from mouse X position relative to center
|
|
||||||
atomic_t<s32> gyro_y = DEFAULT_MOTION_Y; // Accumulated from mouse wheel delta
|
|
||||||
atomic_t<s32> gyro_z = DEFAULT_MOTION_Z; // Accumulated from mouse Y position relative to center
|
|
||||||
|
|
||||||
void set_gyro_active();
|
|
||||||
void set_gyro_reset();
|
|
||||||
void set_gyro_xz(s32 off_x, s32 off_y);
|
|
||||||
void set_gyro_y(s32 steps);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void clear();
|
void clear();
|
||||||
bool toggle_enabled();
|
bool toggle_enabled();
|
||||||
|
|
||||||
void handle_event(QEvent* ev, const QWindow& win);
|
void handle_event(QEvent* ev, const QWindow& win);
|
||||||
void apply_gyro(const std::shared_ptr<Pad>& pad);
|
void apply_gyro(const std::shared_ptr<Pad>& pad);
|
||||||
|
|
||||||
|
private:
|
||||||
|
atomic_t<bool> m_enabled = false; // Whether mouse-based gyro emulation mode has been enabled by using the associated hotkey
|
||||||
|
atomic_t<bool> m_active = false; // Whether right mouse button is currently held (gyro active)
|
||||||
|
atomic_t<bool> m_reset = false; // One-shot reset request on right mouse button release
|
||||||
|
atomic_t<s32> m_gyro_x = DEFAULT_MOTION_X; // Accumulated from mouse X position relative to center
|
||||||
|
atomic_t<s32> m_gyro_y = DEFAULT_MOTION_Y; // Accumulated from mouse wheel delta
|
||||||
|
atomic_t<s32> m_gyro_z = DEFAULT_MOTION_Z; // Accumulated from mouse Y position relative to center
|
||||||
|
|
||||||
|
void set_gyro_active();
|
||||||
|
void set_gyro_reset();
|
||||||
|
void set_gyro_xz(s32 off_x, s32 off_y);
|
||||||
|
void set_gyro_y(s32 steps);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user