From 2c13fc9fefad28ce2b63134e4be4d5e40ff1e91d Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Sat, 21 May 2016 16:39:09 +0200 Subject: Migrate to the new QSGNinePatchNode This makes the style node compatible with backends using graphics APIs other than OpenGL. Change-Id: I97f169d9f82fb83660f95891b0a7c94b5f8dbde9 Reviewed-by: Gunnar Sletta --- src/controls/Private/qquickstyleitem.cpp | 125 +------------------------------ 1 file changed, 3 insertions(+), 122 deletions(-) diff --git a/src/controls/Private/qquickstyleitem.cpp b/src/controls/Private/qquickstyleitem.cpp index 4f6aec08..3fe68230 100644 --- a/src/controls/Private/qquickstyleitem.cpp +++ b/src/controls/Private/qquickstyleitem.cpp @@ -45,12 +45,12 @@ #include #include #include -#include #include #include "private/qguiapplication_p.h" #include #include #include +#include #include "../qquickmenuitem_p.h" QT_BEGIN_NAMESPACE @@ -96,122 +96,6 @@ CGContextRef qt_mac_cg_context(const QPaintDevice *pdev) #endif -class QQuickStyleNode1 : public QSGNinePatchNode -{ -public: - QQuickStyleNode1() - : m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4) - { - m_geometry.setDrawingMode(GL_TRIANGLE_STRIP); - setGeometry(&m_geometry); - // The texture material has mipmap filtering set to Nearest by default. This is not ideal. - m_material.setMipmapFiltering(QSGTexture::None); - setMaterial(&m_material); - } - - ~QQuickStyleNode1() - { - delete m_material.texture(); - } - - virtual void setTexture(QSGTexture *texture) - { - delete m_material.texture(); - m_material.setTexture(texture); - } - - virtual void setBounds(const QRectF &bounds) - { - m_bounds = bounds; - } - - virtual void setDevicePixelRatio(qreal ratio) - { - m_devicePixelRatio = ratio; - } - - virtual void setPadding(qreal left, qreal top, qreal right, qreal bottom) - { - m_paddingLeft = left; - m_paddingTop = top; - m_paddingRight = right; - m_paddingBottom = bottom; - } - - virtual void update() { - QSGTexture *texture = m_material.texture(); - - if (m_paddingLeft <= 0 && m_paddingTop <= 0 && m_paddingRight <= 0 && m_paddingBottom <= 0) { - m_geometry.allocate(4, 0); - QSGGeometry::updateTexturedRectGeometry(&m_geometry, m_bounds, texture->normalizedTextureSubRect()); - markDirty(QSGNode::DirtyGeometry | QSGNode::DirtyMaterial); - return; - } - - QRectF tc = texture->normalizedTextureSubRect(); - QSize ts = texture->textureSize(); - ts.setHeight(ts.height() / m_devicePixelRatio); - ts.setWidth(ts.width() / m_devicePixelRatio); - - qreal invtw = tc.width() / ts.width(); - qreal invth = tc.height() / ts.height(); - - struct Coord { qreal p; qreal t; }; - Coord cx[4] = { { m_bounds.left(), tc.left() }, - { m_bounds.left() + m_paddingLeft, tc.left() + m_paddingLeft * invtw }, - { m_bounds.right() - m_paddingRight, tc.right() - m_paddingRight * invtw }, - { m_bounds.right(), tc.right() } - }; - Coord cy[4] = { { m_bounds.top(), tc.top() }, - { m_bounds.top() + m_paddingTop, tc.top() + m_paddingTop * invth }, - { m_bounds.bottom() - m_paddingBottom, tc.bottom() - m_paddingBottom * invth }, - { m_bounds.bottom(), tc.bottom() } - }; - - m_geometry.allocate(16, 28); - QSGGeometry::TexturedPoint2D *v = m_geometry.vertexDataAsTexturedPoint2D(); - for (int y=0; y<4; ++y) { - for (int x=0; x<4; ++x) { - v->set(cx[x].p, cy[y].p, cx[x].t, cy[y].t); - ++v; - } - } - - quint16 *i = m_geometry.indexDataAsUShort(); - for (int r=0; r<3; ++r) { - if (r > 0) - *i++ = 4 * r; - for (int c=0; c<4; ++c) { - i[0] = 4 * r + c; - i[1] = 4 * r + c + 4; - i+=2; - } - if (r < 2) - *i++ = 4 * r + 3 + 4; - } - - markDirty(QSGNode::DirtyGeometry | QSGNode::DirtyMaterial); - -// v = m_geometry.vertexDataAsTexturedPoint2D(); -// for (int j=0; j(node); - if (!styleNode) { - styleNode = QQuickItemPrivate::get(this)->sceneGraphContext()->createNinePatchNode(); - if (!styleNode) - styleNode = new QQuickStyleNode1; - } + if (!styleNode) + styleNode = window()->createNinePatchNode(); #ifdef QSG_RUNTIME_DESCRIPTION qsgnode_set_description(styleNode, -- cgit v1.2.1