From 0e442c81a177978aa0c8d5aee772b0b2135b4c4c Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 16 Dec 2015 21:12:28 -0500 Subject: events: joystick: Add axis motion bindings. * sdl2/events.scm (): New record type. (make-joystick-axis-event, joystick-axis-event?, joystick-axis-event-timestamp, joystick-axis-event-which, joystick-axis-event-axis, joystick-axis-event-value, parse-joystick-axis-event): New procedures. (poll-event): Add support for joystick axis motion events. --- sdl2/events.scm | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'sdl2/events.scm') diff --git a/sdl2/events.scm b/sdl2/events.scm index b667098..883f32b 100644 --- a/sdl2/events.scm +++ b/sdl2/events.scm @@ -74,6 +74,13 @@ mouse-motion-event-x-rel mouse-motion-event-y-rel + make-joystick-axis-event + joystick-axis-event? + joystick-axis-event-timestamp + joystick-axis-event-which + joystick-axis-event-axis + joystick-axis-event-value + poll-event)) (define (make-sdl-event) @@ -789,6 +796,35 @@ (button-mask->list state) x y xrel yrel)))) + +;;; +;;; Joystick +;;; + +(define-record-type + (make-joystick-axis-event timestamp which axis value) + joystick-axis-event? + (timestamp joystick-axis-event-timestamp) + (which joystick-axis-event-which) + (axis joystick-axis-event-axis) + (value joystick-axis-event-value)) + +(define (parse-joystick-axis-event ptr) + (define types + (list uint32 ; type + uint32 ; timestamp + int32 ; which + uint8 ; axis + uint8 ; padding1 + uint8 ; padding2 + uint8 ; padding3 + int16 ; value + uint16)) ; padding4 + + (match (parse-c-struct ptr types) + ((_ timestamp which axis _ _ _ value _) + (make-joystick-axis-event timestamp which axis value)))) + ;;; ;;; Event management @@ -811,4 +847,6 @@ (parse-mouse-button-event ptr)) ((= type ffi:SDL_MOUSEMOTION) (parse-mouse-motion-event ptr)) + ((= type ffi:SDL_JOYAXISMOTION) + (parse-joystick-axis-event ptr)) (else 'fixme:unsupported-event)))))) -- cgit v1.2.3