1 
2 //          Copyright 2018 - 2021 Michael D. Parker
3 // Distributed under the Boost Software License, Version 1.0.
4 //    (See accompanying file LICENSE_1_0.txt or copy at
5 //          http://www.boost.org/LICENSE_1_0.txt)
6 
7 module bindbc.sdl.bind.sdlhaptic;
8 
9 import bindbc.sdl.config;
10 import bindbc.sdl.bind.sdljoystick : SDL_Joystick;
11 
12 struct SDL_Haptic;
13 
14 enum : ushort {
15     SDL_HAPTIC_CONSTANT = 1u<<0,
16     SDL_HAPTIC_SINE = 1u<<1,
17     SDL_HAPTIC_LEFTRIGHT = 1u<<2,
18     SDL_HAPTIC_TRIANGLE = 1u<<3,
19     SDL_HAPTIC_SAWTOOTHUP = 1u<<4,
20     SDL_HAPTIC_SAWTOOTHDOWN = 1u<<5,
21     SDL_HAPTIC_RAMP = 1u<<6,
22     SDL_HAPTIC_SPRING = 1u<<7,
23     SDL_HAPTIC_DAMPER = 1u<<8,
24     SDL_HAPTIC_INERTIA = 1u<<9,
25     SDL_HAPTIC_FRICTION = 1u<<10,
26     SDL_HAPTIC_CUSTOM = 1u<<11,
27     SDL_HAPTIC_GAIN = 1u<<12,
28     SDL_HAPTIC_AUTOCENTER = 1u<<13,
29     SDL_HAPTIC_STATUS = 1u<<14,
30     SDL_HAPTIC_PAUSE = 1u<<15,
31 }
32 
33 enum SDL_HAPTIC_POLAR = 0;
34 enum SDL_HAPTIC_CARTESIAN = 1;
35 enum SDL_HAPTIC_SPHERICAL = 2;
36 static if(sdlSupport >= SDLSupport.sdl2014) enum SDL_HAPTIC_STEERING_AXIS = 3;
37 
38 enum SDL_HAPTIC_INFINITY = 4294967295U;
39 
40 struct SDL_HapticDirection {
41     ubyte type;
42     int[3] dir;
43 }
44 
45 struct SDL_HapticConstant {
46     ushort type;
47     SDL_HapticDirection direction;
48     uint length;
49     ushort delay;
50     ushort button;
51     ushort interval;
52     short level;
53     ushort attack_length;
54     ushort attack_level;
55     ushort fade_length;
56     ushort fade_level;
57 }
58 
59 struct SDL_HapticPeriodic {
60     ushort type;
61     SDL_HapticDirection direction;
62     uint length;
63     uint delay;
64     ushort button;
65     ushort interval;
66     ushort period;
67     short magnitude;
68     short offset;
69     ushort phase;
70     ushort attack_length;
71     ushort attack_level;
72     ushort fade_length;
73     ushort fade_level;
74 }
75 
76 struct SDL_HapticCondition {
77     ushort type;
78     SDL_HapticDirection direciton;
79     uint length;
80     ushort delay;
81     ushort button;
82     ushort interval;
83     ushort[3] right_sat;
84     ushort[3] left_sat;
85     short[3] right_coeff;
86     short[3] left_coeff;
87     ushort[3] deadband;
88     ushort[3] center;
89 }
90 
91 struct SDL_HapticRamp {
92     ushort type;
93     SDL_HapticDirection direction;
94     uint length;
95     ushort delay;
96     ushort button;
97     ushort interval;
98     short start;
99     short end;
100     ushort attack_length;
101     ushort attack_level;
102     ushort fade_length;
103     ushort fade_level;
104 }
105 
106 struct SDL_HapticLeftRight {
107     ushort type;
108     uint length;
109     ushort large_magnitude;
110     ushort small_magnitude;
111 }
112 
113 struct SDL_HapticCustom {
114     ushort type;
115     SDL_HapticDirection direction;
116     uint length;
117     ushort delay;
118     ushort button;
119     ushort interval;
120     ubyte channels;
121     ushort period;
122     ushort samples;
123     ushort* data;
124     ushort attack_length;
125     ushort attack_level;
126     ushort fade_length;
127     ushort fade_level;
128 }
129 
130 union SDL_HapticEffect {
131     ushort type;
132     SDL_HapticConstant constant;
133     SDL_HapticPeriodic periodic;
134     SDL_HapticCondition condition;
135     SDL_HapticRamp ramp;
136     SDL_HapticLeftRight leftright;
137     SDL_HapticCustom custom;
138 }
139 
140 static if(staticBinding) {
141     extern(C) @nogc nothrow {
142         int SDL_NumHaptics();
143         const(char)* SDL_HapticName(int device_index);
144         SDL_Haptic* SDL_HapticOpen(int device_index);
145         int SDL_HapticOpened(int device_index);
146         int SDL_HapticIndex(SDL_Haptic* haptic);
147         int SDL_MouseIsHaptic();
148         SDL_Haptic* SDL_HapticOpenFromMouse();
149         int SDL_JoystickIsHaptic(SDL_Joystick* joystick);
150         SDL_Haptic* SDL_HapticOpenFromJoystick(SDL_Joystick* joystick);
151         int SDL_HapticClose(SDL_Haptic* haptic);
152         int SDL_HapticNumEffects(SDL_Haptic* haptic);
153         int SDL_HapticNumEffectsPlaying(SDL_Haptic* haptic);
154         uint SDL_HapticQuery(SDL_Haptic* haptic);
155         int SDL_HapticNumAxes(SDL_Haptic* haptic);
156         int SDL_HapticEffectSupported(SDL_Haptic* haptic, SDL_HapticEffect* effect);
157         int SDL_HapticNewEffect(SDL_Haptic* haptic, SDL_HapticEffect* effect);
158         int SDL_HapticUpdateEffect(SDL_Haptic* haptic, int effect, SDL_HapticEffect* data);
159         int SDL_HapticRunEffect(SDL_Haptic* haptic, int effect, uint iterations);
160         int SDL_HapticStopEffect(SDL_Haptic* haptic, int effect);
161         int SDL_HapticDestroyEffect(SDL_Haptic* haptic, int effect);
162         int SDL_HapticGetEffectStatus(SDL_Haptic* haptic, int effect);
163         int SDL_HapticSetGain(SDL_Haptic* haptic, int gain);
164         int SDL_HapticSetAutocenter(SDL_Haptic* haptic, int autocenter);
165         int SDL_HapticPause(SDL_Haptic* haptic);
166         int SDL_HapticUnpause(SDL_Haptic* haptic);
167         int SDL_HapticStopAll(SDL_Haptic* haptic);
168         int SDL_HapticRumbleSupported(SDL_Haptic* haptic);
169         int SDL_HapticRumbleInit(SDL_Haptic* haptic);
170         int SDL_HapticRumblePlay(SDL_Haptic* haptic, float strength, uint length);
171         int SDL_HapticRumbleStop(SDL_Haptic* haptic);
172     }
173 }
174 else {
175     extern(C) @nogc nothrow {
176         alias pSDL_NumHaptics = int function();
177         alias pSDL_HapticName = const(char)* function(int device_index);
178         alias pSDL_HapticOpen = SDL_Haptic* function(int device_index);
179         alias pSDL_HapticOpened = int function(int device_index);
180         alias pSDL_HapticIndex = int function(SDL_Haptic* haptic);
181         alias pSDL_MouseIsHaptic = int function();
182         alias pSDL_HapticOpenFromMouse = SDL_Haptic* function();
183         alias pSDL_JoystickIsHaptic = int function(SDL_Joystick* joystick);
184         alias pSDL_HapticOpenFromJoystick = SDL_Haptic* function(SDL_Joystick* joystick);
185         alias pSDL_HapticClose = int function(SDL_Haptic* haptic);
186         alias pSDL_HapticNumEffects = int function(SDL_Haptic* haptic);
187         alias pSDL_HapticNumEffectsPlaying = int function(SDL_Haptic* haptic);
188         alias pSDL_HapticQuery = uint function(SDL_Haptic* haptic);
189         alias pSDL_HapticNumAxes = int function(SDL_Haptic* haptic);
190         alias pSDL_HapticEffectSupported = int function(SDL_Haptic* haptic, SDL_HapticEffect* effect);
191         alias pSDL_HapticNewEffect = int function(SDL_Haptic* haptic, SDL_HapticEffect* effect);
192         alias pSDL_HapticUpdateEffect = int function(SDL_Haptic* haptic, int effect, SDL_HapticEffect* data);
193         alias pSDL_HapticRunEffect = int function(SDL_Haptic* haptic, int effect, uint iterations);
194         alias pSDL_HapticStopEffect = int function(SDL_Haptic* haptic, int effect);
195         alias pSDL_HapticDestroyEffect = int function(SDL_Haptic* haptic, int effect);
196         alias pSDL_HapticGetEffectStatus = int function(SDL_Haptic* haptic, int effect);
197         alias pSDL_HapticSetGain = int function(SDL_Haptic* haptic, int gain);
198         alias pSDL_HapticSetAutocenter = int function(SDL_Haptic* haptic, int autocenter);
199         alias pSDL_HapticPause = int function(SDL_Haptic* haptic);
200         alias pSDL_HapticUnpause = int function(SDL_Haptic* haptic);
201         alias pSDL_HapticStopAll = int function(SDL_Haptic* haptic);
202         alias pSDL_HapticRumbleSupported = int function(SDL_Haptic* haptic);
203         alias pSDL_HapticRumbleInit = int function(SDL_Haptic* haptic);
204         alias pSDL_HapticRumblePlay = int function(SDL_Haptic* haptic, float strength, uint length);
205         alias pSDL_HapticRumbleStop = int function(SDL_Haptic* haptic);
206     }
207 
208     __gshared {
209         pSDL_NumHaptics SDL_NumHaptics;
210         pSDL_HapticName SDL_HapticName;
211         pSDL_HapticOpen SDL_HapticOpen;
212         pSDL_HapticOpened SDL_HapticOpened;
213         pSDL_HapticIndex SDL_HapticIndex;
214         pSDL_MouseIsHaptic SDL_MouseIsHaptic;
215         pSDL_HapticOpenFromMouse SDL_HapticOpenFromMouse;
216         pSDL_JoystickIsHaptic SDL_JoystickIsHaptic;
217         pSDL_HapticOpenFromJoystick SDL_HapticOpenFromJoystick;
218         pSDL_HapticClose SDL_HapticClose;
219         pSDL_HapticNumEffects SDL_HapticNumEffects;
220         pSDL_HapticNumEffectsPlaying SDL_HapticNumEffectsPlaying;
221         pSDL_HapticQuery SDL_HapticQuery;
222         pSDL_HapticNumAxes SDL_HapticNumAxes;
223         pSDL_HapticEffectSupported SDL_HapticEffectSupported;
224         pSDL_HapticNewEffect SDL_HapticNewEffect;
225         pSDL_HapticUpdateEffect SDL_HapticUpdateEffect;
226         pSDL_HapticRunEffect SDL_HapticRunEffect;
227         pSDL_HapticStopEffect SDL_HapticStopEffect;
228         pSDL_HapticDestroyEffect SDL_HapticDestroyEffect;
229         pSDL_HapticGetEffectStatus SDL_HapticGetEffectStatus;
230         pSDL_HapticSetGain SDL_HapticSetGain;
231         pSDL_HapticSetAutocenter SDL_HapticSetAutocenter;
232         pSDL_HapticPause SDL_HapticPause;
233         pSDL_HapticUnpause SDL_HapticUnpause;
234         pSDL_HapticStopAll SDL_HapticStopAll;
235         pSDL_HapticRumbleSupported SDL_HapticRumbleSupported;
236         pSDL_HapticRumbleInit SDL_HapticRumbleInit;
237         pSDL_HapticRumblePlay SDL_HapticRumblePlay;
238         pSDL_HapticRumbleStop SDL_HapticRumbleStop;
239     }
240 }