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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
// Copyright 2018 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "DolphinQt/Config/Graphics/PostProcessingConfigWindow.h"
#include <cmath>
#include <vector>
#include <QCheckBox>
#include <QDialog>
#include <QDialogButtonBox>
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QSlider>
#include <QString>
#include <QTabWidget>
#include <QVBoxLayout>
#include <QWidget>
#include "DolphinQt/Config/Graphics/EnhancementsWidget.h"
#include "VideoCommon/PostProcessing.h"
#include "VideoCommon/Present.h"
using ConfigurationOption = VideoCommon::PostProcessingConfiguration::ConfigurationOption;
using OptionType = ConfigurationOption::OptionType;
PostProcessingConfigWindow::PostProcessingConfigWindow(EnhancementsWidget* parent,
const std::string& shader)
: QDialog(parent), m_shader(shader)
{
if (g_presenter && g_presenter->GetPostProcessor())
{
m_post_processor = g_presenter->GetPostProcessor()->GetConfig();
}
else
{
m_post_processor = new VideoCommon::PostProcessingConfiguration();
m_post_processor->LoadShader(m_shader);
}
setWindowTitle(tr("Post-Processing Shader Configuration"));
PopulateGroups();
Create();
ConnectWidgets();
adjustSize();
}
PostProcessingConfigWindow::~PostProcessingConfigWindow()
{
m_post_processor->SaveOptionsConfiguration();
if (!(g_presenter && g_presenter->GetPostProcessor()))
{
delete m_post_processor;
}
}
void PostProcessingConfigWindow::PopulateGroups()
{
const VideoCommon::PostProcessingConfiguration::ConfigMap& config_map =
m_post_processor->GetOptions();
auto config_groups = std::vector<std::unique_ptr<ConfigGroup>>();
for (const auto& it : config_map)
{
auto config_group = std::make_unique<ConfigGroup>(&it.second);
m_config_map[it.first] = config_group.get();
config_groups.push_back(std::move(config_group));
}
for (auto& config_group : config_groups)
{
const std::string& parent_name = config_group->GetParent();
if (parent_name.empty())
{
m_config_groups.emplace_back(std::move(config_group));
}
else
{
m_config_map[parent_name]->AddSubGroup(std::move(config_group));
}
}
}
void PostProcessingConfigWindow::Create()
{
m_tabs = new QTabWidget();
auto* const general = new QWidget(m_tabs);
auto* const general_layout = new QGridLayout(general);
u32 row = 0;
bool add_general_page = false;
for (auto& it : m_config_groups)
{
if (it->HasSubGroups())
{
auto* const tab = CreateDependentTab(it);
m_tabs->addTab(tab, QString::fromStdString(it->GetGUIName()));
if (it->GetConfigurationOption()->m_type == OptionType::Bool)
{
it->EnableSuboptions(it->GetCheckboxValue());
}
}
else
{
if (!add_general_page)
{
add_general_page = true;
}
row = it->AddWidgets(this, general_layout, row);
}
}
if (add_general_page)
{
m_tabs->insertTab(0, general, tr("General"));
}
m_buttons = new QDialogButtonBox(QDialogButtonBox::Ok);
auto* layout = new QVBoxLayout(this);
layout->addWidget(m_tabs);
layout->addWidget(m_buttons);
}
void PostProcessingConfigWindow::ConnectWidgets()
{
connect(m_buttons, &QDialogButtonBox::accepted, this, &PostProcessingConfigWindow::accept);
}
QWidget*
PostProcessingConfigWindow::CreateDependentTab(const std::unique_ptr<ConfigGroup>& config_group)
{
auto* const tab = new QWidget(m_tabs);
auto* const layout = new QGridLayout(tab);
u32 row = config_group->AddWidgets(this, layout, 0);
for (const auto& child : config_group->GetSubGroups())
{
row = child->AddWidgets(this, layout, row);
}
return tab;
}
void PostProcessingConfigWindow::UpdateBool(ConfigGroup* const config_group, const bool state)
{
m_post_processor->SetOptionb(config_group->GetOptionName(), state);
config_group->EnableSuboptions(state);
}
void PostProcessingConfigWindow::UpdateInteger(ConfigGroup* const config_group, const int value)
{
const ConfigurationOption& config_option =
m_post_processor->GetOption(config_group->GetOptionName());
const size_t vector_size = config_option.m_integer_values.size();
for (size_t i = 0; i < vector_size; ++i)
{
const int current_step = config_group->GetSliderValue(i);
const s32 current_value = config_option.m_integer_step_values[i] * current_step +
config_option.m_integer_min_values[i];
m_post_processor->SetOptioni(config_option.m_option_name, static_cast<int>(i), current_value);
config_group->SetSliderText(i, QString::number(current_value));
}
}
void PostProcessingConfigWindow::UpdateFloat(ConfigGroup* const config_group, const int value)
{
const ConfigurationOption& config_option =
m_post_processor->GetOption(config_group->GetOptionName());
const size_t vector_size = config_option.m_float_values.size();
for (size_t i = 0; i < vector_size; ++i)
{
const int current_step = config_group->GetSliderValue(static_cast<unsigned int>(i));
const float current_value =
config_option.m_float_step_values[i] * current_step + config_option.m_float_min_values[i];
m_post_processor->SetOptionf(config_option.m_option_name, static_cast<int>(i), current_value);
config_group->SetSliderText(i, QString::asprintf("%f", current_value));
}
}
PostProcessingConfigWindow::ConfigGroup::ConfigGroup(const ConfigurationOption* config_option)
: m_config_option(config_option)
{
}
const std::string& PostProcessingConfigWindow::ConfigGroup::GetGUIName() const noexcept
{
return m_config_option->m_gui_name;
}
const std::string& PostProcessingConfigWindow::ConfigGroup::GetParent() const noexcept
{
return m_config_option->m_dependent_option;
}
const std::string& PostProcessingConfigWindow::ConfigGroup::GetOptionName() const noexcept
{
return m_config_option->m_option_name;
}
void PostProcessingConfigWindow::ConfigGroup::AddSubGroup(std::unique_ptr<ConfigGroup>&& subgroup)
{
m_subgroups.emplace_back(std::move(subgroup));
}
bool PostProcessingConfigWindow::ConfigGroup::HasSubGroups() const noexcept
{
return !m_subgroups.empty();
}
const ConfigurationOption*
PostProcessingConfigWindow::ConfigGroup::GetConfigurationOption() const noexcept
{
return m_config_option;
}
const std::vector<std::unique_ptr<PostProcessingConfigWindow::ConfigGroup>>&
PostProcessingConfigWindow::ConfigGroup::GetSubGroups() const noexcept
{
return m_subgroups;
}
u32 PostProcessingConfigWindow::ConfigGroup::AddWidgets(PostProcessingConfigWindow* const parent,
QGridLayout* const grid, const u32 row)
{
auto* const name = new QLabel(QString::fromStdString(m_config_option->m_gui_name));
grid->addWidget(name, row, 0);
switch (m_config_option->m_type)
{
case OptionType::Bool:
return AddBool(parent, grid, row);
case OptionType::Float:
return AddFloat(parent, grid, row);
case OptionType::Integer:
return AddInteger(parent, grid, row);
default:
// obviously shouldn't get here
std::abort();
}
}
u32 PostProcessingConfigWindow::ConfigGroup::AddBool(PostProcessingConfigWindow* const parent,
QGridLayout* const grid, const u32 row)
{
m_checkbox = new QCheckBox();
m_checkbox->setChecked(m_config_option->m_bool_value);
QObject::connect(m_checkbox, &QCheckBox::toggled,
[this, parent](bool checked) { parent->UpdateBool(this, checked); });
grid->addWidget(m_checkbox, row, 2);
return row + 1;
}
u32 PostProcessingConfigWindow::ConfigGroup::AddInteger(PostProcessingConfigWindow* const parent,
QGridLayout* const grid, u32 row)
{
const size_t vector_size = m_config_option->m_integer_values.size();
for (size_t i = 0; i < vector_size; ++i)
{
const double range =
m_config_option->m_integer_max_values[i] - m_config_option->m_integer_min_values[i];
// "How many steps we have is the range divided by the step interval configured.
// This may not be 100% spot on accurate since developers can have odd stepping intervals
// set.
// Round up so if it is outside our range, then set it to the minimum or maximum"
const int steps =
std::ceil(range / static_cast<double>(m_config_option->m_integer_step_values[i]));
const int current_value = std::round(
(m_config_option->m_integer_values[i] - m_config_option->m_integer_min_values[i]) /
static_cast<double>(m_config_option->m_integer_step_values[i]));
auto* const slider = new QSlider(Qt::Orientation::Horizontal);
slider->setMinimum(0);
slider->setMaximum(steps);
slider->setValue(current_value);
slider->setTickInterval(range / steps);
QObject::connect(slider, &QSlider::valueChanged,
[this, parent](int value) { parent->UpdateInteger(this, value); });
auto* const value_box = new QLineEdit(QString::number(m_config_option->m_integer_values[i]));
value_box->setEnabled(false);
grid->addWidget(slider, row, 1);
grid->addWidget(value_box, row, 2);
m_sliders.push_back(slider);
m_value_boxes.push_back(value_box);
if (vector_size > 1)
{
row++;
}
}
return row + 1;
}
u32 PostProcessingConfigWindow::ConfigGroup::AddFloat(PostProcessingConfigWindow* const parent,
QGridLayout* const grid, u32 row)
{
const size_t vector_size = m_config_option->m_float_values.size();
for (size_t i = 0; i < vector_size; ++i)
{
const float range =
m_config_option->m_float_max_values[i] - m_config_option->m_float_min_values[i];
const int steps = std::ceil(range / m_config_option->m_float_step_values[i]);
const int current_value =
std::round((m_config_option->m_float_values[i] - m_config_option->m_float_min_values[i]) /
m_config_option->m_float_step_values[i]);
auto* const slider = new QSlider(Qt::Orientation::Horizontal);
slider->setMinimum(0);
slider->setMaximum(steps);
slider->setValue(current_value);
slider->setTickInterval(range / steps);
QObject::connect(slider, &QSlider::valueChanged,
[this, parent](int value) { parent->UpdateFloat(this, value); });
auto* const value_box =
new QLineEdit(QString::asprintf("%f", m_config_option->m_float_values[i]));
value_box->setEnabled(false);
grid->addWidget(slider, row, 1);
grid->addWidget(value_box, row, 2);
m_sliders.push_back(slider);
m_value_boxes.push_back(value_box);
if (vector_size > 1)
{
row++;
}
}
return row + 1;
}
void PostProcessingConfigWindow::ConfigGroup::EnableSuboptions(const bool state)
{
for (auto& it : m_subgroups)
{
if (it->m_config_option->m_type == OptionType::Bool)
{
it->m_checkbox->setEnabled(state);
}
else
{
for (auto& slider : it->m_sliders)
{
slider->setEnabled(state);
}
}
it->EnableSuboptions(state);
}
}
int PostProcessingConfigWindow::ConfigGroup::GetCheckboxValue() const
{
return m_checkbox->isChecked();
}
int PostProcessingConfigWindow::ConfigGroup::GetSliderValue(size_t index) const
{
return m_sliders[index]->value();
}
void PostProcessingConfigWindow::ConfigGroup::SetSliderText(size_t index, const QString& text)
{
m_value_boxes[index]->setText(text);
}
|