From: Holger Schemel Date: Wed, 9 May 2018 19:36:39 +0000 (+0200) Subject: added support for updating grid buttons after the screen was rotated X-Git-Tag: 4.1.1.0~168 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=73b48f8afe7e1e1faf0e87436d7d74b27bba5f27;p=rocksndiamonds.git added support for updating grid buttons after the screen was rotated --- diff --git a/src/events.c b/src/events.c index 3d116363..5a4023ec 100644 --- a/src/events.c +++ b/src/events.c @@ -636,10 +636,35 @@ void HandleWindowEvent(WindowEvent *event) if (new_display_width != video.display_width || new_display_height != video.display_height) { + int nr = GRID_ACTIVE_NR(); // previous screen orientation + video.display_width = new_display_width; video.display_height = new_display_height; SDLSetScreenProperties(); + + // check if screen orientation has changed (should always be true here) + if (nr != GRID_ACTIVE_NR()) + { + int x, y; + + if (game_status == GAME_MODE_SETUP) + { + // save active virtual buttons (in case of just configuring them) + for (x = 0; x < MAX_GRID_XSIZE; x++) + for (y = 0; y < MAX_GRID_YSIZE; y++) + overlay.grid_button_all[nr][x][y] = overlay.grid_button[x][y]; + } + + nr = GRID_ACTIVE_NR(); + + overlay.grid_xsize = overlay.grid_xsize_all[nr]; + overlay.grid_ysize = overlay.grid_ysize_all[nr]; + + for (x = 0; x < MAX_GRID_XSIZE; x++) + for (y = 0; y < MAX_GRID_YSIZE; y++) + overlay.grid_button[x][y] = overlay.grid_button_all[nr][x][y]; + } } } #endif diff --git a/src/screens.c b/src/screens.c index 3dd571fe..8b5c2bb4 100644 --- a/src/screens.c +++ b/src/screens.c @@ -7351,6 +7351,31 @@ boolean ConfigureVirtualButtonsMain() } break; +#if defined(TARGET_SDL2) + case SDL_WINDOWEVENT: + HandleWindowEvent((WindowEvent *) &event); + + // check if device has been rotated + if (nr != GRID_ACTIVE_NR()) + { + nr = GRID_ACTIVE_NR(); + + for (x = 0; x < MAX_GRID_XSIZE; x++) + for (y = 0; y < MAX_GRID_YSIZE; y++) + grid_button_old[x][y] = grid_button_tmp[x][y] = + overlay.grid_button[x][y]; + } + + break; + + case SDL_APP_WILLENTERBACKGROUND: + case SDL_APP_DIDENTERBACKGROUND: + case SDL_APP_WILLENTERFOREGROUND: + case SDL_APP_DIDENTERFOREGROUND: + HandlePauseResumeEvent((PauseResumeEvent *) &event); + break; +#endif + default: HandleOtherEvents(&event); break;