diff options
author | David Thompson <dthompson2@worcester.edu> | 2013-12-15 20:51:15 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2013-12-15 20:51:15 -0500 |
commit | 0c8129eab0d1521bca26f5e6dae03a37b8795454 (patch) | |
tree | 710ee1d00d4c7436ba583fe17e17b88fca0436cb /2d | |
parent | e2b31c192d6e10984629c4e72abf3ed8cfbc9552 (diff) |
Update mouse module to use new signal API.
* 2d/mouse.scm (mouse-x, mouse-y): New signals.
(mouse-position): Define in terms of signal-map.
Diffstat (limited to '2d')
-rw-r--r-- | 2d/mouse.scm | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/2d/mouse.scm b/2d/mouse.scm index bd11678..8f1129b 100644 --- a/2d/mouse.scm +++ b/2d/mouse.scm @@ -26,31 +26,36 @@ #:use-module (2d game) #:use-module (2d signals) #:use-module (2d vector2) - #:export (mouse-position + #:export (mouse-x + mouse-y + mouse-position mouse-last-down mouse-last-up mouse-down?)) -(define mouse-last-down (make-signal)) -(define mouse-last-up (make-signal)) -(define mouse-position (make-signal (vector2 0 0))) +(define mouse-last-down (make-root-signal 'none)) +(define mouse-last-up (make-root-signal 'none)) +(define mouse-x (make-root-signal 0)) +(define mouse-y (make-root-signal 0)) +(define mouse-position (signal-map vector2 mouse-x mouse-y)) (define (mouse-down? button) "Create a signal for the state of BUTTON. Value is #t when mouse -button is pressed and #f otherwise." - (make-signal - #:filter (lambda (value old from) - (eq? value button)) - #:transformer (lambda (value old from) - (if (eq? from mouse-last-down) #t #f)) - #:connectors (list mouse-last-down mouse-last-up))) +button is pressed or #f otherwise." + (define (same-button? other-button) + (eq? button other-button)) + + (define (button-filter value signal) + (signal-constant value (signal-filter #f same-button? signal))) + + (signal-merge (button-filter #f mouse-last-up) + (button-filter #t mouse-last-down))) (register-event-handler 'mouse-motion (lambda (e) - (signal-set! mouse-position - (vector2 (SDL:event:motion:x e) - (SDL:event:motion:y e))))) + (signal-set! mouse-x (SDL:event:motion:x e)) + (signal-set! mouse-y (SDL:event:motion:y e)))) (register-event-handler 'mouse-down |