mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 20:14:37 +00:00
lottie: code refactoring.
keep the coding style.
This commit is contained in:
parent
0b5152f138
commit
026d85f6a8
4 changed files with 18 additions and 13 deletions
|
@ -38,6 +38,7 @@ LottieAnimation::~LottieAnimation()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Result LottieAnimation::override(const char* slot) noexcept
|
Result LottieAnimation::override(const char* slot) noexcept
|
||||||
{
|
{
|
||||||
if (!pImpl->picture->pImpl->loader) return Result::InsufficientCondition;
|
if (!pImpl->picture->pImpl->loader) return Result::InsufficientCondition;
|
||||||
|
@ -49,33 +50,34 @@ Result LottieAnimation::override(const char* slot) noexcept
|
||||||
return Result::InvalidArguments;
|
return Result::InvalidArguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Result LottieAnimation::segment(const char* marker) noexcept
|
Result LottieAnimation::segment(const char* marker) noexcept
|
||||||
{
|
{
|
||||||
auto loader = pImpl->picture->pImpl->loader;
|
auto loader = pImpl->picture->pImpl->loader;
|
||||||
if (!loader) return Result::InsufficientCondition;
|
if (!loader) return Result::InsufficientCondition;
|
||||||
if (!loader->animatable()) return Result::NonSupport;
|
if (!loader->animatable()) return Result::NonSupport;
|
||||||
|
|
||||||
auto lottieLoader = static_cast<LottieLoader*>(loader);
|
|
||||||
|
|
||||||
if (!marker) {
|
if (!marker) {
|
||||||
lottieLoader->segment(0.0, 1.0);
|
static_cast<FrameModule*>(loader)->segment(0.0f, 1.0f);
|
||||||
return Result::Success;
|
return Result::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
float begin, end;
|
float begin, end;
|
||||||
if (!lottieLoader->getSegment(begin, end, marker)) {
|
if (!static_cast<LottieLoader*>(loader)->segment(marker, begin, end)) {
|
||||||
return Result::InvalidArguments;
|
return Result::InvalidArguments;
|
||||||
}
|
}
|
||||||
return static_cast<Animation*>(this)->segment(begin, end);
|
return static_cast<Animation*>(this)->segment(begin, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint32_t LottieAnimation::markersCnt() noexcept
|
uint32_t LottieAnimation::markersCnt() noexcept
|
||||||
{
|
{
|
||||||
auto loader = pImpl->picture->pImpl->loader;
|
auto loader = pImpl->picture->pImpl->loader;
|
||||||
if (!loader || !loader->animatable()) return 0;
|
if (!loader || !loader->animatable()) return 0;
|
||||||
return static_cast<LottieLoader*>(loader)->markerCount();
|
return static_cast<LottieLoader*>(loader)->markersCnt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char* LottieAnimation::marker(uint32_t idx) noexcept
|
const char* LottieAnimation::marker(uint32_t idx) noexcept
|
||||||
{
|
{
|
||||||
auto loader = pImpl->picture->pImpl->loader;
|
auto loader = pImpl->picture->pImpl->loader;
|
||||||
|
@ -83,6 +85,7 @@ const char* LottieAnimation::marker(uint32_t idx) noexcept
|
||||||
return static_cast<LottieLoader*>(loader)->markers(idx);
|
return static_cast<LottieLoader*>(loader)->markers(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unique_ptr<LottieAnimation> LottieAnimation::gen() noexcept
|
unique_ptr<LottieAnimation> LottieAnimation::gen() noexcept
|
||||||
{
|
{
|
||||||
return unique_ptr<LottieAnimation>(new LottieAnimation);
|
return unique_ptr<LottieAnimation>(new LottieAnimation);
|
||||||
|
|
|
@ -359,7 +359,7 @@ void LottieLoader::sync()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint32_t LottieLoader::markerCount()
|
uint32_t LottieLoader::markersCnt()
|
||||||
{
|
{
|
||||||
if (!comp) done();
|
if (!comp) done();
|
||||||
return comp->markers.count;
|
return comp->markers.count;
|
||||||
|
@ -369,13 +369,13 @@ uint32_t LottieLoader::markerCount()
|
||||||
const char* LottieLoader::markers(uint32_t index)
|
const char* LottieLoader::markers(uint32_t index)
|
||||||
{
|
{
|
||||||
if (!comp) done();
|
if (!comp) done();
|
||||||
if (index < 0 || index >= markerCount()) return nullptr;
|
if (index < 0 || index >= markersCnt()) return nullptr;
|
||||||
auto marker = comp->markers.begin() + index;
|
auto marker = comp->markers.begin() + index;
|
||||||
return (*marker)->name;
|
return (*marker)->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool LottieLoader::getSegment(float& begin, float& end, const char* marker)
|
bool LottieLoader::segment(const char* marker, float& begin, float& end)
|
||||||
{
|
{
|
||||||
if (!comp) done();
|
if (!comp) done();
|
||||||
|
|
||||||
|
|
|
@ -64,9 +64,9 @@ public:
|
||||||
void sync() override;
|
void sync() override;
|
||||||
|
|
||||||
//Marker Supports
|
//Marker Supports
|
||||||
uint32_t markerCount();
|
uint32_t markersCnt();
|
||||||
const char* markers(uint32_t index);
|
const char* markers(uint32_t index);
|
||||||
bool getSegment(float& beign, float& end, const char* marker);
|
bool segment(const char* marker, float& beign, float& end);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool header();
|
bool header();
|
||||||
|
|
|
@ -42,12 +42,14 @@ public:
|
||||||
virtual float curFrame() = 0; //return the current frame number
|
virtual float curFrame() = 0; //return the current frame number
|
||||||
virtual float duration() = 0; //return the animation duration in seconds
|
virtual float duration() = 0; //return the animation duration in seconds
|
||||||
|
|
||||||
void segment(float* begin, float* end) {
|
void segment(float* begin, float* end)
|
||||||
|
{
|
||||||
if (begin) *begin = segmentBegin;
|
if (begin) *begin = segmentBegin;
|
||||||
if (end) *end = segmentEnd;
|
if (end) *end = segmentEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void segment(float begin, float end) {
|
void segment(float begin, float end)
|
||||||
|
{
|
||||||
segmentBegin = begin;
|
segmentBegin = begin;
|
||||||
segmentEnd = end;
|
segmentEnd = end;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue