joystick update
[blender.git] / source / gameengine / GameLogic / Joystick / SCA_JoystickEvents.cpp
index 0e2078265c9e5b3be48a7bcd67b042a6c6ce3d16..7a2ec5b3deaa9ade3fb0918b42c590940b54a55a 100644 (file)
  *
  * ***** END GPL LICENSE BLOCK *****
  */
+#ifndef DISABLE_SDL
 #include <SDL.h>
+#endif
+
 #include "SCA_Joystick.h"
 #include "SCA_JoystickPrivate.h"
 
@@ -46,17 +49,26 @@ void SCA_Joystick::OnHatMotion(SDL_Event* sdl_event)
        m_istrig = 1;
 }
 
-
 void SCA_Joystick::OnButtonUp(SDL_Event* sdl_event)
 {
+       m_istrig = 1;
+       
+       /* this is needed for the "all events" option
+        * so we know if there are no buttons pressed */
+       int i;
+       for (i=0; i<m_buttonmax; i++) {
+               if (SDL_JoystickGetButton(m_private->m_joystick, i)) {
+                       m_buttonnum = i;
+                       return;
+               }
+       }
        m_buttonnum = -2;
 }
 
 
 void SCA_Joystick::OnButtonDown(SDL_Event* sdl_event)
 {
-       m_buttonmax = GetNumberOfButtons();
-       if(sdl_event->jbutton.button >= 1 || sdl_event->jbutton.button <= m_buttonmax)
+       if(sdl_event->jbutton.button >= 0 || sdl_event->jbutton.button <= m_buttonmax)
        {
                m_istrig = 1;
                m_buttonnum = sdl_event->jbutton.button;
@@ -74,7 +86,12 @@ void SCA_Joystick::OnNothing(SDL_Event* sdl_event)
 void SCA_Joystick::HandleEvents(void)
 {
        SDL_Event               sdl_event;
-
+       
+       int i;
+       for (i=0; i<JOYINDEX_MAX; i++) {
+               SCA_Joystick::m_instance[i]->OnNothing(&sdl_event);
+       }
+       
        if(SDL_PollEvent(&sdl_event))
        {
                /* Note! m_instance[sdl_event.jaxis.which]