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