qskinny/src/nodes/QskArcRenderNode.cpp

125 lines
3.2 KiB
C++
Raw Normal View History

/******************************************************************************
* 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 );
}
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 );
}
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() );
}
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 )
{
Q_D( QskArcRenderNode );
2024-06-12 10:10:57 +00:00
const auto metrics = arcMetrics.toAbsolute( rect.size() );
const auto borderMax = 0.5 * metrics.thickness();
const auto hasFilling = gradient.isVisible()
&& ( borderWidth < borderMax );
2024-06-12 10:10:57 +00:00
bool visible = !( rect.isEmpty() || metrics.isNull() );
if ( visible )
{
visible = hasFilling;
if ( !visible )
{
visible = ( borderWidth > 0.0 )
&& borderColor.isValid() && ( borderColor.alpha() > 0 );
}
}
if ( !visible )
{
d->resetValues();
QskSGNode::resetGeometry( this );
return;
}
QskHashValue hash = 3496;
hash = qHashBits( &rect, sizeof( QRectF ), hash );
hash = qHash( borderWidth, hash );
hash = qHash( borderColor.rgba(), hash );
hash = metrics.hash( hash );
hash = gradient.hash( hash );
2024-06-12 10:10:57 +00:00
hash = qHash( radial, hash );
if ( hash != d->hash )
{
d->hash = hash;
2024-07-15 08:59:43 +00:00
if ( borderWidth > 0.0 && borderColor.isValid() )
{
borderWidth = std::min( borderWidth, borderMax );
QskArcRenderer::renderBorder(
2024-07-15 08:59:43 +00:00
rect, metrics, radial, borderWidth, borderColor, *geometry() );
}
2024-06-12 10:10:57 +00:00
if ( hasFilling )
2024-07-15 08:59:43 +00:00
{
QskArcRenderer::renderFillGeometry(
rect, metrics, radial, borderWidth, gradient, *geometry() );
}
markDirty( QSGNode::DirtyGeometry );
markDirty( QSGNode::DirtyMaterial );
}
}