From b17cabaa833b5d2e5a92b58cdafcf0ed65817dfc Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Fri, 20 Sep 2024 11:58:32 +0200 Subject: [PATCH] wip --- src/nodes/QskArcRenderNode.cpp | 80 +++++++++++++++++++++++++------ src/nodes/QskArcRenderer.cpp | 4 +- src/nodes/QskArcRenderer.h | 3 +- src/nodes/QskBoxRectangleNode.cpp | 5 +- 4 files changed, 73 insertions(+), 19 deletions(-) diff --git a/src/nodes/QskArcRenderNode.cpp b/src/nodes/QskArcRenderNode.cpp index 984aab61..e2462cba 100644 --- a/src/nodes/QskArcRenderNode.cpp +++ b/src/nodes/QskArcRenderNode.cpp @@ -20,6 +20,31 @@ class QskArcRenderNodePrivate final : public QskFillNodePrivate node->resetGeometry(); } + inline bool updateHash( const QRectF& rect, const QskArcMetrics& metrics, + bool radial, qreal borderWidth, const QColor& borderColor, + const QskGradient& gradient ) + { + QskHashValue value = 3496; + + value = qHashBits( &rect, sizeof( QRectF ), value ); + value = metrics.hash( value ); + value = qHash( radial, value ); + value = qHash( borderWidth, value ); + value = qHashBits( &borderColor, sizeof( borderColor ), value ); + + if ( gradient.isVisible() ) + value = gradient.hash( value ); + + if ( hash != value ) + { + hash = value; + return true; + } + + return false; + } + + private: QskHashValue hash = 0; }; @@ -39,10 +64,45 @@ void QskArcRenderNode::updateFilling( const QRectF& rect, } void QskArcRenderNode::updateFilling( const QRectF& rect, - const QskArcMetrics& metrics, bool radial, + const QskArcMetrics& arcMetrics, bool radial, qreal borderWidth, const QskGradient& gradient ) { - updateArc( rect, metrics, radial, borderWidth, QColor(), gradient ); + Q_D( QskArcRenderNode ); + + const auto metrics = arcMetrics.toAbsolute( rect.size() ); + const auto borderMax = 0.5 * metrics.thickness(); + + const bool hasFill = gradient.isVisible() && ( borderWidth < borderMax ); + const bool hasBorder = false; + + if ( rect.isEmpty() || metrics.isNull() || !( hasFill || hasBorder ) ) + { + d->resetNode( this ); + return; + } + + borderWidth = qMin( borderWidth, borderMax ); + + if ( !d->updateHash( rect, metrics, radial, borderWidth, QColor(), gradient ) ) + { + d->resetNode( this ); + return; + } + +#if 1 + const bool coloredGeometry = hasHint( PreferColoredGeometry ) + && QskArcRenderer::isGradientSupported( rect, metrics, gradient ); + Q_ASSERT( coloredGeometry ); // TODO ... +#endif + + auto& geometry = *this->geometry(); + + setColoring( QskFillNode::Polychrome ); + + QskArcRenderer::setColoredFillLines( rect, metrics, radial, + borderWidth, gradient, geometry ); + + markDirty( QSGNode::DirtyGeometry ); } void QskArcRenderNode::updateBorder( const QRectF& rect, @@ -73,19 +133,11 @@ void QskArcRenderNode::updateArc( borderWidth = qMin( borderWidth, borderMax ); - QskHashValue hash = 3496; - - hash = qHashBits( &rect, sizeof( QRectF ), hash ); - hash = qHash( borderWidth, hash ); - hash = qHashBits( &borderColor, sizeof( borderColor ), hash ); - hash = metrics.hash( hash ); - hash = gradient.hash( hash ); - hash = qHash( radial, hash ); - - if ( hash == d->hash ) + if ( !d->updateHash( rect, metrics, radial, borderWidth, borderColor, gradient ) ) + { + d->resetNode( this ); return; - - d->hash = hash; + } #if 1 const bool coloredGeometry = hasHint( PreferColoredGeometry ) diff --git a/src/nodes/QskArcRenderer.cpp b/src/nodes/QskArcRenderer.cpp index db8c6306..7569939d 100644 --- a/src/nodes/QskArcRenderer.cpp +++ b/src/nodes/QskArcRenderer.cpp @@ -505,7 +505,7 @@ void QskArcRenderer::setColoredBorderLines( const QRectF& rect, } void QskArcRenderer::setColoredFillLines( const QRectF& rect, const QskArcMetrics& metrics, - bool radial, const QskGradient& gradient, QSGGeometry& geometry ) + bool radial, qreal borderWidth, const QskGradient& gradient, QSGGeometry& geometry ) { geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip ); geometry.markVertexDataDirty(); @@ -520,7 +520,7 @@ void QskArcRenderer::setColoredFillLines( const QRectF& rect, const QskArcMetric if ( const auto lines = qskAllocateColoredLines( geometry, renderer.fillCount() ) ) { - renderer.renderArc( metrics.thickness(), 0.0, lines, + renderer.renderArc( metrics.thickness(), borderWidth, lines, static_cast< QskVertex::ColoredLine* >( nullptr ) ); } } diff --git a/src/nodes/QskArcRenderer.h b/src/nodes/QskArcRenderer.h index 10b740f3..aa0e40f2 100644 --- a/src/nodes/QskArcRenderer.h +++ b/src/nodes/QskArcRenderer.h @@ -45,7 +45,8 @@ namespace QskArcRenderer const QColor& borderColor, QSGGeometry& ); QSK_EXPORT void setColoredFillLines( const QRectF&, - const QskArcMetrics&, bool radial, const QskGradient&, QSGGeometry& ); + const QskArcMetrics&, bool radial, qreal borderWidth, + const QskGradient&, QSGGeometry& ); QSK_EXPORT void setColoredBorderAndFillLines( const QRectF&, const QskArcMetrics&, bool radial, qreal borderWidth, diff --git a/src/nodes/QskBoxRectangleNode.cpp b/src/nodes/QskBoxRectangleNode.cpp index ec8b2a7e..001745b3 100644 --- a/src/nodes/QskBoxRectangleNode.cpp +++ b/src/nodes/QskBoxRectangleNode.cpp @@ -21,7 +21,7 @@ class QskBoxRectangleNodePrivate final : public QskFillNodePrivate node->resetGeometry(); } - bool updateMetrics( const QRectF& rect, + inline bool updateMetrics( const QRectF& rect, const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& borderMetrics ) { QskHashValue hash = 13000; @@ -33,7 +33,8 @@ class QskBoxRectangleNodePrivate final : public QskFillNodePrivate return updateValue( m_metricsHash, hash ); } - bool updateColors( const QskBoxBorderColors& borderColors, const QskGradient& gradient ) + inline bool updateColors( + const QskBoxBorderColors& borderColors, const QskGradient& gradient ) { QskHashValue hash = 13000;