summaryrefslogtreecommitdiff
path: root/sdl2/events.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2015-12-16 21:12:28 -0500
committerDavid Thompson <dthompson2@worcester.edu>2015-12-16 21:27:54 -0500
commit0e442c81a177978aa0c8d5aee772b0b2135b4c4c (patch)
tree86173554f51f1876cea16c24928edc4ee9a47931 /sdl2/events.scm
parent2fd545051eb6307ab2a3fe70e69af27cb44e96cb (diff)
events: joystick: Add axis motion bindings.
* sdl2/events.scm (<joystick-axis-event>): 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.
Diffstat (limited to 'sdl2/events.scm')
-rw-r--r--sdl2/events.scm38
1 files changed, 38 insertions, 0 deletions
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)
@@ -791,6 +798,35 @@
;;;
+;;; Joystick
+;;;
+
+(define-record-type <joystick-axis-event>
+ (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))))))