Lottie animations are now paused during view transitions.

This commit is contained in:
Leon Styhre 2022-02-19 22:44:02 +01:00
parent f803e23fd2
commit c06dea5d2d
6 changed files with 22 additions and 3 deletions

View file

@ -85,6 +85,12 @@ void GamelistView::onShow()
updateInfoPanel();
}
void GamelistView::onTransition()
{
for (auto& animation : mLottieAnimComponents)
animation->setPauseAnimation(true);
}
void GamelistView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
{
auto themeSets = ThemeData::getThemeSets();

View file

@ -23,6 +23,7 @@ public:
// Called when a FileData* is added, has its metadata changed, or is removed.
void onFileChanged(FileData* file, bool reloadGamelist) override;
void onShow() override;
void onTransition() override;
void preloadGamelist() { updateInfoPanel(); }
void launch(FileData* game) override { ViewController::getInstance()->triggerGameLaunch(game); }

View file

@ -330,6 +330,9 @@ void ViewController::goToSystemView(SystemData* system, bool playTransition)
mPreviousView = nullptr;
}
if (mCurrentView != nullptr)
mCurrentView->onTransition();
mPreviousView = mCurrentView;
if (system->isGroupedCustomCollection())
@ -415,6 +418,9 @@ void ViewController::goToGamelist(SystemData* system)
bool wrapLastToFirst = false;
bool slideTransitions = false;
if (mCurrentView != nullptr)
mCurrentView->onTransition();
if (Settings::getInstance()->getString("TransitionStyle") == "slide")
slideTransitions = true;

View file

@ -238,6 +238,7 @@ public:
virtual void onShow();
virtual void onHide();
virtual void onTransition() {}
// System view and gamelist view video controls.
virtual void startViewVideos() {}

View file

@ -36,6 +36,7 @@ LottieComponent::LottieComponent()
, mSkippedFrames {0}
, mHoldFrame {false}
, mPause {false}
, mExternalPause {false}
, mAlternate {false}
, mKeepAspectRatio {true}
{
@ -190,6 +191,7 @@ void LottieComponent::setAnimation(const std::string& path)
void LottieComponent::resetFileAnimation()
{
mExternalPause = false;
mTimeAccumulator = 0;
mFrameNum = mStartDirection == "reverse" ? mTotalFrames - 1 : 0;
@ -336,7 +338,7 @@ void LottieComponent::render(const glm::mat4& parentTrans)
glm::mat4 trans {parentTrans * getTransform()};
// This is necessary as there may otherwise be no texture to render when paused.
if (mPause && mTexture->getSize().x == 0.0f) {
if ((mExternalPause || mPause) && mTexture->getSize().x == 0.0f) {
mTexture->initFromPixels(&mPictureRGBA.at(0), static_cast<size_t>(mSize.x),
static_cast<size_t>(mSize.y));
}
@ -352,7 +354,7 @@ void LottieComponent::render(const glm::mat4& parentTrans)
}
// Don't render any new frames if paused or if a menu is open (unless invalidating background).
if (!mPause && doRender) {
if ((!mPause && !mExternalPause) && doRender) {
if ((mDirection == "normal" && mFrameNum >= mTotalFrames) ||
(mDirection == "reverse" && mFrameNum > mTotalFrames)) {
if (DEBUG_ANIMATION) {

View file

@ -33,6 +33,7 @@ public:
{
mMaxCacheSize = static_cast<size_t>(glm::clamp(value, 0, 1024) * 1024 * 1024);
}
void setPauseAnimation(bool state) { mExternalPause = state; }
void resetFileAnimation() override;
void onSizeChanged() override;
@ -42,8 +43,9 @@ public:
const std::string& element,
unsigned int properties) override;
private:
void update(int deltaTime) override;
private:
void render(const glm::mat4& parentTrans) override;
std::shared_ptr<TextureResource> mTexture;
@ -76,6 +78,7 @@ private:
bool mHoldFrame;
bool mPause;
bool mExternalPause;
bool mAlternate;
bool mKeepAspectRatio;
};