joy.cpl: Corrected misplaced elements when using high DPIs

Lucas Zawacki lfzawacki at gmail.com
Wed Aug 1 15:39:44 CDT 2012


From: Lucas Zawacki <lfzawacki at gmail.com>

Fixes bug #31316

joy.cpl uses CreateWindow and SetWindowPos to draw some elements
and the hardcoded coordinates where wrong when the dpi was set to anything
bigger than 96px in winecfg. My approach to solve is normalize the
coordinates based on the dialog window size.
---
 dlls/joy.cpl/joy.h  |   16 +++++++++++++---
 dlls/joy.cpl/main.c |   45 +++++++++++++++++++++++++++++----------------
 2 files changed, 42 insertions(+), 19 deletions(-)

diff --git a/dlls/joy.cpl/joy.h b/dlls/joy.cpl/joy.h
index e40a71b..79489f1 100644
--- a/dlls/joy.cpl/joy.h
+++ b/dlls/joy.cpl/joy.h
@@ -50,6 +50,15 @@ 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;
+    float dpi_x;
+    float dpi_y;
+};
+
 struct JoystickData {
     IDirectInput8W *di;
     struct Joystick *joysticks;
@@ -57,9 +66,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;
 };
 
@@ -94,6 +101,9 @@ struct JoystickData {
 #define IDC_FFAXIS          2011
 
 /* constants */
+#define DIALOG_BOX_WIDTH    480
+#define DIALOG_BOX_HEIGHT   358
+
 #define TEST_POLL_TIME      100
 
 #define TEST_BUTTON_COL_MAX 8
diff --git a/dlls/joy.cpl/main.c b/dlls/joy.cpl/main.c
index 54771b0..494d13d 100644
--- a/dlls/joy.cpl/main.c
+++ b/dlls/joy.cpl/main.c
@@ -157,6 +157,7 @@ static INT_PTR CALLBACK list_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM
         case WM_INITDIALOG:
         {
             int i;
+            RECT view;
             struct JoystickData *data = (struct JoystickData*) ((PROPSHEETPAGEW*)lparam)->lParam;
 
             /* Set dialog information */
@@ -166,6 +167,11 @@ static INT_PTR CALLBACK list_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM
                 SendDlgItemMessageW(hwnd, IDC_JOYSTICKLIST, LB_ADDSTRING, 0, (LPARAM) joy->instance.tszInstanceName);
             }
 
+            /* Set graphics DPI information based on window size */
+            GetClientRect(hwnd, &view);
+            data->graphics.dpi_x = view.right/(float)DIALOG_BOX_WIDTH;
+            data->graphics.dpi_y = view.bottom/(float)DIALOG_BOX_HEIGHT;
+
             return TRUE;
         }
 
@@ -253,6 +259,7 @@ static DWORD WINAPI input_thread(void *param)
     while (!data->stop)
     {
         int i;
+
         poll_input(&data->joysticks[data->chosen_joystick], &state);
 
         dump_joy_state(&state, data->joysticks[data->chosen_joystick].num_buttons);
@@ -260,7 +267,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 +288,16 @@ 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],
+            SetWindowPos(data->graphics.axes[i], 0,
+                        (TEST_AXIS_X + TEST_NEXT_AXIS_X*i + axes_pos[i][0]) * data->graphics.dpi_x,
+                        (TEST_AXIS_Y + axes_pos[i][1]) * data->graphics.dpi_y,
                         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 +313,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);
 }
 
 /*********************************************************************
@@ -339,9 +346,11 @@ static void draw_joystick_buttons(HWND hwnd, struct JoystickData* data)
 
         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,
+        /* Draw the buttons according to the screen dpi */
+        data->graphics.buttons[i] = CreateWindowW(button_class, button_label, WS_CHILD,
+            (TEST_BUTTON_X + TEST_NEXT_BUTTON_X*col) * data->graphics.dpi_x,
+            (TEST_BUTTON_Y + TEST_NEXT_BUTTON_Y*row) * data->graphics.dpi_y,
+            TEST_BUTTON_SIZE_X * data->graphics.dpi_x, TEST_BUTTON_SIZE_Y * data->graphics.dpi_y,
             hwnd, NULL, NULL, hinst);
 
         col += 1;
@@ -363,9 +372,11 @@ static void draw_joystick_axes(HWND hwnd, struct JoystickData* data)
         /* 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,
+        /* Draw according to DPI */
+        data->graphics.axes[i] = CreateWindowW( button_class, NULL, WS_CHILD | WS_VISIBLE,
+            (TEST_AXIS_X + TEST_NEXT_AXIS_X*i) * data->graphics.dpi_x,
+            TEST_AXIS_Y * data->graphics.dpi_y,
+            TEST_AXIS_SIZE_X * data->graphics.dpi_x, TEST_AXIS_SIZE_Y * data->graphics.dpi_y,
             hwnd, (HMENU) IDC_JOYSTICKAXES + i, NULL, hinst);
     }
 }
@@ -454,9 +465,9 @@ static void draw_ff_axis(HWND hwnd, struct JoystickData *data)
     static WCHAR button_class[] = {'B','u','t','t','o','n','\0'};
 
     /* 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,
+    data->graphics.ff_axis = CreateWindowW( button_class, NULL, WS_CHILD | WS_VISIBLE,
+        FF_AXIS_X * data->graphics.dpi_x, FF_AXIS_Y * data->graphics.dpi_y,
+        FF_AXIS_SIZE_X * data->graphics.dpi_x, FF_AXIS_SIZE_Y * data->graphics.dpi_y,
         hwnd, (HMENU) IDC_FFAXIS, NULL, hinst);
 }
 
@@ -519,7 +530,9 @@ 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,
+        SetWindowPos(data->graphics.ff_axis, 0,
+                    (FF_AXIS_X + state.lX) * data->graphics.dpi_x,
+                    (FF_AXIS_Y + state.lY) * data->graphics.dpi_y,
                      0, 0, SWP_NOZORDER | SWP_NOSIZE);
 
         for (i=0; i < joy->num_buttons; i++)
-- 
1.7.9.5




More information about the wine-patches mailing list