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();
174 if (
auto lines = qskAllocateColoredLines( geometry, stroker.borderCount() ) )
175 stroker.setBoxLines( lines,
nullptr );
178void QskBoxRenderer::setColoredBorderAndFillLines(
const QRectF& rect,
181 QSGGeometry& geometry )
183 geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
184 geometry.markVertexDataDirty();
187 const auto effectiveGradient = qskEffectiveGradient( metrics.innerRect, gradient );
189 if ( metrics.innerRect.isEmpty() ||
190 QskVertex::ColorMap::isGradientSupported( effectiveGradient, metrics.innerRect ) )
203 const int fillCount = stroker.fillCount();
204 const int borderCount = stroker.borderCount();
206 if (
auto lines = qskAllocateColoredLines( geometry, borderCount + fillCount ) )
208 auto fillLines = fillCount ? lines :
nullptr;
209 auto borderLines = borderCount ? lines + fillCount :
nullptr;
211 stroker.setBoxLines( borderLines, fillLines );
223 const int fillCount = fillStroker.lineCount();
224 const int borderCount = borderStroker.borderCount();
225 const int extraLine = ( fillCount && borderCount ) ? 1 : 0;
227 auto lines = qskAllocateColoredLines(
228 geometry, fillCount + borderCount + extraLine );
231 fillStroker.setLines( fillCount, lines );
234 borderStroker.setBorderLines( lines + fillCount + extraLine );
239 const auto l = lines + fillCount;
248 if ( ( gradient.type() == QskGradient::Stops ) || gradient.isMonochrome() )
253 g.setDirection( QskGradient::Linear );