-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainWindow.WorkingSpace.cpp
More file actions
188 lines (161 loc) · 7 KB
/
MainWindow.WorkingSpace.cpp
File metadata and controls
188 lines (161 loc) · 7 KB
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
// MainWindow partial (Phase 4 split): display-profile selection and the
// per-frame Working Space node sync. All methods are members of
// `winrt::ShaderLab::implementation::MainWindow` and share state via
// MainWindow.xaml.h. Extracted from MainWindow.xaml.cpp lines 1102-1370
// at commit c177770 (Phase 3 + earlier health phases).
#include "pch.h"
#include "MainWindow.xaml.h"
#include "Rendering/IccProfileParser.h"
#include "Rendering/WorkingSpaceSync.h"
namespace winrt::ShaderLab::implementation
{
// -----------------------------------------------------------------------
// Display profile selection
// -----------------------------------------------------------------------
void MainWindow::PopulateDisplayProfileSelector()
{
m_suppressProfileEvent = true;
auto selector = DisplayProfileSelector();
selector.Items().Clear();
// "Current Monitor" item.
auto currentItem = winrt::Microsoft::UI::Xaml::Controls::ComboBoxItem();
currentItem.Content(winrt::box_value(L"Current Monitor"));
currentItem.Tag(winrt::box_value(L"current"));
selector.Items().Append(currentItem);
// Preset items.
m_displayPresets = ::ShaderLab::Rendering::AllPresets();
for (size_t i = 0; i < m_displayPresets.size(); ++i)
{
auto item = winrt::Microsoft::UI::Xaml::Controls::ComboBoxItem();
item.Content(winrt::box_value(winrt::hstring(m_displayPresets[i].profileName)));
item.Tag(winrt::box_value(L"preset:" + std::to_wstring(i)));
selector.Items().Append(item);
}
// "Load ICC Profile..." action item.
auto loadItem = winrt::Microsoft::UI::Xaml::Controls::ComboBoxItem();
loadItem.Content(winrt::box_value(L"Load ICC Profile\u2026"));
loadItem.Tag(winrt::box_value(L"load"));
selector.Items().Append(loadItem);
selector.SelectedIndex(0);
m_committedProfileIndex = 0;
m_suppressProfileEvent = false;
}
void MainWindow::ApplyDisplayProfile(const ::ShaderLab::Rendering::DisplayProfile& profile)
{
m_displayMonitor.SetSimulatedProfile(profile);
m_graph.MarkAllDirty();
m_forceRender = true;
UpdateWorkingSpaceNodes();
UpdateStatusBar();
}
void MainWindow::RevertToLiveDisplay()
{
m_displayMonitor.ClearSimulatedProfile();
m_graph.MarkAllDirty();
m_forceRender = true;
UpdateWorkingSpaceNodes();
UpdateStatusBar();
}
void MainWindow::UpdateWorkingSpaceNodes()
{
// Engine-side helper does the actual work; we just propagate the
// m_forceRender side effect when something changed so the render
// tick picks up the dirty Working Space nodes next frame.
if (::ShaderLab::Rendering::UpdateWorkingSpaceNodes(m_graph, m_displayMonitor))
m_forceRender = true;
}
void MainWindow::OnDisplayProfileSelectionChanged(
winrt::Windows::Foundation::IInspectable const& /*sender*/,
winrt::Microsoft::UI::Xaml::Controls::SelectionChangedEventArgs const& /*args*/)
{
if (m_suppressProfileEvent) return;
auto selector = DisplayProfileSelector();
auto selected = selector.SelectedItem();
if (!selected) return;
auto item = selected.as<winrt::Microsoft::UI::Xaml::Controls::ComboBoxItem>();
auto tag = winrt::unbox_value<winrt::hstring>(item.Tag());
if (tag == L"current")
{
RevertToLiveDisplay();
m_committedProfileIndex = selector.SelectedIndex();
}
else if (tag.size() > 7 && tag.c_str()[0] == L'p') // "preset:N"
{
auto indexStr = std::wstring(tag.c_str() + 7);
size_t presetIdx = static_cast<size_t>(std::stoul(indexStr));
if (presetIdx < m_displayPresets.size())
{
ApplyDisplayProfile(m_displayPresets[presetIdx]);
m_committedProfileIndex = selector.SelectedIndex();
}
}
else if (tag == L"icc")
{
if (m_loadedIccProfile.has_value())
{
ApplyDisplayProfile(m_loadedIccProfile.value());
m_committedProfileIndex = selector.SelectedIndex();
}
}
else if (tag == L"load")
{
LoadIccProfileAsync();
}
}
winrt::fire_and_forget MainWindow::LoadIccProfileAsync()
{
auto strong = get_strong();
winrt::Windows::Storage::Pickers::FileOpenPicker picker;
picker.as<::IInitializeWithWindow>()->Initialize(m_hwnd);
picker.SuggestedStartLocation(winrt::Windows::Storage::Pickers::PickerLocationId::DocumentsLibrary);
picker.FileTypeFilter().Append(L".icc");
picker.FileTypeFilter().Append(L".icm");
auto file = co_await picker.PickSingleFileAsync();
if (!file)
{
// User cancelled — revert to the previously committed selection.
m_suppressProfileEvent = true;
DisplayProfileSelector().SelectedIndex(m_committedProfileIndex);
m_suppressProfileEvent = false;
co_return;
}
auto path = std::wstring(file.Path().c_str());
auto parsed = ::ShaderLab::Rendering::IccProfileParser::LoadFromFile(path);
if (!parsed.has_value() || !parsed->valid)
{
// Parse failed — revert selection and show error in status bar.
m_suppressProfileEvent = true;
DisplayProfileSelector().SelectedIndex(m_committedProfileIndex);
m_suppressProfileEvent = false;
PipelineFormatText().Text(L"ICC Error: Failed to parse profile");
co_return;
}
auto profile = ::ShaderLab::Rendering::DisplayProfileFromIcc(parsed.value());
m_loadedIccProfile = profile;
// Insert or update the ICC item (just before the "Load ICC..." sentinel).
m_suppressProfileEvent = true;
auto selector = DisplayProfileSelector();
uint32_t loadIdx = selector.Items().Size() - 1;
// Remove any previous ICC item.
if (loadIdx > 0)
{
auto prevItem = selector.Items().GetAt(loadIdx - 1).as<winrt::Microsoft::UI::Xaml::Controls::ComboBoxItem>();
auto prevTag = winrt::unbox_value<winrt::hstring>(prevItem.Tag());
if (prevTag == L"icc")
{
selector.Items().RemoveAt(loadIdx - 1);
loadIdx--;
}
}
// Insert the new ICC item before the "Load..." sentinel.
auto iccItem = winrt::Microsoft::UI::Xaml::Controls::ComboBoxItem();
iccItem.Content(winrt::box_value(winrt::hstring(profile.profileName)));
iccItem.Tag(winrt::box_value(L"icc"));
selector.Items().InsertAt(loadIdx, iccItem);
// Select the newly inserted item.
selector.SelectedIndex(loadIdx);
m_committedProfileIndex = static_cast<int32_t>(loadIdx);
m_suppressProfileEvent = false;
ApplyDisplayProfile(profile);
}
}