1 | /* |
---|---|
2 | * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl> |
3 | * |
4 | * SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #include "shadowedtexture.h" |
8 | |
9 | #include <QQuickWindow> |
10 | #include <QSGRectangleNode> |
11 | #include <QSGRendererInterface> |
12 | |
13 | #include "scenegraph/shadowedtexturenode.h" |
14 | |
15 | ShadowedTexture::ShadowedTexture(QQuickItem *parentItem) |
16 | : ShadowedRectangle(parentItem) |
17 | { |
18 | } |
19 | |
20 | ShadowedTexture::~ShadowedTexture() |
21 | { |
22 | } |
23 | |
24 | QQuickItem *ShadowedTexture::source() const |
25 | { |
26 | return m_source; |
27 | } |
28 | |
29 | void ShadowedTexture::setSource(QQuickItem *newSource) |
30 | { |
31 | if (newSource == m_source) { |
32 | return; |
33 | } |
34 | |
35 | m_source = newSource; |
36 | m_sourceChanged = true; |
37 | if (m_source && !m_source->parentItem()) { |
38 | m_source->setParentItem(this); |
39 | } |
40 | |
41 | if (!isSoftwareRendering()) { |
42 | update(); |
43 | } |
44 | Q_EMIT sourceChanged(); |
45 | } |
46 | |
47 | QSGNode *ShadowedTexture::updatePaintNode(QSGNode *node, QQuickItem::UpdatePaintNodeData *data) |
48 | { |
49 | Q_UNUSED(data) |
50 | |
51 | if (boundingRect().isEmpty()) { |
52 | delete node; |
53 | return nullptr; |
54 | } |
55 | |
56 | auto shadowNode = static_cast<ShadowedRectangleNode *>(node); |
57 | |
58 | if (!shadowNode || m_sourceChanged) { |
59 | m_sourceChanged = false; |
60 | delete shadowNode; |
61 | if (m_source) { |
62 | shadowNode = new ShadowedTextureNode{}; |
63 | } else { |
64 | shadowNode = new ShadowedRectangleNode{}; |
65 | } |
66 | |
67 | if (qEnvironmentVariableIsSet(varName: "KIRIGAMI_LOWPOWER_HARDWARE")) { |
68 | shadowNode->setShaderType(ShadowedRectangleMaterial::ShaderType::LowPower); |
69 | } |
70 | } |
71 | |
72 | shadowNode->setBorderEnabled(border()->isEnabled()); |
73 | shadowNode->setRect(boundingRect()); |
74 | shadowNode->setSize(shadow()->size()); |
75 | shadowNode->setRadius(corners()->toVector4D(all: radius())); |
76 | shadowNode->setOffset(QVector2D{float(shadow()->xOffset()), float(shadow()->yOffset())}); |
77 | shadowNode->setColor(color()); |
78 | shadowNode->setShadowColor(shadow()->color()); |
79 | shadowNode->setBorderWidth(border()->width()); |
80 | shadowNode->setBorderColor(border()->color()); |
81 | |
82 | if (m_source) { |
83 | static_cast<ShadowedTextureNode *>(shadowNode)->setTextureSource(m_source->textureProvider()); |
84 | } |
85 | |
86 | shadowNode->updateGeometry(); |
87 | return shadowNode; |
88 | } |
89 | |
90 | #include "moc_shadowedtexture.cpp" |
91 |