1 | // Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "viewportnode_p.h" |
5 | #include <Qt3DRender/qviewport.h> |
6 | #include <Qt3DRender/private/qviewport_p.h> |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | using namespace Qt3DCore; |
11 | |
12 | namespace Qt3DRender { |
13 | namespace Render { |
14 | |
15 | ViewportNode::ViewportNode() |
16 | : FrameGraphNode(FrameGraphNode::Viewport) |
17 | , m_xMin(0.0f) |
18 | , m_yMin(0.0f) |
19 | , m_xMax(1.0f) |
20 | , m_yMax(1.0f) |
21 | , m_gamma(2.2f) |
22 | { |
23 | } |
24 | |
25 | |
26 | void ViewportNode::syncFromFrontEnd(const QNode *frontEnd, bool firstTime) |
27 | { |
28 | const QViewport *node = qobject_cast<const QViewport *>(object: frontEnd); |
29 | if (!node) |
30 | return; |
31 | |
32 | FrameGraphNode::syncFromFrontEnd(frontEnd, firstTime); |
33 | |
34 | const QRectF oldRect(m_xMin, m_yMin, m_xMax, m_yMax); |
35 | if (oldRect != node->normalizedRect()) { |
36 | m_xMin = node->normalizedRect().x(); |
37 | m_yMin = node->normalizedRect().y(); |
38 | m_xMax = node->normalizedRect().width(); |
39 | m_yMax = node->normalizedRect().height(); |
40 | markDirty(changes: AbstractRenderer::FrameGraphDirty); |
41 | } |
42 | |
43 | if (node->gamma() != m_gamma) { |
44 | m_gamma = node->gamma(); |
45 | markDirty(changes: AbstractRenderer::FrameGraphDirty); |
46 | } |
47 | } |
48 | |
49 | float ViewportNode::xMin() const |
50 | { |
51 | return m_xMin; |
52 | } |
53 | |
54 | void ViewportNode::setXMin(float xMin) |
55 | { |
56 | m_xMin = xMin; |
57 | } |
58 | float ViewportNode::yMin() const |
59 | { |
60 | return m_yMin; |
61 | } |
62 | |
63 | void ViewportNode::setYMin(float yMin) |
64 | { |
65 | m_yMin = yMin; |
66 | } |
67 | float ViewportNode::xMax() const |
68 | { |
69 | return m_xMax; |
70 | } |
71 | |
72 | void ViewportNode::setXMax(float xMax) |
73 | { |
74 | m_xMax = xMax; |
75 | } |
76 | float ViewportNode::yMax() const |
77 | { |
78 | return m_yMax; |
79 | } |
80 | |
81 | void ViewportNode::setYMax(float yMax) |
82 | { |
83 | m_yMax = yMax; |
84 | } |
85 | |
86 | float ViewportNode::gamma() const |
87 | { |
88 | return m_gamma; |
89 | } |
90 | |
91 | void ViewportNode::setGamma(float gamma) |
92 | { |
93 | m_gamma = gamma; |
94 | } |
95 | |
96 | QRectF ViewportNode::computeViewport(const QRectF &childViewport, const ViewportNode *parentViewport) |
97 | { |
98 | QRectF vp(parentViewport->xMin(), |
99 | parentViewport->yMin(), |
100 | parentViewport->xMax(), |
101 | parentViewport->yMax()); |
102 | |
103 | if (childViewport.isEmpty()) { |
104 | return vp; |
105 | } else { |
106 | return QRectF(vp.x() + vp.width() * childViewport.x(), |
107 | vp.y() + vp.height() * childViewport.y(), |
108 | vp.width() * childViewport.width(), |
109 | vp.height() * childViewport.height()); |
110 | } |
111 | } |
112 | |
113 | } // namespace Render |
114 | } // namespace Qt3DRender |
115 | |
116 | QT_END_NAMESPACE |
117 | |