From 457abe4e8de9b10096af75c026409ab068570b7f Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sat, 12 May 2018 12:18:51 +0200 Subject: [PATCH] added option to draw pressed virtual buttons highlighted --- src/events.c | 6 ++++++ src/files.c | 13 ++++++++----- src/libgame/sdl.c | 10 ++++++++++ src/libgame/system.c | 1 + src/libgame/system.h | 18 +++++++++++++++++- src/screens.c | 2 ++ 6 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/events.c b/src/events.c index 9aad2bca..dd3e88af 100644 --- a/src/events.c +++ b/src/events.c @@ -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++) { diff --git a/src/files.c b/src/files.c index e59d3621..ac75c2af 100644 --- a/src/files.c +++ b/src/files.c @@ -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++) { diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 8ac2fc3a..47ad2623 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -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; diff --git a/src/libgame/system.c b/src/libgame/system.c index 3d499768..2d375e23 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -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)) diff --git a/src/libgame/system.h b/src/libgame/system.h index 3fcdf6c7..47293837 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -493,6 +493,20 @@ #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; }; diff --git a/src/screens.c b/src/screens.c index c44fb2b0..9562c08c 100644 --- a/src/screens.c +++ b/src/screens.c @@ -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, "" }, -- 2.34.1