diff --git a/es-app/src/SystemScreenSaver.cpp b/es-app/src/SystemScreenSaver.cpp index 39ab7b930..6084a81e1 100644 --- a/es-app/src/SystemScreenSaver.cpp +++ b/es-app/src/SystemScreenSaver.cpp @@ -1,4 +1,6 @@ +// SPDX-License-Identifier: MIT // +// EmulationStation Desktop Edition // SystemScreenSaver.cpp // // Screensaver, supporting the following modes: @@ -86,9 +88,8 @@ void SystemScreenSaver::startScreenSaver() if (!mVideoScreensaver && (screensaver_behavior == "video")) { // Configure to fade out the windows, skip fading if mode is set to Instant. - mState = PowerSaver::getMode() == PowerSaver::INSTANT - ? STATE_SCREENSAVER_ACTIVE - : STATE_FADE_OUT_WINDOW; + mState = PowerSaver::getMode() == + PowerSaver::INSTANT ? STATE_SCREENSAVER_ACTIVE : STATE_FADE_OUT_WINDOW; mVideoChangeTime = Settings::getInstance()->getInt("ScreenSaverSwapVideoTimeout"); mOpacity = 0.0f; @@ -120,11 +121,11 @@ void SystemScreenSaver::startScreenSaver() Renderer::getScreenHeight() / 2.0f); if (Settings::getInstance()->getBool("ScreenSaverStretchVideos")) - mVideoScreensaver->setResize((float)Renderer::getScreenWidth(), - (float)Renderer::getScreenHeight()); + mVideoScreensaver->setResize(static_cast(Renderer::getScreenWidth()), + static_cast(Renderer::getScreenHeight())); else - mVideoScreensaver->setMaxSize((float)Renderer::getScreenWidth(), - (float)Renderer::getScreenHeight()); + mVideoScreensaver->setMaxSize(static_cast(Renderer::getScreenWidth()), + static_cast(Renderer::getScreenHeight())); mVideoScreensaver->setVideo(path); mVideoScreensaver->setScreensaverMode(true); @@ -136,9 +137,8 @@ void SystemScreenSaver::startScreenSaver() } else if (screensaver_behavior == "slideshow") { // Configure to fade out the windows, skip fading if mode is set to Instant. - mState = PowerSaver::getMode() == PowerSaver::INSTANT - ? STATE_SCREENSAVER_ACTIVE - : STATE_FADE_OUT_WINDOW; + mState = PowerSaver::getMode() == + PowerSaver::INSTANT ? STATE_SCREENSAVER_ACTIVE : STATE_FADE_OUT_WINDOW; mVideoChangeTime = Settings::getInstance()->getInt("ScreenSaverSwapImageTimeout"); mOpacity = 0.0f; @@ -164,11 +164,11 @@ void SystemScreenSaver::startScreenSaver() Renderer::getScreenHeight() / 2.0f); if (Settings::getInstance()->getBool("ScreenSaverStretchImages")) - mImageScreensaver->setResize((float)Renderer::getScreenWidth(), - (float)Renderer::getScreenHeight()); + mImageScreensaver->setResize(static_cast(Renderer::getScreenWidth()), + static_cast(Renderer::getScreenHeight())); else - mImageScreensaver->setMaxSize((float)Renderer::getScreenWidth(), - (float)Renderer::getScreenHeight()); + mImageScreensaver->setMaxSize(static_cast(Renderer::getScreenWidth()), + static_cast(Renderer::getScreenHeight())); std::string bg_audio_file = Settings::getInstance()-> getString("SlideshowScreenSaverBackgroundAudioFile"); @@ -222,7 +222,7 @@ void SystemScreenSaver::renderScreenSaver() Renderer::getScreenHeight(), 0x000000FF, 0x000000FF); // Only render the video if the state requires it. - if ((int)mState >= STATE_FADE_IN_VIDEO) { + if (static_cast(mState) >= STATE_FADE_IN_VIDEO) { Transform4x4f transform = Transform4x4f::Identity(); mVideoScreensaver->render(transform); } @@ -236,7 +236,7 @@ void SystemScreenSaver::renderScreenSaver() // Only render the video if the state requires it. if ((int)mState >= STATE_FADE_IN_VIDEO) { if (mImageScreensaver->hasImage()) { - mImageScreensaver->setOpacity(255- (unsigned char) (mOpacity * 255)); + mImageScreensaver->setOpacity(255 - static_cast(mOpacity * 255)); Transform4x4f transform = Transform4x4f::Identity(); mImageScreensaver->render(transform); @@ -357,7 +357,8 @@ void SystemScreenSaver::pickRandomVideo(std::string& path) // not shown again. if (mVideoCount > 0) { do { - int video = (int)(((float)rand() / float(RAND_MAX)) * (float)mVideoCount); + int video = static_cast((static_cast(rand()) / + static_cast(RAND_MAX)) * static_cast(mVideoCount)); pickGameListNode(video, "video", path); } while (mPreviousGame && mCurrentGame == mPreviousGame); @@ -376,7 +377,8 @@ void SystemScreenSaver::pickRandomGameListImage(std::string& path) // not shown again. if (mImageCount > 0) { do { - int image = (int)(((float)rand() / float(RAND_MAX)) * (float)mImageCount); + int image = static_cast((static_cast(rand()) / + static_cast(RAND_MAX)) * static_cast(mImageCount)); pickGameListNode(image, "image", path); } while (mPreviousGame && mCurrentGame == mPreviousGame); @@ -405,7 +407,7 @@ void SystemScreenSaver::pickRandomCustomImage(std::string& path) } } - int fileCount = (int)matchingFiles.size(); + int fileCount = static_cast(matchingFiles.size()); if (fileCount > 0) { // Get a random index in the range 0 to fileCount (exclusive). int randomIndex = rand() % fileCount; @@ -425,7 +427,7 @@ void SystemScreenSaver::update(int deltaTime) { // Use this to update the fade value for the current fade stage. if (mState == STATE_FADE_OUT_WINDOW) { - mOpacity += (float)deltaTime / FADE_TIME; + mOpacity += static_cast(deltaTime) / FADE_TIME; if (mOpacity >= 1.0f) { mOpacity = 1.0f; @@ -434,7 +436,7 @@ void SystemScreenSaver::update(int deltaTime) } } else if (mState == STATE_FADE_IN_VIDEO) { - mOpacity -= (float)deltaTime / FADE_TIME; + mOpacity -= static_cast(deltaTime) / FADE_TIME; if (mOpacity <= 0.0f) { mOpacity = 0.0f; // Update to the next state. @@ -475,7 +477,7 @@ void SystemScreenSaver::launchGame() IGameListView* view = ViewController::get()-> getGameListView(mCurrentGame->getSystem()).get(); view->setCursor(mCurrentGame); - if (Settings::getInstance()->getBool("ScreenSaverControls")) - view->launch(mCurrentGame); + ViewController::get()->resetMovingCamera(); + ViewController::get()->launch(mCurrentGame); } } diff --git a/es-app/src/SystemScreenSaver.h b/es-app/src/SystemScreenSaver.h index 1392642c4..f765bf242 100644 --- a/es-app/src/SystemScreenSaver.h +++ b/es-app/src/SystemScreenSaver.h @@ -1,11 +1,12 @@ +// SPDX-License-Identifier: MIT // +// EmulationStation Desktop Edition // SystemScreenSaver.h // // Screensaver, supporting the following modes: // Dim, black, slideshow, video. // -#pragma once #ifndef ES_APP_SYSTEM_SCREEN_SAVER_H #define ES_APP_SYSTEM_SCREEN_SAVER_H diff --git a/es-app/src/views/SystemView.cpp b/es-app/src/views/SystemView.cpp index ac1a148ad..8f26ae9fd 100644 --- a/es-app/src/views/SystemView.cpp +++ b/es-app/src/views/SystemView.cpp @@ -37,7 +37,8 @@ SystemView::SystemView( mExtrasCamOffset = 0; mExtrasFadeOpacity = 0.0f; - setSize((float)Renderer::getScreenWidth(), (float)Renderer::getScreenHeight()); + setSize(static_cast(Renderer::getScreenWidth()), + static_cast(Renderer::getScreenHeight())); populate(); } @@ -218,13 +219,7 @@ bool SystemView::input(InputConfig* config, Input input) setCursor(SystemData::getRandomSystem(getSelected())); return true; } - } - else { - if (config->isMappedLike("left", input) || - config->isMappedLike("right", input) || - config->isMappedLike("up", input) || - config->isMappedLike("down", input)) - listInput(0); + if (!UIModeController::getInstance()->isUIModeKid() && config->isMappedTo("select", input) && Settings::getInstance()->getBool("ScreenSaverControls")) { @@ -232,12 +227,16 @@ bool SystemView::input(InputConfig* config, Input input) mWindow->startScreenSaver(); mWindow->renderScreenSaver(); } - else { - mWindow->cancelScreenSaver(); - } return true; } } + else { + if (config->isMappedLike("left", input) || + config->isMappedLike("right", input) || + config->isMappedLike("up", input) || + config->isMappedLike("down", input)) + listInput(0); + } return GuiComponent::input(config, input); } @@ -255,8 +254,8 @@ void SystemView::onCursorChanged(const CursorState& /*state*/) float startPos = mCamOffset; - float posMax = (float)mEntries.size(); - float target = (float)mCursor; + float posMax = static_cast(mEntries.size()); + float target = static_cast(mCursor); // What's the shortest way to get to our target? // It's one of these... @@ -280,8 +279,9 @@ void SystemView::onCursorChanged(const CursorState& /*state*/) Animation* infoFadeOut = new LambdaAnimation( [infoStartOpacity, this] (float t) { - mSystemInfo.setOpacity((unsigned char)(Math::lerp(infoStartOpacity, 0.f, t) * 255)); - }, (int)(infoStartOpacity * (goFast ? 10 : 150))); + mSystemInfo.setOpacity(static_cast( + Math::lerp(infoStartOpacity, 0.f, t) * 255)); + }, static_cast(infoStartOpacity * (goFast ? 10 : 150))); unsigned int gameCount = getSelected()->getDisplayedGameCount(); @@ -299,7 +299,7 @@ void SystemView::onCursorChanged(const CursorState& /*state*/) Animation* infoFadeIn = new LambdaAnimation( [this](float t) { - mSystemInfo.setOpacity((unsigned char)(Math::lerp(0.f, 1.f, t) * 255)); + mSystemInfo.setOpacity(static_cast(Math::lerp(0.f, 1.f, t) * 255)); }, goFast ? 10 : 300); // Wait 150ms to fade in. @@ -467,8 +467,8 @@ void SystemView::renderCarousel(const Transform4x4f& trans) mCarousel.origin.y() * mCarousel.size.y() * -1, 0.0f)); Vector2f clipPos(carouselTrans.translation().x(), carouselTrans.translation().y()); - Renderer::pushClipRect(Vector2i((int)clipPos.x(), (int)clipPos.y()), - Vector2i((int)mCarousel.size.x(), (int)mCarousel.size.y())); + Renderer::pushClipRect(Vector2i(static_cast(clipPos.x()), static_cast(clipPos.y())), + Vector2i(static_cast(mCarousel.size.x()), static_cast(mCarousel.size.y()))); Renderer::setMatrix(carouselTrans); Renderer::drawRect(0.0f, 0.0f, mCarousel.size.x(), mCarousel.size.y(), @@ -530,8 +530,8 @@ void SystemView::renderCarousel(const Transform4x4f& trans) break; } - int center = (int)(mCamOffset); - int logoCount = Math::min(mCarousel.maxLogoCount, (int)mEntries.size()); + int center = static_cast(mCamOffset); + int logoCount = Math::min(mCarousel.maxLogoCount, static_cast(mEntries.size())); // Adding texture loading buffers depending on scrolling speed and status. int bufferIndex = getScrollingVelocity() + 1; @@ -546,9 +546,9 @@ void SystemView::renderCarousel(const Transform4x4f& trans) i <= center + logoCount / 2 + bufferRight; i++) { int index = i; while (index < 0) - index += (int)mEntries.size(); - while (index >= (int)mEntries.size()) - index -= (int)mEntries.size(); + index += static_cast(mEntries.size()); + while (index >= static_cast(mEntries.size())) + index -= static_cast(mEntries.size()); Transform4x4f logoTrans = carouselTrans; logoTrans.translate(Vector3f(i * logoSpacing[0] + xOff, i * logoSpacing[1] + yOff, 0)); @@ -559,8 +559,9 @@ void SystemView::renderCarousel(const Transform4x4f& trans) scale = Math::min(mCarousel.logoScale, Math::max(1.0f, scale)); scale /= mCarousel.logoScale; - int opacity = (int)Math::round(0x80 + ((0xFF - 0x80) * (1.0f - fabs(distance)))); - opacity = Math::max((int) 0x80, opacity); + int opacity = static_cast(Math::round(0x80 + ((0xFF - 0x80) * + (1.0f - fabs(distance))))); + opacity = Math::max(static_cast(0x80), opacity); const std::shared_ptr &comp = mEntries.at(index).data.logo; if (mCarousel.type == VERTICAL_WHEEL || mCarousel.type == HORIZONTAL_WHEEL) { @@ -568,7 +569,7 @@ void SystemView::renderCarousel(const Transform4x4f& trans) comp->setRotationOrigin(mCarousel.logoRotationOrigin); } comp->setScale(scale); - comp->setOpacity((unsigned char)opacity); + comp->setOpacity(static_cast(opacity)); comp->render(logoTrans); } Renderer::popClipRect(); @@ -583,20 +584,21 @@ void SystemView::renderInfoBar(const Transform4x4f& trans) // Draw background extras. void SystemView::renderExtras(const Transform4x4f& trans, float lower, float upper) { - int extrasCenter = (int)mExtrasCamOffset; + int extrasCenter = static_cast(mExtrasCamOffset); // Adding texture loading buffers depending on scrolling speed and status. int bufferIndex = getScrollingVelocity() + 1; - Renderer::pushClipRect(Vector2i::Zero(), Vector2i((int)mSize.x(), (int)mSize.y())); + Renderer::pushClipRect(Vector2i::Zero(), Vector2i(static_cast(mSize.x()), + static_cast(mSize.y()))); for (int i = extrasCenter + logoBuffersLeft[bufferIndex]; i <= extrasCenter + logoBuffersRight[bufferIndex]; i++) { int index = i; while (index < 0) - index += (int)mEntries.size(); - while (index >= (int)mEntries.size()) - index -= (int)mEntries.size(); + index += static_cast(mEntries.size()); + while (index >= static_cast(mEntries.size())) + index -= static_cast(mEntries.size()); // Only render selected system when not showing. if (mShowing || index == mCursor) @@ -607,9 +609,9 @@ void SystemView::renderExtras(const Transform4x4f& trans, float lower, float upp else extrasTrans.translate(Vector3f(0, (i - mExtrasCamOffset) * mSize.y(), 0)); - Renderer::pushClipRect(Vector2i((int)extrasTrans.translation()[0], - (int)extrasTrans.translation()[1]), - Vector2i((int)mSize.x(), (int)mSize.y())); + Renderer::pushClipRect(Vector2i(static_cast(extrasTrans.translation()[0]), + static_cast(extrasTrans.translation()[1])), + Vector2i(static_cast(mSize.x()), static_cast(mSize.y()))); SystemViewData data = mEntries.at(index).data; for (unsigned int j = 0; j < data.backgroundExtras.size(); j++) { GuiComponent *extra = data.backgroundExtras[j]; @@ -627,7 +629,7 @@ void SystemView::renderFade(const Transform4x4f& trans) { // Fade extras if necessary. if (mExtrasFadeOpacity) { - unsigned int fadeColor = 0x00000000 | (unsigned char)(mExtrasFadeOpacity * 255); + unsigned int fadeColor = 0x00000000 | static_cast(mExtrasFadeOpacity * 255); Renderer::setMatrix(trans); Renderer::drawRect(0.0f, 0.0f, mSize.x(), mSize.y(), fadeColor, fadeColor); } @@ -662,7 +664,7 @@ void SystemView::getDefaultElements(void) mSystemInfo.setPosition(0, (mCarousel.pos.y() + mCarousel.size.y() - 0.2f)); mSystemInfo.setBackgroundColor(0xDDDDDDD8); mSystemInfo.setRenderBackground(true); - mSystemInfo.setFont(Font::get((int)(0.035f * mSize.y()), Font::getDefaultPath())); + mSystemInfo.setFont(Font::get(static_cast(0.035f * mSize.y()), Font::getDefaultPath())); mSystemInfo.setColor(0x000000FF); mSystemInfo.setZIndex(50); mSystemInfo.setDefaultZIndex(50); @@ -699,7 +701,7 @@ void SystemView::getCarouselFromTheme(const ThemeData::ThemeElement* elem) if (elem->has("logoSize")) mCarousel.logoSize = elem->get("logoSize") * mSize; if (elem->has("maxLogoCount")) - mCarousel.maxLogoCount = (int)Math::round(elem->get("maxLogoCount")); + mCarousel.maxLogoCount = static_cast(Math::round(elem->get("maxLogoCount"))); if (elem->has("zIndex")) mCarousel.zIndex = elem->get("zIndex"); if (elem->has("logoRotation")) diff --git a/es-app/src/views/ViewController.cpp b/es-app/src/views/ViewController.cpp index 804dc972c..ac9adf12f 100644 --- a/es-app/src/views/ViewController.cpp +++ b/es-app/src/views/ViewController.cpp @@ -191,7 +191,7 @@ void ViewController::goToPrevGameList() void ViewController::goToGameList(SystemData* system) { // Stop any scrolling, animations and camera movements. - if (mSystemListView) { + if (mState.viewing == SYSTEM_SELECT) { mSystemListView->stopScrolling(); if (mSystemListView->isAnimationPlaying(0)) mSystemListView->finishAnimation(0); @@ -201,9 +201,8 @@ void ViewController::goToGameList(SystemData* system) // Disable rendering of the system view. if (getSystemListView()->getRenderView()) getSystemListView()->setRenderView(false); - // If switching between gamelists, disable rendering of the current view. - if (mCurrentView) + else if (mCurrentView) mCurrentView->setRenderView(false); if (mState.viewing == SYSTEM_SELECT) { @@ -329,8 +328,6 @@ void ViewController::launch(FileData* game, Vector3f center) while (NavigationSounds::getInstance()->isPlayingThemeNavigationSound(LAUNCHSOUND)); game->launchGame(mWindow); onFileChanged(game, FILE_METADATA_CHANGED); - if (mCurrentView) - mCurrentView->onShow(); // This is a workaround so that any key or button presses used for exiting the emulator // are not captured upon returning to ES. setAnimation(new LambdaAnimation([](float t){}, 1), 0, [this] { diff --git a/es-core/src/Window.cpp b/es-core/src/Window.cpp index 7e560ed53..3cbee9b2f 100644 --- a/es-core/src/Window.cpp +++ b/es-core/src/Window.cpp @@ -136,6 +136,8 @@ void Window::textInput(const char* text) void Window::input(InputConfig* config, Input input) { + mTimeSinceLastInput = 0; + if (Settings::getInstance()->getBool("Debug")) logInput(config, input); @@ -168,17 +170,17 @@ void Window::input(InputConfig* config, Input input) if (mSleeping) { // Wake up. - mTimeSinceLastInput = 0; cancelScreenSaver(); mSleeping = false; onWake(); return; } - mTimeSinceLastInput = 0; - if (!config->isMappedTo("select", input)) - if (cancelScreenSaver()) - return; + // Any keypress cancels the screensaver. + if (input.value != 0 && isScreenSaverActive()) { + cancelScreenSaver(); + return; + } if (config->getDeviceId() == DEVICE_KEYBOARD && input.value && input.id == SDLK_g && SDL_GetModState() & KMOD_LCTRL && Settings::getInstance()->getBool("Debug")) {