1 | // Copyright (C) 2016 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qquickellipseextruder_p.h" |
5 | #include <qmath.h> |
6 | #include <qrandom.h> |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | /*! |
10 | \qmltype EllipseShape |
11 | \instantiates QQuickEllipseExtruder |
12 | \inqmlmodule QtQuick.Particles |
13 | \ingroup qtquick-particles |
14 | \inherits Shape |
15 | \brief Represents an ellipse to other particle system elements. |
16 | |
17 | This shape can be used by Emitter subclasses and Affector subclasses to have |
18 | them act upon an ellipse shaped area. |
19 | */ |
20 | QQuickEllipseExtruder::QQuickEllipseExtruder(QObject *parent) : |
21 | QQuickParticleExtruder(parent) |
22 | , m_fill(true) |
23 | { |
24 | } |
25 | |
26 | /*! |
27 | \qmlproperty bool QtQuick.Particles::EllipseShape::fill |
28 | If fill is true the ellipse is filled; otherwise it is just a border. |
29 | |
30 | Default is true. |
31 | */ |
32 | |
33 | QPointF QQuickEllipseExtruder::extrude(const QRectF & r) |
34 | { |
35 | qreal theta = QRandomGenerator::global()->bounded(highest: 2 * M_PI); |
36 | qreal mag = m_fill ? QRandomGenerator::global()->generateDouble() : 1; |
37 | return QPointF(r.x() + r.width()/2 + mag * (r.width()/2) * qCos(v: theta), |
38 | r.y() + r.height()/2 + mag * (r.height()/2) * qSin(v: theta)); |
39 | } |
40 | |
41 | bool QQuickEllipseExtruder::contains(const QRectF &bounds, const QPointF &point) |
42 | { |
43 | if (!bounds.contains(p: point)) |
44 | return false; |
45 | |
46 | QPointF relPoint(bounds.center() - point); |
47 | qreal xa = relPoint.x()/bounds.width(); |
48 | qreal yb = relPoint.y()/bounds.height(); |
49 | return (xa * xa + yb * yb) < 0.25; |
50 | } |
51 | |
52 | QT_END_NAMESPACE |
53 | |
54 | #include "moc_qquickellipseextruder_p.cpp" |
55 |