diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2019-04-05 22:04:38 +0300 |
---|---|---|
committer | Rebecca Worledge <rebecca.worledge@theqtcompany.com> | 2019-04-06 04:01:21 +0000 |
commit | 9b332f6533fdbfd73326782fb7dd47c2377a9f73 (patch) | |
tree | 3738b770e45710fa86e08909c01363cfecf55cec | |
parent | 16b32a004e8a5df6df3cb83b3e206faa25428b10 (diff) |
LottieAnimation: make Direction enum reflect the actual step value
which allows to simplify the code
Change-Id: I2430fac6fc5fef11ae2a0e889670cd69a1a28307
Reviewed-by: Rebecca Worledge <rebecca.worledge@theqtcompany.com>
-rw-r--r-- | src/imports/lottieanimation.cpp | 23 | ||||
-rw-r--r-- | src/imports/lottieanimation.h | 4 | ||||
-rw-r--r-- | src/imports/rasterrenderer/batchrenderer.cpp | 4 |
3 files changed, 10 insertions, 21 deletions
diff --git a/src/imports/lottieanimation.cpp b/src/imports/lottieanimation.cpp index 5477bdf..931a9c0 100644 --- a/src/imports/lottieanimation.cpp +++ b/src/imports/lottieanimation.cpp @@ -539,25 +539,16 @@ double LottieAnimation::getDuration(bool inFrames) */ LottieAnimation::Direction LottieAnimation::direction() const { - if (m_direction < 0) - return Reverse; - else if (m_direction > 0) - return Forward; - else { - Q_UNREACHABLE(); - return Forward; - } + return static_cast<Direction>(m_direction); } -void LottieAnimation::setDirection(Direction direction) +void LottieAnimation::setDirection(LottieAnimation::Direction direction) { - if (direction == Forward) { - m_direction = 1; - emit directionChanged(); - } else if (direction == Reverse) { - m_direction = -1; - emit directionChanged(); - } + if (Q_UNLIKELY(static_cast<Direction>(m_direction) == direction)) + return; + + m_direction = direction; + emit directionChanged(); } bool LottieAnimation::loadSource(QString filename) diff --git a/src/imports/lottieanimation.h b/src/imports/lottieanimation.h index a1cc41d..96ec348 100644 --- a/src/imports/lottieanimation.h +++ b/src/imports/lottieanimation.h @@ -65,7 +65,7 @@ public: enum Quality{LowQuality, MediumQuality, HighQuality}; Q_ENUM(Quality) - enum Direction{Forward = 1, Reverse}; + enum Direction{Forward = 1, Reverse = -1}; Q_ENUM(Direction) enum LoopCount{Infinite = -1}; @@ -152,7 +152,7 @@ private: bool m_autoPlay = true; int m_loops = 1; int m_currentLoop = 0; - int m_direction = 1; + int m_direction = Forward; QByteArray m_jsonSource; }; diff --git a/src/imports/rasterrenderer/batchrenderer.cpp b/src/imports/rasterrenderer/batchrenderer.cpp index 39745f3..f14eec1 100644 --- a/src/imports/rasterrenderer/batchrenderer.cpp +++ b/src/imports/rasterrenderer/batchrenderer.cpp @@ -84,9 +84,7 @@ void BatchRenderer::registerAnimator(LottieAnimation *animator) entry->startFrame = animator->startFrame(); entry->endFrame = animator->endFrame(); entry->currentFrame = animator->startFrame(); - if (animator->direction() == LottieAnimation::Reverse) - entry->animDir = -1; - // animDir == 1 by default + entry->animDir = animator->direction(); entry->bmTreeBlueprint = new BMBase; parse(entry->bmTreeBlueprint, animator->jsonSource()); m_animData.insert(animator, entry); |