Reduced the slideshow screensaver fade-in time

Also made some general code cleanup
This commit is contained in:
Leon Styhre 2023-08-20 13:21:11 +02:00
parent 964f9fabff
commit c32bbc4888
5 changed files with 33 additions and 80 deletions

View file

@ -22,24 +22,23 @@
#include <random> #include <random>
#include <time.h> #include <time.h>
#include <unordered_map>
#if defined(_WIN64) #if defined(_WIN64)
#include <cstring> #include <cstring>
#endif #endif
#define FADE_TIME 300.0f #define IMAGES_FADE_IN_TIME 450.0f
Screensaver::Screensaver() Screensaver::Screensaver()
: mRenderer {Renderer::getInstance()} : mRenderer {Renderer::getInstance()}
, mWindow {Window::getInstance()} , mWindow {Window::getInstance()}
, mState {STATE_INACTIVE}
, mImageScreensaver {nullptr} , mImageScreensaver {nullptr}
, mVideoScreensaver {nullptr} , mVideoScreensaver {nullptr}
, mCurrentGame {nullptr} , mCurrentGame {nullptr}
, mPreviousGame {nullptr} , mPreviousGame {nullptr}
, mTimer {0} , mTimer {0}
, mMediaSwapTime {0} , mMediaSwapTime {0}
, mScreensaverActive {false}
, mTriggerNextGame {false} , mTriggerNextGame {false}
, mHasMediaFiles {false} , mHasMediaFiles {false}
, mFallbackScreensaver {false} , mFallbackScreensaver {false}
@ -63,6 +62,7 @@ void Screensaver::startScreensaver(bool generateMediaList)
mScreensaverType = "dim"; mScreensaverType = "dim";
} }
std::string path; std::string path;
mScreensaverActive = true;
mHasMediaFiles = false; mHasMediaFiles = false;
mFallbackScreensaver = false; mFallbackScreensaver = false;
mOpacity = 0.0f; mOpacity = 0.0f;
@ -85,9 +85,6 @@ void Screensaver::startScreensaver(bool generateMediaList)
mImageCustomFiles.clear(); mImageCustomFiles.clear();
} }
// This creates a fade transition between the images.
mState = STATE_FADE_OUT_WINDOW;
mMediaSwapTime = Settings::getInstance()->getInt("ScreensaverSwapImageTimeout"); mMediaSwapTime = Settings::getInstance()->getInt("ScreensaverSwapImageTimeout");
// Load a random image. // Load a random image.
@ -141,9 +138,6 @@ void Screensaver::startScreensaver(bool generateMediaList)
if (generateMediaList) if (generateMediaList)
mVideoFiles.clear(); mVideoFiles.clear();
// This creates a fade transition between the videos.
mState = STATE_FADE_OUT_WINDOW;
mMediaSwapTime = Settings::getInstance()->getInt("ScreensaverSwapVideoTimeout"); mMediaSwapTime = Settings::getInstance()->getInt("ScreensaverSwapVideoTimeout");
// Load a random video. // Load a random video.
@ -178,7 +172,6 @@ void Screensaver::startScreensaver(bool generateMediaList)
} }
} }
// No videos or images, just use a standard screensaver. // No videos or images, just use a standard screensaver.
mState = STATE_SCREENSAVER_ACTIVE;
mCurrentGame = nullptr; mCurrentGame = nullptr;
} }
@ -187,7 +180,7 @@ void Screensaver::stopScreensaver()
mImageScreensaver.reset(); mImageScreensaver.reset();
mVideoScreensaver.reset(); mVideoScreensaver.reset();
mState = STATE_INACTIVE; mScreensaverActive = false;
mDimValue = 1.0f; mDimValue = 1.0f;
mRectangleFadeIn = 50; mRectangleFadeIn = 50;
mTextFadeIn = 0; mTextFadeIn = 0;
@ -270,22 +263,16 @@ void Screensaver::renderScreensaver()
// Render a black background below the video. // Render a black background below the video.
mRenderer->drawRect(0.0f, 0.0f, Renderer::getScreenWidth(), Renderer::getScreenHeight(), mRenderer->drawRect(0.0f, 0.0f, Renderer::getScreenWidth(), Renderer::getScreenHeight(),
0x000000FF, 0x000000FF); 0x000000FF, 0x000000FF);
mVideoScreensaver->render(trans);
// Only render the video if the state requires it.
if (static_cast<int>(mState) >= STATE_FADE_IN_VIDEO)
mVideoScreensaver->render(trans);
} }
else if (mImageScreensaver && mScreensaverType == "slideshow") { else if (mImageScreensaver && mScreensaverType == "slideshow") {
// Render a black background below the image. // Render a black background below the image.
mRenderer->drawRect(0.0f, 0.0f, Renderer::getScreenWidth(), Renderer::getScreenHeight(), mRenderer->drawRect(0.0f, 0.0f, Renderer::getScreenWidth(), Renderer::getScreenHeight(),
0x000000FF, 0x000000FF); 0x000000FF, 0x000000FF);
// Leave a small gap without rendering during fade-in.
// Only render the image if the state requires it. if (mOpacity > 0.5f) {
if (static_cast<int>(mState) >= STATE_FADE_IN_VIDEO) { mImageScreensaver->setOpacity(mOpacity);
if (mImageScreensaver->hasImage()) { mImageScreensaver->render(trans);
mImageScreensaver->setOpacity(1.0f - mOpacity);
mImageScreensaver->render(trans);
}
} }
} }
@ -382,44 +369,28 @@ void Screensaver::renderScreensaver()
void Screensaver::update(int deltaTime) void Screensaver::update(int deltaTime)
{ {
// Use this to update the fade value for the current fade stage. // Update the timer that swaps the media, unless the swap time is set to 0 (only
if (mState == STATE_FADE_OUT_WINDOW) { // applicable for the video screensaver). This means that videos play to the end,
mOpacity += static_cast<float>(deltaTime) / FADE_TIME; // at which point the video player will trigger a skip to the next game.
if (mOpacity >= 1.0f) { if (mMediaSwapTime != 0) {
mOpacity = 1.0f; mTimer += deltaTime;
if (mTimer > mMediaSwapTime)
// Update to the next state.
mState = STATE_FADE_IN_VIDEO;
}
}
else if (mState == STATE_FADE_IN_VIDEO) {
mOpacity -= static_cast<float>(deltaTime) / FADE_TIME;
if (mOpacity <= 0.0f) {
mOpacity = 0.0f;
// Update to the next state.
mState = STATE_SCREENSAVER_ACTIVE;
}
}
else if (mState == STATE_SCREENSAVER_ACTIVE) {
// Update the timer that swaps the media, unless the swap time is set to 0 (only
// applicable for the video screensaver). This means that videos play to the end,
// at which point the video player will trigger a skip to the next game.
if (mMediaSwapTime != 0) {
mTimer += deltaTime;
if (mTimer > mMediaSwapTime)
nextGame();
}
if (mTriggerNextGame) {
mTriggerNextGame = false;
nextGame(); nextGame();
} }
if (mTriggerNextGame) {
mTriggerNextGame = false;
nextGame();
}
// Fade-in for the video screensaver is handled in VideoComponent.
if (mImageScreensaver && mOpacity < 1.0f) {
mOpacity += static_cast<float>(deltaTime) / IMAGES_FADE_IN_TIME;
if (mOpacity > 1.0f)
mOpacity = 1.0f;
} }
// If we have a loaded a video or image, then update it.
if (mVideoScreensaver) if (mVideoScreensaver)
mVideoScreensaver->update(deltaTime); mVideoScreensaver->update(deltaTime);
if (mImageScreensaver)
mImageScreensaver->update(deltaTime);
} }
void Screensaver::generateImageList() void Screensaver::generateImageList()

