added option to draw virtual buttons outlined
authorHolger Schemel <info@artsoft.org>
Sat, 12 May 2018 09:40:59 +0000 (11:40 +0200)
committerHolger Schemel <info@artsoft.org>
Tue, 5 Jun 2018 18:58:42 +0000 (20:58 +0200)
src/files.c
src/libgame/sdl.c
src/libgame/system.h
src/screens.c

index c7408331e2fe1c04b9783780336023a6c7e686b1..e59d36214e622edc7d0a71b4408643c5b5ddc874 100644 (file)
@@ -8306,12 +8306,13 @@ void SaveScore(int nr)
 #define SETUP_TOKEN_TOUCH_MOVE_DISTANCE                42
 #define SETUP_TOKEN_TOUCH_DROP_DISTANCE                43
 #define SETUP_TOKEN_TOUCH_TRANSPARENCY         44
-#define SETUP_TOKEN_TOUCH_GRID_XSIZE_0         45
-#define SETUP_TOKEN_TOUCH_GRID_YSIZE_0         46
-#define SETUP_TOKEN_TOUCH_GRID_XSIZE_1         47
-#define SETUP_TOKEN_TOUCH_GRID_YSIZE_1         48
+#define SETUP_TOKEN_TOUCH_DRAW_OUTLINED                45
+#define SETUP_TOKEN_TOUCH_GRID_XSIZE_0         46
+#define SETUP_TOKEN_TOUCH_GRID_YSIZE_0         47
+#define SETUP_TOKEN_TOUCH_GRID_XSIZE_1         48
+#define SETUP_TOKEN_TOUCH_GRID_YSIZE_1         49
 
-#define NUM_GLOBAL_SETUP_TOKENS                        49
+#define NUM_GLOBAL_SETUP_TOKENS                        50
 
 /* auto setup */
 #define SETUP_TOKEN_AUTO_EDITOR_ZOOM_TILESIZE  0
@@ -8513,6 +8514,7 @@ static struct TokenInfo global_setup_tokens[] =
   { TYPE_INTEGER,&si.touch.move_distance,     "touch.move_distance"    },
   { TYPE_INTEGER,&si.touch.drop_distance,     "touch.drop_distance"    },
   { TYPE_INTEGER,&si.touch.transparency,      "touch.transparency"     },
+  { TYPE_INTEGER,&si.touch.draw_outlined,     "touch.draw_outlined"    },
   { TYPE_INTEGER,&si.touch.grid_xsize[0],     "touch.virtual_buttons.0.xsize" },
   { TYPE_INTEGER,&si.touch.grid_ysize[0],     "touch.virtual_buttons.0.ysize" },
   { TYPE_INTEGER,&si.touch.grid_xsize[1],     "touch.virtual_buttons.1.xsize" },
@@ -8731,6 +8733,7 @@ static void setSetupInfoToDefaults(struct SetupInfo *si)
   si->touch.move_distance = TOUCH_MOVE_DISTANCE_DEFAULT;       /* percent */
   si->touch.drop_distance = TOUCH_DROP_DISTANCE_DEFAULT;       /* percent */
   si->touch.transparency = TOUCH_TRANSPARENCY_DEFAULT;         /* percent */
+  si->touch.draw_outlined = TRUE;
 
   for (i = 0; i < 2; i++)
   {
index 46d9abac9ea7aef6cb5d048c3f3f94ce86a1812f..8ac2fc3af6e298f3eb3ba20fb8155c4607d64205 100644 (file)
@@ -3012,6 +3012,13 @@ static void DrawTouchInputOverlay_ShowGrid(int alpha)
   SDL_SetRenderDrawColor(sdl_renderer, 0, 0, 0, 255);
 }
 
