QskArcRenderNode stays inside its given rectangle
This commit is contained in:
parent
e937e3941f
commit
0d87964727
|
@ -8,6 +8,7 @@
|
||||||
#include "Slider.h"
|
#include "Slider.h"
|
||||||
|
|
||||||
#include <QskGridBox.h>
|
#include <QskGridBox.h>
|
||||||
|
#include <QskRgbValue.h>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -54,6 +55,9 @@ namespace
|
||||||
public:
|
public:
|
||||||
Arc()
|
Arc()
|
||||||
{
|
{
|
||||||
|
setBackgroundColor( QskRgb::LemonChiffon );
|
||||||
|
setClip( true ); // for testing if the arc stays inside its bounding rectangle
|
||||||
|
|
||||||
setStartAngle( 45.0 );
|
setStartAngle( 45.0 );
|
||||||
setSpanAngle( 270.0 );
|
setSpanAngle( 270.0 );
|
||||||
setThickness( 10.0 );
|
setThickness( 10.0 );
|
||||||
|
@ -101,7 +105,6 @@ ArcPage::ArcPage( QQuickItem* parent )
|
||||||
: QskLinearBox( Qt::Vertical, parent )
|
: QskLinearBox( Qt::Vertical, parent )
|
||||||
{
|
{
|
||||||
auto arc = new Arc();
|
auto arc = new Arc();
|
||||||
arc->setMargins( 40 ); // some extra space for testing the offsets
|
|
||||||
|
|
||||||
auto panel = new ControlPanel( arc );
|
auto panel = new ControlPanel( arc );
|
||||||
panel->setSizePolicy( Qt::Vertical, QskSizePolicy::Fixed );
|
panel->setSizePolicy( Qt::Vertical, QskSizePolicy::Fixed );
|
||||||
|
|
|
@ -56,15 +56,6 @@ static inline QskGradient qskEffectiveGradient(
|
||||||
return gradient;
|
return gradient;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline QRectF qskEffectiveRect(
|
|
||||||
const QRectF& rect, const qreal borderWidth )
|
|
||||||
{
|
|
||||||
if ( borderWidth <= 0.0 )
|
|
||||||
return rect;
|
|
||||||
|
|
||||||
return qskValidOrEmptyInnerRect( rect, QskMargins( 0.5 * borderWidth ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
static void qskUpdateChildren( QSGNode* parentNode, quint8 role, QSGNode* node )
|
static void qskUpdateChildren( QSGNode* parentNode, quint8 role, QSGNode* node )
|
||||||
{
|
{
|
||||||
static const QVector< quint8 > roles =
|
static const QVector< quint8 > roles =
|
||||||
|
@ -114,8 +105,7 @@ void QskArcNode::setArcData( const QRectF& rect, const QskArcMetrics& arcMetrics
|
||||||
auto borderNode = static_cast< BorderNode* >(
|
auto borderNode = static_cast< BorderNode* >(
|
||||||
QskSGNode::findChildNode( this, BorderRole ) );
|
QskSGNode::findChildNode( this, BorderRole ) );
|
||||||
|
|
||||||
const auto arcRect = qskEffectiveRect( rect, borderWidth );
|
if ( metricsArc.isNull() || rect.isEmpty() )
|
||||||
if ( metricsArc.isNull() || arcRect.isEmpty() )
|
|
||||||
{
|
{
|
||||||
delete shadowNode;
|
delete shadowNode;
|
||||||
delete pathNode;
|
delete pathNode;
|
||||||
|
@ -125,12 +115,10 @@ void QskArcNode::setArcData( const QRectF& rect, const QskArcMetrics& arcMetrics
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto isFillNodeVisible = gradient.isVisible();
|
const auto isFillNodeVisible = gradient.isVisible();
|
||||||
const auto isStrokeNodeVisible = ( borderWidth > 0.0 ) && ( borderColor.alpha() > 0 );
|
const auto isBorderNodeVisible = ( borderWidth > 0.0 ) && ( borderColor.alpha() > 0 );
|
||||||
const auto isShadowNodeVisible = isFillNodeVisible &&
|
const auto isShadowNodeVisible = isFillNodeVisible &&
|
||||||
shadowColor.isValid() && ( shadowColor.alpha() > 0.0 );
|
shadowColor.isValid() && ( shadowColor.alpha() > 0.0 );
|
||||||
|
|
||||||
const auto path = metricsArc.painterPath( arcRect, radial );
|
|
||||||
|
|
||||||
if ( isShadowNodeVisible )
|
if ( isShadowNodeVisible )
|
||||||
{
|
{
|
||||||
if ( shadowNode == nullptr )
|
if ( shadowNode == nullptr )
|
||||||
|
@ -146,8 +134,8 @@ void QskArcNode::setArcData( const QRectF& rect, const QskArcMetrics& arcMetrics
|
||||||
and not only to its radius. TODO ...
|
and not only to its radius. TODO ...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const auto sm = shadowMetrics.toAbsolute( arcRect.size() );
|
const auto sm = shadowMetrics.toAbsolute( rect.size() );
|
||||||
const auto shadowRect = sm.shadowRect( arcRect );
|
const auto shadowRect = sm.shadowRect( rect );
|
||||||
const auto spreadRadius = sm.spreadRadius() + 0.5 * metricsArc.thickness();
|
const auto spreadRadius = sm.spreadRadius() + 0.5 * metricsArc.thickness();
|
||||||
|
|
||||||
shadowNode->setShadowData( shadowRect, spreadRadius, sm.blurRadius(),
|
shadowNode->setShadowData( shadowRect, spreadRadius, sm.blurRadius(),
|
||||||
|
@ -172,7 +160,7 @@ void QskArcNode::setArcData( const QRectF& rect, const QskArcMetrics& arcMetrics
|
||||||
QskSGNode::setNodeRole( arcNode, ArcRole );
|
QskSGNode::setNodeRole( arcNode, ArcRole );
|
||||||
}
|
}
|
||||||
|
|
||||||
arcNode->updateNode( arcRect, metricsArc, radial,
|
arcNode->updateNode( rect, metricsArc, radial,
|
||||||
borderWidth, QColor(), gradient );
|
borderWidth, QColor(), gradient );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -186,7 +174,8 @@ void QskArcNode::setArcData( const QRectF& rect, const QskArcMetrics& arcMetrics
|
||||||
QskSGNode::setNodeRole( pathNode, PathRole );
|
QskSGNode::setNodeRole( pathNode, PathRole );
|
||||||
}
|
}
|
||||||
|
|
||||||
pathNode->updateNode( path, QTransform(), arcRect,
|
const auto path = metricsArc.painterPath( rect, radial );
|
||||||
|
pathNode->updateNode( path, QTransform(), rect,
|
||||||
qskEffectiveGradient( gradient, metricsArc ) );
|
qskEffectiveGradient( gradient, metricsArc ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,7 +188,7 @@ void QskArcNode::setArcData( const QRectF& rect, const QskArcMetrics& arcMetrics
|
||||||
arcNode = nullptr;
|
arcNode = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isStrokeNodeVisible )
|
if ( isBorderNodeVisible )
|
||||||
{
|
{
|
||||||
if ( borderNode == nullptr )
|
if ( borderNode == nullptr )
|
||||||
{
|
{
|
||||||
|
@ -208,12 +197,13 @@ void QskArcNode::setArcData( const QRectF& rect, const QskArcMetrics& arcMetrics
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ARC_BORDER_NODE
|
#ifdef ARC_BORDER_NODE
|
||||||
borderNode->updateNode( arcRect, metricsArc, radial,
|
borderNode->updateNode( rect, metricsArc, radial,
|
||||||
borderWidth, borderColor, QskGradient() );
|
borderWidth, borderColor, QskGradient() );
|
||||||
#else
|
#else
|
||||||
QPen pen( borderColor, borderWidth );
|
QPen pen( borderColor, borderWidth );
|
||||||
pen.setCapStyle( Qt::FlatCap );
|
pen.setCapStyle( Qt::FlatCap );
|
||||||
|
|
||||||
|
const auto path = metricsArc.painterPath( rect, radial );
|
||||||
borderNode->updateNode( path, QTransform(), pen );
|
borderNode->updateNode( path, QTransform(), pen );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,11 +68,15 @@ void QskArcRenderNode::updateNode(
|
||||||
Q_D( QskArcRenderNode );
|
Q_D( QskArcRenderNode );
|
||||||
|
|
||||||
const auto metrics = arcMetrics.toAbsolute( rect.size() );
|
const auto metrics = arcMetrics.toAbsolute( rect.size() );
|
||||||
|
const auto borderMax = 0.5 * metrics.thickness();
|
||||||
|
|
||||||
|
const auto hasFilling = gradient.isVisible()
|
||||||
|
&& ( borderWidth < borderMax );
|
||||||
|
|
||||||
bool visible = !( rect.isEmpty() || metrics.isNull() );
|
bool visible = !( rect.isEmpty() || metrics.isNull() );
|
||||||
if ( visible )
|
if ( visible )
|
||||||
{
|
{
|
||||||
visible = gradient.isVisible();
|
visible = hasFilling;
|
||||||
if ( !visible )
|
if ( !visible )
|
||||||
{
|
{
|
||||||
visible = ( borderWidth > 0.0 )
|
visible = ( borderWidth > 0.0 )
|
||||||
|
@ -103,11 +107,12 @@ void QskArcRenderNode::updateNode(
|
||||||
|
|
||||||
if ( borderWidth > 0.0 && borderColor.isValid() )
|
if ( borderWidth > 0.0 && borderColor.isValid() )
|
||||||
{
|
{
|
||||||
|
borderWidth = std::min( borderWidth, borderMax );
|
||||||
QskArcRenderer::renderBorder(
|
QskArcRenderer::renderBorder(
|
||||||
rect, metrics, radial, borderWidth, borderColor, *geometry() );
|
rect, metrics, radial, borderWidth, borderColor, *geometry() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( gradient.isVisible() )
|
if ( hasFilling )
|
||||||
{
|
{
|
||||||
QskArcRenderer::renderFillGeometry(
|
QskArcRenderer::renderFillGeometry(
|
||||||
rect, metrics, radial, borderWidth, gradient, *geometry() );
|
rect, metrics, radial, borderWidth, gradient, *geometry() );
|
||||||
|
|
|
@ -378,8 +378,7 @@ void QskArcRenderer::renderFillGeometry( const QRectF& rect,
|
||||||
{
|
{
|
||||||
geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
|
geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
|
||||||
|
|
||||||
const auto b2 = 0.5 * borderWidth;
|
const auto r = rect.adjusted( borderWidth, borderWidth, -borderWidth, -borderWidth );
|
||||||
const auto r = rect.adjusted( b2, b2, -b2, -b2 );
|
|
||||||
|
|
||||||
FillStroker stroker( r, metrics, radial, gradient );
|
FillStroker stroker( r, metrics, radial, gradient );
|
||||||
|
|
||||||
|
@ -390,7 +389,7 @@ void QskArcRenderer::renderFillGeometry( const QRectF& rect,
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto effectiveCount = stroker.setLines(
|
const auto effectiveCount = stroker.setLines(
|
||||||
metrics.thickness() - borderWidth, lines );
|
metrics.thickness() - 2 * borderWidth, lines );
|
||||||
|
|
||||||
if ( effectiveCount > lineCount )
|
if ( effectiveCount > lineCount )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue