sdl_gesture_haptic.odin 10 KB

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