7#include "QskBoxShadowNode.h"
8#include "QskBoxRectangleNode.h"
11#include "QskGradient.h"
12#include "QskGradientDirection.h"
13#include "QskShadowMetrics.h"
14#include "QskBoxBorderMetrics.h"
15#include "QskBoxBorderColors.h"
16#include "QskBoxShapeMetrics.h"
17#include "QskRgbValue.h"
30static void qskUpdateChildren( QSGNode* parentNode, quint8 role, QSGNode* node )
32 static const QVector< quint8 > roles =
33 { ShadowRole, ShadowFillRole, BoxRole, FillRole };
35 auto oldNode = QskSGNode::findChildNode( parentNode, role );
36 QskSGNode::replaceChildNode( roles, role, parentNode, oldNode, node );
39template<
typename Node >
40static inline Node* qskNode( QSGNode* parentNode, quint8 role )
42 using namespace QskSGNode;
44 auto node =
static_cast< Node*
> ( findChildNode( parentNode, role ) );
46 if ( node ==
nullptr )
49 setNodeRole( node, role );
55QskBoxNode::QskBoxNode()
59QskBoxNode::~QskBoxNode()
63void QskBoxNode::updateNode(
const QQuickWindow* window,
const QRectF& rect,
68 using namespace QskSGNode;
75 if ( !rect.isEmpty() )
77 const auto hasFilling = gradient.isVisible();
78 const auto hasBorder = !borderMetrics.isNull() && borderColors.isVisible();
79 const auto hasShadow = !shadowMetrics.isNull() && QskRgb::isVisible( shadowColor );
83 const auto shadow = shadowMetrics.toAbsolute( rect.size() );
84 const auto shadowRect = shadow.shadowRect( rect );
86 auto shadowShape = shapeMetrics;
88 switch(
static_cast< int >( shadow.shapeMode() ) )
90 case QskShadowMetrics::Ellipse:
91 shadowShape.setRadius( 100.0, Qt::RelativeSize );
94 case QskShadowMetrics::Rectangle:
95 shadowShape.setRadius( 0.0, Qt::AbsoluteSize );
99 if ( shadow.blurRadius() <= 0.0 )
102 shadowFillNode = qskNode< QskBoxRectangleNode >(
this, ShadowFillRole );
103 shadowFillNode->updateFilling( window,
104 shadowRect, shadowShape, shadowColor );
108 shadowNode = qskNode< QskBoxShadowNode >(
this, ShadowRole );
109 shadowNode->setShadowData( shadowRect,
110 shadowShape, shadow.blurRadius(), shadowColor );
114 if ( hasBorder || hasFilling )
116 rectNode = qskNode< QskBoxRectangleNode >(
this, BoxRole );
118 if ( hasBorder && hasFilling )
120 const bool doCombine = rectNode->hasHint( QskFillNode::PreferColoredGeometry )
121 && QskBoxRectangleNode::isCombinedGeometrySupported( gradient );
124 fillNode = qskNode< QskBoxRectangleNode >(
this, FillRole );
129 rectNode->updateBorder( window, rect,
130 shapeMetrics, borderMetrics, borderColors );
132 fillNode->updateFilling( window, rect,
133 shapeMetrics, borderMetrics, gradient );
137 rectNode->updateBox( window, rect,
138 shapeMetrics, borderMetrics, borderColors, gradient );
143 qskUpdateChildren(
this, ShadowRole, shadowNode );
144 qskUpdateChildren(
this, ShadowFillRole, shadowFillNode );
145 qskUpdateChildren(
this, BoxRole, rectNode );
146 qskUpdateChildren(
this, FillRole, fillNode );