diff --git a/src/nodes/QskBoxRendererEllipse.cpp b/src/nodes/QskBoxRendererEllipse.cpp index 808b640e..d1a6196c 100644 --- a/src/nodes/QskBoxRendererEllipse.cpp +++ b/src/nodes/QskBoxRendererEllipse.cpp @@ -561,25 +561,38 @@ namespace { } + inline void setAdditionalLine( + float x11, float y11, float x12, float y12, + float dx1, float dy1, float dx2, float dy2, + const QskGradientStop& stop, Line* line ) + { + const auto pos = 1.0 - stop.position(); + + const float x1 = x11 + pos * dx1; + const float y1 = y11 + pos * dy1; + const float x2 = x12 + pos * dx2; + const float y2 = y12 + pos * dy2; + + line->setLine( x1, y1, x2, y2, stop.color() ); + } + void addAdditionalLines( float x11, float y11, float x12, float y12, // start line float x21, float y21, float x22, float y22, // end line const QskGradient& gradient, Line* lines ) { - int additionalStopCount = additionalGradientStops( gradient ); + const float dx1 = x21 - x11; + const float dy1 = y21 - y11; + const float dx2 = x22 - x12; + const float dy2 = y22 - y12; - auto s = gradient.stops(); + const auto stops = gradient.stops(); - for( int i = 1; i <= additionalStopCount; ++i ) + auto line = lines + additionalGradientStops( gradient ); + + for( int i = 1; i < stops.count() - 1; i++ ) { - auto p = ( 1 - s.at( i ).position() ); - float xStart = x11 + p * ( x21 - x11 ), - yStart = y11 + p * ( y21 - y11 ), - xEnd = x12 + p * ( x22 - x12 ), - yEnd = y12 + p * ( y22 - y12 ); - - lines[ additionalStopCount - i + 1 ].setLine( xStart, yStart, - xEnd, yEnd, s.at( i ).color() ); + setAdditionalLine( x11, y11, x12, y12, dx1, dy1, dx2, dy2, stops[i], line-- ); } } diff --git a/src/nodes/QskBoxRendererRect.cpp b/src/nodes/QskBoxRendererRect.cpp index c7eca9b1..5494b3a1 100644 --- a/src/nodes/QskBoxRendererRect.cpp +++ b/src/nodes/QskBoxRendererRect.cpp @@ -422,62 +422,57 @@ static inline void qskCreateBorder( const QskBoxRenderer::Quad& out, const QskBoxRenderer::Quad& in, const QskBoxBorderColors& colors, Line* line ) { - const auto& gradientLeft = colors.left(); - const auto& gradientRight = colors.right(); - const auto& gradientTop = colors.top(); - const auto& gradientBottom = colors.bottom(); - - // qdebug - 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 : qAsConst( gradientBottom.stops() ) ) { - const Color c( stop.color() ); - 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; + const auto stops = colors.bottom().stops(); - ( line++ )->setLine( x1, y1, x2, y2, c ); + for( const auto& stop : stops ) + { + const qreal x1 = in.right - stop.position() * dx1; + const qreal x2 = out.right - stop.position() * dx2; + + ( line++ )->setLine( x1, in.bottom, x2, out.bottom, stop.color() ); + } } - for( const auto& stop : qAsConst( gradientLeft.stops() ) ) { - const Color c( stop.color() ); - const qreal x1 = in.left; - const qreal x2 = out.left; - const qreal y1 = in.bottom + stop.position() * dy1; - const qreal y2 = out.bottom + stop.position() * dy2; + const auto stops = colors.left().stops(); - ( line++ )->setLine( x1, y1, x2, y2, c ); + for( const auto& stop : stops ) + { + const qreal y1 = in.bottom + stop.position() * dy1; + const qreal y2 = out.bottom + stop.position() * dy2; + + ( line++ )->setLine( in.left, y1, out.left, y2, stop.color() ); + } } - for( const auto& stop : qAsConst( gradientTop.stops() ) ) { - const Color c( stop.color() ); - 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; + const auto stops = colors.top().stops(); - ( line++ )->setLine( x1, y1, x2, y2, c ); + for( const auto& stop : stops ) + { + const qreal x1 = in.left + stop.position() * dx1; + const qreal x2 = out.left + stop.position() * dx2; + + ( line++ )->setLine( x1, in.top, x2, out.top, stop.color() ); + } } - for( const auto& stop : qAsConst( 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() ) * dy1; - const qreal y2 = out.bottom + ( 1 - stop.position() ) * dy2; + const auto stops = colors.right().stops(); - ( line++ )->setLine( x1, y1, x2, y2, c ); + for( const auto& stop : stops ) + { + const qreal y1 = in.bottom + ( 1 - stop.position() ) * dy1; + const qreal y2 = out.bottom + ( 1 - stop.position() ) * dy2; + + ( line++ )->setLine( in.right, y1, out.right, y2, stop.color() ); + } } } @@ -531,7 +526,7 @@ void QskBoxRenderer::renderRect( const Quad in = qskValidOrEmptyInnerRect( rect, border.widths() ); int fillLineCount = 0; - if ( !in.isEmpty() ) + if ( gradient.isValid() && !in.isEmpty() ) { fillLineCount = gradient.stops().count();