added option to draw pressed virtual buttons highlighted
authorHolger Schemel <info@artsoft.org>
Sat, 12 May 2018 10:18:51 +0000 (12:18 +0200)
committerHolger Schemel <info@artsoft.org>
Tue, 5 Jun 2018 18:58:43 +0000 (20:58 +0200)
src/events.c
src/files.c
src/libgame/sdl.c
src/libgame/system.c
src/libgame/system.h
src/screens.c

index 9aad2bca87dfa837891244e5099d004c97a7d629..dd3e88af8721f49039488aba261eb8bc3f51c9ea 100644 (file)
@@ -682,6 +682,7 @@ void HandleFingerEvent_VirtualButtons(FingerEvent *event)
   int x = event->x * overlay.grid_xsize;
   int y = event->y * overlay.grid_ysize;
   int grid_button = overlay.grid_button[x][y];
+  int grid_button_action = GET_ACTION_FROM_GRID_BUTTON(grid_button);
   Key key = (grid_button == CHAR_GRID_BUTTON_LEFT  ? setup.input[0].key.left :
             grid_button == CHAR_GRID_BUTTON_RIGHT ? setup.input[0].key.right :
             grid_button == CHAR_GRID_BUTTON_UP    ? setup.input[0].key.up :
@@ -725,6 +726,11 @@ void HandleFingerEvent_VirtualButtons(FingerEvent *event)
   Error(ERR_DEBUG, "::: key '%s' was '%s' [fingerId: %lld]",
        getKeyNameFromKey(key), key_status_name, event->fingerId);
 
+  if (key_status == KEY_PRESSED)
+    overlay.grid_button_action |= grid_button_action;
+  else
+    overlay.grid_button_action &= ~grid_button_action;
+
   // check if we already know this touch event's finger id
   for (i = 0; i < NUM_TOUCH_FINGERS; i++)
   {
index e59d36214e622edc7d0a71b4408643c5b5ddc874..ac75c2afc8151a97e03cd7428bb08ab5265c8b59 100644 (file)
@@ -8307,12 +8307,13 @@ void SaveScore(int nr)
 #define SETUP_TOKEN_TOUCH_DROP_DISTANCE                43
 #define SETUP_TOKEN_TOUCH_TRANSPARENCY         44
 #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 SETUP_TOKEN_TOUCH_DRAW_PRESSED         46
+#define SETUP_TOKEN_TOUCH_GRID_XSIZE_0         47
+#define SETUP_TOKEN_TOUCH_GRID_YSIZE_0         48
+#define SETUP_TOKEN_TOUCH_GRID_XSIZE_1         49
+#define SETUP_TOKEN_TOUCH_GRID_YSIZE_1         50
 
-#define NUM_GLOBAL_SETUP_TOKENS                        50
+#define NUM_GLOBAL_SETUP_TOKENS                        51
 
 /* auto setup */
 #define SETUP_TOKEN_AUTO_EDITOR_ZOOM_TILESIZE  0
@@ -8515,6 +8516,7 @@ static struct TokenInfo global_setup_tokens[] =
   { 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.draw_pressed,      "touch.draw_pressed"     },
   { 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" },
@@ -8734,6 +8736,7 @@ static void setSetupInfoToDefaults(struct SetupInfo *si)
   si->touch.drop_distance = TOUCH_DROP_DISTANCE_DEFAULT;       /* percent */
   si->touch.transparency = TOUCH_TRANSPARENCY_DEFAULT;         /* percent */
   si->touch.draw_outlined = TRUE;
+  si->touch.draw_pressed = TRUE;
 
   for (i = 0; i < 2; i++)
   {
index 8ac2fc3af6e298f3eb3ba20fb8155c4607d64205..47ad26237b32ab1186c6a059152f038c69655b96 100644 (file)
@@ -3060,10 +3060,12 @@ static void DrawTouchInputOverlay_ShowGridButtons(int alpha)
     for (y = 0; y < grid_ysize; y++)
     {
       int grid_button = overlay.grid_button[x][y];
+      int grid_button_action = GET_ACTION_FROM_GRID_BUTTON(grid_button);
       int alpha_draw = alpha;
       int outline_border = MV_NONE;
       int border_size = 2;
       boolean draw_outlined = setup.touch.draw_outlined;
+      boolean draw_pressed = setup.touch.draw_pressed;
 
       if (grid_button == CHAR_GRID_BUTTON_NONE)
        continue;
@@ -3071,6 +3073,14 @@ static void DrawTouchInputOverlay_ShowGridButtons(int alpha)
       if (grid_button == overlay.grid_button_highlight)
        alpha_draw = alpha_highlight;
 
+      if (draw_pressed && overlay.grid_button_action & grid_button_action)
+      {
+       if (draw_outlined)
+         draw_outlined = FALSE;
+       else
+         alpha_draw = MIN((float)alpha_draw * 1.5, SDL_ALPHA_OPAQUE);
+      }
+
       SDL_SetRenderDrawColor(sdl_renderer, 255, 255, 255, alpha_draw);
 
       rect.x = (x + 0) * video.screen_width  / grid_xsize;
index 3d499768e1a3a088d8559c2d89a4ba8b8e33a6ba..2d375e23e7f67dc4ce6598a84380511468020144 100644 (file)
@@ -341,6 +341,7 @@ void InitOverlayInfo()
       overlay.grid_button[x][y] = setup.touch.grid_button[nr][x][y];
 
   overlay.grid_button_highlight = CHAR_GRID_BUTTON_NONE;
+  overlay.grid_button_action = JOY_NO_ACTION;
 
 #if defined(USE_TOUCH_INPUT_OVERLAY)
   if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
index 3fcdf6c72177e386d8b720072824bf1d9b04ea26..47293837fe97f377e244d8008fed65b8bbb518bd 100644 (file)
 #define CHAR_GRID_BUTTON_SNAP          '1'
 #define CHAR_GRID_BUTTON_DROP          '2'
 
+#define GET_ACTION_FROM_GRID_BUTTON(c) ((c) == CHAR_GRID_BUTTON_LEFT ?  \
+                                        JOY_LEFT :                      \
+                                        (c) == CHAR_GRID_BUTTON_RIGHT ? \
+                                        JOY_RIGHT :                     \
+                                        (c) == CHAR_GRID_BUTTON_UP ?    \
+                                        JOY_UP :                        \
+                                        (c) == CHAR_GRID_BUTTON_DOWN ?  \
+                                        JOY_DOWN :                      \
+                                        (c) == CHAR_GRID_BUTTON_SNAP ?  \
+                                        JOY_BUTTON_1 :                  \
+                                        (c) == CHAR_GRID_BUTTON_DROP ?  \
+                                        JOY_BUTTON_2 :                  \
+                                        JOY_NO_ACTION)
+
 /* default name for empty highscore entry */
 #define EMPTY_PLAYER_NAME      "no name"
 
@@ -1024,8 +1038,9 @@ struct OverlayInfo
   int grid_ysize;
 
   char grid_button[MAX_GRID_XSIZE][MAX_GRID_YSIZE];
-
   char grid_button_highlight;
+
+  int grid_button_action;
 };
 
 struct JoystickInfo
@@ -1062,6 +1077,7 @@ struct SetupTouchInfo
 
   int transparency;            /* in percent (0 == opaque, 100 == invisible) */
   boolean draw_outlined;
+  boolean draw_pressed;
 
   boolean grid_initialized;
 };
index c44fb2b0cdf9f9250f95561c1b0d17dc76d8490d..9562c08cf5c58f9ae14eeb993615fe2442f693d3 100644 (file)
@@ -6029,6 +6029,7 @@ static struct TokenInfo setup_info_touch_virtual_buttons_0[] =
   { TYPE_ENTER_LIST,   execSetupChooseTransparency, "Button Transparency:" },
   { TYPE_STRING,       &transparency_text,     ""                      },
   { TYPE_SWITCH,       &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
+  { TYPE_SWITCH,       &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
   { TYPE_EMPTY,                NULL,                   ""                      },
   { TYPE_ENTER_LIST,   execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
   { TYPE_EMPTY,                NULL,                   ""                      },
@@ -6049,6 +6050,7 @@ static struct TokenInfo setup_info_touch_virtual_buttons_1[] =
   { TYPE_ENTER_LIST,   execSetupChooseTransparency, "Button Transparency:" },
   { TYPE_STRING,       &transparency_text,     ""                      },
   { TYPE_SWITCH,       &setup.touch.draw_outlined, "Draw Buttons Outlined:" },
+  { TYPE_SWITCH,       &setup.touch.draw_pressed, "Highlight Pressed Buttons:" },
   { TYPE_EMPTY,                NULL,                   ""                      },
   { TYPE_ENTER_LIST,   execSetupConfigureVirtualButtons, "Configure Virtual Buttons" },
   { TYPE_EMPTY,                NULL,                   ""                      },