zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_dxjoystick_c.h
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "SDL_config.h"
22 
23 #ifndef SDL_JOYSTICK_DINPUT_H
24 
25 /* DirectInput joystick driver; written by Glenn Maynard, based on Andrei de
26  * A. Formiga's WINMM driver.
27  *
28  * Hats and sliders are completely untested; the app I'm writing this for mostly
29  * doesn't use them and I don't own any joysticks with them.
30  *
31  * We don't bother to use event notification here. It doesn't seem to work
32  * with polled devices, and it's fine to call IDirectInputDevice2_GetDeviceData and
33  * let it return 0 events. */
34 
35 #include "../../core/windows/SDL_windows.h"
36 
37 #define DIRECTINPUT_VERSION 0x0800 /* Need version 7 for force feedback. Need version 8 so IDirectInput8_EnumDevices doesn't leak like a sieve... */
38 #include <dinput.h>
39 #define COBJMACROS
40 #include <wbemcli.h>
41 #include <oleauto.h>
42 #include <xinput.h>
43 #include <devguid.h>
44 #include <dbt.h>
45 #include <xinput.h>
46 
47 #ifndef XUSER_MAX_COUNT
48 #define XUSER_MAX_COUNT 4
49 #endif
50 #ifndef XUSER_INDEX_ANY
51 #define XUSER_INDEX_ANY 0x000000FF
52 #endif
53 #ifndef XINPUT_CAPS_FFB_SUPPORTED
54 #define XINPUT_CAPS_FFB_SUPPORTED 0x0001
55 #endif
56 
57 
58 /* typedef's for XInput structs we use */
59 typedef struct
60 {
61  WORD wButtons;
64  SHORT sThumbLX;
65  SHORT sThumbLY;
66  SHORT sThumbRX;
67  SHORT sThumbRY;
70 
71 typedef struct
72 {
76 
77 /* Forward decl's for XInput API's we load dynamically and use if available */
78 typedef DWORD (WINAPI *XInputGetState_t)
79  (
80  DWORD dwUserIndex, /* [in] Index of the gamer associated with the device */
81  XINPUT_STATE_EX* pState /* [out] Receives the current state */
82  );
83 
84 typedef DWORD (WINAPI *XInputSetState_t)
85  (
86  DWORD dwUserIndex, /* [in] Index of the gamer associated with the device */
87  XINPUT_VIBRATION* pVibration /* [in, out] The vibration information to send to the controller */
88  );
89 
90 typedef DWORD (WINAPI *XInputGetCapabilities_t)
91  (
92  DWORD dwUserIndex, /* [in] Index of the gamer associated with the device */
93  DWORD dwFlags, /* [in] Input flags that identify the device type */
94  XINPUT_CAPABILITIES* pCapabilities /* [out] Receives the capabilities */
95  );
96 
97 extern int WIN_LoadXInputDLL(void);
98 extern void WIN_UnloadXInputDLL(void);
99 
100 extern XInputGetState_t SDL_XInputGetState;
101 extern XInputSetState_t SDL_XInputSetState;
102 extern XInputGetCapabilities_t SDL_XInputGetCapabilities;
103 extern DWORD SDL_XInputVersion; /* ((major << 16) & 0xFF00) | (minor & 0xFF) */
104 
105 #define XINPUTGETSTATE SDL_XInputGetState
106 #define XINPUTSETSTATE SDL_XInputSetState
107 #define XINPUTGETCAPABILITIES SDL_XInputGetCapabilities
108 #define INVALID_XINPUT_USERID XUSER_INDEX_ANY
109 #define SDL_XINPUT_MAX_DEVICES XUSER_MAX_COUNT
110 
111 #define MAX_INPUTS 256 /* each joystick can have up to 256 inputs */
112 
113 
114 /* local types */
115 typedef enum Type
117 
118 typedef struct input_t
119 {
120  /* DirectInput offset for this input type: */
122 
123  /* Button, axis or hat: */
125 
126  /* SDL input offset: */
128 } input_t;
129 
130 /* The private structure used to keep track of a joystick */
131 struct joystick_hwdata
132 {
133  LPDIRECTINPUTDEVICE8 InputDevice;
134  DIDEVCAPS Capabilities;
135  int buffered;
137 
143  Uint8 bXInputDevice; /* 1 if this device supports using the xinput API rather than DirectInput */
144  Uint8 bXInputHaptic; /* Supports force feedback via XInput. */
145  Uint8 userid; /* XInput userid index for this joystick */
146  Uint8 currentXInputSlot; /* the current position to write to in XInputState below, used so we can compare old and new values */
148 };
149 
150 #endif /* SDL_JOYSTICK_DINPUT_H */
input_t Inputs[MAX_INPUTS]
XINPUT_GAMEPAD_EX Gamepad
struct input_t input_t
SDL_JoystickGUID guid
LPDIRECTINPUTDEVICE8 InputDevice
XInputSetState_t SDL_XInputSetState
DIDEVCAPS Capabilities
DWORD XINPUT_CAPABILITIES * pCapabilities
void WIN_UnloadXInputDLL(void)
#define MAX_INPUTS
DWORD dwFlags
DWORD SDL_XInputVersion
XINPUT_VIBRATION * pVibration
int WIN_LoadXInputDLL(void)
XInputGetCapabilities_t SDL_XInputGetCapabilities
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:129
typedef DWORD(WINAPI *XInputGetState_t)(DWORD dwUserIndex
XInputGetState_t SDL_XInputGetState
XINPUT_STATE_EX XInputState[2]