Project64-input: Add Setup button
This commit is contained in:
parent
1be3f869d6
commit
d21c3a89f2
|
@ -71,6 +71,7 @@ void CProject64Input::StartScanDevices(int32_t DisplayCtrlId)
|
|||
{
|
||||
m_Scanning = true;
|
||||
m_DisplayCtrlId = DisplayCtrlId;
|
||||
m_DirectInput->UpdateDeviceData();
|
||||
}
|
||||
|
||||
void CProject64Input::EndScanDevices(void)
|
||||
|
|
|
@ -7,7 +7,6 @@ CDirectInput::CDirectInput(HINSTANCE hinst) :
|
|||
m_hinst(hinst),
|
||||
m_hWnd(nullptr)
|
||||
{
|
||||
LoadConfig();
|
||||
if (m_hDirectInputDLL == nullptr)
|
||||
{
|
||||
m_hDirectInputDLL = LoadLibrary(L"dinput8.dll");
|
||||
|
@ -173,7 +172,7 @@ CDirectInput::ScanResult CDirectInput::ScanDevices(BUTTON & Button)
|
|||
uint8_t DeviceType = LOBYTE(device.dwDevType);
|
||||
if (DeviceType == DI8DEVTYPE_KEYBOARD)
|
||||
{
|
||||
Result = ScanKeyboard(itr->first, device.didHandle, Button);
|
||||
Result = ScanKeyboard(itr->first, device.didHandle, device.State.Keyboard, Button);
|
||||
}
|
||||
else if (DeviceType == DI8DEVTYPE_MOUSE)
|
||||
{
|
||||
|
@ -288,7 +287,7 @@ void CDirectInput::UpdateDeviceData(void)
|
|||
}
|
||||
}
|
||||
|
||||
CDirectInput::ScanResult CDirectInput::ScanKeyboard(const GUID & DeviceGuid, LPDIRECTINPUTDEVICE8 didHandle, BUTTON & pButton)
|
||||
CDirectInput::ScanResult CDirectInput::ScanKeyboard(const GUID & DeviceGuid, LPDIRECTINPUTDEVICE8 didHandle, uint8_t * KeyboardState, BUTTON & pButton)
|
||||
{
|
||||
if (didHandle == nullptr)
|
||||
{
|
||||
|
@ -304,6 +303,11 @@ CDirectInput::ScanResult CDirectInput::ScanKeyboard(const GUID & DeviceGuid, LPD
|
|||
|
||||
for (size_t i = 0, n = sizeof(cKeys) / sizeof(cKeys[0]); i < n; i++)
|
||||
{
|
||||
if (KeyboardState[i] == cKeys[i])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
KeyboardState[i] = cKeys[i];
|
||||
if ((cKeys[i] & 0x80) == 0)
|
||||
{
|
||||
continue;
|
||||
|
@ -343,8 +347,3 @@ bool CDirectInput::AcquireDevice(LPDIRECTINPUTDEVICE8 lpDirectInputDevice)
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CDirectInput::LoadConfig(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ private:
|
|||
|
||||
static BOOL CALLBACK stEnumMakeDeviceList(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef);
|
||||
BOOL EnumMakeDeviceList(LPCDIDEVICEINSTANCE lpddi);
|
||||
ScanResult ScanKeyboard(const GUID & DeviceGuid, LPDIRECTINPUTDEVICE8 didHandle, BUTTON & pButton);
|
||||
ScanResult ScanKeyboard(const GUID & DeviceGuid, LPDIRECTINPUTDEVICE8 didHandle, uint8_t * KeyboardState, BUTTON & pButton);
|
||||
bool AcquireDevice(LPDIRECTINPUTDEVICE8 lpDirectInputDevice);
|
||||
void LoadConfig(void);
|
||||
|
||||
|
|
|
@ -17,13 +17,16 @@ class CControllerSettings :
|
|||
public:
|
||||
enum { IDD = IDD_Controller };
|
||||
|
||||
BEGIN_MSG_MAP(CDebugSettings)
|
||||
BEGIN_MSG_MAP(CControllerSettings)
|
||||
MSG_WM_INITDIALOG(OnInitDialog)
|
||||
MSG_WM_CTLCOLORSTATIC(OnCtlColorStatic)
|
||||
COMMAND_HANDLER_EX(IDC_BTN_SETUP, BN_CLICKED, SetupBtnClicked)
|
||||
COMMAND_HANDLER_EX(IDC_CHK_PLUGGED_IN, BN_CLICKED, ItemChanged)
|
||||
COMMAND_HANDLER_EX(IDC_CMB_DEVICE, CBN_SELCHANGE, ItemChanged)
|
||||
NOTIFY_HANDLER_EX(IDC_TACK_RANGE, NM_RELEASEDCAPTURE, ItemChangedNotify);
|
||||
MESSAGE_HANDLER(WM_HSCROLL, OnScroll)
|
||||
MESSAGE_HANDLER(CScanButton::WM_SCAN_SUCCESS, OnScanSuccess)
|
||||
MESSAGE_HANDLER(CScanButton::WM_SCAN_CANCELED, OnScanCanceled)
|
||||
CHAIN_MSG_MAP(CPropertyPageImpl<CControllerSettings>)
|
||||
END_MSG_MAP()
|
||||
|
||||
|
@ -34,6 +37,9 @@ public:
|
|||
|
||||
private:
|
||||
LRESULT OnScroll(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
||||
LRESULT OnScanSuccess(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
||||
LRESULT OnScanCanceled(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
|
||||
void SetupBtnClicked(UINT Code, int id, HWND ctl);
|
||||
void ItemChanged(UINT Code, int id, HWND ctl);
|
||||
LRESULT ItemChangedNotify(NMHDR* /*pNMHDR*/);
|
||||
void ButtonChannged(void);
|
||||
|
@ -42,6 +48,7 @@ private:
|
|||
std::wstring m_Title;
|
||||
uint32_t m_ControllerNumber;
|
||||
uint32_t m_ScanCount;
|
||||
int32_t m_SetupIndex;
|
||||
CBitmapPicture m_ControllerImg;
|
||||
CButton m_PluggedIn;
|
||||
CComboBox m_cmbDevice;
|
||||
|
@ -56,6 +63,7 @@ private:
|
|||
CControllerSettings::CControllerSettings(uint32_t ControllerNumber) :
|
||||
m_ControllerNumber(ControllerNumber),
|
||||
m_ScanCount(0),
|
||||
m_SetupIndex(-1),
|
||||
m_ButtonUDPad(g_InputPlugin->Controllers(ControllerNumber).U_DPAD, IDC_EDIT_DIGITIAL_UP, IDC_BTN_DIGITIAL_UP),
|
||||
m_ButtonDDPad(g_InputPlugin->Controllers(ControllerNumber).D_DPAD, IDC_EDIT_DIGITIAL_DOWN, IDC_BTN_DIGITIAL_DOWN),
|
||||
m_ButtonLDPad(g_InputPlugin->Controllers(ControllerNumber).L_DPAD, IDC_EDIT_DIGITIAL_LEFT, IDC_BTN_DIGITIAL_LEFT),
|
||||
|
@ -83,7 +91,6 @@ BOOL CControllerSettings::OnInitDialog(CWindow /*wndFocus*/, LPARAM /*lInitParam
|
|||
{
|
||||
N64CONTROLLER & Controller = g_InputPlugin->Controllers(m_ControllerNumber);
|
||||
CONTROL & ControlInfo = g_InputPlugin->ControlInfo(m_ControllerNumber);
|
||||
GetDlgItem(IDC_BTN_SETUP).EnableWindow(false);
|
||||
GetDlgItem(IDC_BTN_DEFAULTS).EnableWindow(false);
|
||||
GetDlgItem(IDC_BTN_LOAD).EnableWindow(false);
|
||||
GetDlgItem(IDC_BTN_SAVE).EnableWindow(false);
|
||||
|
@ -146,6 +153,7 @@ bool CControllerSettings::OnApply()
|
|||
Controller.Range = (uint8_t)m_Range.GetPos();
|
||||
ControlInfo.Present = (m_PluggedIn.GetCheck() == BST_CHECKED) ? 1 : 0;
|
||||
ControlInfo.Plugin = m_cmbDevice.GetItemData(m_cmbDevice.GetCurSel());
|
||||
|
||||
return g_InputPlugin->SaveController(m_ControllerNumber);
|
||||
}
|
||||
|
||||
|
@ -159,6 +167,41 @@ LRESULT CControllerSettings::OnScroll(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM l
|
|||
return 0;
|
||||
}
|
||||
|
||||
LRESULT CControllerSettings::OnScanSuccess(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
||||
{
|
||||
if (m_SetupIndex < 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
CScanButton * Buttons[] = {
|
||||
&m_ButtonUDPad, &m_ButtonDDPad, &m_ButtonLDPad, &m_ButtonRDPad,
|
||||
&m_ButtonAnalogU, &m_ButtonAnalogD, &m_ButtonAnalogL, &m_ButtonAnalogR,
|
||||
&m_ButtonCUp, &m_ButtonCDown, &m_ButtonCLeft, &m_ButtonCRight,
|
||||
&m_ButtonB, &m_ButtonA, &m_ButtonStart, &m_ButtonZtrigger,
|
||||
&m_ButtonLTrigger, &m_ButtonRTrigger
|
||||
};
|
||||
|
||||
m_SetupIndex += 1;
|
||||
if (m_SetupIndex < (sizeof(Buttons) / sizeof(Buttons[0])))
|
||||
{
|
||||
Buttons[m_SetupIndex]->DetectKey();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
LRESULT CControllerSettings::OnScanCanceled(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
|
||||
{
|
||||
m_SetupIndex = -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CControllerSettings::SetupBtnClicked(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
|
||||
{
|
||||
m_SetupIndex = 0;
|
||||
m_ButtonUDPad.DetectKey();
|
||||
}
|
||||
|
||||
void CControllerSettings::ItemChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
|
||||
{
|
||||
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
|
||||
|
|
|
@ -35,7 +35,7 @@ void CScanButton::DisplayButton(void)
|
|||
m_DisplayCtrl.SetWindowText(g_InputPlugin->ButtonAssignment(m_Button).c_str());
|
||||
}
|
||||
|
||||
void CScanButton::OnScan(void)
|
||||
void CScanButton::DetectKey(void)
|
||||
{
|
||||
enum
|
||||
{
|
||||
|
@ -53,7 +53,7 @@ void CScanButton::OnTimer(UINT_PTR nIDEvent)
|
|||
{
|
||||
if (nIDEvent == DETECT_KEY_TIMER)
|
||||
{
|
||||
bool Stop = false;
|
||||
bool Stop = false, ScanSuccess = false;
|
||||
if (g_InputPlugin)
|
||||
{
|
||||
BUTTON Button = m_Button;
|
||||
|
@ -68,6 +68,7 @@ void CScanButton::OnTimer(UINT_PTR nIDEvent)
|
|||
}
|
||||
if (Result == CDirectInput::SCAN_SUCCEED || Result == CDirectInput::SCAN_ESCAPE)
|
||||
{
|
||||
ScanSuccess = Result == CDirectInput::SCAN_SUCCEED;
|
||||
Stop = true;
|
||||
DisplayButton();
|
||||
}
|
||||
|
@ -108,6 +109,7 @@ void CScanButton::OnTimer(UINT_PTR nIDEvent)
|
|||
|
||||
g_InputPlugin->EndScanDevices();
|
||||
m_DisplayCtrl.Invalidate();
|
||||
m_DisplayCtrl.GetParent().SendMessage(ScanSuccess ? WM_SCAN_SUCCESS : WM_SCAN_CANCELED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -147,7 +149,7 @@ UINT_PTR CALLBACK CScanButton::ScanButtonProc(HWND hWnd, UINT uMsg, WPARAM wPara
|
|||
_this->m_ScanBtn.GetWindowRect(&rect);
|
||||
if (PtInRect(&rect, ptCursor))
|
||||
{
|
||||
_this->OnScan();
|
||||
_this->DetectKey();
|
||||
}
|
||||
}
|
||||
else if (uMsg == WM_TIMER)
|
||||
|
|
|
@ -10,20 +10,25 @@ class CScanButton
|
|||
};
|
||||
|
||||
public:
|
||||
enum
|
||||
{
|
||||
WM_SCAN_SUCCESS = WM_USER + 0x140,
|
||||
WM_SCAN_CANCELED = WM_USER + 0x141,
|
||||
};
|
||||
typedef void(*ChangeCallback)(size_t Data);
|
||||
|
||||
CScanButton(BUTTON & Button, int DisplayCtrlId, int ScanBtnId);
|
||||
|
||||
void SubclassWindow(CWindow Wnd);
|
||||
void SetChangeCallback(ChangeCallback callback, size_t callbackdata);
|
||||
void DetectKey(void);
|
||||
void DisplayButton(void);
|
||||
|
||||
private:
|
||||
CScanButton(void);
|
||||
CScanButton(const CScanButton&);
|
||||
CScanButton& operator=(const CScanButton&);
|
||||
|
||||
void DisplayButton(void);
|
||||
void OnScan(void);
|
||||
void OnTimer(UINT_PTR nIDEvent);
|
||||
void MakeOverlay(void);
|
||||
static UINT_PTR CALLBACK ScanButtonProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
|
|
Loading…
Reference in New Issue