From: Holger Schemel Date: Sun, 16 Jul 2017 11:50:27 +0000 (+0200) Subject: added enabling/disabling virtual button overlay depending on input events X-Git-Tag: 4.0.1.0~26 X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=commitdiff_plain;h=6746a99c1d7348748c06d457f8496b4253bb7c84 added enabling/disabling virtual button overlay depending on input events --- diff --git a/src/events.c b/src/events.c index 2472fdf5..64fda808 100644 --- a/src/events.c +++ b/src/events.c @@ -250,7 +250,11 @@ void HandleOtherEvents(Event *event) #if defined(TARGET_SDL2) case SDL_CONTROLLERBUTTONDOWN: case SDL_CONTROLLERBUTTONUP: + // for any game controller button event, disable overlay buttons + SetOverlayEnabled(FALSE); + HandleSpecialGameControllerButtons(event); + /* FALL THROUGH */ case SDL_CONTROLLERDEVICEADDED: case SDL_CONTROLLERDEVICEREMOVED: @@ -668,6 +672,9 @@ void HandleFingerEvent(FingerEvent *event) "KEY_PRESSED"); int i; + // for any touch input event, enable overlay buttons (if activated) + SetOverlayEnabled(TRUE); + Error(ERR_DEBUG, "::: key '%s' was '%s' [fingerId: %lld]", getKeyNameFromKey(key), key_status_name, event->fingerId); @@ -1148,9 +1155,16 @@ void HandleKeyEvent(KeyEvent *event) #endif #if defined(PLATFORM_ANDROID) - // always map the "back" button to the "escape" key on Android devices if (key == KSYM_Back) + { + // always map the "back" button to the "escape" key on Android devices key = KSYM_Escape; + } + else + { + // for any key event other than "back" button, disable overlay buttons + SetOverlayEnabled(FALSE); + } #endif HandleKeyModState(keymod, key_status); diff --git a/src/libgame/sdl.c b/src/libgame/sdl.c index 04fa05e8..8751f1b9 100644 --- a/src/libgame/sdl.c +++ b/src/libgame/sdl.c @@ -2966,11 +2966,12 @@ static void DrawTouchInputOverlay() static int alpha_step = 5; static int alpha_last = 0; static int alpha = 0; + boolean active = (overlay.enabled && overlay.active); - if (!overlay.active && deactivated) + if (!active && deactivated) return; - if (overlay.active) + if (active) { if (alpha < alpha_max) alpha = MIN(alpha + alpha_step, alpha_max); diff --git a/src/libgame/system.c b/src/libgame/system.c index 5ccf3fb3..2b283c1a 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -300,7 +300,18 @@ void InitGfxOtherSettings() void InitOverlayInfo() { + overlay.enabled = FALSE; overlay.active = FALSE; + +#if defined(PLATFORM_ANDROID) + if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS)) + overlay.enabled = TRUE; +#endif +} + +void SetOverlayEnabled(boolean enabled) +{ + overlay.enabled = enabled; } void SetOverlayActive(boolean active) diff --git a/src/libgame/system.h b/src/libgame/system.h index ca25b287..1b1dc2a4 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -941,7 +941,8 @@ struct GfxInfo struct OverlayInfo { - boolean active; + boolean enabled; /* overlay generally enabled or disabled */ + boolean active; /* overlay activated (depending on game mode) */ }; struct JoystickInfo @@ -1469,6 +1470,7 @@ void InitGfxDrawGlobalBorderFunction(void (*draw_global_border_function)(int)); void InitGfxCustomArtworkInfo(); void InitGfxOtherSettings(); void InitOverlayInfo(); +void SetOverlayEnabled(boolean); void SetOverlayActive(boolean); boolean GetOverlayActive(); void SetDrawDeactivationMask(int);