1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include "bmshapetransform_p.h"
5
6#include <QJsonObject>
7#include <QtMath>
8
9#include "bmconstants_p.h"
10#include "bmbasictransform_p.h"
11
12BMShapeTransform::BMShapeTransform(const BMShapeTransform &other)
13 : BMBasicTransform(other)
14{
15 m_skew = other.m_skew;
16 m_skewAxis = other.m_skewAxis;
17 m_shearX = other.m_shearX;
18 m_shearY = other.m_shearY;
19 m_shearAngle = other.m_shearAngle;
20}
21
22BMShapeTransform::BMShapeTransform(const QJsonObject &definition, const QVersionNumber &version,
23 BMBase *parent)
24{
25 setParent(parent);
26 construct(definition, version);
27}
28
29BMBase *BMShapeTransform::clone() const
30{
31 return new BMShapeTransform(*this);
32}
33
34void BMShapeTransform::construct(const QJsonObject &definition, const QVersionNumber &version)
35{
36 BMBasicTransform::construct(definition, version);
37
38 qCDebug(lcLottieQtBodymovinParser) << "BMShapeTransform::construct():" << BMShape::name();
39
40 QJsonObject skew = definition.value(key: QLatin1String("sk")).toObject();
41 skew = resolveExpression(definition: skew);
42 m_skew.construct(definition: skew, version);
43
44 QJsonObject skewAxis = definition.value(key: QLatin1String("sa")).toObject();
45 skewAxis = resolveExpression(definition: skewAxis);
46 m_skewAxis.construct(definition: skewAxis, version);
47}
48
49void BMShapeTransform::updateProperties(int frame)
50{
51 BMBasicTransform::updateProperties(frame);
52
53 m_skew.update(frame);
54 m_skewAxis.update(frame);
55
56 double rads = qDegreesToRadians(degrees: m_skewAxis.value());
57 m_shearX = qCos(v: rads);
58 m_shearY = qSin(v: rads);
59 double tan = qDegreesToRadians(degrees: -m_skew.value());
60 m_shearAngle = qTan(v: tan);
61}
62
63void BMShapeTransform::render(LottieRenderer &renderer) const
64{
65 renderer.render(trans: *this);
66}
67
68qreal BMShapeTransform::skew() const
69{
70 return m_skew.value();
71}
72
73qreal BMShapeTransform::skewAxis() const
74{
75 return m_skewAxis.value();
76}
77
78qreal BMShapeTransform::shearX() const
79{
80 return m_shearX;
81}
82
83qreal BMShapeTransform::shearY() const
84{
85 return m_shearY;
86}
87
88qreal BMShapeTransform::shearAngle() const
89{
90 return m_shearAngle;
91}
92

source code of qtlottie/src/bodymovin/bmshapetransform.cpp