From: subhransu mohanty Date: Tue, 28 Aug 2018 06:14:24 +0000 (+0900) Subject: lottie/vector: refactor VPathMesure to handle offset . X-Git-Tag: submit/tizen/20180917.042405~57 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c87e3933080210f72619bd1e143c1f31db0fa80a;p=platform%2Fcore%2Fuifw%2Flottie-player.git lottie/vector: refactor VPathMesure to handle offset . Change-Id: Ic84c63376c52167ee2ae88d363bf22aadf4fbca9 --- diff --git a/src/lottie/lottieitem.cpp b/src/lottie/lottieitem.cpp index 992009b..0681437 100644 --- a/src/lottie/lottieitem.cpp +++ b/src/lottie/lottieitem.cpp @@ -958,7 +958,9 @@ void LOTTrimItem::update() //@TODO take the offset and trim type into account. for (auto &i : mPathItems) { VPathMesure pm; - pm.setOffset(mCache.mStart, mCache.mEnd); + pm.setStart(mCache.mStart); + pm.setEnd(mCache.mEnd); + pm.setOffset(mCache.mOffset); i->updatePath(pm.trim(i->localPath())); } } diff --git a/src/lottie/lottiemodel.h b/src/lottie/lottiemodel.h index 165a502..85e5077 100644 --- a/src/lottie/lottiemodel.h +++ b/src/lottie/lottiemodel.h @@ -656,7 +656,7 @@ public: {visitor->visit(this);} float start(int frameNo) const {return mStart.value(frameNo)/100.0f;} float end(int frameNo) const {return mEnd.value(frameNo)/100.0f;} - float offset(int frameNo) const {return mOffset.value(frameNo)/100.0f;} + float offset(int frameNo) const {return mOffset.value(frameNo);} LOTTrimData::TrimType type() const {return mTrimType;} public: LOTAnimatable mStart{0}; diff --git a/src/vector/vpathmesure.cpp b/src/vector/vpathmesure.cpp index 5e93f8f..05c61b6 100644 --- a/src/vector/vpathmesure.cpp +++ b/src/vector/vpathmesure.cpp @@ -4,25 +4,58 @@ V_BEGIN_NAMESPACE -void VPathMesure::setOffset(float sp, float ep) +VPath oneSegment(float start, float end, const VPath & path) { - startOffset = sp; - endOffset = ep; + if (start > end) { + std::swap(start, end); + } + float array[5] = {0.0f, start, end - start, 1000, 0.0f}; + VDasher dasher(array, 5); + return dasher.dashed(path); } VPath VPathMesure::trim(const VPath &path) { - if (vCompare(startOffset, 0.0f) && (vCompare(endOffset, 1.0f))) return path; + if (vCompare(mStart, mEnd)) return VPath(); - float len = path.length(); - float sg = len * startOffset; - float eg = len * (1.0f - endOffset); - len = len - (sg + eg); + if ((vCompare(mStart, 0.0f) && (vCompare(mEnd, 1.0f))) || + (vCompare(mStart, 1.0f) && (vCompare(mEnd, 0.0f)))) return path; - float array[5] = {0.0f, sg, len, 1000, 0.0f}; - VDasher dasher(array, 5); + if (vIsZero(mOffset)) { + float length = path.length(); + return oneSegment(length * mStart, length * mEnd, path); + } else { + float length = path.length(); + float offset = fmod(mOffset, length); + float start = length * mStart; + float end = length * mEnd; + start += offset; + end +=offset; - return dasher.dashed(path); + if (start < 0 && end < 0) { + return oneSegment(length + start, length + end, path); + } else if (start > 0 && end > 0) { + if (start > length && end > length) + return oneSegment(start - length, end - length, path); + else if (start < length && end < length) + return oneSegment(start, end, path); + else { + float len1 = start > end ? start - length : end - length; + float start2 = start < end ? start : end; + float gap1 = start2 - len1; + float array[5] = {len1, gap1, length - start2, 1000, 0.0f}; + VDasher dasher(array, 5); + return dasher.dashed(path); + } + } else { + float len1 = start > end ? start : end; + float start2 = start < end ? length + start : length + end; + float gap1 = start2 - len1; + float array[5] = {len1, gap1, length - start2, 1000, 0.0f}; + VDasher dasher(array, 5); + return dasher.dashed(path); + } + } } V_END_NAMESPACE diff --git a/src/vector/vpathmesure.h b/src/vector/vpathmesure.h index 61b1d34..8202913 100644 --- a/src/vector/vpathmesure.h +++ b/src/vector/vpathmesure.h @@ -7,12 +7,14 @@ V_BEGIN_NAMESPACE class VPathMesure { public: - void setOffset(float sp, float ep); + void setStart(float start){mStart = start;} + void setEnd(float end){mEnd = end;} + void setOffset(float offset){mOffset = offset;} VPath trim(const VPath &path); - private: - float startOffset{0.0f}; - float endOffset{1.0f}; + float mStart{0.0f}; + float mEnd{1.0f}; + float mOffset{0.0f}; }; V_END_NAMESPACE