| 1 | // Copyright (C) 2018 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include <QPointF> |
| 5 | #include <QTransform> |
| 6 | |
| 7 | #include "QtLottie/private/qlottierenderer_p.h" |
| 8 | #include "QtLottie/private/qlottiebasictransform_p.h" |
| 9 | #include "QtLottie/private/qlottieshapetransform_p.h" |
| 10 | |
| 11 | QT_BEGIN_NAMESPACE |
| 12 | |
| 13 | void QLottieRenderer::setTrimmingState(QLottieRenderer::TrimmingState trimmingState) |
| 14 | { |
| 15 | m_trimmingState = trimmingState; |
| 16 | } |
| 17 | |
| 18 | QLottieRenderer::TrimmingState QLottieRenderer::trimmingState() const |
| 19 | { |
| 20 | return m_trimmingState; |
| 21 | } |
| 22 | |
| 23 | void QLottieRenderer::saveTrimmingState() |
| 24 | { |
| 25 | m_trimStateStack.push(t: m_trimmingState); |
| 26 | } |
| 27 | |
| 28 | void QLottieRenderer::restoreTrimmingState() |
| 29 | { |
| 30 | if (m_trimStateStack.size()) |
| 31 | m_trimmingState = m_trimStateStack.pop(); |
| 32 | } |
| 33 | |
| 34 | void QLottieRenderer::applyTransform(QTransform *xf, const QLottieBasicTransform &lottieXf, bool isShapeTransform) |
| 35 | { |
| 36 | const QPointF pos = lottieXf.position(); |
| 37 | const qreal rot = lottieXf.rotation(); |
| 38 | const QPointF sca = lottieXf.scale(); |
| 39 | const QPointF anc = lottieXf.anchorPoint(); |
| 40 | |
| 41 | xf->translate(dx: pos.x(), dy: pos.y()); |
| 42 | |
| 43 | if (!qFuzzyIsNull(d: rot)) |
| 44 | xf->rotate(a: rot); |
| 45 | |
| 46 | if (isShapeTransform) { |
| 47 | const QLottieShapeTransform &shxf = static_cast<const QLottieShapeTransform &>(lottieXf); |
| 48 | if (!qFuzzyIsNull(d: shxf.skew())) { |
| 49 | QTransform t(shxf.shearX(), shxf.shearY(), 0, -shxf.shearY(), shxf.shearX(), 0, 0, 0, 1); |
| 50 | t *= QTransform(1, 0, 0, shxf.shearAngle(), 1, 0, 0, 0, 1); |
| 51 | t *= QTransform(shxf.shearX(), -shxf.shearY(), 0, shxf.shearY(), shxf.shearX(), 0, 0, 0, 1); |
| 52 | *xf = t * (*xf); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | xf->scale(sx: sca.x(), sy: sca.y()); |
| 57 | xf->translate(dx: -anc.x(), dy: -anc.y()); |
| 58 | } |
| 59 | |
| 60 | QT_END_NAMESPACE |
| 61 | |