annotate src/joystick/win32/SDL_dxjoystick.c @ 1717:e3637569ab86 SDL-1.3

Include sdl.pc in the development RPM
author Sam Lantinga <slouken@libsdl.org>
date Tue, 27 Jun 2006 04:59:10 +0000
parents 4da1ee79c9af
children
rev   line source
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #ifdef SDL_JOYSTICK_DINPUT
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 /* DirectInput joystick driver; written by Glenn Maynard, based on Andrei de
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 * A. Formiga's WINMM driver.
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 *
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 * Hats and sliders are completely untested; the app I'm writing this for mostly
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 * doesn't use them and I don't own any joysticks with them.
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 *
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 * We don't bother to use event notification here. It doesn't seem to work
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 * with polled devices, and it's fine to call IDirectInputDevice2_GetDeviceData and
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 * let it return 0 events. */
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 #include "SDL_error.h"
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 #include "SDL_events.h"
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 #include "SDL_joystick.h"
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 #include "../SDL_sysjoystick.h"
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 #include "../SDL_joystick_c.h"
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 #define WIN32_LEAN_AND_MEAN
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 #include <windows.h>
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 #define DIRECTINPUT_VERSION 0x0500
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 #include <dinput.h>
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
48 #define INPUT_QSIZE 32 /* Buffer up to 32 input messages */
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 extern HINSTANCE SDL_Instance;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
51 extern int DX5_Load();
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
52 extern void DX5_Unload();
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
53 extern HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
54 LPDIRECTINPUT * ppDI,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
55 LPUNKNOWN punkOuter);
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 static LPDIRECTINPUT dinput = NULL;
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 #define MAX_JOYSTICKS 8
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
60 #define MAX_INPUTS 256 /* each joystick can have up to 256 inputs */
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 #define AXIS_MIN -32768 /* minimum value for axis coordinate */
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 #define AXIS_MAX 32767 /* maximum value for axis coordinate */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
63 #define JOY_AXIS_THRESHOLD (((AXIS_MAX)-(AXIS_MIN))/100) /* 1% motion */
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
65 typedef enum Type
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
66 { BUTTON, AXIS, HAT } Type;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 /* array to hold joystick ID values */
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 static DIDEVICEINSTANCE SYS_Joystick[MAX_JOYSTICKS];
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
70 static int SYS_NumJoysticks;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 extern HWND SDL_Window;
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 typedef struct input_t
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
76 /* DirectInput offset for this input type: */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
77 DWORD ofs;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
79 /* Button, axis or hat: */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
80 Type type;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
82 /* SDL input offset: */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
83 Uint8 num;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 } input_t;
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 /* The private structure used to keep track of a joystick */
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 struct joystick_hwdata
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
89 LPDIRECTINPUTDEVICE2 InputDevice;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
90 int buffered;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
92 input_t Inputs[MAX_INPUTS];
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
93 int NumInputs;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 };
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 /* Convert a DirectInput return code to a text message */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
97 static void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
98 SetDIerror(char *function, int code)
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
100 static char *error;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
101 static char errbuf[1024];
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
103 errbuf[0] = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
104 switch (code) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
105 case DIERR_GENERIC:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
106 error = "Undefined error!";
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
107 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
108 case DIERR_OLDDIRECTINPUTVERSION:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
109 error = "Your version of DirectInput needs upgrading";
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
110 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
111 case DIERR_INVALIDPARAM:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
112 error = "Invalid parameters";
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
113 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
114 case DIERR_OUTOFMEMORY:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
115 error = "Out of memory";
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
116 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
117 case DIERR_DEVICENOTREG:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
118 error = "Device not registered";
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
119 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
120 case DIERR_NOINTERFACE:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
121 error = "Interface not supported";
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
122 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
123 case DIERR_NOTINITIALIZED:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
124 error = "Device not initialized";
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
125 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
126 default:
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
127 sprintf(errbuf, "%s: Unknown DirectInput error: 0x%x",
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
128 function, code);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
129 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
130 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
131 if (!errbuf[0]) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
132 sprintf(errbuf, "%s: %s", function, error);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
133 }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
134 SDL_SetError("%s", errbuf);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
135 return;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 }
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
139 BOOL CALLBACK
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
140 EnumJoysticksCallback(const DIDEVICEINSTANCE * pdidInstance, VOID * pContext)
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
142 memcpy(&SYS_Joystick[SYS_NumJoysticks], pdidInstance,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
143 sizeof(DIDEVICEINSTANCE));
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
144 SYS_NumJoysticks++;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
146 if (SYS_NumJoysticks >= MAX_JOYSTICKS)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
147 return DIENUM_STOP;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
149 return DIENUM_CONTINUE;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 }
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
152 static BOOL CALLBACK
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
153 DIJoystick_EnumDevObjectsProc(LPCDIDEVICEOBJECTINSTANCE dev, LPVOID pvRef)
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
155 SDL_Joystick *joystick = (SDL_Joystick *) pvRef;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
156 HRESULT result;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
157 input_t *in = &joystick->hwdata->Inputs[joystick->hwdata->NumInputs];
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
158 const int SupportedMask = DIDFT_BUTTON | DIDFT_POV | DIDFT_AXIS;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
159 if (!(dev->dwType & SupportedMask))
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
160 return DIENUM_CONTINUE; /* unsupported */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
161
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
162 in->ofs = dev->dwOfs;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
164 if (dev->dwType & DIDFT_BUTTON) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
165 in->type = BUTTON;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
166 in->num = joystick->nbuttons;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
167 joystick->nbuttons++;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
168 } else if (dev->dwType & DIDFT_POV) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
169 in->type = HAT;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
170 in->num = joystick->nhats;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
171 joystick->nhats++;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
172 } else { /* dev->dwType & DIDFT_AXIS */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
173 DIPROPRANGE diprg;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
174 DIPROPDWORD dilong;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
175
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
176 in->type = AXIS;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
177 in->num = joystick->naxes;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
179 diprg.diph.dwSize = sizeof(diprg);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
180 diprg.diph.dwHeaderSize = sizeof(diprg.diph);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
181 diprg.diph.dwObj = dev->dwOfs;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
182 diprg.diph.dwHow = DIPH_BYOFFSET;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
183 diprg.lMin = AXIS_MIN;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
184 diprg.lMax = AXIS_MAX;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
185
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
186 result =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
187 IDirectInputDevice2_SetProperty(joystick->hwdata->InputDevice,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
188 DIPROP_RANGE, &diprg.diph);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
189 if (result != DI_OK)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
190 return DIENUM_CONTINUE; /* don't use this axis */
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
192 /* Set dead zone to 0. */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
193 dilong.diph.dwSize = sizeof(dilong);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
194 dilong.diph.dwHeaderSize = sizeof(dilong.diph);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
195 dilong.diph.dwObj = dev->dwOfs;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
196 dilong.diph.dwHow = DIPH_BYOFFSET;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
197 dilong.dwData = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
198 result =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
199 IDirectInputDevice2_SetProperty(joystick->hwdata->InputDevice,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
200 DIPROP_DEADZONE, &dilong.diph);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
201 if (result != DI_OK)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
202 return DIENUM_CONTINUE; /* don't use this axis */
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
204 joystick->naxes++;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
205 }
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
207 joystick->hwdata->NumInputs++;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
209 if (joystick->hwdata->NumInputs == MAX_INPUTS)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
210 return DIENUM_STOP; /* too many */
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
212 return DIENUM_CONTINUE;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 }
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 /* Function to scan the system for joysticks.
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 * This function should set SDL_numjoysticks to the number of available
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 * joysticks. Joystick 0 should be the system default joystick.
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 * It should return 0, or -1 on an unrecoverable fatal error.
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
220 int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
221 SDL_SYS_JoystickInit(void)
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
223 HRESULT result;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
225 SYS_NumJoysticks = 0;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
227 /* Create the DirectInput object */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
228 if (DX5_Load() < 0) {
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
229 SDL_SetError("Couldn't load DirectInput");
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
230 return (-1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
231 }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
232 result = DInputCreate(SDL_Instance, DIRECTINPUT_VERSION, &dinput, NULL);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
233 if (result != DI_OK) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
234 DX5_Unload();
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
235 SetDIerror("DirectInputCreate", result);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
236 return (-1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
237 }
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
239 result = IDirectInput_EnumDevices(dinput,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
240 DIDEVTYPE_JOYSTICK,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
241 EnumJoysticksCallback,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
242 NULL, DIEDFL_ATTACHEDONLY);
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
244 return SYS_NumJoysticks;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 }
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247 /* Function to get the device-dependent name of a joystick */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
248 const char *
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
249 SDL_SYS_JoystickName(int index)
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
251 /***-> test for invalid index ? */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
252 return (SYS_Joystick[index].tszProductName);
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 }
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 /* Function to open a joystick for use.
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 The joystick to open is specified by the index field of the joystick.
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257 This should fill the nbuttons and naxes fields of the joystick structure.
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 It returns 0, or -1 if there is an error.
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
260 int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
261 SDL_SYS_JoystickOpen(SDL_Joystick * joystick)
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
263 HRESULT result;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
264 LPDIRECTINPUTDEVICE device;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
265
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
266 /* allocate memory for system specific hardware data */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
267 joystick->hwdata =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
268 (struct joystick_hwdata *) malloc(sizeof(*joystick->hwdata));
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
269 if (joystick->hwdata == NULL) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
270 SDL_OutOfMemory();
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
271 return (-1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
272 }
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
273 memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
274 joystick->hwdata->buffered = 1;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
276 result =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
277 IDirectInput_CreateDevice(dinput,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
278 &SYS_Joystick[joystick->index].
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
279 guidInstance, &device, NULL);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
280 if (result != DI_OK) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
281 SetDIerror("DirectInput::CreateDevice", result);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
282 return (-1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
283 }
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
285 result = IDirectInputDevice_QueryInterface(device,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
286 &IID_IDirectInputDevice2,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
287 (LPVOID *) & joystick->
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
288 hwdata->InputDevice);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
289 IDirectInputDevice_Release(device);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
290 if (result != DI_OK) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
291 SetDIerror("DirectInputDevice::QueryInterface", result);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
292 return (-1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
293 }
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
294
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
295 result =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
296 IDirectInputDevice2_SetCooperativeLevel(joystick->hwdata->
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
297 InputDevice, SDL_Window,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
298 DISCL_NONEXCLUSIVE |
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
299 DISCL_BACKGROUND);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
300 if (result != DI_OK) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
301 SetDIerror("DirectInputDevice::SetCooperativeLevel", result);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
302 return (-1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
303 }
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
304
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
305 result =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
306 IDirectInputDevice2_SetDataFormat(joystick->hwdata->InputDevice,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
307 &c_dfDIJoystick);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
308 if (result != DI_OK) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
309 SetDIerror("DirectInputDevice::SetDataFormat", result);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
310 return (-1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
311 }
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
313 IDirectInputDevice2_EnumObjects(joystick->hwdata->InputDevice,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
314 DIJoystick_EnumDevObjectsProc,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
315 joystick,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
316 DIDFT_BUTTON | DIDFT_AXIS | DIDFT_POV);
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
318 {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
319 DIPROPDWORD dipdw;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
320 memset(&dipdw, 0, sizeof(dipdw));
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
321 dipdw.diph.dwSize = sizeof(dipdw);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
322 dipdw.diph.dwHeaderSize = sizeof(dipdw.diph);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
323 dipdw.diph.dwObj = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
324 dipdw.diph.dwHow = DIPH_DEVICE;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
325 dipdw.dwData = INPUT_QSIZE;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
326 result =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
327 IDirectInputDevice2_SetProperty(joystick->hwdata->InputDevice,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
328 DIPROP_BUFFERSIZE, &dipdw.diph);
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
329
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
330 if (result == DI_POLLEDDEVICE) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
331 /* This device doesn't support buffering, so we're forced
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
332 * to use less reliable polling. */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
333 joystick->hwdata->buffered = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
334 } else if (result != DI_OK) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
335 SetDIerror("DirectInputDevice::SetProperty", result);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
336 return (-1);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
337 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
338 }
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
339
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
340 return (0);
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
341 }
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
342
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
343 static Uint8
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
344 TranslatePOV(DWORD value)
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
346 const int HAT_VALS[] = {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
347 SDL_HAT_UP,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
348 SDL_HAT_UP | SDL_HAT_RIGHT,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
349 SDL_HAT_RIGHT,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
350 SDL_HAT_DOWN | SDL_HAT_RIGHT,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
351 SDL_HAT_DOWN,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
352 SDL_HAT_DOWN | SDL_HAT_LEFT,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
353 SDL_HAT_LEFT,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
354 SDL_HAT_UP | SDL_HAT_LEFT
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
355 };
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
356
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
357 if (LOWORD(value) == 0xFFFF)
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
358 return SDL_HAT_CENTERED;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
359
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
360 /* Round the value up: */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
361 value += 4500 / 2;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
362 value %= 36000;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
363 value /= 4500;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
364
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
365 if (value >= 8)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
366 return SDL_HAT_CENTERED; /* shouldn't happen */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
367
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
368 return HAT_VALS[value];
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369 }
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
370
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
371 /* SDL_PrivateJoystick* doesn't discard duplicate events, so we need to
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372 * do it. */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
373 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
374 SDL_PrivateJoystickAxis_Int(SDL_Joystick * joystick, Uint8 axis, Sint16 value)
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
376 if (joystick->axes[axis] != value)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
377 return SDL_PrivateJoystickAxis(joystick, axis, value);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
378 return 0;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379 }
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
380
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
381 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
382 SDL_PrivateJoystickHat_Int(SDL_Joystick * joystick, Uint8 hat, Uint8 value)
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
383 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
384 if (joystick->hats[hat] != value)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
385 return SDL_PrivateJoystickHat(joystick, hat, value);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
386 return 0;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
387 }
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
388
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
389 static int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
390 SDL_PrivateJoystickButton_Int(SDL_Joystick * joystick, Uint8 button,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
391 Uint8 state)
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
392 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
393 if (joystick->buttons[button] != state)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
394 return SDL_PrivateJoystickButton(joystick, button, state);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
395 return 0;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
396 }
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
397
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
398 /* Function to update the state of a joystick - called as a device poll.
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
399 * This function shouldn't update the joystick structure directly,
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400 * but instead should call SDL_PrivateJoystick*() to deliver events
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
401 * and update joystick device state.
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
402 */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
403 void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
404 SDL_SYS_JoystickUpdate_Polled(SDL_Joystick * joystick)
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
405 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
406 DIJOYSTATE state;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
407 HRESULT result;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
408 int i;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
409
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
410 result =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
411 IDirectInputDevice2_GetDeviceState(joystick->hwdata->InputDevice,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
412 sizeof(state), &state);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
413 if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
414 IDirectInputDevice2_Acquire(joystick->hwdata->InputDevice);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
415 result =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
416 IDirectInputDevice2_GetDeviceState(joystick->hwdata->
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
417 InputDevice, sizeof(state),
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
418 &state);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
419 }
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
420
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
421 /* Set each known axis, button and POV. */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
422 for (i = 0; i < joystick->hwdata->NumInputs; ++i) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
423 const input_t *in = &joystick->hwdata->Inputs[i];
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
424
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
425 switch (in->type) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
426 case AXIS:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
427 switch (in->ofs) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
428 case DIJOFS_X:
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
429 SDL_PrivateJoystickAxis_Int(joystick, in->num,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
430 (Sint16) state.lX);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
431 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
432 case DIJOFS_Y:
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
433 SDL_PrivateJoystickAxis_Int(joystick, in->num,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
434 (Sint16) state.lY);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
435 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
436 case DIJOFS_Z:
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
437 SDL_PrivateJoystickAxis_Int(joystick, in->num,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
438 (Sint16) state.lZ);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
439 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
440 case DIJOFS_RX:
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
441 SDL_PrivateJoystickAxis_Int(joystick, in->num,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
442 (Sint16) state.lRx);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
443 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
444 case DIJOFS_RY:
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
445 SDL_PrivateJoystickAxis_Int(joystick, in->num,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
446 (Sint16) state.lRy);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
447 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
448 case DIJOFS_RZ:
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
449 SDL_PrivateJoystickAxis_Int(joystick, in->num,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
450 (Sint16) state.lRz);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
451 break;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
452 case DIJOFS_SLIDER(0):
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
453 SDL_PrivateJoystickAxis_Int(joystick, in->num,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
454 (Sint16) state.rglSlider[0]);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
455 break;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
456 case DIJOFS_SLIDER(1):
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
457 SDL_PrivateJoystickAxis_Int(joystick, in->num,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
458 (Sint16) state.rglSlider[0]);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
459 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
460 }
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
461
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
462 break;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
463
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
464 case BUTTON:
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
465 SDL_PrivateJoystickButton_Int(joystick, in->num,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
466 (Uint8) (state.
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
467 rgbButtons[in->ofs -
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
468 DIJOFS_BUTTON0]
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
469 ? SDL_PRESSED :
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
470 SDL_RELEASED));
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
471 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
472 case HAT:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
473 {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
474 Uint8 pos =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
475 TranslatePOV(state.rgdwPOV[in->ofs - DIJOFS_POV(0)]);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
476 SDL_PrivateJoystickHat_Int(joystick, in->num, pos);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
477 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
478 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
479 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
480 }
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
481 }
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
482
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
483 void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
484 SDL_SYS_JoystickUpdate_Buffered(SDL_Joystick * joystick)
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
485 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
486 int i;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
487 HRESULT result;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
488 DWORD numevents;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
489 DIDEVICEOBJECTDATA evtbuf[INPUT_QSIZE];
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
490
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
491 numevents = INPUT_QSIZE;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
492 result =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
493 IDirectInputDevice2_GetDeviceData(joystick->hwdata->InputDevice,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
494 sizeof(DIDEVICEOBJECTDATA),
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
495 evtbuf, &numevents, 0);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
496 if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
497 IDirectInputDevice2_Acquire(joystick->hwdata->InputDevice);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
498 result =
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
499 IDirectInputDevice2_GetDeviceData(joystick->hwdata->
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
500 InputDevice,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
501 sizeof(DIDEVICEOBJECTDATA),
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
502 evtbuf, &numevents, 0);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
503 }
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
504
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
505 /* Handle the events */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
506 if (result != DI_OK)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
507 return;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
508
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
509 for (i = 0; i < (int) numevents; ++i) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
510 int j;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
511
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
512 for (j = 0; j < joystick->hwdata->NumInputs; ++j) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
513 const input_t *in = &joystick->hwdata->Inputs[j];
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
514
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
515 if (evtbuf[i].dwOfs != in->ofs)
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
516 continue;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
517
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
518 switch (in->type) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
519 case AXIS:
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
520 SDL_PrivateJoystickAxis(joystick, in->num,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
521 (Sint16) evtbuf[i].dwData);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
522 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
523 case BUTTON:
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
524 SDL_PrivateJoystickButton(joystick, in->num,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
525 (Uint8) (evtbuf[i].
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
526 dwData ? SDL_PRESSED
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
527 : SDL_RELEASED));
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
528 break;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
529 case HAT:
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
530 {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
531 Uint8 pos = TranslatePOV(evtbuf[i].dwData);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
532 SDL_PrivateJoystickHat(joystick, in->num, pos);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
533 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
534 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
535 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
536 }
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
537 }
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
538
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
539 void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
540 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
541 {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
542 HRESULT result;
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
543
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
544 result = IDirectInputDevice2_Poll(joystick->hwdata->InputDevice);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
545 if (result == DIERR_INPUTLOST || result == DIERR_NOTACQUIRED) {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
546 IDirectInputDevice2_Acquire(joystick->hwdata->InputDevice);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
547 IDirectInputDevice2_Poll(joystick->hwdata->InputDevice);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
548 }
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
549
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
550 if (joystick->hwdata->buffered)
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
551 SDL_SYS_JoystickUpdate_Buffered(joystick);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
552 else
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
553 SDL_SYS_JoystickUpdate_Polled(joystick);
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
554 }
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
555
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
556 /* Function to close a joystick after use */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
557 void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
558 SDL_SYS_JoystickClose(SDL_Joystick * joystick)
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
559 {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
560 IDirectInputDevice2_Unacquire(joystick->hwdata->InputDevice);
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
561 IDirectInputDevice2_Release(joystick->hwdata->InputDevice);
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
562
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
563 if (joystick->hwdata != NULL) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
564 /* free system specific hardware data */
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
565 free(joystick->hwdata);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
566 }
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
567 }
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
568
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
569 /* Function to perform any system-specific joystick related cleanup */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
570 void
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
571 SDL_SYS_JoystickQuit(void)
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
572 {
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
573 IDirectInput_Release(dinput);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
574 dinput = NULL;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
575 DX5_Unload();
1661
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
576 }
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
577
281d3f4870e5 Moved DirectInput joystick code to 1.3 branch
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
578 #endif /* SDL_JOYSTICK_DINPUT */
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents: 1661
diff changeset
579 /* vi: set ts=4 sw=4 expandtab: */