test/testgamecontroller.c
changeset 7639 9406b7dd2f2d
parent 7517 965d57022c01
child 7705 e70dc8b38f26
     1.1 --- a/test/testgamecontroller.c	Mon Aug 12 22:00:21 2013 -0700
     1.2 +++ b/test/testgamecontroller.c	Wed Aug 14 23:30:10 2013 -0700
     1.3 @@ -91,7 +91,7 @@
     1.4      const char *name = SDL_GameControllerName(gamecontroller);
     1.5      const char *basetitle = "Game Controller Test: ";
     1.6      const size_t titlelen = SDL_strlen(basetitle) + SDL_strlen(name) + 1;
     1.7 -    char *title = SDL_malloc(titlelen);
     1.8 +    char *title = (char *)SDL_malloc(titlelen);
     1.9      SDL_Window *window = NULL;
    1.10      SDL_Renderer *screen = NULL;
    1.11      int done = 0;
    1.12 @@ -107,13 +107,13 @@
    1.13                                SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
    1.14                                SCREEN_HEIGHT, 0);
    1.15      if (window == NULL) {
    1.16 -        fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
    1.17 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
    1.18          return;
    1.19      }
    1.20  
    1.21      screen = SDL_CreateRenderer(window, -1, 0);
    1.22      if (screen == NULL) {
    1.23 -        fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError());
    1.24 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
    1.25          SDL_DestroyWindow(window);
    1.26          return;
    1.27      }
    1.28 @@ -124,7 +124,7 @@
    1.29      SDL_RaiseWindow(window);
    1.30  
    1.31      /* Print info about the controller we are watching */
    1.32 -    printf("Watching controller %s\n",  name ? name : "Unknown Controller");
    1.33 +    SDL_Log("Watching controller %s\n",  name ? name : "Unknown Controller");
    1.34  
    1.35      /* Loop, getting controller events! */
    1.36      while (!done) {
    1.37 @@ -135,21 +135,21 @@
    1.38          while (SDL_PollEvent(&event)) {
    1.39              switch (event.type) {
    1.40              case SDL_CONTROLLERAXISMOTION:
    1.41 -                printf("Controller %d axis %d ('%s') value: %d\n",
    1.42 +                SDL_Log("Controller %d axis %d ('%s') value: %d\n",
    1.43                         event.caxis.which,
    1.44                         event.caxis.axis,
    1.45 -                       ControllerAxisName(event.caxis.axis),
    1.46 +                       ControllerAxisName((SDL_GameControllerAxis)event.caxis.axis),
    1.47                         event.caxis.value);
    1.48                  break;
    1.49              case SDL_CONTROLLERBUTTONDOWN:
    1.50 -                printf("Controller %d button %d ('%s') down\n",
    1.51 +                SDL_Log("Controller %d button %d ('%s') down\n",
    1.52                         event.cbutton.which, event.cbutton.button,
    1.53 -                       ControllerButtonName(event.cbutton.button));
    1.54 +                       ControllerButtonName((SDL_GameControllerButton)event.cbutton.button));
    1.55                  break;
    1.56              case SDL_CONTROLLERBUTTONUP:
    1.57 -                printf("Controller %d button %d ('%s') up\n",
    1.58 +                SDL_Log("Controller %d button %d ('%s') up\n",
    1.59                         event.cbutton.which, event.cbutton.button,
    1.60 -                       ControllerButtonName(event.cbutton.button));
    1.61 +                       ControllerButtonName((SDL_GameControllerButton)event.cbutton.button));
    1.62                  break;
    1.63              case SDL_KEYDOWN:
    1.64                  if (event.key.keysym.sym != SDLK_ESCAPE) {
    1.65 @@ -167,7 +167,7 @@
    1.66          /* Update visual controller state */
    1.67          SDL_SetRenderDrawColor(screen, 0x00, 0xFF, 0x00, SDL_ALPHA_OPAQUE);
    1.68          for (i = 0; i <SDL_CONTROLLER_BUTTON_MAX; ++i) {
    1.69 -            if (SDL_GameControllerGetButton(gamecontroller, i) == SDL_PRESSED) {
    1.70 +            if (SDL_GameControllerGetButton(gamecontroller, (SDL_GameControllerButton)i) == SDL_PRESSED) {
    1.71                  DrawRect(screen, i * 34, SCREEN_HEIGHT - 34, 32, 32);
    1.72              }
    1.73          }
    1.74 @@ -176,7 +176,7 @@
    1.75          for (i = 0; i < SDL_CONTROLLER_AXIS_MAX / 2; ++i) {
    1.76              /* Draw the X/Y axis */
    1.77              int x, y;
    1.78 -            x = (((int) SDL_GameControllerGetAxis(gamecontroller, i * 2 + 0)) + 32768);
    1.79 +            x = (((int) SDL_GameControllerGetAxis(gamecontroller, (SDL_GameControllerAxis)(i * 2 + 0))) + 32768);
    1.80              x *= SCREEN_WIDTH;
    1.81              x /= 65535;
    1.82              if (x < 0) {
    1.83 @@ -184,7 +184,7 @@
    1.84              } else if (x > (SCREEN_WIDTH - 16)) {
    1.85                  x = SCREEN_WIDTH - 16;
    1.86              }
    1.87 -            y = (((int) SDL_GameControllerGetAxis(gamecontroller, i * 2 + 1)) + 32768);
    1.88 +            y = (((int) SDL_GameControllerGetAxis(gamecontroller, (SDL_GameControllerAxis)(i * 2 + 1))) + 32768);
    1.89              y *= SCREEN_HEIGHT;
    1.90              y /= 65535;
    1.91              if (y < 0) {
    1.92 @@ -217,9 +217,12 @@
    1.93      char guid[64];
    1.94      SDL_GameController *gamecontroller;
    1.95  
    1.96 +    /* Enable standard application logging */
    1.97 +	SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
    1.98 +
    1.99      /* Initialize SDL (Note: video is required to start event loop) */
   1.100      if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER ) < 0) {
   1.101 -        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
   1.102 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
   1.103          return 1;
   1.104      }
   1.105  
   1.106 @@ -238,22 +241,22 @@
   1.107          } else {
   1.108              name = SDL_JoystickNameForIndex(i);
   1.109          }
   1.110 -        printf("%s %d: %s (guid %s)\n", description, i, name ? name : "Unknown", guid);
   1.111 +        SDL_Log("%s %d: %s (guid %s)\n", description, i, name ? name : "Unknown", guid);
   1.112      }
   1.113 -    printf("There are %d game controller(s) attached (%d joystick(s))\n", nController, SDL_NumJoysticks());
   1.114 +    SDL_Log("There are %d game controller(s) attached (%d joystick(s))\n", nController, SDL_NumJoysticks());
   1.115  
   1.116      if (argv[1]) {
   1.117          int device = atoi(argv[1]);
   1.118          if (device >= SDL_NumJoysticks()) {
   1.119 -            printf("%i is an invalid joystick index.\n", device);
   1.120 +			SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%i is an invalid joystick index.\n", device);
   1.121              retcode = 1;
   1.122          } else {
   1.123              SDL_JoystickGetGUIDString(SDL_JoystickGetDeviceGUID(device),
   1.124                                        guid, sizeof (guid));
   1.125 -            printf("Attempting to open device %i, guid %s\n", device, guid);
   1.126 +            SDL_Log("Attempting to open device %i, guid %s\n", device, guid);
   1.127              gamecontroller = SDL_GameControllerOpen(device);
   1.128              if (gamecontroller == NULL) {
   1.129 -                printf("Couldn't open joystick %d: %s\n", device, SDL_GetError());
   1.130 +                SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open joystick %d: %s\n", device, SDL_GetError());
   1.131                  retcode = 1;
   1.132              } else {
   1.133                  WatchGameController(gamecontroller);
   1.134 @@ -272,7 +275,7 @@
   1.135  int
   1.136  main(int argc, char *argv[])
   1.137  {
   1.138 -    fprintf(stderr, "SDL compiled without Joystick support.\n");
   1.139 +    SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL compiled without Joystick support.\n");
   1.140      exit(1);
   1.141  }
   1.142