being more careful with setting the dirty bits of a QskBoxShadowNode
This commit is contained in:
parent
49bc726376
commit
824325eccf
@ -135,27 +135,21 @@ QSGNode* LightDisplaySkinlet::updateSubNode(
|
||||
{
|
||||
return updateBoxNode( skinnable, node, LightDisplay::Panel );
|
||||
}
|
||||
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
|
||||
case GrooveRole:
|
||||
{
|
||||
const QRectF grooveRect = display->subControlRect( LightDisplay::Groove );
|
||||
if ( grooveRect.isEmpty() )
|
||||
return nullptr;
|
||||
|
||||
auto shadowNode = QskSGNode::ensureNode< QskBoxShadowNode >( node );
|
||||
|
||||
const auto& shadowMetrics = display->shadow();
|
||||
const auto shadowRect = shadowMetrics.shadowRect( grooveRect );
|
||||
|
||||
shadowNode->setRect( shadowMetrics.shadowRect( grooveRect ) );
|
||||
shadowNode->setShape( grooveRect.width() / 2 );
|
||||
shadowNode->setBlurRadius( shadowMetrics.blurRadius() );
|
||||
shadowNode->setColor( display->shadowColor() );
|
||||
|
||||
shadowNode->updateGeometry();
|
||||
auto shadowNode = QskSGNode::ensureNode< QskBoxShadowNode >( node );
|
||||
shadowNode->setShadowData( shadowRect, grooveRect.width() / 2,
|
||||
shadowMetrics.blurRadius(), display->shadowColor() );
|
||||
|
||||
return shadowNode;
|
||||
}
|
||||
#endif
|
||||
case ColdAndWarmArcRole:
|
||||
{
|
||||
return updateArcNode( skinnable, node, LightDisplay::ColdAndWarmArc );
|
||||
|
@ -55,12 +55,8 @@ namespace
|
||||
|
||||
auto shadowNode = QskSGNode::ensureNode< QskBoxShadowNode >( node );
|
||||
|
||||
shadowNode->setRect( shadowMetrics.shadowRect( r ) );
|
||||
shadowNode->setShape( box->shape() );
|
||||
shadowNode->setBlurRadius( shadowMetrics.blurRadius() );
|
||||
shadowNode->setColor( box->shadowColor() );
|
||||
|
||||
shadowNode->updateGeometry();
|
||||
shadowNode->setShadowData( shadowMetrics.shadowRect( r ),
|
||||
box->shape(), shadowMetrics.blurRadius(), box->shadowColor() );
|
||||
|
||||
return shadowNode;
|
||||
}
|
||||
|
@ -268,98 +268,77 @@ QskBoxShadowNode::~QskBoxShadowNode()
|
||||
{
|
||||
}
|
||||
|
||||
void QskBoxShadowNode::setRect( const QRectF& rect )
|
||||
void QskBoxShadowNode::setShadowData(
|
||||
const QRectF& rect, const QskBoxShapeMetrics& shape,
|
||||
qreal blurRadius, const QColor& color )
|
||||
{
|
||||
Q_D( QskBoxShadowNode );
|
||||
|
||||
if ( rect == d->rect )
|
||||
return;
|
||||
|
||||
d->rect = rect;
|
||||
|
||||
QVector2D aspect( 1.0, 1.0 );
|
||||
|
||||
if ( rect.width() >= rect.height() )
|
||||
aspect.setX( rect.width() / rect.height() );
|
||||
else
|
||||
aspect.setY( rect.height() / rect.width() );
|
||||
|
||||
if ( d->material.m_aspect != aspect )
|
||||
if ( rect != d->rect )
|
||||
{
|
||||
d->material.m_aspect = aspect;
|
||||
markDirty( QSGNode::DirtyMaterial );
|
||||
d->rect = rect;
|
||||
|
||||
QSGGeometry::updateTexturedRectGeometry(
|
||||
&d->geometry, d->rect, QRectF( -0.5, -0.5, 1.0, 1.0 ) );
|
||||
|
||||
markDirty( QSGNode::DirtyGeometry );
|
||||
|
||||
QVector2D aspect( 1.0, 1.0 );
|
||||
|
||||
if ( rect.width() >= rect.height() )
|
||||
aspect.setX( rect.width() / rect.height() );
|
||||
else
|
||||
aspect.setY( rect.height() / rect.width() );
|
||||
|
||||
if ( d->material.m_aspect != aspect )
|
||||
{
|
||||
d->material.m_aspect = aspect;
|
||||
markDirty( QSGNode::DirtyMaterial );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const float t = std::min( d->rect.width(), d->rect.height() );
|
||||
|
||||
const float r1 = shape.radius( Qt::BottomRightCorner ).width();
|
||||
const float r2 = shape.radius( Qt::TopRightCorner ).width();
|
||||
const float r3 = shape.radius( Qt::BottomLeftCorner ).width();
|
||||
const float r4 = shape.radius( Qt::TopLeftCorner ).width();
|
||||
|
||||
const auto uniformRadius = QVector4D(
|
||||
std::min( r1 / t, 1.0f ), std::min( r2 / t, 1.0f ),
|
||||
std::min( r3 / t, 1.0f ), std::min( r4 / t, 1.0f ) );
|
||||
|
||||
if ( d->material.m_radius != uniformRadius )
|
||||
{
|
||||
d->material.m_radius = uniformRadius;
|
||||
markDirty( QSGNode::DirtyMaterial );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
if ( blurRadius <= 0.0 )
|
||||
blurRadius = 0.0;
|
||||
|
||||
const float t = 0.5 * std::min( d->rect.width(), d->rect.height() );
|
||||
const float uniformExtent = blurRadius / t;
|
||||
|
||||
if ( !qFuzzyCompare( d->material.m_blurExtent, uniformExtent ) )
|
||||
{
|
||||
d->material.m_blurExtent = uniformExtent;
|
||||
markDirty( QSGNode::DirtyMaterial );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const auto a = color.alphaF();
|
||||
|
||||
const QVector4D c( color.redF() * a, color.greenF() * a, color.blueF() * a, a );
|
||||
|
||||
if ( d->material.m_color != c )
|
||||
{
|
||||
d->material.m_color = c;
|
||||
markDirty( QSGNode::DirtyMaterial );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QskBoxShadowNode::setShape( const QskBoxShapeMetrics& shape )
|
||||
{
|
||||
Q_D( QskBoxShadowNode );
|
||||
|
||||
const float t = std::min( d->rect.width(), d->rect.height() );
|
||||
|
||||
const float r1 = shape.radius( Qt::BottomRightCorner ).width();
|
||||
const float r2 = shape.radius( Qt::TopRightCorner ).width();
|
||||
const float r3 = shape.radius( Qt::BottomLeftCorner ).width();
|
||||
const float r4 = shape.radius( Qt::TopLeftCorner ).width();
|
||||
|
||||
const auto uniformRadius = QVector4D(
|
||||
std::min( r1 / t, 1.0f ), std::min( r2 / t, 1.0f ),
|
||||
std::min( r3 / t, 1.0f ), std::min( r4 / t, 1.0f ) );
|
||||
|
||||
if ( d->material.m_radius != uniformRadius )
|
||||
{
|
||||
d->material.m_radius = uniformRadius;
|
||||
|
||||
markDirty( QSGNode::DirtyMaterial );
|
||||
}
|
||||
}
|
||||
|
||||
void QskBoxShadowNode::setColor( const QColor& color )
|
||||
{
|
||||
Q_D( QskBoxShadowNode );
|
||||
|
||||
const auto a = color.alphaF();
|
||||
|
||||
const QVector4D c( color.redF() * a, color.greenF() * a, color.blueF() * a, a );
|
||||
|
||||
if ( d->material.m_color != c )
|
||||
{
|
||||
d->material.m_color = c;
|
||||
markDirty( QSGNode::DirtyMaterial );
|
||||
}
|
||||
}
|
||||
|
||||
void QskBoxShadowNode::setBlurRadius( qreal blurRadius )
|
||||
{
|
||||
Q_D( QskBoxShadowNode );
|
||||
|
||||
if ( blurRadius <= 0.0 )
|
||||
blurRadius = 0.0;
|
||||
|
||||
const float t = 0.5 * std::min( d->rect.width(), d->rect.height() );
|
||||
const float uniformExtent = blurRadius / t;
|
||||
|
||||
if ( !qFuzzyCompare( d->material.m_blurExtent, uniformExtent ) )
|
||||
{
|
||||
d->material.m_blurExtent = uniformExtent;
|
||||
markDirty( QSGNode::DirtyMaterial );
|
||||
}
|
||||
}
|
||||
|
||||
void QskBoxShadowNode::setClipShape( const QskBoxShapeMetrics& )
|
||||
{
|
||||
/*
|
||||
Usually only the parts, that are not covered by the related box
|
||||
should be painted. TODO ...
|
||||
*/
|
||||
}
|
||||
|
||||
void QskBoxShadowNode::updateGeometry()
|
||||
{
|
||||
Q_D( QskBoxShadowNode );
|
||||
|
||||
QSGGeometry::updateTexturedRectGeometry(
|
||||
&d->geometry, d->rect, QRectF( -0.5, -0.5, 1.0, 1.0 ) );
|
||||
|
||||
markDirty( QSGNode::DirtyGeometry );
|
||||
}
|
||||
|
@ -20,14 +20,8 @@ class QSK_EXPORT QskBoxShadowNode : public QSGGeometryNode
|
||||
QskBoxShadowNode();
|
||||
~QskBoxShadowNode() override;
|
||||
|
||||
void setRect( const QRectF& );
|
||||
void setShape( const QskBoxShapeMetrics& );
|
||||
void setColor( const QColor& );
|
||||
void setBlurRadius( qreal );
|
||||
|
||||
void setClipShape( const QskBoxShapeMetrics& );
|
||||
|
||||
void updateGeometry();
|
||||
void setShadowData( const QRectF&, const QskBoxShapeMetrics&,
|
||||
qreal blurRadius, const QColor& );
|
||||
|
||||
private:
|
||||
Q_DECLARE_PRIVATE( QskBoxShadowNode )
|
||||
|
@ -24,14 +24,9 @@ void QskShadedBoxNode::setBoxData( const QRectF& rect,
|
||||
const QskShadowMetrics& shadowMetrics, const QColor& shadowColor )
|
||||
{
|
||||
m_boxNode.setBoxData( rect, shape, borderMetrics, borderColors, gradient );
|
||||
setShadowData( rect, shape, shadowMetrics, shadowColor );
|
||||
}
|
||||
|
||||
void QskShadedBoxNode::setShadowData(
|
||||
const QRectF& rect, const QskBoxShapeMetrics& shape,
|
||||
const QskShadowMetrics& metrics, const QColor& color )
|
||||
{
|
||||
if ( metrics.isNull() || !color.isValid() || color.alpha() == 0 )
|
||||
if ( shadowMetrics.isNull()
|
||||
|| !shadowColor.isValid() || shadowColor.alpha() == 0 )
|
||||
{
|
||||
if ( m_shadowNode )
|
||||
{
|
||||
@ -48,13 +43,7 @@ void QskShadedBoxNode::setShadowData(
|
||||
insertChildNodeBefore( m_shadowNode, &m_boxNode );
|
||||
}
|
||||
|
||||
m_shadowNode->setColor( color );
|
||||
|
||||
m_shadowNode->setRect( metrics.shadowRect( rect ) );
|
||||
m_shadowNode->setShape( shape );
|
||||
m_shadowNode->setBlurRadius( metrics.blurRadius() );
|
||||
m_shadowNode->setClipShape( shape );
|
||||
|
||||
m_shadowNode->updateGeometry();
|
||||
m_shadowNode->setShadowData( shadowMetrics.shadowRect( rect ),
|
||||
shape, shadowMetrics.blurRadius(), shadowColor );
|
||||
}
|
||||
}
|
||||
|
@ -24,9 +24,6 @@ class QSK_EXPORT QskShadedBoxNode : public QSGNode
|
||||
const QskShadowMetrics&, const QColor& shadowColor );
|
||||
|
||||
private:
|
||||
void setShadowData( const QRectF&, const QskBoxShapeMetrics&,
|
||||
const QskShadowMetrics&, const QColor& );
|
||||
|
||||
QskBoxNode m_boxNode;
|
||||
QskBoxShadowNode* m_shadowNode = nullptr;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user