-
Notifications
You must be signed in to change notification settings - Fork 141
/
Copy pathpresentation.cpp
689 lines (613 loc) · 23.1 KB
/
presentation.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
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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
#include "../desktop-ui.hpp"
namespace Instances { Instance<Presentation> presentation; }
Presentation& presentation = Instances::presentation();
#define ELLIPSIS "\u2026"
Presentation::Presentation() {
loadMenu.setText("Load");
systemMenu.setVisible(false);
settingsMenu.setText("Settings");
videoSizeMenu.setText("Size").setIcon(Icon::Emblem::Image);
//generate size menu
u32 multipliers = 5;
for(u32 multiplier : range(1, multipliers + 1)) {
MenuRadioItem item{&videoSizeMenu};
item.setText({multiplier, "x"});
item.onActivate([=] {
settings.video.multiplier = multiplier;
resizeWindow();
});
videoSizeGroup.append(item);
}
for(auto& item : videoSizeGroup.objects<MenuRadioItem>()) {
if(item.text() == string{settings.video.multiplier, "x"}) item.setChecked();
}
videoSizeMenu.append(MenuSeparator());
MenuItem centerWindow{&videoSizeMenu};
centerWindow.setText("Center Window").setIcon(Icon::Place::Settings).onActivate([&] {
setAlignment(Alignment::Center);
});
videoOutputMenu.setText("Output").setIcon(Icon::Emblem::Image);
videoOutputPixelPerfect.setText("Pixel Perfect").onActivate([&] {
settings.video.output = "Perfect";
});
videoOutputFixedScale.setText("Scale (Fixed)").onActivate([&] {
settings.video.output = "Fixed";
});
videoOutputIntegerScale.setText("Scale (Integer)").onActivate([&] {
settings.video.output = "Integer";
});
videoOutputScale.setText("Scale (Best Fit)").onActivate([&] {
settings.video.output = "Scale";
});
videoOutputStretch.setText("Stretch").onActivate([&] {
settings.video.output = "Stretch";
});
if(settings.video.output == "Perfect" ) videoOutputPixelPerfect.setChecked();
if(settings.video.output == "Fixed" ) videoOutputFixedScale.setChecked();
if(settings.video.output == "Integer" ) videoOutputIntegerScale.setChecked();
if(settings.video.output == "Scale" ) videoOutputScale.setChecked();
if(settings.video.output == "Stretch" ) videoOutputStretch.setChecked();
videoAspectCorrection.setText("Aspect Correction").setChecked(settings.video.aspectCorrection).onToggle([&] {
settings.video.aspectCorrection = videoAspectCorrection.checked();
if(settings.video.adaptiveSizing) resizeWindow();
});
videoAdaptiveSizing.setText("Adaptive Sizing").setChecked(settings.video.adaptiveSizing).onToggle([&] {
if(settings.video.adaptiveSizing = videoAdaptiveSizing.checked()) resizeWindow();
});
videoAutoCentering.setText("Auto Centering").setChecked(settings.video.autoCentering).onToggle([&] {
if(settings.video.autoCentering = videoAutoCentering.checked()) resizeWindow();
});
videoShaderMenu.setText("Shader").setIcon(Icon::Emblem::Image);
loadShaders();
bootOptionsMenu.setText("Boot Options").setIcon(Icon::Place::Settings);
fastBoot.setText("Fast Boot").setChecked(settings.boot.fast).onToggle([&] {
settings.boot.fast = fastBoot.checked();
});
launchDebugger.setText("Launch Debugger").setChecked(settings.boot.debugger).onToggle([&] {
settings.boot.debugger = launchDebugger.checked();
});
preferNTSCU.setText("Prefer US").onActivate([&] {
settings.boot.prefer = "NTSC-U";
});
preferNTSCJ.setText("Prefer Japan").onActivate([&] {
settings.boot.prefer = "NTSC-J";
});
preferPAL.setText("Prefer Europe").onActivate([&] {
settings.boot.prefer = "PAL";
});
if(settings.boot.prefer == "NTSC-U") preferNTSCU.setChecked();
if(settings.boot.prefer == "NTSC-J") preferNTSCJ.setChecked();
if(settings.boot.prefer == "PAL") preferPAL.setChecked();
muteAudioSetting.setText("Mute Audio").setChecked(settings.audio.mute).onToggle([&] {
settings.audio.mute = muteAudioSetting.checked();
});
showStatusBarSetting.setText("Show Status Bar").setChecked(settings.general.showStatusBar).onToggle([&] {
settings.general.showStatusBar = showStatusBarSetting.checked();
if(!showStatusBarSetting.checked()) {
layout.remove(statusLayout);
} else {
layout.append(statusLayout, Size{~0, StatusHeight});
}
if(visible()) resizeWindow();
}).doToggle();
videoSettingsAction.setText("Video" ELLIPSIS).setIcon(Icon::Device::Display).onActivate([&] {
settingsWindow.show("Video");
});
audioSettingsAction.setText("Audio" ELLIPSIS).setIcon(Icon::Device::Speaker).onActivate([&] {
settingsWindow.show("Audio");
});
inputSettingsAction.setText("Input" ELLIPSIS).setIcon(Icon::Device::Joypad).onActivate([&] {
settingsWindow.show("Input");
});
hotkeySettingsAction.setText("Hotkeys" ELLIPSIS).setIcon(Icon::Device::Keyboard).onActivate([&] {
settingsWindow.show("Hotkeys");
});
emulatorSettingsAction.setText("Emulators" ELLIPSIS).setIcon(Icon::Place::Server).onActivate([&] {
settingsWindow.show("Emulators");
});
optionSettingsAction.setText("Options" ELLIPSIS).setIcon(Icon::Action::Settings).onActivate([&] {
settingsWindow.show("Options");
});
firmwareSettingsAction.setText("Firmware" ELLIPSIS).setIcon(Icon::Emblem::Binary).onActivate([&] {
settingsWindow.show("Firmware");
});
pathSettingsAction.setText("Paths" ELLIPSIS).setIcon(Icon::Emblem::Folder).onActivate([&] {
settingsWindow.show("Paths");
});
driverSettingsAction.setText("Drivers" ELLIPSIS).setIcon(Icon::Place::Settings).onActivate([&] {
settingsWindow.show("Drivers");
});
debugSettingsAction.setText("Debug" ELLIPSIS).setIcon(Icon::Device::Network).onActivate([&] {
settingsWindow.show("Debug");
});
toolsMenu.setVisible(false).setText("Tools");
saveStateMenu.setText("Save State").setIcon(Icon::Media::Record);
for(u32 slot : range(9)) {
MenuItem item{&saveStateMenu};
item.setText({"Slot ", 1 + slot}).onActivate([=] {
if(program.stateSave(1 + slot)) {
undoSaveStateMenu.setEnabled(true);
}
});
}
loadStateMenu.setText("Load State").setIcon(Icon::Media::Rewind);
for(u32 slot : range(9)) {
MenuItem item{&loadStateMenu};
item.setText({"Slot ", 1 + slot}).onActivate([=] {
if(program.stateLoad(1 + slot)) {
undoLoadStateMenu.setEnabled(true);
}
});
}
undoSaveStateMenu.setText("Undo Last Save State").setIcon(Icon::Edit::Undo).setEnabled(false);
undoSaveStateMenu.onActivate([&] {
program.undoStateSave();
undoSaveStateMenu.setEnabled(false);
});
undoLoadStateMenu.setText("Undo Last Load State").setIcon(Icon::Edit::Undo).setEnabled(false);
undoLoadStateMenu.onActivate([&] {
program.undoStateLoad();
undoLoadStateMenu.setEnabled(false);
});
captureScreenshot.setText("Capture Screenshot").setIcon(Icon::Emblem::Image).onActivate([&] {
program.requestScreenshot = true;
});
pauseEmulation.setText("Pause Emulation").onToggle([&] {
program.pause(!program.paused);
});
reloadGame.setText("Reload Game").setIcon(Icon::Action::Refresh).onActivate([&] {
program.load(emulator, emulator->game->location);
});
frameAdvance.setText("Frame Advance").setIcon(Icon::Media::Play).onActivate([&] {
if (!program.paused) program.pause(true);
program.requestFrameAdvance = true;
});
manifestViewerAction.setText("Manifest").setIcon(Icon::Emblem::Binary).onActivate([&] {
toolsWindow.show("Manifest");
});
cheatEditorAction.setText("Cheats").setIcon(Icon::Emblem::File).onActivate([&] {
toolsWindow.show("Cheats");
});
#if !defined(PLATFORM_MACOS)
// Cocoa hiro is missing the hex editor widget
memoryEditorAction.setText("Memory").setIcon(Icon::Device::Storage).onActivate([&] {
toolsWindow.show("Memory");
});
#endif
graphicsViewerAction.setText("Graphics").setIcon(Icon::Emblem::Image).onActivate([&] {
toolsWindow.show("Graphics");
});
streamManagerAction.setText("Streams").setIcon(Icon::Emblem::Audio).onActivate([&] {
toolsWindow.show("Streams");
});
propertiesViewerAction.setText("Properties").setIcon(Icon::Emblem::Text).onActivate([&] {
toolsWindow.show("Properties");
});
traceLoggerAction.setText("Tracer").setIcon(Icon::Emblem::Script).onActivate([&] {
toolsWindow.show("Tracer");
});
helpMenu.setText("Help");
aboutAction.setText("About" ELLIPSIS).setIcon(Icon::Prompt::Question).onActivate([&] {
multiFactorImage logo(Resource::Ares::Logo1x, Resource::Ares::Logo2x);
AboutDialog()
.setName(ares::Name)
.setLogo(logo)
.setDescription({ares::Name, " — a simplified multi-system emulator"})
.setVersion(ares::Version)
.setCopyright(ares::Copyright)
.setLicense(ares::License, ares::LicenseURI)
.setWebsite(ares::Website, ares::WebsiteURI)
.setAlignment(presentation)
.show();
});
viewport.setDroppable().onDrop([&](auto filenames) {
if(filenames.size() != 1) return;
if(auto emulator = program.identify(filenames.first())) {
program.load(emulator, filenames.first());
}
});
Application::onOpenFile([&](auto filename) {
if(auto emulator = program.identify(filename)) {
program.load(emulator, filename);
}
});
iconLayout.setCollapsible();
iconSpacer.setCollapsible().setColor({0, 0, 0}).setDroppable().onDrop([&](auto filenames) {
viewport.doDrop(filenames);
});
multiFactorImage icon(Resource::Ares::Icon1x, Resource::Ares::Icon2x);
icon.alphaBlend(0x000000);
iconCanvas.setCollapsible().setIcon(icon).setDroppable().onDrop([&](auto filenames) {
viewport.doDrop(filenames);
});
iconPadding.setCollapsible().setColor({0, 0, 0}).setDroppable().onDrop([&](auto filenames) {
viewport.doDrop(filenames);
});
iconBottom.setCollapsible().setColor({0, 0, 0}).setDroppable().onDrop([&](auto filenames) {
viewport.doDrop(filenames);
});
spacerLeft .setBackgroundColor({32, 32, 32});
statusLeft .setBackgroundColor({32, 32, 32}).setForegroundColor({255, 255, 255});
statusDebug.setBackgroundColor({32, 32, 32}).setForegroundColor({255, 255, 255});
statusRight.setBackgroundColor({32, 32, 32}).setForegroundColor({255, 255, 255});
spacerRight.setBackgroundColor({32, 32, 32});
statusLeft .setAlignment(0.0).setFont(Font().setBold());
statusDebug.setAlignment(1.0).setFont(Font().setBold());
statusRight.setAlignment(1.0).setFont(Font().setBold());
onClose([&] {
program.quit();
});
loadEmulators();
resizeWindow();
setTitle({ares::Name, " v", ares::Version});
setAssociatedFile();
setBackgroundColor({0, 0, 0});
setAlignment(Alignment::Center);
setVisible();
#if defined(PLATFORM_MACOS)
Application::Cocoa::onAbout([&] { aboutAction.doActivate(); });
Application::Cocoa::onActivate([&] { setFocused(); });
Application::Cocoa::onPreferences([&] { settingsWindow.show("Video"); });
Application::Cocoa::onQuit([&] { doClose(); });
#endif
}
auto Presentation::resizeWindow() -> void {
if(fullScreen()) setFullScreen(false);
if(maximized()) return;
if(settings.video.output == "Fixed") return;
u32 multiplier = settings.video.multiplier;
u32 viewportWidth = 320 * multiplier;
u32 viewportHeight = 240 * multiplier;
if(emulator && program.screens) {
auto& node = program.screens.first();
u32 videoWidth = node->width() * node->scaleX();
u32 videoHeight = node->height() * node->scaleY();
if(settings.video.aspectCorrection) videoWidth = videoWidth * node->aspectX() / node->aspectY();
if(node->rotation() == 90 || node->rotation() == 270) swap(videoWidth, videoHeight);
viewportWidth = videoWidth * multiplier;
viewportHeight = videoHeight * multiplier;
}
u32 statusHeight = showStatusBarSetting.checked() ? StatusHeight : 0;
// Prevent the window frame from going out of bounds
u32 monitorHeight = 1;
u32 monitorWidth = 1;
for(u32 monitor : range(Monitor::count())) {
monitorHeight = max(monitorHeight, Monitor::workspace(monitor).height());
}
for(u32 monitor : range(Monitor::count())) {
monitorWidth = max(monitorWidth, Monitor::workspace(monitor).width());
}
if(viewportWidth > monitorWidth || viewportHeight > monitorHeight) {
// setMaximized causes odd window glitches and is not supported on macOS, avoid!
// 100px buffer to account for possible taskbars
setGeometry(Alignment::Center, {monitorWidth, monitorHeight - statusHeight - 100});
return;
}
if(settings.video.autoCentering) {
setGeometry(Alignment::Center, {viewportWidth, viewportHeight + statusHeight});
} else {
setSize({viewportWidth, viewportHeight + statusHeight});
}
setMinimumSize({160, 144 + statusHeight});
}
auto Presentation::loadEmulators() -> void {
loadMenu.reset();
//clean up the recent games history first
vector<string> recentGames;
for(u32 index : range(9)) {
auto entry = settings.recent.game[index];
auto system = entry.split(";", 1L)(0);
auto location = entry.split(";", 1L)(1);
if(location.length()) { //remove missing games
if(!recentGames.find(entry)) { //remove duplicate entries
recentGames.append(entry);
}
}
settings.recent.game[index] = {};
}
//build recent games list
u32 count = 0;
for(auto& game : recentGames) {
settings.recent.game[count++] = game;
}
{ Menu recentGames{&loadMenu};
recentGames.setIcon(Icon::Action::Open);
recentGames.setText("Recent Games");
for(u32 index : range(count)) {
MenuItem item{&recentGames};
auto entry = settings.recent.game[index];
auto system = entry.split(";", 1L)(0);
auto location = entry.split(";", 1L)(1);
item.setIconForFile(location);
item.setText({Location::base(location).trimRight("/"), " (", system, ")"});
item.onActivate([=] {
if(!inode::exists(location)) {
MessageDialog()
.setTitle("Error")
.setText({location, " does not exist"})
.setAlignment(presentation)
.error();
//remove the entry from the recent games list
settings.recent.game[index] = {};
loadEmulators();
return;
}
for(auto& emulator : emulators) {
if(emulator->name == system) {
return (void)program.load(emulator, location);
}
}
});
}
if(count > 0) {
recentGames.append(MenuSeparator());
MenuItem clearHistory{&recentGames};
clearHistory.setIcon(Icon::Edit::Clear);
#if !defined(PLATFORM_MACOS)
clearHistory.setText("Clear History");
#else
clearHistory.setText("Clear Menu");
#endif
clearHistory.onActivate([&] {
for(u32 index : range(9)) settings.recent.game[index] = {};
loadEmulators();
});
} else {
recentGames.setEnabled(false);
}
}
loadMenu.append(MenuSeparator());
//build emulator load list
u32 enabled = 0;
//first pass; make sure "Arcade" is start of list
for(auto& emulator : emulators) {
if(!emulator->configuration.visible) continue;
if(emulator->group() == "Arcade") {
Menu menu;
menu.setIcon(Icon::Emblem::Folder);
menu.setText(emulator->group());
loadMenu.append(menu);
break;
}
}
for(auto& emulator : emulators) {
if (!emulator->configuration.visible) continue;
enabled++;
MenuItem item;
item.setIcon(Icon::Place::Server);
item.setText({emulator->name, ELLIPSIS});
item.setVisible(emulator->configuration.visible);
item.onActivate([=] {
program.load(emulator);
});
Menu menu;
for(auto& action : loadMenu.actions()) {
if(auto group = action.cast<Menu>()) {
if(group.text() == emulator->group()) {
menu = group;
break;
}
}
}
if(!menu) {
menu.setIcon(Icon::Emblem::Folder);
menu.setText(emulator->group());
loadMenu.append(menu);
}
menu.append(item);
}
if(enabled == 0) {
//if the user disables every system, give an indication for how to re-add systems to the load menu
MenuItem item{&loadMenu};
item.setIcon(Icon::Action::Add);
item.setText("Add Systems" ELLIPSIS);
item.onActivate([&] {
settingsWindow.show("Emulators");
});
}
#if !defined(PLATFORM_MACOS)
loadMenu.append(MenuSeparator());
{ MenuItem quit{&loadMenu};
quit.setIcon(Icon::Action::Quit);
quit.setText("Quit");
quit.onActivate([&] {
program.quit();
});
}
#endif
}
auto Presentation::loadEmulator() -> void {
setTitle(emulator->root->game());
setAssociatedFile(emulator->game->location);
systemMenu.setText(emulator->name);
systemMenu.setVisible();
refreshSystemMenu();
toolsMenu.setVisible(true);
pauseEmulation.setChecked(false);
setFocused();
viewport.setFocused();
}
auto Presentation::refreshSystemMenu() -> void {
systemMenu.reset();
//allow each emulator core to create any specialized menus necessary:
//for instance, floppy disk and CD-ROM swapping support.
emulator->load(systemMenu);
if(systemMenu.actionCount() > 0) systemMenu.append(MenuSeparator());
u32 portsFound = 0;
for(auto port : ares::Node::enumerate<ares::Node::Port>(emulator->root)) {
//do not add unsupported ports to the port menu
if(emulator->portBlacklist.find(port->name())) continue;
if(!port->hotSwappable()) continue;
if(port->type() != "Controller" && port->type() != "Expansion") continue;
portsFound++;
Menu portMenu{&systemMenu};
if(port->type() == "Controller") portMenu.setIcon(Icon::Device::Joypad);
if(port->type() == "Expansion" ) portMenu.setIcon(Icon::Device::Storage);
portMenu.setText(port->name());
Group peripheralGroup;
{ MenuRadioItem peripheralItem{&portMenu};
peripheralItem.setAttribute<ares::Node::Port>("port", port);
peripheralItem.setText("Nothing");
peripheralItem.onActivate([=] {
auto port = peripheralItem.attribute<ares::Node::Port>("port");
port->disconnect();
refreshSystemMenu();
});
peripheralGroup.append(peripheralItem);
}
for(auto peripheral : port->supported()) {
//do not add unsupported peripherals to the peripheral port menu
if(emulator->inputBlacklist.find(peripheral)) continue;
MenuRadioItem peripheralItem{&portMenu};
peripheralItem.setAttribute<ares::Node::Port>("port", port);
peripheralItem.setText(peripheral);
peripheralItem.onActivate([=] {
auto port = peripheralItem.attribute<ares::Node::Port>("port");
port->disconnect();
port->allocate(peripheralItem.text());
port->connect();
refreshSystemMenu();
});
peripheralGroup.append(peripheralItem);
}
//check the peripheral item menu option that is currently connected to said port
if(auto connected = port->connected()) {
for(auto peripheralItem : peripheralGroup.objects<MenuRadioItem>()) {
if(peripheralItem.text() == connected->name()) peripheralItem.setChecked();
}
}
}
if(portsFound > 0) systemMenu.append(MenuSeparator());
MenuItem reset{&systemMenu};
reset.setText("Reset").setIcon(Icon::Action::Refresh).onActivate([&] {
emulator->root->power(true);
program.showMessage("System reset");
});
systemMenu.append(MenuSeparator());
MenuItem unload{&systemMenu};
unload.setText("Unload").setIcon(Icon::Media::Eject).onActivate([&] {
program.unload();
if(settings.video.adaptiveSizing) presentation.resizeWindow();
presentation.showIcon(true);
});
}
auto Presentation::unloadEmulator(bool reloading) -> void {
setTitle({ares::Name, " v", ares::Version});
setAssociatedFile();
systemMenu.setVisible(false);
systemMenu.reset();
toolsMenu.setVisible(false);
}
auto Presentation::showIcon(bool visible) -> void {
iconLayout.setVisible(visible);
iconSpacer.setVisible(visible);
iconCanvas.setVisible(visible);
iconBottom.setVisible(visible);
layout.resize();
}
auto Presentation::loadShaders() -> void {
videoShaderMenu.reset();
#if !defined(NO_LIBRASHADER)
const auto hasShader = ruby::video.hasShader();
#else
const auto hasShader = false;
#endif
videoShaderMenu.setEnabled(hasShader);
if(!hasShader) return;
Group shaders;
MenuCheckItem none{&videoShaderMenu};
none.setText("None").onToggle([&] {
settings.video.shader = "None";
ruby::video.setShader(settings.video.shader);
loadShaders();
});
shaders.append(none);
string location = locate("Shaders/");
if(shaderDirectories.size() == 0) {
function<void(string)> findShaderDirectories = [&](string path) {
for(auto &entry: directory::folders(path)) findShaderDirectories({path, entry});
auto files = directory::files(path, "*.slangp");
if(files.size() > 0) shaderDirectories.append((string({path}).trimLeft(location, 1L)));
};
findShaderDirectories(location);
// Sort by name and depth such that child folders appear after their parents
shaderDirectories.sort([](const string &lhs, const string &rhs) {
auto lhsParts = lhs.split("/");
auto rhsParts = rhs.split("/");
for(u32 i : range(min(lhsParts.size(), rhsParts.size()))) {
if(lhsParts[i] != rhsParts[i]) return lhsParts[i] < rhsParts[i];
}
return lhsParts.size() < rhsParts.size();
});
}
if(ruby::video.hasShader()) {
for(auto &directory : shaderDirectories) {
auto parts = directory.split("/");
Menu parent = videoShaderMenu;
if(directory != "") {
for (auto &part: parts) {
if(part == "") continue;
Menu child;
bool found = false;
for(auto &action: parent.actions()) {
if(auto menu = action.cast<Menu>()) {
if(menu.text() == part) {
child = menu;
found = true;
break;
}
}
}
if(found) {
parent = child;
} else {
Menu newMenu{&parent};
newMenu.setText(part);
parent = newMenu;
}
}
}
auto files = directory::files({location, directory}, "*.slangp");
for(auto &file: files) {
MenuCheckItem item{&parent};
item.setAttribute("file", {directory, file});
item.setText(string{file}.trimRight(".slangp", 1L)).onToggle([=] {
settings.video.shader = {directory, file};
ruby::video.setShader({location, settings.video.shader});
loadShaders();
});
shaders.append(item);
}
}
}
if(program.startShader) {
string existingShader = settings.video.shader;
if(!program.startShader.imatch("None")) {
settings.video.shader = {location, program.startShader, ".slangp"};
} else {
settings.video.shader = program.startShader;
}
if(inode::exists(settings.video.shader)) {
ruby::video.setShader({location, settings.video.shader});
loadShaders();
} else if(settings.video.shader.imatch("None")) {
ruby::video.setShader("None");
loadShaders();
} else {
hiro::MessageDialog()
.setTitle("Warning")
.setAlignment(hiro::Alignment::Center)
.setText({ "Requested shader not found: ", settings.video.shader , "\nUsing existing defined shader: ", existingShader })
.warning();
settings.video.shader = existingShader;
}
}
if(settings.video.shader.imatch("None")) {none.setChecked(); settings.video.shader = "None";}
for(auto item : shaders.objects<MenuCheckItem>()) {
if(settings.video.shader.imatch(item.attribute("file"))) {
item.setChecked();
settings.video.shader = item.attribute("file");
ruby::video.setShader({location, settings.video.shader});
}
}
}