test/testgamecontroller.c
changeset 6916 92e978d6dafa
parent 6914 8a9915ab24f0
child 6917 47dc155b774d
equal deleted inserted replaced
6915:d58bf9cfd709 6916:92e978d6dafa
    86 }
    86 }
    87 
    87 
    88 void
    88 void
    89 WatchGameController(SDL_GameController * gamecontroller)
    89 WatchGameController(SDL_GameController * gamecontroller)
    90 {
    90 {
    91     const char *controllername = gamecontroller ? SDL_GameControllerName(gamecontroller) : "???";
    91     const char *name = SDL_GameControllerName(gamecontroller);
    92     const char *basetitle = "Game Controller Test: ";
    92     const char *basetitle = "Game Controller Test: ";
    93     const size_t titlelen = SDL_strlen(basetitle) + SDL_strlen(controllername) + 1;
    93     const size_t titlelen = SDL_strlen(basetitle) + SDL_strlen(name) + 1;
    94     char *title = SDL_malloc(titlelen);
    94     char *title = SDL_malloc(titlelen);
    95     SDL_Window *window = NULL;
    95     SDL_Window *window = NULL;
    96     SDL_Renderer *screen = NULL;
    96     SDL_Renderer *screen = NULL;
    97     const char *name = NULL;
       
    98     int done = 0;
    97     int done = 0;
    99     SDL_Event event;
    98     SDL_Event event;
   100     int i;
    99     int i;
   101 
   100 
   102     if (title) {
   101     if (title) {
   103         SDL_snprintf(title, titlelen, "%s%s", basetitle, controllername);
   102         SDL_snprintf(title, titlelen, "%s%s", basetitle, name);
   104     }
   103     }
   105 
   104 
   106     /* Create a window to display controller axis position */
   105     /* Create a window to display controller axis position */
   107     window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED,
   106     window = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED,
   108                               SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
   107                               SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
   123     SDL_RenderClear(screen);
   122     SDL_RenderClear(screen);
   124     SDL_RenderPresent(screen);
   123     SDL_RenderPresent(screen);
   125 	SDL_RaiseWindow(window);
   124 	SDL_RaiseWindow(window);
   126 
   125 
   127     /* Print info about the controller we are watching */
   126     /* Print info about the controller we are watching */
   128     name = SDL_GameControllerName(gamecontroller);
       
   129     printf("Watching controller %s\n",  name ? name : "Unknown Controller");
   127     printf("Watching controller %s\n",  name ? name : "Unknown Controller");
   130     
   128     
   131     /* Loop, getting controller events! */
   129     /* Loop, getting controller events! */
   132     while (!done) {
   130     while (!done) {
   133         /* blank screen, set up for drawing this frame. */
   131         /* blank screen, set up for drawing this frame. */