From 4319d38de8726632b11eebf38cdb3c076664d9b9 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Mon, 15 Apr 2024 00:06:16 +0900 Subject: [PATCH] lottie: code refactoring. keep the coding style. --- src/loaders/lottie/tvgLottieAnimation.cpp | 15 +++++++++------ src/loaders/lottie/tvgLottieLoader.cpp | 6 +++--- src/loaders/lottie/tvgLottieLoader.h | 4 ++-- src/renderer/tvgFrameModule.h | 6 ++++-- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/loaders/lottie/tvgLottieAnimation.cpp b/src/loaders/lottie/tvgLottieAnimation.cpp index 636fc377..9f165b51 100644 --- a/src/loaders/lottie/tvgLottieAnimation.cpp +++ b/src/loaders/lottie/tvgLottieAnimation.cpp @@ -38,6 +38,7 @@ LottieAnimation::~LottieAnimation() { } + Result LottieAnimation::override(const char* slot) noexcept { if (!pImpl->picture->pImpl->loader) return Result::InsufficientCondition; @@ -49,33 +50,34 @@ Result LottieAnimation::override(const char* slot) noexcept return Result::InvalidArguments; } + Result LottieAnimation::segment(const char* marker) noexcept { auto loader = pImpl->picture->pImpl->loader; if (!loader) return Result::InsufficientCondition; if (!loader->animatable()) return Result::NonSupport; - - auto lottieLoader = static_cast(loader); - + if (!marker) { - lottieLoader->segment(0.0, 1.0); + static_cast(loader)->segment(0.0f, 1.0f); return Result::Success; } float begin, end; - if (!lottieLoader->getSegment(begin, end, marker)) { + if (!static_cast(loader)->segment(marker, begin, end)) { return Result::InvalidArguments; } return static_cast(this)->segment(begin, end); } + uint32_t LottieAnimation::markersCnt() noexcept { auto loader = pImpl->picture->pImpl->loader; if (!loader || !loader->animatable()) return 0; - return static_cast(loader)->markerCount(); + return static_cast(loader)->markersCnt(); } + const char* LottieAnimation::marker(uint32_t idx) noexcept { auto loader = pImpl->picture->pImpl->loader; @@ -83,6 +85,7 @@ const char* LottieAnimation::marker(uint32_t idx) noexcept return static_cast(loader)->markers(idx); } + unique_ptr LottieAnimation::gen() noexcept { return unique_ptr(new LottieAnimation); diff --git a/src/loaders/lottie/tvgLottieLoader.cpp b/src/loaders/lottie/tvgLottieLoader.cpp index d2f3face..1873871e 100644 --- a/src/loaders/lottie/tvgLottieLoader.cpp +++ b/src/loaders/lottie/tvgLottieLoader.cpp @@ -359,7 +359,7 @@ void LottieLoader::sync() } -uint32_t LottieLoader::markerCount() +uint32_t LottieLoader::markersCnt() { if (!comp) done(); return comp->markers.count; @@ -369,13 +369,13 @@ uint32_t LottieLoader::markerCount() const char* LottieLoader::markers(uint32_t index) { if (!comp) done(); - if (index < 0 || index >= markerCount()) return nullptr; + if (index < 0 || index >= markersCnt()) return nullptr; auto marker = comp->markers.begin() + index; 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(); diff --git a/src/loaders/lottie/tvgLottieLoader.h b/src/loaders/lottie/tvgLottieLoader.h index a23344a5..abffd1b3 100644 --- a/src/loaders/lottie/tvgLottieLoader.h +++ b/src/loaders/lottie/tvgLottieLoader.h @@ -64,9 +64,9 @@ public: void sync() override; //Marker Supports - uint32_t markerCount(); + uint32_t markersCnt(); 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: bool header(); diff --git a/src/renderer/tvgFrameModule.h b/src/renderer/tvgFrameModule.h index adca1ad9..37d01e05 100644 --- a/src/renderer/tvgFrameModule.h +++ b/src/renderer/tvgFrameModule.h @@ -42,12 +42,14 @@ public: virtual float curFrame() = 0; //return the current frame number 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 (end) *end = segmentEnd; } - void segment(float begin, float end) { + void segment(float begin, float end) + { segmentBegin = begin; segmentEnd = end; }