qskInterpolatedColor added

This commit is contained in:
Uwe Rathmann 2024-01-06 15:00:23 +01:00
parent faf2ecd3c8
commit a420407a56
2 changed files with 21 additions and 1 deletions

View File

@ -273,6 +273,25 @@ QskGradientStops qskInterpolatedGradientStops(
return qskInterpolatedStops( from, to, ratio ); return qskInterpolatedStops( from, to, ratio );
} }
QColor qskInterpolatedColorAt( const QskGradientStops& stops, qreal pos ) noexcept
{
if ( stops.isEmpty() )
return QColor();
pos = qBound( 0.0, pos, 1.0 );
if ( pos <= stops.first().position() )
return stops.first().color();
for ( int i = 1; i < stops.count(); i++ )
{
if ( pos <= stops[i].position() )
return qskInterpolatedColor( stops, i - 1, i, pos );
}
return stops.last().color();
}
QskGradientStops qskExtractedGradientStops( QskGradientStops qskExtractedGradientStops(
const QskGradientStops& stops, qreal from, qreal to ) const QskGradientStops& stops, qreal from, qreal to )
{ {
@ -421,4 +440,3 @@ QGradientStops qskToQGradientStops( const QskGradientStops& stops )
return qStops; return qStops;
} }

View File

@ -120,6 +120,8 @@ QSK_EXPORT QDebug operator<<( QDebug, const QskGradientStop& );
typedef QVector< QskGradientStop > QskGradientStops; typedef QVector< QskGradientStop > QskGradientStops;
QSK_EXPORT QColor qskInterpolatedColorAt( const QskGradientStops&, qreal pos ) noexcept;
QSK_EXPORT bool qskIsMonochrome( const QskGradientStops& ) noexcept; QSK_EXPORT bool qskIsMonochrome( const QskGradientStops& ) noexcept;
QSK_EXPORT bool qskIsVisible( const QskGradientStops& ) noexcept; QSK_EXPORT bool qskIsVisible( const QskGradientStops& ) noexcept;