1 ;;; Gacela, a GNU Guile extension for fast games development
2 ;;; Copyright (C) 2017 by Javier Sancho Fernandez <jsf at jsancho dot org>
4 ;;; This program is free software: you can redistribute it and/or modify
5 ;;; it under the terms of the GNU General Public License as published by
6 ;;; the Free Software Foundation, either version 3 of the License, or
7 ;;; (at your option) any later version.
9 ;;; This program is distributed in the hope that it will be useful,
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ;;; GNU General Public License for more details.
14 ;;; You should have received a copy of the GNU General Public License
15 ;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
18 (define-module (gacela event)
19 #:use-module ((sdl2 events) #:prefix sdl2:)
20 #:export (process-events
30 (define *current-events* '())
33 (let ((event (sdl2:poll-event)))
35 (cons event (poll-events)))
39 (define (clear-events)
40 (set! *current-events* '()))
42 (define (process-events)
43 (set! *current-events* (append *current-events* (poll-events))))
46 (not (null? (filter (lambda (e) (sdl2:quit-event? e)) *current-events*))))
49 (filter (lambda (e) (sdl2:keyboard-event? e)) *current-events*))
51 (define (any-key-down?)
52 (let loop ((events *current-events*))
55 (or (sdl2:keyboard-down-event? (car events))
56 (loop (cdr events))))))
59 (let loop ((events *current-events*))
62 (or (sdl2:keyboard-up-event? (car events))
63 (loop (cdr events))))))
65 (define (key-down? key)
68 (and (sdl2:keyboard-down-event? e)
69 (equal? (sdl2:keyboard-event-key e) key)))
76 (and (sdl2:keyboard-up-event? e)
77 (equal? (sdl2:keyboard-event-key e) key)))