sdl_gesture_haptic.odin 9.9 KB

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