aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/util
diff options
context:
space:
mode:
authorJocelyn Turcotte <jocelyn.turcotte@digia.com>2014-10-17 17:36:57 +0200
committerJocelyn Turcotte <jocelyn.turcotte@digia.com>2014-11-19 13:50:53 +0100
commit8c82d3b6aa254f85ed966ed04d204a6a2912555e (patch)
tree756439233540f8af5700f17f10f4be7659cee1f1 /src/quick/scenegraph/util
parent1f74dde59f8ecb8be3a41973ab5d8d435815edd6 (diff)
Allow setting the source rect on QSGSimpleTextureNode
This allows the QtQuick 2D Renderer to get this information without having to extract it from the QSGGeometry. Change-Id: Iec99c4bc910fea9c7d0e6712a418787254a70cb2 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Diffstat (limited to 'src/quick/scenegraph/util')
-rw-r--r--src/quick/scenegraph/util/qsgsimpletexturenode.cpp59
-rw-r--r--src/quick/scenegraph/util/qsgsimpletexturenode.h4
2 files changed, 53 insertions, 10 deletions
diff --git a/src/quick/scenegraph/util/qsgsimpletexturenode.cpp b/src/quick/scenegraph/util/qsgsimpletexturenode.cpp
index 1e7133cf26..27b9e656ec 100644
--- a/src/quick/scenegraph/util/qsgsimpletexturenode.cpp
+++ b/src/quick/scenegraph/util/qsgsimpletexturenode.cpp
@@ -42,12 +42,13 @@ class QSGSimpleTextureNodePrivate : public QSGGeometryNodePrivate
public:
QSGSimpleTextureNodePrivate()
: QSGGeometryNodePrivate()
- , m_texCoordMode(QSGSimpleTextureNode::NoTransform)
+ , texCoordMode(QSGSimpleTextureNode::NoTransform)
, isAtlasTexture(false)
, ownsTexture(false)
{}
- QSGSimpleTextureNode::TextureCoordinatesTransformMode m_texCoordMode;
+ QRectF sourceRect;
+ QSGSimpleTextureNode::TextureCoordinatesTransformMode texCoordMode;
uint isAtlasTexture : 1;
uint ownsTexture : 1;
};
@@ -55,13 +56,16 @@ public:
static void qsgsimpletexturenode_update(QSGGeometry *g,
QSGTexture *texture,
const QRectF &rect,
+ QRectF sourceRect,
QSGSimpleTextureNode::TextureCoordinatesTransformMode texCoordMode)
{
if (!texture)
return;
- QSize ts = texture->textureSize();
- QRectF sourceRect(0, 0, ts.width(), ts.height());
+ if (!sourceRect.width() || !sourceRect.height()) {
+ QSize ts = texture->textureSize();
+ sourceRect = QRectF(0, 0, ts.width(), ts.height());
+ }
// Maybe transform the texture coordinates
if (texCoordMode.testFlag(QSGSimpleTextureNode::MirrorHorizontally)) {
@@ -151,7 +155,7 @@ void QSGSimpleTextureNode::setRect(const QRectF &r)
return;
m_rect = r;
Q_D(QSGSimpleTextureNode);
- qsgsimpletexturenode_update(&m_geometry, texture(), m_rect, d->m_texCoordMode);
+ qsgsimpletexturenode_update(&m_geometry, texture(), m_rect, d->sourceRect, d->texCoordMode);
markDirty(DirtyGeometry);
}
@@ -172,6 +176,41 @@ QRectF QSGSimpleTextureNode::rect() const
}
/*!
+ Sets the source rect of this texture node to \a r.
+
+ \since 5.5
+ */
+void QSGSimpleTextureNode::setSourceRect(const QRectF &r)
+{
+ Q_D(QSGSimpleTextureNode);
+ if (d->sourceRect == r)
+ return;
+ d->sourceRect = r;
+ qsgsimpletexturenode_update(&m_geometry, texture(), m_rect, d->sourceRect, d->texCoordMode);
+ markDirty(DirtyGeometry);
+}
+
+/*!
+ \fn void QSGSimpleTextureNode::setSourceRect(qreal x, qreal y, qreal w, qreal h)
+ \overload
+ \since 5.5
+
+ Sets the rectangle of this texture node to show its texture from (\a x, \a y) and
+ have width \a w and height \a h relatively to the QSGTexture::textureSize.
+ */
+
+/*!
+ Returns the source rect of this texture node.
+
+ \since 5.5
+ */
+QRectF QSGSimpleTextureNode::sourceRect() const
+{
+ Q_D(const QSGSimpleTextureNode);
+ return d->sourceRect;
+}
+
+/*!
Sets the texture of this texture node to \a texture.
Use setOwnsTexture() to set whether the node should take
@@ -187,7 +226,7 @@ void QSGSimpleTextureNode::setTexture(QSGTexture *texture)
m_material.setTexture(texture);
m_opaque_material.setTexture(texture);
Q_D(QSGSimpleTextureNode);
- qsgsimpletexturenode_update(&m_geometry, texture, m_rect, d->m_texCoordMode);
+ qsgsimpletexturenode_update(&m_geometry, texture, m_rect, d->sourceRect, d->texCoordMode);
DirtyState dirty = DirtyMaterial;
// It would be tempting to skip the extra bit here and instead use
@@ -236,10 +275,10 @@ QSGTexture *QSGSimpleTextureNode::texture() const
void QSGSimpleTextureNode::setTextureCoordinatesTransform(QSGSimpleTextureNode::TextureCoordinatesTransformMode mode)
{
Q_D(QSGSimpleTextureNode);
- if (d->m_texCoordMode == mode)
+ if (d->texCoordMode == mode)
return;
- d->m_texCoordMode = mode;
- qsgsimpletexturenode_update(&m_geometry, texture(), m_rect, d->m_texCoordMode);
+ d->texCoordMode = mode;
+ qsgsimpletexturenode_update(&m_geometry, texture(), m_rect, d->sourceRect, d->texCoordMode);
markDirty(DirtyMaterial);
}
@@ -251,7 +290,7 @@ void QSGSimpleTextureNode::setTextureCoordinatesTransform(QSGSimpleTextureNode::
QSGSimpleTextureNode::TextureCoordinatesTransformMode QSGSimpleTextureNode::textureCoordinatesTransform() const
{
Q_D(const QSGSimpleTextureNode);
- return d->m_texCoordMode;
+ return d->texCoordMode;
}
/*!
diff --git a/src/quick/scenegraph/util/qsgsimpletexturenode.h b/src/quick/scenegraph/util/qsgsimpletexturenode.h
index 56f5c5a0df..60fa445fe0 100644
--- a/src/quick/scenegraph/util/qsgsimpletexturenode.h
+++ b/src/quick/scenegraph/util/qsgsimpletexturenode.h
@@ -52,6 +52,10 @@ public:
inline void setRect(qreal x, qreal y, qreal w, qreal h) { setRect(QRectF(x, y, w, h)); }
QRectF rect() const;
+ void setSourceRect(const QRectF &r);
+ inline void setSourceRect(qreal x, qreal y, qreal w, qreal h) { setSourceRect(QRectF(x, y, w, h)); }
+ QRectF sourceRect() const;
+
void setTexture(QSGTexture *texture);
QSGTexture *texture() const;