Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickclipnode.cpp
Go to the documentation of this file.
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
5#include "qquickclipnode_p.h"
6
7#include <QtGui/qvector2d.h>
8#include <QtCore/qmath.h>
9
11
13 : m_rect(rect)
14 , m_radius(0)
15 , m_dirty_geometry(true)
16 , m_geometry(QSGGeometry::defaultAttributes_Point2D(), 0)
17{
18 Q_UNUSED(m_reserved);
19 setGeometry(&m_geometry);
20 setIsRectangular(true);
21}
22
24{
25 m_rect = rect;
26 m_dirty_geometry = true;
27}
28
30{
31 m_radius = radius;
32 m_dirty_geometry = true;
34}
35
37{
38 if (m_dirty_geometry) {
39 updateGeometry();
40 m_dirty_geometry = false;
41 }
42}
43
44void QQuickDefaultClipNode::updateGeometry()
45{
47
48 if (qFuzzyIsNull(m_radius)) {
49 g->allocate(4);
51
52 } else {
53 int vertexCount = 0;
54
55 // Radius should never exceeds half of the width or half of the height
56 qreal radius = qMin(qMin(m_rect.width() / 2, m_rect.height() / 2), m_radius);
57 QRectF rect = m_rect;
59
60 int segments = qMin(30, qCeil(radius)); // Number of segments per corner.
61
62 g->allocate((segments + 1) * 4);
63
64 QVector2D *vertices = (QVector2D *)g->vertexData();
65
66 for (int part = 0; part < 2; ++part) {
67 for (int i = 0; i <= segments; ++i) {
68 //### Should change to calculate sin/cos only once.
69 qreal angle = qreal(0.5 * M_PI) * (part + i / qreal(segments));
72 qreal y = (part ? rect.bottom() : rect.top()) - radius * c; // current inner y-coordinate.
73 qreal lx = rect.left() - radius * s; // current inner left x-coordinate.
74 qreal rx = rect.right() + radius * s; // current inner right x-coordinate.
75
76 vertices[vertexCount++] = QVector2D(rx, y);
77 vertices[vertexCount++] = QVector2D(lx, y);
78 }
79 }
80
81 }
82#ifdef QSG_RUNTIME_DESCRIPTION
83#ifndef QT_NO_DEBUG_STREAM
85 {
86 QDebug dbg(&desc);
87 dbg << m_rect;
88 if (!qFuzzyIsNull(m_radius))
89 dbg << "radius" << m_radius;
90 }
91 qsgnode_set_description(this, desc);
92#endif
93#endif
94 setClipRect(m_rect);
96}
97
\inmodule QtCore
QQuickDefaultClipNode(const QRectF &)
void setRect(const QRectF &)
void setRadius(qreal radius)
\inmodule QtCore\reentrant
Definition qrect.h:484
constexpr qreal bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
Definition qrect.h:500
constexpr qreal height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:732
constexpr qreal width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:729
constexpr qreal left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:497
constexpr void adjust(qreal x1, qreal y1, qreal x2, qreal y2) noexcept
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition qrect.h:805
constexpr qreal top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:498
constexpr qreal right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
Definition qrect.h:499
const QSGGeometry * geometry() const
Returns this node's geometry.
Definition qsgnode.h:160
void setGeometry(QSGGeometry *geometry)
Sets the geometry of this node to geometry.
Definition qsgnode.cpp:764
void setClipRect(const QRectF &)
Sets the clip rect of this clip node to rect.
Definition qsgnode.cpp:1101
void setIsRectangular(bool rectHint)
Sets whether this clip node has a rectangular clip to rectHint.
Definition qsgnode.cpp:1081
The QSGGeometry class provides low-level storage for graphics primitives in the \l{Qt Quick Scene Gra...
Definition qsggeometry.h:15
static void updateRectGeometry(QSGGeometry *g, const QRectF &rect)
Updates the geometry g with the coordinates in rect.
@ DirtyGeometry
Definition qsgnode.h:74
void markDirty(DirtyState bits)
Notifies all connected renderers that the node has dirty bits.
Definition qsgnode.cpp:624
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QVector2D class represents a vector or vertex in 2D space.
Definition qvectornd.h:31
rect
[4]
Combined button and popup list for selecting options.
bool qFuzzyIsNull(qfloat16 f) noexcept
Definition qfloat16.h:349
qreal qFastSin(qreal x)
Definition qmath.h:240
qreal qFastCos(qreal x)
Definition qmath.h:250
int qCeil(T v)
Definition qmath.h:36
#define M_PI
Definition qmath.h:209
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
GLfloat angle
GLboolean GLboolean g
GLint y
GLdouble s
[6]
Definition qopenglext.h:235
const GLubyte * c
GLuint segments
void qsgnode_set_description(QSGNode *node, const QString &description)
Definition qsgnode.cpp:641
#define Q_UNUSED(x)
double qreal
Definition qtypes.h:187
p rx()++