From 2d92a37237fc8bd4c06b0c1087b0f96f843f456b Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 10 Feb 2014 11:29:48 -0500 Subject: [PATCH] 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 | 14 ++++++++------ test/testgamecontroller.c | 5 ++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/test/controllermap.c b/test/controllermap.c index f990ff4f4ca98..e6e9607ce456e 100644 --- a/test/controllermap.c +++ b/test/controllermap.c @@ -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; @@ -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), @@ -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(); @@ -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)) { diff --git a/test/testgamecontroller.c b/test/testgamecontroller.c index e7c1e0575d7c5..f762ce622f312 100644 --- a/test/testgamecontroller.c +++ b/test/testgamecontroller.c @@ -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); @@ -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);