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"
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
if ( shape.isRectangle() )
|
2022-12-28 18:39:08 +00:00
|
|
|
{
|
|
|
|
QskRectRenderer::renderRect(
|
|
|
|
rect, border, borderColors, gradient, geometry );
|
|
|
|
}
|
2022-12-06 15:52:55 +00:00
|
|
|
else
|
2022-12-28 18:39:08 +00:00
|
|
|
{
|
|
|
|
QskRoundedRectRenderer::renderRectellipse(
|
|
|
|
rect, shape, border, borderColors, gradient, geometry );
|
|
|
|
}
|
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:
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
const auto dir = gradient.linearDirection();
|
|
|
|
|
|
|
|
if ( dir.isTilted() )
|
|
|
|
{
|
|
|
|
return ( dir.x1() == 0.0 && dir.x2() == 0.0 )
|
|
|
|
&& ( dir.y1() == 1.0 && dir.y2() == 1.0 );
|
|
|
|
}
|
2022-12-28 18:39:08 +00:00
|
|
|
else
|
|
|
|
{
|
2023-01-04 15:15:22 +00:00
|
|
|
// different radii at oppsoite corners are not implemented TODO ...
|
2022-12-28 18:39:08 +00:00
|
|
|
|
2023-01-04 15:15:22 +00:00
|
|
|
const auto r1 = shape.radius( Qt::TopLeftCorner );
|
|
|
|
const auto r2 = shape.radius( Qt::TopRightCorner );
|
|
|
|
const auto r3 = shape.radius( Qt::BottomLeftCorner );
|
|
|
|
const auto r4 = shape.radius( Qt::BottomRightCorner );
|
|
|
|
|
|
|
|
if ( dir.isHorizontal() )
|
2022-12-28 18:39:08 +00:00
|
|
|
{
|
2023-01-04 15:15:22 +00:00
|
|
|
if ( dir.x1() == 0.0 && dir.x2() == 1.0 )
|
|
|
|
{
|
|
|
|
return ( r1.width() == r3.width() )
|
|
|
|
&& ( r2.width() == r4.width() );
|
|
|
|
}
|
2022-12-28 18:39:08 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-01-04 15:15:22 +00:00
|
|
|
if ( dir.y1() == 0.0 && dir.y2() == 1.0 )
|
|
|
|
{
|
|
|
|
return ( r1.height() == r2.height() )
|
|
|
|
&& ( r3.height() == r4.height() );
|
|
|
|
}
|
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
|
|
|
}
|