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