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
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
4#include "qsgninepatchnode.h"
5
7
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);
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
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
\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 left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:497
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
The QSGGeometry class provides low-level storage for graphics primitives in the \l{Qt Quick Scene Gra...
Definition qsggeometry.h:15
TexturedPoint2D * vertexDataAsTexturedPoint2D()
Convenience function to access the vertex data as a mutable array of QSGGeometry::TexturedPoint2D.
static void updateTexturedRectGeometry(QSGGeometry *g, const QRectF &rect, const QRectF &sourceRect)
Updates the geometry g with the coordinates in rect and texture coordinates from textureRect.
void allocate(int vertexCount, int indexCount=0)
Resizes the vertex and index data of this geometry object to fit vertexCount vertices and indexCount ...
quint16 * indexDataAsUShort()
Convenience function to access the index data as a mutable array of 16-bit unsigned integers.
static void rebuildGeometry(QSGTexture *texture, QSGGeometry *geometry, const QVector4D &padding, const QRectF &bounds, qreal dpr)
\inmodule QtQuick
Definition qsgtexture.h:20
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
constexpr void setWidth(int w) noexcept
Sets the width to the given width.
Definition qsize.h:136
constexpr void setHeight(int h) noexcept
Sets the height to the given height.
Definition qsize.h:139
The QVector4D class represents a vector or vertex in 4D space.
Definition qvectornd.h:330
constexpr float x() const noexcept
Returns the x coordinate of this point.
Definition qvectornd.h:878
constexpr float w() const noexcept
Returns the w coordinate of this point.
Definition qvectornd.h:881
constexpr float y() const noexcept
Returns the y coordinate of this point.
Definition qvectornd.h:879
constexpr float z() const noexcept
Returns the z coordinate of this point.
Definition qvectornd.h:880
Combined button and popup list for selecting options.
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLboolean r
[2]
GLenum GLuint texture
GLint y
const GLubyte * c
const GLfloat * tc
GLdouble GLdouble t
Definition qopenglext.h:243
GLfloat GLfloat p
[1]
static QT_BEGIN_NAMESPACE qreal dpr(const QWindow *w)
unsigned short quint16
Definition qtypes.h:48
double qreal
Definition qtypes.h:187
The QSGGeometry::TexturedPoint2D struct is a convenience struct for accessing 2D Points with texture ...
Definition qsggeometry.h:85
void set(float nx, float ny, float ntx, float nty)
Sets the position of the vertex to x and y and the texture coordinate to tx and ty.
Definition qsggeometry.h:88