mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-05 05:51:42 +00:00
lottie: handle trim path
Change-Id: I05f1daec3c7e0c4cbb953c5c0a076d81e82d8e30
This commit is contained in:
parent
a411696b12
commit
4067491267
@ -5,7 +5,6 @@
|
|||||||
#include"vdasher.h"
|
#include"vdasher.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
|
|
||||||
VDrawable::VDrawable():mFlag(DirtyState::All),
|
VDrawable::VDrawable():mFlag(DirtyState::All),
|
||||||
mType(Type::Fill),
|
mType(Type::Fill),
|
||||||
mFillRule(FillRule::Winding)
|
mFillRule(FillRule::Winding)
|
||||||
@ -608,6 +607,7 @@ LOTShapeLayerItem::LOTShapeLayerItem(LOTLayerData *layerData):LOTLayerItem(layer
|
|||||||
mRoot = new LOTContentGroupItem(nullptr);
|
mRoot = new LOTContentGroupItem(nullptr);
|
||||||
mRoot->addChildren(layerData);
|
mRoot->addChildren(layerData);
|
||||||
mRoot->processPaintOperation();
|
mRoot->processPaintOperation();
|
||||||
|
mRoot->processTrimOperation();
|
||||||
}
|
}
|
||||||
|
|
||||||
LOTShapeLayerItem::~LOTShapeLayerItem()
|
LOTShapeLayerItem::~LOTShapeLayerItem()
|
||||||
@ -658,6 +658,10 @@ LOTContentItem * LOTShapeLayerItem::createContentItem(LOTData *contentData)
|
|||||||
return new LOTRepeaterItem(static_cast<LOTRepeaterData *>(contentData));
|
return new LOTRepeaterItem(static_cast<LOTRepeaterData *>(contentData));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case LOTData::Type::Trim: {
|
||||||
|
return new LOTTrimItem(static_cast<LOTTrimData *>(contentData));
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
break;
|
break;
|
||||||
@ -765,9 +769,42 @@ void LOTPathDataItem::addPaintOperation(std::vector<LOTPaintDataItem *> &list, i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LOTContentGroupItem::processTrimOperation()
|
||||||
|
{
|
||||||
|
std::vector<LOTTrimItem *> list;
|
||||||
|
trimOperationHelper(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LOTContentGroupItem::trimOperationHelper(std::vector<LOTTrimItem *> &list)
|
||||||
|
{
|
||||||
|
int curOpCount = list.size();
|
||||||
|
for (auto i = mContents.rbegin(); i != mContents.rend(); ++i) {
|
||||||
|
auto child = *i;
|
||||||
|
if (auto pathNode = dynamic_cast<LOTPathDataItem *>(child)) {
|
||||||
|
// the node is a path data node add the paint operation list to it.
|
||||||
|
pathNode->addTrimOperation(list);
|
||||||
|
} else if (auto trimNode = dynamic_cast<LOTTrimItem *>(child)) {
|
||||||
|
// add it to the trim operation list
|
||||||
|
list.push_back(trimNode);
|
||||||
|
} else if (auto groupNode = dynamic_cast<LOTContentGroupItem *>(child)) {
|
||||||
|
// update the groups node with current list
|
||||||
|
groupNode->trimOperationHelper(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list.erase(list.begin() + curOpCount, list.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
void LOTPathDataItem::addTrimOperation(std::vector<LOTTrimItem *> &list)
|
||||||
|
{
|
||||||
|
for(auto trimItem : list) {
|
||||||
|
mTrimNodeRefs.push_back(trimItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LOTPathDataItem::update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag)
|
void LOTPathDataItem::update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag)
|
||||||
{
|
{
|
||||||
|
VPath tempPath;
|
||||||
|
|
||||||
mPathChanged = false;
|
mPathChanged = false;
|
||||||
mCombinedAlpha = parentAlpha;
|
mCombinedAlpha = parentAlpha;
|
||||||
|
|
||||||
@ -778,12 +815,28 @@ void LOTPathDataItem::update(int frameNo, const VMatrix &parentMatrix, float par
|
|||||||
mPathChanged = true;
|
mPathChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tempPath = mLocalPath;
|
||||||
|
|
||||||
// 2. apply path operation if needed
|
// 2. apply path operation if needed
|
||||||
// TODO
|
if (mTrimNodeRefs.size() > 0)
|
||||||
|
{
|
||||||
|
//TODO apply more than one trim path if necessary
|
||||||
|
VPathMesure pm;
|
||||||
|
float s = mTrimNodeRefs.front()->getStart(frameNo);
|
||||||
|
float e = mTrimNodeRefs.front()->getEnd(frameNo);
|
||||||
|
|
||||||
|
pm.setPath(mLocalPath);
|
||||||
|
pm.setStart(s);
|
||||||
|
pm.setEnd(e);
|
||||||
|
tempPath = pm.getPath();
|
||||||
|
|
||||||
|
mPathChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
// 3. compute the final path with parentMatrix
|
// 3. compute the final path with parentMatrix
|
||||||
|
|
||||||
if ((flag & DirtyFlagBit::Matrix) || mPathChanged) {
|
if ((flag & DirtyFlagBit::Matrix) || mPathChanged) {
|
||||||
mFinalPath = mLocalPath;
|
mFinalPath = tempPath;
|
||||||
mFinalPath.transform(parentMatrix);
|
mFinalPath.transform(parentMatrix);
|
||||||
mPathChanged = true;
|
mPathChanged = true;
|
||||||
}
|
}
|
||||||
@ -1051,7 +1104,10 @@ void LOTGStrokeItem::updateRenderNode(LOTPathDataItem *pathNode, VDrawable *draw
|
|||||||
|
|
||||||
LOTTrimItem::LOTTrimItem(LOTTrimData *data):mData(data)
|
LOTTrimItem::LOTTrimItem(LOTTrimData *data):mData(data)
|
||||||
{
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void LOTTrimItem::update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
LOTRepeaterItem::LOTRepeaterItem(LOTRepeaterData *data):mData(data)
|
LOTRepeaterItem::LOTRepeaterItem(LOTRepeaterData *data):mData(data)
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
#include"vmatrix.h"
|
#include"vmatrix.h"
|
||||||
#include"vpath.h"
|
#include"vpath.h"
|
||||||
#include"vpoint.h"
|
#include"vpoint.h"
|
||||||
|
#include"vpathmesure.h"
|
||||||
#include"lottieplayer.h"
|
#include"lottieplayer.h"
|
||||||
#include"vbrush.h"
|
#include"vbrush.h"
|
||||||
#include"vpainter.h"
|
#include"vpainter.h"
|
||||||
@ -202,6 +203,7 @@ public:
|
|||||||
class LOTNode;
|
class LOTNode;
|
||||||
class LOTPathDataItem;
|
class LOTPathDataItem;
|
||||||
class LOTPaintDataItem;
|
class LOTPaintDataItem;
|
||||||
|
class LOTTrimItem;
|
||||||
struct LOTRenderNode
|
struct LOTRenderNode
|
||||||
{
|
{
|
||||||
LOTRenderNode(LOTPathDataItem *path, LOTPaintDataItem *paint, VDrawable *render, bool sameG)
|
LOTRenderNode(LOTPathDataItem *path, LOTPaintDataItem *paint, VDrawable *render, bool sameG)
|
||||||
@ -229,9 +231,11 @@ public:
|
|||||||
void addChildren(LOTGroupData *data);
|
void addChildren(LOTGroupData *data);
|
||||||
void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) final;
|
void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) final;
|
||||||
void processPaintOperation();
|
void processPaintOperation();
|
||||||
|
void processTrimOperation();
|
||||||
void renderList(std::vector<VDrawable *> &list) final;
|
void renderList(std::vector<VDrawable *> &list) final;
|
||||||
private:
|
private:
|
||||||
void paintOperationHelper(std::vector<LOTPaintDataItem *> &list);
|
void paintOperationHelper(std::vector<LOTPaintDataItem *> &list);
|
||||||
|
void trimOperationHelper(std::vector<LOTTrimItem *> &list);
|
||||||
LOTShapeGroupData *mData;
|
LOTShapeGroupData *mData;
|
||||||
std::vector<LOTContentItem *> mContents;
|
std::vector<LOTContentItem *> mContents;
|
||||||
};
|
};
|
||||||
@ -243,9 +247,11 @@ public:
|
|||||||
void addPaintOperation(std::vector<LOTPaintDataItem *> &list, int externalCount);
|
void addPaintOperation(std::vector<LOTPaintDataItem *> &list, int externalCount);
|
||||||
void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) final;
|
void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) final;
|
||||||
VPath path() const;
|
VPath path() const;
|
||||||
|
void addTrimOperation(std::vector<LOTTrimItem *> &list);
|
||||||
inline float combinedAlpha() const{ return mCombinedAlpha;}
|
inline float combinedAlpha() const{ return mCombinedAlpha;}
|
||||||
void renderList(std::vector<VDrawable *> &list) final;
|
void renderList(std::vector<VDrawable *> &list) final;
|
||||||
private:
|
private:
|
||||||
|
std::vector<LOTTrimItem *> mTrimNodeRefs;
|
||||||
std::vector<LOTRenderNode> mRenderList;
|
std::vector<LOTRenderNode> mRenderList;
|
||||||
std::vector<std::unique_ptr<VDrawable>> mNodeList;
|
std::vector<std::unique_ptr<VDrawable>> mNodeList;
|
||||||
bool mInit;
|
bool mInit;
|
||||||
@ -386,6 +392,9 @@ class LOTTrimItem : public LOTContentItem
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LOTTrimItem(LOTTrimData *data);
|
LOTTrimItem(LOTTrimData *data);
|
||||||
|
void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) final;
|
||||||
|
float getStart(int frameNo) {return mData->mStart.value(frameNo);}
|
||||||
|
float getEnd(int frameNo) {return mData->mEnd.value(frameNo);}
|
||||||
private:
|
private:
|
||||||
LOTTrimData *mData;
|
LOTTrimData *mData;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user