From 40c9607befb1cce6ef771dc9bd77ac91a7e1f3b4 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Wed, 5 Oct 2011 09:37:24 +0200 Subject: [PATCH] Support atlased textures in QSGNinePatchNode Change-Id: I0433d15c22d0f7b9de2d5a5590f51a554e56a912 Reviewed-on: http://codereview.qt-project.org/6028 Reviewed-by: Qt Sanity Bot Reviewed-by: Kim M. Kalland --- src/declarative/items/qsgninepatchnode.cpp | 35 ++++++++++++++++++------------ src/declarative/items/qsgninepatchnode_p.h | 2 +- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/declarative/items/qsgninepatchnode.cpp b/src/declarative/items/qsgninepatchnode.cpp index 5d1ff98..3658b3c 100644 --- a/src/declarative/items/qsgninepatchnode.cpp +++ b/src/declarative/items/qsgninepatchnode.cpp @@ -55,7 +55,7 @@ QSGNinePatchNode::QSGNinePatchNode() setGeometry(&m_geometry); m_geometry.setDrawingMode(GL_TRIANGLES); #ifdef QML_RUNTIME_TESTING - description = "borderimage"; + description = QLatin1String("borderimage"); #endif } @@ -145,6 +145,9 @@ void QSGNinePatchNode::update() float tw = m_material.texture()->textureSize().width(); float th = m_material.texture()->textureSize().height(); + QRectF textureSubRect = m_material.texture()->textureSubRect(); + QSize textureSize = m_material.texture()->textureSize(); + float rightBorder = tw - m_innerRect.right(); float bottomBorder = th - m_innerRect.bottom(); @@ -202,26 +205,26 @@ void QSGNinePatchNode::update() float yTexChunk1 = m_innerRect.top() / th; float yTexChunk2 = m_innerRect.bottom() / th; - fillRow(v, 0, 0, xChunkCount, xChunkSize); - fillRow(v, m_innerRect.y(), yTexChunk1, xChunkCount, xChunkSize); + fillRow(v, 0, 0, xChunkCount, xChunkSize, textureSubRect, textureSize); + fillRow(v, m_innerRect.y(), yTexChunk1, xChunkCount, xChunkSize, textureSubRect, textureSize); for (int yc=0; yctextureSize().width(); + ty = tsr.y() + ty * tsr.width(); + + float tw = ts.width(); float rightBorder = tw - m_innerRect.right(); - float xTexChunk1 = m_innerRect.left() / tw; - float xTexChunk2 = m_innerRect.right() / tw; + float xTexChunk1 = tsr.left() + tsr.width() * m_innerRect.left() / tw; + float xTexChunk2 = tsr.left() + tsr.width() * m_innerRect.right() / tw; - v++->set(0, y, 0, ty); + v++->set(0, y, tsr.left(), ty); v++->set(m_innerRect.x(), y, xTexChunk1, ty); for (int xc=0; xcset(m_targetRect.width() - rightBorder, y, xTexChunk2, ty); - v++->set(m_targetRect.width(), y, 1, ty); + v++->set(m_targetRect.width(), y, tsr.right(), ty); } diff --git a/src/declarative/items/qsgninepatchnode_p.h b/src/declarative/items/qsgninepatchnode_p.h index 0062d0b..fd0a0c5 100644 --- a/src/declarative/items/qsgninepatchnode_p.h +++ b/src/declarative/items/qsgninepatchnode_p.h @@ -81,7 +81,7 @@ public: void update(); private: - void fillRow(QSGGeometry::TexturedPoint2D *&v, float y, float ty, int xChunkCount, float xChunkSize); + void fillRow(QSGGeometry::TexturedPoint2D *&v, float y, float ty, int xChunkCount, float xChunkSize, const QRectF &tsr, const QSize &ts); QRectF m_targetRect; QRectF m_innerRect; QSGOpaqueTextureMaterial m_material; -- 2.7.4