summaryrefslogtreecommitdiff
path: root/ssg/src/lottie/lottiemodel.h
blob: 0825b7cbd70d4619dfdabd063e32e5ccea83571c (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
#ifndef LOTTIEMODEL_H
#define LOTTIEMODEL_H

#include<vector>
#include"sgpoint.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 isStatic() const {return false;}
public:
    std::vector<LottieKeyFrame<T>> mKeyFrames;
};

template<typename T>
class LottieProperty<T, false>
{
public:
    LottieProperty(){}
    LottieProperty<T,false>(T initialvalue): mValue(initialvalue){}
    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<bool animation>
using LottiePointFProperty = LottieProperty<SGPointF, animation>;

class LottieObject
{
public:
    enum class Type {
        Composition,
        Layer,
        Group,
        Fill,
        Stroke,
        GFill,
        GStroke,
        Rect,
        Ellipse,
        Shape,
        Star
    };

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

class LottieGroup : 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 LottieGroupObject
//{
//public:

//};

class LottieLayer : public LottieGroup
{
public:
    int         mlayerType; //lottie layer type  (solid/shape/precomp)
};

class LottieMatrix : public LottieGroup
{
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 LottieRect : public LottieObject
{
public:
    LottiePointFProperty<pos>       mPos;
    LottiePointFProperty<size>      mSize;
    LottieFloatProperty<roundness>  mRound;
};



#endif // LOTTIEMODEL_H