events: Add quit event.
authorDavid Thompson <dthompson2@worcester.edu>
Mon, 21 Dec 2015 16:40:38 +0000 (11:40 -0500)
committerDavid Thompson <dthompson2@worcester.edu>
Mon, 21 Dec 2015 16:40:38 +0000 (11:40 -0500)
* sdl2/events.scm (<quit-event>): New record type.
(make-quit-event, quit-event?, quit-event-timestamp, parse-quit-event):
New procedures.
(poll-event): Add support for SDL_QUIT events.

sdl2/events.scm

index e32c8ef..282fc34 100644 (file)
   #:use-module (system foreign)
   #:use-module ((sdl2 bindings) #:prefix ffi:)
   #:use-module (sdl2)
-  #:export (make-window-event
+  #:export (make-quit-event
+            quit-event?
+            quit-event-timestamp
+
+            make-window-event
             window-event?
             window-event-timestamp
             window-event-window-id
 
 \f
 ;;;
+;;; Quit
+;;;
+
+(define-record-type <quit-event>
+  (make-quit-event timestamp)
+  quit-event?
+  (timestamp quit-event-timestamp))
+
+(define (parse-quit-event ptr)
+  (match (parse-c-struct ptr (list uint32 uint32))
+    ((_ timestamp)
+     (make-quit-event timestamp))))
+
+\f
+;;;
 ;;; Window
 ;;;
 
     (and (= result 1)
          (let ((type (sdl-event-type e)))
            (cond
+            ((= type ffi:SDL_QUIT)
+             (parse-quit-event ptr))
             ((= type ffi:SDL_WINDOWEVENT)
              (parse-window-event ptr))
             ((or (= type ffi:SDL_KEYDOWN)