From c27ee24cc40fb4a750b53edc46902c974b102103 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 14 Jan 2024 21:55:09 +0100 Subject: [PATCH] (Android) Added fade-out support to the touch overlay --- es-app/src/guis/GuiMenu.cpp | 38 ++++++++++++++++++++++++++++++++++--- es-app/src/main.cpp | 2 +- es-core/src/Settings.cpp | 1 + es-core/src/Window.cpp | 5 +++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/es-app/src/guis/GuiMenu.cpp b/es-app/src/guis/GuiMenu.cpp index a0336081c..9af463c48 100644 --- a/es-app/src/guis/GuiMenu.cpp +++ b/es-app/src/guis/GuiMenu.cpp @@ -1171,6 +1171,21 @@ void GuiMenu::openInputDeviceOptions() } }); + // Touch overlay fade-out timer. + auto touchOverlayFadeTime = std::make_shared(0.0f, 20.0f, 1.0f, "s"); + touchOverlayFadeTime->setValue( + static_cast(Settings::getInstance()->getInt("InputTouchOverlayFadeTime"))); + s->addWithLabel("TOUCH OVERLAY FADE-OUT TIME", touchOverlayFadeTime); + s->addSaveFunc([touchOverlayFadeTime, s] { + if (touchOverlayFadeTime->getValue() != + static_cast(Settings::getInstance()->getInt("InputTouchOverlayFadeTime"))) { + Settings::getInstance()->setInt("InputTouchOverlayFadeTime", + static_cast(touchOverlayFadeTime->getValue())); + InputOverlay::getInstance().resetFadeTimer(); + s->setNeedsSaving(); + } + }); + // Whether to enable the touch overlay. auto inputTouchOverlay = std::make_shared(); inputTouchOverlay->setState(Settings::getInstance()->getBool("InputTouchOverlay")); @@ -1179,12 +1194,10 @@ void GuiMenu::openInputDeviceOptions() if (Settings::getInstance()->getBool("InputTouchOverlay") != inputTouchOverlay->getState()) { Settings::getInstance()->setBool("InputTouchOverlay", inputTouchOverlay->getState()); - if (Settings::getInstance()->getBool("InputTouchOverlay")) InputOverlay::getInstance().createButtons(); else InputOverlay::getInstance().clearButtons(); - s->setNeedsSaving(); } }); @@ -1195,9 +1208,16 @@ void GuiMenu::openInputDeviceOptions() touchOverlaySize->getParent() ->getChild(touchOverlaySize->getChildIndex() - 1) ->setOpacity(DISABLED_OPACITY); + + touchOverlayFadeTime->setEnabled(false); + touchOverlayFadeTime->setOpacity(DISABLED_OPACITY); + touchOverlayFadeTime->getParent() + ->getChild(touchOverlayFadeTime->getChildIndex() - 1) + ->setOpacity(DISABLED_OPACITY); } - auto inputTouchOverlayCallback = [this, inputTouchOverlay, touchOverlaySize]() { + auto inputTouchOverlayCallback = [this, inputTouchOverlay, touchOverlaySize, + touchOverlayFadeTime]() { if (!inputTouchOverlay->getState()) { const std::string message { "DON'T DISABLE THE TOUCH OVERLAY UNLESS YOU ARE USING A CONTROLLER OR YOU WILL " @@ -1221,6 +1241,12 @@ void GuiMenu::openInputDeviceOptions() touchOverlaySize->getParent() ->getChild(touchOverlaySize->getChildIndex() - 1) ->setOpacity(DISABLED_OPACITY); + + touchOverlayFadeTime->setEnabled(false); + touchOverlayFadeTime->setOpacity(DISABLED_OPACITY); + touchOverlayFadeTime->getParent() + ->getChild(touchOverlayFadeTime->getChildIndex() - 1) + ->setOpacity(DISABLED_OPACITY); } else { touchOverlaySize->setEnabled(true); @@ -1228,6 +1254,12 @@ void GuiMenu::openInputDeviceOptions() touchOverlaySize->getParent() ->getChild(touchOverlaySize->getChildIndex() - 1) ->setOpacity(1.0f); + + touchOverlayFadeTime->setEnabled(true); + touchOverlayFadeTime->setOpacity(1.0f); + touchOverlayFadeTime->getParent() + ->getChild(touchOverlayFadeTime->getChildIndex() - 1) + ->setOpacity(1.0f); } }; diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index afd77b086..eb43bdcd0 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -896,7 +896,7 @@ int main(int argc, char* argv[]) } #if defined(__ANDROID__) - InputOverlay::getInstance(); + InputOverlay::getInstance().init(); LOG(LogDebug) << "Android API level: " << SDL_GetAndroidSDKVersion(); Utils::Platform::Android::printDeviceInfo(); diff --git a/es-core/src/Settings.cpp b/es-core/src/Settings.cpp index 761c4ceaa..02f3f11e1 100644 --- a/es-core/src/Settings.cpp +++ b/es-core/src/Settings.cpp @@ -241,6 +241,7 @@ void Settings::setDefaults() mStringMap["InputControllerType"] = {"xbox", "xbox"}; #if defined(__ANDROID__) mStringMap["InputTouchOverlaySize"] = {"medium", "medium"}; + mIntMap["InputTouchOverlayFadeTime"] = {6, 6}; mBoolMap["InputTouchOverlay"] = {true, true}; #endif mBoolMap["InputOnlyFirstController"] = {false, false}; diff --git a/es-core/src/Window.cpp b/es-core/src/Window.cpp index 5c5a7eb0c..a74b2d591 100644 --- a/es-core/src/Window.cpp +++ b/es-core/src/Window.cpp @@ -447,6 +447,11 @@ void Window::update(int deltaTime) if (mScreensaver && mRenderScreensaver) mScreensaver->update(deltaTime); + +#if defined(__ANDROID__) + if (Settings::getInstance()->getBool("InputTouchOverlay")) + InputOverlay::getInstance().update(deltaTime); +#endif } bool Window::isBackgroundDimmed()