project64/Source/Project64-input/DirectInput.h

101 lines
2.8 KiB
C
Raw Normal View History

2020-06-23 07:47:46 +00:00
#pragma once
#include "ControllerSpec1.1.h"
#include "Button.h"
#include "DeviceNotification.h"
#include "N64Controller.h"
2021-02-28 21:32:50 +00:00
#include <Common/CriticalSection.h>
2020-06-23 07:47:46 +00:00
#define DIRECTINPUT_VERSION 0x0800
#include <Windows.h>
#include <dinput.h>
#include <string>
#include <map>
class CDirectInput
{
2020-07-15 11:32:48 +00:00
enum
{
CONFIG_THRESHOLD = 50,
2020-07-27 11:51:30 +00:00
MIN_AXIS_VALUE = -32767,
MAX_AXIS_VALUE = 32767,
2020-08-03 11:12:00 +00:00
AXIS_TOP_VALUE = MAX_AXIS_VALUE / 2,
AXIS_BOTTOM_VALUE = MAX_AXIS_VALUE + AXIS_TOP_VALUE,
2020-07-15 11:32:48 +00:00
RANGE_RELATIVE = 0x8000,
AI_AXE_POSITIVE = 0,
AI_AXE_NEGATIVE = 1,
THRESHOLD = 50,
};
enum AI_POV
{
AI_POV_UP = 0,
AI_POV_RIGHT = 1,
AI_POV_DOWN = 2,
AI_POV_LEFT = 3,
};
2020-06-23 07:47:46 +00:00
public:
enum ScanResult
{
SCAN_FAILED = 0x00,
SCAN_SUCCEED = 0x01,
SCAN_ESCAPE = 0x10,
};
CDirectInput(HINSTANCE hinst);
~CDirectInput();
void Initiate(CONTROL_INFO * ControlInfo);
void MapControllerDevice(N64CONTROLLER & Controller);
2020-06-23 07:47:46 +00:00
ScanResult ScanDevices(BUTTON & Button);
std::wstring ButtonAssignment(BUTTON & Button);
std::wstring ControllerDevices(const N64CONTROLLER & Controller);
bool IsButtonPressed(BUTTON & Button);
2020-07-15 11:32:48 +00:00
void GetAxis(N64CONTROLLER & Controller, BUTTONS * Keys);
void UpdateDeviceData(void);
void DevicesChanged(void);
2020-06-23 07:47:46 +00:00
private:
CDirectInput();
CDirectInput(const CDirectInput&);
CDirectInput& operator=(const CDirectInput&);
static BOOL CALLBACK stEnumMakeDeviceList(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef);
BOOL EnumMakeDeviceList(LPCDIDEVICEINSTANCE lpddi);
2020-07-15 11:04:23 +00:00
ScanResult ScanKeyboard(const GUID & DeviceGuid, LPDIRECTINPUTDEVICE8 didHandle, uint8_t * KeyboardState, BUTTON & pButton);
2020-07-15 11:32:48 +00:00
ScanResult ScanGamePad(const GUID & DeviceGuid, LPDIRECTINPUTDEVICE8 didHandle, DIJOYSTATE & BaseState, BUTTON & pButton);
bool AcquireDevice(LPDIRECTINPUTDEVICE8 lpDirectInputDevice);
void RefreshDeviceList(void);
2020-07-15 11:32:48 +00:00
bool JoyPadPovPressed(AI_POV Pov, int32_t Angle);
2020-06-23 07:47:46 +00:00
typedef struct
{
LPDIRECTINPUTDEVICE8 didHandle;
uint32_t dwDevType;
std::string InstanceName;
std::string ProductName;
union INPUTSTATE
{
DIJOYSTATE Joy;
DIMOUSESTATE2 Mouse;
uint8_t Keyboard[256];
} State;
2020-06-23 07:47:46 +00:00
} DEVICE;
struct GUIDComparer
{
bool operator()(const GUID & Left, const GUID & Right) const
{
return memcmp(&Left, &Right, sizeof(Right)) < 0;
}
};
typedef std::map<GUID, DEVICE, GUIDComparer> DEVICE_MAP;
DeviceNotification m_DeviceNotification;
2020-06-23 07:47:46 +00:00
DEVICE_MAP m_Devices;
CriticalSection m_DeviceCS;
2020-06-23 07:47:46 +00:00
HMODULE m_hDirectInputDLL;
LPDIRECTINPUT8 m_pDIHandle;
HINSTANCE m_hinst;
HWND m_hWnd;
2021-03-27 05:36:16 +00:00
};