Adding slider to control screensaver swap time

This commit is contained in:
pjft 2017-08-23 09:21:31 +01:00
parent 6d95146df6
commit 7caf70a5e5
7 changed files with 35 additions and 7 deletions

View file

@ -15,7 +15,6 @@
#include <stdio.h> #include <stdio.h>
#define FADE_TIME 300 #define FADE_TIME 300
#define SWAP_VIDEO_TIMEOUT 30000
SystemScreenSaver::SystemScreenSaver(Window* window) : SystemScreenSaver::SystemScreenSaver(Window* window) :
mVideoScreensaver(NULL), mVideoScreensaver(NULL),
@ -34,6 +33,7 @@ SystemScreenSaver::SystemScreenSaver(Window* window) :
if(!boost::filesystem::exists(path)) if(!boost::filesystem::exists(path))
boost::filesystem::create_directory(path); boost::filesystem::create_directory(path);
srand((unsigned int)time(NULL)); srand((unsigned int)time(NULL));
mVideoChangeTime = 30000;
} }
SystemScreenSaver::~SystemScreenSaver() SystemScreenSaver::~SystemScreenSaver()
@ -63,6 +63,7 @@ void SystemScreenSaver::startScreenSaver()
mState = PowerSaver::getMode() == PowerSaver::INSTANT mState = PowerSaver::getMode() == PowerSaver::INSTANT
? STATE_SCREENSAVER_ACTIVE ? STATE_SCREENSAVER_ACTIVE
: STATE_FADE_OUT_WINDOW; : STATE_FADE_OUT_WINDOW;
mVideoChangeTime = Settings::getInstance()->getInt("ScreenSaverSwapVideoTimeout");
mOpacity = 0.0f; mOpacity = 0.0f;
// Load a random video // Load a random video
@ -117,6 +118,7 @@ void SystemScreenSaver::stopScreenSaver()
{ {
delete mVideoScreensaver; delete mVideoScreensaver;
mVideoScreensaver = NULL; mVideoScreensaver = NULL;
// we need this to loop through different videos
mState = STATE_INACTIVE; mState = STATE_INACTIVE;
PowerSaver::runningScreenSaver(false); PowerSaver::runningScreenSaver(false);
} }
@ -291,7 +293,7 @@ void SystemScreenSaver::update(int deltaTime)
{ {
// Update the timer that swaps the videos // Update the timer that swaps the videos
mTimer += deltaTime; mTimer += deltaTime;
if (mTimer > SWAP_VIDEO_TIMEOUT) if (mTimer > mVideoChangeTime)
{ {
nextVideo(); nextVideo();
} }

View file

@ -46,4 +46,5 @@ private:
FileData* mCurrentGame; FileData* mCurrentGame;
std::string mGameName; std::string mGameName;
std::string mSystemName; std::string mSystemName;
int mVideoChangeTime;
}; };

View file

