mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-01-17 22:55:38 +00:00
Added an iterationCount property to GIFAnimComponent and LottieAnimComponent.
This commit is contained in:
parent
b034fe61fe
commit
309e635be4
|
@ -360,6 +360,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
|
|||
{"path", PATH},
|
||||
{"speed", FLOAT},
|
||||
{"direction", STRING},
|
||||
{"iterationCount", UNSIGNED_INTEGER},
|
||||
{"interpolation", STRING},
|
||||
{"color", COLOR},
|
||||
{"colorEnd", COLOR},
|
||||
|
|
|
@ -42,6 +42,8 @@ GIFAnimComponent::GIFAnimComponent()
|
|||
, mPause {false}
|
||||
, mExternalPause {false}
|
||||
, mAlternate {false}
|
||||
, mIterationCount {0}
|
||||
, mPlayCount {0}
|
||||
, mTargetIsMax {false}
|
||||
, mColorShift {0xFFFFFFFF}
|
||||
, mColorShiftEnd {0xFFFFFFFF}
|
||||
|
@ -264,7 +266,9 @@ void GIFAnimComponent::setAnimation(const std::string& path)
|
|||
void GIFAnimComponent::resetFileAnimation()
|
||||
{
|
||||
mExternalPause = false;
|
||||
mPlayCount = 0;
|
||||
mTimeAccumulator = 0;
|
||||
mDirection = mStartDirection;
|
||||
mFrameNum = mStartDirection == "reverse" ? mTotalFrames - 1 : 0;
|
||||
|
||||
if (mAnimation != nullptr)
|
||||
|
@ -346,6 +350,12 @@ void GIFAnimComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
|
|||
}
|
||||
}
|
||||
|
||||
if (elem->has("iterationCount")) {
|
||||
mIterationCount = glm::clamp(elem->get<unsigned int>("iterationCount"), 0u, 10u);
|
||||
if (mAlternate)
|
||||
mIterationCount *= 2;
|
||||
}
|
||||
|
||||
if (elem->has("interpolation")) {
|
||||
const std::string& interpolation {elem->get<std::string>("interpolation")};
|
||||
if (interpolation == "linear") {
|
||||
|
@ -482,6 +492,7 @@ void GIFAnimComponent::render(const glm::mat4& parentTrans)
|
|||
|
||||
mTimeAccumulator = 0;
|
||||
mSkippedFrames = 0;
|
||||
++mPlayCount;
|
||||
|
||||
if (mDirection == "reverse" && mAlternate)
|
||||
mFrameNum = mTotalFrames - 2;
|
||||
|
@ -492,6 +503,12 @@ void GIFAnimComponent::render(const glm::mat4& parentTrans)
|
|||
else
|
||||
mFrameNum = 0;
|
||||
|
||||
if (mIterationCount != 0 && mPlayCount >= mIterationCount) {
|
||||
mPlayCount = 0;
|
||||
mExternalPause = true;
|
||||
mFrameNum = mTotalFrames;
|
||||
}
|
||||
|
||||
if (DEBUG_ANIMATION)
|
||||
mAnimationStartTime = std::chrono::system_clock::now();
|
||||
}
|
||||
|
|
|
@ -100,6 +100,8 @@ private:
|
|||
bool mPause;
|
||||
bool mExternalPause;
|
||||
bool mAlternate;
|
||||
int mIterationCount;
|
||||
int mPlayCount;
|
||||
bool mTargetIsMax;
|
||||
|
||||
unsigned int mColorShift;
|
||||
|
|
|
@ -37,6 +37,8 @@ LottieAnimComponent::LottieAnimComponent()
|
|||
, mPause {false}
|
||||
, mExternalPause {false}
|
||||
, mAlternate {false}
|
||||
, mIterationCount {0}
|
||||
, mPlayCount {0}
|
||||
, mTargetIsMax {false}
|
||||
, mColorShift {0xFFFFFFFF}
|
||||
, mColorShiftEnd {0xFFFFFFFF}
|
||||
|
@ -230,7 +232,9 @@ void LottieAnimComponent::setAnimation(const std::string& path)
|
|||
void LottieAnimComponent::resetFileAnimation()
|
||||
{
|
||||
mExternalPause = false;
|
||||
mPlayCount = 0;
|
||||
mTimeAccumulator = 0;
|
||||
mDirection = mStartDirection;
|
||||
mFrameNum = mStartDirection == "reverse" ? mTotalFrames - 1 : 0;
|
||||
|
||||
if (mAnimation != nullptr) {
|
||||
|
@ -316,6 +320,12 @@ void LottieAnimComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
|
|||
}
|
||||
}
|
||||
|
||||
if (elem->has("iterationCount")) {
|
||||
mIterationCount = glm::clamp(elem->get<unsigned int>("iterationCount"), 0u, 10u);
|
||||
if (mAlternate)
|
||||
mIterationCount *= 2;
|
||||
}
|
||||
|
||||
if (properties & COLOR) {
|
||||
if (elem->has("color")) {
|
||||
mColorShift = elem->get<unsigned int>("color");
|
||||
|
@ -437,6 +447,7 @@ void LottieAnimComponent::render(const glm::mat4& parentTrans)
|
|||
|
||||
mTimeAccumulator = 0;
|
||||
mSkippedFrames = 0;
|
||||
++mPlayCount;
|
||||
|
||||
if (mDirection == "reverse" && mAlternate)
|
||||
mFrameNum = mTotalFrames - 2;
|
||||
|
@ -447,6 +458,12 @@ void LottieAnimComponent::render(const glm::mat4& parentTrans)
|
|||
else
|
||||
mFrameNum = 0;
|
||||
|
||||
if (mIterationCount != 0 && mPlayCount >= mIterationCount) {
|
||||
mPlayCount = 0;
|
||||
mExternalPause = true;
|
||||
mFrameNum = mTotalFrames;
|
||||
}
|
||||
|
||||
if (DEBUG_ANIMATION)
|
||||
mAnimationStartTime = std::chrono::system_clock::now();
|
||||
}
|
||||
|
|
|
@ -86,6 +86,8 @@ private:
|
|||
bool mPause;
|
||||
bool mExternalPause;
|
||||
bool mAlternate;
|
||||
int mIterationCount;
|
||||
int mPlayCount;
|
||||
bool mTargetIsMax;
|
||||
|
||||
unsigned int mColorShift;
|
||||
|
|
Loading…
Reference in a new issue