From: Subhransu Mohanty Date: Wed, 8 Jul 2020 04:50:50 +0000 (+0900) Subject: lottie/model: refactor code to remove LOTAnimatableShape class X-Git-Tag: submit/tizen/20200713.050659~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e3a63391579d82af5a18522812b5e15e23cfcb1c;p=platform%2Fcore%2Fuifw%2Flottie-player.git lottie/model: refactor code to remove LOTAnimatableShape class --- diff --git a/src/lottie/lottieitem.cpp b/src/lottie/lottieitem.cpp index 4791d4f..a017e47 100644 --- a/src/lottie/lottieitem.cpp +++ b/src/lottie/lottieitem.cpp @@ -169,10 +169,10 @@ void LOTMaskItem::update(int frameNo, const VMatrix & parentMatrix, if (mData->mShape.isStatic()) { if (mLocalPath.empty()) { - mData->mShape.updatePath(frameNo, mLocalPath); + mData->mShape.value(frameNo, mLocalPath); } } else { - mData->mShape.updatePath(frameNo, mLocalPath); + mData->mShape.value(frameNo, mLocalPath); } /* mask item dosen't inherit opacity */ mCombinedAlpha = mData->opacity(frameNo); @@ -1104,7 +1104,7 @@ LOTShapeItem::LOTShapeItem(LOTShapeData *data) void LOTShapeItem::updatePath(VPath &path, int frameNo) { - mData->mShape.updatePath(frameNo, path); + mData->mShape.value(frameNo, path); } LOTPolystarItem::LOTPolystarItem(LOTPolystarData *data) diff --git a/src/lottie/lottiemodel.h b/src/lottie/lottiemodel.h index c61c920..55d94a1 100644 --- a/src/lottie/lottiemodel.h +++ b/src/lottie/lottiemodel.h @@ -1,16 +1,16 @@ -/* +/* * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA @@ -325,6 +325,30 @@ public: return isStatic() ? value() : animation().value(frameNo); } + // special function only for type T=LottieShapeData + template + auto value(int frameNo, VPath& path) const-> typename std::enable_if_t::value, void> + { + if (isStatic()) { + value().toPath(path); + } else { + const auto &vec = animation().mKeyFrames; + if (vec.front().mStartFrame >= frameNo) + return vec.front().mValue.mStartValue.toPath(path); + if(vec.back().mEndFrame <= frameNo) + return vec.back().mValue.mEndValue.toPath(path); + + for(const auto &keyFrame : vec) { + if (frameNo >= keyFrame.mStartFrame && frameNo < keyFrame.mEndFrame) { + LottieShapeData::lerp(keyFrame.mValue.mStartValue, + keyFrame.mValue.mEndValue, + keyFrame.progress(frameNo), + path); + } + } + } + } + float angle(int frameNo) const { return isStatic() ? 0 : animation().angle(frameNo); } @@ -360,33 +384,6 @@ private: bool mStatic{true}; }; - -class LOTAnimatableShape : public LOTAnimatable -{ -public: - void updatePath(int frameNo, VPath &path) const { - if (isStatic()) { - value().toPath(path); - } else { - const auto &vec = animation().mKeyFrames; - if (vec.front().mStartFrame >= frameNo) - return vec.front().mValue.mStartValue.toPath(path); - if(vec.back().mEndFrame <= frameNo) - return vec.back().mValue.mEndValue.toPath(path); - - for(const auto &keyFrame : vec) { - if (frameNo >= keyFrame.mStartFrame && frameNo < keyFrame.mEndFrame) { - LottieShapeData::lerp(keyFrame.mValue.mStartValue, - keyFrame.mValue.mEndValue, - keyFrame.progress(frameNo), - path); - } - } - } - } -}; - - enum class LottieBlendMode: uchar { Normal = 0, @@ -896,7 +893,7 @@ class LOTShapeData : public LOTPath public: LOTShapeData():LOTPath(LOTData::Type::Shape){} public: - LOTAnimatableShape mShape; + LOTAnimatable mShape; }; class LOTMaskData @@ -912,7 +909,7 @@ public: float opacity(int frameNo) const {return mOpacity.value(frameNo)/100.0f;} bool isStatic() const {return mIsStatic;} public: - LOTAnimatableShape mShape; + LOTAnimatable mShape; LOTAnimatable mOpacity{100}; bool mInv{false}; bool mIsStatic{true};