6#include "QskBoxRenderer.h"
7#include "QskBoxShapeMetrics.h"
8#include "QskBoxBorderMetrics.h"
9#include "QskBoxBorderColors.h"
10#include "QskBoxMetrics.h"
11#include "QskBoxBasicStroker.h"
12#include "QskBoxGradientStroker.h"
14#include "QskGradient.h"
15#include "QskGradientDirection.h"
16#include "QskFunctions.h"
18#include <qsggeometry.h>
21 QSGGeometry& geometry,
int lineCount )
23 geometry.allocate( 2 * lineCount );
28 QSGGeometry& geometry,
int lineCount )
30 geometry.allocate( 2 * lineCount );
37 if ( !gradient.isVisible() )
40 const auto dir = gradient.linearDirection();
44 if ( !dir.isTilted() )
50 if ( ( dir.x1() > dir.x2() ) || ( dir.y1() > dir.y2() ) )
52 g.setLinearDirection( dir.x2(), dir.y2(), dir.x1(), dir.y1() );
54 if ( !g.isMonochrome() )
55 g.setStops( qskRevertedGradientStops( gradient.stops() ) );
59 if ( g.stretchMode() == QskGradient::StretchToSize )
65static inline bool qskMaybeSpreading(
const QskGradient& gradient )
67 if ( gradient.stretchMode() == QskGradient::StretchToSize )
68 return !gradient.linearDirection().contains( QRectF( 0, 0, 1, 1 ) );
73QskBoxRenderer::QskBoxRenderer(
const QQuickWindow* window )
78QskBoxRenderer::~QskBoxRenderer()
82bool QskBoxRenderer::isGradientSupported(
const QskGradient& gradient )
84 if ( !gradient.isVisible() || gradient.isMonochrome() )
87 switch( gradient.type() )
89 case QskGradient::Stops:
94 case QskGradient::Linear:
96 if ( ( gradient.spreadMode() != QskGradient::PadSpread )
97 && qskMaybeSpreading( gradient ) )
121void QskBoxRenderer::setBorderLines(
125 geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
126 geometry.markVertexDataDirty();
131 const auto lines = qskAllocateLines( geometry, stroker.borderCount() );
133 stroker.setBorderLines( lines );
136void QskBoxRenderer::setFillLines(
142void QskBoxRenderer::setFillLines(
146 geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
147 geometry.markVertexDataDirty();
152 if (
auto lines = qskAllocateLines( geometry, stroker.fillCount() ) )
153 stroker.setFillLines( lines );
156void QskBoxRenderer::setColoredFillLines(
const QRectF& rect,
158 const QskGradient& gradient, QSGGeometry& geometry )
160 setColoredBorderAndFillLines( rect, shape, border,
164void QskBoxRenderer::setColoredBorderLines(
const QRectF& rect,
168 geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
169 geometry.markVertexDataDirty();
173 if (
auto lines = qskAllocateColoredLines( geometry, stroker.borderCount() ) )
174 stroker.setBoxLines( lines,
nullptr );
177void QskBoxRenderer::setColoredBorderAndFillLines(
const QRectF& rect,
180 QSGGeometry& geometry )
182 geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
183 geometry.markVertexDataDirty();
186 const auto effectiveGradient = qskEffectiveGradient( metrics.innerRect, gradient );
188 if ( metrics.innerRect.isEmpty() ||
189 QskVertex::ColorMap::isGradientSupported( effectiveGradient, metrics.innerRect ) )
202 const int fillCount = stroker.fillCount();
203 const int borderCount = stroker.borderCount();
205 if (
auto lines = qskAllocateColoredLines( geometry, borderCount + fillCount ) )
207 auto fillLines = fillCount ? lines :
nullptr;
208 auto borderLines = borderCount ? lines + fillCount :
nullptr;
210 stroker.setBoxLines( borderLines, fillLines );
222 const int fillCount = fillStroker.lineCount();
223 const int borderCount = borderStroker.borderCount();
224 const int extraLine = ( fillCount && borderCount ) ? 1 : 0;
226 auto lines = qskAllocateColoredLines(
227 geometry, fillCount + borderCount + extraLine );
230 fillStroker.setLines( fillCount, lines );
233 borderStroker.setBorderLines( lines + fillCount + extraLine );
238 const auto l = lines + fillCount;
247 if ( ( gradient.type() == QskGradient::Stops ) || gradient.isMonochrome() )
252 g.setDirection( QskGradient::Linear );