View file

@ -11,18 +11,16 @@
#define ES_APP_SCREENSAVER_H #define ES_APP_SCREENSAVER_H
#include "Window.h" #include "Window.h"
#include "components/ImageComponent.h"
#include "components/VideoComponent.h"
#include "resources/Font.h" #include "resources/Font.h"
class ImageComponent;
class VideoComponent;
// Screensaver implementation.
class Screensaver : public Window::Screensaver class Screensaver : public Window::Screensaver
{ {
public: public:
Screensaver(); Screensaver();
virtual bool isScreensaverActive() { return (mState != STATE_INACTIVE); } virtual bool isScreensaverActive() { return mScreensaverActive; }
virtual bool isFallbackScreensaver() { return mFallbackScreensaver; } virtual bool isFallbackScreensaver() { return mFallbackScreensaver; }
virtual void startScreensaver(bool generateMediaList); virtual void startScreensaver(bool generateMediaList);
@ -46,16 +44,8 @@ private:
void pickRandomCustomImage(std::string& path); void pickRandomCustomImage(std::string& path);
void generateOverlayInfo(); void generateOverlayInfo();
enum STATE {
STATE_INACTIVE,
STATE_FADE_OUT_WINDOW,
STATE_FADE_IN_VIDEO,
STATE_SCREENSAVER_ACTIVE
};
Renderer* mRenderer; Renderer* mRenderer;
Window* mWindow; Window* mWindow;
STATE mState;
std::vector<FileData*> mImageFiles; std::vector<FileData*> mImageFiles;
std::vector<FileData*> mVideoFiles; std::vector<FileData*> mVideoFiles;
@ -72,6 +62,7 @@ private:
int mTimer; int mTimer;
int mMediaSwapTime; int mMediaSwapTime;
bool mScreensaverActive;
bool mTriggerNextGame; bool mTriggerNextGame;
bool mHasMediaFiles; bool mHasMediaFiles;
bool mFallbackScreensaver; bool mFallbackScreensaver;

View file

@ -128,7 +128,6 @@ bool SystemView::input(InputConfig* config, Input input)
ViewController::getInstance()->stopScrolling(); ViewController::getInstance()->stopScrolling();
ViewController::getInstance()->cancelViewTransitions(); ViewController::getInstance()->cancelViewTransitions();
mWindow->startScreensaver(false); mWindow->startScreensaver(false);
mWindow->renderScreensaver();
} }
return true; return true;
} }

