incorporate feedback from Uwe

This commit is contained in:
Peter Hartmann 2022-01-21 07:42:23 +01:00
parent 0050fe5456
commit fbd178a4ab
5 changed files with 65 additions and 52 deletions

View File

@ -22,9 +22,9 @@ static void qskRegisterBoxBorderColors()
Q_CONSTRUCTOR_FUNCTION( 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( static inline void qskSetGradients(
@ -110,7 +110,7 @@ void QskBoxBorderColors::setGradientAt( Qt::Edges edges, const QskGradient& grad
m_gradients[ Qsk::Bottom ] = gradient; m_gradients[ Qsk::Bottom ] = gradient;
} }
QskGradient QskBoxBorderColors::gradientAt( Qt::Edge edge ) const const QskGradient& QskBoxBorderColors::gradientAt( Qt::Edge edge ) const
{ {
switch ( edge ) switch ( edge )
{ {
@ -127,7 +127,8 @@ QskGradient QskBoxBorderColors::gradientAt( Qt::Edge edge ) const
return m_gradients[ Qsk::Bottom ]; return m_gradients[ Qsk::Bottom ];
} }
return QColor(); static QskGradient noGradient;
return noGradient;
} }
bool QskBoxBorderColors::isVisible() const bool QskBoxBorderColors::isVisible() const

View File

@ -42,7 +42,7 @@ class QSK_EXPORT QskBoxBorderColors
QskGradient gradient( Qsk::Position ) const; QskGradient gradient( Qsk::Position ) const;
void setGradientAt( Qt::Edges, const QskGradient& ); void setGradientAt( Qt::Edges, const QskGradient& );
QskGradient gradientAt( Qt::Edge ) const; const QskGradient& gradientAt( Qt::Edge ) const;
QskBoxBorderColors interpolated( const QskBoxBorderColors&, qreal value ) const; QskBoxBorderColors interpolated( const QskBoxBorderColors&, qreal value ) const;

View File

@ -117,7 +117,8 @@ void QskBoxNode::setBoxData( const QRectF& rect,
{ {
if ( isFillMonochrome && isBorderMonochrome ) 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 // we can draw border and background in one
hasBorder = false; hasBorder = false;

View File

@ -102,6 +102,21 @@ namespace
{ {
return qMax( 0, gradient.stops().count() - 2 ); 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 namespace
@ -568,7 +583,7 @@ namespace
} }
template< class BorderMap, class FillMap > 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& borderMapTL, const BorderMap& borderMapTR,
const BorderMap& borderMapBL, const BorderMap& borderMapBR, const BorderMap& borderMapBL, const BorderMap& borderMapBR,
Line* fillLines, FillMap& fillMap ) Line* fillLines, FillMap& fillMap )
@ -690,8 +705,6 @@ namespace
{ {
if( additionalGradientStops( borderMapTR.gradient() ) > 0 ) if( additionalGradientStops( borderMapTR.gradient() ) > 0 )
{ {
auto stops = borderMapTR.gradient().stops();
float x1TR = c[ TopRight ].centerX + v.dx1( TopRight ), float x1TR = c[ TopRight ].centerX + v.dx1( TopRight ),
y1TR = c[ TopRight ].centerY - v.dy1( TopRight ), y1TR = c[ TopRight ].centerY - v.dy1( TopRight ),
x2TR = c[ TopRight ].centerX + v.dx2( TopRight ), x2TR = c[ TopRight ].centerX + v.dx2( TopRight ),
@ -709,8 +722,6 @@ namespace
if( additionalGradientStops( borderMapBL.gradient() ) > 0 ) if( additionalGradientStops( borderMapBL.gradient() ) > 0 )
{ {
auto stops = borderMapBL.gradient().stops();
float x1BL = c[ BottomLeft ].centerX - v.dx1( BottomLeft ), float x1BL = c[ BottomLeft ].centerX - v.dx1( BottomLeft ),
y1BL = c[ BottomLeft ].centerY + v.dy1( BottomLeft ), y1BL = c[ BottomLeft ].centerY + v.dy1( BottomLeft ),
x2BL = c[ BottomLeft ].centerX - v.dx2( BottomLeft ), x2BL = c[ BottomLeft ].centerX - v.dx2( BottomLeft ),
@ -731,8 +742,6 @@ namespace
{ {
if( additionalGradientStops( borderMapTL.gradient() ) > 0 ) if( additionalGradientStops( borderMapTL.gradient() ) > 0 )
{ {
auto stops = borderMapTL.gradient().stops();
float x1TL = c[ TopLeft ].centerX - v.dx1( TopLeft ), float x1TL = c[ TopLeft ].centerX - v.dx1( TopLeft ),
y1TL = c[ TopLeft ].centerY - v.dy1( TopLeft ), y1TL = c[ TopLeft ].centerY - v.dy1( TopLeft ),
x2TL = c[ TopLeft ].centerX - v.dx2( TopLeft ), x2TL = c[ TopLeft ].centerX - v.dx2( TopLeft ),
@ -750,8 +759,6 @@ namespace
if( additionalGradientStops( borderMapBR.gradient() ) > 0 ) if( additionalGradientStops( borderMapBR.gradient() ) > 0 )
{ {
auto stops = borderMapBR.gradient().stops();
float x1BR = c[ BottomRight ].centerX + v.dx1( BottomRight ), float x1BR = c[ BottomRight ].centerX + v.dx1( BottomRight ),
y1BR = c[ BottomRight ].centerY + v.dy1( BottomRight ), y1BR = c[ BottomRight ].centerY + v.dy1( BottomRight ),
x2BR = c[ BottomRight ].centerX + v.dx2( BottomRight ), x2BR = c[ BottomRight ].centerX + v.dx2( BottomRight ),
@ -990,7 +997,7 @@ static inline void qskRenderBorder( const QskBoxRenderer::Metrics& metrics,
if ( colors.isMonochrome() ) if ( colors.isMonochrome() )
{ {
qskRenderBorderLines( metrics, orientation, line, BorderMapSolid( c.gradient( Qsk::Left ).startColor().rgb() ) ); qskRenderBorderLines( metrics, orientation, line, BorderMapSolid( qskRgbBorder( c ) ) );
} }
else else
{ {
@ -1000,14 +1007,14 @@ static inline void qskRenderBorder( const QskBoxRenderer::Metrics& metrics,
right = c.gradient( Qsk::Right ), bottom = c.gradient( Qsk::Bottom ); right = c.gradient( Qsk::Right ), bottom = c.gradient( Qsk::Bottom );
qskRenderBorderLines( metrics, orientation, line, qskRenderBorderLines( metrics, orientation, line,
BorderMapGradient( stepCount, top.startColor().rgb(), BorderMapGradient( stepCount, qskRgbGradientStart( top ),
left.endColor().rgb(), left ), qskRgbGradientEnd( left ), left ),
BorderMapGradient( stepCount, right.startColor().rgb(), BorderMapGradient( stepCount, qskRgbGradientStart( right ),
top.endColor().rgb(), top ), qskRgbGradientEnd( top ), top ),
BorderMapGradient( stepCount, left.startColor().rgb(), BorderMapGradient( stepCount, qskRgbGradientStart( left ),
bottom.endColor().rgb(), bottom ), qskRgbGradientEnd( bottom ), bottom ),
BorderMapGradient( stepCount, bottom.startColor().rgb(), BorderMapGradient( stepCount, qskRgbGradientStart( bottom ),
right.endColor().rgb(), right ) ); qskRgbGradientEnd( right ), right ) );
} }
} }
@ -1037,7 +1044,7 @@ static inline void qskRenderBoxRandom(
if ( bc.isMonochrome() ) if ( bc.isMonochrome() )
{ {
const BorderMapSolid borderMap( bc.gradient( Qsk::Left ).startColor().rgb() ); const BorderMapSolid borderMap( qskRgbBorder( bc.gradient( Qsk::Left ) ) );
if ( gradient.isMonochrome() ) if ( gradient.isMonochrome() )
{ {
@ -1056,18 +1063,17 @@ static inline void qskRenderBoxRandom(
{ {
const int n = metrics.corner[ 0 ].stepCount; const int n = metrics.corner[ 0 ].stepCount;
const BorderMapGradient tl( n, bc.gradient( Qsk::Top ).startColor().rgb(), auto left = bc.gradient( Qsk::Left ), top = bc.gradient( Qsk::Top ),
bc.gradient( Qsk::Left ).endColor().rgb(), right = bc.gradient( Qsk::Right ), bottom = bc.gradient( Qsk::Bottom );
borderColors.gradient( Qsk::Left ) );
const BorderMapGradient tr( n, bc.gradient( Qsk::Right ).startColor().rgb(), const BorderMapGradient tl( n, qskRgbGradientStart( top.startColor() ),
bc.gradient( Qsk::Top ).endColor().rgb(), qskRgbGradientEnd( left.endColor() ), left );
borderColors.gradient( Qsk::Top ) ); const BorderMapGradient tr( n, qskRgbGradientStart( right ),
const BorderMapGradient bl( n, bc.gradient( Qsk::Left ).startColor().rgb(), qskRgbGradientEnd( top ), top );
bc.gradient( Qsk::Bottom ).endColor().rgb(), const BorderMapGradient bl( n, qskRgbGradientStart( left ),
borderColors.gradient( Qsk::Bottom ) ); qskRgbGradientEnd( bottom ), bottom );
const BorderMapGradient br( n, bc.gradient( Qsk::Bottom ).startColor().rgb(), const BorderMapGradient br( n, qskRgbGradientStart( bottom ),
bc.gradient( Qsk::Right ).endColor().rgb(), qskRgbGradientEnd( right ), right );
borderColors.gradient( Qsk::Right ) );
if ( gradient.isMonochrome() ) if ( gradient.isMonochrome() )
{ {
@ -1270,7 +1276,7 @@ void QskBoxRenderer::renderRectellipseBorder(
const int stepCount = metrics.corner[ 0 ].stepCount; const int stepCount = metrics.corner[ 0 ].stepCount;
const int lineCount = 4 * ( stepCount + 1 ) + 1; 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() ); qskRenderBorderLines( metrics, Qt::Vertical, line, BorderMapNone() );
} }

View File

@ -429,48 +429,53 @@ static inline void qskCreateBorder(
// qdebug // 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 Color c( stop.color() );
const qreal x1 = in.right - stop.position() * ( in.right - in.left ); const qreal x1 = in.right - stop.position() * dx1;
const qreal x2 = out.right - stop.position() * ( out.right - out.left ); const qreal x2 = out.right - stop.position() * dx2;
const qreal y1 = in.bottom; const qreal y1 = in.bottom;
const qreal y2 = out.bottom; const qreal y2 = out.bottom;
( line++ )->setLine( x1, y1, x2, y2, c ); ( 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 Color c( stop.color() );
const qreal x1 = in.left; const qreal x1 = in.left;
const qreal x2 = out.left; const qreal x2 = out.left;
const qreal y1 = in.bottom + stop.position() * ( in.top - in.bottom ); const qreal y1 = in.bottom + stop.position() * dy1;
const qreal y2 = out.bottom + stop.position() * ( out.top - out.bottom ); const qreal y2 = out.bottom + stop.position() * dy2;
( line++ )->setLine( x1, y1, x2, y2, c ); ( 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 Color c( stop.color() );
const qreal x1 = in.left + stop.position() * ( in.right - in.left ); const qreal x1 = in.left + stop.position() * dx1;
const qreal x2 = out.left + stop.position() * ( out.right - out.left ); const qreal x2 = out.left + stop.position() * dx2;
const qreal y1 = in.top; const qreal y1 = in.top;
const qreal y2 = out.top; const qreal y2 = out.top;
( line++ )->setLine( x1, y1, x2, y2, c ); ( 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 Color c( stop.color() );
const qreal x1 = in.right; const qreal x1 = in.right;
const qreal x2 = out.right; const qreal x2 = out.right;
// ( 1 - stop.position() ) because we want to make the gradients go // ( 1 - stop.position() ) because we want to make the gradients go
// around the border clock-wise: // around the border clock-wise:
const qreal y1 = in.bottom + ( 1 - stop.position() ) * ( in.top - in.bottom ); const qreal y1 = in.bottom + ( 1 - stop.position() ) * dy1;
const qreal y2 = out.bottom + ( 1 - stop.position() ) * ( out.top - out.bottom ); const qreal y2 = out.bottom + ( 1 - stop.position() ) * dy2;
( line++ )->setLine( x1, y1, x2, y2, c ); ( line++ )->setLine( x1, y1, x2, y2, c );
} }
@ -491,7 +496,7 @@ void QskBoxRenderer::renderRectBorder(
return; return;
} }
const auto line = allocateLines< ColoredLine >( geometry, 4 + 1 ); const auto line = allocateLines< Line >( geometry, 4 + 1 );
qskCreateBorderMonochrome( out, in, Color(), line ); qskCreateBorderMonochrome( out, in, Color(), line );
} }
@ -618,7 +623,7 @@ void QskBoxRenderer::renderRect(
auto fillLines = line + fillLineCount; auto fillLines = line + fillLineCount;
if ( bc.isMonochrome() ) if ( bc.isMonochrome() )
qskCreateBorderMonochrome( rect, in, bc.gradient( Qsk::Left ).startColor().rgb(), fillLines ); qskCreateBorderMonochrome( rect, in, bc.gradient( Qsk::Left ).startColor().rgba(), fillLines );
else else
qskCreateBorder( rect, in, bc, fillLines ); qskCreateBorder( rect, in, bc, fillLines );
} }