2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2010 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2014-02-10 18:54:46 +00:00
|
|
|
|
|
|
|
#pragma once
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2014-02-19 01:17:31 +00:00
|
|
|
#include <windows.h>
|
|
|
|
|
2020-01-24 06:06:39 +00:00
|
|
|
#include "Common/Matrix.h"
|
2020-04-21 04:16:07 +00:00
|
|
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
2020-09-15 11:34:41 +00:00
|
|
|
#include "InputCommon/ControllerInterface/CoreDevice.h"
|
2014-08-23 00:17:49 +00:00
|
|
|
#include "InputCommon/ControllerInterface/DInput/DInput8.h"
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2019-06-17 20:39:24 +00:00
|
|
|
namespace ciface::DInput
|
2010-07-03 08:04:10 +00:00
|
|
|
{
|
2019-04-20 14:25:11 +00:00
|
|
|
void InitKeyboardMouse(IDirectInput8* const idi8, HWND hwnd);
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2020-04-21 04:16:07 +00:00
|
|
|
using RelativeMouseState = RelativeInputState<Common::TVec3<LONG>>;
|
2021-05-15 09:20:20 +00:00
|
|
|
void SetKeyboardMouseWindow(HWND hwnd);
|
2020-04-21 04:16:07 +00:00
|
|
|
|
2013-06-17 00:07:10 +00:00
|
|
|
class KeyboardMouse : public Core::Device
|
2010-07-03 08:04:10 +00:00
|
|
|
{
|
2011-03-14 01:20:11 +00:00
|
|
|
private:
|
2010-07-03 08:04:10 +00:00
|
|
|
struct State
|
|
|
|
{
|
2021-09-04 04:43:19 +00:00
|
|
|
BYTE keyboard[256]{};
|
2020-04-21 04:16:07 +00:00
|
|
|
|
|
|
|
// Old smoothed relative mouse movement.
|
2021-09-04 04:43:19 +00:00
|
|
|
DIMOUSESTATE2 mouse{};
|
2020-04-21 04:16:07 +00:00
|
|
|
|
|
|
|
// Normalized mouse cursor position.
|
2020-01-24 06:06:39 +00:00
|
|
|
Common::TVec2<ControlState> cursor;
|
2020-04-21 04:16:07 +00:00
|
|
|
|
|
|
|
// Raw relative mouse movement.
|
|
|
|
RelativeMouseState relative_mouse;
|
2010-07-03 08:04:10 +00:00
|
|
|
};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-05-15 08:32:00 +00:00
|
|
|
// Keyboard key
|
2010-07-03 08:04:10 +00:00
|
|
|
class Key : public Input
|
|
|
|
{
|
|
|
|
public:
|
2015-09-06 02:32:05 +00:00
|
|
|
Key(u8 index, const BYTE& key) : m_key(key), m_index(index) {}
|
|
|
|
std::string GetName() const override;
|
|
|
|
ControlState GetState() const override;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2010-07-03 08:04:10 +00:00
|
|
|
private:
|
2011-03-14 01:20:11 +00:00
|
|
|
const BYTE& m_key;
|
|
|
|
const u8 m_index;
|
2010-07-03 08:04:10 +00:00
|
|
|
};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-05-15 08:32:00 +00:00
|
|
|
// Mouse button
|
2010-07-03 08:04:10 +00:00
|
|
|
class Button : public Input
|
|
|
|
{
|
|
|
|
public:
|
2015-09-06 02:32:05 +00:00
|
|
|
Button(u8 index, const BYTE& button) : m_button(button), m_index(index) {}
|
|
|
|
std::string GetName() const override;
|
|
|
|
ControlState GetState() const override;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2010-07-03 08:04:10 +00:00
|
|
|
private:
|
2011-03-14 01:20:11 +00:00
|
|
|
const BYTE& m_button;
|
|
|
|
const u8 m_index;
|
2010-07-03 08:04:10 +00:00
|
|
|
};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-05-15 08:32:00 +00:00
|
|
|
// Mouse movement offset axis. Includes mouse wheel
|
2010-07-03 08:04:10 +00:00
|
|
|
class Axis : public Input
|
|
|
|
{
|
|
|
|
public:
|
2015-09-06 02:32:05 +00:00
|
|
|
Axis(u8 index, const LONG& axis, LONG range) : m_axis(axis), m_range(range), m_index(index) {}
|
|
|
|
std::string GetName() const override;
|
2020-04-21 04:16:07 +00:00
|
|
|
bool IsDetectable() const override { return false; }
|
2015-09-06 02:32:05 +00:00
|
|
|
ControlState GetState() const override;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2010-07-03 08:04:10 +00:00
|
|
|
private:
|
2011-03-14 01:20:11 +00:00
|
|
|
const LONG& m_axis;
|
|
|
|
const LONG m_range;
|
|
|
|
const u8 m_index;
|
2010-07-03 08:04:10 +00:00
|
|
|
};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2021-05-15 08:32:00 +00:00
|
|
|
// Mouse from window center
|
2010-07-10 06:48:24 +00:00
|
|
|
class Cursor : public Input
|
|
|
|
{
|
|
|
|
public:
|
2015-09-06 02:32:05 +00:00
|
|
|
Cursor(u8 index, const ControlState& axis, const bool positive)
|
|
|
|
: m_axis(axis), m_index(index), m_positive(positive)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
std::string GetName() const override;
|
2020-02-22 16:27:43 +00:00
|
|
|
bool IsDetectable() const override { return false; }
|
2015-09-06 02:32:05 +00:00
|
|
|
ControlState GetState() const override;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2010-07-10 06:48:24 +00:00
|
|
|
private:
|
2014-11-09 20:02:18 +00:00
|
|
|
const ControlState& m_axis;
|
2011-03-14 01:20:11 +00:00
|
|
|
const u8 m_index;
|
|
|
|
const bool m_positive;
|
2010-07-10 06:48:24 +00:00
|
|
|
};
|
|
|
|
|
2011-03-14 01:20:11 +00:00
|
|
|
public:
|
2014-11-13 08:55:14 +00:00
|
|
|
void UpdateInput() override;
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2021-05-15 09:20:20 +00:00
|
|
|
KeyboardMouse(const LPDIRECTINPUTDEVICE8 kb_device, const LPDIRECTINPUTDEVICE8 mo_device);
|
2010-07-03 08:04:10 +00:00
|
|
|
~KeyboardMouse();
|
|
|
|
|
2015-09-06 02:32:05 +00:00
|
|
|
std::string GetName() const override;
|
|
|
|
std::string GetSource() const override;
|
2021-05-15 09:14:11 +00:00
|
|
|
int GetSortPriority() const override;
|
2021-05-15 09:20:20 +00:00
|
|
|
bool IsVirtualDevice() const override;
|
2010-07-03 08:04:10 +00:00
|
|
|
|
|
|
|
private:
|
2019-04-20 14:25:11 +00:00
|
|
|
void UpdateCursorInput();
|
|
|
|
|
2014-01-31 00:51:21 +00:00
|
|
|
const LPDIRECTINPUTDEVICE8 m_kb_device;
|
|
|
|
const LPDIRECTINPUTDEVICE8 m_mo_device;
|
2010-07-03 08:04:10 +00:00
|
|
|
|
2014-01-31 00:51:21 +00:00
|
|
|
DWORD m_last_update;
|
|
|
|
State m_state_in;
|
2010-07-03 08:04:10 +00:00
|
|
|
};
|
2019-06-17 20:39:24 +00:00
|
|
|
} // namespace ciface::DInput
|