Merge pull request #1719 from ergo720/default_bindings
Add default bindings for the keyboard
This commit is contained in:
commit
421864c0bb
|
@ -153,7 +153,7 @@ BEGIN
|
||||||
GROUPBOX "Rumble", IDC_XID_RUMBLE, 396, 212, 121, 34, WS_GROUP
|
GROUPBOX "Rumble", IDC_XID_RUMBLE, 396, 212, 121, 34, WS_GROUP
|
||||||
PUSHBUTTON "", IDC_SET_MOTOR, 443, 224, 57, 14, BS_FLAT
|
PUSHBUTTON "", IDC_SET_MOTOR, 443, 224, 57, 14, BS_FLAT
|
||||||
LTEXT "Motor", IDC_STATIC, 412, 224, 26, 14, SS_CENTERIMAGE
|
LTEXT "Motor", IDC_STATIC, 412, 224, 26, 14, SS_CENTERIMAGE
|
||||||
PUSHBUTTON "XInput Default", IDC_XINP_DEFAULT, 362, 256, 69, 14, BS_FLAT
|
PUSHBUTTON "Default Bindings", IDC_XID_DEFAULT, 362, 256, 69, 14, BS_FLAT
|
||||||
PUSHBUTTON "Clear", IDC_XID_CLEAR, 443, 256, 50, 14, BS_FLAT
|
PUSHBUTTON "Clear", IDC_XID_CLEAR, 443, 256, 50, 14, BS_FLAT
|
||||||
END
|
END
|
||||||
|
|
||||||
|
|
|
@ -40,11 +40,6 @@ void Button::UpdateText(const char* text) const
|
||||||
SendMessage(m_button_hwnd, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(text));
|
SendMessage(m_button_hwnd, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Button::UpdateText() const // xinput specific
|
|
||||||
{
|
|
||||||
SendMessage(m_button_hwnd, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(m_xinput_button.c_str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::ClearText() const
|
void Button::ClearText() const
|
||||||
{
|
{
|
||||||
SendMessage(m_button_hwnd, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(""));
|
SendMessage(m_button_hwnd, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(""));
|
||||||
|
@ -55,6 +50,12 @@ void Button::GetText(char* const text, size_t size) const
|
||||||
SendMessage(m_button_hwnd, WM_GETTEXT, size, reinterpret_cast<LPARAM>(text));
|
SendMessage(m_button_hwnd, WM_GETTEXT, size, reinterpret_cast<LPARAM>(text));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Button::GetName(int api, int idx) const
|
||||||
|
{
|
||||||
|
assert(api == XINPUT_DEFAULT || api == DINPUT_DEFAULT);
|
||||||
|
return button_xbox_ctrl_names[idx][api];
|
||||||
|
}
|
||||||
|
|
||||||
LRESULT CALLBACK ButtonSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
|
LRESULT CALLBACK ButtonSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
|
||||||
{
|
{
|
||||||
switch (uMsg)
|
switch (uMsg)
|
||||||
|
|
|
@ -38,21 +38,17 @@
|
||||||
class Button
|
class Button
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Button(const char* name, const char* xname, int id, int index, HWND hwnd) : m_name(name),
|
Button(int id, int index, HWND hwnd) : m_id(id), m_index(index), m_button_hwnd(GetDlgItem(hwnd, m_id)) {};
|
||||||
m_xinput_button(xname), m_id(id), m_index(index), m_button_hwnd(GetDlgItem(hwnd, m_id)) {};
|
|
||||||
void EnableButton(bool enable) const;
|
void EnableButton(bool enable) const;
|
||||||
void UpdateText(const char* text) const;
|
void UpdateText(const char* text) const;
|
||||||
void UpdateText() const;
|
|
||||||
void ClearText() const;
|
void ClearText() const;
|
||||||
void GetText(char* const text, size_t size) const;
|
void GetText(char* const text, size_t size) const;
|
||||||
std::string GetName() const { return m_name; }
|
std::string GetName(int api, int idx) const;
|
||||||
int GetId() const { return m_id; }
|
int GetId() const { return m_id; }
|
||||||
int GetIndex() const { return m_index; }
|
int GetIndex() const { return m_index; }
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_name;
|
|
||||||
std::string m_xinput_button;
|
|
||||||
int m_id;
|
int m_id;
|
||||||
int m_index;
|
int m_index;
|
||||||
HWND m_button_hwnd;
|
HWND m_button_hwnd;
|
||||||
|
|
|
@ -57,32 +57,32 @@ static int button_xbox_ctrl_id[XBOX_CTRL_NUM_BUTTONS] = {
|
||||||
IDC_SET_MOTOR,
|
IDC_SET_MOTOR,
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* button_xbox_ctrl_names[XBOX_CTRL_NUM_BUTTONS][2] = {
|
const char* button_xbox_ctrl_names[XBOX_CTRL_NUM_BUTTONS][3] = {
|
||||||
"D Pad Up", "Pad N",
|
"D Pad Up", "Pad N", "UP",
|
||||||
"D Pad Down", "Pad S",
|
"D Pad Down", "Pad S", "DOWN",
|
||||||
"D Pad Left", "Pad W",
|
"D Pad Left", "Pad W", "LEFT",
|
||||||
"D Pad Right", "Pad E",
|
"D Pad Right", "Pad E", "RIGHT",
|
||||||
"Start", "Start",
|
"Start", "Start", "RETURN",
|
||||||
"Back", "Back",
|
"Back", "Back", "SPACE",
|
||||||
"L Thumb", "Thumb L",
|
"L Thumb", "Thumb L", "B",
|
||||||
"R Thumb", "Thumb R",
|
"R Thumb", "Thumb R", "M",
|
||||||
"A", "Button A",
|
"A", "Button A", "S",
|
||||||
"B", "Button B",
|
"B", "Button B", "D",
|
||||||
"X", "Button X",
|
"X", "Button X", "W",
|
||||||
"Y", "Button Y",
|
"Y", "Button Y", "E",
|
||||||
"Black", "Shoulder R",
|
"Black", "Shoulder R", "C",
|
||||||
"White", "Shoulder L",
|
"White", "Shoulder L", "X",
|
||||||
"L Trigger", "Trigger L",
|
"L Trigger", "Trigger L", "Q",
|
||||||
"R Trigger", "Trigger R",
|
"R Trigger", "Trigger R", "R",
|
||||||
"Left Axis X+", "Left X+",
|
"Left Axis X+", "Left X+", "H",
|
||||||
"Left Axis X-", "Left X-",
|
"Left Axis X-", "Left X-", "F",
|
||||||
"Left Axis Y+", "Left Y+",
|
"Left Axis Y+", "Left Y+", "T",
|
||||||
"Left Axis Y-", "Left Y-",
|
"Left Axis Y-", "Left Y-", "G",
|
||||||
"Right Axis X+", "Right X+",
|
"Right Axis X+", "Right X+", "L",
|
||||||
"Right Axis X-", "Right X-",
|
"Right Axis X-", "Right X-", "J",
|
||||||
"Right Axis Y+", "Right Y+",
|
"Right Axis Y+", "Right Y+", "I",
|
||||||
"Right Axis Y-", "Right Y-",
|
"Right Axis Y-", "Right Y-", "K",
|
||||||
"Motor", "LeftRight",
|
"Motor", "LeftRight", "",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,8 +93,7 @@ EmuDevice::EmuDevice(int type, HWND hwnd)
|
||||||
case to_underlying(XBOX_INPUT_DEVICE::MS_CONTROLLER_DUKE): {
|
case to_underlying(XBOX_INPUT_DEVICE::MS_CONTROLLER_DUKE): {
|
||||||
m_hwnd = hwnd;
|
m_hwnd = hwnd;
|
||||||
for (int i = 0; i < ARRAY_SIZE(button_xbox_ctrl_id); i++) {
|
for (int i = 0; i < ARRAY_SIZE(button_xbox_ctrl_id); i++) {
|
||||||
m_buttons.push_back(new Button(button_xbox_ctrl_names[i][0], button_xbox_ctrl_names[i][1],
|
m_buttons.push_back(new Button(button_xbox_ctrl_id[i], i, hwnd));
|
||||||
button_xbox_ctrl_id[i], i, hwnd));
|
|
||||||
|
|
||||||
// Install the subclass for the button control
|
// Install the subclass for the button control
|
||||||
SetWindowSubclass(GetDlgItem(hwnd, button_xbox_ctrl_id[i]), ButtonSubclassProc, 0, reinterpret_cast<DWORD_PTR>(m_buttons[i]));
|
SetWindowSubclass(GetDlgItem(hwnd, button_xbox_ctrl_id[i]), ButtonSubclassProc, 0, reinterpret_cast<DWORD_PTR>(m_buttons[i]));
|
||||||
|
@ -131,10 +130,10 @@ Button* EmuDevice::FindButtonByIndex(int index)
|
||||||
return m_buttons[index];
|
return m_buttons[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmuDevice::BindXInput()
|
void EmuDevice::BindDefault(int api)
|
||||||
{
|
{
|
||||||
std::for_each(m_buttons.begin(), m_buttons.end(), [](const auto button) {
|
std::for_each(m_buttons.begin(), m_buttons.end(), [&api](const auto button) {
|
||||||
button->UpdateText();
|
button->UpdateText(button->GetName(api, button->GetIndex()).c_str());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#include "Button.h"
|
#include "Button.h"
|
||||||
#include "common\util\CxbxUtil.h"
|
#include "common\util\CxbxUtil.h"
|
||||||
|
|
||||||
extern const char* button_xbox_ctrl_names[XBOX_CTRL_NUM_BUTTONS][2];
|
extern const char* button_xbox_ctrl_names[XBOX_CTRL_NUM_BUTTONS][3];
|
||||||
extern int dev_num_buttons[to_underlying(XBOX_INPUT_DEVICE::DEVICE_MAX)];
|
extern int dev_num_buttons[to_underlying(XBOX_INPUT_DEVICE::DEVICE_MAX)];
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ public:
|
||||||
~EmuDevice();
|
~EmuDevice();
|
||||||
Button* FindButtonById(int id);
|
Button* FindButtonById(int id);
|
||||||
Button* FindButtonByIndex(int index);
|
Button* FindButtonByIndex(int index);
|
||||||
void BindXInput();
|
void BindDefault(int api);
|
||||||
void ClearButtons();
|
void ClearButtons();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,7 @@ void InputWindow::Initialize(HWND hwnd, int port_num, int dev_type)
|
||||||
m_hwnd_window = hwnd;
|
m_hwnd_window = hwnd;
|
||||||
m_hwnd_device_list = GetDlgItem(m_hwnd_window, IDC_DEVICE_LIST);
|
m_hwnd_device_list = GetDlgItem(m_hwnd_window, IDC_DEVICE_LIST);
|
||||||
m_hwnd_profile_list = GetDlgItem(m_hwnd_window, IDC_XID_PROFILE_NAME);
|
m_hwnd_profile_list = GetDlgItem(m_hwnd_window, IDC_XID_PROFILE_NAME);
|
||||||
|
m_hwnd_default = GetDlgItem(m_hwnd_window, IDC_XID_DEFAULT);
|
||||||
m_dev_type = dev_type;
|
m_dev_type = dev_type;
|
||||||
m_max_num_buttons = dev_num_buttons[dev_type];
|
m_max_num_buttons = dev_num_buttons[dev_type];
|
||||||
m_port_num = port_num;
|
m_port_num = port_num;
|
||||||
|
@ -232,10 +233,11 @@ void InputWindow::BindButton(int ControlID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputWindow::BindXInput()
|
void InputWindow::BindDefault()
|
||||||
{
|
{
|
||||||
if (std::strncmp(m_host_dev.c_str(), "XInput", std::strlen("XInput")) == 0) {
|
int api = EnableDefaultButton();
|
||||||
m_DeviceConfig->BindXInput();
|
if (api != -1) {
|
||||||
|
m_DeviceConfig->BindDefault(api);
|
||||||
m_bHasChanges = true;
|
m_bHasChanges = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,6 +249,22 @@ void InputWindow::ClearBindings()
|
||||||
m_bHasChanges = true;
|
m_bHasChanges = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int InputWindow::EnableDefaultButton()
|
||||||
|
{
|
||||||
|
if (std::strncmp(m_host_dev.c_str(), "XInput", std::strlen("XInput")) == 0) {
|
||||||
|
EnableWindow(m_hwnd_default, TRUE);
|
||||||
|
return XINPUT_DEFAULT;
|
||||||
|
}
|
||||||
|
else if (std::strncmp(m_host_dev.c_str(), "DInput", std::strlen("DInput")) == 0) {
|
||||||
|
EnableWindow(m_hwnd_default, TRUE);
|
||||||
|
return DINPUT_DEFAULT;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
EnableWindow(m_hwnd_default, FALSE);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
InputWindow::ProfileIt InputWindow::FindProfile(std::string& name)
|
InputWindow::ProfileIt InputWindow::FindProfile(std::string& name)
|
||||||
{
|
{
|
||||||
auto it = std::find_if(g_Settings->m_input_profiles[m_dev_type].begin(),
|
auto it = std::find_if(g_Settings->m_input_profiles[m_dev_type].begin(),
|
||||||
|
@ -297,6 +315,7 @@ void InputWindow::LoadProfile(std::string& name)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_host_dev = profile->DeviceName;
|
m_host_dev = profile->DeviceName;
|
||||||
|
EnableDefaultButton();
|
||||||
LRESULT dev_str_index = SendMessage(m_hwnd_device_list, CB_FINDSTRINGEXACT, 1, reinterpret_cast<LPARAM>(m_host_dev.c_str()));
|
LRESULT dev_str_index = SendMessage(m_hwnd_device_list, CB_FINDSTRINGEXACT, 1, reinterpret_cast<LPARAM>(m_host_dev.c_str()));
|
||||||
if (dev_str_index == CB_ERR) {
|
if (dev_str_index == CB_ERR) {
|
||||||
SendMessage(m_hwnd_device_list, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(m_host_dev.c_str()));
|
SendMessage(m_hwnd_device_list, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(m_host_dev.c_str()));
|
||||||
|
@ -391,6 +410,7 @@ void InputWindow::UpdateCurrentDevice()
|
||||||
char device_name[50];
|
char device_name[50];
|
||||||
SendMessage(m_hwnd_device_list, WM_GETTEXT, sizeof(device_name), reinterpret_cast<LPARAM>(device_name));
|
SendMessage(m_hwnd_device_list, WM_GETTEXT, sizeof(device_name), reinterpret_cast<LPARAM>(device_name));
|
||||||
m_host_dev = device_name;
|
m_host_dev = device_name;
|
||||||
|
EnableDefaultButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputWindow::InitRumble(HWND hwnd)
|
void InputWindow::InitRumble(HWND hwnd)
|
||||||
|
|
|
@ -40,6 +40,8 @@
|
||||||
#define RUMBLE_CLEAR 7
|
#define RUMBLE_CLEAR 7
|
||||||
#define BUTTON_CLEAR 8
|
#define BUTTON_CLEAR 8
|
||||||
|
|
||||||
|
#define XINPUT_DEFAULT 1
|
||||||
|
#define DINPUT_DEFAULT 2
|
||||||
|
|
||||||
LRESULT CALLBACK ProfileNameSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
|
LRESULT CALLBACK ProfileNameSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
|
||||||
|
|
||||||
|
@ -52,7 +54,7 @@ public:
|
||||||
~InputWindow();
|
~InputWindow();
|
||||||
void UpdateDeviceList();
|
void UpdateDeviceList();
|
||||||
void BindButton(int ControlID);
|
void BindButton(int ControlID);
|
||||||
void BindXInput();
|
void BindDefault();
|
||||||
void ClearBindings();
|
void ClearBindings();
|
||||||
void UpdateProfile(std::string& name, int command);
|
void UpdateProfile(std::string& name, int command);
|
||||||
void UpdateRumble(int command);
|
void UpdateRumble(int command);
|
||||||
|
@ -70,6 +72,7 @@ private:
|
||||||
void DeleteProfile(std::string& name);
|
void DeleteProfile(std::string& name);
|
||||||
void OverwriteProfile(std::string& name);
|
void OverwriteProfile(std::string& name);
|
||||||
void LoadDefaultProfile();
|
void LoadDefaultProfile();
|
||||||
|
int EnableDefaultButton();
|
||||||
|
|
||||||
// xbox device under configuration
|
// xbox device under configuration
|
||||||
EmuDevice* m_DeviceConfig;
|
EmuDevice* m_DeviceConfig;
|
||||||
|
@ -83,6 +86,8 @@ private:
|
||||||
HWND m_hwnd_rumble;
|
HWND m_hwnd_rumble;
|
||||||
// handle of the rumble combobox
|
// handle of the rumble combobox
|
||||||
HWND m_hwnd_rumble_list;
|
HWND m_hwnd_rumble_list;
|
||||||
|
// handle of the default bindings button
|
||||||
|
HWND m_hwnd_default;
|
||||||
// type of the device
|
// type of the device
|
||||||
int m_dev_type;
|
int m_dev_type;
|
||||||
// num of buttons of device under configuration
|
// num of buttons of device under configuration
|
||||||
|
|
|
@ -99,9 +99,9 @@ INT_PTR CALLBACK DlgXidControllerConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wPar
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IDC_XINP_DEFAULT: {
|
case IDC_XID_DEFAULT: {
|
||||||
if (HIWORD(wParam) == BN_CLICKED) {
|
if (HIWORD(wParam) == BN_CLICKED) {
|
||||||
g_InputWindow->BindXInput();
|
g_InputWindow->BindDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -282,7 +282,7 @@
|
||||||
#define IDC_CONFIGURE_PORT4 1284
|
#define IDC_CONFIGURE_PORT4 1284
|
||||||
#define IDC_DEVICE_LIST 1285
|
#define IDC_DEVICE_LIST 1285
|
||||||
#define IDC_REFRESH_DEVICES 1286
|
#define IDC_REFRESH_DEVICES 1286
|
||||||
#define IDC_XINP_DEFAULT 1287
|
#define IDC_XID_DEFAULT 1287
|
||||||
#define IDC_XID_PROFILE 1288
|
#define IDC_XID_PROFILE 1288
|
||||||
#define IDC_XID_PROFILE_NAME 1289
|
#define IDC_XID_PROFILE_NAME 1289
|
||||||
#define IDC_XID_PROFILE_SAVE 1291
|
#define IDC_XID_PROFILE_SAVE 1291
|
||||||
|
|
Loading…
Reference in New Issue