From 929b7a43fd3649a4806f52483cf0e08214cb93e3 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Wed, 5 Jun 2024 10:34:19 +0200 Subject: [PATCH] gradient rendering fixed --- playground/shadows/ArcPage.cpp | 48 +++++++++++++++++++++++------- playground/shadows/ShadowedArc.cpp | 20 ++++--------- playground/shadows/ShadowedArc.h | 5 ++-- src/nodes/QskArcRenderer.cpp | 15 ++++++---- 4 files changed, 55 insertions(+), 33 deletions(-) diff --git a/playground/shadows/ArcPage.cpp b/playground/shadows/ArcPage.cpp index e8618e04..25498877 100644 --- a/playground/shadows/ArcPage.cpp +++ b/playground/shadows/ArcPage.cpp @@ -48,24 +48,50 @@ namespace } } }; + + class Arc : public ShadowedArc + { + public: + Arc() + { + setStartAngle( 45.0 ); + setSpanAngle( 270.0 ); + setThickness( 10.0 ); + + setBorderWidth( 2.0 ); + setBorderColor( Qt::black ); + +#if 0 + const QskGradientStops stops = + { + { 0.1, Qt::darkRed }, + { 0.1, Qt::darkYellow }, + { 0.5, Qt::darkYellow }, + { 0.5, Qt::darkBlue }, + { 0.75, Qt::darkBlue }, + { 0.75, Qt::darkRed } + }; +#else + const QskGradientStops stops = + { + { 0.1, Qt::darkRed }, + { 0.5, Qt::darkYellow }, + { 0.75, Qt::darkBlue }, + { 1.0, Qt::darkRed } + }; +#endif + + setFillGradient( stops ); + } + }; } ArcPage::ArcPage( QQuickItem* parent ) : QskLinearBox( Qt::Vertical, parent ) { - auto arc = new ShadowedArc(); + auto arc = new Arc(); arc->setMargins( 40 ); // some extra space for testing the offsets - { - // initial settings - arc->setStartAngle( 45.0 ); - arc->setSpanAngle( 270.0 ); - arc->setThickness( 10.0 ); - - arc->setBorderWidth( 2.0 ); - arc->setBorderColor( Qt::darkBlue ); - } - auto panel = new ControlPanel( arc ); panel->setSizePolicy( Qt::Vertical, QskSizePolicy::Fixed ); diff --git a/playground/shadows/ShadowedArc.cpp b/playground/shadows/ShadowedArc.cpp index 6337bf9a..8bf9ab47 100644 --- a/playground/shadows/ShadowedArc.cpp +++ b/playground/shadows/ShadowedArc.cpp @@ -101,17 +101,7 @@ ShadowedArc::ShadowedArc( QQuickItem* parent ) setArcMetrics( { 0.0, 360.0, 1.0, Qt::RelativeSize } ); - //setFillColor( Qt::darkRed ); - - const QskGradientStops stops = - { - { 0.1, Qt::darkRed }, - { 0.5, Qt::darkYellow }, - { 0.75, Qt::darkBlue }, - { 1.0, Qt::darkRed } - }; - - setGradientHint( Arc, stops ); + setFillGradient( Qt::white ); setBorderWidth( 0 ); setBorderColor( Qt::gray ); @@ -226,14 +216,14 @@ qreal ShadowedArc::blurRadius() const return shadowMetrics().blurRadius(); } -void ShadowedArc::setFillColor( const QColor& color ) +void ShadowedArc::setFillGradient( const QskGradient& gradient ) { - setColor( Arc, color ); + setGradientHint( Arc, gradient ); } -QColor ShadowedArc::fillColor() const +QskGradient ShadowedArc::fillGradient() const { - return color( Arc ); + return gradientHint( Arc ); } void ShadowedArc::setShadowColor( const QColor& color ) diff --git a/playground/shadows/ShadowedArc.h b/playground/shadows/ShadowedArc.h index c8f486d3..2f683e26 100644 --- a/playground/shadows/ShadowedArc.h +++ b/playground/shadows/ShadowedArc.h @@ -9,6 +9,7 @@ class QskShadowMetrics; class QskArcMetrics; +class QskGradient; class ShadowedArc : public QskControl { @@ -35,7 +36,7 @@ class ShadowedArc : public QskControl qreal blurRadius() const; QColor borderColor() const; - QColor fillColor() const; + QskGradient fillGradient() const; QColor shadowColor() const; public Q_SLOTS: @@ -52,7 +53,7 @@ class ShadowedArc : public QskControl void setBlurRadius( qreal ); void setBorderColor( const QColor& ); - void setFillColor( const QColor& ); + void setFillGradient( const QskGradient& ); void setShadowColor( const QColor& ); private: diff --git a/src/nodes/QskArcRenderer.cpp b/src/nodes/QskArcRenderer.cpp index 211ff994..8022f98a 100644 --- a/src/nodes/QskArcRenderer.cpp +++ b/src/nodes/QskArcRenderer.cpp @@ -166,15 +166,20 @@ namespace it.advance(); // the first stop is always covered by the contour } - const auto stepCount = arcLineCount(); - const auto stepSize = ( m_radians2 - m_radians1 ) / ( stepCount - 1 ); + const auto count = arcLineCount(); - for ( int i = 0; i < stepCount; i++ ) + const qreal stepMax = count - 1; + const auto stepSize = ( m_radians2 - m_radians1 ) / stepMax; + + for ( int i = 0; i < count; i++ ) { - const auto progress = qreal( i ) / stepCount; + const auto progress = i / stepMax; - for ( ; it.position() < progress; it.advance() ) + while( !it.isDone() && ( it.position() < progress ) ) + { setFillLine( radiansAt( it.position() ), it.color(), *l++ ); + it.advance(); + } const auto color = it.colorAt( progress ); setFillLine( m_radians1 + i * stepSize, color, *l++ );