| 1 | // Copyright (C) 2018 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include "bmpathtrimmer_p.h" |
| 5 | |
| 6 | #include "bmtrimpath_p.h" |
| 7 | #include "lottierenderer_p.h" |
| 8 | |
| 9 | #include <QPainterPath> |
| 10 | |
| 11 | QT_BEGIN_NAMESPACE |
| 12 | |
| 13 | BMPathTrimmer::BMPathTrimmer(BMBase *root) |
| 14 | : m_root(root) |
| 15 | { |
| 16 | Q_ASSERT(m_root); |
| 17 | } |
| 18 | |
| 19 | void BMPathTrimmer::addTrim(BMTrimPath* trim) |
| 20 | { |
| 21 | if (!trim) |
| 22 | return; |
| 23 | |
| 24 | m_trimPaths.append(t: trim); |
| 25 | |
| 26 | if (!m_appliedTrim) |
| 27 | m_appliedTrim = trim; |
| 28 | else |
| 29 | qCWarning(lcLottieQtBodymovinParser) |
| 30 | << "BM Shape Layer: more than one trim path found on the layer." |
| 31 | << "Only one (the first encountered) is supported"; |
| 32 | } |
| 33 | |
| 34 | bool BMPathTrimmer::inUse() const |
| 35 | { |
| 36 | return !m_trimPaths.isEmpty(); |
| 37 | } |
| 38 | |
| 39 | void BMPathTrimmer::applyTrim(BMShape *shape) |
| 40 | { |
| 41 | if (!m_appliedTrim) |
| 42 | return; |
| 43 | shape->applyTrim(trimmer: *m_appliedTrim); |
| 44 | } |
| 45 | |
| 46 | void BMPathTrimmer::updateProperties(int frame) |
| 47 | { |
| 48 | QPainterPath unifiedPath; |
| 49 | |
| 50 | if (m_appliedTrim) |
| 51 | m_appliedTrim->updateProperties(frame); |
| 52 | |
| 53 | // for (BMBase *child : m_root->children()) { |
| 54 | // // TODO: Create a better system for recognizing types |
| 55 | // if (child->type() >= 1000) |
| 56 | // continue; |
| 57 | |
| 58 | // BMShape *shape = static_cast<BMShape*>(child); |
| 59 | |
| 60 | // // TODO: Get a better way to inherit trimming |
| 61 | // if (shape->type() == BM_SHAPE_GROUP_IX && m_appliedTrim) |
| 62 | // shape->applyTrim(*m_appliedTrim); |
| 63 | |
| 64 | // shape->updateProperties(frame); |
| 65 | |
| 66 | // if (m_appliedTrim && shape->acceptsTrim()) |
| 67 | // shape->applyTrim(*m_appliedTrim); |
| 68 | // } |
| 69 | } |
| 70 | |
| 71 | void BMPathTrimmer::render(LottieRenderer &renderer) const |
| 72 | { |
| 73 | Q_UNUSED(renderer); |
| 74 | // if (m_appliedTrim) { |
| 75 | // renderer.render(*m_appliedTrim); |
| 76 | // } |
| 77 | } |
| 78 | |
| 79 | QT_END_NAMESPACE |
| 80 |
