1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include "bmfilleffect_p.h"
5
6#include <QJsonObject>
7#include <QJsonValue>
8
9#include "bmglobal.h"
10
11QT_BEGIN_NAMESPACE
12
13BMFillEffect::BMFillEffect(const BMFillEffect &other)
14 : BMBase(other)
15{
16 m_color = other.m_color;
17 m_opacity = other.m_opacity;
18}
19
20BMBase *BMFillEffect::clone() const
21{
22 return new BMFillEffect(*this);
23}
24
25void BMFillEffect::construct(const QJsonObject &definition, const QVersionNumber &version)
26{
27 m_type = BM_EFFECT_FILL;
28
29 if (!definition.value(key: QLatin1String("hd")).toBool(defaultValue: true))
30 return;
31
32 QJsonArray properties = definition.value(key: QLatin1String("ef")).toArray();
33
34 // TODO: Check are property positions really fixed in the effect?
35
36 m_color.construct(definition: properties.at(i: 2).toObject().value(key: QLatin1String("v")).toObject(), version);
37 m_opacity.construct(definition: properties.at(i: 6).toObject().value(key: QLatin1String("v")).toObject(), version);
38
39 if (!qFuzzyCompare(p1: properties.at(i: 0).toObject().value(key: QLatin1String("v")).toObject().value(key: QLatin1String("k")).toDouble(), p2: 0.0))
40 qCWarning(lcLottieQtBodymovinParser)<< "BMFillEffect: Property 'Fill mask' not supported";
41
42 if (!qFuzzyCompare(p1: properties.at(i: 1).toObject().value(key: QLatin1String("v")).toObject().value(key: QLatin1String("k")).toDouble(), p2: 0.0))
43 qCWarning(lcLottieQtBodymovinParser) << "BMFillEffect: Property 'All masks' not supported";
44
45 if (!qFuzzyCompare(p1: properties.at(i: 3).toObject().value(key: QLatin1String("v")).toObject().value(key: QLatin1String("k")).toDouble(), p2: 0.0))
46 qCWarning(lcLottieQtBodymovinParser) << "BMFillEffect: Property 'Invert' not supported";
47
48 if (!qFuzzyCompare(p1: properties.at(i: 4).toObject().value(key: QLatin1String("v")).toObject().value(key: QLatin1String("k")).toDouble(), p2: 0.0))
49 qCWarning(lcLottieQtBodymovinParser) << "BMFillEffect: Property 'Horizontal feather' not supported";
50
51 if (!qFuzzyCompare(p1: properties.at(i: 5).toObject().value(key: QLatin1String("v")).toObject().value(key: QLatin1String("k")).toDouble(), p2: 0.0))
52 qCWarning(lcLottieQtBodymovinParser)
53 << "BMFillEffect: Property 'Vertical feather' not supported";
54}
55
56void BMFillEffect::updateProperties(int frame)
57{
58 m_color.update(frame);
59 m_opacity.update(frame);
60}
61
62void BMFillEffect::render(LottieRenderer &renderer) const
63{
64 renderer.render(effect: *this);
65}
66
67QColor BMFillEffect::color() const
68{
69 QVector4D cVec = m_color.value();
70 QColor color;
71 qreal r = static_cast<qreal>(cVec.x());
72 qreal g = static_cast<qreal>(cVec.y());
73 qreal b = static_cast<qreal>(cVec.z());
74 qreal a = static_cast<qreal>(cVec.w());
75 color.setRgbF(r, g, b, a);
76 return color;
77}
78
79qreal BMFillEffect::opacity() const
80{
81 return m_opacity.value();
82}
83
84QT_END_NAMESPACE
85

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