7#include "shadowedrectanglenode.h"
8#include "shadowedborderrectanglematerial.h"
18ShadowedRectangleNode::ShadowedRectangleNode()
34 if (!m_material || m_material->type() == borderlessMaterialType()) {
35 auto newMaterial = createBorderMaterial();
36 newMaterial->shaderType = m_shaderType;
38 m_material = newMaterial;
43 if (!m_material || m_material->type() == borderMaterialType()) {
44 auto newMaterial = createBorderlessMaterial();
45 newMaterial->shaderType = m_shaderType;
47 m_material = newMaterial;
54void ShadowedRectangleNode::setRect(
const QRectF &rect)
69 if (m_material->aspect != newAspect) {
70 m_material->aspect = newAspect;
76void ShadowedRectangleNode::setSize(qreal size)
78 auto minDimension = std::min(m_rect.
width(), m_rect.
height());
79 float uniformSize = (size / minDimension) * 2.0;
81 if (!qFuzzyCompare(m_material->size, uniformSize)) {
82 m_material->size = uniformSize;
88void ShadowedRectangleNode::setRadius(
const QVector4D &radius)
90 float minDimension = std::min(m_rect.
width(), m_rect.
height());
91 auto uniformRadius =
QVector4D{std::min(radius.
x() * 2.0f / minDimension, 1.0f),
92 std::min(radius.
y() * 2.0f / minDimension, 1.0f),
93 std::min(radius.
z() * 2.0f / minDimension, 1.0f),
94 std::min(radius.
w() * 2.0f / minDimension, 1.0f)};
96 if (m_material->radius != uniformRadius) {
97 m_material->radius = uniformRadius;
103void ShadowedRectangleNode::setColor(
const QColor &color)
105 auto premultiplied = premultiply(color);
106 if (m_material->color != premultiplied) {
107 m_material->color = premultiplied;
112void ShadowedRectangleNode::setShadowColor(
const QColor &color)
114 auto premultiplied = premultiply(color);
115 if (m_material->shadowColor != premultiplied) {
116 m_material->shadowColor = premultiplied;
121void ShadowedRectangleNode::setOffset(
const QVector2D &offset)
123 auto minDimension = std::min(m_rect.
width(), m_rect.
height());
124 auto uniformOffset = offset / minDimension;
126 if (m_material->offset != uniformOffset) {
127 m_material->offset = uniformOffset;
133void ShadowedRectangleNode::setBorderWidth(qreal width)
135 if (m_material->type() != borderMaterialType()) {
139 auto minDimension = std::min(m_rect.
width(), m_rect.
height());
140 float uniformBorderWidth = width / minDimension;
143 if (!qFuzzyCompare(borderMaterial->borderWidth, uniformBorderWidth)) {
144 borderMaterial->borderWidth = uniformBorderWidth;
146 m_borderWidth = width;
150void ShadowedRectangleNode::setBorderColor(
const QColor &color)
152 if (m_material->type() != borderMaterialType()) {
157 auto premultiplied = premultiply(color);
158 if (borderMaterial->borderColor != premultiplied) {
159 borderMaterial->borderColor = premultiplied;
164void ShadowedRectangleNode::setShaderType(ShadowedRectangleMaterial::ShaderType type)
172 if (m_shaderType == ShadowedRectangleMaterial::ShaderType::Standard) {
173 rect = rect.
adjusted(-m_size * m_aspect.
x(),
174 -m_size * m_aspect.
y(),
175 m_size * m_aspect.
x(),
176 m_size * m_aspect.
y());
178 auto offsetLength = m_offset.
length();
179 rect = rect.
adjusted(-offsetLength * m_aspect.
x(),
180 -offsetLength * m_aspect.
y(),
181 offsetLength * m_aspect.
x(),
182 offsetLength * m_aspect.
y());
201 return &ShadowedRectangleMaterial::staticType;
206 return &ShadowedBorderRectangleMaterial::staticType;
A material rendering a rectangle with a shadow and a border.
A material rendering a rectangle with a shadow.
void updateGeometry()
Update the geometry for this node.
void setBorderEnabled(bool enabled)
Set whether to draw a border.
float alphaF() const const
float blueF() const const
QColor fromRgbF(float r, float g, float b, float a)
float greenF() const const
QRectF adjusted(qreal dx1, qreal dy1, qreal dx2, qreal dy2) const const
qreal height() const const
qreal width() const const
void setGeometry(QSGGeometry *geometry)
const AttributeSet & defaultAttributes_TexturedPoint2D()
void updateTexturedRectGeometry(QSGGeometry *g, const QRectF &rect, const QRectF &textureRect)
void setMaterial(QSGMaterial *material)
void markDirty(DirtyState bits)
void setFlags(Flags f, bool enabled)
NodeType type() const const
float length() const const