2024-05-14 15:03:03 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) The authors
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "QskArcRenderNode.h"
|
|
|
|
#include "QskGradient.h"
|
|
|
|
#include "QskArcRenderer.h"
|
|
|
|
#include "QskArcMetrics.h"
|
|
|
|
#include "QskGradient.h"
|
|
|
|
#include "QskSGNode.h"
|
|
|
|
|
|
|
|
QSK_QT_PRIVATE_BEGIN
|
|
|
|
#include <private/qsgnode_p.h>
|
|
|
|
QSK_QT_PRIVATE_END
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
#include <qsgvertexcolormaterial.h>
|
|
|
|
#include <qglobalstatic.h>
|
|
|
|
// deriving from QskFillNode:TODO ...
|
|
|
|
Q_GLOBAL_STATIC( QSGVertexColorMaterial, qskMaterialColorVertex )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class QskArcRenderNodePrivate final : public QSGGeometryNodePrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QskArcRenderNodePrivate()
|
|
|
|
: geometry( QSGGeometry::defaultAttributes_ColoredPoint2D(), 0 )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void resetValues()
|
|
|
|
{
|
|
|
|
hash = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSGGeometry geometry;
|
|
|
|
QskHashValue hash = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
QskArcRenderNode::QskArcRenderNode()
|
|
|
|
: QSGGeometryNode( *new QskArcRenderNodePrivate )
|
|
|
|
{
|
|
|
|
Q_D( QskArcRenderNode );
|
|
|
|
|
|
|
|
setGeometry( &d->geometry );
|
|
|
|
|
|
|
|
setMaterial( qskMaterialColorVertex );
|
|
|
|
setFlag( QSGNode::OwnsMaterial, false );
|
|
|
|
}
|
|
|
|
|
2024-05-30 17:06:02 +00:00
|
|
|
void QskArcRenderNode::updateNode( const QRectF& rect,
|
|
|
|
const QskArcMetrics& metrics, const QskGradient& gradient )
|
|
|
|
{
|
2024-06-12 10:10:57 +00:00
|
|
|
updateNode( rect, metrics, false, 0.0, QColor(), gradient );
|
2024-05-30 17:06:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QskArcRenderNode::updateNode( const QRectF& rect,
|
|
|
|
const QskArcMetrics& metrics, qreal borderWidth, const QColor& borderColor )
|
|
|
|
{
|
2024-06-12 10:10:57 +00:00
|
|
|
updateNode( rect, metrics, false, borderWidth, borderColor, QskGradient() );
|
2024-05-30 17:06:02 +00:00
|
|
|
}
|
|
|
|
|
2024-05-14 15:03:03 +00:00
|
|
|
void QskArcRenderNode::updateNode(
|
2024-06-12 10:10:57 +00:00
|
|
|
const QRectF& rect, const QskArcMetrics& arcMetrics, bool radial,
|
|
|
|
qreal borderWidth, const QColor& borderColor, const QskGradient& gradient )
|
2024-05-14 15:03:03 +00:00
|
|
|
{
|
|
|
|
Q_D( QskArcRenderNode );
|
|
|
|
|
2024-06-12 10:10:57 +00:00
|
|
|
const auto metrics = arcMetrics.toAbsolute( rect.size() );
|
2024-07-17 12:19:54 +00:00
|
|
|
const auto borderMax = 0.5 * metrics.thickness();
|
|
|
|
|
2024-05-14 15:03:03 +00:00
|
|
|
bool visible = !( rect.isEmpty() || metrics.isNull() );
|
|
|
|
if ( visible )
|
|
|
|
{
|
2024-07-24 13:00:05 +00:00
|
|
|
visible = gradient.isVisible() && ( borderWidth < borderMax );
|
2024-05-14 15:03:03 +00:00
|
|
|
if ( !visible )
|
|
|
|
{
|
|
|
|
visible = ( borderWidth > 0.0 )
|
|
|
|
&& borderColor.isValid() && ( borderColor.alpha() > 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !visible )
|
|
|
|
{
|
|
|
|
d->resetValues();
|
|
|
|
QskSGNode::resetGeometry( this );
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-07-24 13:00:05 +00:00
|
|
|
borderWidth = qMin( borderWidth, borderMax );
|
|
|
|
|
2024-05-14 15:03:03 +00:00
|
|
|
QskHashValue hash = 3496;
|
|
|
|
|
|
|
|
hash = qHashBits( &rect, sizeof( QRectF ), hash );
|
|
|
|
hash = qHash( borderWidth, hash );
|
2024-07-24 13:00:05 +00:00
|
|
|
hash = qHashBits( &borderColor, sizeof( borderColor ), hash );
|
2024-05-14 15:03:03 +00:00
|
|
|
hash = metrics.hash( hash );
|
|
|
|
hash = gradient.hash( hash );
|
2024-06-12 10:10:57 +00:00
|
|
|
hash = qHash( radial, hash );
|
2024-05-14 15:03:03 +00:00
|
|
|
|
|
|
|
if ( hash != d->hash )
|
|
|
|
{
|
|
|
|
d->hash = hash;
|
|
|
|
|
2024-07-24 13:00:05 +00:00
|
|
|
QskArcRenderer::renderArc( rect, metrics, radial,
|
|
|
|
borderWidth, gradient, borderColor, *geometry() );
|
2024-05-14 15:03:03 +00:00
|
|
|
|
|
|
|
markDirty( QSGNode::DirtyGeometry );
|
|
|
|
markDirty( QSGNode::DirtyMaterial );
|
|
|
|
}
|
|
|
|
}
|