QskBoxRenderer::isGradientSupported introduced

This commit is contained in:
Uwe Rathmann 2022-12-05 17:08:32 +01:00
parent 9d409ab89b
commit c31d554d6b
3 changed files with 36 additions and 32 deletions

View File

@ -7,6 +7,7 @@
#include "QskBoxFillNode.h"
#include "QskBoxShadowNode.h"
#include "QskBoxRectangleNode.h"
#include "QskBoxRenderer.h"
#include "QskSGNode.h"
#include "QskGradient.h"
@ -49,37 +50,6 @@ inline Node* qskNode( QSGNode* parentNode, quint8 role )
return node;
}
static inline bool qskIsBoxGradient( const QskGradient& gradient )
{
if ( !gradient.isVisible() || gradient.isMonochrome() )
return true;
switch( gradient.type() )
{
case QskGradient::Linear:
{
auto dir = gradient.linearDirection();
if ( dir.isTilted() )
{
// only diagonal from topLeft to bottomRight
return ( dir.x1() == dir.x2() ) && ( dir.y1() == dir.y2() );
}
return true;
}
case QskGradient::Radial:
case QskGradient::Conic:
{
return false;
}
default:
{
return true;
}
}
}
QskBoxNode::QskBoxNode()
{
}
@ -113,7 +83,7 @@ void QskBoxNode::updateNode( const QRectF& rect,
However the border is always done with a QskBoxRectangleNode
*/
if ( qskIsBoxGradient( gradient ) )
if ( QskBoxRenderer::isGradientSupported( gradient ) )
{
rectNode = qskNode< QskBoxRectangleNode >( this, BoxRole );
rectNode->updateNode( rect, shape, borderMetrics, borderColors, gradient );

View File

@ -36,6 +36,8 @@ class QSK_EXPORT QskBoxRenderer
static void renderRect( const QRectF&, const QskGradient&, QSGGeometry& );
static void renderRect( const QRectF&, QSGGeometry& );
static bool isGradientSupported( const QskGradient& );
class Quad
{
public:

View File

@ -681,3 +681,35 @@ void QskBoxRenderer::renderRectFill( const QskBoxRenderer::Quad& rect,
{
qskCreateFillOrdered( rect, gradient, line );
}
bool QskBoxRenderer::isGradientSupported( const QskGradient& gradient )
{
if ( !gradient.isVisible() || gradient.isMonochrome() )
return true;
switch( gradient.type() )
{
case QskGradient::Linear:
{
auto dir = gradient.linearDirection();
if ( dir.isTilted() )
{
// only diagonal from topLeft to bottomRight
return ( dir.x1() == dir.x2() ) && ( dir.y1() == dir.y2() );
}
return true;
}
case QskGradient::Radial:
case QskGradient::Conic:
{
return false;
}
default:
{
return true;
}
}
}