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 "qquickrectangleextruder_p.h" |
5 | #include <QRandomGenerator> |
6 | |
7 | QT_BEGIN_NAMESPACE |
8 | |
9 | /*! |
10 | \qmltype RectangleShape |
11 | \instantiates QQuickRectangleExtruder |
12 | \inqmlmodule QtQuick.Particles |
13 | \brief For specifying an area for affectors and emitter. |
14 | \ingroup qtquick-particles |
15 | |
16 | Just a rectangle. |
17 | */ |
18 | |
19 | QQuickRectangleExtruder::QQuickRectangleExtruder(QObject *parent) : |
20 | QQuickParticleExtruder(parent), m_fill(true) |
21 | { |
22 | } |
23 | |
24 | QPointF QQuickRectangleExtruder::extrude(const QRectF &rect) |
25 | { |
26 | if (m_fill) |
27 | return QPointF(QRandomGenerator::global()->generateDouble() * rect.width() + rect.x(), |
28 | QRandomGenerator::global()->generateDouble() * rect.height() + rect.y()); |
29 | int side = QRandomGenerator::global()->bounded(highest: 4); |
30 | switch (side){//TODO: Doesn't this overlap the corners? |
31 | case 0: |
32 | return QPointF(rect.x(), |
33 | QRandomGenerator::global()->generateDouble() * rect.height() + rect.y()); |
34 | case 1: |
35 | return QPointF(rect.width() + rect.x(), |
36 | QRandomGenerator::global()->generateDouble() * rect.height() + rect.y()); |
37 | case 2: |
38 | return QPointF(QRandomGenerator::global()->generateDouble() * rect.width() + rect.x(), |
39 | rect.y()); |
40 | default: |
41 | return QPointF(QRandomGenerator::global()->generateDouble() * rect.width() + rect.x(), |
42 | rect.height() + rect.y()); |
43 | } |
44 | } |
45 | |
46 | bool QQuickRectangleExtruder::contains(const QRectF &bounds, const QPointF &point) |
47 | { |
48 | return bounds.contains(p: point); |
49 | } |
50 | |
51 | QT_END_NAMESPACE |
52 | |
53 | #include "moc_qquickrectangleextruder_p.cpp" |
54 |