1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef LOTTIEFEEFORMSHAPE_P_H
5#define LOTTIEFEEFORMSHAPE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QPainterPath>
19#include <QJsonArray>
20#include <QMap>
21#include <QHash>
22#include <QList>
23
24#include <QtLottie/qtlottieexports.h>
25#include <QtLottie/private/qlottieshape_p.h>
26#include <QtLottie/private/qlottietrimpath_p.h>
27#include <QtLottie/private/qlottierenderer_p.h>
28
29QT_BEGIN_NAMESPACE
30
31class QJsonObject;
32
33class Q_LOTTIE_EXPORT QLottieFreeFormShape : public QLottieShape
34{
35public:
36 QLottieFreeFormShape();
37 explicit QLottieFreeFormShape(const QLottieFreeFormShape &other);
38 QLottieFreeFormShape(const QJsonObject &definition, QLottieBase *parent = nullptr);
39
40 QLottieBase *clone() const override;
41
42 void construct(const QJsonObject &definition);
43
44 void updateProperties(int frame) override;
45 void render(QLottieRenderer &renderer) const override;
46
47 bool acceptsTrim() const override;
48
49protected:
50 struct VertexInfo {
51 QLottieProperty2D<QPointF> pos;
52 QLottieProperty2D<QPointF> ci;
53 QLottieProperty2D<QPointF> co;
54 };
55
56 void parseShapeKeyframes(QJsonObject &keyframes);
57 void buildShape(const QJsonObject &keyframe);
58 void buildShape(int frame);
59 void parseEasedVertices(const QJsonObject &keyframe, int startFrame);
60
61 QHash<int, QJsonObject> m_vertexMap;
62 QList<VertexInfo> m_vertexList;
63 QMap<int, bool> m_closedShape;
64
65private:
66 struct VertexBuildInfo
67 {
68 QJsonArray posKeyframes;
69 QJsonArray ciKeyframes;
70 QJsonArray coKeyframes;
71 };
72
73 void finalizeVertices();
74
75 QMap<int, VertexBuildInfo*> m_vertexInfos;
76
77 QJsonObject createKeyframe(QJsonArray startValue, QJsonArray endValue,
78 int startFrame, QJsonObject easingIn,
79 QJsonObject easingOut);
80};
81
82QT_END_NAMESPACE
83
84#endif // LOTTIEFEEFORMSHAPE_P_H
85

source code of qtlottie/src/lottie/qlottiefreeformshape_p.h