joy.cpl: Added joystick testing tab and button tests.

This commit is contained in:
Lucas Zawacki 2012-06-07 14:44:12 -03:00 committed by Alexandre Julliard
parent d3f7247ea5
commit fd951a7ec2
48 changed files with 425 additions and 46 deletions

View File

@ -36,12 +36,16 @@ struct Joystick {
int num_axes;
};
#define TEST_MAX_BUTTONS 32
struct JoystickData {
IDirectInput8W *di;
struct Joystick *joysticks;
int num_joysticks;
int cur_joystick;
int chosen_joystick;
HWND buttons[TEST_MAX_BUTTONS];
BOOL stop;
};
#define NUM_PROPERTY_PAGES 3
@ -61,5 +65,19 @@ struct JoystickData {
#define IDC_BUTTONDISABLE 2001
#define IDC_BUTTONENABLE 2002
#define IDC_DISABLEDLIST 2003
#define IDC_TESTSELECTCOMBO 2004
#define IDC_JOYSTICKBUTTON 3000
/* constants */
#define TEST_POLL_TIME 100
#define TEST_BUTTON_COL_MAX 8
#define TEST_BUTTON_X 15
#define TEST_BUTTON_Y 200
#define TEST_NEXT_BUTTON_X 45
#define TEST_NEXT_BUTTON_Y 30
#define TEST_BUTTON_SIZE_X 30
#define TEST_BUTTON_SIZE_Y 25
#endif

View File

@ -46,6 +46,8 @@ STYLE WS_CAPTION | WS_CHILD | WS_DISABLED
CAPTION "Test Joystick"
FONT 8, "Ms Shell Dlg"
{
COMBOBOX IDC_TESTSELECTCOMBO, 5, 5, 100, 30, CBS_DROPDOWNLIST | CBS_HASSTRINGS
GROUPBOX "Buttons", IDC_STATIC, 0, 110, 250, 90
}
IDD_FORCEFEEDBACK DIALOG 0, 0, 250, 200

View File

@ -67,6 +67,7 @@ static BOOL CALLBACK enum_callback(const DIDEVICEINSTANCEW *instance, void *cont
{
struct JoystickData *data = context;
struct Joystick *joystick;
DIDEVCAPS caps;
if (data->joysticks == NULL)
{
@ -82,6 +83,12 @@ static BOOL CALLBACK enum_callback(const DIDEVICEINSTANCEW *instance, void *cont
joystick->instance = *instance;
caps.dwSize = sizeof(caps);
IDirectInputDevice8_GetCapabilities(joystick->device, &caps);
joystick->num_buttons = caps.dwButtons;
joystick->num_axes = caps.dwAxes;
return DIENUM_CONTINUE;
}
@ -163,6 +170,178 @@ INT_PTR CALLBACK list_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
return FALSE;
}
/*********************************************************************
* Joystick testing functions
*
*/
static void poll_input(const struct Joystick *joy, DIJOYSTATE *state)
{
HRESULT hr;
hr = IDirectInputDevice8_Poll(joy->device);
/* If it failed, try to acquire the joystick */
if (FAILED(hr))
{
hr = IDirectInputDevice8_Acquire(joy->device);
while (hr == DIERR_INPUTLOST) hr = IDirectInputDevice8_Acquire(joy->device);
}
if (hr == DIERR_OTHERAPPHASPRIO) return;
IDirectInputDevice8_GetDeviceState(joy->device, sizeof(DIJOYSTATE), state);
}
static DWORD WINAPI input_thread(void *param)
{
DIJOYSTATE state;
struct JoystickData *data = param;
ZeroMemory(&state, sizeof(state));
while (!data->stop)
{
int i;
poll_input(&data->joysticks[data->chosen_joystick], &state);
/* Indicate pressed buttons */
for (i = 0; i < data->joysticks[data->chosen_joystick].num_buttons; i++)
if (state.rgbButtons[i])
SendMessageW(data->buttons[i], BM_SETSTATE, TRUE, 0);
Sleep(TEST_POLL_TIME);
/* Reset button state */
for (i = 0; i < data->joysticks[data->chosen_joystick].num_buttons; i++)
SendMessageW(data->buttons[i], BM_SETSTATE, FALSE, 0);
}
return 0;
}
static void test_handle_joychange(HWND hwnd, struct JoystickData *data)
{
int i;
if (data->num_joysticks == 0) return;
data->chosen_joystick = SendDlgItemMessageW(hwnd, IDC_TESTSELECTCOMBO, CB_GETCURSEL, 0, 0);
/* Enable only buttons present in the device */
for (i = 0; i < TEST_MAX_BUTTONS; i++)
ShowWindow(data->buttons[i], i <= data->joysticks[data->chosen_joystick].num_buttons);
}
/*********************************************************************
* button_number_to_wchar [internal]
* Transforms an integer in the interval [0,99] into a 2 character WCHAR string
*/
static void button_number_to_wchar(int n, WCHAR str[3])
{
str[1] = n % 10 + '0';
n /= 10;
str[0] = n % 10 + '0';
str[2] = '\0';
}
static void draw_joystick_buttons(HWND hwnd, struct JoystickData* data)
{
int i;
int row = 0, col = 0;
WCHAR button_label[3];
HINSTANCE hinst = (HINSTANCE) GetWindowLongPtrW(hwnd, GWLP_HINSTANCE);
static WCHAR button_class[] = {'B','u','t','t','o','n','\0'};
for (i = 0; i < TEST_MAX_BUTTONS; i++)
{
if ((i % TEST_BUTTON_COL_MAX) == 0 && i != 0)
{
row += 1;
col = 0;
}
button_number_to_wchar(i + 1, button_label);
data->buttons[i] = CreateWindowW(button_class, button_label, WS_CHILD,
TEST_BUTTON_X + TEST_NEXT_BUTTON_X*col, TEST_BUTTON_Y + TEST_NEXT_BUTTON_Y*row,
TEST_BUTTON_SIZE_X, TEST_BUTTON_SIZE_Y,
hwnd, NULL, NULL, hinst);
col += 1;
}
}
/*********************************************************************
* test_dlgproc [internal]
*
*/
static INT_PTR CALLBACK test_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
static HANDLE thread;
static struct JoystickData *data;
TRACE("(%p, 0x%08x/%d, 0x%lx)\n", hwnd, msg, msg, lparam);
switch (msg)
{
case WM_INITDIALOG:
{
int i;
data = (struct JoystickData*) ((PROPSHEETPAGEW*)lparam)->lParam;
/* Add enumerated joysticks to the combobox */
for (i = 0; i < data->num_joysticks; i++)
{
struct Joystick *joy = &data->joysticks[i];
SendDlgItemMessageW(hwnd, IDC_TESTSELECTCOMBO, CB_ADDSTRING, 0, (LPARAM) joy->instance.tszInstanceName);
}
draw_joystick_buttons(hwnd, data);
return TRUE;
}
case WM_COMMAND:
switch(wparam)
{
case MAKEWPARAM(IDC_TESTSELECTCOMBO, CBN_SELCHANGE):
test_handle_joychange(hwnd, data);
break;
}
return TRUE;
case WM_NOTIFY:
switch(((LPNMHDR)lparam)->code)
{
case PSN_SETACTIVE:
{
DWORD tid;
/* Initialize input thread */
if (data->num_joysticks > 0)
{
data->stop = FALSE;
/* Set the first joystick as default */
SendDlgItemMessageW(hwnd, IDC_TESTSELECTCOMBO, CB_SETCURSEL, 0, 0);
test_handle_joychange(hwnd, data);
thread = CreateThread(NULL, 0, input_thread, (void*) data, 0, &tid);
}
}
break;
case PSN_RESET:
/* Stop input thread */
data->stop = TRUE;
CloseHandle(thread);
break;
}
return TRUE;
}
return FALSE;
}
/******************************************************************************
* propsheet_callback [internal]
*/
@ -210,7 +389,7 @@ static void display_cpl_sheets(HWND parent, struct JoystickData *data)
psp[id].dwSize = sizeof (PROPSHEETPAGEW);
psp[id].hInstance = hcpl;
psp[id].u.pszTemplate = MAKEINTRESOURCEW(IDD_TEST);
psp[id].pfnDlgProc = NULL;
psp[id].pfnDlgProc = test_dlgproc;
psp[id].lParam = (INT_PTR) data;
id++;

View File

@ -3420,7 +3420,11 @@ msgstr ""
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3446,7 +3446,11 @@ msgstr "&Забрани"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3490,7 +3490,11 @@ msgstr "&Deshabilitada"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3494,7 +3494,11 @@ msgstr "&Zakázat"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3466,7 +3466,11 @@ msgstr "&Deaktiver"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3453,7 +3453,11 @@ msgstr "Ausgeschaltet"
msgid "Test Joystick"
msgstr "Joystick testen"
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr "Force Feedback testen"

View File

@ -3380,7 +3380,11 @@ msgstr ""
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3444,7 +3444,11 @@ msgstr "Disabled"
msgid "Test Joystick"
msgstr "Test Joystick"
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr "Buttons"
#: joy.rc:55
msgid "Test Force Feedback"
msgstr "Test Force Feedback"

View File

@ -3446,7 +3446,11 @@ msgstr "Disabled"
msgid "Test Joystick"
msgstr "Test Joystick"
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr "Buttons"
#: joy.rc:55
msgid "Test Force Feedback"
msgstr "Test Force Feedback"

View File

@ -3356,7 +3356,11 @@ msgstr "&Malaktivigi"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3480,7 +3480,11 @@ msgstr "&Deshabilitar"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3420,7 +3420,11 @@ msgstr ""
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3441,7 +3441,11 @@ msgstr "Ei käytössä"
msgid "Test Joystick"
msgstr "Testaa joystickia"
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr "Testaa voimapalautetta"

View File

@ -3476,7 +3476,11 @@ msgstr "&désactivé"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3443,7 +3443,11 @@ msgstr "Table"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3358,7 +3358,11 @@ msgstr ""
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3482,7 +3482,11 @@ msgstr "Tiltá&s"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3490,7 +3490,11 @@ msgstr "&Disabilita"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3438,7 +3438,11 @@ msgstr "無効"
msgid "Test Joystick"
msgstr "ジョイスティックのテスト"
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr "フォース フィードバックのテスト"

View File

@ -3442,7 +3442,11 @@ msgstr "사용하지 않음(&D)"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3460,7 +3460,11 @@ msgstr "&Išjungti"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3358,7 +3358,11 @@ msgstr ""
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3615,7 +3615,11 @@ msgstr "&Deaktiver"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3507,7 +3507,11 @@ msgstr "&Uitzetten"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3358,7 +3358,11 @@ msgstr ""
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3358,7 +3358,11 @@ msgstr ""
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3484,7 +3484,11 @@ msgstr "&Wyłącz bibliotekę"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3488,7 +3488,11 @@ msgstr "&Desativar"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3487,7 +3487,11 @@ msgstr "&Desactivar"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3386,7 +3386,11 @@ msgstr ""
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3447,7 +3447,11 @@ msgstr "&Dezactivează"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3459,7 +3459,11 @@ msgstr "&Блокировать загрузку"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3389,7 +3389,11 @@ msgstr "&Zakázať"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3479,7 +3479,11 @@ msgstr "&Onemogoči"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3477,7 +3477,11 @@ msgstr "табела"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3555,7 +3555,11 @@ msgstr "&Isključi"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3436,7 +3436,11 @@ msgstr "Inaktiverad"
msgid "Test Joystick"
msgstr "Testa joysticken"
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr "Testa kraftåterkoppling"

View File

@ -3358,7 +3358,11 @@ msgstr ""
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3397,7 +3397,11 @@ msgstr ""
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3351,7 +3351,11 @@ msgstr "&Etkisizleştir"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3473,7 +3473,11 @@ msgstr "Вим&кнути"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3405,7 +3405,11 @@ msgstr ""
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3320,7 +3320,11 @@ msgstr ""
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3366,7 +3366,11 @@ msgstr "停用(&D)"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""

View File

@ -3370,7 +3370,11 @@ msgstr "停用(&D)"
msgid "Test Joystick"
msgstr ""
#: joy.rc:53
#: joy.rc:50
msgid "Buttons"
msgstr ""
#: joy.rc:55
msgid "Test Force Feedback"
msgstr ""