qskExtractedGradientStops fixed (
https://github.com/uwerat/qskinny/issues/374 )
This commit is contained in:
parent
59c2e8ca33
commit
2e34bfd4c6
@ -293,44 +293,67 @@ QColor qskInterpolatedColorAt( const QskGradientStops& stops, qreal pos ) noexce
|
||||
}
|
||||
|
||||
QskGradientStops qskExtractedGradientStops(
|
||||
const QskGradientStops& stops, qreal from, qreal to )
|
||||
const QskGradientStops& gradientStops, qreal from, qreal to )
|
||||
{
|
||||
if ( ( from > to ) || ( from > 1.0 ) || stops.isEmpty() )
|
||||
if ( ( from > to ) || ( from > 1.0 ) || gradientStops.isEmpty() )
|
||||
return QskGradientStops();
|
||||
|
||||
if ( ( from <= 0.0 ) && ( to >= 1.0 ) )
|
||||
return stops;
|
||||
return gradientStops;
|
||||
|
||||
from = qMax( from, 0.0 );
|
||||
to = qMin( to, 1.0 );
|
||||
|
||||
QVector< QskGradientStop > extracted;
|
||||
extracted.reserve( stops.count() );
|
||||
QVector< QskGradientStop > stops1 = gradientStops;
|
||||
|
||||
#if 1
|
||||
// not the most efficient implementation - maybe later TODO ...
|
||||
|
||||
if ( stops1.first().position() > 0.0 )
|
||||
stops1.prepend( QskGradientStop( 0.0, stops1.first().color() ) );
|
||||
|
||||
if ( stops1.last().position() < 1.0 )
|
||||
stops1.append( QskGradientStop( 1.0, stops1.last().color() ) );
|
||||
#endif
|
||||
|
||||
QVector< QskGradientStop > stops2;
|
||||
stops2.reserve( stops1.count() );
|
||||
|
||||
if ( stops1.count() == 2 )
|
||||
{
|
||||
const auto rgb1 = stops1.first().rgb();
|
||||
const auto rgb2 = stops1.last().rgb();
|
||||
|
||||
stops2 += QskGradientStop( 0.0, QskRgb::interpolated( rgb1, rgb2, from ) );
|
||||
stops2 += QskGradientStop( 1.0, QskRgb::interpolated( rgb1, rgb2, to ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for ( ; i < stops.count(); i++ )
|
||||
for ( ; i < stops1.count(); i++ )
|
||||
{
|
||||
if ( stops[i].position() > from )
|
||||
if ( stops1[i].position() > from )
|
||||
break;
|
||||
}
|
||||
|
||||
extracted += QskGradientStop( 0.0,
|
||||
qskInterpolatedColor( stops, i - 1, i, from ) );
|
||||
stops2 += QskGradientStop( 0.0,
|
||||
qskInterpolatedColor( stops1, i - 1, i, from ) );
|
||||
|
||||
for ( ; i < stops.count(); i++ )
|
||||
for ( ; i < stops1.count(); i++ )
|
||||
{
|
||||
if ( stops[i].position() >= to )
|
||||
if ( stops1[i].position() >= to )
|
||||
break;
|
||||
|
||||
const auto pos = ( stops[i].position() - from ) / ( to - from );
|
||||
extracted += QskGradientStop( pos, stops[i].color() );
|
||||
const auto pos = ( stops1[i].position() - from ) / ( to - from );
|
||||
stops2 += QskGradientStop( pos, stops1[i].color() );
|
||||
}
|
||||
|
||||
extracted += QskGradientStop( 1.0,
|
||||
qskInterpolatedColor( stops, i, i + 1, to ) );
|
||||
stops2 += QskGradientStop( 1.0,
|
||||
qskInterpolatedColor( stops1, i, i + 1, to ) );
|
||||
}
|
||||
|
||||
return extracted;
|
||||
return stops2;
|
||||
}
|
||||
|
||||
QskGradientStops qskRevertedGradientStops( const QskGradientStops& stops )
|
||||
|
Loading…
x
Reference in New Issue
Block a user