mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-25 15:45:38 +00:00
Reduced the slideshow screensaver fade-in time
Also made some general code cleanup
This commit is contained in:
parent
964f9fabff
commit
c32bbc4888
|
@ -22,24 +22,23 @@
|
|||
|
||||
#include <random>
|
||||
#include <time.h>
|
||||
#include <unordered_map>
|
||||
|
||||
#if defined(_WIN64)
|
||||
#include <cstring>
|
||||
#endif
|
||||
|
||||
#define FADE_TIME 300.0f
|
||||
#define IMAGES_FADE_IN_TIME 450.0f
|
||||
|
||||
Screensaver::Screensaver()
|
||||
: mRenderer {Renderer::getInstance()}
|
||||
, mWindow {Window::getInstance()}
|
||||
, mState {STATE_INACTIVE}
|
||||
, mImageScreensaver {nullptr}
|
||||
, mVideoScreensaver {nullptr}
|
||||
, mCurrentGame {nullptr}
|
||||
, mPreviousGame {nullptr}
|
||||
, mTimer {0}
|
||||
, mMediaSwapTime {0}
|
||||
, mScreensaverActive {false}
|
||||
, mTriggerNextGame {false}
|
||||
, mHasMediaFiles {false}
|
||||
, mFallbackScreensaver {false}
|
||||
|
@ -63,6 +62,7 @@ void Screensaver::startScreensaver(bool generateMediaList)
|
|||
mScreensaverType = "dim";
|
||||
}
|
||||
std::string path;
|
||||
mScreensaverActive = true;
|
||||
mHasMediaFiles = false;
|
||||
mFallbackScreensaver = false;
|
||||
mOpacity = 0.0f;
|
||||
|
@ -85,9 +85,6 @@ void Screensaver::startScreensaver(bool generateMediaList)
|
|||
mImageCustomFiles.clear();
|
||||
}
|
||||
|
||||
// This creates a fade transition between the images.
|
||||
mState = STATE_FADE_OUT_WINDOW;
|
||||
|
||||
mMediaSwapTime = Settings::getInstance()->getInt("ScreensaverSwapImageTimeout");
|
||||
|
||||
// Load a random image.
|
||||
|
@ -141,9 +138,6 @@ void Screensaver::startScreensaver(bool generateMediaList)
|
|||
if (generateMediaList)
|
||||
mVideoFiles.clear();
|
||||
|
||||
// This creates a fade transition between the videos.
|
||||
mState = STATE_FADE_OUT_WINDOW;
|
||||
|
||||
mMediaSwapTime = Settings::getInstance()->getInt("ScreensaverSwapVideoTimeout");
|
||||
|
||||
// Load a random video.
|
||||
|
@ -178,7 +172,6 @@ void Screensaver::startScreensaver(bool generateMediaList)
|
|||
}
|
||||
}
|
||||
// No videos or images, just use a standard screensaver.
|
||||
mState = STATE_SCREENSAVER_ACTIVE;
|
||||
mCurrentGame = nullptr;
|
||||
}
|
||||
|
||||
|
@ -187,7 +180,7 @@ void Screensaver::stopScreensaver()
|
|||
mImageScreensaver.reset();
|
||||
mVideoScreensaver.reset();
|
||||
|
||||
mState = STATE_INACTIVE;
|
||||
mScreensaverActive = false;
|
||||
mDimValue = 1.0f;
|
||||
mRectangleFadeIn = 50;
|
||||
mTextFadeIn = 0;
|
||||
|
@ -270,24 +263,18 @@ void Screensaver::renderScreensaver()
|
|||
// Render a black background below the video.
|
||||
mRenderer->drawRect(0.0f, 0.0f, Renderer::getScreenWidth(), Renderer::getScreenHeight(),
|
||||
0x000000FF, 0x000000FF);
|
||||
|
||||
// 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") {
|
||||
// Render a black background below the image.
|
||||
mRenderer->drawRect(0.0f, 0.0f, Renderer::getScreenWidth(), Renderer::getScreenHeight(),
|
||||
0x000000FF, 0x000000FF);
|
||||
|
||||
// Only render the image if the state requires it.
|
||||
if (static_cast<int>(mState) >= STATE_FADE_IN_VIDEO) {
|
||||
if (mImageScreensaver->hasImage()) {
|
||||
mImageScreensaver->setOpacity(1.0f - mOpacity);
|
||||
// Leave a small gap without rendering during fade-in.
|
||||
if (mOpacity > 0.5f) {
|
||||
mImageScreensaver->setOpacity(mOpacity);
|
||||
mImageScreensaver->render(trans);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isScreensaverActive()) {
|
||||
if (mScreensaverType == "slideshow") {
|
||||
|
@ -382,25 +369,6 @@ void Screensaver::renderScreensaver()
|
|||
|
||||
void Screensaver::update(int deltaTime)
|
||||
{
|
||||
// Use this to update the fade value for the current fade stage.
|
||||
if (mState == STATE_FADE_OUT_WINDOW) {
|
||||
mOpacity += static_cast<float>(deltaTime) / FADE_TIME;
|
||||
if (mOpacity >= 1.0f) {
|
||||
mOpacity = 1.0f;
|
||||
|
||||
// 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.
|
||||
|
@ -413,13 +381,16 @@ void Screensaver::update(int deltaTime)
|
|||
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)
|
||||
mVideoScreensaver->update(deltaTime);
|
||||
if (mImageScreensaver)
|
||||
mImageScreensaver->update(deltaTime);
|
||||
}
|
||||
|
||||
void Screensaver::generateImageList()
|
||||
|
|
|
@ -11,18 +11,16 @@
|
|||
#define ES_APP_SCREENSAVER_H
|
||||
|
||||
#include "Window.h"
|
||||
#include "components/ImageComponent.h"
|
||||
#include "components/VideoComponent.h"
|
||||
#include "resources/Font.h"
|
||||
|
||||
class ImageComponent;
|
||||
class VideoComponent;
|
||||
|
||||
// Screensaver implementation.
|
||||
class Screensaver : public Window::Screensaver
|
||||
{
|
||||
public:
|
||||
Screensaver();
|
||||
|
||||
virtual bool isScreensaverActive() { return (mState != STATE_INACTIVE); }
|
||||
virtual bool isScreensaverActive() { return mScreensaverActive; }
|
||||
virtual bool isFallbackScreensaver() { return mFallbackScreensaver; }
|
||||
|
||||
virtual void startScreensaver(bool generateMediaList);
|
||||
|
@ -46,16 +44,8 @@ private:
|
|||
void pickRandomCustomImage(std::string& path);
|
||||
void generateOverlayInfo();
|
||||
|
||||
enum STATE {
|
||||
STATE_INACTIVE,
|
||||
STATE_FADE_OUT_WINDOW,
|
||||
STATE_FADE_IN_VIDEO,
|
||||
STATE_SCREENSAVER_ACTIVE
|
||||
};
|
||||
|
||||
Renderer* mRenderer;
|
||||
Window* mWindow;
|
||||
STATE mState;
|
||||
|
||||
std::vector<FileData*> mImageFiles;
|
||||
std::vector<FileData*> mVideoFiles;
|
||||
|
@ -72,6 +62,7 @@ private:
|
|||
|
||||
int mTimer;
|
||||
int mMediaSwapTime;
|
||||
bool mScreensaverActive;
|
||||
bool mTriggerNextGame;
|
||||
bool mHasMediaFiles;
|
||||
bool mFallbackScreensaver;
|
||||
|
|
|
@ -128,7 +128,6 @@ bool SystemView::input(InputConfig* config, Input input)
|
|||
ViewController::getInstance()->stopScrolling();
|
||||
ViewController::getInstance()->cancelViewTransitions();
|
||||
mWindow->startScreensaver(false);
|
||||
mWindow->renderScreensaver();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -642,10 +642,6 @@ void Window::render()
|
|||
if (mInfoPopup)
|
||||
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)
|
||||
mMediaViewer->render(trans);
|
||||
|
||||
|
@ -655,6 +651,9 @@ void Window::render()
|
|||
if (mRenderLaunchScreen)
|
||||
mLaunchScreen->render(trans);
|
||||
|
||||
if (mRenderScreensaver)
|
||||
mScreensaver->renderScreensaver();
|
||||
|
||||
if (Settings::getInstance()->getBool("DisplayGPUStatistics") && mFrameDataText) {
|
||||
mRenderer->setMatrix(mRenderer->getIdentity());
|
||||
mDefaultFonts.at(1)->renderTextCache(mFrameDataText.get());
|
||||
|
@ -829,12 +828,6 @@ bool Window::stopScreensaver()
|
|||
return false;
|
||||
}
|
||||
|
||||
void Window::renderScreensaver()
|
||||
{
|
||||
if (mScreensaver)
|
||||
mScreensaver->renderScreensaver();
|
||||
}
|
||||
|
||||
void Window::startMediaViewer(FileData* game)
|
||||
{
|
||||
if (mMediaViewer) {
|
||||
|
|
|
@ -127,7 +127,6 @@ public:
|
|||
|
||||
void startScreensaver(bool onTimer);
|
||||
bool stopScreensaver();
|
||||
void renderScreensaver();
|
||||
void screensaverTriggerNextGame() { mScreensaver->triggerNextGame(); }
|
||||
void setScreensaver(Screensaver* screensaver) { mScreensaver = screensaver; }
|
||||
bool isScreensaverActive() { return mRenderScreensaver; }
|
||||
|
|
Loading…
Reference in a new issue