| 1 | // Copyright (C) 2018 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include "qlottieshapelayer_p.h" |
| 5 | |
| 6 | #include <QJsonObject> |
| 7 | #include <QJsonArray> |
| 8 | |
| 9 | |
| 10 | #include "qlottieconstants_p.h" |
| 11 | #include "qlottiebase_p.h" |
| 12 | #include "qlottieshape_p.h" |
| 13 | #include "qlottietrimpath_p.h" |
| 14 | #include "qlottiebasictransform_p.h" |
| 15 | #include "qlottierenderer_p.h" |
| 16 | |
| 17 | QT_BEGIN_NAMESPACE |
| 18 | |
| 19 | QLottieShapeLayer::QLottieShapeLayer(const QLottieShapeLayer &other) |
| 20 | : QLottieLayer(other) |
| 21 | { |
| 22 | m_appliedTrim = other.m_appliedTrim; |
| 23 | } |
| 24 | |
| 25 | QLottieShapeLayer::QLottieShapeLayer(const QJsonObject &definition) |
| 26 | { |
| 27 | m_type = LOTTIE_LAYER_SHAPE_IX; |
| 28 | |
| 29 | QLottieLayer::parse(definition); |
| 30 | if (m_hidden) |
| 31 | return; |
| 32 | |
| 33 | qCDebug(lcLottieQtLottieParser) << "QLottieShapeLayer::QLottieShapeLayer()"<< m_name; |
| 34 | |
| 35 | QJsonArray items = definition.value(key: QLatin1String("shapes")).toArray(); |
| 36 | QJsonArray::const_iterator itemIt = items.constEnd(); |
| 37 | while (itemIt != items.constBegin()) { |
| 38 | itemIt--; |
| 39 | QLottieShape *shape = QLottieShape::construct(definition: (*itemIt).toObject(), parent: this); |
| 40 | if (shape) |
| 41 | appendChild(child: shape); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | QLottieBase *QLottieShapeLayer::clone() const |
| 46 | { |
| 47 | return new QLottieShapeLayer(*this); |
| 48 | } |
| 49 | |
| 50 | void QLottieShapeLayer::updateProperties(int frame) |
| 51 | { |
| 52 | QLottieLayer::updateProperties(frame); |
| 53 | |
| 54 | for (QLottieBase *child : children()) { |
| 55 | if (child->hidden()) |
| 56 | continue; |
| 57 | |
| 58 | QLottieShape *shape = dynamic_cast<QLottieShape*>(child); |
| 59 | |
| 60 | if (!shape) |
| 61 | continue; |
| 62 | |
| 63 | if (shape->type() == LOTTIE_SHAPE_TRIM_IX) { |
| 64 | QLottieTrimPath *trim = static_cast<QLottieTrimPath*>(shape); |
| 65 | if (m_appliedTrim) |
| 66 | m_appliedTrim->applyTrim(trimmer: *trim); |
| 67 | else |
| 68 | m_appliedTrim = trim; |
| 69 | } else if (m_appliedTrim) { |
| 70 | if (shape->acceptsTrim()) |
| 71 | shape->applyTrim(trimmer: *m_appliedTrim); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | void QLottieShapeLayer::render(QLottieRenderer &renderer) const |
| 77 | { |
| 78 | if (!m_isActive) |
| 79 | return; |
| 80 | renderer.saveState(); |
| 81 | |
| 82 | QLottieLayer::render(renderer); |
| 83 | |
| 84 | if (m_appliedTrim && !m_appliedTrim->hidden()) |
| 85 | m_appliedTrim->render(renderer); |
| 86 | |
| 87 | renderer.finish(*this); |
| 88 | renderer.restoreState(); |
| 89 | } |
| 90 | |
| 91 | QT_END_NAMESPACE |
| 92 |
