1 
2 //          Copyright Michael D. Parker 2018.
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 {
34     SDL_HAPTIC_POLAR = 0,
35     SDL_HAPTIC_CARTESIAN = 1,
36     SDL_HAPTIC_SPHERICAL = 2,
37 }
38 
39 enum SDL_HAPTIC_INFINITY = 4294967295U;
40 
41 struct SDL_HapticDirection {
42     ubyte type;
43     int[3] dir;
44 }
45 
46 struct SDL_HapticConstant {
47     ushort type;
48     SDL_HapticDirection direction;
49     uint length;
50     ushort delay;
51     ushort button;
52     ushort interval;
53     short level;
54     ushort attack_length;
55     ushort attack_level;
56     ushort fade_length;
57     ushort fade_level;
58 }
59 
60 struct SDL_HapticPeriodic {
61     ushort type;
62     SDL_HapticDirection direction;
63     uint length;
64     uint delay;
65     ushort button;
66     ushort interval;
67     ushort period;
68     short magnitude;
69     short offset;
70     ushort phase;
71     ushort attack_length;
72     ushort attack_level;
73     ushort fade_length;
74     ushort fade_level;
75 }
76 
77 struct SDL_HapticCondition {
78     ushort type;
79     SDL_HapticDirection direciton;
80     uint length;
81     ushort delay;
82     ushort button;
83     ushort interval;
84     ushort[3] right_sat;
85     ushort[3] left_sat;
86     short[3] right_coeff;
87     short[3] left_coeff;
88     ushort[3] deadband;
89     ushort[3] center;
90 }
91 
92 struct SDL_HapticRamp {
93     ushort type;
94     SDL_HapticDirection direction;
95     uint length;
96     ushort delay;
97     ushort button;
98     ushort interval;
99     short start;
100     short end;
101     ushort attack_length;
102     ushort attack_level;
103     ushort fade_length;
104     ushort fade_level;
105 }
106 
107 struct SDL_HapticLeftRight {
108     ushort type;
109     uint length;
110     ushort large_magnitude;
111     ushort small_magnitude;
112 }
113 
114 struct SDL_HapticCustom {
115     ushort type;
116     SDL_HapticDirection direction;
117     uint length;
118     ushort delay;
119     ushort button;
120     ushort interval;
121     ubyte channels;
122     ushort period;
123     ushort samples;
124     ushort* data;
125     ushort attack_length;
126     ushort attack_level;
127     ushort fade_length;
128     ushort fade_level;
129 }
130 
131 union SDL_HapticEffect {
132     ushort type;
133     SDL_HapticConstant constant;
134     SDL_HapticPeriodic periodic;
135     SDL_HapticCondition condition;
136     SDL_HapticRamp ramp;
137     SDL_HapticLeftRight leftright;
138     SDL_HapticCustom custom;
139 }
140 
141 static if(staticBinding) {
142     extern(C) @nogc nothrow {
143         int SDL_NumHaptics();
144         const(char)* SDL_HapticName(int);
145         SDL_Haptic* SDL_HapticOpen(int);
146         int SDL_HapticOpened(int);
147         int SDL_HapticIndex(SDL_Haptic*);
148         int SDL_MouseIsHaptic();
149         SDL_Haptic* SDL_HapticOpenFromMouse();
150         int SDL_JoystickIsHaptic(SDL_Joystick*);
151         SDL_Haptic* SDL_HapticOpenFromJoystick(SDL_Joystick*);
152         int SDL_HapticClose(SDL_Haptic*);
153         int SDL_HapticNumEffects(SDL_Haptic*);
154         int SDL_HapticNumEffectsPlaying(SDL_Haptic*);
155         uint SDL_HapticQuery(SDL_Haptic*);
156         int SDL_HapticNumAxes(SDL_Haptic*);
157         int SDL_HapticEffectSupported(SDL_Haptic*,SDL_HapticEffect*);
158         int SDL_HapticNewEffect(SDL_Haptic*,SDL_HapticEffect*);
159         int SDL_HapticUpdateEffect(SDL_Haptic*,int,SDL_HapticEffect*);
160         int SDL_HapticRunEffect(SDL_Haptic*,int,uint);
161         int SDL_HapticStopEffect(SDL_Haptic*,int);
162         int SDL_HapticDestroyEffect(SDL_Haptic*,int);
163         int SDL_HapticGetEffectStatus(SDL_Haptic*,int);
164         int SDL_HapticSetGain(SDL_Haptic*,int);
165         int SDL_HapticSetAutocenter(SDL_Haptic*,int);
166         int SDL_HapticPause(SDL_Haptic*);
167         int SDL_HapticUnpause(SDL_Haptic*);
168         int SDL_HapticStopAll(SDL_Haptic*);
169         int SDL_HapticRumbleSupported(SDL_Haptic*);
170         int SDL_HapticRumbleInit(SDL_Haptic*);
171         int SDL_HapticRumblePlay(SDL_Haptic*,float,uint);
172         int SDL_HapticRumbleStop(SDL_Haptic*);
173     }
174 }
175 else {
176     extern(C) @nogc nothrow {
177         alias pSDL_NumHaptics = int function();
178         alias pSDL_HapticName = const(char)* function(int);
179         alias pSDL_HapticOpen = SDL_Haptic* function(int);
180         alias pSDL_HapticOpened = int function(int);
181         alias pSDL_HapticIndex = int function(SDL_Haptic*);
182         alias pSDL_MouseIsHaptic = int function();
183         alias pSDL_HapticOpenFromMouse = SDL_Haptic* function();
184         alias pSDL_JoystickIsHaptic = int function(SDL_Joystick*);
185         alias pSDL_HapticOpenFromJoystick = SDL_Haptic* function(SDL_Joystick*);
186         alias pSDL_HapticClose = int function(SDL_Haptic*);
187         alias pSDL_HapticNumEffects = int function(SDL_Haptic*);
188         alias pSDL_HapticNumEffectsPlaying = int function(SDL_Haptic*);
189         alias pSDL_HapticQuery = uint function(SDL_Haptic*);
190         alias pSDL_HapticNumAxes = int function(SDL_Haptic*);
191         alias pSDL_HapticEffectSupported = int function(SDL_Haptic*,SDL_HapticEffect*);
192         alias pSDL_HapticNewEffect = int function(SDL_Haptic*,SDL_HapticEffect*);
193         alias pSDL_HapticUpdateEffect = int function(SDL_Haptic*,int,SDL_HapticEffect*);
194         alias pSDL_HapticRunEffect = int function(SDL_Haptic*,int,uint);
195         alias pSDL_HapticStopEffect = int function(SDL_Haptic*,int);
196         alias pSDL_HapticDestroyEffect = int function(SDL_Haptic*,int);
197         alias pSDL_HapticGetEffectStatus = int function(SDL_Haptic*,int);
198         alias pSDL_HapticSetGain = int function(SDL_Haptic*,int);
199         alias pSDL_HapticSetAutocenter = int function(SDL_Haptic*,int);
200         alias pSDL_HapticPause = int function(SDL_Haptic*);
201         alias pSDL_HapticUnpause = int function(SDL_Haptic*);
202         alias pSDL_HapticStopAll = int function(SDL_Haptic*);
203         alias pSDL_HapticRumbleSupported = int function(SDL_Haptic*);
204         alias pSDL_HapticRumbleInit = int function(SDL_Haptic*);
205         alias pSDL_HapticRumblePlay = int function(SDL_Haptic*,float,uint);
206         alias pSDL_HapticRumbleStop = int function(SDL_Haptic*);
207     }
208 
209     __gshared {
210         pSDL_NumHaptics SDL_NumHaptics;
211         pSDL_HapticName SDL_HapticName;
212         pSDL_HapticOpen SDL_HapticOpen;
213         pSDL_HapticOpened SDL_HapticOpened;
214         pSDL_HapticIndex SDL_HapticIndex;
215         pSDL_MouseIsHaptic SDL_MouseIsHaptic;
216         pSDL_HapticOpenFromMouse SDL_HapticOpenFromMouse;
217         pSDL_JoystickIsHaptic SDL_JoystickIsHaptic;
218         pSDL_HapticOpenFromJoystick SDL_HapticOpenFromJoystick;
219         pSDL_HapticClose SDL_HapticClose;
220         pSDL_HapticNumEffects SDL_HapticNumEffects;
221         pSDL_HapticNumEffectsPlaying SDL_HapticNumEffectsPlaying;
222         pSDL_HapticQuery SDL_HapticQuery;
223         pSDL_HapticNumAxes SDL_HapticNumAxes;
224         pSDL_HapticEffectSupported SDL_HapticEffectSupported;
225         pSDL_HapticNewEffect SDL_HapticNewEffect;
226         pSDL_HapticUpdateEffect SDL_HapticUpdateEffect;
227         pSDL_HapticRunEffect SDL_HapticRunEffect;
228         pSDL_HapticStopEffect SDL_HapticStopEffect;
229         pSDL_HapticDestroyEffect SDL_HapticDestroyEffect;
230         pSDL_HapticGetEffectStatus SDL_HapticGetEffectStatus;
231         pSDL_HapticSetGain SDL_HapticSetGain;
232         pSDL_HapticSetAutocenter SDL_HapticSetAutocenter;
233         pSDL_HapticPause SDL_HapticPause;
234         pSDL_HapticUnpause SDL_HapticUnpause;
235         pSDL_HapticStopAll SDL_HapticStopAll;
236         pSDL_HapticRumbleSupported SDL_HapticRumbleSupported;
237         pSDL_HapticRumbleInit SDL_HapticRumbleInit;
238         pSDL_HapticRumblePlay SDL_HapticRumblePlay;
239         pSDL_HapticRumbleStop SDL_HapticRumbleStop;
240     }
241 }