src/joystick/SDL_joystick.c
changeset 10477 dc4bec0fc176
parent 10226 cb13d22b7f09
child 10595 9da2701eeb4a
equal deleted inserted replaced
10476:612fbaee8e3c 10477:dc4bec0fc176
   140         joystick->name = SDL_strdup(joystickname);
   140         joystick->name = SDL_strdup(joystickname);
   141     else
   141     else
   142         joystick->name = NULL;
   142         joystick->name = NULL;
   143 
   143 
   144     if (joystick->naxes > 0) {
   144     if (joystick->naxes > 0) {
   145         joystick->axes = (Sint16 *) SDL_malloc
   145         joystick->axes = (Sint16 *) SDL_malloc(joystick->naxes * sizeof(Sint16));
   146             (joystick->naxes * sizeof(Sint16));
   146         joystick->axes_zero = (Sint16 *) SDL_malloc(joystick->naxes * sizeof(Sint16));
   147     }
   147     }
   148     if (joystick->nhats > 0) {
   148     if (joystick->nhats > 0) {
   149         joystick->hats = (Uint8 *) SDL_malloc
   149         joystick->hats = (Uint8 *) SDL_malloc
   150             (joystick->nhats * sizeof(Uint8));
   150             (joystick->nhats * sizeof(Uint8));
   151     }
   151     }
   165         SDL_JoystickClose(joystick);
   165         SDL_JoystickClose(joystick);
   166         return NULL;
   166         return NULL;
   167     }
   167     }
   168     if (joystick->axes) {
   168     if (joystick->axes) {
   169         SDL_memset(joystick->axes, 0, joystick->naxes * sizeof(Sint16));
   169         SDL_memset(joystick->axes, 0, joystick->naxes * sizeof(Sint16));
       
   170         SDL_memset(joystick->axes_zero, 0, joystick->naxes * sizeof(Sint16));
   170     }
   171     }
   171     if (joystick->hats) {
   172     if (joystick->hats) {
   172         SDL_memset(joystick->hats, 0, joystick->nhats * sizeof(Uint8));
   173         SDL_memset(joystick->hats, 0, joystick->nhats * sizeof(Uint8));
   173     }
   174     }
   174     if (joystick->balls) {
   175     if (joystick->balls) {
   577 
   578 
   578     /* We ignore events if we don't have keyboard focus, except for centering
   579     /* We ignore events if we don't have keyboard focus, except for centering
   579      * events.
   580      * events.
   580      */
   581      */
   581     if (SDL_PrivateJoystickShouldIgnoreEvent()) {
   582     if (SDL_PrivateJoystickShouldIgnoreEvent()) {
   582         if ((value > 0 && value >= joystick->axes[axis]) ||
   583         if ((value > joystick->axes_zero[axis] && value >= joystick->axes[axis]) ||
   583             (value < 0 && value <= joystick->axes[axis])) {
   584             (value < joystick->axes_zero[axis] && value <= joystick->axes[axis])) {
   584             return 0;
   585             return 0;
   585         }
   586         }
   586     }
   587     }
   587 
   588 
   588     /* Update internal joystick state */
   589     /* Update internal joystick state */
   751         if (joystick->force_recentering) {
   752         if (joystick->force_recentering) {
   752             int i;
   753             int i;
   753 
   754 
   754             /* Tell the app that everything is centered/unpressed...  */
   755             /* Tell the app that everything is centered/unpressed...  */
   755             for (i = 0; i < joystick->naxes; i++) {
   756             for (i = 0; i < joystick->naxes; i++) {
   756                 SDL_PrivateJoystickAxis(joystick, i, 0);
   757                 SDL_PrivateJoystickAxis(joystick, i, joystick->axes_zero[i]);
   757             }
   758             }
   758 
   759 
   759             for (i = 0; i < joystick->nbuttons; i++) {
   760             for (i = 0; i < joystick->nbuttons; i++) {
   760                 SDL_PrivateJoystickButton(joystick, i, 0);
   761                 SDL_PrivateJoystickButton(joystick, i, 0);
   761             }
   762             }