events: Add predicates for different controller device events.
authorDavid Thompson <dthompson2@worcester.edu>
Sun, 1 Jan 2017 20:08:44 +0000 (15:08 -0500)
committerDavid Thompson <dthompson2@worcester.edu>
Sun, 1 Jan 2017 20:08:44 +0000 (15:08 -0500)
* sdl2/events.scm (controller-added-event?, controller-removed-event?,
controller-remapped-event?): New procedures.

sdl2/events.scm

index 56bf233..2c303c7 100644 (file)
 
             make-controller-device-event
             controller-device-event?
+            controller-added-event?
+            controller-removed-event?
+            controller-remapped-event?
             controller-device-event-timestamp
             controller-device-event-which
             controller-device-event-action
   (which controller-device-event-which)
   (action controller-device-event-action))
 
+(define (controller-added-event? event)
+  "Return #t if EVENT is a game controller device event with the
+'added' action."
+  (and (controller-device-event? event)
+       (eq? (controller-device-event-action event) 'added)))
+
+(define (controller-removed-event? event)
+  "Return #t if EVENT is a game controller device event with the
+'removed' action."
+  (and (controller-device-event? event)
+       (eq? (controller-device-event-action event) 'removed)))
+
+(define (controller-remapped-event? event)
+  "Return #t if EVENT is a game controller device event with the
+'remapped' action."
+  (and (controller-device-event? event)
+       (eq? (controller-device-event-action event) 'remapped)))
+
 (define (parse-controller-device-event ptr)
   (define types
     (list uint32  ; type