summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-01-09 20:48:11 -0500
committerDavid Thompson <dthompson2@worcester.edu>2014-01-09 20:48:11 -0500
commitccc85c51f5617ef0305fcb0e1d067ab6d39fc778 (patch)
tree92307c314832dc9b7ed039bd36a5a1dfde67c319
parent292aa670881cb93c0979696d33b6b0d1d5a4d065 (diff)
Add mouse move/press/click hooks.
* 2d/mouse.scm (mouse-move-hook, mouse-press-hook) (mouse-click-hook): New hooks.
-rw-r--r--2d/mouse.scm23
1 files changed, 20 insertions, 3 deletions
diff --git a/2d/mouse.scm b/2d/mouse.scm
index 8f1129b..b132b96 100644
--- a/2d/mouse.scm
+++ b/2d/mouse.scm
@@ -26,13 +26,19 @@
#:use-module (2d game)
#:use-module (2d signals)
#:use-module (2d vector2)
- #:export (mouse-x
+ #:export (mouse-move-hook
+ mouse-press-hook
+ mouse-click-hook
+ mouse-x
mouse-y
mouse-position
mouse-last-down
mouse-last-up
mouse-down?))
+(define mouse-move-hook (make-hook 2))
+(define mouse-press-hook (make-hook 3))
+(define mouse-click-hook (make-hook 3))
(define mouse-last-down (make-root-signal 'none))
(define mouse-last-up (make-root-signal 'none))
(define mouse-x (make-root-signal 0))
@@ -54,15 +60,26 @@ button is pressed or #f otherwise."
(register-event-handler
'mouse-motion
(lambda (e)
+ (run-hook mouse-move-hook
+ (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
+ 'mouse-button-down
(lambda (e)
+ (run-hook mouse-press-hook
+ (SDL:event:button:button e)
+ (SDL:event:button:x e)
+ (SDL:event:button:y e))
(signal-set! mouse-last-down (SDL:event:button:button e))))
(register-event-handler
- 'mouse-up
+ 'mouse-button-up
(lambda (e)
+ (run-hook mouse-click-hook
+ (SDL:event:button:button e)
+ (SDL:event:button:x e)
+ (SDL:event:button:y e))
(signal-set! mouse-last-up (SDL:event:button:button e))))