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.bind.sdljoystick : SDL_Joystick; 10 11 struct SDL_Haptic; 12 13 enum : ushort { 14 SDL_HAPTIC_CONSTANT = 1u<<0, 15 SDL_HAPTIC_SINE = 1u<<1, 16 SDL_HAPTIC_LEFTRIGHT = 1u<<2, 17 SDL_HAPTIC_TRIANGLE = 1u<<3, 18 SDL_HAPTIC_SAWTOOTHUP = 1u<<4, 19 SDL_HAPTIC_SAWTOOTHDOWN = 1u<<5, 20 SDL_HAPTIC_RAMP = 1u<<6, 21 SDL_HAPTIC_SPRING = 1u<<7, 22 SDL_HAPTIC_DAMPER = 1u<<8, 23 SDL_HAPTIC_INERTIA = 1u<<9, 24 SDL_HAPTIC_FRICTION = 1u<<10, 25 SDL_HAPTIC_CUSTOM = 1u<<11, 26 SDL_HAPTIC_GAIN = 1u<<12, 27 SDL_HAPTIC_AUTOCENTER = 1u<<13, 28 SDL_HAPTIC_STATUS = 1u<<14, 29 SDL_HAPTIC_PAUSE = 1u<<15, 30 } 31 32 enum { 33 SDL_HAPTIC_POLAR = 0, 34 SDL_HAPTIC_CARTESIAN = 1, 35 SDL_HAPTIC_SPHERICAL = 2, 36 } 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 version(BindSDL_Static) { 141 extern(C) @nogc nothrow { 142 int SDL_NumHaptics(); 143 const(char)* SDL_HapticName(int); 144 SDL_Haptic* SDL_HapticOpen(int); 145 int SDL_HapticOpened(int); 146 int SDL_HapticIndex(SDL_Haptic*); 147 int SDL_MouseIsHaptic(); 148 SDL_Haptic* SDL_HapticOpenFromMouse(); 149 int SDL_JoystickIsHaptic(SDL_Joystick*); 150 SDL_Haptic* SDL_HapticOpenFromJoystick(SDL_Joystick*); 151 int SDL_HapticClose(SDL_Haptic*); 152 int SDL_HapticNumEffects(SDL_Haptic*); 153 int SDL_HapticNumEffectsPlaying(SDL_Haptic*); 154 uint SDL_HapticQuery(SDL_Haptic*); 155 int SDL_HapticNumAxes(SDL_Haptic*); 156 int SDL_HapticEffectSupported(SDL_Haptic*,SDL_HapticEffect*); 157 int SDL_HapticNewEffect(SDL_Haptic*,SDL_HapticEffect*); 158 int SDL_HapticUpdateEffect(SDL_Haptic*,int,SDL_HapticEffect*); 159 int SDL_HapticRunEffect(SDL_Haptic*,int,uint); 160 int SDL_HapticStopEffect(SDL_Haptic*,int); 161 int SDL_HapticDestroyEffect(SDL_Haptic*,int); 162 int SDL_HapticGetEffectStatus(SDL_Haptic*,int); 163 int SDL_HapticSetGain(SDL_Haptic*,int); 164 int SDL_HapticSetAutocenter(SDL_Haptic*,int); 165 int SDL_HapticPause(SDL_Haptic*); 166 int SDL_HapticUnpause(SDL_Haptic*); 167 int SDL_HapticStopAll(SDL_Haptic*); 168 int SDL_HapticRumbleSupported(SDL_Haptic*); 169 int SDL_HapticRumbleInit(SDL_Haptic*); 170 int SDL_HapticRumblePlay(SDL_Haptic*,float,uint); 171 int SDL_HapticRumbleStop(SDL_Haptic*); 172 } 173 } 174 else { 175 extern(C) @nogc nothrow { 176 alias pSDL_NumHaptics = int function(); 177 alias pSDL_HapticName = const(char)* function(int); 178 alias pSDL_HapticOpen = SDL_Haptic* function(int); 179 alias pSDL_HapticOpened = int function(int); 180 alias pSDL_HapticIndex = int function(SDL_Haptic*); 181 alias pSDL_MouseIsHaptic = int function(); 182 alias pSDL_HapticOpenFromMouse = SDL_Haptic* function(); 183 alias pSDL_JoystickIsHaptic = int function(SDL_Joystick*); 184 alias pSDL_HapticOpenFromJoystick = SDL_Haptic* function(SDL_Joystick*); 185 alias pSDL_HapticClose = int function(SDL_Haptic*); 186 alias pSDL_HapticNumEffects = int function(SDL_Haptic*); 187 alias pSDL_HapticNumEffectsPlaying = int function(SDL_Haptic*); 188 alias pSDL_HapticQuery = uint function(SDL_Haptic*); 189 alias pSDL_HapticNumAxes = int function(SDL_Haptic*); 190 alias pSDL_HapticEffectSupported = int function(SDL_Haptic*,SDL_HapticEffect*); 191 alias pSDL_HapticNewEffect = int function(SDL_Haptic*,SDL_HapticEffect*); 192 alias pSDL_HapticUpdateEffect = int function(SDL_Haptic*,int,SDL_HapticEffect*); 193 alias pSDL_HapticRunEffect = int function(SDL_Haptic*,int,uint); 194 alias pSDL_HapticStopEffect = int function(SDL_Haptic*,int); 195 alias pSDL_HapticDestroyEffect = int function(SDL_Haptic*,int); 196 alias pSDL_HapticGetEffectStatus = int function(SDL_Haptic*,int); 197 alias pSDL_HapticSetGain = int function(SDL_Haptic*,int); 198 alias pSDL_HapticSetAutocenter = int function(SDL_Haptic*,int); 199 alias pSDL_HapticPause = int function(SDL_Haptic*); 200 alias pSDL_HapticUnpause = int function(SDL_Haptic*); 201 alias pSDL_HapticStopAll = int function(SDL_Haptic*); 202 alias pSDL_HapticRumbleSupported = int function(SDL_Haptic*); 203 alias pSDL_HapticRumbleInit = int function(SDL_Haptic*); 204 alias pSDL_HapticRumblePlay = int function(SDL_Haptic*,float,uint); 205 alias pSDL_HapticRumbleStop = int function(SDL_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 }