Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsgninepatchnode.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
5
7
8/*!
9 \class QSGNinePatchNode
10 \inmodule QtQuick
11 \since 5.8
12 \internal
13 */
14
15/*!
16 \fn void QSGNinePatchNode::setTexture(QSGTexture *texture)
17 \internal
18 */
19
20/*!
21 \fn void QSGNinePatchNode::setBounds(const QRectF &bounds)
22 \internal
23 */
24
25/*!
26 \fn void QSGNinePatchNode::setDevicePixelRatio(qreal ratio)
27 \internal
28 */
29
30/*!
31 \fn void QSGNinePatchNode::setPadding(qreal left, qreal top, qreal right, qreal bottom)
32 \internal
33 */
34
35
36/*!
37 \fn void QSGNinePatchNode::update()
38 \internal
39 */
40
41void QSGNinePatchNode::rebuildGeometry(QSGTexture *texture, QSGGeometry *geometry, const QVector4D &padding,
42 const QRectF &bounds, qreal dpr)
43{
44 if (padding.x() <= 0 && padding.y() <= 0 && padding.z() <= 0 && padding.w() <= 0) {
45 geometry->allocate(4, 0);
46 QSGGeometry::updateTexturedRectGeometry(geometry, bounds, texture->normalizedTextureSubRect());
47 return;
48 }
49
50 QRectF tc = texture->normalizedTextureSubRect();
51 QSize ts = texture->textureSize();
52 ts.setHeight(ts.height() / dpr);
53 ts.setWidth(ts.width() / dpr);
54
55 qreal invtw = tc.width() / ts.width();
56 qreal invth = tc.height() / ts.height();
57
58 struct Coord { qreal p; qreal t; };
59 Coord cx[4] = { { bounds.left(), tc.left() },
60 { bounds.left() + padding.x(), tc.left() + padding.x() * invtw },
61 { bounds.right() - padding.z(), tc.right() - padding.z() * invtw },
62 { bounds.right(), tc.right() }
63 };
64 Coord cy[4] = { { bounds.top(), tc.top() },
65 { bounds.top() + padding.y(), tc.top() + padding.y() * invth },
66 { bounds.bottom() - padding.w(), tc.bottom() - padding.w() * invth },
67 { bounds.bottom(), tc.bottom() }
68 };
69
70 geometry->allocate(16, 28);
71 QSGGeometry::TexturedPoint2D *v = geometry->vertexDataAsTexturedPoint2D();
72 for (int y = 0; y < 4; ++y) {
73 for (int x = 0; x < 4; ++x) {
74 v->set(cx[x].p, cy[y].p, cx[x].t, cy[y].t);
75 ++v;
76 }
77 }
78
79 quint16 *i = geometry->indexDataAsUShort();
80 for (int r = 0; r < 3; ++r) {
81 if (r > 0)
82 *i++ = 4 * r;
83 for (int c = 0; c < 4; ++c) {
84 i[0] = 4 * r + c;
85 i[1] = 4 * r + c + 4;
86 i += 2;
87 }
88 if (r < 2)
89 *i++ = 4 * r + 3 + 4;
90 }
91}
92
93QT_END_NAMESPACE