diff options
author | David Thompson <dthompson@vistahigherlearning.com> | 2016-12-30 11:55:44 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2016-12-31 13:31:18 -0500 |
commit | 1800240eb3154c5460907917ae3f4659002efc47 (patch) | |
tree | 3cc5f5365d34fb441a3ab00e6698201abaf57bda /sdl2/bindings.scm | |
parent | b833f588b3d9528e7fc650d841ee7a46b6c0ba78 (diff) |
Add bindings for game controller input.
* sdl2.scm (%default-init-flags): Add 'joystick' to default flags.
(sdl-init): Translate to 'joystick' to SDL2 init bit flag.
* sdl2/bindings.scm (SDL_INIT_JOYSTICK, SDL_JOYSTICK_POWER_UNKNOWN,
SDL_JOYSTICK_POWER_EMPTY, SDL_JOYSTICK_POWER_LOW,
SDL_JOYSTICK_POWER_MEDIUM, SDL_JOYSTICK_POWER_FULL,
SDL_JOYSTICK_POWER_WIRED, SDL_JOYSTICK_POWER_MAX,
SDL_CONTROLLER_AXIS_INVALID, SDL_CONTROLLER_AXIS_LEFTX,
SDL_CONTROLLER_AXIS_LEFTY, SDL_CONTROLLER_AXIS_RIGHTX,
SDL_CONTROLLER_AXIS_RIGHTY, SDL_CONTROLLER_AXIS_TRIGGERLEFT,
SDL_CONTROLLER_AXIS_TRIGGERRIGHT, SDL_CONTROLLER_AXIS_MAX,
SDL_CONTROLLER_BUTTON_INVALID, SDL_CONTROLLER_BUTTON_A,
SDL_CONTROLLER_BUTTON_B, SDL_CONTROLLER_BUTTON_X,
SDL_CONTROLLER_BUTTON_Y, SDL_CONTROLLER_BUTTON_BACK,
SDL_CONTROLLER_BUTTON_GUIDE, SDL_CONTROLLER_BUTTON_START,
SDL_CONTROLLER_BUTTON_LEFTSTICK, SDL_CONTROLLER_BUTTON_RIGHTSTICK,
SDL_CONTROLLER_BUTTON_LEFTSHOULDER, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
SDL_CONTROLLER_BUTTON_DPAD_UP, SDL_CONTROLLER_BUTTON_DPAD_DOWN,
SDL_CONTROLLER_BUTTON_DPAD_LEFT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT,
SDL_CONTROLLER_BUTTON_MAX): New variables.
(sdl-joystick-open, sdl-joystick-close,
sdl-joystick-current-power-level, sdl-joystick-event-state,
sdl-joystick-from-instance-id, sdl-joystick-get-attached,
sdl-joystick-get-axis, sdl-joystick-get-ball, sdl-joystick-get-button,
sdl-joystick-get-device-guid, sdl-joystick-get-guide,
sdl-joystick-get-guid-from-string, sdl-joystick-get-guid-string,
sdl-joystick-get-hat, sdl-joystick-instance-id, sdl-joystick-name,
sdl-joystick-name-for-index, sdl-joystick-num-axes,
sdl-joystick-num-balls, sdl-joystick-num-buttons, sdl-joystick-num-hats,
sdl-num-joysticks, sdl-joystick-update, sdl-game-controller-add-mapping,
sdl-game-controller-open, sdl-game-controller-close,
sdl-game-controller-event-state, sdl-game-controller-from-instance-id,
sdl-game-controller-get-attached, sdl-game-controller-get-axis,
sdl-game-controller-get-axis-from-string,
sdl-game-controller-get-string-from-axis,
sdl-game-controller-get-string-for-axis, sdl-game-controller-get-button,
sdl-game-controller-get-button-from-string,
sdl-game-controller-get-string-from-button,
sdl-game-controller-get-joystick, sdl-game-controller-mapping,
sdl-game-controller-mapping-for-guid, sdl-game-controller-name,
sdl-game-controller-name-for-index, sdl-game-controller-update,
sdl-is-game-controller): New procedures.
* sdl2/events.scm (make-joystick-ball-event, joystick-ball-event?,
joystick-ball-event-timestamp, joystick-ball-event-which,
joystick-ball-event-ball, joystick-ball-event-x-rel,
joystick-ball-event-y-rel, make-joystick-hat-event, joystick-hat-event?,
joystick-hat-event-timestamp, joystick-hat-event-which,
joystick-hat-event-hat, joystick-hat-event-value,
make-joystick-device-event, joystick-device-event?,
joystick-device-event-timestamp, joystick-device-event-which,
joystick-device-event-action, make-controller-axis-event,
controller-axis-event?, controller-axis-event-timestamp,
controller-axis-event-which, controller-axis-event-axis,
controller-axis-event-value, make-controller-button-event,
controller-button-event?, controller-button-down-event?,
controller-button-up-event?, controller-button-event-timestamp,
controller-button-event-which, controller-button-event-button,
controller-button-event-pressed?, make-controller-device-event,
controller-device-event?, controller-device-event-timestamp,
controller-device-event-which, controller-device-event-action,
parse-joystick-ball-event, parse-joystick-hat-event,
parse-joystick-device-event, parse-controller-axis-event,
parse-controller-button-event, parse-controller-device-event): New
procedures.
(poll-event): Parse joystick/controller events.
* sdl2/input/joystick.scm: New file.
* sdl2/input/game-controller.scm: New file.
* Makefile.am (SOURCES): Add them
Diffstat (limited to 'sdl2/bindings.scm')
-rw-r--r-- | sdl2/bindings.scm | 172 |
1 files changed, 172 insertions, 0 deletions
diff --git a/sdl2/bindings.scm b/sdl2/bindings.scm index e48ce64..1eb4813 100644 --- a/sdl2/bindings.scm +++ b/sdl2/bindings.scm @@ -71,6 +71,7 @@ RETURN-TYPE and accept arguments of ARG-TYPES." (define-public SDL_INIT_TIMER #x00000001) (define-public SDL_INIT_AUDIO #x00000010) (define-public SDL_INIT_VIDEO #x00000020) +(define-public SDL_INIT_JOYSTICK #x00000200) (define-public SDL_INIT_HAPTIC #x00001000) (define-public SDL_INIT_GAMECONTROLLER #x00002000) (define-public SDL_INIT_EVENTS #x00004000) @@ -949,3 +950,174 @@ RETURN-TYPE and accept arguments of ARG-TYPES." (define-public AUDIO_F32LSB #x8120) (define-public AUDIO_F32MSB #x9120) (define-public AUDIO_F32 AUDIO_F32LSB) + + +;;; +;;; Joystick +;;; + +(define-public SDL_JOYSTICK_POWER_UNKNOWN -1) +(define-public SDL_JOYSTICK_POWER_EMPTY 0) +(define-public SDL_JOYSTICK_POWER_LOW 1) +(define-public SDL_JOYSTICK_POWER_MEDIUM 2) +(define-public SDL_JOYSTICK_POWER_FULL 3) +(define-public SDL_JOYSTICK_POWER_WIRED 4) +(define-public SDL_JOYSTICK_POWER_MAX 5) + +(define-foreign sdl-joystick-open + '* "SDL_JoystickOpen" (list int)) + +(define-foreign sdl-joystick-close + void "SDL_JoystickClose" '(*)) + +(define-foreign sdl-joystick-current-power-level + int "SDL_JoystickCurrentPowerLevel" '(*)) + +(define-foreign sdl-joystick-event-state + int "SDL_JoystickEventState" (list int)) + +(define-foreign sdl-joystick-from-instance-id + '* "SDL_JoystickFromInstanceID" (list int32)) + +(define-foreign sdl-joystick-get-attached + sdl-bool "SDL_JoystickGetAttached" '(*)) + +(define-foreign sdl-joystick-get-axis + int16 "SDL_JoystickGetAxis" (list '* int)) + +(define-foreign sdl-joystick-get-ball + int "SDL_JoystickGetBall" (list '* int '* '*)) + +(define-foreign sdl-joystick-get-button + uint8 "SDL_JoystickGetButton" (list '* int)) + +(define-foreign sdl-joystick-get-device-guid + '* "SDL_JoystickGetDeviceGUID" (list int)) + +(define-foreign sdl-joystick-get-guid + '* "SDL_JoystickGetGUID" (list int)) + +(define-foreign sdl-joystick-get-guid-from-string + '* "SDL_JoystickGetGUIDFromString" '(*)) + +(define-foreign sdl-joystick-get-guid-string + void "SDL_JoystickGetGUIDString" (list '* '* int)) + +(define-foreign sdl-joystick-get-hat + uint8 "SDL_JoystickGetHat" (list '* int)) + +(define-foreign sdl-joystick-instance-id + int32 "SDL_JoystickInstanceID" '(*)) + +(define-foreign sdl-joystick-name + '* "SDL_JoystickName" '(*)) + +(define-foreign sdl-joystick-name-for-index + '* "SDL_JoystickNameForIndex" (list int)) + +(define-foreign sdl-joystick-num-axes + int "SDL_JoystickNumAxes" '(*)) + +(define-foreign sdl-joystick-num-balls + int "SDL_JoystickNumBalls" '(*)) + +(define-foreign sdl-joystick-num-buttons + int "SDL_JoystickNumButtons" '(*)) + +(define-foreign sdl-joystick-num-hats + int "SDL_JoystickNumHats" '(*)) + +(define-foreign sdl-num-joysticks + int "SDL_NumJoysticks" '()) + +(define-foreign sdl-joystick-update + void "SDL_JoystickUpdate" '()) + + +;;; +;;; Game Controllers +;;; + +(define-public SDL_CONTROLLER_AXIS_INVALID -1) +(define-public SDL_CONTROLLER_AXIS_LEFTX 0) +(define-public SDL_CONTROLLER_AXIS_LEFTY 1) +(define-public SDL_CONTROLLER_AXIS_RIGHTX 2) +(define-public SDL_CONTROLLER_AXIS_RIGHTY 3) +(define-public SDL_CONTROLLER_AXIS_TRIGGERLEFT 4) +(define-public SDL_CONTROLLER_AXIS_TRIGGERRIGHT 5) +(define-public SDL_CONTROLLER_AXIS_MAX 6) + +(define-public SDL_CONTROLLER_BUTTON_INVALID -1) +(define-public SDL_CONTROLLER_BUTTON_A 0) +(define-public SDL_CONTROLLER_BUTTON_B 1) +(define-public SDL_CONTROLLER_BUTTON_X 2) +(define-public SDL_CONTROLLER_BUTTON_Y 3) +(define-public SDL_CONTROLLER_BUTTON_BACK 4) +(define-public SDL_CONTROLLER_BUTTON_GUIDE 5) +(define-public SDL_CONTROLLER_BUTTON_START 6) +(define-public SDL_CONTROLLER_BUTTON_LEFTSTICK 7) +(define-public SDL_CONTROLLER_BUTTON_RIGHTSTICK 8) +(define-public SDL_CONTROLLER_BUTTON_LEFTSHOULDER 9) +(define-public SDL_CONTROLLER_BUTTON_RIGHTSHOULDER 10) +(define-public SDL_CONTROLLER_BUTTON_DPAD_UP 11) +(define-public SDL_CONTROLLER_BUTTON_DPAD_DOWN 12) +(define-public SDL_CONTROLLER_BUTTON_DPAD_LEFT 13) +(define-public SDL_CONTROLLER_BUTTON_DPAD_RIGHT 14) +(define-public SDL_CONTROLLER_BUTTON_MAX 15) + +(define-foreign sdl-game-controller-add-mapping + int "SDL_GameControllerAddMapping" '(*)) + +(define-foreign sdl-game-controller-open + '* "SDL_GameControllerOpen" (list int)) + +(define-foreign sdl-game-controller-close + void "SDL_GameControllerClose" '(*)) + +(define-foreign sdl-game-controller-event-state + int "SDL_GameControllerEventState" (list int)) + +(define-foreign sdl-game-controller-from-instance-id + '* "SDL_GameControllerFromInstanceID" (list int32)) + +(define-foreign sdl-game-controller-get-attached + sdl-bool "SDL_GameControllerGetAttached" '(*)) + +(define-foreign sdl-game-controller-get-axis + int16 "SDL_GameControllerGetAxis" (list '* int)) + +(define-foreign sdl-game-controller-get-axis-from-string + int "SDL_GameControllerGetAxisFromString" '(*)) + +(define-foreign sdl-game-controller-get-string-for-axis + '* "SDL_GameControllerGetStringForAxis" (list int)) + +(define-foreign sdl-game-controller-get-button + uint8 "SDL_GameControllerGetButton" (list '* int)) + +(define-foreign sdl-game-controller-get-button-from-string + int "SDL_GameControllerGetButtonFromString" '(*)) + +(define-foreign sdl-game-controller-get-string-for-button + '* "SDL_GameControllerGetStringForButton" (list int)) + +(define-foreign sdl-game-controller-get-joystick + '* "SDL_GameControllerGetJoystick" '(*)) + +(define-foreign sdl-game-controller-mapping + '* "SDL_GameControllerMapping" '(*)) + +(define-foreign sdl-game-controller-mapping-for-guid + '* "SDL_GameControllerMappingForGUID" '(*)) + +(define-foreign sdl-game-controller-name + '* "SDL_GameControllerName" '(*)) + +(define-foreign sdl-game-controller-name-for-index + '* "SDL_GameControllerNameForIndex" (list int)) + +(define-foreign sdl-game-controller-update + void "SDL_GameControllerUpdate" '()) + +(define-foreign sdl-is-game-controller + sdl-bool "SDL_IsGameController" (list int)) |