More Input Configuration Stuff
This commit is contained in:
parent
d3b1be57cb
commit
cc93465d7d
2
Cxbx.dsp
2
Cxbx.dsp
|
@ -1,5 +1,5 @@
|
|||
# Microsoft Developer Studio Project File - Name="Cxbx" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 60000
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Application" 0x0101
|
||||
|
|
|
@ -71,6 +71,18 @@ extern CXBXKRNL_API class EmuShared : public Mutex
|
|||
|
||||
Unlock();
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * RetrieveInputConfiguration
|
||||
// ******************************************************************
|
||||
void RetrieveInputConfiguration(InputConfig *x_InputConfig)
|
||||
{
|
||||
Lock();
|
||||
|
||||
memcpy(x_InputConfig, &m_InputConfig, sizeof(InputConfig));
|
||||
|
||||
Unlock();
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Check the current Change ID
|
||||
|
|
|
@ -35,26 +35,30 @@
|
|||
#define INPUTCONFIG_H
|
||||
|
||||
// ******************************************************************
|
||||
// * 32 input devices maximum
|
||||
// * 32 Input Devices Maximum
|
||||
// ******************************************************************
|
||||
#define MAX_INPUT_DEVICES 0x20
|
||||
|
||||
// ******************************************************************
|
||||
// * InputMapping flags
|
||||
// * InputMapping Flags
|
||||
// ******************************************************************
|
||||
#define INPUT_MAPPING_AXIS_POSITIVE (1 << 0)
|
||||
#define INPUT_MAPPING_AXIS_NEGATIVE (1 << 1)
|
||||
#define INPUT_MAPPING_JOYSTICK (1 << 0)
|
||||
#define INPUT_MAPPING_KEYBOARD (1 << 1)
|
||||
#define INPUT_MAPPING_MOUSE (1 << 2)
|
||||
#define INPUT_MAPPING_AXIS_POSITIVE (1 << 3)
|
||||
#define INPUT_MAPPING_AXIS_NEGATIVE (1 << 4)
|
||||
#define INPUT_MAPPING_MOUSE_CLICK (1 << 5)
|
||||
|
||||
// ******************************************************************
|
||||
// * Input mapping information
|
||||
// ******************************************************************
|
||||
struct InputMapping
|
||||
{
|
||||
InputMapping() : dwDevice(-1), dwType(-1), dwFlags(0) {}
|
||||
InputMapping() : dwDevice(-1), dwInfo(-1), dwFlags(0) {}
|
||||
|
||||
int dwDevice; // lookup into m_Devices
|
||||
int dwType; // used to locate the data inside GetDeviceState's return data
|
||||
int dwFlags; // flags giving more precise information about the data format
|
||||
int dwDevice; // Offset into m_Devices
|
||||
int dwInfo; // Extended information, depending on dwFlags
|
||||
int dwFlags; // Flags explaining the data format
|
||||
};
|
||||
|
||||
// ******************************************************************
|
||||
|
@ -71,37 +75,37 @@ class InputConfig
|
|||
// ******************************************************************
|
||||
// * Deconstructor
|
||||
// ******************************************************************
|
||||
~InputConfig();
|
||||
~InputConfig() {}
|
||||
|
||||
// ******************************************************************
|
||||
// * Mapping Accessors
|
||||
// ******************************************************************
|
||||
void MapLThumbX(const char *DeviceName, int dwType, int dwFlags) { Map(m_LThumbX, DeviceName, dwType, dwFlags); }
|
||||
void MapLThumbY(const char *DeviceName, int dwType, int dwFlags) { Map(m_LThumbY, DeviceName, dwType, dwFlags); }
|
||||
void MapRThumbX(const char *DeviceName, int dwType, int dwFlags) { Map(m_RThumbX, DeviceName, dwType, dwFlags); }
|
||||
void MapRThumbY(const char *DeviceName, int dwType, int dwFlags) { Map(m_RThumbY, DeviceName, dwType, dwFlags); }
|
||||
void MapX(const char *DeviceName, int dwType, int dwFlags) { Map(m_X, DeviceName, dwType, dwFlags); }
|
||||
void MapY(const char *DeviceName, int dwType, int dwFlags) { Map(m_Y, DeviceName, dwType, dwFlags); }
|
||||
void MapA(const char *DeviceName, int dwType, int dwFlags) { Map(m_A, DeviceName, dwType, dwFlags); }
|
||||
void MapB(const char *DeviceName, int dwType, int dwFlags) { Map(m_B, DeviceName, dwType, dwFlags); }
|
||||
void MapWhite(const char *DeviceName, int dwType, int dwFlags) { Map(m_White, DeviceName, dwType, dwFlags); }
|
||||
void MapBlack(const char *DeviceName, int dwType, int dwFlags) { Map(m_Black, DeviceName, dwType, dwFlags); }
|
||||
void MapLTrigger(const char *DeviceName, int dwType, int dwFlags) { Map(m_LTrigger, DeviceName, dwType, dwFlags); }
|
||||
void MapRTrigger(const char *DeviceName, int dwType, int dwFlags) { Map(m_RTrigger, DeviceName, dwType, dwFlags); }
|
||||
void MapDPadUp(const char *DeviceName, int dwType, int dwFlags) { Map(m_DPadUp, DeviceName, dwType, dwFlags); }
|
||||
void MapDPadDown(const char *DeviceName, int dwType, int dwFlags) { Map(m_DPadDown, DeviceName, dwType, dwFlags); }
|
||||
void MapDPadLeft(const char *DeviceName, int dwType, int dwFlags) { Map(m_DPadLeft, DeviceName, dwType, dwFlags); }
|
||||
void MapDPadRight(const char *DeviceName, int dwType, int dwFlags) { Map(m_DPadRight, DeviceName, dwType, dwFlags); }
|
||||
void MapBack(const char *DeviceName, int dwType, int dwFlags) { Map(m_Back, DeviceName, dwType, dwFlags); }
|
||||
void MapStart(const char *DeviceName, int dwType, int dwFlags) { Map(m_Start, DeviceName, dwType, dwFlags); }
|
||||
void MapLThumb(const char *DeviceName, int dwType, int dwFlags) { Map(m_LThumb, DeviceName, dwType, dwFlags); }
|
||||
void MapRThumb(const char *DeviceName, int dwType, int dwFlags) { Map(m_RThumb, DeviceName, dwType, dwFlags); }
|
||||
void MapLThumbX(const char *DeviceName, int dwInfo, int dwFlags) { Map(m_LThumbX, DeviceName, dwInfo, dwFlags); }
|
||||
void MapLThumbY(const char *DeviceName, int dwInfo, int dwFlags) { Map(m_LThumbY, DeviceName, dwInfo, dwFlags); }
|
||||
void MapRThumbX(const char *DeviceName, int dwInfo, int dwFlags) { Map(m_RThumbX, DeviceName, dwInfo, dwFlags); }
|
||||
void MapRThumbY(const char *DeviceName, int dwInfo, int dwFlags) { Map(m_RThumbY, DeviceName, dwInfo, dwFlags); }
|
||||
void MapX(const char *DeviceName, int dwInfo, int dwFlags) { Map(m_X, DeviceName, dwInfo, dwFlags); }
|
||||
void MapY(const char *DeviceName, int dwInfo, int dwFlags) { Map(m_Y, DeviceName, dwInfo, dwFlags); }
|
||||
void MapA(const char *DeviceName, int dwInfo, int dwFlags) { Map(m_A, DeviceName, dwInfo, dwFlags); }
|
||||
void MapB(const char *DeviceName, int dwInfo, int dwFlags) { Map(m_B, DeviceName, dwInfo, dwFlags); }
|
||||
void MapWhite(const char *DeviceName, int dwInfo, int dwFlags) { Map(m_White, DeviceName, dwInfo, dwFlags); }
|
||||
void MapBlack(const char *DeviceName, int dwInfo, int dwFlags) { Map(m_Black, DeviceName, dwInfo, dwFlags); }
|
||||
void MapLTrigger(const char *DeviceName, int dwInfo, int dwFlags) { Map(m_LTrigger, DeviceName, dwInfo, dwFlags); }
|
||||
void MapRTrigger(const char *DeviceName, int dwInfo, int dwFlags) { Map(m_RTrigger, DeviceName, dwInfo, dwFlags); }
|
||||
void MapDPadUp(const char *DeviceName, int dwInfo, int dwFlags) { Map(m_DPadUp, DeviceName, dwInfo, dwFlags); }
|
||||
void MapDPadDown(const char *DeviceName, int dwInfo, int dwFlags) { Map(m_DPadDown, DeviceName, dwInfo, dwFlags); }
|
||||
void MapDPadLeft(const char *DeviceName, int dwInfo, int dwFlags) { Map(m_DPadLeft, DeviceName, dwInfo, dwFlags); }
|
||||
void MapDPadRight(const char *DeviceName, int dwInfo, int dwFlags) { Map(m_DPadRight, DeviceName, dwInfo, dwFlags); }
|
||||
void MapBack(const char *DeviceName, int dwInfo, int dwFlags) { Map(m_Back, DeviceName, dwInfo, dwFlags); }
|
||||
void MapStart(const char *DeviceName, int dwInfo, int dwFlags) { Map(m_Start, DeviceName, dwInfo, dwFlags); }
|
||||
void MapLThumb(const char *DeviceName, int dwInfo, int dwFlags) { Map(m_LThumb, DeviceName, dwInfo, dwFlags); }
|
||||
void MapRThumb(const char *DeviceName, int dwInfo, int dwFlags) { Map(m_RThumb, DeviceName, dwInfo, dwFlags); }
|
||||
|
||||
private:
|
||||
// ******************************************************************
|
||||
// * Map a given input control mapping
|
||||
// ******************************************************************
|
||||
void Map(InputMapping &IM, const char *DeviceName, int dwType, int dwFlags);
|
||||
void Map(InputMapping &IM, const char *DeviceName, int dwInfo, int dwFlags);
|
||||
|
||||
// ******************************************************************
|
||||
// * Find the look-up value for a DeviceName (creates if needed)
|
||||
|
|
|
@ -40,12 +40,12 @@
|
|||
#include <stdio.h>
|
||||
|
||||
// ******************************************************************
|
||||
// * exported globals
|
||||
// * Exported Global(s)
|
||||
// ******************************************************************
|
||||
InputConfig g_InputConfig;
|
||||
|
||||
// ******************************************************************
|
||||
// * static functions
|
||||
// * Static Function(s)
|
||||
// ******************************************************************
|
||||
static INT_PTR CALLBACK DlgControllerConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
static BOOL CALLBACK EnumGameCtrlCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef);
|
||||
|
@ -53,18 +53,21 @@ static BOOL CALLBACK EnumObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LP
|
|||
static void ConfigureInput(HWND hWndDlg, HWND hWndButton, void (InputConfig::*MapFunc)(const char *, int, int));
|
||||
|
||||
// ******************************************************************
|
||||
// * static variables
|
||||
// * Static Variable(s)
|
||||
// ******************************************************************
|
||||
static LPDIRECTINPUT8 g_pDirectInput8 = NULL;
|
||||
static LPDIRECTINPUTDEVICE8 g_pInputDev[MAX_INPUT_DEVICES] = {0};
|
||||
static int g_pInputCur = 0;
|
||||
static bool g_bConfigDone = true;
|
||||
static LPDIRECTINPUT8 g_pDirectInput8 = NULL;
|
||||
static LPDIRECTINPUTDEVICE8 g_pInputDev[MAX_INPUT_DEVICES] = {0};
|
||||
static DWORD g_pInputDevFlags[MAX_INPUT_DEVICES] = {0};
|
||||
static int g_pInputCur = 0;
|
||||
static bool g_bConfigDone = true;
|
||||
|
||||
// ******************************************************************
|
||||
// * Show Controller configuration dialog window
|
||||
// * Show Controller Configuration Dialog Window
|
||||
// ******************************************************************
|
||||
void ShowControllerConfig(HWND hwnd)
|
||||
{
|
||||
g_EmuShared->RetrieveInputConfiguration(&g_InputConfig);
|
||||
|
||||
DialogBox
|
||||
(
|
||||
GetModuleHandle(NULL),
|
||||
|
@ -75,10 +78,10 @@ void ShowControllerConfig(HWND hwnd)
|
|||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Controller configuration dialog procedure
|
||||
// * Controller Configuration Dialog Procedure
|
||||
// ******************************************************************
|
||||
INT_PTR CALLBACK DlgControllerConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
{
|
||||
switch(uMsg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
|
@ -169,22 +172,23 @@ INT_PTR CALLBACK DlgControllerConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam,
|
|||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Enumerate all game controllers
|
||||
// * Enumerate Game Controller(s)
|
||||
// ******************************************************************
|
||||
BOOL CALLBACK EnumGameCtrlCallback(LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef)
|
||||
{
|
||||
HRESULT hRet = g_pDirectInput8->CreateDevice(lpddi->guidInstance, &g_pInputDev[g_pInputCur], NULL);
|
||||
|
||||
if(FAILED(hRet))
|
||||
return DIENUM_CONTINUE;
|
||||
|
||||
g_pInputDev[g_pInputCur++]->SetDataFormat(&c_dfDIJoystick);
|
||||
|
||||
if(!FAILED(hRet))
|
||||
{
|
||||
g_pInputDevFlags[g_pInputCur] = INPUT_MAPPING_JOYSTICK;
|
||||
g_pInputDev[g_pInputCur++]->SetDataFormat(&c_dfDIJoystick);
|
||||
}
|
||||
|
||||
return DIENUM_CONTINUE;
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Enumerate all game controller objects
|
||||
// * Enumerate Game Controller Object(s)
|
||||
// ******************************************************************
|
||||
BOOL CALLBACK EnumObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef)
|
||||
{
|
||||
|
@ -196,9 +200,9 @@ BOOL CALLBACK EnumObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef
|
|||
diprg.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
||||
diprg.diph.dwHow = DIPH_BYID;
|
||||
diprg.diph.dwObj = lpddoi->dwType;
|
||||
diprg.lMin = -32768;
|
||||
diprg.lMax = 32767;
|
||||
|
||||
diprg.lMin = 0 - 32768;
|
||||
diprg.lMax = 0 + 32767;
|
||||
|
||||
// set axis range
|
||||
HRESULT hRet = g_pInputDev[(int)pvRef]->SetProperty(DIPROP_RANGE, &diprg.diph);
|
||||
|
||||
|
@ -216,7 +220,7 @@ void ConfigureInput(HWND hWndDlg, HWND hWndButton, void (InputConfig::*MapFunc)(
|
|||
{
|
||||
if(!g_bConfigDone)
|
||||
return;
|
||||
|
||||
|
||||
g_bConfigDone = false;
|
||||
|
||||
char szOrgText[32];
|
||||
|
@ -240,27 +244,45 @@ void ConfigureInput(HWND hWndDlg, HWND hWndButton, void (InputConfig::*MapFunc)(
|
|||
);
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Enumerate Controller(s)
|
||||
// ******************************************************************
|
||||
// ******************************************************************
|
||||
// * Create all the devices available (well...most of them)
|
||||
// ******************************************************************
|
||||
if(g_pDirectInput8 != 0)
|
||||
{
|
||||
g_pDirectInput8->EnumDevices
|
||||
{
|
||||
HRESULT hRet;
|
||||
|
||||
hRet = g_pDirectInput8->EnumDevices
|
||||
(
|
||||
DI8DEVCLASS_GAMECTRL,
|
||||
EnumGameCtrlCallback,
|
||||
NULL,
|
||||
DIEDFL_ATTACHEDONLY
|
||||
);
|
||||
|
||||
hRet = g_pDirectInput8->CreateDevice(GUID_SysKeyboard, &g_pInputDev[g_pInputCur], NULL);
|
||||
|
||||
if(!FAILED(hRet))
|
||||
{
|
||||
g_pInputDevFlags[g_pInputCur] = INPUT_MAPPING_KEYBOARD;
|
||||
g_pInputDev[g_pInputCur++]->SetDataFormat(&c_dfDIKeyboard);
|
||||
}
|
||||
|
||||
hRet = g_pDirectInput8->CreateDevice(GUID_SysMouse, &g_pInputDev[g_pInputCur], NULL);
|
||||
|
||||
if(!FAILED(hRet))
|
||||
{
|
||||
g_pInputDevFlags[g_pInputCur] = INPUT_MAPPING_MOUSE;
|
||||
g_pInputDev[g_pInputCur++]->SetDataFormat(&c_dfDIMouse2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ******************************************************************
|
||||
// * Set cooperative level and acquire
|
||||
// ******************************************************************
|
||||
{
|
||||
for(int v=g_pInputCur-1;v>=0;v--)
|
||||
{
|
||||
g_pInputDev[v]->SetCooperativeLevel(hWndDlg, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
|
||||
g_pInputDev[v]->SetCooperativeLevel(hWndDlg, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
|
||||
g_pInputDev[v]->Acquire();
|
||||
|
||||
HRESULT hRet = g_pInputDev[v]->Poll();
|
||||
|
@ -290,23 +312,22 @@ void ConfigureInput(HWND hWndDlg, HWND hWndButton, void (InputConfig::*MapFunc)(
|
|||
// * Wait for input, or 5 second timeout
|
||||
// ******************************************************************
|
||||
{
|
||||
DIJOYSTATE tInputState = {0};
|
||||
DIDEVICEINSTANCE DeviceInstance;
|
||||
DIDEVICEOBJECTINSTANCE ObjectInstance;
|
||||
|
||||
DeviceInstance.dwSize = sizeof(DIDEVICEINSTANCE);
|
||||
ObjectInstance.dwSize = sizeof(DIDEVICEOBJECTINSTANCE);
|
||||
|
||||
for(int v=500;v>0 && !g_bConfigDone;v--)
|
||||
for(int v=100;v>0 && !g_bConfigDone;v--)
|
||||
{
|
||||
// ******************************************************************
|
||||
// * Update the button text every second
|
||||
// ******************************************************************
|
||||
if(v%100 == 0)
|
||||
if(v%20 == 0)
|
||||
{
|
||||
char szBuffer[255];
|
||||
|
||||
sprintf(szBuffer, "%d", (v+99)/100);
|
||||
sprintf(szBuffer, "%d", (v+19)/20);
|
||||
|
||||
SetWindowText(hWndButton, szBuffer);
|
||||
}
|
||||
|
@ -329,83 +350,143 @@ void ConfigureInput(HWND hWndDlg, HWND hWndButton, void (InputConfig::*MapFunc)(
|
|||
}
|
||||
|
||||
DWORD dwHow = -1;
|
||||
DWORD dwFlags = 0;
|
||||
DWORD dwFlags = g_pInputDevFlags[v];
|
||||
|
||||
g_pInputDev[v]->GetDeviceState(sizeof(DIJOYSTATE), &tInputState);
|
||||
|
||||
// ******************************************************************
|
||||
// * Determinate where (if anywhere) there was a state change
|
||||
// ******************************************************************
|
||||
// ******************************************************************
|
||||
// * Detect Joystick Input
|
||||
// ******************************************************************
|
||||
if(g_pInputDevFlags[v] & INPUT_MAPPING_JOYSTICK)
|
||||
{
|
||||
DIJOYSTATE InputState = {0};
|
||||
|
||||
g_pInputDev[v]->GetDeviceState(sizeof(DIJOYSTATE), &InputState);
|
||||
|
||||
int v=0;
|
||||
|
||||
if(abs(tInputState.lX) > JOYSTICK_DETECT_SENSITIVITY)
|
||||
if(abs(InputState.lX) > JOYSTICK_DETECT_SENSITIVITY)
|
||||
{
|
||||
dwHow = FIELD_OFFSET(DIJOYSTATE, lX);
|
||||
dwFlags = (tInputState.lX > 0) ? INPUT_MAPPING_AXIS_POSITIVE : INPUT_MAPPING_AXIS_NEGATIVE;
|
||||
dwFlags |= (InputState.lX > 0) ? INPUT_MAPPING_AXIS_POSITIVE : INPUT_MAPPING_AXIS_NEGATIVE;
|
||||
}
|
||||
else if(abs(tInputState.lY) > JOYSTICK_DETECT_SENSITIVITY)
|
||||
else if(abs(InputState.lY) > JOYSTICK_DETECT_SENSITIVITY)
|
||||
{
|
||||
dwHow = FIELD_OFFSET(DIJOYSTATE, lY);
|
||||
dwFlags = (tInputState.lY > 0) ? INPUT_MAPPING_AXIS_POSITIVE : INPUT_MAPPING_AXIS_NEGATIVE;
|
||||
dwFlags |= (InputState.lY > 0) ? INPUT_MAPPING_AXIS_POSITIVE : INPUT_MAPPING_AXIS_NEGATIVE;
|
||||
}
|
||||
else if(abs(tInputState.lZ) > JOYSTICK_DETECT_SENSITIVITY)
|
||||
else if(abs(InputState.lZ) > JOYSTICK_DETECT_SENSITIVITY)
|
||||
{
|
||||
dwHow = FIELD_OFFSET(DIJOYSTATE, lZ);
|
||||
dwFlags = (tInputState.lZ > 0) ? INPUT_MAPPING_AXIS_POSITIVE : INPUT_MAPPING_AXIS_NEGATIVE;
|
||||
dwFlags |= (InputState.lZ > 0) ? INPUT_MAPPING_AXIS_POSITIVE : INPUT_MAPPING_AXIS_NEGATIVE;
|
||||
}
|
||||
else if(abs(tInputState.lRx) > JOYSTICK_DETECT_SENSITIVITY)
|
||||
else if(abs(InputState.lRx) > JOYSTICK_DETECT_SENSITIVITY)
|
||||
{
|
||||
dwHow = FIELD_OFFSET(DIJOYSTATE, lRx);
|
||||
dwFlags = (tInputState.lRx > 0) ? INPUT_MAPPING_AXIS_POSITIVE : INPUT_MAPPING_AXIS_NEGATIVE;
|
||||
dwFlags |= (InputState.lRx > 0) ? INPUT_MAPPING_AXIS_POSITIVE : INPUT_MAPPING_AXIS_NEGATIVE;
|
||||
}
|
||||
else if(abs(tInputState.lRy) > JOYSTICK_DETECT_SENSITIVITY)
|
||||
else if(abs(InputState.lRy) > JOYSTICK_DETECT_SENSITIVITY)
|
||||
{
|
||||
dwHow = FIELD_OFFSET(DIJOYSTATE, lRy);
|
||||
dwFlags = (tInputState.lRy > 0) ? INPUT_MAPPING_AXIS_POSITIVE : INPUT_MAPPING_AXIS_NEGATIVE;
|
||||
dwFlags |= (InputState.lRy > 0) ? INPUT_MAPPING_AXIS_POSITIVE : INPUT_MAPPING_AXIS_NEGATIVE;
|
||||
}
|
||||
else if(abs(tInputState.lRz) > JOYSTICK_DETECT_SENSITIVITY)
|
||||
else if(abs(InputState.lRz) > JOYSTICK_DETECT_SENSITIVITY)
|
||||
{
|
||||
dwHow = FIELD_OFFSET(DIJOYSTATE, lRz);
|
||||
dwFlags = (tInputState.lRz > 0) ? INPUT_MAPPING_AXIS_POSITIVE : INPUT_MAPPING_AXIS_NEGATIVE;
|
||||
dwFlags |= (InputState.lRz > 0) ? INPUT_MAPPING_AXIS_POSITIVE : INPUT_MAPPING_AXIS_NEGATIVE;
|
||||
}
|
||||
else for(v=0;v<2;v++)
|
||||
if(abs(tInputState.rglSlider[v]) > JOYSTICK_DETECT_SENSITIVITY)
|
||||
if(abs(InputState.rglSlider[v]) > JOYSTICK_DETECT_SENSITIVITY)
|
||||
dwHow = FIELD_OFFSET(DIJOYSTATE, rglSlider[v]);
|
||||
else for(v=0;v<4;v++)
|
||||
if(abs(tInputState.rgdwPOV[v]) > POV_DETECT_SENSITIVITY)
|
||||
if(abs(InputState.rgdwPOV[v]) > POV_DETECT_SENSITIVITY)
|
||||
dwHow = FIELD_OFFSET(DIJOYSTATE, rgdwPOV[v]);
|
||||
else for(v=0;v<32;v++)
|
||||
if(tInputState.rgbButtons[v] > BUTTON_DETECT_SENSITIVITY)
|
||||
if(InputState.rgbButtons[v] > BUTTON_DETECT_SENSITIVITY)
|
||||
dwHow = FIELD_OFFSET(DIJOYSTATE, rgbButtons[v]);
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Retrieve Object Info
|
||||
// ******************************************************************
|
||||
if(dwHow != -1)
|
||||
{
|
||||
g_pInputDev[v]->GetDeviceInfo(&DeviceInstance);
|
||||
|
||||
g_pInputDev[v]->GetObjectInfo(&ObjectInstance, dwHow, DIPH_BYOFFSET);
|
||||
|
||||
(g_InputConfig.*MapFunc)(DeviceInstance.tszInstanceName, ObjectInstance.dwType, dwFlags);
|
||||
|
||||
printf("Cxbx: Detected %s on %s (dwType : %.08X)\n", ObjectInstance.tszName, DeviceInstance.tszInstanceName, ObjectInstance.dwType);
|
||||
|
||||
sprintf(szNewText, "%s Successfully Mapped To %s On %s!", szOrgText, ObjectInstance.tszName, DeviceInstance.tszInstanceName);
|
||||
|
||||
g_bConfigDone = true;
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Retrieve Object Info
|
||||
// ******************************************************************
|
||||
if(dwHow != -1)
|
||||
{
|
||||
g_pInputDev[v]->GetDeviceInfo(&DeviceInstance);
|
||||
|
||||
g_pInputDev[v]->GetObjectInfo(&ObjectInstance, dwHow, DIPH_BYOFFSET);
|
||||
|
||||
(g_InputConfig.*MapFunc)(DeviceInstance.tszInstanceName, ObjectInstance.dwType, dwFlags);
|
||||
|
||||
printf("Cxbx: Detected %s on %s (dwType : %.08X)\n", ObjectInstance.tszName, DeviceInstance.tszInstanceName, ObjectInstance.dwType);
|
||||
|
||||
sprintf(szNewText, "%s Successfully Mapped To %s On %s!", szOrgText, ObjectInstance.tszName, DeviceInstance.tszInstanceName);
|
||||
}
|
||||
|
||||
}
|
||||
// ******************************************************************
|
||||
// * Detect Keyboard Input
|
||||
// ******************************************************************
|
||||
else if(g_pInputDevFlags[v] & INPUT_MAPPING_KEYBOARD)
|
||||
{
|
||||
BYTE InputState[256];
|
||||
|
||||
g_pInputDev[v]->GetDeviceState(256, InputState);
|
||||
|
||||
for(int v=0;v<256;v++)
|
||||
{
|
||||
if(InputState[v] != 0)
|
||||
{
|
||||
dwHow = v;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(dwHow != -1)
|
||||
{
|
||||
(g_InputConfig.*MapFunc)("SysKeyboard", dwHow, dwFlags);
|
||||
|
||||
printf("Cxbx: Detected Key %d on SysKeyboard\n", dwHow);
|
||||
|
||||
sprintf(szNewText, "%s Successfully Mapped To Key %d On %s!", szOrgText, dwHow, "SysKeyboard");
|
||||
}
|
||||
}
|
||||
// ******************************************************************
|
||||
// * Detect Mouse Input
|
||||
// ******************************************************************
|
||||
else if(g_pInputDevFlags[v] & INPUT_MAPPING_MOUSE)
|
||||
{
|
||||
DIMOUSESTATE2 InputState = {0};
|
||||
|
||||
g_pInputDev[v]->GetDeviceState(sizeof(DIMOUSESTATE2), &InputState);
|
||||
|
||||
for(int v=0;v<8;v++)
|
||||
{
|
||||
if(InputState.rgbButtons[v] & 0x80)
|
||||
{
|
||||
dwHow = v;
|
||||
dwFlags &= INPUT_MAPPING_MOUSE_CLICK;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(dwHow != -1)
|
||||
{
|
||||
(g_InputConfig.*MapFunc)("SysMouse", dwHow, dwFlags);
|
||||
|
||||
printf("Cxbx: Detected Button %d on SysMouse\n", dwHow);
|
||||
|
||||
sprintf(szNewText, "%s Successfully Mapped To Button %d On %s!", szOrgText, dwHow, "SysMouse");
|
||||
}
|
||||
}
|
||||
|
||||
if(dwHow != -1)
|
||||
g_bConfigDone = true;
|
||||
}
|
||||
|
||||
Sleep(20);
|
||||
Sleep(50);
|
||||
}
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Cleanup devices
|
||||
// ******************************************************************
|
||||
// ******************************************************************
|
||||
// * Cleanup Devices
|
||||
// ******************************************************************
|
||||
{
|
||||
for(int v=g_pInputCur-1;v>=0;v--)
|
||||
{
|
||||
|
@ -422,10 +503,20 @@ void ConfigureInput(HWND hWndDlg, HWND hWndButton, void (InputConfig::*MapFunc)(
|
|||
g_pDirectInput8 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
SetWindowText(hWndButton, szOrgText);
|
||||
|
||||
SetWindowText(GetDlgItem(hWndDlg, IDC_CONFIG_STATUS), szNewText);
|
||||
|
||||
// ******************************************************************
|
||||
// * Update Window
|
||||
// ******************************************************************
|
||||
{
|
||||
SetWindowText(hWndButton, szOrgText);
|
||||
|
||||
SetWindowText(GetDlgItem(hWndDlg, IDC_CONFIG_STATUS), szNewText);
|
||||
|
||||
MSG Msg;
|
||||
|
||||
while(PeekMessage(&Msg, hWndDlg, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE));
|
||||
while(PeekMessage(&Msg, hWndDlg, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE));
|
||||
}
|
||||
|
||||
g_bConfigDone = true;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
// ******************************************************************
|
||||
#include "InputConfig.h"
|
||||
|
||||
#undef FIELD_OFFSET // prevent macro redefinition warnings
|
||||
#include <windows.h>
|
||||
#include <string.h>
|
||||
|
||||
|
@ -46,24 +45,18 @@ InputConfig::InputConfig()
|
|||
m_DeviceName[v][0] = '\0';
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Deconstructor
|
||||
// ******************************************************************
|
||||
InputConfig::~InputConfig()
|
||||
{
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
// * Map a given input control mapping
|
||||
// ******************************************************************
|
||||
void InputConfig::Map(InputMapping &IM, const char *DeviceName, int dwType, int dwFlags)
|
||||
void InputConfig::Map(InputMapping &IM, const char *DeviceName, int dwInfo, int dwFlags)
|
||||
{
|
||||
// initialize IM
|
||||
// Initialize InputMapping instance
|
||||
IM.dwDevice = Insert(DeviceName);
|
||||
IM.dwType = dwType;
|
||||
IM.dwInfo = dwInfo;
|
||||
IM.dwFlags = dwFlags;
|
||||
|
||||
// purge unused slots
|
||||
// Purse unused device slots
|
||||
// TODO: Make this more efficient (the current check technique is ridiculous)
|
||||
for(int v=0;v<MAX_INPUT_DEVICES;v++)
|
||||
{
|
||||
if(m_LThumbX.dwDevice != v && m_LThumbY.dwDevice != v &&
|
||||
|
@ -90,6 +83,7 @@ void InputConfig::Map(InputMapping &IM, const char *DeviceName, int dwType, int
|
|||
int InputConfig::Insert(const char *DeviceName)
|
||||
{
|
||||
int v=0;
|
||||
|
||||
for(v=0;v<MAX_INPUT_DEVICES;v++)
|
||||
if(m_DeviceName[v][0] != '\0' && strcmp(DeviceName, m_DeviceName[v]) == 0)
|
||||
return v;
|
||||
|
|
Loading…
Reference in New Issue