Fix inverted Y coordinates in mouse events.
authorDavid Thompson <dthompson2@worcester.edu>
Fri, 5 Jan 2018 19:57:15 +0000 (14:57 -0500)
committerDavid Thompson <dthompson2@worcester.edu>
Fri, 5 Jan 2018 19:57:15 +0000 (14:57 -0500)
* chickadee.scm (run-game): Invert all Y coordinates received from SDL.

chickadee.scm

index 2a282b4..3c0e1c9 100644 (file)
                              #: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)
                   (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))