1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include "bmellipse_p.h"
5
6#include <QJsonObject>
7#include <QRectF>
8
9#include "bmtrimpath_p.h"
10
11QT_BEGIN_NAMESPACE
12
13BMEllipse::BMEllipse(const BMEllipse &other)
14 : BMShape(other)
15{
16 m_position = other.m_position;
17 m_size = other.m_size;
18}
19
20BMEllipse::BMEllipse(const QJsonObject &definition, const QVersionNumber &version, BMBase *parent)
21{
22 setParent(parent);
23 construct(definition, version);
24}
25
26BMBase *BMEllipse::clone() const
27{
28 return new BMEllipse(*this);
29}
30
31void BMEllipse::construct(const QJsonObject &definition, const QVersionNumber &version)
32{
33 BMBase::parse(definition);
34 if (m_hidden)
35 return;
36
37 qCDebug(lcLottieQtBodymovinParser) << "BMEllipse::construct():" << m_name;
38
39 QJsonObject position = definition.value(key: QLatin1String("p")).toObject();
40 position = resolveExpression(definition: position);
41 m_position.construct(definition: position, version);
42
43 QJsonObject size = definition.value(key: QLatin1String("s")).toObject();
44 size = resolveExpression(definition: size);
45 m_size.construct(definition: size, version);
46
47 m_direction = definition.value(key: QLatin1String("d")).toInt();
48}
49
50bool BMEllipse::acceptsTrim() const
51{
52 return true;
53}
54
55void BMEllipse::updateProperties(int frame)
56{
57 m_position.update(frame);
58 m_size.update(frame);
59
60 // AE uses center of a shape as it's position,
61 // in Qt a translation is needed
62 QPointF pos = QPointF(m_position.value().x() - m_size.value().width() / 2,
63 m_position.value().y() - m_size.value().height() / 2);
64
65 m_path = QPainterPath();
66 m_path.arcMoveTo(rect: QRectF(pos, m_size.value()), angle: 90);
67 m_path.arcTo(rect: QRectF(pos, m_size.value()), startAngle: 90, arcLength: 360);
68
69 if (m_direction)
70 m_path = m_path.toReversed();
71}
72
73void BMEllipse::render(LottieRenderer &renderer) const
74{
75 renderer.render(ellipse: *this);
76}
77
78QPointF BMEllipse::position() const
79{
80 return m_position.value();
81}
82
83QSizeF BMEllipse::size() const
84{
85 return m_size.value();
86}
87
88QT_END_NAMESPACE
89

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