Project64-input: Display device bound to
This commit is contained in:
parent
fc51e39738
commit
878725490b
|
@ -1,5 +1,6 @@
|
||||||
#include "CProject64Input.h"
|
#include "CProject64Input.h"
|
||||||
#include "InputSettings.h"
|
#include "InputSettings.h"
|
||||||
|
#include "InputConfigUI.h"
|
||||||
|
|
||||||
CProject64Input * g_InputPlugin = nullptr;
|
CProject64Input * g_InputPlugin = nullptr;
|
||||||
|
|
||||||
|
@ -25,6 +26,11 @@ void CProject64Input::DevicesChanged(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CProject64Input::DeviceAdded(void)
|
||||||
|
{
|
||||||
|
ConfigUIDeviceAdded();
|
||||||
|
}
|
||||||
|
|
||||||
void CProject64Input::InitiateControllers(CONTROL_INFO * ControlInfo)
|
void CProject64Input::InitiateControllers(CONTROL_INFO * ControlInfo)
|
||||||
{
|
{
|
||||||
CGuard guard(m_CS);
|
CGuard guard(m_CS);
|
||||||
|
@ -107,6 +113,20 @@ std::wstring CProject64Input::ButtonAssignment(BUTTON & Button)
|
||||||
return L"Unknown";
|
return L"Unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::wstring CProject64Input::ControllerDevices(uint32_t ControlIndex)
|
||||||
|
{
|
||||||
|
if (ControlIndex >= sizeof(m_Controllers) / sizeof(m_Controllers[0]))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_DirectInput.get() != NULL)
|
||||||
|
{
|
||||||
|
return m_DirectInput->ControllerDevices(m_Controllers[ControlIndex]);
|
||||||
|
}
|
||||||
|
return L"";
|
||||||
|
}
|
||||||
|
|
||||||
bool CProject64Input::SaveController(uint32_t ControlIndex)
|
bool CProject64Input::SaveController(uint32_t ControlIndex)
|
||||||
{
|
{
|
||||||
CGuard guard(m_CS);
|
CGuard guard(m_CS);
|
||||||
|
|
|
@ -12,12 +12,14 @@ public:
|
||||||
~CProject64Input();
|
~CProject64Input();
|
||||||
|
|
||||||
void DevicesChanged(void);
|
void DevicesChanged(void);
|
||||||
|
void DeviceAdded(void);
|
||||||
void InitiateControllers(CONTROL_INFO * ControlInfo);
|
void InitiateControllers(CONTROL_INFO * ControlInfo);
|
||||||
void GetKeys(int32_t Control, BUTTONS * Keys);
|
void GetKeys(int32_t Control, BUTTONS * Keys);
|
||||||
void StartScanDevices(int32_t DisplayCtrlId);
|
void StartScanDevices(int32_t DisplayCtrlId);
|
||||||
void EndScanDevices(void);
|
void EndScanDevices(void);
|
||||||
CDirectInput::ScanResult ScanDevices(BUTTON & Button);
|
CDirectInput::ScanResult ScanDevices(BUTTON & Button);
|
||||||
std::wstring ButtonAssignment(BUTTON & Button);
|
std::wstring ButtonAssignment(BUTTON & Button);
|
||||||
|
std::wstring ControllerDevices(uint32_t ControlIndex);
|
||||||
bool SaveController(uint32_t ControlIndex);
|
bool SaveController(uint32_t ControlIndex);
|
||||||
bool ResetController(uint32_t ControlIndex);
|
bool ResetController(uint32_t ControlIndex);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include "DirectInput.h"
|
#include "DirectInput.h"
|
||||||
#include <Common\StdString.h>
|
#include <Common\StdString.h>
|
||||||
#include <Common\SyncEvent.h>
|
#include <Common\SyncEvent.h>
|
||||||
|
#include <set>
|
||||||
|
#include "CProject64Input.h"
|
||||||
|
|
||||||
CDirectInput::CDirectInput(HINSTANCE hinst) :
|
CDirectInput::CDirectInput(HINSTANCE hinst) :
|
||||||
m_hDirectInputDLL(nullptr),
|
m_hDirectInputDLL(nullptr),
|
||||||
|
@ -32,6 +34,8 @@ CDirectInput::CDirectInput(HINSTANCE hinst) :
|
||||||
|
|
||||||
CDirectInput::~CDirectInput()
|
CDirectInput::~CDirectInput()
|
||||||
{
|
{
|
||||||
|
CGuard Guard(m_DeviceCS);
|
||||||
|
|
||||||
for (DEVICE_MAP::iterator itr = m_Devices.begin(); itr != m_Devices.end(); itr++)
|
for (DEVICE_MAP::iterator itr = m_Devices.begin(); itr != m_Devices.end(); itr++)
|
||||||
{
|
{
|
||||||
if (itr->second.didHandle != nullptr)
|
if (itr->second.didHandle != nullptr)
|
||||||
|
@ -71,6 +75,7 @@ void CDirectInput::MapControllerDevice(N64CONTROLLER & Controller)
|
||||||
&Controller.R_ANALOG,
|
&Controller.R_ANALOG,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CGuard Guard(m_DeviceCS);
|
||||||
for (size_t i = 0, n = sizeof(Buttons) / sizeof(Buttons[0]); i < n; i++)
|
for (size_t i = 0, n = sizeof(Buttons) / sizeof(Buttons[0]); i < n; i++)
|
||||||
{
|
{
|
||||||
DEVICE_MAP::iterator itr = m_Devices.find(Buttons[i]->DeviceGuid);
|
DEVICE_MAP::iterator itr = m_Devices.find(Buttons[i]->DeviceGuid);
|
||||||
|
@ -99,11 +104,14 @@ BOOL CDirectInput::EnumMakeDeviceList(LPCDIDEVICEINSTANCE lpddi)
|
||||||
return DIENUM_CONTINUE;
|
return DIENUM_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
CGuard Guard(m_DeviceCS);
|
||||||
DEVICE_MAP::iterator itr = m_Devices.find(lpddi->guidInstance);
|
DEVICE_MAP::iterator itr = m_Devices.find(lpddi->guidInstance);
|
||||||
if (itr != m_Devices.end())
|
if (itr != m_Devices.end())
|
||||||
{
|
{
|
||||||
return DIENUM_CONTINUE;
|
return DIENUM_CONTINUE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
DEVICE Device = { 0 };
|
DEVICE Device = { 0 };
|
||||||
Device.didHandle = nullptr;
|
Device.didHandle = nullptr;
|
||||||
|
@ -142,11 +150,15 @@ BOOL CDirectInput::EnumMakeDeviceList(LPCDIDEVICEINSTANCE lpddi)
|
||||||
return DIENUM_CONTINUE;
|
return DIENUM_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
CGuard Guard(m_DeviceCS);
|
||||||
std::pair<DEVICE_MAP::iterator, bool> res = m_Devices.insert(DEVICE_MAP::value_type(lpddi->guidInstance, Device));
|
std::pair<DEVICE_MAP::iterator, bool> res = m_Devices.insert(DEVICE_MAP::value_type(lpddi->guidInstance, Device));
|
||||||
if (!res.second)
|
if (!res.second)
|
||||||
{
|
{
|
||||||
Device.didHandle->Release();
|
Device.didHandle->Release();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
g_InputPlugin->DeviceAdded();
|
||||||
return DIENUM_CONTINUE;
|
return DIENUM_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,6 +166,7 @@ CDirectInput::ScanResult CDirectInput::ScanDevices(BUTTON & Button)
|
||||||
{
|
{
|
||||||
ScanResult Result = SCAN_FAILED;
|
ScanResult Result = SCAN_FAILED;
|
||||||
|
|
||||||
|
CGuard Guard(m_DeviceCS);
|
||||||
for (DEVICE_MAP::iterator itr = m_Devices.begin(); itr != m_Devices.end(); itr++)
|
for (DEVICE_MAP::iterator itr = m_Devices.begin(); itr != m_Devices.end(); itr++)
|
||||||
{
|
{
|
||||||
DEVICE &device = itr->second;
|
DEVICE &device = itr->second;
|
||||||
|
@ -272,6 +285,64 @@ std::wstring CDirectInput::ButtonAssignment(BUTTON & Button)
|
||||||
return L"Unknown";
|
return L"Unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::wstring CDirectInput::ControllerDevices(N64CONTROLLER & Controller)
|
||||||
|
{
|
||||||
|
BUTTON * Buttons[] =
|
||||||
|
{
|
||||||
|
&Controller.U_DPAD,
|
||||||
|
&Controller.D_DPAD,
|
||||||
|
&Controller.L_DPAD,
|
||||||
|
&Controller.R_DPAD,
|
||||||
|
&Controller.A_BUTTON,
|
||||||
|
&Controller.B_BUTTON,
|
||||||
|
&Controller.U_CBUTTON,
|
||||||
|
&Controller.D_CBUTTON,
|
||||||
|
&Controller.L_CBUTTON,
|
||||||
|
&Controller.R_CBUTTON,
|
||||||
|
&Controller.START_BUTTON,
|
||||||
|
&Controller.Z_TRIG,
|
||||||
|
&Controller.R_TRIG,
|
||||||
|
&Controller.L_TRIG,
|
||||||
|
&Controller.U_ANALOG,
|
||||||
|
&Controller.D_ANALOG,
|
||||||
|
&Controller.L_ANALOG,
|
||||||
|
&Controller.R_ANALOG,
|
||||||
|
};
|
||||||
|
typedef std::set<GUID, GUIDComparer> GUID_LIST;
|
||||||
|
GUID_LIST DeviceGuids;
|
||||||
|
|
||||||
|
for (size_t i = 0, n = sizeof(Buttons) / sizeof(Buttons[0]); i < n; i++)
|
||||||
|
{
|
||||||
|
GUID_LIST::iterator itr = DeviceGuids.find(Buttons[i]->DeviceGuid);
|
||||||
|
if (itr != DeviceGuids.end())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
DeviceGuids.insert(Buttons[i]->DeviceGuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring DeviceList;
|
||||||
|
CGuard Guard(m_DeviceCS);
|
||||||
|
bool UnknownDevice = false;
|
||||||
|
for (GUID_LIST::iterator itr = DeviceGuids.begin(); itr != DeviceGuids.end(); itr++)
|
||||||
|
{
|
||||||
|
DEVICE_MAP::iterator DeviceItr = m_Devices.find(*itr);
|
||||||
|
if (DeviceItr == m_Devices.end())
|
||||||
|
{
|
||||||
|
UnknownDevice = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!DeviceList.empty()) { DeviceList += L", "; }
|
||||||
|
DeviceList += stdstr(DeviceItr->second.ProductName).ToUTF16();
|
||||||
|
}
|
||||||
|
if (UnknownDevice)
|
||||||
|
{
|
||||||
|
if (!DeviceList.empty()) { DeviceList += L", "; }
|
||||||
|
DeviceList += L"Unknown Device";
|
||||||
|
}
|
||||||
|
return DeviceList;
|
||||||
|
}
|
||||||
|
|
||||||
bool CDirectInput::IsButtonPressed(BUTTON & Button)
|
bool CDirectInput::IsButtonPressed(BUTTON & Button)
|
||||||
{
|
{
|
||||||
if (Button.Device == nullptr)
|
if (Button.Device == nullptr)
|
||||||
|
@ -390,6 +461,7 @@ void CDirectInput::GetAxis(N64CONTROLLER & Controller, BUTTONS * Keys)
|
||||||
|
|
||||||
void CDirectInput::UpdateDeviceData(void)
|
void CDirectInput::UpdateDeviceData(void)
|
||||||
{
|
{
|
||||||
|
CGuard Guard(m_DeviceCS);
|
||||||
for (DEVICE_MAP::iterator itr = m_Devices.begin(); itr != m_Devices.end(); itr++)
|
for (DEVICE_MAP::iterator itr = m_Devices.begin(); itr != m_Devices.end(); itr++)
|
||||||
{
|
{
|
||||||
DEVICE & device = itr->second;
|
DEVICE & device = itr->second;
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "Button.h"
|
#include "Button.h"
|
||||||
#include "DeviceNotification.h"
|
#include "DeviceNotification.h"
|
||||||
#include "N64Controller.h"
|
#include "N64Controller.h"
|
||||||
|
#include <Common\CriticalSection.h>
|
||||||
#define DIRECTINPUT_VERSION 0x0800
|
#define DIRECTINPUT_VERSION 0x0800
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <dinput.h>
|
#include <dinput.h>
|
||||||
|
@ -45,10 +46,12 @@ public:
|
||||||
void MapControllerDevice(N64CONTROLLER & Controller);
|
void MapControllerDevice(N64CONTROLLER & Controller);
|
||||||
ScanResult ScanDevices(BUTTON & Button);
|
ScanResult ScanDevices(BUTTON & Button);
|
||||||
std::wstring ButtonAssignment(BUTTON & Button);
|
std::wstring ButtonAssignment(BUTTON & Button);
|
||||||
|
std::wstring ControllerDevices(N64CONTROLLER & Controller);
|
||||||
bool IsButtonPressed(BUTTON & Button);
|
bool IsButtonPressed(BUTTON & Button);
|
||||||
void GetAxis(N64CONTROLLER & Controller, BUTTONS * Keys);
|
void GetAxis(N64CONTROLLER & Controller, BUTTONS * Keys);
|
||||||
void UpdateDeviceData(void);
|
void UpdateDeviceData(void);
|
||||||
void DevicesChanged(void);
|
void DevicesChanged(void);
|
||||||
|
void DeviceAdded(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CDirectInput();
|
CDirectInput();
|
||||||
|
@ -88,6 +91,7 @@ private:
|
||||||
|
|
||||||
DeviceNotification m_DeviceNotification;
|
DeviceNotification m_DeviceNotification;
|
||||||
DEVICE_MAP m_Devices;
|
DEVICE_MAP m_Devices;
|
||||||
|
CriticalSection m_DeviceCS;
|
||||||
HMODULE m_hDirectInputDLL;
|
HMODULE m_hDirectInputDLL;
|
||||||
LPDIRECTINPUT8 m_pDIHandle;
|
LPDIRECTINPUT8 m_pDIHandle;
|
||||||
HINSTANCE m_hinst;
|
HINSTANCE m_hinst;
|
||||||
|
|
|
@ -188,7 +188,7 @@ LRESULT CControllerSettings::OnScanCanceled(UINT /*uMsg*/, WPARAM /*wParam*/, LP
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CControllerSettings::DefaultBtnClicked(UINT Code, int id, HWND ctl)
|
void CControllerSettings::DefaultBtnClicked(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
|
||||||
{
|
{
|
||||||
g_InputPlugin->ResetController(m_ControllerNumber);
|
g_InputPlugin->ResetController(m_ControllerNumber);
|
||||||
DisplayController();
|
DisplayController();
|
||||||
|
@ -232,10 +232,12 @@ void CControllerSettings::DisplayController(void)
|
||||||
{
|
{
|
||||||
Buttons[i]->DisplayButton();
|
Buttons[i]->DisplayButton();
|
||||||
}
|
}
|
||||||
|
GetDlgItem(IDC_BOUND_DEVICE).SetWindowText(g_InputPlugin->ControllerDevices(m_ControllerNumber).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CControllerSettings::ButtonChannged(void)
|
void CControllerSettings::ButtonChannged(void)
|
||||||
{
|
{
|
||||||
|
GetDlgItem(IDC_BOUND_DEVICE).SetWindowText(g_InputPlugin->ControllerDevices(m_ControllerNumber).c_str());
|
||||||
CPropertySheetWindow(GetParent()).SetModified(m_hWnd);
|
CPropertySheetWindow(GetParent()).SetModified(m_hWnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,15 +248,21 @@ public:
|
||||||
CInputConfigUI();
|
CInputConfigUI();
|
||||||
~CInputConfigUI();
|
~CInputConfigUI();
|
||||||
|
|
||||||
|
void UpdateDeviceMapping(void);
|
||||||
void OnSheetInitialized();
|
void OnSheetInitialized();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CControllerSettings m_pgController0, m_pgController1, m_pgController2, m_pgController3;
|
CControllerSettings m_pgController0, m_pgController1, m_pgController2, m_pgController3;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CInputConfigUI * g_ConfigUI = nullptr;
|
||||||
|
|
||||||
void ConfigInput(void * hParent)
|
void ConfigInput(void * hParent)
|
||||||
{
|
{
|
||||||
CInputConfigUI().DoModal((HWND)hParent);
|
CInputConfigUI ConfigUI;
|
||||||
|
g_ConfigUI = &ConfigUI;
|
||||||
|
ConfigUI.DoModal((HWND)hParent);
|
||||||
|
g_ConfigUI = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
CInputConfigUI::CInputConfigUI() :
|
CInputConfigUI::CInputConfigUI() :
|
||||||
|
@ -278,3 +286,23 @@ void CInputConfigUI::OnSheetInitialized()
|
||||||
{
|
{
|
||||||
ModifyStyleEx(WS_EX_CONTEXTHELP,0);
|
ModifyStyleEx(WS_EX_CONTEXTHELP,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CInputConfigUI::UpdateDeviceMapping(void)
|
||||||
|
{
|
||||||
|
for (size_t i = 0, n = GetPageCount(); i < n; i++)
|
||||||
|
{
|
||||||
|
HWND hPage = IndexToHwnd(i);
|
||||||
|
if (hPage != nullptr)
|
||||||
|
{
|
||||||
|
CWindow(::GetDlgItem(hPage, IDC_BOUND_DEVICE)).SetWindowText(g_InputPlugin->ControllerDevices(i).c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigUIDeviceAdded(void)
|
||||||
|
{
|
||||||
|
if (g_ConfigUI != nullptr)
|
||||||
|
{
|
||||||
|
g_ConfigUI->UpdateDeviceMapping();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
void ConfigInput(void * hParent);
|
void ConfigInput(void * hParent);
|
||||||
|
void ConfigUIDeviceAdded(void);
|
||||||
|
|
Loading…
Reference in New Issue