@ -10,11 +10,21 @@
#include "components/OptionListComponent.h" #include "components/OptionListComponent.h"
#include "components/MenuComponent.h" #include "components/MenuComponent.h"
#include "guis/GuiMsgBox.h" #include "guis/GuiMsgBox.h"
#include "PowerSaver.h"
GuiScreensaverOptions::GuiScreensaverOptions(Window* window, const char* title) : GuiComponent(window), mMenu(window, title) GuiScreensaverOptions::GuiScreensaverOptions(Window* window, const char* title) : GuiComponent(window), mMenu(window, title)
{ {
addChild(&mMenu); addChild(&mMenu);
// timeout to swap videos
auto swap = std::make_shared<SliderComponent>(mWindow, 10.f, 1000.f, 1.f, "s");
swap->setValue((float)(Settings::getInstance()->getInt("ScreenSaverSwapVideoTimeout") / (1000)));
addWithLabel("SWAP VIDEO AFTER (SECS)", swap);
addSaveFunc([swap] {
Settings::getInstance()->setInt("ScreenSaverSwapVideoTimeout", (int)round(swap->getValue()) * (1000));
PowerSaver::updateTimeouts();
});
#ifdef _RPI_ #ifdef _RPI_
auto ss_omx = std::make_shared<SwitchComponent>(mWindow); auto ss_omx = std::make_shared<SwitchComponent>(mWindow);
ss_omx->setState(Settings::getInstance()->getBool("ScreenSaverOmxPlayer")); ss_omx->setState(Settings::getInstance()->getBool("ScreenSaverOmxPlayer"));

View file

@ -25,7 +25,7 @@ void PowerSaver::updateTimeouts()
{ {
mScreenSaverTimeout = (unsigned int) Settings::getInstance()->getInt("ScreenSaverTime"); mScreenSaverTimeout = (unsigned int) Settings::getInstance()->getInt("ScreenSaverTime");
mScreenSaverTimeout = mScreenSaverTimeout > 0 ? mScreenSaverTimeout - getMode() : -1; mScreenSaverTimeout = mScreenSaverTimeout > 0 ? mScreenSaverTimeout - getMode() : -1;
mPlayNextTimeout = 30000 - getMode(); mPlayNextTimeout = Settings::getInstance()->getInt("ScreenSaverSwapVideoTimeout") - getMode();
} }
PowerSaver::mode PowerSaver::getMode() PowerSaver::mode PowerSaver::getMode()

View file

@ -1,3 +1,5 @@
#pragma once
class PowerSaver class PowerSaver
{ {
public: public:

View file

@ -94,6 +94,8 @@ void Settings::setDefaults()
mBoolMap["ScreenSaverOmxPlayer"] = false; mBoolMap["ScreenSaverOmxPlayer"] = false;
#endif #endif
mIntMap["ScreenSaverSwapVideoTimeout"] = 30000;
mBoolMap["VideoAudio"] = true; mBoolMap["VideoAudio"] = true;
mBoolMap["CaptionsCompatibility"] = true; mBoolMap["CaptionsCompatibility"] = true;
// Audio out device for Video playback using OMX player. // Audio out device for Video playback using OMX player.

View file

@ -1,6 +1,7 @@
#include "components/VideoComponent.h" #include "components/VideoComponent.h"
#include "Renderer.h" #include "Renderer.h"
#include "ThemeData.h" #include "ThemeData.h"
#include "Settings.h"
#include "Util.h" #include "Util.h"
#include "Window.h" #include "Window.h"
#include "PowerSaver.h" #include "PowerSaver.h"
@ -23,8 +24,11 @@ std::string getTitleFolder() {
void writeSubtitle(const char* gameName, const char* systemName, bool always) void writeSubtitle(const char* gameName, const char* systemName, bool always)
{ {
FILE* file = fopen(getTitlePath().c_str(), "w"); FILE* file = fopen(getTitlePath().c_str(), "w");
int end = (int)(Settings::getInstance()->getInt("ScreenSaverSwapVideoTimeout") / (1000));
if (always) { if (always) {
fprintf(file, "1\n00:00:01,000 --> 00:00:30,000\n"); fprintf(file, "1\n00:00:01,000 --> 00:00:");
fprintf(file, std::to_string(end).c_str());
fprintf(file, ",000\n");
} }
else else
{ {
@ -34,9 +38,16 @@ void writeSubtitle(const char* gameName, const char* systemName, bool always)
fprintf(file, "<i>%s</i>\n\n", systemName); fprintf(file, "<i>%s</i>\n\n", systemName);
if (!always) { if (!always) {
fprintf(file, "2\n00:00:26,000 --> 00:00:30,000\n"); if (end > 12)
fprintf(file, "%s\n", gameName); {
fprintf(file, "<i>%s</i>\n", systemName); fprintf(file, "2\n00:00:");
fprintf(file, std::to_string(end - 4).c_str());
fprintf(file, ",000 --> 00:00:");
fprintf(file, std::to_string(end).c_str());
fprintf(file, ",000\n");
fprintf(file, "%s\n", gameName);
fprintf(file, "<i>%s</i>\n", systemName);
}
} }
fflush(file); fflush(file);