+static void RenderFillRectangle(int x, int y, int width, int height)
+{
+  SDL_Rect rect = { x, y, width, height };
+
+  SDL_RenderFillRect(sdl_renderer, &rect);
+}
+
 static void DrawTouchInputOverlay_ShowGridButtons(int alpha)
 {
   static int alpha_direction = 0;
@@ -3054,6 +3061,9 @@ static void DrawTouchInputOverlay_ShowGridButtons(int alpha)
     {
       int grid_button = overlay.grid_button[x][y];
       int alpha_draw = alpha;
+      int outline_border = MV_NONE;
+      int border_size = 2;
+      boolean draw_outlined = setup.touch.draw_outlined;
 
       if (grid_button == CHAR_GRID_BUTTON_NONE)
        continue;
@@ -3070,27 +3080,60 @@ static void DrawTouchInputOverlay_ShowGridButtons(int alpha)
 
       if (x == 0 || overlay.grid_button[x - 1][y] != grid_button)
       {
-       rect.x += 2;
-       rect.w -= 2;
+       rect.x += border_size;
+       rect.w -= border_size;
+
+       outline_border |= MV_LEFT;
       }
 
       if (x == grid_xsize - 1 || overlay.grid_button[x + 1][y] != grid_button)
       {
-       rect.w -= 2;
+       rect.w -= border_size;
+
+       outline_border |= MV_RIGHT;
       }
 
       if (y == 0 || overlay.grid_button[x][y - 1] != grid_button)
       {
-       rect.y += 2;
-       rect.h -= 2;
+       rect.y += border_size;
+       rect.h -= border_size;
+
+       outline_border |= MV_UP;
       }
 
       if (y == grid_ysize - 1 || overlay.grid_button[x][y + 1] != grid_button)
       {
-       rect.h -= 2;
+       rect.h -= border_size;
+
+       outline_border |= MV_DOWN;
       }
 
-      SDL_RenderFillRect(sdl_renderer, &rect);
+      if (draw_outlined)
+      {
+       int rect_x = rect.x +
+         (outline_border & MV_LEFT  ? border_size : 0);
+       int rect_w = rect.w -
+         (outline_border & MV_LEFT  ? border_size : 0) -
+         (outline_border & MV_RIGHT ? border_size : 0);
+
+       if (outline_border & MV_LEFT)
+         RenderFillRectangle(rect.x, rect.y, border_size, rect.h);
+
+       if (outline_border & MV_RIGHT)
+         RenderFillRectangle(rect.x + rect.w - border_size, rect.y,
+                             border_size, rect.h);
+
+       if (outline_border & MV_UP)
+         RenderFillRectangle(rect_x, rect.y, rect_w, border_size);
+
+       if (outline_border & MV_DOWN)
+         RenderFillRectangle(rect_x, rect.y + rect.h - border_size,
+                             rect_w, border_size);
+      }
+      else
+      {
+       SDL_RenderFillRect(sdl_renderer, &rect);
+      }
     }
   }
 
index 6ed27de2c5a01fe529940329553dd2751eda7dcb..3fcdf6c72177e386d8b720072824bf1d9b04ea26 100644 (file)
@@ -1024,6 +1024,7 @@ struct OverlayInfo
   int grid_ysize;
 
   char grid_button[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
+
   char grid_button_highlight;
 };
 
@@ -1060,6 +1061,7 @@ struct SetupTouchInfo
   char grid_button[2][MAX_GRID_XSIZE][MAX_GRID_YSIZE];
 
   int transparency;            /* in percent (0 == opaque, 100 == invisible) */
+  boolean draw_outlined;
 
   boolean grid_initialized;
 };
index 6f6e7a13dec6b5c2c28e709dbdd3e75e23c19d42..c44fb2b0cdf9f9250f95561c1b0d17dc76d8490d 100644 (file)
@@ -6026,8 +6026,9 @@ static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
   { TYPE_STRING,       &grid_size_text[0][0],  ""                      },
   { TYPE_ENTER_LIST,   execSetupChooseGridYSize_0, "Vertical Buttons (Landscape):"     },
   { TYPE_STRING,       &grid_size_text[0][1],  ""                      },
-  { TYPE_ENTER_LIST,   execSetupChooseTransparency, "Transparency:"    },
+  { TYPE_ENTER_LIST,   execSetupChooseTransparency, "Button Transparency:" },
   { TYPE_STRING,       &transparency_text,     ""                      },
+  { TYPE_SWITCH,       &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
   { TYPE_EMPTY,                NULL,                   ""                      },
   { TYPE_ENTER_LIST,   execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
   { TYPE_EMPTY,                NULL,                   ""                      },
@@ -6045,8 +6046,9 @@ static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
   { TYPE_STRING,       &grid_size_text[1][0],  ""                      },
   { TYPE_ENTER_LIST,   execSetupChooseGridYSize_1, "Vertical Buttons (Portrait):"      },
   { TYPE_STRING,       &grid_size_text[1][1],  ""                      },
-  { TYPE_ENTER_LIST,   execSetupChooseTransparency, "Transparency:"    },
+  { TYPE_ENTER_LIST,   execSetupChooseTransparency, "Button Transparency:" },
   { TYPE_STRING,       &transparency_text,     ""                      },
+  { TYPE_SWITCH,       &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
   { TYPE_EMPTY,                NULL,                   ""                      },
   { TYPE_ENTER_LIST,   execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
   { TYPE_EMPTY,                NULL,                   ""                      },