Renamed LottieComponent to LottieAnimComponent.

This commit is contained in:
Leon Styhre 2022-02-23 21:54:57 +01:00
parent 81291dcbbf
commit 32349dc9a6
9 changed files with 53 additions and 51 deletions

View file

@ -16,7 +16,7 @@
#include "Window.h" #include "Window.h"
#include "components/BadgeComponent.h" #include "components/BadgeComponent.h"
#include "components/DateTimeComponent.h" #include "components/DateTimeComponent.h"
#include "components/LottieComponent.h" #include "components/LottieAnimComponent.h"
#include "components/RatingComponent.h" #include "components/RatingComponent.h"
#include "components/ScrollableContainer.h" #include "components/ScrollableContainer.h"
#include "components/TextComponent.h" #include "components/TextComponent.h"

View file

@ -126,7 +126,7 @@ void GamelistView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
mVideoComponents.back()->setScrollHide(true); mVideoComponents.back()->setScrollHide(true);
} }
else if (element.second.type == "animation") { else if (element.second.type == "animation") {
mLottieAnimComponents.push_back(std::make_unique<LottieComponent>()); mLottieAnimComponents.push_back(std::make_unique<LottieAnimComponent>());
mLottieAnimComponents.back()->setDefaultZIndex(35.0f); mLottieAnimComponents.back()->setDefaultZIndex(35.0f);
mLottieAnimComponents.back()->applyTheme(theme, "gamelist", element.first, ALL); mLottieAnimComponents.back()->applyTheme(theme, "gamelist", element.first, ALL);
addChild(mLottieAnimComponents.back().get()); addChild(mLottieAnimComponents.back().get());

View file

@ -100,7 +100,7 @@ private:
std::vector<std::unique_ptr<DateTimeComponent>> mDateTimeComponents; std::vector<std::unique_ptr<DateTimeComponent>> mDateTimeComponents;
std::vector<std::unique_ptr<ImageComponent>> mImageComponents; std::vector<std::unique_ptr<ImageComponent>> mImageComponents;
std::vector<std::unique_ptr<VideoFFmpegComponent>> mVideoComponents; std::vector<std::unique_ptr<VideoFFmpegComponent>> mVideoComponents;
std::vector<std::unique_ptr<LottieComponent>> mLottieAnimComponents; std::vector<std::unique_ptr<LottieAnimComponent>> mLottieAnimComponents;
std::vector<std::unique_ptr<BadgeComponent>> mBadgeComponents; std::vector<std::unique_ptr<BadgeComponent>> mBadgeComponents;
std::vector<std::unique_ptr<RatingComponent>> mRatingComponents; std::vector<std::unique_ptr<RatingComponent>> mRatingComponents;
std::vector<std::unique_ptr<ScrollableContainer>> mContainerComponents; std::vector<std::unique_ptr<ScrollableContainer>> mContainerComponents;

View file

@ -429,7 +429,7 @@ void SystemView::populate()
} }
else if (element.second.type == "animation") { else if (element.second.type == "animation") {
elements.lottieAnimComponents.emplace_back( elements.lottieAnimComponents.emplace_back(
std::make_unique<LottieComponent>()); std::make_unique<LottieAnimComponent>());
elements.lottieAnimComponents.back()->setDefaultZIndex(35.0f); elements.lottieAnimComponents.back()->setDefaultZIndex(35.0f);
elements.lottieAnimComponents.back()->applyTheme( elements.lottieAnimComponents.back()->applyTheme(
theme, "system", element.first, ThemeFlags::ALL); theme, "system", element.first, ThemeFlags::ALL);

View file

@ -16,7 +16,7 @@
#include "components/CarouselComponent.h" #include "components/CarouselComponent.h"
#include "components/DateTimeComponent.h" #include "components/DateTimeComponent.h"
#include "components/GameSelectorComponent.h" #include "components/GameSelectorComponent.h"
#include "components/LottieComponent.h" #include "components/LottieAnimComponent.h"
#include "components/TextComponent.h" #include "components/TextComponent.h"
#include "components/TextListComponent.h" #include "components/TextListComponent.h"
#include "components/VideoFFmpegComponent.h" #include "components/VideoFFmpegComponent.h"
@ -38,7 +38,7 @@ struct SystemViewElements {
std::vector<std::unique_ptr<DateTimeComponent>> dateTimeComponents; std::vector<std::unique_ptr<DateTimeComponent>> dateTimeComponents;
std::vector<std::unique_ptr<ImageComponent>> imageComponents; std::vector<std::unique_ptr<ImageComponent>> imageComponents;
std::vector<std::unique_ptr<VideoFFmpegComponent>> videoComponents; std::vector<std::unique_ptr<VideoFFmpegComponent>> videoComponents;
std::vector<std::unique_ptr<LottieComponent>> lottieAnimComponents; std::vector<std::unique_ptr<LottieAnimComponent>> lottieAnimComponents;
}; };
class SystemView : public GuiComponent class SystemView : public GuiComponent

View file

@ -48,7 +48,7 @@ set(CORE_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/src/components/IList.h ${CMAKE_CURRENT_SOURCE_DIR}/src/components/IList.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ImageComponent.h ${CMAKE_CURRENT_SOURCE_DIR}/src/components/ImageComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ImageGridComponent.h ${CMAKE_CURRENT_SOURCE_DIR}/src/components/ImageGridComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/LottieComponent.h ${CMAKE_CURRENT_SOURCE_DIR}/src/components/LottieAnimComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/MenuComponent.h ${CMAKE_CURRENT_SOURCE_DIR}/src/components/MenuComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/NinePatchComponent.h ${CMAKE_CURRENT_SOURCE_DIR}/src/components/NinePatchComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/OptionListComponent.h ${CMAKE_CURRENT_SOURCE_DIR}/src/components/OptionListComponent.h
@ -125,7 +125,7 @@ set(CORE_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/components/GridTileComponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/GridTileComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/HelpComponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/HelpComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/ImageComponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/ImageComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/LottieComponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/LottieAnimComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/MenuComponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/MenuComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/NinePatchComponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/NinePatchComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/RatingComponent.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/components/RatingComponent.cpp

View file

@ -13,7 +13,7 @@
#include "Log.h" #include "Log.h"
#include "Settings.h" #include "Settings.h"
#include "components/ImageComponent.h" #include "components/ImageComponent.h"
#include "components/LottieComponent.h" #include "components/LottieAnimComponent.h"
#include "components/TextComponent.h" #include "components/TextComponent.h"
#include "utils/FileSystemUtil.h" #include "utils/FileSystemUtil.h"
#include "utils/StringUtil.h" #include "utils/StringUtil.h"
@ -462,7 +462,7 @@ std::vector<GuiComponent*> ThemeData::makeExtras(const std::shared_ptr<ThemeData
else if (t == "text") else if (t == "text")
comp = new TextComponent; comp = new TextComponent;
else if (t == "animation") else if (t == "animation")
comp = new LottieComponent; comp = new LottieAnimComponent;
if (comp) { if (comp) {
comp->setDefaultZIndex(10.0f); comp->setDefaultZIndex(10.0f);

View file

@ -1,14 +1,14 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // EmulationStation Desktop Edition
// LottieComponent.cpp // LottieAnimComponent.cpp
// //
// Component to play Lottie animations using the rlottie library. // Component to play Lottie animations using the rlottie library.
// //
#define DEBUG_ANIMATION false #define DEBUG_ANIMATION false
#include "components/LottieComponent.h" #include "components/LottieAnimComponent.h"
#include "Log.h" #include "Log.h"
#include "ThemeData.h" #include "ThemeData.h"
@ -18,7 +18,7 @@
#include <chrono> #include <chrono>
LottieComponent::LottieComponent() LottieAnimComponent::LottieAnimComponent()
: mCacheFrames {true} : mCacheFrames {true}
, mMaxCacheSize {0} , mMaxCacheSize {0}
, mCacheSize {0} , mCacheSize {0}
@ -67,7 +67,7 @@ LottieComponent::LottieComponent()
setZIndex(10.0f); setZIndex(10.0f);
} }
LottieComponent::~LottieComponent() LottieAnimComponent::~LottieAnimComponent()
{ {
// This is required as rlottie could otherwise crash on application shutdown. // This is required as rlottie could otherwise crash on application shutdown.
if (mFuture.valid()) if (mFuture.valid())
@ -76,7 +76,7 @@ LottieComponent::~LottieComponent()
mTotalFrameCache -= mCacheSize; mTotalFrameCache -= mCacheSize;
} }
void LottieComponent::setAnimation(const std::string& path) void LottieAnimComponent::setAnimation(const std::string& path)
{ {
if (mAnimation != nullptr) { if (mAnimation != nullptr) {
if (mFuture.valid()) if (mFuture.valid())
@ -113,7 +113,7 @@ void LottieComponent::setAnimation(const std::string& path)
} }
if (!mKeepAspectRatio && (mSize.x == 0.0f || mSize.y == 0.0f)) { if (!mKeepAspectRatio && (mSize.x == 0.0f || mSize.y == 0.0f)) {
LOG(LogWarning) << "LottieComponent: Width or height auto sizing is incompatible with " LOG(LogWarning) << "LottieAnimComponent: Width or height auto sizing is incompatible with "
"disabling of <keepAspectRatio> so ignoring this setting"; "disabling of <keepAspectRatio> so ignoring this setting";
} }
@ -167,29 +167,29 @@ void LottieComponent::setAnimation(const std::string& path)
mFrameNum = mTotalFrames - 1; mFrameNum = mTotalFrames - 1;
if (DEBUG_ANIMATION) { if (DEBUG_ANIMATION) {
LOG(LogDebug) << "LottieComponent::setAnimation(): Rasterized width: " << mSize.x; LOG(LogDebug) << "LottieAnimComponent::setAnimation(): Rasterized width: " << mSize.x;
LOG(LogDebug) << "LottieComponent::setAnimation(): Rasterized height: " << mSize.y; LOG(LogDebug) << "LottieAnimComponent::setAnimation(): Rasterized height: " << mSize.y;
LOG(LogDebug) << "LottieComponent::setAnimation(): Total number of frames: " LOG(LogDebug) << "LottieAnimComponent::setAnimation(): Total number of frames: "
<< mTotalFrames; << mTotalFrames;
LOG(LogDebug) << "LottieComponent::setAnimation(): Frame rate: " << mFrameRate; LOG(LogDebug) << "LottieAnimComponent::setAnimation(): Frame rate: " << mFrameRate;
LOG(LogDebug) << "LottieComponent::setAnimation(): Speed modifier: " << mSpeedModifier; LOG(LogDebug) << "LottieAnimComponent::setAnimation(): Speed modifier: " << mSpeedModifier;
LOG(LogDebug) << "LottieComponent::setAnimation(): Target duration: " LOG(LogDebug) << "LottieAnimComponent::setAnimation(): Target duration: "
<< duration / mSpeedModifier * 1000.0 << " ms"; << duration / mSpeedModifier * 1000.0 << " ms";
LOG(LogDebug) << "LottieComponent::setAnimation(): Frame size: " << mFrameSize << " bytes (" LOG(LogDebug) << "LottieAnimComponent::setAnimation(): Frame size: " << mFrameSize
<< std::fixed << std::setprecision(1) << " bytes (" << std::fixed << std::setprecision(1)
<< static_cast<double>(mFrameSize) / 1024.0 / 1024.0 << " MiB)"; << static_cast<double>(mFrameSize) / 1024.0 / 1024.0 << " MiB)";
LOG(LogDebug) << "LottieComponent::setAnimation(): Animation size: " LOG(LogDebug) << "LottieAnimComponent::setAnimation(): Animation size: "
<< mFrameSize * mTotalFrames << " bytes (" << std::fixed << mFrameSize * mTotalFrames << " bytes (" << std::fixed
<< std::setprecision(1) << std::setprecision(1)
<< static_cast<double>(mFrameSize * mTotalFrames) / 1024.0 / 1024.0 << static_cast<double>(mFrameSize * mTotalFrames) / 1024.0 / 1024.0
<< " MiB)"; << " MiB)";
LOG(LogDebug) << "LottieComponent::setAnimation(): Per file maximum cache size: " LOG(LogDebug) << "LottieAnimComponent::setAnimation(): Per file maximum cache size: "
<< mMaxCacheSize << " bytes (" << std::fixed << std::setprecision(1) << mMaxCacheSize << " bytes (" << std::fixed << std::setprecision(1)
<< static_cast<double>(mMaxCacheSize) / 1024.0 / 1024.0 << " MiB)"; << static_cast<double>(mMaxCacheSize) / 1024.0 / 1024.0 << " MiB)";
} }
} }
void LottieComponent::resetFileAnimation() void LottieAnimComponent::resetFileAnimation()
{ {
mExternalPause = false; mExternalPause = false;
mTimeAccumulator = 0; mTimeAccumulator = 0;
@ -203,17 +203,17 @@ void LottieComponent::resetFileAnimation()
} }
} }
void LottieComponent::onSizeChanged() void LottieAnimComponent::onSizeChanged()
{ {
// Setting the animation again will completely reinitialize it. // Setting the animation again will completely reinitialize it.
if (mPath != "") if (mPath != "")
setAnimation(mPath); setAnimation(mPath);
} }
void LottieComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, void LottieAnimComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
const std::string& view, const std::string& view,
const std::string& element, const std::string& element,
unsigned int properties) unsigned int properties)
{ {
using namespace ThemeFlags; using namespace ThemeFlags;
const ThemeData::ThemeElement* elem {theme->getElement(view, element, "animation")}; const ThemeData::ThemeElement* elem {theme->getElement(view, element, "animation")};
@ -221,7 +221,7 @@ void LottieComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (elem->has("size")) { if (elem->has("size")) {
glm::vec2 size = elem->get<glm::vec2>("size"); glm::vec2 size = elem->get<glm::vec2>("size");
if (size.x == 0.0f && size.y == 0.0f) { if (size.x == 0.0f && size.y == 0.0f) {
LOG(LogWarning) << "LottieComponent: Invalid theme configuration, <size> set to \"" LOG(LogWarning) << "LottieAnimComponent: Invalid theme configuration, <size> set to \""
<< size.x << " " << size.y << "\""; << size.x << " " << size.y << "\"";
return; return;
} }
@ -230,7 +230,7 @@ void LottieComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (elem->has("speed")) { if (elem->has("speed")) {
const float speed {elem->get<float>("speed")}; const float speed {elem->get<float>("speed")};
if (speed < 0.2f || speed > 3.0f) { if (speed < 0.2f || speed > 3.0f) {
LOG(LogWarning) << "LottieComponent: Invalid theme configuration, <speed> set to \"" LOG(LogWarning) << "LottieAnimComponent: Invalid theme configuration, <speed> set to \""
<< std::fixed << std::setprecision(1) << speed << "\""; << std::fixed << std::setprecision(1) << speed << "\"";
} }
else { else {
@ -261,8 +261,9 @@ void LottieComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
mAlternate = true; mAlternate = true;
} }
else { else {
LOG(LogWarning) << "LottieComponent: Invalid theme configuration, <direction> set to \"" LOG(LogWarning)
<< direction << "\""; << "LottieAnimComponent: Invalid theme configuration, <direction> set to \""
<< direction << "\"";
mStartDirection = "normal"; mStartDirection = "normal";
mAlternate = false; mAlternate = false;
} }
@ -277,12 +278,12 @@ void LottieComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
} }
} }
else { else {
LOG(LogWarning) << "LottieComponent: Invalid theme configuration, <path> not set"; LOG(LogWarning) << "LottieAnimComponent: Invalid theme configuration, <path> not set";
return; return;
} }
} }
void LottieComponent::update(int deltaTime) void LottieAnimComponent::update(int deltaTime)
{ {
if (mAnimation == nullptr) if (mAnimation == nullptr)
return; return;
@ -315,9 +316,9 @@ void LottieComponent::update(int deltaTime)
// Rudimentary frame skipping logic, not entirely accurate but probably good enough. // Rudimentary frame skipping logic, not entirely accurate but probably good enough.
while (mTimeAccumulator - deltaTime > mTargetPacing) { while (mTimeAccumulator - deltaTime > mTargetPacing) {
if (DEBUG_ANIMATION && 0) { if (DEBUG_ANIMATION && 0) {
LOG(LogDebug) LOG(LogDebug) << "LottieAnimComponent::update(): Skipped frame, mTimeAccumulator / "
<< "LottieComponent::update(): Skipped frame, mTimeAccumulator / mTargetPacing: " "mTargetPacing: "
<< mTimeAccumulator - deltaTime << " / " << mTargetPacing; << mTimeAccumulator - deltaTime << " / " << mTargetPacing;
} }
if (mDirection == "reverse") if (mDirection == "reverse")
@ -330,7 +331,7 @@ void LottieComponent::update(int deltaTime)
} }
} }
void LottieComponent::render(const glm::mat4& parentTrans) void LottieAnimComponent::render(const glm::mat4& parentTrans)
{ {
if (!isVisible() || mThemeOpacity == 0.0f || mAnimation == nullptr) if (!isVisible() || mThemeOpacity == 0.0f || mAnimation == nullptr)
return; return;
@ -358,8 +359,9 @@ void LottieComponent::render(const glm::mat4& parentTrans)
if ((mDirection == "normal" && mFrameNum >= mTotalFrames) || if ((mDirection == "normal" && mFrameNum >= mTotalFrames) ||
(mDirection == "reverse" && mFrameNum > mTotalFrames)) { (mDirection == "reverse" && mFrameNum > mTotalFrames)) {
if (DEBUG_ANIMATION) { if (DEBUG_ANIMATION) {
LOG(LogDebug) << "LottieComponent::render(): Skipped frames: " << mSkippedFrames; LOG(LogDebug) << "LottieAnimComponent::render(): Skipped frames: "
LOG(LogDebug) << "LottieComponent::render(): Actual duration: " << mSkippedFrames;
LOG(LogDebug) << "LottieAnimComponent::render(): Actual duration: "
<< std::chrono::duration_cast<std::chrono::milliseconds>( << std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now() - mAnimationStartTime) std::chrono::system_clock::now() - mAnimationStartTime)
.count() .count()

View file

@ -1,13 +1,13 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// //
// EmulationStation Desktop Edition // EmulationStation Desktop Edition
// LottieComponent.h // LottieAnimComponent.h
// //
// Component to play Lottie animations using the rlottie library. // Component to play Lottie animations using the rlottie library.
// //
#ifndef ES_CORE_COMPONENTS_LOTTIE_COMPONENT_H #ifndef ES_CORE_COMPONENTS_LOTTIE_ANIM_COMPONENT_H
#define ES_CORE_COMPONENTS_LOTTIE_COMPONENT_H #define ES_CORE_COMPONENTS_LOTTIE_ANIM_COMPONENT_H
#include "GuiComponent.h" #include "GuiComponent.h"
#include "renderers/Renderer.h" #include "renderers/Renderer.h"
@ -20,11 +20,11 @@
#include <future> #include <future>
#include <unordered_map> #include <unordered_map>
class LottieComponent : public GuiComponent class LottieAnimComponent : public GuiComponent
{ {
public: public:
LottieComponent(); LottieAnimComponent();
~LottieComponent(); ~LottieAnimComponent();
void setAnimation(const std::string& path); void setAnimation(const std::string& path);
void setKeepAspectRatio(bool value) { mKeepAspectRatio = value; } void setKeepAspectRatio(bool value) { mKeepAspectRatio = value; }
@ -83,4 +83,4 @@ private:
bool mKeepAspectRatio; bool mKeepAspectRatio;
}; };
#endif // ES_CORE_COMPONENTS_LOTTIE_COMPONENT_H #endif // ES_CORE_COMPONENTS_LOTTIE_ANIM_COMPONENT_H