Make controllermap, etc, work on platforms with hardcoded window sizes.
authorRyan C. Gordon <icculus@icculus.org>
Mon, 10 Feb 2014 11:29:48 -0500
changeset 8202b84a1f55075e
parent 8201 4a16c26b6055
child 8203 5c9ac454116e
Make controllermap, etc, work on platforms with hardcoded window sizes.

This makes sure everything renders correctly, even if, say, an Android device
gives you a certain "window" size no matter what you ask for.
test/controllermap.c
test/testgamecontroller.c
     1.1 --- a/test/controllermap.c	Mon Feb 10 09:26:22 2014 -0300
     1.2 +++ b/test/controllermap.c	Mon Feb 10 11:29:48 2014 -0500
     1.3 @@ -101,7 +101,7 @@
     1.4  {
     1.5      SDL_Window *window = NULL;
     1.6      SDL_Renderer *screen = NULL;
     1.7 -    SDL_Texture *target, *background, *button, *axis, *marker;
     1.8 +    SDL_Texture *background, *button, *axis, *marker;
     1.9      const char *name = NULL;
    1.10      SDL_bool retval = SDL_FALSE;
    1.11      SDL_bool done = SDL_FALSE, next=SDL_FALSE;
    1.12 @@ -152,12 +152,14 @@
    1.13          return SDL_FALSE;
    1.14      }
    1.15      
    1.16 -    target = SDL_CreateTexture(screen, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_TARGET, MAP_WIDTH, MAP_HEIGHT);
    1.17      background = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
    1.18      button = LoadTexture(screen, "button.bmp", SDL_TRUE);
    1.19      axis = LoadTexture(screen, "axis.bmp", SDL_TRUE);
    1.20      SDL_RaiseWindow(window);
    1.21  
    1.22 +    /* scale for platforms that don't give you the window size you asked for. */
    1.23 +    SDL_RenderSetLogicalSize(screen, SCREEN_WIDTH, SCREEN_HEIGHT);
    1.24 +
    1.25      /* Print info about the joystick we are watching */
    1.26      name = SDL_JoystickName(joystick);
    1.27      SDL_Log("Watching joystick %d: (%s)\n", SDL_JoystickInstanceID(joystick),
    1.28 @@ -206,7 +208,9 @@
    1.29          dst.y = step->y;
    1.30          SDL_QueryTexture(marker, NULL, NULL, &dst.w, &dst.h);
    1.31          next=SDL_FALSE;
    1.32 -        
    1.33 +
    1.34 +        SDL_SetRenderDrawColor(screen, 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE);
    1.35 +
    1.36          while (!done && !next) {
    1.37              if (SDL_GetTicks() - alpha_ticks > 5) {
    1.38                  alpha_ticks = SDL_GetTicks();
    1.39 @@ -219,13 +223,11 @@
    1.40                  }
    1.41              }
    1.42              
    1.43 -            SDL_SetRenderTarget(screen, target);
    1.44 +            SDL_RenderClear(screen);
    1.45              SDL_RenderCopy(screen, background, NULL, NULL);
    1.46              SDL_SetTextureAlphaMod(marker, alpha);
    1.47              SDL_SetTextureColorMod(marker, 10, 255, 21);
    1.48              SDL_RenderCopyEx(screen, marker, NULL, &dst, step->angle, NULL, 0);
    1.49 -            SDL_SetRenderTarget(screen, NULL);
    1.50 -            SDL_RenderCopy(screen, target, NULL, NULL);
    1.51              SDL_RenderPresent(screen);
    1.52              
    1.53              if (SDL_PollEvent(&event)) {
     2.1 --- a/test/testgamecontroller.c	Mon Feb 10 09:26:22 2014 -0300
     2.2 +++ b/test/testgamecontroller.c	Mon Feb 10 11:29:48 2014 -0500
     2.3 @@ -170,6 +170,9 @@
     2.4      SDL_RenderPresent(screen);
     2.5      SDL_RaiseWindow(window);
     2.6  
     2.7 +    /* scale for platforms that don't give you the window size you asked for. */
     2.8 +    SDL_RenderSetLogicalSize(screen, SCREEN_WIDTH, SCREEN_HEIGHT);
     2.9 +
    2.10      background = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
    2.11      button = LoadTexture(screen, "button.bmp", SDL_TRUE);
    2.12      axis = LoadTexture(screen, "axis.bmp", SDL_TRUE);
    2.13 @@ -191,7 +194,7 @@
    2.14      /* Loop, getting controller events! */
    2.15      while (!done) {
    2.16          /* blank screen, set up for drawing this frame. */
    2.17 -        SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
    2.18 +        SDL_SetRenderDrawColor(screen, 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE);
    2.19          SDL_RenderClear(screen);
    2.20          SDL_RenderCopy(screen, background, NULL, NULL);
    2.21