View file

@ -642,10 +642,6 @@ void Window::render()
if (mInfoPopup) if (mInfoPopup)
mInfoPopup->render(trans); mInfoPopup->render(trans);
// Always call the screensaver render function regardless of whether the screensaver is active
// or not because it may perform a fade on transition.
renderScreensaver();
if (mRenderMediaViewer) if (mRenderMediaViewer)
mMediaViewer->render(trans); mMediaViewer->render(trans);
@ -655,6 +651,9 @@ void Window::render()
if (mRenderLaunchScreen) if (mRenderLaunchScreen)
mLaunchScreen->render(trans); mLaunchScreen->render(trans);
if (mRenderScreensaver)
mScreensaver->renderScreensaver();
if (Settings::getInstance()->getBool("DisplayGPUStatistics") && mFrameDataText) { if (Settings::getInstance()->getBool("DisplayGPUStatistics") && mFrameDataText) {
mRenderer->setMatrix(mRenderer->getIdentity()); mRenderer->setMatrix(mRenderer->getIdentity());
mDefaultFonts.at(1)->renderTextCache(mFrameDataText.get()); mDefaultFonts.at(1)->renderTextCache(mFrameDataText.get());
@ -829,12 +828,6 @@ bool Window::stopScreensaver()
return false; return false;
} }
void Window::renderScreensaver()
{
if (mScreensaver)
mScreensaver->renderScreensaver();
}
void Window::startMediaViewer(FileData* game) void Window::startMediaViewer(FileData* game)
{ {
if (mMediaViewer) { if (mMediaViewer) {

View file

@ -127,7 +127,6 @@ public:
void startScreensaver(bool onTimer); void startScreensaver(bool onTimer);
bool stopScreensaver(); bool stopScreensaver();
void renderScreensaver();
void screensaverTriggerNextGame() { mScreensaver->triggerNextGame(); } void screensaverTriggerNextGame() { mScreensaver->triggerNextGame(); }
void setScreensaver(Screensaver* screensaver) { mScreensaver = screensaver; } void setScreensaver(Screensaver* screensaver) { mScreensaver = screensaver; }
bool isScreensaverActive() { return mRenderScreensaver; } bool isScreensaverActive() { return mRenderScreensaver; }