| 1 | // Copyright (C) 2018 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include "qlottieshapetransform_p.h" |
| 5 | |
| 6 | #include <QJsonObject> |
| 7 | #include <QtMath> |
| 8 | |
| 9 | #include "qlottieconstants_p.h" |
| 10 | #include "qlottiebasictransform_p.h" |
| 11 | |
| 12 | QLottieShapeTransform::QLottieShapeTransform(const QLottieShapeTransform &other) |
| 13 | : QLottieBasicTransform(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 | |
| 22 | QLottieShapeTransform::QLottieShapeTransform(const QJsonObject &definition, |
| 23 | QLottieBase *parent) |
| 24 | { |
| 25 | setParent(parent); |
| 26 | construct(definition); |
| 27 | } |
| 28 | |
| 29 | QLottieBase *QLottieShapeTransform::clone() const |
| 30 | { |
| 31 | return new QLottieShapeTransform(*this); |
| 32 | } |
| 33 | |
| 34 | void QLottieShapeTransform::construct(const QJsonObject &definition) |
| 35 | { |
| 36 | QLottieBasicTransform::construct(definition); |
| 37 | |
| 38 | qCDebug(lcLottieQtLottieParser) << "QLottieShapeTransform::construct():"<< QLottieShape::name(); |
| 39 | |
| 40 | QJsonObject skew = definition.value(key: QLatin1String("sk")).toObject(); |
| 41 | skew = resolveExpression(definition: skew); |
| 42 | m_skew.construct(definition: skew); |
| 43 | |
| 44 | QJsonObject skewAxis = definition.value(key: QLatin1String("sa")).toObject(); |
| 45 | skewAxis = resolveExpression(definition: skewAxis); |
| 46 | m_skewAxis.construct(definition: skewAxis); |
| 47 | } |
| 48 | |
| 49 | void QLottieShapeTransform::updateProperties(int frame) |
| 50 | { |
| 51 | QLottieBasicTransform::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 | |
| 63 | void QLottieShapeTransform::render(QLottieRenderer &renderer) const |
| 64 | { |
| 65 | renderer.render(trans: *this); |
| 66 | } |
| 67 | |
| 68 | qreal QLottieShapeTransform::skew() const |
| 69 | { |
| 70 | return m_skew.value(); |
| 71 | } |
| 72 | |
| 73 | qreal QLottieShapeTransform::skewAxis() const |
| 74 | { |
| 75 | return m_skewAxis.value(); |
| 76 | } |
| 77 | |
| 78 | qreal QLottieShapeTransform::shearX() const |
| 79 | { |
| 80 | return m_shearX; |
| 81 | } |
| 82 | |
| 83 | qreal QLottieShapeTransform::shearY() const |
| 84 | { |
| 85 | return m_shearY; |
| 86 | } |
| 87 | |
| 88 | qreal QLottieShapeTransform::shearAngle() const |
| 89 | { |
| 90 | return m_shearAngle; |
| 91 | } |
| 92 |
