1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include "bmrepeatertransform_p.h"
5
6QT_BEGIN_NAMESPACE
7
8BMRepeaterTransform::BMRepeaterTransform(const BMRepeaterTransform &other)
9 : BMBasicTransform(other)
10{
11 m_startOpacity = other.m_startOpacity;
12 m_endOpacity = other.m_endOpacity;
13 m_opacities = other.m_opacities;
14}
15
16BMRepeaterTransform::BMRepeaterTransform(const QJsonObject &definition,
17 const QVersionNumber &version, BMBase *parent)
18{
19 setParent(parent);
20 construct(definition, version);
21}
22
23BMBase *BMRepeaterTransform::clone() const
24{
25 return new BMRepeaterTransform(*this);
26}
27
28void BMRepeaterTransform::construct(const QJsonObject &definition, const QVersionNumber &version)
29{
30 qCDebug(lcLottieQtBodymovinParser) << "BMRepeaterTransform::construct():" << name();
31
32 BMBasicTransform::construct(definition, version);
33 if (m_hidden)
34 return;
35
36 QJsonObject startOpacity = definition.value(key: QLatin1String("so")).toObject();
37 startOpacity = resolveExpression(definition: startOpacity);
38 m_startOpacity.construct(definition: startOpacity, version);
39
40 QJsonObject endOpacity = definition.value(key: QLatin1String("eo")).toObject();
41 endOpacity = resolveExpression(definition: endOpacity);
42 m_endOpacity.construct(definition: endOpacity, version);
43}
44
45void BMRepeaterTransform::updateProperties(int frame)
46{
47 BMBasicTransform::updateProperties(frame);
48
49 m_startOpacity.update(frame);
50 m_endOpacity.update(frame);
51
52 m_opacities.clear();
53 for (int i = 0; i < m_copies; i++) {
54 qreal opacity = m_startOpacity.value() +
55 (m_endOpacity.value() - m_startOpacity.value()) * i / m_copies;
56 m_opacities.push_back(t: opacity);
57 }
58}
59
60void BMRepeaterTransform::render(LottieRenderer &renderer) const
61{
62 renderer.render(trans: *this);
63}
64
65void BMRepeaterTransform::setInstanceCount(int copies)
66{
67 m_copies = copies;
68}
69
70qreal BMRepeaterTransform::opacityAtInstance(int instance) const
71{
72 return m_opacities.at(i: instance) / 100.0;
73}
74
75qreal BMRepeaterTransform::startOpacity() const
76{
77 return m_startOpacity.value();
78}
79
80qreal BMRepeaterTransform::endOpacity() const
81{
82 return m_endOpacity.value();
83}
84
85QT_END_NAMESPACE
86

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