QskArcRenderer API in line with QskBoxRenderer
This commit is contained in:
parent
31470a7a50
commit
98967a5619
|
@ -14,7 +14,11 @@
|
||||||
class QskArcRenderNodePrivate final : public QskFillNodePrivate
|
class QskArcRenderNodePrivate final : public QskFillNodePrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline void resetValues() { hash = 0; }
|
inline void resetNode( QskArcRenderNode* node )
|
||||||
|
{
|
||||||
|
hash = 0;
|
||||||
|
node->resetGeometry();
|
||||||
|
}
|
||||||
|
|
||||||
QskHashValue hash = 0;
|
QskHashValue hash = 0;
|
||||||
};
|
};
|
||||||
|
@ -55,9 +59,7 @@ void QskArcRenderNode::updateNode(
|
||||||
|
|
||||||
if ( rect.isEmpty() || metrics.isNull() || !( hasFill || hasBorder ) )
|
if ( rect.isEmpty() || metrics.isNull() || !( hasFill || hasBorder ) )
|
||||||
{
|
{
|
||||||
d->resetValues();
|
d->resetNode( this );
|
||||||
QskSGNode::resetGeometry( this );
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,45 +79,18 @@ void QskArcRenderNode::updateNode(
|
||||||
|
|
||||||
d->hash = hash;
|
d->hash = hash;
|
||||||
|
|
||||||
auto coloring = QskFillNode::Polychrome;
|
#if 1
|
||||||
|
const bool coloredGeometry = hasHint( PreferColoredGeometry )
|
||||||
#if 0
|
&& QskArcRenderer::isGradientSupported( rect, metrics, gradient );
|
||||||
if ( !( hasFill && hasBorder ) )
|
Q_ASSERT( coloredGeometry ); // TODO ...
|
||||||
{
|
|
||||||
if ( hasBorder || ( hasFill && gradient.isMonochrome() ) )
|
|
||||||
coloring = QskFillNode::Monochrome;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto& geometry = *this->geometry();
|
auto& geometry = *this->geometry();
|
||||||
|
|
||||||
if ( coloring == QskFillNode::Polychrome )
|
setColoring( QskFillNode::Polychrome );
|
||||||
{
|
|
||||||
setColoring( coloring );
|
|
||||||
|
|
||||||
QskArcRenderer::renderArc( rect, metrics, radial,
|
QskArcRenderer::setColoredBorderAndFillLines( rect, metrics, radial,
|
||||||
borderWidth, gradient, borderColor, geometry );
|
borderWidth, borderColor, gradient, geometry );
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( hasFill )
|
|
||||||
{
|
|
||||||
setColoring( gradient.rgbStart() );
|
|
||||||
|
|
||||||
QskArcRenderer::renderArc( rect, metrics, radial,
|
|
||||||
borderWidth, gradient, borderColor, geometry );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
setColoring( borderColor );
|
|
||||||
|
|
||||||
QskArcRenderer::renderArc( rect, metrics, radial,
|
|
||||||
borderWidth, gradient, borderColor, geometry );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
markDirty( QSGNode::DirtyGeometry );
|
markDirty( QSGNode::DirtyGeometry );
|
||||||
markDirty( QSGNode::DirtyMaterial );
|
|
||||||
|
|
||||||
geometry.markVertexDataDirty();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include "QskRgbValue.h"
|
#include "QskRgbValue.h"
|
||||||
|
|
||||||
#include <qsggeometry.h>
|
#include <qsggeometry.h>
|
||||||
#include <qdebug.h>
|
|
||||||
|
|
||||||
static inline QskVertex::Line* qskAllocateLines(
|
static inline QskVertex::Line* qskAllocateLines(
|
||||||
QSGGeometry& geometry, int lineCount )
|
QSGGeometry& geometry, int lineCount )
|
||||||
|
@ -466,8 +465,8 @@ bool QskArcRenderer::isGradientSupported( const QRectF& rect,
|
||||||
if ( qskFuzzyCompare( direction.aspectRatio(), aspectRatio ) )
|
if ( qskFuzzyCompare( direction.aspectRatio(), aspectRatio ) )
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
we should be able to create a list of stops from
|
we should be able to create a list of stops from
|
||||||
this gradient that works for the renderer. TODO ...
|
this gradient that works for the renderer. TODO ...
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -483,17 +482,55 @@ bool QskArcRenderer::isGradientSupported( const QRectF& rect,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskArcRenderer::renderArc( const QRectF& rect, const QskArcMetrics& metrics,
|
void QskArcRenderer::setColoredBorderLines( const QRectF& rect,
|
||||||
bool radial, const QskGradient& gradient, QSGGeometry& geometry )
|
const QskArcMetrics& metrics, bool radial, qreal borderWidth,
|
||||||
{
|
|
||||||
renderArc( rect, metrics, radial, 0, gradient, QColor(), geometry );
|
|
||||||
}
|
|
||||||
|
|
||||||
void QskArcRenderer::renderArc( const QRectF& rect, const QskArcMetrics& metrics,
|
|
||||||
bool radial, qreal borderWidth, const QskGradient& gradient,
|
|
||||||
const QColor& borderColor, QSGGeometry& geometry )
|
const QColor& borderColor, QSGGeometry& geometry )
|
||||||
{
|
{
|
||||||
geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
|
geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
|
||||||
|
geometry.markVertexDataDirty();
|
||||||
|
|
||||||
|
if ( borderWidth <= 0.0 || !( borderColor.isValid() && borderColor.alpha() > 0 ) )
|
||||||
|
{
|
||||||
|
qskAllocateColoredLines( geometry, 0 );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Renderer renderer( rect, metrics, radial, QskGradient(), borderColor );
|
||||||
|
|
||||||
|
if ( const auto lines = qskAllocateColoredLines( geometry, renderer.borderCount() ) )
|
||||||
|
{
|
||||||
|
renderer.renderArc( metrics.thickness(), borderWidth,
|
||||||
|
static_cast< QskVertex::ColoredLine* >( nullptr ), lines );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void QskArcRenderer::setColoredFillLines( const QRectF& rect, const QskArcMetrics& metrics,
|
||||||
|
bool radial, const QskGradient& gradient, QSGGeometry& geometry )
|
||||||
|
{
|
||||||
|
geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
|
||||||
|
geometry.markVertexDataDirty();
|
||||||
|
|
||||||
|
if ( !gradient.isVisible() )
|
||||||
|
{
|
||||||
|
qskAllocateColoredLines( geometry, 0 );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Renderer renderer( rect, metrics, radial, gradient, QColor( 0, 0, 0, 0 ) );
|
||||||
|
|
||||||
|
if ( const auto lines = qskAllocateColoredLines( geometry, renderer.fillCount() ) )
|
||||||
|
{
|
||||||
|
renderer.renderArc( metrics.thickness(), 0.0, lines,
|
||||||
|
static_cast< QskVertex::ColoredLine* >( nullptr ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void QskArcRenderer::setColoredBorderAndFillLines( const QRectF& rect,
|
||||||
|
const QskArcMetrics& metrics, bool radial, qreal borderWidth,
|
||||||
|
const QColor& borderColor, const QskGradient& gradient, QSGGeometry& geometry )
|
||||||
|
{
|
||||||
|
geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
|
||||||
|
geometry.markVertexDataDirty();
|
||||||
|
|
||||||
const Renderer renderer( rect, metrics, radial, gradient,
|
const Renderer renderer( rect, metrics, radial, gradient,
|
||||||
borderColor.isValid() ? borderColor : QColor( 0, 0, 0, 0 ) );
|
borderColor.isValid() ? borderColor : QColor( 0, 0, 0, 0 ) );
|
||||||
|
@ -523,13 +560,20 @@ void QskArcRenderer::renderArc( const QRectF& rect, const QskArcMetrics& metrics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskArcRenderer::renderBorderGeometry( const QRectF& rect,
|
void QskArcRenderer::setBorderLines( const QRectF& rect,
|
||||||
const QskArcMetrics& metrics, bool radial, qreal borderWidth, QSGGeometry& geometry )
|
const QskArcMetrics& metrics, bool radial, qreal borderWidth, QSGGeometry& geometry )
|
||||||
{
|
{
|
||||||
geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
|
geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
|
||||||
|
geometry.markVertexDataDirty();
|
||||||
|
|
||||||
|
if ( borderWidth <= 0.0 )
|
||||||
|
{
|
||||||
|
qskAllocateLines( geometry, 0 );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const Renderer renderer( rect, metrics, radial, QskGradient(), 0 );
|
const Renderer renderer( rect, metrics, radial, QskGradient(), 0 );
|
||||||
|
|
||||||
const auto lines = qskAllocateLines( geometry, renderer.borderCount() );
|
const auto lines = qskAllocateLines( geometry, renderer.borderCount() );
|
||||||
if ( lines )
|
if ( lines )
|
||||||
{
|
{
|
||||||
|
@ -538,10 +582,11 @@ void QskArcRenderer::renderBorderGeometry( const QRectF& rect,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskArcRenderer::renderFillGeometry( const QRectF& rect,
|
void QskArcRenderer::setFillLines( const QRectF& rect,
|
||||||
const QskArcMetrics& metrics, bool radial, qreal borderWidth, QSGGeometry& geometry )
|
const QskArcMetrics& metrics, bool radial, qreal borderWidth, QSGGeometry& geometry )
|
||||||
{
|
{
|
||||||
geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
|
geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
|
||||||
|
geometry.markVertexDataDirty();
|
||||||
|
|
||||||
const Renderer renderer( rect, metrics, radial, QskRgb::Black, 0 );
|
const Renderer renderer( rect, metrics, radial, QskRgb::Black, 0 );
|
||||||
|
|
||||||
|
|
|
@ -25,24 +25,31 @@ namespace QskArcRenderer
|
||||||
- using shaders setting the colors
|
- using shaders setting the colors
|
||||||
*/
|
*/
|
||||||
|
|
||||||
QSK_EXPORT void renderBorderGeometry( const QRectF&,
|
QSK_EXPORT void setBorderLines( const QRectF&,
|
||||||
const QskArcMetrics&, bool radial, qreal borderWidth, QSGGeometry& );
|
const QskArcMetrics&, bool radial, qreal borderWidth, QSGGeometry& );
|
||||||
|
|
||||||
QSK_EXPORT void renderFillGeometry( const QRectF&,
|
QSK_EXPORT void setFillLines( const QRectF&,
|
||||||
const QskArcMetrics&, bool radial, qreal borderWidth, QSGGeometry& );
|
const QskArcMetrics&, bool radial, qreal borderWidth, QSGGeometry& );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Filling the geometry with color information:
|
Filling the geometry with color information:
|
||||||
see QSGGeometry::defaultAttributes_ColoredPoint2D()
|
see QSGGeometry::defaultAttributes_ColoredPoint2D()
|
||||||
|
|
||||||
|
Usually used in combination with QSGVertexColorMaterial
|
||||||
*/
|
*/
|
||||||
QSK_EXPORT bool isGradientSupported(
|
QSK_EXPORT bool isGradientSupported(
|
||||||
const QRectF&, const QskArcMetrics&, const QskGradient& );
|
const QRectF&, const QskArcMetrics&, const QskGradient& );
|
||||||
|
|
||||||
QSK_EXPORT void renderArc( const QRectF&, const QskArcMetrics&, bool radial,
|
QSK_EXPORT void setColoredBorderLines( const QRectF&,
|
||||||
qreal borderWidth, const QskGradient&, const QColor& borderColor, QSGGeometry& );
|
const QskArcMetrics&, bool radial, qreal borderWidth,
|
||||||
|
const QColor& borderColor, QSGGeometry& );
|
||||||
|
|
||||||
QSK_EXPORT void renderArc( const QRectF&, const QskArcMetrics&, bool radial,
|
QSK_EXPORT void setColoredFillLines( const QRectF&,
|
||||||
const QskGradient&, QSGGeometry& );
|
const QskArcMetrics&, bool radial, const QskGradient&, QSGGeometry& );
|
||||||
|
|
||||||
|
QSK_EXPORT void setColoredBorderAndFillLines( const QRectF&,
|
||||||
|
const QskArcMetrics&, bool radial, qreal borderWidth,
|
||||||
|
const QColor& borderColor, const QskGradient&, QSGGeometry& );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue