From fbd178a4abb5fa9406c8053534577f5b0551236d Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Fri, 21 Jan 2022 07:42:23 +0100 Subject: [PATCH] incorporate feedback from Uwe --- src/common/QskBoxBorderColors.cpp | 9 ++-- src/common/QskBoxBorderColors.h | 2 +- src/nodes/QskBoxNode.cpp | 3 +- src/nodes/QskBoxRendererEllipse.cpp | 70 ++++++++++++++++------------- src/nodes/QskBoxRendererRect.cpp | 33 ++++++++------ 5 files changed, 65 insertions(+), 52 deletions(-) diff --git a/src/common/QskBoxBorderColors.cpp b/src/common/QskBoxBorderColors.cpp index 0acd4b17..1dc4f5b3 100644 --- a/src/common/QskBoxBorderColors.cpp +++ b/src/common/QskBoxBorderColors.cpp @@ -22,9 +22,9 @@ static void qskRegisterBoxBorderColors() Q_CONSTRUCTOR_FUNCTION( qskRegisterBoxBorderColors ) -static inline void qskSetGradients( const QskGradient& c, QskGradient* gradients ) +static inline void qskSetGradients( const QskGradient& gradient, QskGradient* gradients ) { - gradients[ 0 ] = gradients[ 1 ] = gradients[ 2 ] = gradients[ 3 ] = c; + gradients[ 0 ] = gradients[ 1 ] = gradients[ 2 ] = gradients[ 3 ] = gradient; } static inline void qskSetGradients( @@ -110,7 +110,7 @@ void QskBoxBorderColors::setGradientAt( Qt::Edges edges, const QskGradient& grad m_gradients[ Qsk::Bottom ] = gradient; } -QskGradient QskBoxBorderColors::gradientAt( Qt::Edge edge ) const +const QskGradient& QskBoxBorderColors::gradientAt( Qt::Edge edge ) const { switch ( edge ) { @@ -127,7 +127,8 @@ QskGradient QskBoxBorderColors::gradientAt( Qt::Edge edge ) const return m_gradients[ Qsk::Bottom ]; } - return QColor(); + static QskGradient noGradient; + return noGradient; } bool QskBoxBorderColors::isVisible() const diff --git a/src/common/QskBoxBorderColors.h b/src/common/QskBoxBorderColors.h index fae443ae..daec2b68 100644 --- a/src/common/QskBoxBorderColors.h +++ b/src/common/QskBoxBorderColors.h @@ -42,7 +42,7 @@ class QSK_EXPORT QskBoxBorderColors QskGradient gradient( Qsk::Position ) const; void setGradientAt( Qt::Edges, const QskGradient& ); - QskGradient gradientAt( Qt::Edge ) const; + const QskGradient& gradientAt( Qt::Edge ) const; QskBoxBorderColors interpolated( const QskBoxBorderColors&, qreal value ) const; diff --git a/src/nodes/QskBoxNode.cpp b/src/nodes/QskBoxNode.cpp index 106a75e8..586157ba 100644 --- a/src/nodes/QskBoxNode.cpp +++ b/src/nodes/QskBoxNode.cpp @@ -117,7 +117,8 @@ void QskBoxNode::setBoxData( const QRectF& rect, { if ( isFillMonochrome && isBorderMonochrome ) { - if ( borderColors.gradient( Qsk::Left ) == fillGradient.startColor() ) + if ( borderColors.gradient( Qsk::Left ).startColor() + == fillGradient.startColor() ) { // we can draw border and background in one hasBorder = false; diff --git a/src/nodes/QskBoxRendererEllipse.cpp b/src/nodes/QskBoxRendererEllipse.cpp index f4cb373d..90c0284e 100644 --- a/src/nodes/QskBoxRendererEllipse.cpp +++ b/src/nodes/QskBoxRendererEllipse.cpp @@ -102,6 +102,21 @@ namespace { return qMax( 0, gradient.stops().count() - 2 ); } + + static inline QRgb qskRgbGradientStart( const QskGradient& gradient ) + { + return gradient.startColor().rgba(); + } + + static inline QRgb qskRgbGradientEnd( const QskGradient& gradient ) + { + return gradient.endColor().rgba(); + } + + static inline QRgb qskRgbBorder( const QskBoxBorderColors& borderColors ) + { + return qskRgbGradientStart( borderColors.gradient( Qsk::Left ) ); + } } namespace @@ -568,7 +583,7 @@ namespace } template< class BorderMap, class FillMap > - void createLines( Qt::Orientation orientation, Line* borderLines, + inline void createLines( Qt::Orientation orientation, Line* borderLines, const BorderMap& borderMapTL, const BorderMap& borderMapTR, const BorderMap& borderMapBL, const BorderMap& borderMapBR, Line* fillLines, FillMap& fillMap ) @@ -690,8 +705,6 @@ namespace { if( additionalGradientStops( borderMapTR.gradient() ) > 0 ) { - auto stops = borderMapTR.gradient().stops(); - float x1TR = c[ TopRight ].centerX + v.dx1( TopRight ), y1TR = c[ TopRight ].centerY - v.dy1( TopRight ), x2TR = c[ TopRight ].centerX + v.dx2( TopRight ), @@ -709,8 +722,6 @@ namespace if( additionalGradientStops( borderMapBL.gradient() ) > 0 ) { - auto stops = borderMapBL.gradient().stops(); - float x1BL = c[ BottomLeft ].centerX - v.dx1( BottomLeft ), y1BL = c[ BottomLeft ].centerY + v.dy1( BottomLeft ), x2BL = c[ BottomLeft ].centerX - v.dx2( BottomLeft ), @@ -731,8 +742,6 @@ namespace { if( additionalGradientStops( borderMapTL.gradient() ) > 0 ) { - auto stops = borderMapTL.gradient().stops(); - float x1TL = c[ TopLeft ].centerX - v.dx1( TopLeft ), y1TL = c[ TopLeft ].centerY - v.dy1( TopLeft ), x2TL = c[ TopLeft ].centerX - v.dx2( TopLeft ), @@ -750,8 +759,6 @@ namespace if( additionalGradientStops( borderMapBR.gradient() ) > 0 ) { - auto stops = borderMapBR.gradient().stops(); - float x1BR = c[ BottomRight ].centerX + v.dx1( BottomRight ), y1BR = c[ BottomRight ].centerY + v.dy1( BottomRight ), x2BR = c[ BottomRight ].centerX + v.dx2( BottomRight ), @@ -990,7 +997,7 @@ static inline void qskRenderBorder( const QskBoxRenderer::Metrics& metrics, if ( colors.isMonochrome() ) { - qskRenderBorderLines( metrics, orientation, line, BorderMapSolid( c.gradient( Qsk::Left ).startColor().rgb() ) ); + qskRenderBorderLines( metrics, orientation, line, BorderMapSolid( qskRgbBorder( c ) ) ); } else { @@ -1000,14 +1007,14 @@ static inline void qskRenderBorder( const QskBoxRenderer::Metrics& metrics, right = c.gradient( Qsk::Right ), bottom = c.gradient( Qsk::Bottom ); qskRenderBorderLines( metrics, orientation, line, - BorderMapGradient( stepCount, top.startColor().rgb(), - left.endColor().rgb(), left ), - BorderMapGradient( stepCount, right.startColor().rgb(), - top.endColor().rgb(), top ), - BorderMapGradient( stepCount, left.startColor().rgb(), - bottom.endColor().rgb(), bottom ), - BorderMapGradient( stepCount, bottom.startColor().rgb(), - right.endColor().rgb(), right ) ); + BorderMapGradient( stepCount, qskRgbGradientStart( top ), + qskRgbGradientEnd( left ), left ), + BorderMapGradient( stepCount, qskRgbGradientStart( right ), + qskRgbGradientEnd( top ), top ), + BorderMapGradient( stepCount, qskRgbGradientStart( left ), + qskRgbGradientEnd( bottom ), bottom ), + BorderMapGradient( stepCount, qskRgbGradientStart( bottom ), + qskRgbGradientEnd( right ), right ) ); } } @@ -1037,7 +1044,7 @@ static inline void qskRenderBoxRandom( if ( bc.isMonochrome() ) { - const BorderMapSolid borderMap( bc.gradient( Qsk::Left ).startColor().rgb() ); + const BorderMapSolid borderMap( qskRgbBorder( bc.gradient( Qsk::Left ) ) ); if ( gradient.isMonochrome() ) { @@ -1056,18 +1063,17 @@ static inline void qskRenderBoxRandom( { const int n = metrics.corner[ 0 ].stepCount; - const BorderMapGradient tl( n, bc.gradient( Qsk::Top ).startColor().rgb(), - bc.gradient( Qsk::Left ).endColor().rgb(), - borderColors.gradient( Qsk::Left ) ); - const BorderMapGradient tr( n, bc.gradient( Qsk::Right ).startColor().rgb(), - bc.gradient( Qsk::Top ).endColor().rgb(), - borderColors.gradient( Qsk::Top ) ); - const BorderMapGradient bl( n, bc.gradient( Qsk::Left ).startColor().rgb(), - bc.gradient( Qsk::Bottom ).endColor().rgb(), - borderColors.gradient( Qsk::Bottom ) ); - const BorderMapGradient br( n, bc.gradient( Qsk::Bottom ).startColor().rgb(), - bc.gradient( Qsk::Right ).endColor().rgb(), - borderColors.gradient( Qsk::Right ) ); + auto left = bc.gradient( Qsk::Left ), top = bc.gradient( Qsk::Top ), + right = bc.gradient( Qsk::Right ), bottom = bc.gradient( Qsk::Bottom ); + + const BorderMapGradient tl( n, qskRgbGradientStart( top.startColor() ), + qskRgbGradientEnd( left.endColor() ), left ); + const BorderMapGradient tr( n, qskRgbGradientStart( right ), + qskRgbGradientEnd( top ), top ); + const BorderMapGradient bl( n, qskRgbGradientStart( left ), + qskRgbGradientEnd( bottom ), bottom ); + const BorderMapGradient br( n, qskRgbGradientStart( bottom ), + qskRgbGradientEnd( right ), right ); if ( gradient.isMonochrome() ) { @@ -1270,7 +1276,7 @@ void QskBoxRenderer::renderRectellipseBorder( const int stepCount = metrics.corner[ 0 ].stepCount; const int lineCount = 4 * ( stepCount + 1 ) + 1; - const auto line = allocateLines< ColoredLine >( geometry, lineCount ); + const auto line = allocateLines< Line >( geometry, lineCount ); qskRenderBorderLines( metrics, Qt::Vertical, line, BorderMapNone() ); } diff --git a/src/nodes/QskBoxRendererRect.cpp b/src/nodes/QskBoxRendererRect.cpp index 9fdd4a34..339957f2 100644 --- a/src/nodes/QskBoxRendererRect.cpp +++ b/src/nodes/QskBoxRendererRect.cpp @@ -429,48 +429,53 @@ static inline void qskCreateBorder( // qdebug - for( const QskGradientStop& stop : gradientBottom.stops() ) + const qreal dx1 = in.right - in.left; + const qreal dx2 = out.right - out.left; + const qreal dy1 = in.top - in.bottom; + const qreal dy2 = out.top - out.bottom; + + for( const auto& stop : gradientBottom.stops() ) { const Color c( stop.color() ); - const qreal x1 = in.right - stop.position() * ( in.right - in.left ); - const qreal x2 = out.right - stop.position() * ( out.right - out.left ); + const qreal x1 = in.right - stop.position() * dx1; + const qreal x2 = out.right - stop.position() * dx2; const qreal y1 = in.bottom; const qreal y2 = out.bottom; ( line++ )->setLine( x1, y1, x2, y2, c ); } - for( const QskGradientStop& stop : gradientLeft.stops() ) + for( const auto& stop : gradientLeft.stops() ) { const Color c( stop.color() ); const qreal x1 = in.left; const qreal x2 = out.left; - const qreal y1 = in.bottom + stop.position() * ( in.top - in.bottom ); - const qreal y2 = out.bottom + stop.position() * ( out.top - out.bottom ); + const qreal y1 = in.bottom + stop.position() * dy1; + const qreal y2 = out.bottom + stop.position() * dy2; ( line++ )->setLine( x1, y1, x2, y2, c ); } - for( const QskGradientStop& stop : gradientTop.stops() ) + for( const auto& stop : gradientTop.stops() ) { const Color c( stop.color() ); - const qreal x1 = in.left + stop.position() * ( in.right - in.left ); - const qreal x2 = out.left + stop.position() * ( out.right - out.left ); + const qreal x1 = in.left + stop.position() * dx1; + const qreal x2 = out.left + stop.position() * dx2; const qreal y1 = in.top; const qreal y2 = out.top; ( line++ )->setLine( x1, y1, x2, y2, c ); } - for( const QskGradientStop& stop : gradientRight.stops() ) + for( const auto& stop : gradientRight.stops() ) { const Color c( stop.color() ); const qreal x1 = in.right; const qreal x2 = out.right; // ( 1 - stop.position() ) because we want to make the gradients go // around the border clock-wise: - const qreal y1 = in.bottom + ( 1 - stop.position() ) * ( in.top - in.bottom ); - const qreal y2 = out.bottom + ( 1 - stop.position() ) * ( out.top - out.bottom ); + const qreal y1 = in.bottom + ( 1 - stop.position() ) * dy1; + const qreal y2 = out.bottom + ( 1 - stop.position() ) * dy2; ( line++ )->setLine( x1, y1, x2, y2, c ); } @@ -491,7 +496,7 @@ void QskBoxRenderer::renderRectBorder( return; } - const auto line = allocateLines< ColoredLine >( geometry, 4 + 1 ); + const auto line = allocateLines< Line >( geometry, 4 + 1 ); qskCreateBorderMonochrome( out, in, Color(), line ); } @@ -618,7 +623,7 @@ void QskBoxRenderer::renderRect( auto fillLines = line + fillLineCount; if ( bc.isMonochrome() ) - qskCreateBorderMonochrome( rect, in, bc.gradient( Qsk::Left ).startColor().rgb(), fillLines ); + qskCreateBorderMonochrome( rect, in, bc.gradient( Qsk::Left ).startColor().rgba(), fillLines ); else qskCreateBorder( rect, in, bc, fillLines ); }