1 /+
2 +            Copyright 2022 – 2023 Aya Partridge
3 +          Copyright 2018 - 2022 Michael D. Parker
4 + Distributed under the Boost Software License, Version 1.0.
5 +     (See accompanying file LICENSE_1_0.txt or copy at
6 +           http://www.boost.org/LICENSE_1_0.txt)
7 +/
8 module sdl.haptic;
9 
10 import bindbc.sdl.config;
11 import bindbc.sdl.codegen;
12 
13 import sdl.joystick: SDL_Joystick;
14 
15 struct SDL_Haptic;
16 
17 enum: ushort{
18 	SDL_HAPTIC_CONSTANT      = 1U<<0,
19 	SDL_HAPTIC_SINE          = 1U<<1,
20 	SDL_HAPTIC_LEFTRIGHT     = 1U<<2,
21 	SDL_HAPTIC_TRIANGLE      = 1U<<3,
22 	SDL_HAPTIC_SAWTOOTHUP    = 1U<<4,
23 	SDL_HAPTIC_SAWTOOTHDOWN  = 1U<<5,
24 	SDL_HAPTIC_RAMP          = 1U<<6,
25 	SDL_HAPTIC_SPRING        = 1U<<7,
26 	SDL_HAPTIC_DAMPER        = 1U<<8,
27 	SDL_HAPTIC_INERTIA       = 1U<<9,
28 	SDL_HAPTIC_FRICTION      = 1U<<10,
29 	SDL_HAPTIC_CUSTOM        = 1U<<11,
30 	SDL_HAPTIC_GAIN          = 1U<<12,
31 	SDL_HAPTIC_AUTOCENTER    = 1U<<13,
32 	SDL_HAPTIC_STATUS        = 1U<<14,
33 	SDL_HAPTIC_PAUSE         = 1U<<15,
34 }
35 
36 enum: uint{
37 	SDL_HAPTIC_POLAR = 0,
38 	SDL_HAPTIC_CARTESIAN = 1,
39 	SDL_HAPTIC_SPHERICAL = 2,
40 	SDL_HAPTIC_INFINITY = 4294967295U,
41 }
42 static if(sdlSupport >= SDLSupport.v2_0_14)
43 enum: uint{
44 	SDL_HAPTIC_STEERING_AXIS = 3,
45 }
46 
47 struct SDL_HapticDirection{
48 	ubyte type;
49 	int[3] dir;
50 }
51 
52 struct SDL_HapticConstant{
53 	ushort type;
54 	SDL_HapticDirection direction;
55 	
56 	uint length;
57 	ushort delay;
58 	
59 	ushort button;
60 	ushort interval;
61 	
62 	short level;
63 	
64 	ushort attack_length;
65 	ushort attack_level;
66 	ushort fade_length;
67 	ushort fade_level;
68 }
69 
70 struct SDL_HapticPeriodic{
71 	ushort type;
72 	SDL_HapticDirection direction;
73 	
74 	uint length;
75 	ushort delay;
76 	
77 	ushort button;
78 	ushort interval;
79 	
80 	ushort period;
81 	short magnitude;
82 	short offset;
83 	ushort phase;
84 	
85 	ushort attack_length;
86 	ushort attack_level;
87 	ushort fade_length;
88 	ushort fade_level;
89 }
90 
91 struct SDL_HapticCondition{
92 	ushort type;
93 	SDL_HapticDirection direciton;
94 	
95 	uint length;
96 	ushort delay;
97 	
98 	ushort button;
99 	ushort interval;
100 	
101 	ushort[3] right_sat;
102 	ushort[3] left_sat;
103 	short[3] right_coeff;
104 	short[3] left_coeff;
105 	ushort[3] deadband;
106 	short[3] center;
107 }
108 
109 struct SDL_HapticRamp{
110 	ushort type;
111 	SDL_HapticDirection direction;
112 	
113 	uint length;
114 	ushort delay;
115 	
116 	ushort button;
117 	ushort interval;
118 	
119 	short start;
120 	short end;
121 	
122 	ushort attack_length;
123 	ushort attack_level;
124 	ushort fade_length;
125 	ushort fade_level;
126 }
127 
128 struct SDL_HapticLeftRight{
129 	ushort type;
130 	
131 	uint length;
132 	
133 	ushort large_magnitude;
134 	ushort small_magnitude;
135 }
136 
137 struct SDL_HapticCustom{
138 	ushort type;
139 	SDL_HapticDirection direction;
140 	
141 	uint length;
142 	ushort delay;
143 	
144 	ushort button;
145 	ushort interval;
146 	
147 	ubyte channels;
148 	ushort period;
149 	ushort samples;
150 	ushort* data;
151 	
152 	ushort attack_length;
153 	ushort attack_level;
154 	ushort fade_length;
155 	ushort fade_level;
156 }
157 
158 union SDL_HapticEffect{
159 	ushort type;
160 	SDL_HapticConstant constant;
161 	SDL_HapticPeriodic periodic;
162 	SDL_HapticCondition condition;
163 	SDL_HapticRamp ramp;
164 	SDL_HapticLeftRight leftright;
165 	SDL_HapticCustom custom;
166 }
167 
168 mixin(joinFnBinds((){
169 	string[][] ret;
170 	ret ~= makeFnBinds([
171 		[q{int}, q{SDL_NumHaptics}, q{}],
172 		[q{const(char)*}, q{SDL_HapticName}, q{int device_index}],
173 		[q{SDL_Haptic*}, q{SDL_HapticOpen}, q{int device_index}],
174 		[q{int}, q{SDL_HapticOpened}, q{int device_index}],
175 		[q{int}, q{SDL_HapticIndex}, q{SDL_Haptic* haptic}],
176 		[q{int}, q{SDL_MouseIsHaptic}, q{}],
177 		[q{SDL_Haptic*}, q{SDL_HapticOpenFromMouse}, q{}],
178 		[q{int}, q{SDL_JoystickIsHaptic}, q{SDL_Joystick* joystick}],
179 		[q{SDL_Haptic*}, q{SDL_HapticOpenFromJoystick}, q{SDL_Joystick* joystick}],
180 		[q{void}, q{SDL_HapticClose}, q{SDL_Haptic* haptic}],
181 		[q{int}, q{SDL_HapticNumEffects}, q{SDL_Haptic* haptic}],
182 		[q{int}, q{SDL_HapticNumEffectsPlaying}, q{SDL_Haptic* haptic}],
183 		[q{uint}, q{SDL_HapticQuery}, q{SDL_Haptic* haptic}],
184 		[q{int}, q{SDL_HapticNumAxes}, q{SDL_Haptic* haptic}],
185 		[q{int}, q{SDL_HapticEffectSupported}, q{SDL_Haptic* haptic, SDL_HapticEffect* effect}],
186 		[q{int}, q{SDL_HapticNewEffect}, q{SDL_Haptic* haptic, SDL_HapticEffect* effect}],
187 		[q{int}, q{SDL_HapticUpdateEffect}, q{SDL_Haptic* haptic, int effect, SDL_HapticEffect* data}],
188 		[q{int}, q{SDL_HapticRunEffect}, q{SDL_Haptic* haptic, int effect, uint iterations}],
189 		[q{int}, q{SDL_HapticStopEffect}, q{SDL_Haptic* haptic, int effect}],
190 		[q{int}, q{SDL_HapticDestroyEffect}, q{SDL_Haptic* haptic, int effect}],
191 		[q{int}, q{SDL_HapticGetEffectStatus}, q{SDL_Haptic* haptic, int effect}],
192 		[q{int}, q{SDL_HapticSetGain}, q{SDL_Haptic* haptic, int gain}],
193 		[q{int}, q{SDL_HapticSetAutocenter}, q{SDL_Haptic* haptic, int autocenter}],
194 		[q{int}, q{SDL_HapticPause}, q{SDL_Haptic* haptic}],
195 		[q{int}, q{SDL_HapticUnpause}, q{SDL_Haptic* haptic}],
196 		[q{int}, q{SDL_HapticStopAll}, q{SDL_Haptic* haptic}],
197 		[q{int}, q{SDL_HapticRumbleSupported}, q{SDL_Haptic* haptic}],
198 		[q{int}, q{SDL_HapticRumbleInit}, q{SDL_Haptic* haptic}],
199 		[q{int}, q{SDL_HapticRumblePlay}, q{SDL_Haptic* haptic, float strength, uint length}],
200 		[q{int}, q{SDL_HapticRumbleStop}, q{SDL_Haptic* haptic}],
201 	]);
202 	return ret;
203 }()));