mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-28 01:49:33 -06:00
InputCommon / DolphinQt / Core: Add a "RelativeMouse" input which provides the raw delta mouse input
Co-authored-by: Jordan Woyak <jordan.woyak@gmail.com>
This commit is contained in:
@ -32,6 +32,23 @@
|
||||
#endif
|
||||
#define CIFACE_USE_DUALSHOCKUDPCLIENT
|
||||
|
||||
namespace ciface
|
||||
{
|
||||
// A thread local "input channel" is maintained to handle the state of relative inputs.
|
||||
// This allows simultaneous use of relative inputs across different input contexts.
|
||||
// e.g. binding relative mouse movements to both GameCube controllers and FreeLook.
|
||||
// These operate at different rates and processing one would break the other without separate state.
|
||||
enum class InputChannel
|
||||
{
|
||||
Host,
|
||||
SerialInterface,
|
||||
Bluetooth,
|
||||
FreeLook,
|
||||
Count,
|
||||
};
|
||||
|
||||
} // namespace ciface
|
||||
|
||||
//
|
||||
// ControllerInterface
|
||||
//
|
||||
@ -66,6 +83,9 @@ public:
|
||||
void UnregisterDevicesChangedCallback(const HotplugCallbackHandle& handle);
|
||||
void InvokeDevicesChangedCallbacks() const;
|
||||
|
||||
static void SetCurrentInputChannel(ciface::InputChannel);
|
||||
static ciface::InputChannel GetCurrentInputChannel();
|
||||
|
||||
private:
|
||||
std::list<std::function<void()>> m_devices_changed_callbacks;
|
||||
mutable std::mutex m_callbacks_mutex;
|
||||
@ -75,4 +95,37 @@ private:
|
||||
std::atomic<float> m_aspect_ratio_adjustment = 1;
|
||||
};
|
||||
|
||||
namespace ciface
|
||||
{
|
||||
template <typename T>
|
||||
class RelativeInputState
|
||||
{
|
||||
public:
|
||||
void Update()
|
||||
{
|
||||
const auto channel = int(ControllerInterface::GetCurrentInputChannel());
|
||||
|
||||
m_value[channel] = m_delta[channel];
|
||||
m_delta[channel] = {};
|
||||
}
|
||||
|
||||
T GetValue() const
|
||||
{
|
||||
const auto channel = int(ControllerInterface::GetCurrentInputChannel());
|
||||
|
||||
return m_value[channel];
|
||||
}
|
||||
|
||||
void Move(T delta)
|
||||
{
|
||||
for (auto& d : m_delta)
|
||||
d += delta;
|
||||
}
|
||||
|
||||
private:
|
||||
std::array<T, int(InputChannel::Count)> m_value;
|
||||
std::array<T, int(InputChannel::Count)> m_delta;
|
||||
};
|
||||
} // namespace ciface
|
||||
|
||||
extern ControllerInterface g_controller_interface;
|
||||
|
Reference in New Issue
Block a user