From: Michal Szczecinski Date: Tue, 13 Aug 2024 23:13:47 +0000 (+0200) Subject: Added trim paths props X-Git-Tag: accepted/tizen/unified/20240821.081455^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Faccepted%2Ftizen_unified_dev;p=platform%2Fcore%2Fuifw%2Flottie-player.git Added trim paths props Change-Id: I1c2bc75078a22c105da496e1141d6f2d2e7794ae --- diff --git a/example/demo.cpp b/example/demo.cpp index fe31e28..4898081 100644 --- a/example/demo.cpp +++ b/example/demo.cpp @@ -207,6 +207,10 @@ public: return rlottie::Color(1, 0, 0); } }); + view8->player()->setValue("Shape Layer 2.Trim Paths 1", + [](const rlottie::FrameInfo& info) { + return rlottie::Point(0, 30); + }); } view8->setPos(2100, 0); view8->setSize(300, 300); diff --git a/inc/rlottie.h b/inc/rlottie.h index 6756569..ec50d2d 100644 --- a/inc/rlottie.h +++ b/inc/rlottie.h @@ -113,7 +113,9 @@ enum class Property { TrPosition, /*!< Transform Position property of Layer and Group object , value type is rlottie::Point */ TrScale, /*!< Transform Scale property of Layer and Group object , value type is rlottie::Size. range[0 ..100] */ TrRotation, /*!< Transform Rotation property of Layer and Group object , value type is float. range[0 .. 360] in degrees*/ - TrOpacity /*!< Transform Opacity property of Layer and Group object , value type is float [ 0 .. 100] */ + TrOpacity, /*!< Transform Opacity property of Layer and Group object , value type is float [ 0 .. 100] */ + TrimStart, /*!< Trim Start property of Shape object , value type is float [ 0 .. 100] */ + TrimEnd /*!< Trim End property of Shape object , value type is rlottie::Point [ 0 .. 100] */ }; struct Color_Type{}; @@ -518,8 +520,8 @@ template<> struct MapType> template<> struct MapType>: Point_Type{}; template<> struct MapType>: Point_Type{}; template<> struct MapType>: Size_Type{}; - - +template<> struct MapType>: Float_Type{}; +template<> struct MapType>: Point_Type{}; } // namespace lotplayer #endif // _RLOTTIE_H_ diff --git a/inc/rlottie_capi.h b/inc/rlottie_capi.h index 80907ae..bf91ae4 100644 --- a/inc/rlottie_capi.h +++ b/inc/rlottie_capi.h @@ -41,7 +41,9 @@ typedef enum { LOTTIE_ANIMATION_PROPERTY_TR_POSITION, /*!< Transform Position property of Layer and Group object , value type is int */ LOTTIE_ANIMATION_PROPERTY_TR_SCALE, /*!< Transform Scale property of Layer and Group object , value type is float range[0 ..100] */ LOTTIE_ANIMATION_PROPERTY_TR_ROTATION, /*!< Transform Scale property of Layer and Group object , value type is float. range[0 .. 360] in degrees*/ - LOTTIE_ANIMATION_PROPERTY_TR_OPACITY /*!< Transform Opacity property of Layer and Group object , value type is float [ 0 .. 100] */ + LOTTIE_ANIMATION_PROPERTY_TR_OPACITY, /*!< Transform Opacity property of Layer and Group object , value type is float [ 0 .. 100] */ + LOTTIE_ANIMATION_PROPERTY_TRIM_PATH_START, /*!< Trim Path Start property of Shape object , value type is float [0 .. 100] */ + LOTTIE_ANIMATION_PROPERTY_TRIM_PATH_END /*!< Trim Path End property of Shape object , value type is float [0 .. 100] */ }Lottie_Animation_Property; typedef struct Lottie_Animation_S Lottie_Animation; diff --git a/src/binding/c/lottieanimation_capi.cpp b/src/binding/c/lottieanimation_capi.cpp index 53ca7bd..e93b055 100644 --- a/src/binding/c/lottieanimation_capi.cpp +++ b/src/binding/c/lottieanimation_capi.cpp @@ -212,9 +212,11 @@ lottie_animation_property_override(Lottie_Animation_S *animation, case LOTTIE_ANIMATION_PROPERTY_STROKEOPACITY: case LOTTIE_ANIMATION_PROPERTY_STROKEWIDTH: case LOTTIE_ANIMATION_PROPERTY_TR_ROTATION: + case LOTTIE_ANIMATION_PROPERTY_TRIM_PATH_START: return 1; case LOTTIE_ANIMATION_PROPERTY_TR_POSITION: case LOTTIE_ANIMATION_PROPERTY_TR_SCALE: + case LOTTIE_ANIMATION_PROPERTY_TRIM_PATH_END: return 2; default: return 0; @@ -278,6 +280,19 @@ lottie_animation_property_override(Lottie_Animation_S *animation, animation->mAnimation->setValue(keypath, (float)r); break; } + case LOTTIE_ANIMATION_PROPERTY_TRIM_PATH_START: { + double start = v[0]; + if (start < 0 || start > 100) break; + animation->mAnimation->setValue(keypath, (float)start); + break; + } + case LOTTIE_ANIMATION_PROPERTY_TRIM_PATH_END: { + double start = v[0]; + double end = v[1]; + if (start < 0 || start > 100 || end < 0 || end > 100) break; + animation->mAnimation->setValue(keypath, rlottie::Point((float)start, (float)end)); + break; + } case LOTTIE_ANIMATION_PROPERTY_TR_ANCHOR: case LOTTIE_ANIMATION_PROPERTY_TR_OPACITY: //@TODO handle propery update. diff --git a/src/lottie/lottiefiltermodel.h b/src/lottie/lottiefiltermodel.h index 4f78c11..015e9cb 100644 --- a/src/lottie/lottiefiltermodel.h +++ b/src/lottie/lottiefiltermodel.h @@ -425,6 +425,25 @@ public: } }; +template <> +class Filter: public FilterBase +{ +public: + Filter(model::Trim* model) : FilterBase(model) {} + + model::Trim::Segment segment(int frameNo) const + { + if (this->hasFilter(rlottie::Property::TrimStart)) { + this->model_->updateTrimStartValue(this->filter()->value(rlottie::Property::TrimStart, frameNo)); + } + if (this->hasFilter(rlottie::Property::TrimEnd)) { + this->model_->updateTrimEndValue(this->filter()->point(rlottie::Property::TrimEnd, frameNo)); + } + model::Trim::Segment segment = this->model()->segment(frameNo); + return segment; + } +}; + } // namespace model diff --git a/src/lottie/lottieitem.cpp b/src/lottie/lottieitem.cpp index d7b7078..02e9477 100644 --- a/src/lottie/lottieitem.cpp +++ b/src/lottie/lottieitem.cpp @@ -72,6 +72,17 @@ static bool strokeProp(rlottie::Property prop) } } +static bool trimProp(rlottie::Property prop) +{ + switch (prop) { + case rlottie::Property::TrimStart: + case rlottie::Property::TrimEnd: + return true; + default: + return false; + } +} + static renderer::Layer *createLayerItem(model::Layer *layerData, VArenaAlloc * allocator) { @@ -1376,6 +1387,21 @@ bool renderer::GradientStroke::updateContent(int frameNo, const VMatrix &matrix, return !vIsZero(combinedAlpha); } +bool renderer::Trim::resolveKeyPath(LOTKeyPath &keyPath, uint32_t depth, + LOTVariant &value) +{ + if (!keyPath.matches(mModel.name(), depth)) { + return false; + } + + if (keyPath.fullyResolvesTo(mModel.name(), depth) && + trimProp(value.property())) { + mModel.filter()->addValue(value); + return true; + } + return false; +} + void renderer::Trim::update(int frameNo, const VMatrix & /*parentMatrix*/, float /*parentAlpha*/, const DirtyFlag & /*flag*/) { @@ -1383,7 +1409,7 @@ void renderer::Trim::update(int frameNo, const VMatrix & /*parentMatrix*/, if (mCache.mFrameNo == frameNo) return; - model::Trim::Segment segment = mData->segment(frameNo); + model::Trim::Segment segment = mModel.segment(frameNo); if (!(vCompare(mCache.mSegment.start, segment.start) && vCompare(mCache.mSegment.end, segment.end))) { diff --git a/src/lottie/lottieitem.h b/src/lottie/lottieitem.h index a1c6a1a..0406697 100644 --- a/src/lottie/lottieitem.h +++ b/src/lottie/lottieitem.h @@ -584,13 +584,16 @@ private: class Trim final : public Object { public: - explicit Trim(model::Trim *data) : mData(data) {} + explicit Trim(model::Trim *data) : mData(data), mModel(data) {} void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) final; Object::Type type() const final { return Object::Type::Trim; } void update(); void addPathItems(std::vector &list, size_t startOffset); +protected: + bool resolveKeyPath(LOTKeyPath &keyPath, uint32_t depth, + LOTVariant &value) final; private: bool pathDirty() const { @@ -608,6 +611,8 @@ private: model::Trim * mData{nullptr}; VPathMesure mPathMesure; bool mDirty{true}; + + model::Filter mModel; }; class Repeater final : public Group { diff --git a/src/lottie/lottiemodel.h b/src/lottie/lottiemodel.h index 745571e..b8ca1ba 100644 --- a/src/lottie/lottiemodel.h +++ b/src/lottie/lottiemodel.h @@ -1009,6 +1009,20 @@ public: }; enum class TrimType { Simultaneously, Individually }; Trim() : Object(Object::Type::Trim) {} + + void updateTrimStartValue(float start) + { + mStart.value() = start; + } + + void updateTrimEndValue(VPointF pos) + { + for (auto &keyFrame : mEnd.animation().frames_) { + keyFrame.value_.start_ = pos.x(); + keyFrame.value_.end_ = pos.y(); + } + } + /* * if start > end vector trims the path as a loop ( 2 segment) * if start < end vector trims the path without loop ( 1 segment).