calculate proper numbers of needed border colors

This commit is contained in:
Peter Hartmann 2021-12-14 15:00:11 +01:00
parent efb35223ac
commit fc71dbd0e0
2 changed files with 56 additions and 19 deletions

View File

@ -365,7 +365,11 @@ static void addColoredBorderRectangles( QskLinearBox* parent )
box = new Box( parent ); box = new Box( parent );
box->setBorderWidth( 20 ); box->setBorderWidth( 20 );
box->setBorderGradient( { Qt::Vertical, Qt::magenta, Qt::cyan } ); QskGradient gradient1( Qt::Vertical, { { 0.0, Qt::blue }, { 0.7, Qt::yellow }, { 1.0, Qt::darkRed } } );
QskGradient gradient2( Qt::Vertical, { { 0.0, Qt::black }, { 0.3, Qt::white }, { 0.7, Qt::white }, { 1.0, Qt::black } } );
QskGradient gradient3( Qt::green );
QskGradient gradient4( Qt::Vertical, Qt::magenta, Qt::cyan );
box->setBorderGradients( gradient1, gradient2, gradient3, gradient4 );
} }
class TabView : public QskTabView class TabView : public QskTabView

View File

@ -11,6 +11,8 @@
#include "QskGradient.h" #include "QskGradient.h"
#include "QskVertex.h" #include "QskVertex.h"
#include <QDebug>
using namespace QskVertex; using namespace QskVertex;
namespace namespace
@ -427,23 +429,51 @@ static inline void qskCreateBorder(
const QskGradient gradientTop = colors.gradient( Qsk::Top ); const QskGradient gradientTop = colors.gradient( Qsk::Top );
const QskGradient gradientBottom = colors.gradient( Qsk::Bottom ); const QskGradient gradientBottom = colors.gradient( Qsk::Bottom );
( line++ )->setLine( in.right, in.bottom, out.right, out.bottom, gradientBottom.startColor() ); // ### // qdebug
( line++ )->setLine( in.left, in.bottom, out.left, out.bottom, gradientBottom.endColor() );
if ( gradientLeft != gradientBottom ) for( const QskGradientStop& stop : gradientBottom.stops() )
( line++ )->setLine( in.left, in.bottom, out.left, out.bottom, gradientLeft.startColor() ); {
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 y1 = in.bottom;
const qreal y2 = out.bottom;
( line++ )->setLine( in.left, in.top, out.left, out.top, gradientLeft.endColor() ); ( line++ )->setLine( x1, y1, x2, y2, c );
}
if ( gradientTop != gradientLeft ) for( const QskGradientStop& stop : gradientLeft.stops() )
( line++ )->setLine( in.left, in.top, out.left, out.top, gradientTop.startColor() ); {
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 );
( line++ )->setLine( in.right, in.top, out.right, out.top, gradientTop.endColor() ); ( line++ )->setLine( x1, y1, x2, y2, c );
}
if ( gradientRight != gradientTop ) for( const QskGradientStop& stop : gradientTop.stops() )
( line++ )->setLine( in.right, in.top, out.right, out.top, gradientRight.startColor() ); {
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 y1 = in.top;
const qreal y2 = out.top;
( line++ )->setLine( in.right, in.bottom, out.right, out.bottom, gradientRight.endColor() ); ( line++ )->setLine( x1, y1, x2, y2, c );
}
for( const QskGradientStop& stop : gradientRight.stops() )
{
const Color c( stop.color() );
const qreal x1 = in.right;
const qreal x2 = out.right;
const qreal y1 = in.bottom + stop.position() * ( in.top - in.bottom );
const qreal y2 = out.bottom + stop.position() * ( out.top - out.bottom );
( line++ )->setLine( x1, y1, x2, y2, c );
}
} }
void QskBoxRenderer::renderRectBorder( void QskBoxRenderer::renderRectBorder(
@ -533,18 +563,21 @@ void QskBoxRenderer::renderRect(
// we might need extra lines to separate colors // we might need extra lines to separate colors
// at the non closing corners // at the non closing corners
if ( bc.gradient( Qsk::Left ) != bc.gradient( Qsk::Bottom ) ) // ### As an optimization we could check orientation and colors
borderLineCount++; // to test whether colors are the same
const int additionalLines = -1
+ bc.gradient( Qsk::Left ).stops().count() - 1
+ bc.gradient( Qsk::Top ).stops().count() - 1
+ bc.gradient( Qsk::Right ).stops().count() - 1
+ bc.gradient( Qsk::Bottom ).stops().count() - 1;
if ( bc.gradient( Qsk::Top ) != bc.gradient( Qsk::Left ) ) borderLineCount += qMax( additionalLines, 0 );
borderLineCount++;
if ( bc.gradient( Qsk::Right ) != bc.gradient( Qsk::Top ) )
borderLineCount++;
} }
} }
} }
qDebug() << "border lines:" << borderLineCount;
auto line = allocateLines< ColoredLine >( geometry, borderLineCount + fillLineCount ); auto line = allocateLines< ColoredLine >( geometry, borderLineCount + fillLineCount );
if ( fillLineCount > 0 ) if ( fillLineCount > 0 )