QskGradient::effectiveGradient added
This commit is contained in:
parent
a7a0510c21
commit
82cb6e6811
|
@ -51,17 +51,18 @@ namespace
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QQuickShapeGradient* createShapeGradient(
|
QQuickShapeGradient* createShapeGradient(
|
||||||
const QRectF& rect, QskGradient gradient ) const
|
const QRectF& rect, const QskGradient& gradient ) const
|
||||||
{
|
{
|
||||||
QQuickShapeGradient* shapeGradient = nullptr;
|
QQuickShapeGradient* shapeGradient = nullptr;
|
||||||
|
|
||||||
gradient.stretchTo( rect );
|
auto effectiveGradient = gradient.effectiveGradient();
|
||||||
|
effectiveGradient.stretchTo( rect );
|
||||||
|
|
||||||
switch( static_cast< int >( gradient.type() ) )
|
switch( static_cast< int >( gradient.type() ) )
|
||||||
{
|
{
|
||||||
case QskGradient::Linear:
|
case QskGradient::Linear:
|
||||||
{
|
{
|
||||||
const auto dir = gradient.linearDirection();
|
const auto dir = effectiveGradient.linearDirection();
|
||||||
|
|
||||||
auto g = new QQuickShapeLinearGradient();
|
auto g = new QQuickShapeLinearGradient();
|
||||||
|
|
||||||
|
@ -76,7 +77,7 @@ namespace
|
||||||
|
|
||||||
case QskGradient::Radial:
|
case QskGradient::Radial:
|
||||||
{
|
{
|
||||||
const auto dir = gradient.radialDirection();
|
const auto dir = effectiveGradient.radialDirection();
|
||||||
|
|
||||||
auto g = new QQuickShapeRadialGradient();
|
auto g = new QQuickShapeRadialGradient();
|
||||||
|
|
||||||
|
@ -94,7 +95,7 @@ namespace
|
||||||
|
|
||||||
case QskGradient::Conic:
|
case QskGradient::Conic:
|
||||||
{
|
{
|
||||||
const auto dir = gradient.conicDirection();
|
const auto dir = effectiveGradient.conicDirection();
|
||||||
|
|
||||||
auto g = new QQuickShapeConicalGradient();
|
auto g = new QQuickShapeConicalGradient();
|
||||||
|
|
||||||
|
|
|
@ -699,6 +699,21 @@ void QskGradient::resetDirection()
|
||||||
m_values[0] = m_values[1] = m_values[2] = m_values[3] = 0.0;
|
m_values[0] = m_values[1] = m_values[2] = m_values[3] = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QskGradient QskGradient::effectiveGradient() const
|
||||||
|
{
|
||||||
|
if ( ( m_type == QskGradient::Stops ) || isMonochrome() )
|
||||||
|
{
|
||||||
|
// the shader for linear gradients is the fastest
|
||||||
|
|
||||||
|
QskGradient g = *this;
|
||||||
|
g.setDirection( QskGradient::Linear );
|
||||||
|
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
QGradient QskGradient::toQGradient() const
|
QGradient QskGradient::toQGradient() const
|
||||||
{
|
{
|
||||||
QGradient g;
|
QGradient g;
|
||||||
|
|
|
@ -149,6 +149,8 @@ class QSK_EXPORT QskGradient
|
||||||
QskGradient stretchedTo( const QSizeF& ) const;
|
QskGradient stretchedTo( const QSizeF& ) const;
|
||||||
QskGradient stretchedTo( const QRectF& ) const;
|
QskGradient stretchedTo( const QRectF& ) const;
|
||||||
|
|
||||||
|
QskGradient effectiveGradient() const;
|
||||||
|
|
||||||
static QVariant interpolate( const QskGradient&,
|
static QVariant interpolate( const QskGradient&,
|
||||||
const QskGradient&, qreal progress );
|
const QskGradient&, qreal progress );
|
||||||
|
|
||||||
|
|
|
@ -27,21 +27,6 @@ static inline QskHashValue qskMetricsHash(
|
||||||
return borderMetrics.hash( hash );
|
return borderMetrics.hash( hash );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline QskGradient qskEffectiveGradient( const QskGradient& gradient )
|
|
||||||
{
|
|
||||||
if ( gradient.type() == QskGradient::Stops || gradient.isMonochrome() )
|
|
||||||
{
|
|
||||||
// the shader for linear gradients is the fastest
|
|
||||||
QskGradient g;
|
|
||||||
g.setLinearDirection( Qt::Vertical );
|
|
||||||
g.setStops( gradient.stops() );
|
|
||||||
|
|
||||||
return g;
|
|
||||||
}
|
|
||||||
|
|
||||||
return gradient;
|
|
||||||
}
|
|
||||||
|
|
||||||
class QskBoxFillNodePrivate final : public QSGGeometryNodePrivate
|
class QskBoxFillNodePrivate final : public QSGGeometryNodePrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -137,7 +122,7 @@ void QskBoxFillNode::updateNode(
|
||||||
|
|
||||||
if ( dirtyColors || dirtyMetrics )
|
if ( dirtyColors || dirtyMetrics )
|
||||||
{
|
{
|
||||||
const auto effectiveGradient = qskEffectiveGradient( gradient );
|
const auto effectiveGradient = gradient.effectiveGradient();
|
||||||
const auto gradientType = effectiveGradient.type();
|
const auto gradientType = effectiveGradient.type();
|
||||||
|
|
||||||
if ( ( material() == nullptr ) || ( gradientType != d->gradientType ) )
|
if ( ( material() == nullptr ) || ( gradientType != d->gradientType ) )
|
||||||
|
|
|
@ -42,19 +42,9 @@ static inline QskHashValue qskColorsHash(
|
||||||
|
|
||||||
static inline QskGradient qskEffectiveGradient( const QskGradient& gradient )
|
static inline QskGradient qskEffectiveGradient( const QskGradient& gradient )
|
||||||
{
|
{
|
||||||
QskGradient g;
|
auto g = gradient.effectiveGradient();
|
||||||
|
|
||||||
if ( gradient.isVisible() )
|
switch( static_cast< int >( g.type() ) )
|
||||||
{
|
|
||||||
if ( gradient.isMonochrome() )
|
|
||||||
{
|
|
||||||
g.setLinearDirection( Qt::Vertical );
|
|
||||||
g.setStops( gradient.rgbStart() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
switch( gradient.type() )
|
|
||||||
{
|
{
|
||||||
case QskGradient::Linear:
|
case QskGradient::Linear:
|
||||||
{
|
{
|
||||||
|
@ -64,9 +54,9 @@ static inline QskGradient qskEffectiveGradient( const QskGradient& gradient )
|
||||||
{
|
{
|
||||||
dir.setStart( 0.0, 0.0 );
|
dir.setStart( 0.0, 0.0 );
|
||||||
dir.setStop( 1.0, 1.0 );
|
dir.setStop( 1.0, 1.0 );
|
||||||
}
|
|
||||||
|
|
||||||
g.setLinearDirection( dir );
|
g.setLinearDirection( dir );
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -74,19 +64,10 @@ static inline QskGradient qskEffectiveGradient( const QskGradient& gradient )
|
||||||
case QskGradient::Conic:
|
case QskGradient::Conic:
|
||||||
{
|
{
|
||||||
qWarning() << "QskBoxRectangleNode does not support radial/conic gradients";
|
qWarning() << "QskBoxRectangleNode does not support radial/conic gradients";
|
||||||
g.setLinearDirection( Qt::Vertical );
|
g.setDirection( QskGradient::Linear );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QskGradient::Stops:
|
|
||||||
{
|
|
||||||
g.setLinearDirection( Qt::Vertical );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g.setStops( gradient.stops() );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return g;
|
return g;
|
||||||
|
|
|
@ -22,21 +22,6 @@ QSK_QT_PRIVATE_END
|
||||||
|
|
||||||
Q_GLOBAL_STATIC( QSGVertexColorMaterial, qskMaterialColorVertex )
|
Q_GLOBAL_STATIC( QSGVertexColorMaterial, qskMaterialColorVertex )
|
||||||
|
|
||||||
static inline QskGradient qskEffectiveGradient( const QskGradient& gradient )
|
|
||||||
{
|
|
||||||
if ( gradient.type() == QskGradient::Stops || gradient.isMonochrome() )
|
|
||||||
{
|
|
||||||
// the shader for linear gradients is the fastest
|
|
||||||
QskGradient g;
|
|
||||||
g.setLinearDirection( Qt::Vertical );
|
|
||||||
g.setStops( gradient.stops() );
|
|
||||||
|
|
||||||
return g;
|
|
||||||
}
|
|
||||||
|
|
||||||
return gradient;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void qskUpdateColoredPoint2D( const QRectF& rect,
|
static inline void qskUpdateColoredPoint2D( const QRectF& rect,
|
||||||
const QskBoxShapeMetrics& shape, const QskGradient& gradient,
|
const QskBoxShapeMetrics& shape, const QskGradient& gradient,
|
||||||
QSGGeometry& geometry )
|
QSGGeometry& geometry )
|
||||||
|
@ -111,7 +96,7 @@ void QskRectangleNode::updateNode(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto effectiveGradient = qskEffectiveGradient( gradient );
|
const auto effectiveGradient = gradient.effectiveGradient();
|
||||||
const auto effectiveShape = shape.toAbsolute( rect.size() );
|
const auto effectiveShape = shape.toAbsolute( rect.size() );
|
||||||
|
|
||||||
const auto gradientHash = effectiveGradient.hash( 54228 );
|
const auto gradientHash = effectiveGradient.hash( 54228 );
|
||||||
|
|
|
@ -17,21 +17,6 @@ QSK_QT_PRIVATE_BEGIN
|
||||||
#include <private/qtriangulator_p.h>
|
#include <private/qtriangulator_p.h>
|
||||||
QSK_QT_PRIVATE_END
|
QSK_QT_PRIVATE_END
|
||||||
|
|
||||||
static inline QskGradient qskEffectiveGradient( const QskGradient& gradient )
|
|
||||||
{
|
|
||||||
if ( gradient.type() == QskGradient::Stops || gradient.isMonochrome() )
|
|
||||||
{
|
|
||||||
// the shader for linear gradients is the fastest
|
|
||||||
QskGradient g;
|
|
||||||
g.setLinearDirection( Qt::Vertical );
|
|
||||||
g.setStops( gradient.stops() );
|
|
||||||
|
|
||||||
return g;
|
|
||||||
}
|
|
||||||
|
|
||||||
return gradient;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void qskUpdateGeometry( const QPainterPath& path,
|
static void qskUpdateGeometry( const QPainterPath& path,
|
||||||
const QTransform& transform, QSGGeometry& geometry )
|
const QTransform& transform, QSGGeometry& geometry )
|
||||||
{
|
{
|
||||||
|
@ -146,7 +131,7 @@ void QskShapeNode::updateNode( const QPainterPath& path,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const auto effectiveGradient = qskEffectiveGradient( gradient );
|
const auto effectiveGradient = gradient.effectiveGradient();
|
||||||
const auto gradientType = effectiveGradient.type();
|
const auto gradientType = effectiveGradient.type();
|
||||||
|
|
||||||
if ( ( material() == nullptr ) || ( gradientType != d->gradientType ) )
|
if ( ( material() == nullptr ) || ( gradientType != d->gradientType ) )
|
||||||
|
|
Loading…
Reference in New Issue