[PATCH 2/2] joy.cpl: Added force feedback direction control (try 2)
Lucas Zawacki
lfzawacki at gmail.com
Wed Jul 11 13:44:07 CDT 2012
From: Lucas Zawacki <lfzawacki at gmail.com>
---
dlls/joy.cpl/joy.h | 7 +++++++
dlls/joy.cpl/joy.rc | 5 ++++-
dlls/joy.cpl/main.c | 51 +++++++++++++++++++++++++++++++++++----------------
3 files changed, 46 insertions(+), 17 deletions(-)
diff --git a/dlls/joy.cpl/joy.h b/dlls/joy.cpl/joy.h
index 13efe1b..e40a71b 100644
--- a/dlls/joy.cpl/joy.h
+++ b/dlls/joy.cpl/joy.h
@@ -59,6 +59,7 @@ struct JoystickData {
int chosen_joystick;
HWND buttons[TEST_MAX_BUTTONS];
HWND axes[TEST_MAX_AXES];
+ HWND ff_axis;
BOOL stop;
};
@@ -90,6 +91,7 @@ struct JoystickData {
#define IDC_FFSELECTCOMBO 2009
#define IDC_FFEFFECTLIST 2010
+#define IDC_FFAXIS 2011
/* constants */
#define TEST_POLL_TIME 100
@@ -110,6 +112,11 @@ struct JoystickData {
#define TEST_AXIS_MIN -40
#define TEST_AXIS_MAX 40
+#define FF_AXIS_X 373
+#define FF_AXIS_Y 98
+#define FF_AXIS_SIZE_X 5
+#define FF_AXIS_SIZE_Y 5
+
#define FF_PLAY_TIME 2*DI_SECONDS
#define FF_PERIOD_TIME FF_PLAY_TIME/4
diff --git a/dlls/joy.cpl/joy.rc b/dlls/joy.cpl/joy.rc
index 0eb4378..1bfcfee 100644
--- a/dlls/joy.cpl/joy.rc
+++ b/dlls/joy.cpl/joy.rc
@@ -62,7 +62,10 @@ FONT 8, "Ms Shell Dlg"
COMBOBOX IDC_FFSELECTCOMBO, 5, 5, 100, 30, CBS_DROPDOWNLIST | CBS_HASSTRINGS
LTEXT "Available Effects", IDC_STATIC, 10, 30, 100, 10
LISTBOX IDC_FFEFFECTLIST, 10, 40, 180, 70, WS_TABSTOP | WS_VSCROLL | LBS_NOTIFY
- LTEXT "Press any button in the controller to activate the chosen effect.", IDC_STATIC, 10, 110, 210, 25
+ LTEXT "Press any button in the controller to activate the chosen effect." \
+ "The effect direction can be changed with the controller axis.", \
+ IDC_STATIC, 10, 110, 210, 25
+ GROUPBOX "Direction", IDC_STATIC, 220, 30, 60, 60
}
#define WINE_FILENAME_STR "joy.cpl"
diff --git a/dlls/joy.cpl/main.c b/dlls/joy.cpl/main.c
index d2fb3b7..c77a445 100644
--- a/dlls/joy.cpl/main.c
+++ b/dlls/joy.cpl/main.c
@@ -67,6 +67,7 @@ static BOOL CALLBACK enum_callback(const DIDEVICEINSTANCEW *instance, void *cont
{
struct JoystickData *data = context;
struct Joystick *joystick;
+ DIPROPRANGE proprange;
DIDEVCAPS caps;
if (data->joysticks == NULL)
@@ -92,6 +93,16 @@ static BOOL CALLBACK enum_callback(const DIDEVICEINSTANCEW *instance, void *cont
if (joystick->forcefeedback) data->num_ff++;
+ /* Set axis range to ease the GUI visualization */
+ proprange.diph.dwSize = sizeof(DIPROPRANGE);
+ proprange.diph.dwHeaderSize = sizeof(DIPROPHEADER);
+ proprange.diph.dwHow = DIPH_DEVICE;
+ proprange.diph.dwObj = 0;
+ proprange.lMin = TEST_AXIS_MIN;
+ proprange.lMax = TEST_AXIS_MAX;
+
+ IDirectInputDevice_SetProperty(joystick->device, DIPROP_RANGE, &proprange.diph);
+
return DIENUM_CONTINUE;
}
@@ -340,8 +351,6 @@ static void draw_joystick_buttons(HWND hwnd, struct JoystickData* data)
static void draw_joystick_axes(HWND hwnd, struct JoystickData* data)
{
int i;
- struct Joystick *joy;
- DIPROPRANGE propRange;
HINSTANCE hinst = (HINSTANCE) GetWindowLongPtrW(hwnd, GWLP_HINSTANCE);
static const WCHAR button_class[] = {'B','u','t','t','o','n','\0'};
static const WCHAR axes_names[TEST_MAX_AXES][7] = { {'X',',','Y','\0'}, {'R','x',',','R','y','\0'},
@@ -349,20 +358,6 @@ static void draw_joystick_axes(HWND hwnd, struct JoystickData* data)
static const DWORD axes_idc[TEST_MAX_AXES] = { IDC_TESTGROUPXY, IDC_TESTGROUPRXRY,
IDC_TESTGROUPZRZ, IDC_TESTGROUPPOV };
- /* Set axis range to ease the GUI visualization */
- for (i = 0; i < data->num_joysticks; i++)
- {
- joy = &data->joysticks[i];
- propRange.diph.dwSize = sizeof(DIPROPRANGE);
- propRange.diph.dwHeaderSize = sizeof(DIPROPHEADER);
- propRange.diph.dwHow = DIPH_DEVICE;
- propRange.diph.dwObj = 0;
- propRange.lMin = TEST_AXIS_MIN;
- propRange.lMax = TEST_AXIS_MAX;
-
- IDirectInputDevice_SetProperty(joy->device, DIPROP_RANGE, &propRange.diph);
- }
-
for (i = 0; i < TEST_MAX_AXES; i++)
{
/* Set axis box name */
@@ -458,6 +453,17 @@ static INT_PTR CALLBACK test_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM
* Joystick force feedback testing functions
*
*/
+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'};
+
+ /* 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);
+}
static void initialize_effects_list(HWND hwnd, struct Joystick* joy)
{
@@ -505,15 +511,26 @@ static DWORD WINAPI ff_input_thread(void *param)
int i;
struct Joystick *joy = &data->joysticks[data->chosen_joystick];
int chosen_effect = joy->chosen_effect;
+ DIEFFECT *dieffect;
+ DWORD flags = DIEP_AXES | DIEP_DIRECTION | DIEP_NORESTART;
/* Skip this if we have no effects */
if (joy->num_effects == 0 || chosen_effect < 0) continue;
poll_input(joy, &state);
+ /* Set ff parameters and draw the axis */
+ dieffect = &joy->effects[chosen_effect].params;
+ 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);
+
for (i=0; i < joy->num_buttons; i++)
if (state.rgbButtons[i])
{
+ IDirectInputEffect_SetParameters(joy->effects[chosen_effect].effect, dieffect, flags);
IDirectInputEffect_Start(joy->effects[chosen_effect].effect, 1, 0);
break;
}
@@ -651,6 +668,8 @@ static INT_PTR CALLBACK ff_dlgproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lp
thread = CreateThread(NULL, 0, ff_input_thread, (void*) data, 0, &tid);
SuspendThread(thread);
+ draw_ff_axis(hwnd, data);
+
return TRUE;
}
--
1.7.9.5
More information about the wine-patches
mailing list