-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
230 lines (194 loc) · 9.25 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
// This is an independent project of an individual developer. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++, C#, and Java: http://www.viva64.com
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QLayout>
#include <QSlider>
#include <QLabel>
#include <QCheckBox>
#include <QSplitter>
#include "GLWidget.h"
#include "GlassWall.h"
struct MainWindow::Impl
{
~Impl() { delete ui; }
Ui::MainWindow *ui = new Ui::MainWindow;
GLWidget * wgt_WBOIT = nullptr, * wgt_CODB = nullptr,
* wgt_Additive = nullptr, * wgt_AdditiveEP = nullptr;
QWidget * settingsBoard = nullptr;
QHBoxLayout * settingsBoardLayout = nullptr;
void ArrangeWallSettings();
void UpdateWidgets();
};
void MainWindow::Impl::ArrangeWallSettings()
{
assert(settingsBoard && settingsBoardLayout);
std::vector<QObject *> objs;
for (auto obj : settingsBoard->children()) objs.push_back(obj);
for (auto obj : objs)
if (!obj->metaObject()->inherits(&QLayout::staticMetaObject))
delete obj;
std::vector<QWidget *> settingsWidgets;
settingsWidgets.reserve(GlassWall::CountOfInstances());
auto & iter = GlassWallIterator::Instance();
for (iter.Reset(); !iter.AtEnd(); ++iter)
{
auto wgt = settingsWidgets.emplace_back(new QWidget(settingsBoard));
auto glay = new QGridLayout(wgt); wgt->setLayout(glay);
auto blackWall = new QLabel(wgt);
glay->addWidget(blackWall, 0, 0, 5, 1);
auto pmap = QPixmap(2, 110); pmap.fill(Qt::black);
blackWall->setPixmap(std::move(pmap));
auto lbl = new QLabel( QString(QStringLiteral("Depth level %1"))
.arg(iter->DepthLevel()) , wgt );
glay->addWidget(lbl, 0, 1, Qt::AlignHCenter);
auto vcbx = new QCheckBox(QStringLiteral("Visible"), wgt);
glay->addWidget(vcbx, 1, 1);
vcbx->setChecked(iter->Visible());
connect( vcbx, &QCheckBox::toggled, wgt,
[&wall = *iter, this](bool checked)//clazy:exclude=lambda-in-connect
{ wall.Visible(checked); UpdateWidgets(); } );
auto tcbx = new QCheckBox(QStringLiteral("Transparent"), wgt);
glay->addWidget(tcbx, 2, 1);
tcbx->setChecked(iter->Transparent());
connect( tcbx, &QCheckBox::toggled, wgt,
[&wall = *iter, this](bool checked)//clazy:exclude=lambda-in-connect
{ wall.Transparent(checked); UpdateWidgets(); } );
auto olbl = new QLabel(QStringLiteral("Opacity:"), wgt);
glay->addWidget(olbl, 3, 1);
auto oslider = new QSlider(Qt::Orientation::Horizontal, wgt);
glay->addWidget(oslider, 4, 1);
static constexpr int smax = 1000;
oslider->setRange(0, smax);
oslider->setValue(static_cast<int>(iter->Opacity() * smax));
connect( oslider, &QSlider::valueChanged, wgt,
[&wall = *iter, this](int value)//clazy:exclude=lambda-in-connect
{ wall.Opacity(static_cast<float>(value) / smax); UpdateWidgets(); } );
}
for (auto it = settingsWidgets.rbegin(); it != settingsWidgets.rend(); ++it)
settingsBoardLayout->addWidget(*it);
}
void MainWindow::Impl::UpdateWidgets()
{ wgt_WBOIT->update(); wgt_CODB->update(); wgt_Additive->update(); wgt_AdditiveEP->update(); }
MainWindow::MainWindow(QWidget * parent) :
QMainWindow(parent), impl(std::make_unique<Impl>())
{
impl->ui->setupUi(this);
{
auto hlay = new QHBoxLayout(impl->ui->sbparent);
impl->ui->sbparent->setLayout(hlay);
auto lbl = new QLabel(impl->ui->sbparent);
hlay->addWidget(lbl);
lbl->setPixmap(QPixmap(":/Res/Eye.png"));
impl->settingsBoard = new QWidget(impl->ui->sbparent);
hlay->addWidget(impl->settingsBoard);
impl->settingsBoardLayout = new QHBoxLayout(impl->settingsBoard);
impl->settingsBoard->setLayout(impl->settingsBoardLayout);
}
impl->wgt_WBOIT = new GLWidget(GLWidget::RenderStrategyEnum::WBOIT, this);
impl->ui->gridLayout_top->addWidget(impl->wgt_WBOIT, 1, 0);
impl->wgt_CODB = new GLWidget(GLWidget::RenderStrategyEnum::CODB , this);
impl->ui->gridLayout_top->addWidget(impl->wgt_CODB, 1, 1);
impl->ui->gridLayout_top->setRowStretch(1, 1);
impl->wgt_Additive = new GLWidget(GLWidget::RenderStrategyEnum::Additive, this);
impl->ui->gridLayout_bottom->addWidget(impl->wgt_Additive, 1, 0);
impl->wgt_AdditiveEP = new GLWidget(GLWidget::RenderStrategyEnum::AdditiveEP, this);
impl->ui->gridLayout_bottom->addWidget(impl->wgt_AdditiveEP, 1, 1);
impl->ui->gridLayout_bottom->setRowStretch(1, 1);
static constexpr int max = 1000;
impl->ui->slider->setRange(0, max);
impl->ui->slider->setValue(0);
connect( impl->ui->slider, &QSlider::valueChanged, this,
[this, max = max](int val)
{ this->UpdateWalls(static_cast<float>(val) / max); }
);
}
MainWindow::~MainWindow() = default;
QVector2D Mult(QVector2D vec, QMatrix2x2 mat)
{
return { mat(0, 0) * vec.x() + mat(0, 1) * vec.y(),
mat(1, 0) * vec.x() + mat(1, 1) * vec.y() };
}
void MainWindow::InitWalls() const
{
{
static constexpr QVector2D a{-0.1f, -0.6f}, b{0.1f, -0.6f}, c{0.0f, -0.9f};
static constexpr QVector2D d{-0.1f, -0.9f}, e{0.1f, -0.9f}, f{0.0f, -0.6f};
QColor clrs [] = { QColor(255, 0, 0), QColor(255, 130, 0), QColor(255, 220, 0),
QColor(0, 255, 0), QColor(0, 200, 255), QColor(0, 50, 255),
QColor(120, 0, 255), QColor(220, 0, 200) };
static constexpr uint8_t count = 8;
static const float angleStep = 2 * g_pi_f / count;
static const float rotdata [] = { std::cos(angleStep), std::sin(angleStep),
-std::sin(angleStep), std::cos(angleStep) };
static const QMatrix2x2 rot(rotdata);
QMatrix2x2 rot_t{};
auto & wall1 = GlassWall::MakeInstance(0, 0.5f, true, true);
auto & wall2 = GlassWall::MakeInstance(1, 0.5f, true, true);
for (auto i = 0; i < count; (++i), (rot_t = rot * rot_t))
{
wall1.AddTriangle( Mult(a, rot_t), Mult(b, rot_t), Mult(c, rot_t),
Qt::white, clrs[i] );
wall2.AddTriangle( Mult(d, rot_t), Mult(e, rot_t), Mult(f, rot_t),
Qt::white, clrs[i] );
}
}
{
static constexpr QVector2D a{-0.9f, -0.04f}, b{-0.9f, 0.04f}, c{0.0f, 0.0f};
QColor clrs [] = { QColor(10, 100, 35), QColor(10, 30, 100), QColor(110, 30, 0),
QColor(10, 35, 100), QColor(100, 5, 40), QColor(0, 70, 70),
QColor(30, 100, 15), QColor(100, 0, 0) };
static constexpr uint8_t count = 8;
static const float angleStep = 2 * g_pi_f / count;
static const float rotdata [] = { std::cos(angleStep), std::sin(angleStep),
-std::sin(angleStep), std::cos(angleStep) };
static const QMatrix2x2 rot(rotdata);
QMatrix2x2 rot_t{};
auto & wall1 = GlassWall::MakeInstance(2, 0.5f, true, true);
for (auto i = 0; i < count; (++i), (rot_t = rot * rot_t))
{
wall1.AddTriangle( Mult(a, rot_t), Mult(b, rot_t), Mult(c, rot_t),
Qt::yellow, clrs[i] );
}
}
{
static constexpr QVector2D a{-1.0f, 0.0f}, b{0.0f, 0.0f}, c{0.0f, 1.0f};
QColor clrs [] = { QColor(255, 255, 255), QColor(0, 255, 255),
QColor(127, 127, 127), QColor(35, 35, 100) };
static constexpr uint8_t count = 4;
static const float angleStep = 2 * g_pi_f / count;
static const float rotdata [] = { std::cos(angleStep), std::sin(angleStep),
-std::sin(angleStep), std::cos(angleStep) };
static const QMatrix2x2 rot(rotdata);
QMatrix2x2 rot_t{};
auto & wall1 = GlassWall::MakeInstance(3, 0.5f, true, true);
for (auto i = 0; i < count; (++i), (rot_t = rot * rot_t))
{
wall1.AddTriangle( Mult(a, rot_t), Mult(b, rot_t), Mult(c, rot_t),
clrs[i], clrs[i] );
}
}
impl->ArrangeWallSettings();
}
void MainWindow::UpdateWalls(float p) const
{
float angle = 2 * g_pi_f * p;
auto cos = std::cos(angle ), sin = std::sin(angle );
auto cos2 = std::cos(angle / 2), sin2 = std::sin(angle / 2);
float trData1 [] = { cos , sin , 0,
-sin , cos , 0,
0 , 0 , 1 };
float trData2 [] = { cos , -sin , 0,
sin , cos , 0,
0 , 0 , 1 };
float trData3 [] = { cos2, -sin2, 0,
sin2, cos2, 0,
0 , 0 , 1 };
auto & wall1 = GlassWall::FindInstance(0);
wall1.Transformation(QMatrix3x3(trData1));
auto & wall2 = GlassWall::FindInstance(1);
wall2.Transformation(QMatrix3x3(trData2));
auto & wall3 = GlassWall::FindInstance(2);
wall3.Transformation(QMatrix3x3(trData3));
impl->UpdateWidgets();
}