1 | /* |
2 | Simple DirectMedia Layer |
3 | Copyright (C) 1997-2025 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_internal.h" |
22 | |
23 | #ifndef SDL_VIRTUALJOYSTICK_C_H |
24 | #define SDL_VIRTUALJOYSTICK_C_H |
25 | |
26 | #ifdef SDL_JOYSTICK_VIRTUAL |
27 | |
28 | #include "../SDL_sysjoystick.h" |
29 | |
30 | #define AXES_CHANGED 0x00000001 |
31 | #define BALLS_CHANGED 0x00000002 |
32 | #define BUTTONS_CHANGED 0x00000004 |
33 | #define HATS_CHANGED 0x00000008 |
34 | #define TOUCHPADS_CHANGED 0x00000010 |
35 | |
36 | /** |
37 | * Data for a virtual, software-only joystick. |
38 | */ |
39 | typedef struct VirtualSensorEvent |
40 | { |
41 | SDL_SensorType type; |
42 | Uint64 sensor_timestamp; |
43 | float data[3]; |
44 | int num_values; |
45 | } VirtualSensorEvent; |
46 | |
47 | typedef struct joystick_hwdata |
48 | { |
49 | SDL_JoystickID instance_id; |
50 | bool attached; |
51 | char *name; |
52 | SDL_JoystickType type; |
53 | SDL_GUID guid; |
54 | SDL_VirtualJoystickDesc desc; |
55 | Uint32 changes; |
56 | Sint16 *axes; |
57 | bool *buttons; |
58 | Uint8 *hats; |
59 | SDL_JoystickBallData *balls; |
60 | SDL_JoystickTouchpadInfo *touchpads; |
61 | SDL_JoystickSensorInfo *sensors; |
62 | bool sensors_enabled; |
63 | int num_sensor_events; |
64 | int max_sensor_events; |
65 | VirtualSensorEvent *sensor_events; |
66 | |
67 | SDL_Joystick *joystick; |
68 | |
69 | struct joystick_hwdata *next; |
70 | } joystick_hwdata; |
71 | |
72 | extern SDL_JoystickID SDL_JoystickAttachVirtualInner(const SDL_VirtualJoystickDesc *desc); |
73 | extern bool SDL_JoystickDetachVirtualInner(SDL_JoystickID instance_id); |
74 | |
75 | extern bool SDL_SetJoystickVirtualAxisInner(SDL_Joystick *joystick, int axis, Sint16 value); |
76 | extern bool SDL_SetJoystickVirtualBallInner(SDL_Joystick *joystick, int ball, Sint16 xrel, Sint16 yrel); |
77 | extern bool SDL_SetJoystickVirtualButtonInner(SDL_Joystick *joystick, int button, bool down); |
78 | extern bool SDL_SetJoystickVirtualHatInner(SDL_Joystick *joystick, int hat, Uint8 value); |
79 | extern bool SDL_SetJoystickVirtualTouchpadInner(SDL_Joystick *joystick, int touchpad, int finger, bool down, float x, float y, float pressure); |
80 | extern bool SDL_SendJoystickVirtualSensorDataInner(SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values); |
81 | |
82 | #endif // SDL_JOYSTICK_VIRTUAL |
83 | |
84 | #endif // SDL_VIRTUALJOYSTICK_C_H |
85 | |