mirror of https://github.com/encounter/SDL.git
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.
This commit is contained in:
parent
9268c7a1b3
commit
2d92a37237
|
@ -101,7 +101,7 @@ WatchJoystick(SDL_Joystick * joystick)
|
||||||
{
|
{
|
||||||
SDL_Window *window = NULL;
|
SDL_Window *window = NULL;
|
||||||
SDL_Renderer *screen = NULL;
|
SDL_Renderer *screen = NULL;
|
||||||
SDL_Texture *target, *background, *button, *axis, *marker;
|
SDL_Texture *background, *button, *axis, *marker;
|
||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
SDL_bool retval = SDL_FALSE;
|
SDL_bool retval = SDL_FALSE;
|
||||||
SDL_bool done = SDL_FALSE, next=SDL_FALSE;
|
SDL_bool done = SDL_FALSE, next=SDL_FALSE;
|
||||||
|
@ -152,12 +152,14 @@ WatchJoystick(SDL_Joystick * joystick)
|
||||||
return SDL_FALSE;
|
return SDL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
target = SDL_CreateTexture(screen, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_TARGET, MAP_WIDTH, MAP_HEIGHT);
|
|
||||||
background = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
|
background = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
|
||||||
button = LoadTexture(screen, "button.bmp", SDL_TRUE);
|
button = LoadTexture(screen, "button.bmp", SDL_TRUE);
|
||||||
axis = LoadTexture(screen, "axis.bmp", SDL_TRUE);
|
axis = LoadTexture(screen, "axis.bmp", SDL_TRUE);
|
||||||
SDL_RaiseWindow(window);
|
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 */
|
/* Print info about the joystick we are watching */
|
||||||
name = SDL_JoystickName(joystick);
|
name = SDL_JoystickName(joystick);
|
||||||
SDL_Log("Watching joystick %d: (%s)\n", SDL_JoystickInstanceID(joystick),
|
SDL_Log("Watching joystick %d: (%s)\n", SDL_JoystickInstanceID(joystick),
|
||||||
|
@ -207,6 +209,8 @@ WatchJoystick(SDL_Joystick * joystick)
|
||||||
SDL_QueryTexture(marker, NULL, NULL, &dst.w, &dst.h);
|
SDL_QueryTexture(marker, NULL, NULL, &dst.w, &dst.h);
|
||||||
next=SDL_FALSE;
|
next=SDL_FALSE;
|
||||||
|
|
||||||
|
SDL_SetRenderDrawColor(screen, 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE);
|
||||||
|
|
||||||
while (!done && !next) {
|
while (!done && !next) {
|
||||||
if (SDL_GetTicks() - alpha_ticks > 5) {
|
if (SDL_GetTicks() - alpha_ticks > 5) {
|
||||||
alpha_ticks = SDL_GetTicks();
|
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_RenderCopy(screen, background, NULL, NULL);
|
||||||
SDL_SetTextureAlphaMod(marker, alpha);
|
SDL_SetTextureAlphaMod(marker, alpha);
|
||||||
SDL_SetTextureColorMod(marker, 10, 255, 21);
|
SDL_SetTextureColorMod(marker, 10, 255, 21);
|
||||||
SDL_RenderCopyEx(screen, marker, NULL, &dst, step->angle, NULL, 0);
|
SDL_RenderCopyEx(screen, marker, NULL, &dst, step->angle, NULL, 0);
|
||||||
SDL_SetRenderTarget(screen, NULL);
|
|
||||||
SDL_RenderCopy(screen, target, NULL, NULL);
|
|
||||||
SDL_RenderPresent(screen);
|
SDL_RenderPresent(screen);
|
||||||
|
|
||||||
if (SDL_PollEvent(&event)) {
|
if (SDL_PollEvent(&event)) {
|
||||||
|
|
|
@ -170,6 +170,9 @@ WatchGameController(SDL_GameController * gamecontroller)
|
||||||
SDL_RenderPresent(screen);
|
SDL_RenderPresent(screen);
|
||||||
SDL_RaiseWindow(window);
|
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);
|
background = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
|
||||||
button = LoadTexture(screen, "button.bmp", SDL_TRUE);
|
button = LoadTexture(screen, "button.bmp", SDL_TRUE);
|
||||||
axis = LoadTexture(screen, "axis.bmp", SDL_TRUE);
|
axis = LoadTexture(screen, "axis.bmp", SDL_TRUE);
|
||||||
|
@ -191,7 +194,7 @@ WatchGameController(SDL_GameController * gamecontroller)
|
||||||
/* Loop, getting controller events! */
|
/* Loop, getting controller events! */
|
||||||
while (!done) {
|
while (!done) {
|
||||||
/* blank screen, set up for drawing this frame. */
|
/* 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_RenderClear(screen);
|
||||||
SDL_RenderCopy(screen, background, NULL, NULL);
|
SDL_RenderCopy(screen, background, NULL, NULL);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue