From fc944144e36b7bc9e0644504a5b6d87c99dcf8f1 Mon Sep 17 00:00:00 2001 From: Lucas Zawacki Date: Mon, 13 Aug 2012 20:36:54 -0300 Subject: [PATCH] joy.cpl: Correct misplaced elements when using high DPIs. --- dlls/joy.cpl/joy.h | 49 ++++++++++++++++--------------- dlls/joy.cpl/main.c | 71 ++++++++++++++++++++++++++++++++------------- 2 files changed, 76 insertions(+), 44 deletions(-) diff --git a/dlls/joy.cpl/joy.h b/dlls/joy.cpl/joy.h index e40a71bc17f..16d7a0beb98 100644 --- a/dlls/joy.cpl/joy.h +++ b/dlls/joy.cpl/joy.h @@ -50,6 +50,13 @@ struct Joystick { #define TEST_MAX_BUTTONS 32 #define TEST_MAX_AXES 4 +struct Graphics { + HWND hwnd; + HWND buttons[TEST_MAX_BUTTONS]; + HWND axes[TEST_MAX_AXES]; + HWND ff_axis; +}; + struct JoystickData { IDirectInput8W *di; struct Joystick *joysticks; @@ -57,9 +64,7 @@ struct JoystickData { int num_ff; int cur_joystick; int chosen_joystick; - HWND buttons[TEST_MAX_BUTTONS]; - HWND axes[TEST_MAX_AXES]; - HWND ff_axis; + struct Graphics graphics; BOOL stop; }; @@ -86,36 +91,32 @@ struct JoystickData { #define IDC_TESTGROUPZRZ 2007 #define IDC_TESTGROUPPOV 2008 -#define IDC_JOYSTICKBUTTON 3000 -#define IDC_JOYSTICKAXES 4000 - #define IDC_FFSELECTCOMBO 2009 #define IDC_FFEFFECTLIST 2010 -#define IDC_FFAXIS 2011 /* 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 40 -#define TEST_BUTTON_SIZE_X 30 -#define TEST_BUTTON_SIZE_Y 25 +#define TEST_BUTTON_X 8 +#define TEST_BUTTON_Y 122 +#define TEST_NEXT_BUTTON_X 30 +#define TEST_NEXT_BUTTON_Y 25 +#define TEST_BUTTON_SIZE_X 20 +#define TEST_BUTTON_SIZE_Y 18 -#define TEST_AXIS_X 65 -#define TEST_AXIS_Y 98 -#define TEST_NEXT_AXIS_X 115 -#define TEST_AXIS_SIZE_X 5 -#define TEST_AXIS_SIZE_Y 5 -#define TEST_AXIS_MIN -40 -#define TEST_AXIS_MAX 40 +#define TEST_AXIS_X 43 +#define TEST_AXIS_Y 60 +#define TEST_NEXT_AXIS_X 77 +#define TEST_AXIS_SIZE_X 3 +#define TEST_AXIS_SIZE_Y 3 +#define TEST_AXIS_MIN -25 +#define TEST_AXIS_MAX 25 -#define FF_AXIS_X 373 -#define FF_AXIS_Y 98 -#define FF_AXIS_SIZE_X 5 -#define FF_AXIS_SIZE_Y 5 +#define FF_AXIS_X 248 +#define FF_AXIS_Y 60 +#define FF_AXIS_SIZE_X 3 +#define FF_AXIS_SIZE_Y 3 #define FF_PLAY_TIME 2*DI_SECONDS #define FF_PERIOD_TIME FF_PLAY_TIME/4 diff --git a/dlls/joy.cpl/main.c b/dlls/joy.cpl/main.c index 54771b01db9..354dfd753c5 100644 --- a/dlls/joy.cpl/main.c +++ b/dlls/joy.cpl/main.c @@ -166,6 +166,9 @@ static INT_PTR CALLBACK list_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM SendDlgItemMessageW(hwnd, IDC_JOYSTICKLIST, LB_ADDSTRING, 0, (LPARAM) joy->instance.tszInstanceName); } + /* Store the hwnd to be used with MapDialogRect for unit conversions */ + data->graphics.hwnd = hwnd; + return TRUE; } @@ -260,7 +263,7 @@ static DWORD WINAPI input_thread(void *param) /* 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); + SendMessageW(data->graphics.buttons[i], BM_SETSTATE, TRUE, 0); /* Indicate axis positions, axes showing are hardcoded for now */ axes_pos[0][0] = state.lX; @@ -281,16 +284,21 @@ static DWORD WINAPI input_thread(void *param) } for (i = 0; i < TEST_MAX_AXES; i++) - SetWindowPos(data->axes[i], 0, - TEST_AXIS_X + TEST_NEXT_AXIS_X*i + axes_pos[i][0], - TEST_AXIS_Y + axes_pos[i][1], - 0, 0, SWP_NOZORDER | SWP_NOSIZE); + { + RECT r; + + r.left = (TEST_AXIS_X + TEST_NEXT_AXIS_X*i + axes_pos[i][0]); + r.top = (TEST_AXIS_Y + axes_pos[i][1]); + MapDialogRect(data->graphics.hwnd, &r); + + SetWindowPos(data->graphics.axes[i], 0, r.left, r.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE); + } 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); + SendMessageW(data->graphics.buttons[i], BM_SETSTATE, FALSE, 0); } return 0; @@ -306,7 +314,7 @@ static void test_handle_joychange(HWND hwnd, struct JoystickData *data) /* 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); + ShowWindow(data->graphics.buttons[i], i <= data->joysticks[data->chosen_joystick].num_buttons); } /********************************************************************* @@ -331,17 +339,24 @@ static void draw_joystick_buttons(HWND hwnd, struct JoystickData* data) for (i = 0; i < TEST_MAX_BUTTONS; i++) { + RECT r; + if ((i % TEST_BUTTON_COL_MAX) == 0 && i != 0) { row += 1; col = 0; } + r.left = (TEST_BUTTON_X + TEST_NEXT_BUTTON_X*col); + r.top = (TEST_BUTTON_Y + TEST_NEXT_BUTTON_Y*row); + r.right = r.left + TEST_BUTTON_SIZE_X; + r.bottom = r.top + TEST_BUTTON_SIZE_Y; + MapDialogRect(hwnd, &r); + 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, + data->graphics.buttons[i] = CreateWindowW(button_class, button_label, WS_CHILD, + r.left, r.top, r.right - r.left, r.bottom - r.top, hwnd, NULL, NULL, hinst); col += 1; @@ -360,13 +375,19 @@ static void draw_joystick_axes(HWND hwnd, struct JoystickData* data) for (i = 0; i < TEST_MAX_AXES; i++) { + RECT r; /* Set axis box name */ SetWindowTextW(GetDlgItem(hwnd, axes_idc[i]), axes_names[i]); - data->axes[i] = CreateWindowW( button_class, NULL, WS_CHILD | WS_VISIBLE, - TEST_AXIS_X + TEST_NEXT_AXIS_X*i, TEST_AXIS_Y, - TEST_AXIS_SIZE_X, TEST_AXIS_SIZE_Y, - hwnd, (HMENU) IDC_JOYSTICKAXES + i, NULL, hinst); + r.left = (TEST_AXIS_X + TEST_NEXT_AXIS_X*i); + r.top = TEST_AXIS_Y; + r.right = r.left + TEST_AXIS_SIZE_X; + r.bottom = r.top + TEST_AXIS_SIZE_Y; + MapDialogRect(hwnd, &r); + + data->graphics.axes[i] = CreateWindowW( button_class, NULL, WS_CHILD | WS_VISIBLE, + r.left, r.top, r.right - r.left, r.bottom - r.top, + hwnd, NULL, NULL, hinst); } } @@ -452,12 +473,18 @@ static void draw_ff_axis(HWND hwnd, struct JoystickData *data) { HINSTANCE hinst = (HINSTANCE) GetWindowLongPtrW(hwnd, GWLP_HINSTANCE); static WCHAR button_class[] = {'B','u','t','t','o','n','\0'}; + RECT r; + + r.left = FF_AXIS_X; + r.top = FF_AXIS_Y; + r.right = r.left + FF_AXIS_SIZE_X; + r.bottom = r.top + FF_AXIS_SIZE_Y; + MapDialogRect(hwnd, &r); /* Draw direction axis */ - data->ff_axis = CreateWindowW( button_class, NULL, WS_CHILD | WS_VISIBLE, - FF_AXIS_X, FF_AXIS_Y, - FF_AXIS_SIZE_X, FF_AXIS_SIZE_Y, - hwnd, (HMENU) IDC_FFAXIS, NULL, hinst); + data->graphics.ff_axis = CreateWindowW( button_class, NULL, WS_CHILD | WS_VISIBLE, + r.left, r.top, r.right - r.left, r.bottom - r.top, + hwnd, NULL, NULL, hinst); } static void initialize_effects_list(HWND hwnd, struct Joystick* joy) @@ -508,6 +535,7 @@ static DWORD WINAPI ff_input_thread(void *param) int chosen_effect = joy->chosen_effect; DIEFFECT *dieffect; DWORD flags = DIEP_AXES | DIEP_DIRECTION | DIEP_NORESTART; + RECT r; /* Skip this if we have no effects */ if (joy->num_effects == 0 || chosen_effect < 0) continue; @@ -519,8 +547,11 @@ static DWORD WINAPI ff_input_thread(void *param) dieffect->rgdwAxes[0] = state.lX; dieffect->rgdwAxes[1] = state.lY; - SetWindowPos(data->ff_axis, 0, FF_AXIS_X + state.lX, FF_AXIS_Y + state.lY, - 0, 0, SWP_NOZORDER | SWP_NOSIZE); + r.left = FF_AXIS_X + state.lX; + r.top = FF_AXIS_Y + state.lY; + MapDialogRect(data->graphics.hwnd, &r); + + SetWindowPos(data->graphics.ff_axis, 0, r.left, r.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE); for (i=0; i < joy->num_buttons; i++) if (state.rgbButtons[i])