moved virtual buttons definitions to setup data structures
authorHolger Schemel <info@artsoft.org>
Thu, 10 May 2018 23:30:30 +0000 (01:30 +0200)
committerHolger Schemel <info@artsoft.org>
Tue, 5 Jun 2018 18:58:42 +0000 (20:58 +0200)
src/events.c
src/files.c
src/init.c
src/libgame/system.c
src/libgame/system.h
src/screens.c

index 4fcbd19981885ce1074cb310c08aae18cb6c2490..2120931852677da9e9a8e70cd4692aa341a77b18 100644 (file)
@@ -653,17 +653,17 @@ void HandleWindowEvent(WindowEvent *event)
            // 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];
+               setup.touch.grid_button[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];
+         overlay.grid_xsize = setup.touch.grid_xsize[nr];
+         overlay.grid_ysize = setup.touch.grid_ysize[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];
+             overlay.grid_button[x][y] = setup.touch.grid_button[nr][x][y];
        }
       }
     }
index 3f456937a028f80f6b1929211d4cc8fa44433541..86fcdc719eedeb8b985beb0569ba80e4cffa253c 100644 (file)
@@ -8721,6 +8721,55 @@ static void setSetupInfoToDefaults(struct SetupInfo *si)
   si->touch.move_distance = TOUCH_MOVE_DISTANCE_DEFAULT;       /* percent */
   si->touch.drop_distance = TOUCH_DROP_DISTANCE_DEFAULT;       /* percent */
 
+  for (i = 0; i < 2; i++)
+  {
+    char *default_grid_button[6][2] =
+    {
+      { "      ", "  ^^  " },
+      { "      ", "  ^^  " },
+      { "      ", "<<  >>" },
+      { "      ", "<<  >>" },
+      { "111222", "  vv  " },
+      { "111222", "  vv  " }
+    };
+    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;
+    int x, y;
+
+    // virtual buttons grid can only be set to defaults if video is initialized
+    // (this will be repeated if virtual buttons are not loaded from setup file)
+    if (video.initialized)
+    {
+      si->touch.grid_xsize[i] = grid_xsize;
+      si->touch.grid_ysize[i] = grid_ysize;
+    }
+    else
+    {
+      si->touch.grid_xsize[i] = -1;
+      si->touch.grid_ysize[i] = -1;
+    }
+
+    for (x = 0; x < MAX_GRID_XSIZE; x++)
+      for (y = 0; y < MAX_GRID_YSIZE; y++)
+       si->touch.grid_button[i][x][y] = CHAR_GRID_BUTTON_NONE;
+
+    for (x = 0; x < min_xsize; x++)
+      for (y = 0; y < min_ysize; y++)
+       si->touch.grid_button[i][x][starty + y] =
+         default_grid_button[y][0][x];
+
+    for (x = 0; x < min_xsize; x++)
+      for (y = 0; y < min_ysize; y++)
+       si->touch.grid_button[i][startx + x][starty + y] =
+         default_grid_button[y][1][x];
+  }
+
+  si->touch.grid_initialized           = video.initialized;
+
   si->editor.el_boulderdash            = TRUE;
   si->editor.el_emerald_mine           = TRUE;
   si->editor.el_emerald_mine_club      = TRUE;
index 3e0f01dbaba6950025412f58e1539ed5320fb4c2..863704ef87709702d125e4d05d2752c9257e2782 100644 (file)
@@ -5237,6 +5237,17 @@ static void InitMixer()
   StartMixer();
 }
 
+static void InitVideoOverlay()
+{
+  // if virtual buttons are not loaded from setup file, repeat initializing
+  // virtual buttons grid with default values now that video is initialized
+  if (!setup.touch.grid_initialized)
+    InitSetup();
+
+  InitTileCursorInfo();
+  InitOverlayInfo();
+}
+
 void InitGfxBuffers()
 {
   static int win_xsize_last = -1;
@@ -6013,9 +6024,7 @@ void OpenAll()
   InitVideoDefaults();
   InitVideoDisplay();
   InitVideoBuffer(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, setup.fullscreen);
-
-  InitTileCursorInfo();
-  InitOverlayInfo();
+  InitVideoOverlay();
 
   print_timestamp_time("[init video stuff]");
 
index 3363ac2b94c7cbfe976ba25c2806b403b75595f6..b7970fd50dddd1c84f8b54d236628ea0307aee02 100644 (file)
@@ -325,56 +325,20 @@ void InitTileCursorInfo()
 
 void InitOverlayInfo()
 {
-  static char *default_grid_button[6][2] =
-  {
-    { "      ",        "  ^^  " },
-    { "      ",        "  ^^  " },
-    { "      ",        "<<  >>" },
-    { "      ",        "<<  >>" },
-    { "111222",        "  vv  " },
-    { "111222",        "  vv  " }
-  };
   int nr = GRID_ACTIVE_NR();
-  int i, x, y;
+  int x, y;
 
   overlay.enabled = FALSE;
   overlay.active = FALSE;
 
   overlay.show_grid = FALSE;
 
-  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];
+  overlay.grid_xsize = setup.touch.grid_xsize[nr];
+  overlay.grid_ysize = setup.touch.grid_ysize[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];
+      overlay.grid_button[x][y] = setup.touch.grid_button[nr][x][y];
 
   overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
 
index 480ef0d426820e4719effd45d914d909fa171c49..4ef22022c95a4e2d1dde0325742dce733695c09b 100644 (file)
 #define MIN_GRID_YSIZE                 3
 #define MAX_GRID_XSIZE                 32
 #define MAX_GRID_YSIZE                 32
-#define GRID_REAL_WIDTH                        MAX(video.screen_width, \
-                                           video.screen_height)
-#define GRID_REAL_HEIGHT               MIN(video.screen_width, \
-                                           video.screen_height)
+#define GRID_REAL_WIDTH                        MAX(1, MAX(video.screen_width,  \
+                                                  video.screen_height))
+#define GRID_REAL_HEIGHT               MAX(1, 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 *  \
@@ -1017,12 +1017,9 @@ struct OverlayInfo
 
   boolean show_grid;
 
-  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;
 };
@@ -1053,6 +1050,13 @@ struct SetupTouchInfo
   char *control_type;
   int move_distance;
   int drop_distance;
+
+  int grid_xsize[2];
+  int grid_ysize[2];
+
+  char grid_button[2][MAX_GRID_XSIZE][MAX_GRID_YSIZE];
+
+  boolean grid_initialized;
 };
 
 struct SetupInputInfo
index 8b5c2bb474efcf9d70e24b507fc6ca684888e9ba..f49f895904f61fe99b3c89995f2769d31eb7548c 100644 (file)
@@ -7397,7 +7397,7 @@ boolean ConfigureVirtualButtonsMain()
 
   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];
+      setup.touch.grid_button[nr][x][y] = overlay.grid_button[x][y];
 
   overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;