added option to draw virtual buttons outlined
[rocksndiamonds.git] / src / libgame / sdl.c
index 877bb16eb3bdd35d0dff071a389a1cdbb95b2746..8ac2fc3af6e298f3eb3ba20fb8155c4607d64205 100644 (file)
@@ -3012,12 +3012,19 @@ 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_max = SDL_ALPHA_OPAQUE / 2;
-  static int alpha_step = 5;
   static int alpha_direction = 0;
   static int alpha_highlight = 0;
+  int alpha_max = ALPHA_FROM_TRANSPARENCY(setup.touch.transparency);
+  int alpha_step = ALPHA_FADING_STEPSIZE(alpha_max);
   SDL_Rect rect;
   int grid_xsize = overlay.grid_xsize;
   int grid_ysize = overlay.grid_ysize;
@@ -3050,21 +3057,83 @@ static void DrawTouchInputOverlay_ShowGridButtons(int alpha)
 
   for (x = 0; x < grid_xsize; x++)
   {
-    rect.x = (x + 0) * video.screen_width / grid_xsize;
-    rect.w = (x + 1) * video.screen_width / grid_xsize - rect.x;
-
     for (y = 0; y < grid_ysize; y++)
     {
+      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;
+
+      if (grid_button == overlay.grid_button_highlight)
+       alpha_draw = alpha_highlight;
+
+      SDL_SetRenderDrawColor(sdl_renderer, 255, 255, 255, alpha_draw);
+
+      rect.x = (x + 0) * video.screen_width  / grid_xsize;
       rect.y = (y + 0) * video.screen_height / grid_ysize;
+      rect.w = (x + 1) * video.screen_width  / grid_xsize - rect.x;
       rect.h = (y + 1) * video.screen_height / grid_ysize - rect.y;
 
-      if (overlay.grid_button[x][y] == overlay.grid_button_highlight)
-       SDL_SetRenderDrawColor(sdl_renderer, 255, 255, 255, alpha_highlight);
-      else
-       SDL_SetRenderDrawColor(sdl_renderer, 255, 255, 255, alpha);
+      if (x == 0 || overlay.grid_button[x - 1][y] != grid_button)
+      {
+       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 -= border_size;
+
+       outline_border |= MV_RIGHT;
+      }
+
+      if (y == 0 || overlay.grid_button[x][y - 1] != grid_button)
+      {
+       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 -= border_size;
+
+       outline_border |= MV_DOWN;
+      }
 
-      if (overlay.grid_button[x][y] != CHAR_GRID_BUTTON_NONE)
+      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);
+      }
     }
   }
 
@@ -3078,10 +3147,10 @@ static void DrawTouchInputOverlay()
   static boolean deactivated = TRUE;
   static boolean show_grid = FALSE;
   static int width = 0, height = 0;
-  static int alpha_max = SDL_ALPHA_OPAQUE / 2;
-  static int alpha_step = 5;
   static int alpha_last = -1;
   static int alpha = 0;
+  int alpha_max = ALPHA_FROM_TRANSPARENCY(setup.touch.transparency);
+  int alpha_step = ALPHA_FADING_STEPSIZE(alpha_max);
   boolean active = (overlay.enabled && overlay.active);
 
   if (!active && deactivated)