Skip to content

Commit

Permalink
Make controllermap, etc, work on platforms with hardcoded window sizes.
Browse files Browse the repository at this point in the history
This makes sure everything renders correctly, even if, say, an Android device
gives you a certain "window" size no matter what you ask for.
  • Loading branch information
icculus committed Feb 10, 2014
1 parent 9268c7a commit 2d92a37
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
14 changes: 8 additions & 6 deletions test/controllermap.c
Expand Up @@ -101,7 +101,7 @@ WatchJoystick(SDL_Joystick * joystick)
{
SDL_Window *window = NULL;
SDL_Renderer *screen = NULL;
SDL_Texture *target, *background, *button, *axis, *marker;
SDL_Texture *background, *button, *axis, *marker;
const char *name = NULL;
SDL_bool retval = SDL_FALSE;
SDL_bool done = SDL_FALSE, next=SDL_FALSE;
Expand Down Expand Up @@ -152,12 +152,14 @@ WatchJoystick(SDL_Joystick * joystick)
return SDL_FALSE;
}

target = SDL_CreateTexture(screen, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_TARGET, MAP_WIDTH, MAP_HEIGHT);
background = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
button = LoadTexture(screen, "button.bmp", SDL_TRUE);
axis = LoadTexture(screen, "axis.bmp", SDL_TRUE);
SDL_RaiseWindow(window);

/* scale for platforms that don't give you the window size you asked for. */
SDL_RenderSetLogicalSize(screen, SCREEN_WIDTH, SCREEN_HEIGHT);

/* Print info about the joystick we are watching */
name = SDL_JoystickName(joystick);
SDL_Log("Watching joystick %d: (%s)\n", SDL_JoystickInstanceID(joystick),
Expand Down Expand Up @@ -206,7 +208,9 @@ WatchJoystick(SDL_Joystick * joystick)
dst.y = step->y;
SDL_QueryTexture(marker, NULL, NULL, &dst.w, &dst.h);
next=SDL_FALSE;


SDL_SetRenderDrawColor(screen, 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE);

while (!done && !next) {
if (SDL_GetTicks() - alpha_ticks > 5) {
alpha_ticks = SDL_GetTicks();
Expand All @@ -219,13 +223,11 @@ WatchJoystick(SDL_Joystick * joystick)
}
}

SDL_SetRenderTarget(screen, target);
SDL_RenderClear(screen);
SDL_RenderCopy(screen, background, NULL, NULL);
SDL_SetTextureAlphaMod(marker, alpha);
SDL_SetTextureColorMod(marker, 10, 255, 21);
SDL_RenderCopyEx(screen, marker, NULL, &dst, step->angle, NULL, 0);
SDL_SetRenderTarget(screen, NULL);
SDL_RenderCopy(screen, target, NULL, NULL);
SDL_RenderPresent(screen);

if (SDL_PollEvent(&event)) {
Expand Down
5 changes: 4 additions & 1 deletion test/testgamecontroller.c
Expand Up @@ -170,6 +170,9 @@ WatchGameController(SDL_GameController * gamecontroller)
SDL_RenderPresent(screen);
SDL_RaiseWindow(window);

/* scale for platforms that don't give you the window size you asked for. */
SDL_RenderSetLogicalSize(screen, SCREEN_WIDTH, SCREEN_HEIGHT);

background = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
button = LoadTexture(screen, "button.bmp", SDL_TRUE);
axis = LoadTexture(screen, "axis.bmp", SDL_TRUE);
Expand All @@ -191,7 +194,7 @@ WatchGameController(SDL_GameController * gamecontroller)
/* Loop, getting controller events! */
while (!done) {
/* blank screen, set up for drawing this frame. */
SDL_SetRenderDrawColor(screen, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
SDL_SetRenderDrawColor(screen, 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE);
SDL_RenderClear(screen);
SDL_RenderCopy(screen, background, NULL, NULL);

Expand Down

0 comments on commit 2d92a37

Please sign in to comment.