summaryrefslogtreecommitdiff
path: root/chickadee.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2018-01-05 14:57:15 -0500
committerDavid Thompson <dthompson2@worcester.edu>2018-01-05 14:57:15 -0500
commit41681454c4a1b0a12605f512a52f8fc46afefff1 (patch)
treeac5164e11854381b712224409d49402abe43bd9b /chickadee.scm
parent9daf9fc933a22359bb546e51029282ae215256f3 (diff)
Fix inverted Y coordinates in mouse events.
* chickadee.scm (run-game): Invert all Y coordinates received from SDL.
Diffstat (limited to 'chickadee.scm')
-rw-r--r--chickadee.scm10
1 files changed, 7 insertions, 3 deletions
diff --git a/chickadee.scm b/chickadee.scm
index 2a282b4..3c0e1c9 100644
--- a/chickadee.scm
+++ b/chickadee.scm
@@ -85,6 +85,10 @@
#:width window-width
#:height window-height
#:fullscreen? window-fullscreen?)))
+ (define (invert-y y)
+ ;; SDL's origin is the top-left, but our origin is the bottom
+ ;; left so we need to invert Y coordinates that SDL gives us.
+ (- (window-height window) y))
(define (process-event event)
(cond
((quit-event? event)
@@ -107,18 +111,18 @@
(mouse-button-event-button event)
(mouse-button-event-clicks event)
(mouse-button-event-x event)
- (mouse-button-event-y event)))
+ (invert-y (mouse-button-event-y event))))
((mouse-button-up-event? event)
(run-hook mouse-release-hook
(mouse-button-event-button event)
(mouse-button-event-x event)
- (mouse-button-event-y event)))
+ (invert-y (mouse-button-event-y event))))
((mouse-motion-event? event)
(run-hook mouse-move-hook
(mouse-motion-event-x event)
(mouse-motion-event-y event)
(mouse-motion-event-x-rel event)
- (mouse-motion-event-y-rel event)
+ (- (mouse-motion-event-y-rel event))
(mouse-motion-event-buttons event)))
((and (controller-device-event? event)
(eq? (controller-device-event-action event) 'added))