added configurability of transparency for virtual buttons
authorHolger Schemel <info@artsoft.org>
Fri, 11 May 2018 15:18:32 +0000 (17:18 +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 3c1faa3342070d8dc9fc22435deeb3bd833a3b74..c7408331e2fe1c04b9783780336023a6c7e686b1 100644 (file)
@@ -8305,12 +8305,13 @@ void SaveScore(int nr)
 #define SETUP_TOKEN_TOUCH_CONTROL_TYPE         41
 #define SETUP_TOKEN_TOUCH_MOVE_DISTANCE                42
 #define SETUP_TOKEN_TOUCH_DROP_DISTANCE                43
-#define SETUP_TOKEN_TOUCH_GRID_XSIZE_0         44
-#define SETUP_TOKEN_TOUCH_GRID_YSIZE_0         45
-#define SETUP_TOKEN_TOUCH_GRID_XSIZE_1         46
-#define SETUP_TOKEN_TOUCH_GRID_YSIZE_1         47
+#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 NUM_GLOBAL_SETUP_TOKENS                        48
+#define NUM_GLOBAL_SETUP_TOKENS                        49
 
 /* auto setup */
 #define SETUP_TOKEN_AUTO_EDITOR_ZOOM_TILESIZE  0
@@ -8511,6 +8512,7 @@ static struct TokenInfo global_setup_tokens[] =
   { TYPE_STRING, &si.touch.control_type,      "touch.control_type"     },
   { 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.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" },
@@ -8728,6 +8730,7 @@ static void setSetupInfoToDefaults(struct SetupInfo *si)
   si->touch.control_type = getStringCopy(TOUCH_CONTROL_DEFAULT);
   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 */
 
   for (i = 0; i < 2; i++)
   {
index 0fd3aa62eb6a319d7523357ce0419e4b2d0f455f..df5b32425fe870d6c0d9547b19bafdc5b5e1bdcd 100644 (file)
@@ -3014,10 +3014,10 @@ static void DrawTouchInputOverlay_ShowGrid(int alpha)
 
 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;
@@ -3103,10 +3103,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)
index 4ef22022c95a4e2d1dde0325742dce733695c09b..88df586da83d553995800bd2767552197b33418e 100644 (file)
 
 #define TOUCH_MOVE_DISTANCE_DEFAULT    2
 #define TOUCH_DROP_DISTANCE_DEFAULT    5
+#define TOUCH_TRANSPARENCY_DEFAULT     50
 
+#define ALPHA_FROM_TRANSPARENCY(x)     ((100 - x) * SDL_ALPHA_OPAQUE / 100)
+#define ALPHA_FADING_STEPSIZE(x)       ((x) / 25)
 
 /* values for special settings for mobile devices */
 #if defined(PLATFORM_ANDROID)
@@ -1056,6 +1059,8 @@ struct SetupTouchInfo
 
   char grid_button[2][MAX_GRID_XSIZE][MAX_GRID_YSIZE];
 
+  int transparency;            /* in percent (0 == opaque, 100 == invisible) */
+
   boolean grid_initialized;
 };
 
index f49f895904f61fe99b3c89995f2769d31eb7548c..2dc2ad81bb100ad1c9c993dd3a7ab91c519df52d 100644 (file)
@@ -77,8 +77,9 @@
 #define SETUP_MODE_CHOOSE_TOUCH_CONTROL        28
 #define SETUP_MODE_CHOOSE_MOVE_DISTANCE        29
 #define SETUP_MODE_CHOOSE_DROP_DISTANCE        30
+#define SETUP_MODE_CHOOSE_TRANSPARENCY 31
 
-#define MAX_SETUP_MODES                        31
+#define MAX_SETUP_MODES                        32
 
 #define MAX_MENU_MODES                 MAX(MAX_INFO_MODES, MAX_SETUP_MODES)
 
 #define STR_SETUP_CHOOSE_TOUCH_CONTROL "Control Type"
 #define STR_SETUP_CHOOSE_MOVE_DISTANCE "Move Distance"
 #define STR_SETUP_CHOOSE_DROP_DISTANCE "Drop Distance"
+#define STR_SETUP_CHOOSE_TRANSPARENCY  "Transparency"
 
 /* for input setup functions */
 #define SETUPINPUT_SCREEN_POS_START    0
@@ -276,6 +278,9 @@ static TreeInfo *move_distance_current = NULL;
 static TreeInfo *drop_distances = NULL;
 static TreeInfo *drop_distance_current = NULL;
 
+static TreeInfo *transparencies = NULL;
+static TreeInfo *transparency_current = NULL;
+
 static TreeInfo *level_number = NULL;
 static TreeInfo *level_number_current = NULL;
 
@@ -452,6 +457,27 @@ static struct
   {    -1,     NULL                            },
 };
 
+static struct
+{
+  int value;
+  char *text;
+} transparencies_list[] =
+{
+  {    0,      "0 % (Opaque)"                  },
+  {    10,     "10 %"                          },
+  {    20,     "20 %"                          },
+  {    30,     "30 %"                          },
+  {    40,     "40 %"                          },
+  {    50,     "50 %"                          },
+  {    60,     "60 %"                          },
+  {    70,     "70 %"                          },
+  {    80,     "80 %"                          },
+  {    90,     "90 %"                          },
+  {    100,    "100 % (Invisible)"             },
+
+  {    -1,     NULL                            },
+};
+
 #define DRAW_MODE(s)           ((s) >= GAME_MODE_MAIN &&               \
                                 (s) <= GAME_MODE_SETUP ? (s) :         \
                                 (s) == GAME_MODE_PSEUDO_TYPENAME ?     \
@@ -4076,7 +4102,8 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
        execSetupSound();
       else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
               setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
