Project64-input: Add more buttons to be scanned

This commit is contained in:
zilmar 2020-07-01 11:42:13 +09:30
parent 31afb1cf6e
commit acd835cfc4
3 changed files with 82 additions and 18 deletions

View File

@ -26,15 +26,21 @@ public:
CControllerSettings(uint32_t ControllerNumber);
BOOL OnInitDialog(CWindow /*wndFocus*/, LPARAM /*lInitParam*/);
HBRUSH OnCtlColorStatic(CDCHandle dc, CWindow wndStatic);
bool OnApply();
private:
void ButtonChannged(void);
static void stButtonChanged(size_t data) { ((CControllerSettings *)data)->ButtonChannged(); }
std::wstring m_Title;
uint32_t m_ControllerNumber;
uint32_t m_ScanCount;
CBitmapPicture m_ControllerImg;
CScanButton ButtonUDPad, ButtonDDPad, ButtonLDPad, ButtonRDPad;
CScanButton ButtonCUp, ButtonCDown, ButtonCLeft, ButtonCRight;
CScanButton ButtonA, ButtonB;
CScanButton ButtonA, ButtonB, ButtonStart;
CScanButton ButtonZtrigger, ButtonRTrigger, ButtonLTrigger;
CScanButton ButtonAnalogU, ButtonAnalogD, ButtonAnalogL, ButtonAnalogR;
};
CControllerSettings::CControllerSettings(uint32_t ControllerNumber) :
@ -49,7 +55,15 @@ CControllerSettings::CControllerSettings(uint32_t ControllerNumber) :
ButtonCUp(g_InputPlugin->Controllers(ControllerNumber).U_CBUTTON, IDC_EDIT_CBUTTON_UP, IDC_BTN_CBUTTON_UP),
ButtonCDown(g_InputPlugin->Controllers(ControllerNumber).D_CBUTTON, IDC_EDIT_CBUTTON_DOWN, IDC_BTN_CBUTTON_DOWN),
ButtonCLeft(g_InputPlugin->Controllers(ControllerNumber).L_CBUTTON, IDC_EDIT_CBUTTON_LEFT, IDC_BTN_CBUTTON_LEFT),
ButtonCRight(g_InputPlugin->Controllers(ControllerNumber).R_CBUTTON, IDC_EDIT_CBUTTON_RIGHT, IDC_BTN_CBUTTON_RIGHT)
ButtonCRight(g_InputPlugin->Controllers(ControllerNumber).R_CBUTTON, IDC_EDIT_CBUTTON_RIGHT, IDC_BTN_CBUTTON_RIGHT),
ButtonStart(g_InputPlugin->Controllers(ControllerNumber).START_BUTTON, IDC_EDIT_BUTTON_START, IDC_BTN_BUTTON_START),
ButtonZtrigger(g_InputPlugin->Controllers(ControllerNumber).Z_TRIG, IDC_EDIT_BUTTON_Z, IDC_BTN_BUTTON_Z),
ButtonRTrigger(g_InputPlugin->Controllers(ControllerNumber).R_TRIG, IDC_EDIT_RTRIGGER, IDC_BTN_RTRIGGER),
ButtonLTrigger(g_InputPlugin->Controllers(ControllerNumber).L_TRIG, IDC_EDIT_LTRIGGER, IDC_BTN_LTRIGGER),
ButtonAnalogU(g_InputPlugin->Controllers(ControllerNumber).U_ANALOG, IDC_EDIT_ANALOG_UP, IDC_BTN_ANALOG_UP),
ButtonAnalogD(g_InputPlugin->Controllers(ControllerNumber).D_ANALOG, IDC_EDIT_ANALOG_DOWN, IDC_BTN_ANALOG_DOWN),
ButtonAnalogL(g_InputPlugin->Controllers(ControllerNumber).L_ANALOG, IDC_EDIT_ANALOG_LEFT, IDC_BTN_ANALOG_LEFT),
ButtonAnalogR(g_InputPlugin->Controllers(ControllerNumber).R_ANALOG, IDC_EDIT_ANALOG_RIGHT, IDC_BTN_ANALOG_RIGHT)
{
m_Title = stdstr_f("Player %d", ControllerNumber + 1).ToUTF16();
SetTitle(m_Title.c_str());
@ -57,18 +71,26 @@ CControllerSettings::CControllerSettings(uint32_t ControllerNumber) :
BOOL CControllerSettings::OnInitDialog(CWindow /*wndFocus*/, LPARAM /*lInitParam*/)
{
GetDlgItem(IDC_BTN_SETUP).EnableWindow(false);
GetDlgItem(IDC_BTN_DEFAULTS).EnableWindow(false);
GetDlgItem(IDC_BTN_LOAD).EnableWindow(false);
GetDlgItem(IDC_BTN_SAVE).EnableWindow(false);
GetDlgItem(IDC_TACK_RANGE).EnableWindow(false);
m_ControllerImg.SubclassWindow(GetDlgItem(IDC_BMP_CONTROLLER));
m_ControllerImg.SetBitmap(MAKEINTRESOURCE(IDB_CONTROLLER));
ButtonUDPad.SubclassWindow(m_hWnd);
ButtonDDPad.SubclassWindow(m_hWnd);
ButtonLDPad.SubclassWindow(m_hWnd);
ButtonRDPad.SubclassWindow(m_hWnd);
ButtonA.SubclassWindow(m_hWnd);
ButtonB.SubclassWindow(m_hWnd);
ButtonCUp.SubclassWindow(m_hWnd);
ButtonCDown.SubclassWindow(m_hWnd);
ButtonCLeft.SubclassWindow(m_hWnd);
ButtonCRight.SubclassWindow(m_hWnd);
CScanButton * Buttons[] = {
&ButtonUDPad, &ButtonDDPad, &ButtonLDPad, &ButtonRDPad, &ButtonA, &ButtonB,
&ButtonCUp, &ButtonCDown, &ButtonCLeft, &ButtonCRight, &ButtonStart,
&ButtonZtrigger, &ButtonRTrigger, &ButtonLTrigger,
&ButtonAnalogU, &ButtonAnalogD, &ButtonAnalogL, &ButtonAnalogR
};
for (size_t i = 0, n = sizeof(Buttons) / sizeof(Buttons[0]); i < n; i++)
{
Buttons[i]->SubclassWindow(m_hWnd);
Buttons[i]->SetChangeCallback(stButtonChanged, (size_t)this);
}
return TRUE;
}
@ -85,6 +107,16 @@ HBRUSH CControllerSettings::OnCtlColorStatic(CDCHandle dc, CWindow wndStatic)
return ::GetSysColorBrush(COLOR_WINDOW);
}
bool CControllerSettings::OnApply()
{
return true;
}
void CControllerSettings::ButtonChannged(void)
{
CPropertySheetWindow(GetParent()).SetModified(m_hWnd);
}
class CInputConfigUI:
public CPropertySheetImpl<CInputConfigUI>
{

View File

@ -9,7 +9,9 @@ CScanButton::CScanButton(BUTTON & Button, int DisplayCtrlId, int ScanBtnId) :
m_ScanBtnId(ScanBtnId),
m_ScanBtnProc(nullptr),
m_ScanCount(0),
m_ScanStart(0)
m_ScanStart(0),
m_ChangeCallback(nullptr),
m_ChangeCallbackData(0)
{
}
@ -22,6 +24,12 @@ void CScanButton::SubclassWindow(CWindow Wnd)
DisplayButton();
}
void CScanButton::SetChangeCallback(ChangeCallback callback, size_t callbackdata)
{
m_ChangeCallback = callback;
m_ChangeCallbackData = callbackdata;
}
void CScanButton::DisplayButton(void)
{
m_DisplayCtrl.SetWindowText(g_InputPlugin->ButtonAssignment(m_Button).c_str());
@ -48,8 +56,17 @@ void CScanButton::OnTimer(UINT_PTR nIDEvent)
bool Stop = false;
if (g_InputPlugin)
{
CDirectInput::ScanResult Result = g_InputPlugin->ScanDevices(m_Button);
if (Result == CDirectInput::SCAN_SUCCEED)
BUTTON Button = m_Button;
CDirectInput::ScanResult Result = g_InputPlugin->ScanDevices(Button);
if (Result == CDirectInput::SCAN_SUCCEED && (Button.Offset != m_Button.Offset || Button.AxisID != m_Button.AxisID || Button.BtnType != m_Button.BtnType))
{
m_Button = Button;
if (m_ChangeCallback != nullptr)
{
m_ChangeCallback(m_ChangeCallbackData);
}
}
if (Result == CDirectInput::SCAN_SUCCEED || Result == CDirectInput::SCAN_ESCAPE)
{
Stop = true;
DisplayButton();
@ -83,9 +100,12 @@ void CScanButton::OnTimer(UINT_PTR nIDEvent)
CWindow Dialog = m_ScanBtn.GetParent().GetParent();
Dialog.SetWindowText(L"Configure Input");
m_Overlay.DestroyWindow();
m_Overlay = NULL;
if (m_Overlay.m_hWnd != NULL)
{
m_Overlay.DestroyWindow();
m_Overlay = NULL;
}
g_InputPlugin->EndScanDevices();
m_DisplayCtrl.Invalidate();
}
@ -103,12 +123,15 @@ void CScanButton::MakeOverlay(void)
CWindow ControllerDlg = m_ScanBtn.GetParent().GetParent();
CRect size;
ControllerDlg.GetWindowRect(&size);
#ifndef _DEBUG
m_Overlay = CreateWindowEx(WS_EX_TOPMOST | WS_EX_TRANSPARENT, L"BlockerClass", L"Blocker", WS_POPUP, size.left, size.top, size.Width(), size.Height(), ControllerDlg, nullptr, g_InputPlugin->hInst(), NULL);
if (m_Overlay == NULL)
{
return;
}
m_Overlay.SetFocus();
m_Overlay.ShowWindow(SW_SHOWNOACTIVATE);
#endif
}
UINT_PTR CALLBACK CScanButton::ScanButtonProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
@ -145,6 +168,10 @@ UINT_PTR CALLBACK CScanButton::BlockerProc(HWND hwnd, UINT msg, WPARAM wParam,
{
return 0;
}
if (msg == WM_KEYDOWN || msg == WM_KEYUP)
{
return 0;
}
if (msg == WM_PAINT)
{
PAINTSTRUCT ps;

View File

@ -10,9 +10,12 @@ class CScanButton
};
public:
typedef void(*ChangeCallback)(size_t Data);
CScanButton(BUTTON & Button, int DisplayCtrlId, int ScanBtnId);
void SubclassWindow(CWindow Wnd);
void SetChangeCallback(ChangeCallback callback, size_t callbackdata);
private:
CScanButton(void);
@ -34,4 +37,6 @@ private:
uint32_t m_ScanCount;
time_t m_ScanStart;
CWindow m_Overlay;
ChangeCallback m_ChangeCallback;
size_t m_ChangeCallbackData;
};