qskinny/src/nodes/QskBoxRenderer.cpp

107 lines
3.2 KiB
C++
Raw Normal View History

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"
#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() )
QskRectRenderer::renderBorder( rect, border, geometry );
2022-12-06 15:52:55 +00:00
else
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() )
QskRectRenderer::renderFill( rect, border, geometry );
2022-12-06 15:52:55 +00:00
else
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() )
{
QskRectRenderer::renderRect(
rect, border, borderColors, gradient, geometry );
}
2022-12-06 15:52:55 +00:00
else
{
QskRoundedRectRenderer::renderRectellipse(
rect, shape, border, borderColors, gradient, geometry );
}
2022-12-06 15:52:55 +00:00
}
bool QskBoxRenderer::isGradientSupported(
const QskBoxShapeMetrics& shape, const QskGradient& gradient )
2022-12-06 15:52:55 +00:00
{
if ( !gradient.isVisible() || gradient.isMonochrome() )
2022-12-06 15:52:55 +00:00
return true;
if ( gradient.spreadMode() != QskGradient::PadSpread )
2022-12-06 15:52:55 +00:00
{
// Only true if the situation requires spreading TODO ...
return false;
}
2022-12-06 15:52:55 +00:00
switch( gradient.type() )
{
case QskGradient::Stops:
2022-12-10 15:08:32 +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
{
// rectangles are fully supported
2022-12-10 15:08:32 +00:00
return true;
2022-12-06 15:52:55 +00:00
}
else
{
/*
For rounded rectangles we currently support
only the most common use cases. TODO ...
*/
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 );
}
else
{
return ( dir.x1() == 0.0 && dir.x2() == 1.0 )
|| ( dir.y1() == 0.0 && dir.y2() == 1.0 );
}
}
2022-12-06 15:52:55 +00:00
}
2022-12-10 15:08:32 +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
}