-              setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
+              setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
+              setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
        execSetupTouch();
       else
        execSetupArtwork();
@@ -4228,7 +4255,8 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
            execSetupSound();
          else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
                   setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
-                  setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
+                  setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
+                  setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
            execSetupTouch();
          else
            execSetupArtwork();
@@ -4294,7 +4322,8 @@ static void HandleChooseTree(int mx, int my, int dx, int dy, int button,
            execSetupSound();
          else if (setup_mode == SETUP_MODE_CHOOSE_TOUCH_CONTROL ||
                   setup_mode == SETUP_MODE_CHOOSE_MOVE_DISTANCE ||
-                  setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
+                  setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE ||
+                  setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
            execSetupTouch();
          else
            execSetupArtwork();
@@ -4561,6 +4590,7 @@ static char *volume_music_text;
 static char *touch_controls_text;
 static char *move_distance_text;
 static char *drop_distance_text;
+static char *transparency_text;
 
 static void execSetupMain()
 {
@@ -5258,6 +5288,13 @@ static void execSetupChooseDropDistance()
   DrawSetupScreen();
 }
 
+static void execSetupChooseTransparency()
+{
+  setup_mode = SETUP_MODE_CHOOSE_TRANSPARENCY;
+
+  DrawSetupScreen();
+}
+
 static void execSetupConfigureVirtualButtons()
 {
   ConfigureVirtualButtons();
@@ -5395,14 +5432,60 @@ static void execSetupTouch()
       drop_distance_current = drop_distances;
   }
 
+  if (transparencies == NULL)
+  {
+    int i;
+
+    for (i = 0; transparencies_list[i].value != -1; i++)
+    {
+      TreeInfo *ti = newTreeInfo_setDefaults(TREE_TYPE_UNDEFINED);
+      char identifier[32], name[32];
+      int value = transparencies_list[i].value;
+      char *text = transparencies_list[i].text;
+
+      ti->node_top = &transparencies;
+      ti->sort_priority = value;
+
+      sprintf(identifier, "%d", value);
+      sprintf(name, "%s", text);
+
+      setString(&ti->identifier, identifier);
+      setString(&ti->name, name);
+      setString(&ti->name_sorting, name);
+      setString(&ti->infotext, STR_SETUP_CHOOSE_TRANSPARENCY);
+
+      pushTreeInfo(&transparencies, ti);
+    }
+
+    /* sort transparency values to start with lowest transparency value */
+    sortTreeInfo(&transparencies);
+
+    /* set current transparency value to configured transparency value */
+    transparency_current =
+      getTreeInfoFromIdentifier(transparencies,
+                               i_to_a(setup.touch.transparency));
+
+    /* if that fails, set current transparency to reliable default value */
+    if (transparency_current == NULL)
+      transparency_current =
+       getTreeInfoFromIdentifier(transparencies,
+                                 i_to_a(TOUCH_TRANSPARENCY_DEFAULT));
+
+    /* if that also fails, set current transparency to first available value */
+    if (transparency_current == NULL)
+      transparency_current = transparencies;
+  }
+
   setup.touch.control_type = touch_control_current->identifier;
   setup.touch.move_distance = atoi(move_distance_current->identifier);
   setup.touch.drop_distance = atoi(drop_distance_current->identifier);
+  setup.touch.transparency = atoi(transparency_current->identifier);
 
   /* needed for displaying volume text instead of identifier */
   touch_controls_text = touch_control_current->name;
   move_distance_text = move_distance_current->name;
   drop_distance_text = drop_distance_current->name;
+  transparency_text = transparency_current->name;
 
   setup_mode = SETUP_MODE_TOUCH;
 
@@ -5569,6 +5652,9 @@ static struct
   { &setup.touch.drop_distance,                execSetupChooseDropDistance     },
   { &setup.touch.drop_distance,                &drop_distance_text             },
 
+  { &setup.touch.transparency,         execSetupChooseTransparency     },
+  { &setup.touch.transparency,         &transparency_text              },
+
   { NULL,                              NULL                            }
 };
 
@@ -5756,6 +5842,9 @@ static struct TokenInfo setup_info_touch_virtual_buttons[] =
   { TYPE_ENTER_LIST,   execSetupChooseTouchControls, "Touch Control Type:" },
   { TYPE_STRING,       &touch_controls_text,   ""                      },
   { TYPE_EMPTY,                NULL,                   ""                      },
+  { TYPE_ENTER_LIST,   execSetupChooseTransparency, "Transparency:"    },
+  { TYPE_STRING,       &transparency_text,     ""                      },
+  { TYPE_EMPTY,                NULL,                   ""                      },
   { TYPE_ENTER_LIST,   execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
   { TYPE_EMPTY,                NULL,                   ""                      },
   { TYPE_LEAVE_MENU,   execSetupMain,          "Back"                  },
@@ -7467,6 +7556,8 @@ void DrawSetupScreen()
     DrawChooseTree(&move_distance_current);
   else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
     DrawChooseTree(&drop_distance_current);
+  else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
+    DrawChooseTree(&transparency_current);
   else
     DrawSetupScreen_Generic();
 
@@ -7519,6 +7610,8 @@ void HandleSetupScreen(int mx, int my, int dx, int dy, int button)
     HandleChooseTree(mx, my, dx, dy, button, &move_distance_current);
   else if (setup_mode == SETUP_MODE_CHOOSE_DROP_DISTANCE)
     HandleChooseTree(mx, my, dx, dy, button, &drop_distance_current);
+  else if (setup_mode == SETUP_MODE_CHOOSE_TRANSPARENCY)
+    HandleChooseTree(mx, my, dx, dy, button, &transparency_current);
   else
     HandleSetupScreen_Generic(mx, my, dx, dy, button);
 }