added support for updating grid buttons after the screen was rotated
authorHolger Schemel <info@artsoft.org>
Wed, 9 May 2018 19:36:39 +0000 (21:36 +0200)
committerHolger Schemel <info@artsoft.org>
Tue, 5 Jun 2018 18:58:41 +0000 (20:58 +0200)
src/events.c
src/screens.c

index 3d1163638a24738f20af985e658300d3e8eedd10..5a4023ec36b3e621d0d22fa5e8dc1b3765dfc293 100644 (file)
@@ -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
index 3dd571fe857cb912493d9dc0105a0a559103d2fe..8b5c2bb474efcf9d70e24b507fc6ca684888e9ba 100644 (file)
@@ -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;