From 623c30217497b82bd9ecfcefd2c3afd10be33f80 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Tue, 17 Nov 2020 22:13:33 +0100 Subject: [PATCH] Cosmetic code cleanup of VideoComponent. --- es-core/src/components/VideoComponent.cpp | 275 +++++++++++----------- es-core/src/components/VideoComponent.h | 16 +- 2 files changed, 140 insertions(+), 151 deletions(-) diff --git a/es-core/src/components/VideoComponent.cpp b/es-core/src/components/VideoComponent.cpp index dc800f934..aabcb96ff 100644 --- a/es-core/src/components/VideoComponent.cpp +++ b/es-core/src/components/VideoComponent.cpp @@ -18,11 +18,6 @@ #define SCREENSAVER_FADE_IN_TIME 1200 -void VideoComponent::setScreensaverMode(bool isScreensaver) -{ - mScreensaverMode = isScreensaver; -} - VideoComponent::VideoComponent( Window* window) : GuiComponent(window), @@ -61,24 +56,6 @@ VideoComponent::~VideoComponent() stopVideo(); } -void VideoComponent::onOriginChanged() -{ - // Update the embeded static image. - mStaticImage.setOrigin(mOrigin); -} - -void VideoComponent::onPositionChanged() -{ - // Update the embeded static image. - mStaticImage.setPosition(mPosition); -} - -void VideoComponent::onSizeChanged() -{ - // Update the embeded static image. - mStaticImage.onSizeChanged(); -} - bool VideoComponent::setVideo(std::string path) { // Convert the path into a generic format. @@ -101,6 +78,11 @@ bool VideoComponent::setVideo(std::string path) return false; } +void VideoComponent::setDefaultVideo() +{ + setVideo(mConfig.defaultVideoPath); +} + void VideoComponent::setImage(std::string path) { // Check that the image has changed. @@ -111,17 +93,106 @@ void VideoComponent::setImage(std::string path) mStaticImagePath = path; } -void VideoComponent::setDefaultVideo() +void VideoComponent::setScreensaverMode(bool isScreensaver) { - setVideo(mConfig.defaultVideoPath); + mScreensaverMode = isScreensaver; } void VideoComponent::setOpacity(unsigned char opacity) { - // Set the opacity for the embedded static image. mOpacity = opacity; } +void VideoComponent::onShow() +{ + mBlockPlayer = false; + mPause = false; + mShowing = true; + manageState(); +} + +void VideoComponent::onHide() +{ + mShowing = false; + manageState(); +} + +void VideoComponent::onPauseVideo() +{ + mBlockPlayer = true; + mPause = true; + manageState(); +} + +void VideoComponent::onUnpauseVideo() +{ + mBlockPlayer = false; + mPause = false; + manageState(); +} + +void VideoComponent::onScreensaverActivate() +{ + mBlockPlayer = true; + mPause = true; + if (Settings::getInstance()->getString("ScreensaverType") == "dim") + stopVideo(); + manageState(); +} + +void VideoComponent::onScreensaverDeactivate() +{ + mBlockPlayer = false; + // Stop video when deactivating the screensaver to force a reload of the + // static image (if the theme is configured as such). + stopVideo(); + manageState(); +} + +void VideoComponent::onGameLaunchedActivate() +{ + mGameLaunched = true; + manageState(); +} + +void VideoComponent::onGameLaunchedDeactivate() +{ + mGameLaunched = false; + stopVideo(); + manageState(); +} + +void VideoComponent::topWindow(bool isTop) +{ + if (isTop) { + mBlockPlayer = false; + mPause = false; + // Stop video when closing the menu to force a reload of the + // static image (if the theme is configured as such). + stopVideo(); + } + else { + mBlockPlayer = true; + mPause = true; + } + manageState(); +} + +void VideoComponent::onOriginChanged() +{ + mStaticImage.setOrigin(mOrigin); +} + +void VideoComponent::onPositionChanged() +{ + mStaticImage.setPosition(mPosition); +} + +void VideoComponent::onSizeChanged() +{ + mStaticImage.onSizeChanged(); +} + void VideoComponent::render(const Transform4x4f& parentTrans) { if (!isVisible()) @@ -207,35 +278,24 @@ std::vector VideoComponent::getHelpPrompts() return ret; } -void VideoComponent::handleStartDelay() +void VideoComponent::update(int deltaTime) { - if (mBlockPlayer) + if (mBlockPlayer) { + setImage(mStaticImagePath); return; - - // Only play if any delay has timed out. - if (mStartDelayed) { - // If the setting to override the theme-supplied video delay setting has been enabled, - // then play the video immediately. - if (!Settings::getInstance()->getBool("PlayVideosImmediately")) { - // If there is a video file available but no static image, then start playing the - // video immediately regardless of theme configuration or settings. - if (mStaticImagePath != "") { - if (mStartTime > SDL_GetTicks()) { - // Timeout not yet completed. - return; - } - } - } - // Completed. - mStartDelayed = false; - // Clear the playing flag so startVideo works. - mIsPlaying = false; - startVideo(); } -} -void VideoComponent::handleLooping() -{ + manageState(); + + // Fade in videos, which is handled a bit differently depending on whether it's the + // video screensaver that is running, or if it's the video in the gamelist. + if (mScreensaverMode && mFadeIn < 1.0f) + mFadeIn = Math::clamp(mFadeIn + (deltaTime / + static_cast(SCREENSAVER_FADE_IN_TIME)), 0.0, 1.0); + else if (mFadeIn < 1.0f) + mFadeIn = Math::clamp(mFadeIn + 0.01, 0.0f, 1.0f); + + GuiComponent::update(deltaTime); } void VideoComponent::startVideoWithDelay() @@ -261,24 +321,31 @@ void VideoComponent::startVideoWithDelay() } } -void VideoComponent::update(int deltaTime) +void VideoComponent::handleStartDelay() { - if (mBlockPlayer) { - setImage(mStaticImagePath); + if (mBlockPlayer) return; + + // Only play if any delay has timed out. + if (mStartDelayed) { + // If the setting to override the theme-supplied video delay setting has been enabled, + // then play the video immediately. + if (!Settings::getInstance()->getBool("PlayVideosImmediately")) { + // If there is a video file available but no static image, then start playing the + // video immediately regardless of theme configuration or settings. + if (mStaticImagePath != "") { + if (mStartTime > SDL_GetTicks()) { + // Timeout not yet completed. + return; + } + } + } + // Completed. + mStartDelayed = false; + // Clear the playing flag so startVideo works. + mIsPlaying = false; + startVideo(); } - - manageState(); - - // Fade in videos, which is handled a bit differently depending on whether it's the - // video screensaver that is running, or if it's the video in the gamelist. - if (mScreensaverMode && mFadeIn < 1.0f) - mFadeIn = Math::clamp(mFadeIn + (deltaTime / - static_cast(SCREENSAVER_FADE_IN_TIME)), 0.0, 1.0); - else if (mFadeIn < 1.0f) - mFadeIn = Math::clamp(mFadeIn + 0.01, 0.0f, 1.0f); - - GuiComponent::update(deltaTime); } void VideoComponent::manageState() @@ -314,79 +381,3 @@ void VideoComponent::manageState() if (mGameLaunched && show && !mPause) mPause = true; } - -void VideoComponent::onShow() -{ - mBlockPlayer = false; - mPause = false; - mShowing = true; - manageState(); -} - -void VideoComponent::onHide() -{ - mShowing = false; - manageState(); -} - -void VideoComponent::onPauseVideo() -{ - mBlockPlayer = true; - mPause = true; - manageState(); -} - -void VideoComponent::onUnpauseVideo() -{ - mBlockPlayer = false; - mPause = false; - manageState(); -} - -void VideoComponent::onScreensaverActivate() -{ - mBlockPlayer = true; - mPause = true; - if (Settings::getInstance()->getString("ScreensaverType") == "dim") - stopVideo(); - manageState(); -} - -void VideoComponent::onScreensaverDeactivate() -{ - mBlockPlayer = false; - // Stop video when deactivating the screensaver to force a reload of the - // static image (if the theme is configured as such). - stopVideo(); - manageState(); -} - -void VideoComponent::onGameLaunchedActivate() -{ - mGameLaunched = true; - manageState(); -} - -void VideoComponent::onGameLaunchedDeactivate() -{ - mGameLaunched = false; - stopVideo(); - manageState(); -} - -void VideoComponent::topWindow(bool isTop) -{ - - if (isTop) { - mBlockPlayer = false; - mPause = false; - // Stop video when closing the menu to force a reload of the - // static image (if the theme is configured as such). - stopVideo(); - } - else { - mBlockPlayer = true; - mPause = true; - } - manageState(); -} diff --git a/es-core/src/components/VideoComponent.h b/es-core/src/components/VideoComponent.h index cd6f9fbce..686f2147e 100644 --- a/es-core/src/components/VideoComponent.h +++ b/es-core/src/components/VideoComponent.h @@ -32,14 +32,14 @@ public: // Loads the video at the given filepath. bool setVideo(std::string path); - // Loads a static image that is displayed if the video cannot be played. - void setImage(std::string path); - // Configures the component to show the default video. void setDefaultVideo(); - + // Loads a static image that is displayed if the video cannot be played. + void setImage(std::string path); // Sets whether it's going to render in screensaver mode. void setScreensaverMode(bool isScreensaver); + // Set the opacity for the embedded static image. + void setOpacity(unsigned char opacity) override; virtual void onShow() override; virtual void onHide() override; @@ -52,10 +52,10 @@ public: virtual void onGameLaunchedDeactivate() override; virtual void topWindow(bool isTop) override; + // These functions update the embedded static image. void onOriginChanged() override; void onPositionChanged() override; void onSizeChanged() override; - void setOpacity(unsigned char opacity) override; void render(const Transform4x4f& parentTrans) override; void renderSnapshot(const Transform4x4f& parentTrans); @@ -87,15 +87,13 @@ private: virtual void stopVideo() {}; // Pause the video when a game has been launched. virtual void pauseVideo() {}; - // Handle looping the video. Must be called periodically. - virtual void handleLooping(); + // Handle looping of the video. Must be called periodically. + virtual void handleLooping() {}; // Start the video after any configured delay. void startVideoWithDelay(); - // Handle any delay to the start of playing the video clip. Must be called periodically. void handleStartDelay(); - // Manage the playing state of the component. void manageState();