src/joystick/android/SDL_sysjoystick.c
changeset 10281 cb13d22b7f09
parent 10278 74c39dbe8d30
equal deleted inserted replaced
10280:3134026517cb 10281:cb13d22b7f09
    24 #ifdef SDL_JOYSTICK_ANDROID
    24 #ifdef SDL_JOYSTICK_ANDROID
    25 
    25 
    26 #include <stdio.h>              /* For the definition of NULL */
    26 #include <stdio.h>              /* For the definition of NULL */
    27 #include "SDL_error.h"
    27 #include "SDL_error.h"
    28 #include "SDL_events.h"
    28 #include "SDL_events.h"
    29 
       
    30 #if !SDL_EVENTS_DISABLED
       
    31 #include "../../events/SDL_events_c.h"
       
    32 #endif
       
    33 
    29 
    34 #include "SDL_joystick.h"
    30 #include "SDL_joystick.h"
    35 #include "SDL_hints.h"
    31 #include "SDL_hints.h"
    36 #include "SDL_assert.h"
    32 #include "SDL_assert.h"
    37 #include "SDL_timer.h"
    33 #include "SDL_timer.h"
   250 int
   246 int
   251 Android_AddJoystick(int device_id, const char *name, SDL_bool is_accelerometer, int nbuttons, int naxes, int nhats, int nballs)
   247 Android_AddJoystick(int device_id, const char *name, SDL_bool is_accelerometer, int nbuttons, int naxes, int nhats, int nballs)
   252 {
   248 {
   253     SDL_JoystickGUID guid;
   249     SDL_JoystickGUID guid;
   254     SDL_joylist_item *item;
   250     SDL_joylist_item *item;
   255 #if !SDL_EVENTS_DISABLED
       
   256     SDL_Event event;
       
   257 #endif
       
   258     
   251     
   259     if(JoystickByDeviceId(device_id) != NULL || name == NULL) {
   252     if(JoystickByDeviceId(device_id) != NULL || name == NULL) {
   260         return -1;
   253         return -1;
   261     }
   254     }
   262     
   255     
   297     }
   290     }
   298 
   291 
   299     /* Need to increment the joystick count before we post the event */
   292     /* Need to increment the joystick count before we post the event */
   300     ++numjoysticks;
   293     ++numjoysticks;
   301 
   294 
   302 #if !SDL_EVENTS_DISABLED
   295     SDL_PrivateJoystickAdded(numjoysticks - 1);
   303     event.type = SDL_JOYDEVICEADDED;
       
   304 
       
   305     if (SDL_GetEventState(event.type) == SDL_ENABLE) {
       
   306         event.jdevice.which = (numjoysticks - 1);
       
   307         if ( (SDL_EventOK == NULL) ||
       
   308              (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
       
   309             SDL_PushEvent(&event);
       
   310         }
       
   311     }
       
   312 #endif /* !SDL_EVENTS_DISABLED */
       
   313 
   296 
   314 #ifdef DEBUG_JOYSTICK
   297 #ifdef DEBUG_JOYSTICK
   315     SDL_Log("Added joystick %s with device_id %d", name, device_id);
   298     SDL_Log("Added joystick %s with device_id %d", name, device_id);
   316 #endif
   299 #endif
   317 
   300 
   321 int 
   304 int 
   322 Android_RemoveJoystick(int device_id)
   305 Android_RemoveJoystick(int device_id)
   323 {
   306 {
   324     SDL_joylist_item *item = SDL_joylist;
   307     SDL_joylist_item *item = SDL_joylist;
   325     SDL_joylist_item *prev = NULL;
   308     SDL_joylist_item *prev = NULL;
   326 #if !SDL_EVENTS_DISABLED
       
   327     SDL_Event event;
       
   328 #endif
       
   329     
   309     
   330     /* Don't call JoystickByDeviceId here or there'll be an infinite loop! */
   310     /* Don't call JoystickByDeviceId here or there'll be an infinite loop! */
   331     while (item != NULL) {
   311     while (item != NULL) {
   332         if (item->device_id == device_id) {
   312         if (item->device_id == device_id) {
   333             break;
   313             break;
   355     }
   335     }
   356 
   336 
   357     /* Need to decrement the joystick count before we post the event */
   337     /* Need to decrement the joystick count before we post the event */
   358     --numjoysticks;
   338     --numjoysticks;
   359 
   339 
   360 #if !SDL_EVENTS_DISABLED
   340     SDL_PrivateJoystickRemoved(item->device_instance);
   361     event.type = SDL_JOYDEVICEREMOVED;
       
   362 
       
   363     if (SDL_GetEventState(event.type) == SDL_ENABLE) {
       
   364         event.jdevice.which = item->device_instance;
       
   365         if ( (SDL_EventOK == NULL) ||
       
   366              (*SDL_EventOK) (SDL_EventOKParam, &event) ) {
       
   367             SDL_PushEvent(&event);
       
   368         }
       
   369     }
       
   370 #endif /* !SDL_EVENTS_DISABLED */
       
   371 
   341 
   372 #ifdef DEBUG_JOYSTICK
   342 #ifdef DEBUG_JOYSTICK
   373     SDL_Log("Removed joystick with device_id %d", device_id);
   343     SDL_Log("Removed joystick with device_id %d", device_id);
   374 #endif
   344 #endif
   375     
   345