sdl_gamecontroller.odin 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. GameController :: struct {}
  8. GameControllerType :: enum c.int {
  9. UNKNOWN = 0,
  10. XBOX360,
  11. XBOXONE,
  12. PS3,
  13. PS4,
  14. NINTENDO_SWITCH_PRO,
  15. VIRTUAL,
  16. PS5,
  17. AMAZON_LUNA,
  18. GOOGLE_STADIA,
  19. }
  20. GameControllerBindType :: enum c.int {
  21. NONE = 0,
  22. BUTTON,
  23. AXIS,
  24. HAT,
  25. }
  26. GameControllerButtonBind :: struct {
  27. bindType: GameControllerBindType,
  28. value: struct #raw_union {
  29. button: c.int,
  30. axis: c.int,
  31. hat: struct {
  32. hat: c.int,
  33. hat_mask: c.int,
  34. },
  35. },
  36. }
  37. GameControllerAxis :: enum c.int {
  38. INVALID = -1,
  39. LEFTX,
  40. LEFTY,
  41. RIGHTX,
  42. RIGHTY,
  43. TRIGGERLEFT,
  44. TRIGGERRIGHT,
  45. MAX,
  46. }
  47. GameControllerButton :: enum c.int {
  48. INVALID = -1,
  49. A,
  50. B,
  51. X,
  52. Y,
  53. BACK,
  54. GUIDE,
  55. START,
  56. LEFTSTICK,
  57. RIGHTSTICK,
  58. LEFTSHOULDER,
  59. RIGHTSHOULDER,
  60. DPAD_UP,
  61. DPAD_DOWN,
  62. DPAD_LEFT,
  63. DPAD_RIGHT,
  64. MISC1, /* Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Amazon Luna microphone button */
  65. PADDLE1, /* Xbox Elite paddle P1 */
  66. PADDLE2, /* Xbox Elite paddle P3 */
  67. PADDLE3, /* Xbox Elite paddle P2 */
  68. PADDLE4, /* Xbox Elite paddle P4 */
  69. TOUCHPAD, /* PS4/PS5 touchpad button */
  70. MAX,
  71. }
  72. GameControllerAddMappingsFromFile :: #force_inline proc "c" (file: cstring) -> c.int {
  73. return GameControllerAddMappingsFromRW(RWFromFile(file, "rb"), true)
  74. }
  75. @(default_calling_convention="c", link_prefix="SDL_")
  76. foreign lib {
  77. GameControllerAddMappingsFromRW :: proc(rw: ^RWops, freerw: bool) -> c.int ---
  78. GameControllerAddMapping :: proc(mappingString: cstring) -> c.int ---
  79. GameControllerNumMappings :: proc() -> c.int ---
  80. GameControllerMappingForIndex :: proc(mapping_index: c.int) -> cstring ---
  81. GameControllerMappingForGUID :: proc(guid: JoystickGUID) -> cstring ---
  82. GameControllerMapping :: proc(gamecontroller: ^GameController) -> cstring ---
  83. IsGameController :: proc(joystick_index: c.int) -> bool ---
  84. GameControllerNameForIndex :: proc(joystick_index: c.int) -> cstring ---
  85. GameControllerTypeForIndex :: proc(joystick_index: c.int) -> GameControllerType ---
  86. GameControllerMappingForDeviceIndex :: proc(joystick_index: c.int) -> cstring ---
  87. GameControllerOpen :: proc(joystick_index: c.int) -> ^GameController ---
  88. GameControllerFromInstanceID :: proc(joyid: JoystickID) -> ^GameController ---
  89. GameControllerFromPlayerIndex :: proc(player_index: c.int) -> ^GameController ---
  90. GameControllerName :: proc(gamecontroller: ^GameController) -> cstring ---
  91. GameControllerGetType :: proc(gamecontroller: ^GameController) -> GameControllerType ---
  92. GameControllerGetPlayerIndex :: proc(gamecontroller: ^GameController) -> c.int ---
  93. GameControllerSetPlayerIndex :: proc(gamecontroller: ^GameController, player_index: c.int) ---
  94. GameControllerGetVendor :: proc(gamecontroller: ^GameController) -> u16 ---
  95. GameControllerGetProduct :: proc(gamecontroller: ^GameController) -> u16 ---
  96. GameControllerGetProductVersion :: proc(gamecontroller: ^GameController) -> u16 ---
  97. GameControllerGetSerial :: proc(gamecontroller: ^GameController) -> cstring ---
  98. GameControllerGetAttached :: proc(gamecontroller: ^GameController) -> bool ---
  99. GameControllerGetJoystick :: proc(gamecontroller: ^GameController) -> ^Joystick ---
  100. GameControllerEventState :: proc(state: c.int) -> c.int ---
  101. GameControllerUpdate :: proc() ---
  102. GameControllerGetAxisFromString :: proc(str: cstring) -> GameControllerAxis ---
  103. GameControllerGetStringForAxis :: proc(axis: GameControllerAxis) -> cstring ---
  104. GameControllerGetBindForAxis :: proc(gamecontroller: ^GameController, axis: GameControllerAxis) -> GameControllerButtonBind---
  105. GameControllerHasAxis :: proc(gamecontroller: ^GameController, axis: GameControllerAxis) -> bool ---
  106. GameControllerGetAxis :: proc(gamecontroller: ^GameController, axis: GameControllerAxis) -> i16 ---
  107. GameControllerGetButtonFromString :: proc(str: cstring) -> GameControllerButton ---
  108. GameControllerGetStringForButton :: proc(button: GameControllerButton) -> cstring ---
  109. GameControllerGetBindForButton :: proc(gamecontroller: ^GameController, button: GameControllerButton) -> GameControllerButtonBind ---
  110. GameControllerHasButton :: proc(gamecontroller: ^GameController, button: GameControllerButton) -> bool ---
  111. GameControllerGetButton :: proc(gamecontroller: ^GameController, button: GameControllerButton) -> u8 ---
  112. GameControllerGetNumTouchpads :: proc(gamecontroller: ^GameController) -> c.int ---
  113. GameControllerGetNumTouchpadFingers :: proc(gamecontroller: ^GameController, touchpad: c.int) -> c.int ---
  114. GameControllerGetTouchpadFinger :: proc(gamecontroller: ^GameController, touchpad: c.int, finger: c.int, state: ^u8, x, y: ^f32, pressure: ^f32) -> c.int ---
  115. GameControllerHasSensor :: proc(gamecontroller: ^GameController, type: SensorType) -> bool ---
  116. GameControllerSetSensorEnabled :: proc(gamecontroller: ^GameController, type: SensorType, enabled: bool) -> c.int ---
  117. GameControllerIsSensorEnabled :: proc(gamecontroller: ^GameController, type: SensorType) -> bool ---
  118. GameControllerGetSensorDataRate :: proc(gamecontroller: ^GameController, type: SensorType) -> f32 ---
  119. GameControllerGetSensorData :: proc(gamecontroller: ^GameController, type: SensorType, data: [^]f32, num_values: c.int) -> c.int ---
  120. GameControllerRumble :: proc(gamecontroller: ^GameController, low_frequency_rumble, high_frequency_rumble: u16, duration_ms: u32) -> c.int ---
  121. GameControllerRumbleTriggers :: proc(gamecontroller: ^GameController, left_rumble, right_rumble: u16, duration_ms: u32) -> c.int ---
  122. GameControllerHasLED :: proc(gamecontroller: ^GameController) -> bool ---
  123. GameControllerSetLED :: proc(gamecontroller: ^GameController, red, green, blue: u8) -> c.int ---
  124. GameControllerSendEffect :: proc(gamecontroller: ^GameController, data: rawptr, size: c.int) -> c.int ---
  125. GameControllerClose :: proc(gamecontroller: ^GameController) ---
  126. }