sdl_gesture_haptic.odin 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. package sdl2
  2. import "core:c"
  3. when ODIN_OS == .Windows {
  4. foreign import lib "SDL2.lib"
  5. } else {
  6. foreign import lib "system:SDL2"
  7. }
  8. // Gesture
  9. GestureID :: distinct i64
  10. @(default_calling_convention="c", link_prefix="SDL_")
  11. foreign lib {
  12. RecordGesture :: proc(touchId: ^TouchID) -> c.int ---
  13. SaveAllDollarTemplates :: proc(dst: ^RWops) -> c.int ---
  14. SaveDollarTemplate :: proc(gestureId: GestureID, dst: ^RWops) -> c.int ---
  15. LoadDollarTemplates :: proc(touchId: ^TouchID, src: ^RWops) -> c.int ---
  16. }
  17. // Haptic
  18. Haptic :: struct {}
  19. HapticType :: enum u16 {
  20. CONSTANT = 1<<0,
  21. SINE = 1<<1,
  22. LEFTRIGHT = 1<<2,
  23. TRIANGLE = 1<<3,
  24. SAWTOOTHUP = 1<<4,
  25. SAWTOOTHDOWN = 1<<5,
  26. RAMP = 1<<6,
  27. SPRING = 1<<7,
  28. DAMPER = 1<<8,
  29. INERTIA = 1<<9,
  30. FRICTION = 1<<10,
  31. CUSTOM = 1<<11,
  32. GAIN = 1<<12,
  33. AUTOCENTER = 1<<13,
  34. STATUS = 1<<14,
  35. PAUSE = 1<<15,
  36. }
  37. HAPTIC_CONSTANT :: HapticType.CONSTANT
  38. HAPTIC_SINE :: HapticType.SINE
  39. HAPTIC_LEFTRIGHT :: HapticType.LEFTRIGHT
  40. HAPTIC_TRIANGLE :: HapticType.TRIANGLE
  41. HAPTIC_SAWTOOTHUP :: HapticType.SAWTOOTHUP
  42. HAPTIC_SAWTOOTHDOWN :: HapticType.SAWTOOTHDOWN
  43. HAPTIC_RAMP :: HapticType.RAMP
  44. HAPTIC_SPRING :: HapticType.SPRING
  45. HAPTIC_DAMPER :: HapticType.DAMPER
  46. HAPTIC_INERTIA :: HapticType.INERTIA
  47. HAPTIC_FRICTION :: HapticType.FRICTION
  48. HAPTIC_CUSTOM :: HapticType.CUSTOM
  49. HAPTIC_GAIN :: HapticType.GAIN
  50. HAPTIC_AUTOCENTER :: HapticType.AUTOCENTER
  51. HAPTIC_STATUS :: HapticType.STATUS
  52. HAPTIC_PAUSE :: HapticType.PAUSE
  53. HapticDirectionType :: enum u8 {
  54. POLAR = 0,
  55. CARTESIAN = 1,
  56. SPHERICAL = 2,
  57. STEERING_AXIS = 3,
  58. }
  59. HAPTIC_POLAR :: HapticDirectionType.POLAR
  60. HAPTIC_CARTESIAN :: HapticDirectionType.CARTESIAN
  61. HAPTIC_SPHERICAL :: HapticDirectionType.SPHERICAL
  62. HAPTIC_STEERING_AXIS :: HapticDirectionType.STEERING_AXIS
  63. HAPTIC_INFINITY :: 4294967295
  64. HapticDirection :: struct {
  65. type: HapticDirectionType, /**< The type of encoding. */
  66. dir: [3]i32, /**< The encoded direction. */
  67. }
  68. HapticConstant :: struct {
  69. /* Header */
  70. type: HapticType, /**< ::SDL_HAPTIC_CONSTANT */
  71. direction: HapticDirection, /**< Direction of the effect. */
  72. /* Replay */
  73. length: u32, /**< Duration of the effect. */
  74. delay: u16, /**< Delay before starting the effect. */
  75. /* Trigger */
  76. button: u16, /**< Button that triggers the effect. */
  77. interval: u16, /**< How soon it can be triggered again after button. */
  78. /* Constant */
  79. level: i16, /**< Strength of the constant effect. */
  80. /* Envelope */
  81. attack_length: u16, /**< Duration of the attack. */
  82. attack_level: u16, /**< Level at the start of the attack. */
  83. fade_length: u16, /**< Duration of the fade. */
  84. fade_level: u16, /**< Level at the end of the fade. */
  85. }
  86. HapticPeriodic :: struct {
  87. /* Header */
  88. type: HapticType, /**< ::SDL_HAPTIC_SINE, ::SDL_HAPTIC_LEFTRIGHT,
  89. ::SDL_HAPTIC_TRIANGLE, ::SDL_HAPTIC_SAWTOOTHUP or
  90. ::SDL_HAPTIC_SAWTOOTHDOWN */
  91. direction: HapticDirection, /**< Direction of the effect. */
  92. /* Replay */
  93. length: u32, /**< Duration of the effect. */
  94. delay: u16, /**< Delay before starting the effect. */
  95. /* Trigger */
  96. button: u16, /**< Button that triggers the effect. */
  97. interval: u16, /**< How soon it can be triggered again after button. */
  98. /* Periodic */
  99. period: u16, /**< Period of the wave. */
  100. magnitude: i16, /**< Peak value; if negative, equivalent to 180 degrees extra phase shift. */
  101. offset: i16, /**< Mean value of the wave. */
  102. phase: u16, /**< Positive phase shift given by hundredth of a degree. */
  103. /* Envelope */
  104. attack_length: u16, /**< Duration of the attack. */
  105. attack_level: u16, /**< Level at the start of the attack. */
  106. fade_length: u16, /**< Duration of the fade. */
  107. fade_level: u16, /**< Level at the end of the fade. */
  108. }
  109. HapticCondition :: struct {
  110. /* Header */
  111. type: HapticType, /**< ::SDL_HAPTIC_SPRING, ::SDL_HAPTIC_DAMPER,
  112. ::SDL_HAPTIC_INERTIA or ::SDL_HAPTIC_FRICTION */
  113. direction: HapticDirection, /**< Direction of the effect - Not used ATM. */
  114. /* Replay */
  115. length: u32, /**< Duration of the effect. */
  116. delay: u16, /**< Delay before starting the effect. */
  117. /* Trigger */
  118. button: u16, /**< Button that triggers the effect. */
  119. interval: u16, /**< How soon it can be triggered again after button. */
  120. /* Condition */
  121. right_sat: [3]u16, /**< Level when joystick is to the positive side; max 0xFFFF. */
  122. left_sat: [3]u16, /**< Level when joystick is to the negative side; max 0xFFFF. */
  123. right_coeff: [3]i16, /**< How fast to increase the force towards the positive side. */
  124. left_coeff: [3]i16, /**< How fast to increase the force towards the negative side. */
  125. deadband: [3]u16, /**< Size of the dead zone; max 0xFFFF: whole axis-range when 0-centered. */
  126. center: [3]i16, /**< Position of the dead zone. */
  127. }
  128. HapticRamp :: struct {
  129. /* Header */
  130. type: HapticType, /**< ::SDL_HAPTIC_RAMP */
  131. direction: HapticDirection, /**< Direction of the effect. */
  132. /* Replay */
  133. length: u32, /**< Duration of the effect. */
  134. delay: u16, /**< Delay before starting the effect. */
  135. /* Trigger */
  136. button: u16, /**< Button that triggers the effect. */
  137. interval: u16, /**< How soon it can be triggered again after button. */
  138. /* Ramp */
  139. start: i16, /**< Beginning strength level. */
  140. end: i16, /**< Ending strength level. */
  141. /* Envelope */
  142. attack_length: u16, /**< Duration of the attack. */
  143. attack_level: u16, /**< Level at the start of the attack. */
  144. fade_length: u16, /**< Duration of the fade. */
  145. fade_level: u16, /**< Level at the end of the fade. */
  146. }
  147. HapticLeftRight :: struct {
  148. /* Header */
  149. type: HapticType, /**< ::SDL_HAPTIC_LEFTRIGHT */
  150. /* Replay */
  151. length: u32, /**< Duration of the effect in milliseconds. */
  152. /* Rumble */
  153. large_magnitude: u16, /**< Control of the large controller motor. */
  154. small_magnitude: u16, /**< Control of the small controller motor. */
  155. }
  156. HapticCustom :: struct {
  157. /* Header */
  158. type: HapticType, /**< ::SDL_HAPTIC_CUSTOM */
  159. direction: HapticDirection, /**< Direction of the effect. */
  160. /* Replay */
  161. length: u32, /**< Duration of the effect. */
  162. delay: u16, /**< Delay before starting the effect. */
  163. /* Trigger */
  164. button: u16, /**< Button that triggers the effect. */
  165. interval: u16, /**< How soon it can be triggered again after button. */
  166. /* Custom */
  167. channels: u8, /**< Axes to use, minimum of one. */
  168. period: u16, /**< Sample periods. */
  169. samples: u16, /**< Amount of samples. */
  170. data: [^]u16, /**< Should contain channels*samples items. */
  171. /* Envelope */
  172. attack_length: u16, /**< Duration of the attack. */
  173. attack_level: u16, /**< Level at the start of the attack. */
  174. fade_length: u16, /**< Duration of the fade. */
  175. fade_level: u16, /**< Level at the end of the fade. */
  176. }
  177. HapticEffect :: struct #raw_union {
  178. /* Common for all force feedback effects */
  179. type: HapticType, /**< Effect type. */
  180. constant: HapticConstant, /**< Constant effect. */
  181. periodic: HapticPeriodic, /**< Periodic effect. */
  182. condition: HapticCondition, /**< Condition effect. */
  183. ramp: HapticRamp, /**< Ramp effect. */
  184. leftright: HapticLeftRight, /**< Left/Right effect. */
  185. custom: HapticCustom, /**< Custom effect. */
  186. }
  187. @(default_calling_convention="c", link_prefix="SDL_")
  188. foreign lib {
  189. NumHaptics :: proc() -> c.int ---
  190. HapticName :: proc(device_index: c.int) -> cstring ---
  191. HapticOpen :: proc(device_index: c.int) -> ^Haptic ---
  192. HapticOpened :: proc(device_index: c.int) -> c.int ---
  193. HapticIndex :: proc(haptic: ^Haptic) -> c.int ---
  194. MouseIsHaptic :: proc() -> c.int ---
  195. HapticOpenFromMouse :: proc() -> ^Haptic ---
  196. JoystickIsHaptic :: proc(joystick: ^Joystick) -> c.int ---
  197. HapticOpenFromJoystick :: proc(joystick: ^Joystick) -> ^Haptic ---
  198. HapticClose :: proc(haptic: ^Haptic) ---
  199. HapticNumEffects :: proc(haptic: ^Haptic) -> c.int ---
  200. HapticNumEffectsPlaying :: proc(haptic: ^Haptic) -> c.int ---
  201. HapticQuery :: proc(haptic: ^Haptic) -> c.uint ---
  202. HapticNumAxes :: proc(haptic: ^Haptic) -> c.int ---
  203. HapticEffectSupported :: proc(haptic: ^Haptic, effect: ^HapticEffect) -> c.int ---
  204. HapticNewEffect :: proc(haptic: ^Haptic, effect: ^HapticEffect) -> c.int ---
  205. HapticUpdateEffect :: proc(haptic: ^Haptic, effect: c.int, data: ^HapticEffect) -> c.int ---
  206. HapticRunEffect :: proc(haptic: ^Haptic, effect: c.int, iterations: u32) -> c.int ---
  207. HapticStopEffect :: proc(haptic: ^Haptic, effect: c.int) -> c.int ---
  208. HapticDestroyEffect :: proc(haptic: ^Haptic, effect: c.int) ---
  209. HapticGetEffectStatus :: proc(haptic: ^Haptic, effect: c.int) -> c.int ---
  210. HapticSetGain :: proc(haptic: ^Haptic, gain: c.int) -> c.int ---
  211. HapticSetAutocenter :: proc(haptic: ^Haptic, autocenter: c.int) -> c.int ---
  212. HapticPause :: proc(haptic: ^Haptic) -> c.int ---
  213. HapticUnpause :: proc(haptic: ^Haptic) -> c.int ---
  214. HapticStopAll :: proc(haptic: ^Haptic) -> c.int ---
  215. HapticRumbleSupported :: proc(haptic: ^Haptic) -> c.int ---
  216. HapticRumbleInit :: proc(haptic: ^Haptic) -> c.int ---
  217. HapticRumblePlay :: proc(haptic: ^Haptic, strength: f32, length: u32) -> c.int ---
  218. HapticRumbleStop :: proc(haptic: ^Haptic) -> c.int ---
  219. }