code reorganized
This commit is contained in:
parent
38130ffb7b
commit
c715b625fb
|
@ -91,12 +91,6 @@ namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
inline QPointF normalVector( const qreal radians ) const
|
|
||||||
{
|
|
||||||
return normalVector( qFastCos( radians ), qFastSin( radians ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
inline QPointF normalVector( const qreal cos, const qreal sin ) const
|
inline QPointF normalVector( const qreal cos, const qreal sin ) const
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -212,33 +206,26 @@ namespace
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
class StrokerBase
|
class ArcStroker
|
||||||
{
|
{
|
||||||
protected:
|
public:
|
||||||
StrokerBase( const QRectF& rect, const QskArcMetrics& metrics, bool radial )
|
ArcStroker( const QRectF&, const QskArcMetrics&,
|
||||||
: m_rect( rect )
|
bool radial, const QskGradient&, const QColor& borderColor );
|
||||||
, m_radians1( qDegreesToRadians( metrics.startAngle() ) )
|
|
||||||
, m_radians2( qDegreesToRadians( metrics.endAngle() ) )
|
|
||||||
, m_radial( qFuzzyCompare( rect.width(), rect.height() ) ? true : radial )
|
|
||||||
, m_closed( metrics.isClosed() )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int arcLineCount() const
|
int fillCount() const;
|
||||||
{
|
int setFillLines( qreal thickness, qreal border, QskVertex::ColoredLine* ) const;
|
||||||
// not very sophisticated - TODO ...
|
|
||||||
|
|
||||||
const auto radius = 0.5 * qMax( m_rect.width(), m_rect.height() );
|
int borderCount() const;
|
||||||
const auto radians = qAbs( m_radians2 - m_radians1 );
|
int setBorderLines( qreal thickness, qreal border, QskVertex::ColoredLine* ) const;
|
||||||
|
|
||||||
const auto count = qCeil( ( radius * radians ) / 3.0 );
|
private:
|
||||||
return qBound( 3, count, 160 );
|
int arcLineCount() const;
|
||||||
}
|
|
||||||
|
|
||||||
inline qreal radiansAt( qreal progress ) const
|
template< class LineStroker >
|
||||||
{
|
int renderFillLines( const LineStroker&, QskVertex::ColoredLine* ) const;
|
||||||
return m_radians1 + progress * ( m_radians2 - m_radians1 );
|
|
||||||
}
|
template< class LineStroker >
|
||||||
|
int renderBorderLines( const LineStroker&, QskVertex::ColoredLine* ) const;
|
||||||
|
|
||||||
const QRectF& m_rect;
|
const QRectF& m_rect;
|
||||||
|
|
||||||
|
@ -247,56 +234,56 @@ namespace
|
||||||
|
|
||||||
const bool m_radial; // for circular arcs radial/orthogonal does not differ
|
const bool m_radial; // for circular arcs radial/orthogonal does not differ
|
||||||
const bool m_closed;
|
const bool m_closed;
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
class FillStroker : private StrokerBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FillStroker( const QRectF&, const QskArcMetrics&,
|
|
||||||
bool radial, const QskGradient& );
|
|
||||||
|
|
||||||
int lineCount() const;
|
|
||||||
int setLines( qreal thickness, qreal border, QskVertex::ColoredLine* ) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
template< class LineStroker >
|
|
||||||
int renderLines( const LineStroker&, QskVertex::ColoredLine* ) const;
|
|
||||||
|
|
||||||
const QskGradient& m_gradient;
|
const QskGradient& m_gradient;
|
||||||
|
const QskVertex::Color m_borderColor;
|
||||||
};
|
};
|
||||||
|
|
||||||
FillStroker::FillStroker( const QRectF& rect,
|
ArcStroker::ArcStroker( const QRectF& rect, const QskArcMetrics& metrics,
|
||||||
const QskArcMetrics& metrics, bool radial, const QskGradient& gradient )
|
bool radial, const QskGradient& gradient, const QColor& borderColor )
|
||||||
: StrokerBase( rect, metrics, radial )
|
: m_rect( rect )
|
||||||
|
, m_radians1( qDegreesToRadians( metrics.startAngle() ) )
|
||||||
|
, m_radians2( qDegreesToRadians( metrics.endAngle() ) )
|
||||||
|
, m_radial( qFuzzyCompare( rect.width(), rect.height() ) ? true : radial )
|
||||||
|
, m_closed( metrics.isClosed() )
|
||||||
, m_gradient( gradient )
|
, m_gradient( gradient )
|
||||||
|
, m_borderColor( borderColor )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int FillStroker::lineCount() const
|
int ArcStroker::arcLineCount() const
|
||||||
|
{
|
||||||
|
// not very sophisticated - TODO ...
|
||||||
|
|
||||||
|
const auto radius = 0.5 * qMax( m_rect.width(), m_rect.height() );
|
||||||
|
const auto radians = qAbs( m_radians2 - m_radians1 );
|
||||||
|
|
||||||
|
const auto count = qCeil( ( radius * radians ) / 3.0 );
|
||||||
|
return qBound( 3, count, 160 );
|
||||||
|
}
|
||||||
|
|
||||||
|
int ArcStroker::fillCount() const
|
||||||
{
|
{
|
||||||
return arcLineCount() + m_gradient.stepCount() - 1;
|
return arcLineCount() + m_gradient.stepCount() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int FillStroker::setLines( const qreal thickness,
|
inline int ArcStroker::setFillLines( const qreal thickness,
|
||||||
const qreal border, QskVertex::ColoredLine* lines ) const
|
const qreal border, QskVertex::ColoredLine* lines ) const
|
||||||
{
|
{
|
||||||
if ( m_radial )
|
if ( m_radial )
|
||||||
{
|
{
|
||||||
const RadialStroker lineStroker( m_rect, thickness, border );
|
const RadialStroker lineStroker( m_rect, thickness, border );
|
||||||
return renderLines( lineStroker, lines );
|
return renderFillLines( lineStroker, lines );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const OrthogonalStroker lineStroker( m_rect, thickness, border );
|
const OrthogonalStroker lineStroker( m_rect, thickness, border );
|
||||||
return renderLines( lineStroker, lines );
|
return renderFillLines( lineStroker, lines );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class LineStroker >
|
template< class LineStroker >
|
||||||
inline int FillStroker::renderLines(
|
inline int ArcStroker::renderFillLines(
|
||||||
const LineStroker& stroker, QskVertex::ColoredLine* lines ) const
|
const LineStroker& stroker, QskVertex::ColoredLine* lines ) const
|
||||||
{
|
{
|
||||||
auto l = lines;
|
auto l = lines;
|
||||||
|
@ -323,7 +310,9 @@ namespace
|
||||||
|
|
||||||
while( !it.isDone() && ( it.position() < progress ) )
|
while( !it.isDone() && ( it.position() < progress ) )
|
||||||
{
|
{
|
||||||
stroker.setLine( radiansAt( it.position() ), it.color(), *l++ );
|
const auto radians = m_radians1 + it.position() * ( m_radians2 - m_radians1 );
|
||||||
|
stroker.setLine( radians, it.color(), *l++ );
|
||||||
|
|
||||||
it.advance();
|
it.advance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,34 +322,8 @@ namespace
|
||||||
|
|
||||||
return l - lines;
|
return l - lines;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
namespace
|
int ArcStroker::borderCount() const
|
||||||
{
|
|
||||||
class BorderStroker : StrokerBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
BorderStroker( const QRectF&, const QskArcMetrics&,
|
|
||||||
bool radial, const QColor& color );
|
|
||||||
|
|
||||||
int lineCount() const;
|
|
||||||
int setLines( qreal thickness, qreal border, QskVertex::ColoredLine* ) const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
template< class LineStroker >
|
|
||||||
int renderLines( const LineStroker&, QskVertex::ColoredLine* ) const;
|
|
||||||
|
|
||||||
const QskVertex::Color m_color;
|
|
||||||
};
|
|
||||||
|
|
||||||
BorderStroker::BorderStroker( const QRectF& rect,
|
|
||||||
const QskArcMetrics& metrics, bool radial, const QColor& color )
|
|
||||||
: StrokerBase( rect, metrics, radial )
|
|
||||||
, m_color( color )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int BorderStroker::lineCount() const
|
|
||||||
{
|
{
|
||||||
auto count = 2 * arcLineCount();
|
auto count = 2 * arcLineCount();
|
||||||
if ( !m_closed )
|
if ( !m_closed )
|
||||||
|
@ -369,23 +332,23 @@ namespace
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BorderStroker::setLines( const qreal thickness, const qreal border,
|
int ArcStroker::setBorderLines( const qreal thickness, const qreal border,
|
||||||
QskVertex::ColoredLine* lines ) const
|
QskVertex::ColoredLine* lines ) const
|
||||||
{
|
{
|
||||||
if ( m_radial )
|
if ( m_radial )
|
||||||
{
|
{
|
||||||
const RadialStroker stroker( m_rect, thickness, border );
|
const RadialStroker stroker( m_rect, thickness, border );
|
||||||
return renderLines( stroker, lines );
|
return renderBorderLines( stroker, lines );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const OrthogonalStroker stroker( m_rect, thickness, border );
|
const OrthogonalStroker stroker( m_rect, thickness, border );
|
||||||
return renderLines( stroker, lines );
|
return renderBorderLines( stroker, lines );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template< class LineStroker >
|
template< class LineStroker >
|
||||||
inline int BorderStroker::renderLines( const LineStroker& stroker,
|
inline int ArcStroker::renderBorderLines( const LineStroker& stroker,
|
||||||
QskVertex::ColoredLine* lines ) const
|
QskVertex::ColoredLine* lines ) const
|
||||||
{
|
{
|
||||||
const auto count = arcLineCount();
|
const auto count = arcLineCount();
|
||||||
|
@ -404,15 +367,15 @@ namespace
|
||||||
for ( int i = 0; i < count; i++ )
|
for ( int i = 0; i < count; i++ )
|
||||||
{
|
{
|
||||||
stroker.setBorderLines( m_radians1 + i * stepSize,
|
stroker.setBorderLines( m_radians1 + i * stepSize,
|
||||||
m_color, outer[i], inner[count - 1 - i] );
|
m_borderColor, outer[i], inner[count - 1 - i] );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !m_closed )
|
if ( !m_closed )
|
||||||
{
|
{
|
||||||
const auto sign = ( stepSize > 0.0 ) ? 1.0 : -1.0;
|
const auto sign = ( stepSize > 0.0 ) ? 1.0 : -1.0;
|
||||||
|
|
||||||
stroker.setClosingBorderLines( inner[count - 1].p1, outer, sign, m_color );
|
stroker.setClosingBorderLines( inner[count - 1].p1, outer, sign, m_borderColor );
|
||||||
stroker.setClosingBorderLines( outer[count - 1].p1, inner, sign, m_color );
|
stroker.setClosingBorderLines( outer[count - 1].p1, inner, sign, m_borderColor );
|
||||||
}
|
}
|
||||||
|
|
||||||
return 2 * ( count + ( m_closed ? 0 : 3 ) );
|
return 2 * ( count + ( m_closed ? 0 : 3 ) );
|
||||||
|
@ -433,15 +396,15 @@ void QskArcRenderer::renderFillGeometry( const QRectF& rect,
|
||||||
{
|
{
|
||||||
geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
|
geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
|
||||||
|
|
||||||
FillStroker stroker( rect, metrics, radial, gradient );
|
ArcStroker stroker( rect, metrics, radial, gradient, QColor() );
|
||||||
|
|
||||||
const auto lineCount = stroker.lineCount();
|
const auto lineCount = stroker.fillCount();
|
||||||
|
|
||||||
const auto lines = qskAllocateColoredLines( geometry, lineCount );
|
const auto lines = qskAllocateColoredLines( geometry, lineCount );
|
||||||
if ( lines == nullptr )
|
if ( lines == nullptr )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto effectiveCount = stroker.setLines(
|
const auto effectiveCount = stroker.setFillLines(
|
||||||
metrics.thickness(), borderWidth, lines );
|
metrics.thickness(), borderWidth, lines );
|
||||||
|
|
||||||
if ( effectiveCount > lineCount )
|
if ( effectiveCount > lineCount )
|
||||||
|
@ -469,14 +432,14 @@ void QskArcRenderer::renderBorder( const QRectF& rect, const QskArcMetrics& metr
|
||||||
|
|
||||||
geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
|
geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
|
||||||
|
|
||||||
BorderStroker stroker( rect, metrics, radial, borderColor );
|
ArcStroker stroker( rect, metrics, radial, QskGradient(), borderColor );
|
||||||
|
|
||||||
const auto lineCount = stroker.lineCount();
|
const auto lineCount = stroker.borderCount();
|
||||||
|
|
||||||
const auto lines = qskAllocateColoredLines( geometry, lineCount );
|
const auto lines = qskAllocateColoredLines( geometry, lineCount );
|
||||||
if ( lines )
|
if ( lines )
|
||||||
{
|
{
|
||||||
const auto effectiveCount = stroker.setLines(
|
const auto effectiveCount = stroker.setBorderLines(
|
||||||
metrics.thickness(), borderWidth, lines );
|
metrics.thickness(), borderWidth, lines );
|
||||||
|
|
||||||
if ( lineCount != effectiveCount )
|
if ( lineCount != effectiveCount )
|
||||||
|
|
Loading…
Reference in New Issue