summaryrefslogtreecommitdiff
path: root/ssg/src/lottie/lottiemodel.h
blob: 0e8c396e15128c31d328a25fd5c80e11e3e49c77 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#ifndef LOTTIEMODEL_H
#define LOTTIEMODEL_H

#include<vector>
#include"sgpoint.h"
#include"sgrect.h"

template<typename T>
class LottieKeyFrame
{
public:
    T     mStartValue;
    T     mEndValue;
    int   mStartFrame;
    int   mEndFrame;
};

template<typename T, bool animation = true>
class LottieProperty
{
public:
    LottieProperty(){}
    constexpr bool staticType() const {return false;}
    constexpr bool isStatic() const {return mKeyFrames.empty();}
public:
    T     mValue;
    std::vector<LottieKeyFrame<T>> mKeyFrames;
};

template<typename T>
class LottieProperty<T, false>
{
public:
    LottieProperty(){}
    LottieProperty<T,false>(T initialvalue): mValue(initialvalue){}
    constexpr bool staticType() const {return true;}
    constexpr bool isStatic() const {return true;}
public:
    T     mValue;
};

// Template aliasing for easy of use.
template<bool animation>
using LottieIntProperty = LottieProperty<int, animation>;

template<bool animation>
using LottieFloatProperty = LottieProperty<float, animation>;

template <typename T>
struct LottiePropertyHelper
{
  LottiePropertyHelper(const T &value):mAnimation(false){ mProperty.mValue = value;}
  bool mAnimation;
  LottieProperty<T,true> mProperty;
};

template<bool animation>
using LottiePointFProperty = LottieProperty<SGPointF, animation>;

enum class LottieBlendMode
{
    Normal = 0,
    Multiply = 1,
    Screen = 2,
    OverLay = 3
};
class LottieObject
{
public:
    enum class Type {
        Composition,
        Layer,
        Group,
        Fill,
        Stroke,
        GFill,
        GStroke,
        Rect,
        Ellipse,
        Shape,
        Star
    };

    bool isStatic();
public:
    LottieObject::Type  mType;
};

class LottieGroupObj : public LottieObject
{
public:
    std::vector<LottieObject *> mChildren;
    int                         mParentId; // Lottie the id of the parent in the composition
    int                         mId;  // Lottie the group id  used for parenting.
};

class LottieComposition : public LottieGroupObj
{
public:
    SGRect      mBound;
    bool        mpreserveAspect = false;
    bool        mAnimation = false;
    long        mStartFrame = 0;
    long        mEndFrame = 0;
    float       mFrameRate;
};

class LottieLayer : public LottieGroupObj
{
public:
    SGRect               mBound;
    int                  mlayerType; //lottie layer type  (solid/shape/precomp)
    int                  mParentId; // Lottie the id of the parent in the composition
    int                  mId;  // Lottie the group id  used for parenting.
    int                  mGroupType; //lottie layer type  (solid/shape/precomp)
    long                 mStartFrame = 0;
    long                 mEndFrame = 0;
    long                 mStartTime;
    LottieBlendMode      mBlendMode;
    float                mTimeStreatch;
};

class LottieMatrix : public LottieGroupObj
{
public:
    LottieFloatProperty<true>   mRotation;  /* "r" */
    LottiePointFProperty<true>  mScale;     /* "s" */
    LottiePointFProperty<true>  mPosition;  /* "p" */
    LottiePointFProperty<true>  mAnchor;    /* "a" */
    LottieFloatProperty<true>   mOpacity;   /* "o" */
    LottiePointFProperty<true>  mSkew;      /* "sk" */
    LottieFloatProperty<true>   mSkewAxis;  /* "sa" */
};

template<bool pos, bool size, bool roundness>
class LottieRectObject : public LottieObject
{
public:
    LottiePointFProperty<pos>       mPos;
    LottiePointFProperty<size>      mSize;
    LottieFloatProperty<roundness>  mRound;
};

template<bool pos, bool size>
class LottieEllipseObject : public LottieObject
{
public:
    LottiePointFProperty<pos>       mPos;
    LottiePointFProperty<size>      mSize;
};



#endif // LOTTIEMODEL_H