Commits

Christian Kellermann committed 7adad99

Translate mouse events

Now mouse events are given back as an event to world-changes in the
following form:

(mouse moved x y)
(mouse pressed x y button)
(mounse released x y button)

with x, y being the coordinates and button the button number.

  • Participants
  • Parent commits 8fa68c5

Comments (0)

Files changed (1)

 
 ;; Event stuff
 
+(define (translate-mouse-event type event)
+(let ((x (sdl-event-x event))
+      (y (sdl-event-y event)))
+  (if (equal? type SDL_MOUSEMOTION)
+      (list 'mouse 'moved x y)
+      (let ((b (sdl-event-button event)))
+        (list 'mouse
+              (if (equal? type SDL_MOUSEBUTTONUP)
+                  'pressed 'released)
+              x y b)))))
+
 (define (translate-key-event type event)
   (let ((k (sdl-event-sym event)))
     (list 
       (let ((t (sdl-event-type event)))
         (cond ((equal? t SDL_QUIT)
                (escape 'quit))
+              ((equal? t SDL_VIDEOEXPOSE)
+               '(redraw))
+              ((or (equal? t SDL_MOUSEBUTTONUP)
+                   (equal? t SDL_MOUSEBUTTONDOWN)
+                   (equal? t SDL_MOUSEMOTION))
+               (translate-mouse-event t event))
               ((or (equal? t SDL_KEYDOWN)
                    (equal? t SDL_KEYUP))
                (translate-key-event t event))