added separate grid buttons for landscape and portrait screen orientation
authorHolger Schemel <info@artsoft.org>
Wed, 9 May 2018 19:24:04 +0000 (21:24 +0200)
committerHolger Schemel <info@artsoft.org>
Tue, 5 Jun 2018 18:58:41 +0000 (20:58 +0200)
Separate grid buttons can be configured for landscape and portrait screen
orientation. The correct grid buttons are currently only selected at the
start of the program, but not after the screen was rotated.

src/libgame/system.c
src/libgame/system.h
src/screens.c

index 33246588592ebf6dab8b5da904fb314f9bd97492..5b7cede45da7a2932ca770d4bc9722b85eac13ed 100644 (file)
@@ -334,15 +334,8 @@ void InitOverlayInfo()
     { "111222",        "  vv  " },
     { "111222",        "  vv  " }
   };
-  int min_xsize, min_ysize;
-  int startx, starty;
-  int x, y;
-
-  min_xsize = MIN(6, DEFAULT_GRID_XSIZE);
-  min_ysize = MIN(6, DEFAULT_GRID_YSIZE);
-
-  startx = DEFAULT_GRID_XSIZE - min_xsize;
-  starty = DEFAULT_GRID_YSIZE - min_ysize;
+  int nr = GRID_ACTIVE_NR();
+  int i, x, y;
 
   overlay.enabled = FALSE;
   overlay.active = FALSE;
@@ -350,22 +343,39 @@ void InitOverlayInfo()
   overlay.show_grid = FALSE;
   overlay.show_grid_buttons = FALSE;
 
-  overlay.grid_xsize = DEFAULT_GRID_XSIZE;
-  overlay.grid_ysize = DEFAULT_GRID_YSIZE;
+  for (i = 0; i < 2; i++)
+  {
+    int grid_xsize = DEFAULT_GRID_XSIZE(i);
+    int grid_ysize = DEFAULT_GRID_YSIZE(i);
+    int min_xsize = MIN(6, grid_xsize);
+    int min_ysize = MIN(6, grid_ysize);
+    int startx = grid_xsize - min_xsize;
+    int starty = grid_ysize - min_ysize;
+
+    overlay.grid_xsize_all[i] = grid_xsize;
+    overlay.grid_ysize_all[i] = grid_ysize;
+
+    for (x = 0; x < MAX_GRID_XSIZE; x++)
+      for (y = 0; y < MAX_GRID_YSIZE; y++)
+       overlay.grid_button_all[i][x][y] = CHAR_GRID_BUTTON_NONE;
+
+    for (x = 0; x < min_xsize; x++)
+      for (y = 0; y < min_ysize; y++)
+       overlay.grid_button_all[i][x][starty + y] =
+         default_grid_button[y][0][x];
+
+    for (x = 0; x < min_xsize; x++)
+      for (y = 0; y < min_ysize; y++)
+       overlay.grid_button_all[i][startx + x][starty + y] =
+         default_grid_button[y][1][x];
+  }
+
+  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] = CHAR_GRID_BUTTON_NONE;
-
-  for (x = 0; x < min_xsize; x++)
-    for (y = 0; y < min_ysize; y++)
-      overlay.grid_button[x][starty + y] =
-       default_grid_button[y][0][x];
-
-  for (x = 0; x < min_xsize; x++)
-    for (y = 0; y < min_ysize; y++)
-      overlay.grid_button[startx + x][starty + y] =
-       default_grid_button[y][1][x];
+      overlay.grid_button[x][y] = overlay.grid_button_all[nr][x][y];
 
   overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
 
index 06a47c3c685fe17fc7eda1692843d7d8c51fa080..b5c5fcee6771397befef3e9f6710bf32f26f2e1b 100644 (file)
 #define MIN_GRID_YSIZE                 3
 #define MAX_GRID_XSIZE                 32
 #define MAX_GRID_YSIZE                 32
-#define DEFAULT_GRID_XSIZE             18
-#define DEFAULT_GRID_YSIZE             MIN(MAX(MIN_GRID_YSIZE,         \
-                                               DEFAULT_GRID_XSIZE *    \
-                                               video.screen_height /   \
-                                               video.screen_width),    \
+#define GRID_REAL_WIDTH                        MAX(video.screen_width, \
+                                           video.screen_height)
+#define GRID_REAL_HEIGHT               MIN(video.screen_width, \
+                                           video.screen_height)
+#define DEFAULT_GRID_XSIZE_0           18
+#define DEFAULT_GRID_YSIZE_0           MIN(MAX(MIN_GRID_YSIZE,         \
+                                               DEFAULT_GRID_XSIZE_0 *  \
+                                               GRID_REAL_HEIGHT /      \
+                                               GRID_REAL_WIDTH),       \
                                            MAX_GRID_YSIZE)
+#define DEFAULT_GRID_XSIZE_1           13
+#define DEFAULT_GRID_YSIZE_1           MIN(MAX(MIN_GRID_YSIZE,         \
+                                               DEFAULT_GRID_XSIZE_1 *  \
+                                               GRID_REAL_WIDTH /       \
+                                               GRID_REAL_HEIGHT),      \
+                                           MAX_GRID_YSIZE)
+
+#define DEFAULT_GRID_XSIZE(n)          (n == 0 ? DEFAULT_GRID_XSIZE_0 : \
+                                        DEFAULT_GRID_XSIZE_1)
+#define DEFAULT_GRID_YSIZE(n)          (n == 0 ? DEFAULT_GRID_YSIZE_0 : \
+                                        DEFAULT_GRID_YSIZE_1)
+
+#define GRID_ACTIVE_NR()               (video.screen_width >   \
+                                        video.screen_height ? 0 : 1)
 
 /* values for grid button characters for virtual buttons */
 #define CHAR_GRID_BUTTON_NONE          ' '
@@ -1000,9 +1018,12 @@ struct OverlayInfo
   boolean show_grid;
   boolean show_grid_buttons;
 
+  int grid_xsize_all[2];
+  int grid_ysize_all[2];
   int grid_xsize;
   int grid_ysize;
 
+  char grid_button_all[2][MAX_GRID_XSIZE][MAX_GRID_YSIZE];
   char grid_button[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
   char grid_button_highlight;
 };
index 1444fe8be075de897b9e91c869047097f903bf2f..3dd571fe857cb912493d9dc0105a0a559103d2fe 100644 (file)
@@ -7206,6 +7206,7 @@ boolean ConfigureVirtualButtonsMain()
   char grid_button_old[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
   char grid_button_tmp[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
   boolean set_grid_button = FALSE;
+  int nr = GRID_ACTIVE_NR();
   int x, y;
 
   for (x = 0; x < MAX_GRID_XSIZE; x++)
@@ -7369,6 +7370,10 @@ boolean ConfigureVirtualButtonsMain()
     BackToFront();
   }
 
+  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];
+
   overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
 
   SetOverlayShowGrid(FALSE);