2022-12-06 15:52:55 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the QSkinny License, Version 1.0
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "QskBoxRenderer.h"
|
2022-12-28 18:39:08 +00:00
|
|
|
#include "QskRectRenderer.h"
|
|
|
|
#include "QskRoundedRectRenderer.h"
|
2022-12-06 15:52:55 +00:00
|
|
|
#include "QskBoxShapeMetrics.h"
|
|
|
|
|
|
|
|
#include "QskGradient.h"
|
|
|
|
#include "QskGradientDirection.h"
|
|
|
|
|
2023-01-10 11:17:56 +00:00
|
|
|
static inline QskGradient qskNormalizedGradient( const QskGradient gradient )
|
|
|
|
{
|
|
|
|
const auto dir = gradient.linearDirection();
|
|
|
|
if ( !dir.isTilted() )
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Dealing with inverted gradient vectors makes the code even
|
|
|
|
more unreadable. So we simply invert stops/vector instead.
|
|
|
|
*/
|
|
|
|
if ( ( dir.x1() > dir.x2() ) || ( dir.y1() > dir.y2() ) )
|
|
|
|
{
|
|
|
|
QskGradient g = gradient;
|
|
|
|
g.setLinearDirection( dir.x2(), dir.y2(), dir.x1(), dir.y1() );
|
|
|
|
|
|
|
|
if ( !g.isMonochrome() )
|
|
|
|
g.setStops( qskRevertedGradientStops( gradient.stops() ) );
|
|
|
|
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return gradient;
|
|
|
|
}
|
|
|
|
|
2022-12-06 15:52:55 +00:00
|
|
|
void QskBoxRenderer::renderBorder(
|
|
|
|
const QRectF& rect, const QskBoxShapeMetrics& shape,
|
|
|
|
const QskBoxBorderMetrics& border, QSGGeometry& geometry )
|
|
|
|
{
|
|
|
|
if ( shape.isRectangle() )
|
2022-12-28 18:39:08 +00:00
|
|
|
QskRectRenderer::renderBorder( rect, border, geometry );
|
2022-12-06 15:52:55 +00:00
|
|
|
else
|
2022-12-28 18:39:08 +00:00
|
|
|
QskRoundedRectRenderer::renderRectellipseBorder( rect, shape, border, geometry );
|
2022-12-06 15:52:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QskBoxRenderer::renderFill(
|
|
|
|
const QRectF& rect, const QskBoxShapeMetrics& shape,
|
|
|
|
const QskBoxBorderMetrics& border, QSGGeometry& geometry )
|
|
|
|
{
|
|
|
|
if ( shape.isRectangle() )
|
2022-12-28 18:39:08 +00:00
|
|
|
QskRectRenderer::renderFill( rect, border, geometry );
|
2022-12-06 15:52:55 +00:00
|
|
|
else
|
2022-12-28 18:39:08 +00:00
|
|
|
QskRoundedRectRenderer::renderRectellipseFill( rect, shape, border, geometry );
|
2022-12-06 15:52:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QskBoxRenderer::renderBox( const QRectF& rect,
|
|
|
|
const QskBoxShapeMetrics& shape, const QskBoxBorderMetrics& border,
|
|
|
|
const QskBoxBorderColors& borderColors, const QskGradient& gradient,
|
|
|
|
QSGGeometry& geometry )
|
|
|
|
{
|
2023-01-10 11:17:56 +00:00
|
|
|
const auto gradientN = qskNormalizedGradient( gradient );
|
|
|
|
|
2022-12-06 15:52:55 +00:00
|
|
|
if ( shape.isRectangle() )
|
2022-12-28 18:39:08 +00:00
|
|
|
{
|
|
|
|
QskRectRenderer::renderRect(
|
2023-01-10 11:17:56 +00:00
|
|
|
rect, border, borderColors, gradientN, geometry );
|
2022-12-28 18:39:08 +00:00
|
|
|
}
|
2022-12-06 15:52:55 +00:00
|
|
|
else
|
2022-12-28 18:39:08 +00:00
|
|
|
{
|
|
|
|
QskRoundedRectRenderer::renderRectellipse(
|
2023-01-10 11:17:56 +00:00
|
|
|
rect, shape, border, borderColors, gradientN, geometry );
|
2022-12-28 18:39:08 +00:00
|
|
|
}
|
2022-12-06 15:52:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool QskBoxRenderer::isGradientSupported(
|
2022-12-28 18:39:08 +00:00
|
|
|
const QskBoxShapeMetrics& shape, const QskGradient& gradient )
|
2022-12-06 15:52:55 +00:00
|
|
|
{
|
2022-12-28 18:39:08 +00:00
|
|
|
if ( !gradient.isVisible() || gradient.isMonochrome() )
|
2022-12-06 15:52:55 +00:00
|
|
|
return true;
|
|
|
|
|
2022-12-28 18:39:08 +00:00
|
|
|
if ( gradient.spreadMode() != QskGradient::PadSpread )
|
2022-12-06 15:52:55 +00:00
|
|
|
{
|
2022-12-28 18:39:08 +00:00
|
|
|
// Only true if the situation requires spreading TODO ...
|
|
|
|
return false;
|
|
|
|
}
|
2022-12-06 15:52:55 +00:00
|
|
|
|
2022-12-28 18:39:08 +00:00
|
|
|
switch( gradient.type() )
|
|
|
|
{
|
|
|
|
case QskGradient::Stops:
|
2022-12-10 15:08:32 +00:00
|
|
|
{
|
2022-12-28 18:39:08 +00:00
|
|
|
// will be rendered as vertical linear gradient
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case QskGradient::Linear:
|
|
|
|
{
|
2023-01-05 16:18:34 +00:00
|
|
|
const auto dir = gradient.linearDirection();
|
|
|
|
|
2022-12-28 18:39:08 +00:00
|
|
|
if ( shape.isRectangle() )
|
2022-12-06 15:52:55 +00:00
|
|
|
{
|
2022-12-28 18:39:08 +00:00
|
|
|
// rectangles are fully supported
|
2022-12-10 15:08:32 +00:00
|
|
|
return true;
|
2022-12-06 15:52:55 +00:00
|
|
|
}
|
2023-01-04 15:15:22 +00:00
|
|
|
|
|
|
|
if ( dir.isTilted() )
|
|
|
|
{
|
2023-01-10 11:09:53 +00:00
|
|
|
return ( dir.x1() == 0.0 ) && ( dir.x2() == 1.0 )
|
|
|
|
&& ( dir.y1() == 0.0 ) && ( dir.y2() == 1.0 );
|
2023-01-04 15:15:22 +00:00
|
|
|
}
|
2022-12-28 18:39:08 +00:00
|
|
|
else
|
|
|
|
{
|
2023-01-05 16:18:34 +00:00
|
|
|
qreal r1, r2, r3, r4;
|
2023-01-04 15:15:22 +00:00
|
|
|
|
|
|
|
if ( dir.isHorizontal() )
|
2022-12-28 18:39:08 +00:00
|
|
|
{
|
2023-01-05 16:18:34 +00:00
|
|
|
r1 = shape.radius( Qt::TopLeftCorner ).width();
|
|
|
|
r2 = shape.radius( Qt::BottomLeftCorner ).width();
|
|
|
|
r3 = shape.radius( Qt::TopRightCorner ).width();
|
|
|
|
r4 = shape.radius( Qt::BottomRightCorner ).width();
|
2022-12-28 18:39:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-01-05 16:18:34 +00:00
|
|
|
r1 = shape.radius( Qt::TopLeftCorner ).height();
|
|
|
|
r2 = shape.radius( Qt::TopRightCorner ).height();
|
|
|
|
r3 = shape.radius( Qt::BottomLeftCorner ).height();
|
|
|
|
r4 = shape.radius( Qt::BottomRightCorner ).height();
|
2022-12-28 18:39:08 +00:00
|
|
|
}
|
2023-01-05 16:18:34 +00:00
|
|
|
|
|
|
|
if ( ( r1 <= 0.0 || r2 <= 0.0 ) && ( r3 <= 0.0 || r4 <= 0.0 ) )
|
|
|
|
{
|
|
|
|
// one of the corners is not rounded
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// different radii at opposite corners are not implemented TODO ...
|
|
|
|
return ( r1 == r2 ) && ( r3 == r4 );
|
2022-12-28 18:39:08 +00:00
|
|
|
}
|
2023-01-04 15:15:22 +00:00
|
|
|
|
|
|
|
return false;
|
2022-12-06 15:52:55 +00:00
|
|
|
}
|
2022-12-10 15:08:32 +00:00
|
|
|
|
2022-12-28 18:39:08 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
// Radial/Conical gradients have to be done with QskGradientMaterial
|
|
|
|
return false;
|
2022-12-06 15:52:55 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-10 15:08:32 +00:00
|
|
|
|
|
|
|
return false;
|
2022-12-06 15:52:55 +00:00
|
|
|
}
|