summaryrefslogtreecommitdiff
path: root/2d
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2013-06-25 21:13:41 -0400
committerDavid Thompson <dthompson2@worcester.edu>2013-06-25 21:13:41 -0400
commit286166217fc4a956cbbf1664637987d054c979cc (patch)
treeb8783f7cd9ce60f6f73a24d1611f162156d4ed09 /2d
parent69a20cd448ccc5f1974b80bbc1f6501504858450 (diff)
Add mouse event callbacks.
Diffstat (limited to '2d')
-rw-r--r--2d/game-loop.scm34
1 files changed, 33 insertions, 1 deletions
diff --git a/2d/game-loop.scm b/2d/game-loop.scm
index eef3d2f..2d015ba 100644
--- a/2d/game-loop.scm
+++ b/2d/game-loop.scm
@@ -28,6 +28,9 @@
set-update-callback
set-key-up-callback
set-key-down-callback
+ set-mouse-motion-callback
+ set-mouse-button-down-callback
+ set-mouse-button-up-callback
run-game-loop))
(define target-fps 60)
@@ -41,6 +44,9 @@
(define update-callback (lambda () #t))
(define key-up-callback (lambda (key mod unicode) #t))
(define key-down-callback (lambda (key mod unicode) #t))
+(define mouse-motion-callback (lambda (buttons x y xrel yrel) #t))
+(define mouse-button-down-callback (lambda (button x y) #t))
+(define mouse-button-up-callback (lambda (button x y) #t))
(define (set-render-callback callback)
"Sets the render callback procedure."
@@ -58,6 +64,18 @@
"Sets the key down callback procedure."
(set! key-down-callback callback))
+(define (set-mouse-motion-callback callback)
+ "Sets the mouse motion callback procedure."
+ (set! mouse-motion-callback callback))
+
+(define (set-mouse-button-down-callback callback)
+ "Sets the mouse button down callback procedure."
+ (set! mouse-button-down-callback callback))
+
+(define (set-mouse-button-up-callback callback)
+ "Sets the mouse button up callback procedure."
+ (set! mouse-button-up-callback callback))
+
;;;
;;; Event Handling
;;;
@@ -79,7 +97,21 @@
((SDL_KEYUP)
(key-up-callback (event-keycode e)
(event-keymods e)
- (SDL:event:key:keysym:unicode e)))))
+ (SDL:event:key:keysym:unicode e)))
+ ((SDL_MOUSEMOTION)
+ (mouse-motion-callback (SDL:event:motion:state e)
+ (SDL:event:motion:x e)
+ (SDL:event:motion:y e)
+ (SDL:event:motion:xrel e)
+ (SDL:event:motion:yrel e)))
+ ((SDL_MOUSEBUTTONDOWN)
+ (mouse-button-down-callback (SDL:event:button:button e)
+ (SDL:event:button:x e)
+ (SDL:event:button:y e)))
+ ((SDL_MOUSEBUTTONUP)
+ (mouse-button-up-callback (SDL:event:button:button e)
+ (SDL:event:button:x e)
+ (SDL:event:button:y e)))))
(define (event-keycode e)
"Returns an integer keycode from an SDL event."