diff options
author | David Thompson <dthompson2@worcester.edu> | 2015-12-22 14:35:44 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2015-12-22 16:28:18 -0500 |
commit | 8b9b5d371d1dc1c780e227ce9a555cf6c88a85c8 (patch) | |
tree | f1b6524f92aaa329667f08f4a010a7b5e6925ae8 /sly/event.scm | |
parent | 60d601cbb5eb142d01f880b5902329ada93fc91a (diff) |
Upgrade to SDL2!
This commit is massive and crazy and I'm not going to do the usual GNU
ChangeLog thing because it's just too much. Let's just be happy that
the port is completed!
Diffstat (limited to 'sly/event.scm')
-rw-r--r-- | sly/event.scm | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/sly/event.scm b/sly/event.scm index c5e57cb..90fae3b 100644 --- a/sly/event.scm +++ b/sly/event.scm @@ -22,16 +22,16 @@ ;;; Code: (define-module (sly event) - #:use-module ((sdl sdl) #:prefix SDL:) + #:use-module ((sdl2 events) #:prefix sdl2:) #:export (process-events register-event-handler)) -(define process-events - (let ((e (SDL:make-event))) - (lambda () - "Process all events in the input event queue." - (while (SDL:poll-event e) - (handle-event e))))) +(define (process-events) + "Process all events in the input event queue." + (let ((e (sdl2:poll-event))) + (when e + (handle-event e) + (process-events)))) (define event-handlers (make-hash-table)) @@ -40,6 +40,28 @@ (define (handle-event e) "Run the relevant hook for the event E." - (let ((handle (hashq-get-handle event-handlers (SDL:event:type e)))) - (when handle - ((cdr handle) e)))) + (define (event-type e) + (cond + ((sdl2:keyboard-down-event? e) + 'key-down) + ((sdl2:keyboard-up-event? e) + 'key-up) + ((sdl2:mouse-button-down-event? e) + 'mouse-button-down) + ((sdl2:mouse-button-up-event? e) + 'mouse-button-up) + ((sdl2:mouse-motion-event? e) + 'mouse-motion) + ((sdl2:joystick-button-down-event? e) + 'joy-button-down) + ((sdl2:joystick-button-up-event? e) + 'joy-button-up) + ((sdl2:joystick-axis-event? e) + 'joy-axis-motion) + ((sdl2:window-resized-event? e) + 'window-resize) + ((sdl2:quit-event? e) + 'quit))) + + (let ((handler (hashq-ref event-handlers (event-type e)))) + (and handler (handler e)))) |