summaryrefslogtreecommitdiff
path: root/sdl2
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2015-12-16 21:25:58 -0500
committerDavid Thompson <dthompson2@worcester.edu>2015-12-16 21:28:06 -0500
commit28503ef3b65b69f243a6fc10db04f28c1ae34bb1 (patch)
tree0f2052b0ba793080e4f97d7a767807aba39bc93c /sdl2
parent0e442c81a177978aa0c8d5aee772b0b2135b4c4c (diff)
events: joystick: Add button bindings.
* sdl2/events.scm (<joystick-button-event>): New record type. (make-joystick-button-event, joystick-button-event?, joystick-button-down-event?, joystick-button-up-event?, joystick-button-event-timestamp, joystick-button-event-which, joystick-button-event-button, joystick-button-event-pressed?, parse-joystick-button-event): New procedures. (poll-event): Add support for joystick button events.
Diffstat (limited to 'sdl2')
-rw-r--r--sdl2/events.scm45
1 files changed, 45 insertions, 0 deletions
diff --git a/sdl2/events.scm b/sdl2/events.scm
index 883f32b..cc78710 100644
--- a/sdl2/events.scm
+++ b/sdl2/events.scm
@@ -81,6 +81,15 @@
joystick-axis-event-axis
joystick-axis-event-value
+ make-joystick-button-event
+ joystick-button-event?
+ joystick-button-down-event?
+ joystick-button-up-event?
+ joystick-button-event-timestamp
+ joystick-button-event-which
+ joystick-button-event-button
+ joystick-button-event-pressed?
+
poll-event))
(define (make-sdl-event)
@@ -825,6 +834,39 @@
((_ timestamp which axis _ _ _ value _)
(make-joystick-axis-event timestamp which axis value))))
+(define-record-type <joystick-button-event>
+ (make-joystick-button-event timestamp which button pressed?)
+ joystick-button-event?
+ (timestamp joystick-button-event-timestamp)
+ (which joystick-button-which)
+ (button joystick-button-event-button)
+ (pressed? joystick-button-event-pressed?))
+
+(define (joystick-button-down-event? e)
+ "Return #t if E is a joystick button press event."
+ (and (joystick-button-event? e)
+ (joystick-button-event-pressed? e)))
+
+(define (joystick-button-up-event? e)
+ "Return #t if E is a joystick button release event."
+ (and (joystick-button-event? e)
+ (not (joystick-button-event-pressed? e))))
+
+(define (parse-joystick-button-event ptr)
+ (define types
+ (list uint32 ; type
+ uint32 ; timestamp
+ int32 ; which
+ uint8 ; button
+ uint8 ; state
+ uint8 ; padding1
+ uint8)) ; padding2
+
+ (match (parse-c-struct ptr types)
+ ((_ timestamp which button state _ _)
+ (make-joystick-button-event timestamp which button
+ (= state ffi:SDL_PRESSED)))))
+
;;;
;;; Event management
@@ -849,4 +891,7 @@
(parse-mouse-motion-event ptr))
((= type ffi:SDL_JOYAXISMOTION)
(parse-joystick-axis-event ptr))
+ ((or (= type ffi:SDL_JOYBUTTONDOWN)
+ (= type ffi:SDL_JOYBUTTONUP))
+ (parse-joystick-button-event ptr))
(else 'fixme:unsupported-event))))))