| 1 | Presentation* presentation = nullptr; |
| 2 | |
| 3 | void Presentation::synchronize() { |
| 4 | for(auto& emulator : emulatorList) emulator->menu.setVisible(false); |
| 5 | for(auto& emulator : emulatorList) { |
| 6 | if(emulator->interface == program->active) { |
| 7 | active = emulator; |
| 8 | emulator->menu.setVisible(true); |
| 9 | } |
| 10 | } |
| 11 | |
| 12 | shaderNone.setChecked(); |
| 13 | if(config->video.shader == "None") shaderNone.setChecked(); |
| 14 | if(config->video.shader == "Blur") shaderBlur.setChecked(); |
| 15 | if(config->video.shader == "Display Emulation") shaderEmulation.setChecked(); |
| 16 | for(auto& shader : shaderList) { |
| 17 | string name = notdir(config->video.shader.split<1>(".shader/")(0)); |
| 18 | if(name == shader->text()) shader->setChecked(); |
| 19 | } |
| 20 | |
| 21 | switch(config->video.scaleMode) { |
| 22 | case 0: centerVideo.setChecked(); break; |
| 23 | case 1: scaleVideo.setChecked(); break; |
| 24 | case 2: stretchVideo.setChecked(); break; |
| 25 | } |
| 26 | aspectCorrection.setChecked(config->video.aspectCorrection); |
| 27 | maskOverscan.setChecked(config->video.maskOverscan.enable); |
| 28 | synchronizeVideo.setChecked(config->video.synchronize); |
| 29 | synchronizeAudio.setChecked(config->audio.synchronize); |
| 30 | muteAudio.setChecked(config->audio.mute); |
| 31 | |
| 32 | if(program->active == nullptr) { |
| 33 | toolsMenu.setVisible(false); |
| 34 | } else { |
| 35 | toolsMenu.setVisible(true); |
| 36 | saveStateMenu.setVisible(system().information.capability.states); |
| 37 | loadStateMenu.setVisible(system().information.capability.states); |
| 38 | stateMenuSeparator.setVisible(system().information.capability.states); |
| 39 | resizeWindow.setVisible(config->video.scaleMode != 2); |
| 40 | stateManager.setVisible(system().information.capability.states); |
| 41 | cheatEditor.setVisible(system().information.capability.cheats); |
| 42 | synchronizeTime.setVisible(system().rtc()); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | void Presentation::setSystemName(string name) { |
| 47 | if(active) active->menu.setText(systemName = name); |
| 48 | } |
| 49 | |
| 50 | Presentation::Presentation() { |
| 51 | bootstrap(); |
| 52 | loadShaders(); |
| 53 | setGeometry({256, 256, 720, 480}); |
| 54 | windowManager->append(this, "Presentation"); |
| 55 | |
| 56 | setTitle({::Emulator::Name, " v", ::Emulator::Version}); |
| 57 | setBackgroundColor({0, 0, 0}); |
| 58 | setMenuVisible(); |
| 59 | setStatusVisible(); |
| 60 | |
| 61 | setDroppable(); |
| 62 | viewport.setDroppable(); |
| 63 | |
| 64 | loadMenu.setText("Library"); |
| 65 | settingsMenu.setText("Settings"); |
| 66 | videoMenu.setText("Video"); |
| 67 | centerVideo.setText("Center"); |
| 68 | scaleVideo.setText("Scale"); |
| 69 | stretchVideo.setText("Stretch"); |
| 70 | RadioItem::group(centerVideo, scaleVideo, stretchVideo); |
| 71 | aspectCorrection.setText("Aspect Correction"); |
| 72 | maskOverscan.setText("Mask Overscan"); |
| 73 | shaderMenu.setText("Shader"); |
| 74 | shaderNone.setText("None"); |
| 75 | shaderBlur.setText("Blur"); |
| 76 | shaderEmulation.setText("Display Emulation"); |
| 77 | synchronizeVideo.setText("Synchronize Video"); |
| 78 | synchronizeAudio.setText("Synchronize Audio"); |
| 79 | muteAudio.setText("Mute Audio"); |
| 80 | configurationSettings.setText("Configuration ..."); |
| 81 | toolsMenu.setText("Tools"); |
| 82 | saveStateMenu.setText("Save State"); |
| 83 | for(unsigned n = 0; n < 5; n++) saveStateItem[n].setText({"Slot ", 1 + n}); |
| 84 | loadStateMenu.setText("Load State"); |
| 85 | for(unsigned n = 0; n < 5; n++) loadStateItem[n].setText({"Slot ", 1 + n}); |
| 86 | resizeWindow.setText("Resize Window"); |
| 87 | stateManager.setText("State Manager"); |
| 88 | cheatEditor.setText("Cheat Editor"); |
| 89 | synchronizeTime.setText("Synchronize Time"); |
| 90 | |
| 91 | append(loadMenu); |
| 92 | for(auto& item : loadBootableMedia) loadMenu.append(*item); |
| 93 | for(auto& systemItem : emulatorList) append(systemItem->menu); |
| 94 | append(settingsMenu); |
| 95 | settingsMenu.append(videoMenu); |
| 96 | videoMenu.append(centerVideo); |
| 97 | videoMenu.append(scaleVideo); |
| 98 | videoMenu.append(stretchVideo); |
| 99 | videoMenu.append(*new Separator); |
| 100 | videoMenu.append(aspectCorrection); |
| 101 | videoMenu.append(maskOverscan); |
| 102 | settingsMenu.append(shaderMenu); |
| 103 | shaderMenu.append(shaderNone); |
| 104 | shaderMenu.append(shaderBlur); |
| 105 | if(config->video.driver == "OpenGL") shaderMenu.append(shaderEmulation); |
| 106 | if(shaderList.size() > 0) { |
| 107 | shaderMenu.append(*new Separator); |
| 108 | for(auto& shader : shaderList) shaderMenu.append(*shader); |
| 109 | } |
| 110 | settingsMenu.append(*new Separator); |
| 111 | settingsMenu.append(synchronizeVideo); |
| 112 | settingsMenu.append(synchronizeAudio); |
| 113 | settingsMenu.append(muteAudio); |
| 114 | if(Intrinsics::platform() != Intrinsics::Platform::MacOSX) { |
| 115 | settingsMenu.append(*new Separator); |
| 116 | settingsMenu.append(configurationSettings); |
| 117 | } |
| 118 | append(toolsMenu); |
| 119 | toolsMenu.append(saveStateMenu); |
| 120 | for(unsigned n = 0; n < 5; n++) saveStateMenu.append(saveStateItem[n]); |
| 121 | toolsMenu.append(loadStateMenu); |
| 122 | for(unsigned n = 0; n < 5; n++) loadStateMenu.append(loadStateItem[n]); |
| 123 | toolsMenu.append(stateMenuSeparator); |
| 124 | toolsMenu.append(resizeWindow); |
| 125 | toolsMenu.append(stateManager); |
| 126 | toolsMenu.append(cheatEditor); |
| 127 | toolsMenu.append(synchronizeTime); |
| 128 | |
| 129 | append(layout); |
| 130 | layout.append(viewport, {0, 0, 1, 1}); |
| 131 | |
| 132 | onDrop = viewport.onDrop = [&](lstring paths) { |
| 133 | if(paths.size() && directory::exists(paths[0])) { |
| 134 | utility->loadMedia(paths[0]); |
| 135 | setFocused(); |
| 136 | } |
| 137 | }; |
| 138 | |
| 139 | onSize = [&] { |
| 140 | utility->resize(); |
| 141 | }; |
| 142 | |
| 143 | onClose = [&] { |
| 144 | setVisible(false); |
| 145 | if(Intrinsics::platform() == Intrinsics::Platform::MacOSX) { |
| 146 | utility->unload(); |
| 147 | } else { |
| 148 | Application::quit(); |
| 149 | } |
| 150 | }; |
| 151 | |
| 152 | shaderNone.onActivate = [&] { config->video.shader = "None"; utility->updateShader(); }; |
| 153 | shaderBlur.onActivate = [&] { config->video.shader = "Blur"; utility->updateShader(); }; |
| 154 | shaderEmulation.onActivate = [&] { config->video.shader = "Display Emulation"; utility->updateShader(); }; |
| 155 | centerVideo.onActivate = [&] { config->video.scaleMode = 0; utility->resize(); }; |
| 156 | scaleVideo.onActivate = [&] { config->video.scaleMode = 1; utility->resize(); }; |
| 157 | stretchVideo.onActivate = [&] { config->video.scaleMode = 2; utility->resize(); }; |
| 158 | aspectCorrection.onToggle = [&] { config->video.aspectCorrection = aspectCorrection.checked(); utility->resize(); }; |
| 159 | maskOverscan.onToggle = [&] { config->video.maskOverscan.enable = maskOverscan.checked(); }; |
| 160 | synchronizeVideo.onToggle = [&] { config->video.synchronize = synchronizeVideo.checked(); utility->synchronizeRuby(); }; |
| 161 | synchronizeAudio.onToggle = [&] { config->audio.synchronize = synchronizeAudio.checked(); utility->synchronizeRuby(); }; |
| 162 | muteAudio.onToggle = [&] { config->audio.mute = muteAudio.checked(); utility->synchronizeRuby(); }; |
| 163 | configurationSettings.onActivate = [&] { settings->setVisible(); }; |
| 164 | for(unsigned n = 0; n < 5; n++) saveStateItem[n].onActivate = [=] { utility->saveState(1 + n); }; |
| 165 | for(unsigned n = 0; n < 5; n++) loadStateItem[n].onActivate = [=] { utility->loadState(1 + n); }; |
| 166 | resizeWindow.onActivate = [&] { utility->resize(true); }; |
| 167 | stateManager.onActivate = [&] { tools->panels.setSelection(1); tools->setVisible(); }; |
| 168 | cheatEditor.onActivate = [&] { tools->panels.setSelection(0); tools->setVisible(); }; |
| 169 | synchronizeTime.onActivate = [&] { system().rtcsync(); }; |
| 170 | |
| 171 | synchronize(); |
| 172 | } |
| 173 | |
| 174 | void Presentation::bootstrap() { |
| 175 | for(auto& emulator : program->emulator) { |
| 176 | for(auto& media : emulator->media) { |
| 177 | if(media.bootable == false) continue; |
| 178 | Item* item = new Item; |
| 179 | item->setText({media.name, " ..."}); |
| 180 | item->onActivate = [=] { libraryManager->show(media.type); }; |
| 181 | loadBootableMedia.append(item); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | for(auto& emulator : program->emulator) { |
| 186 | auto iEmulator = new Emulator; |
| 187 | iEmulator->interface = emulator; |
| 188 | |
| 189 | iEmulator->menu.setText(emulator->information.name); |
| 190 | iEmulator->power.setText("Power"); |
| 191 | iEmulator->reset.setText("Reset"); |
| 192 | iEmulator->unload.setText("Unload"); |
| 193 | |
| 194 | for(auto& port : emulator->port) { |
| 195 | auto iPort = new Emulator::Port; |
| 196 | iPort->menu.setText(port.name); |
| 197 | iEmulator->port.append(iPort); |
| 198 | |
| 199 | for(auto& device : port.device) { |
| 200 | auto iDevice = new RadioItem; |
| 201 | iDevice->setText(device.name); |
| 202 | iDevice->onActivate = [=] { utility->connect(port.id, device.id); }; |
| 203 | iPort->group.append(*iDevice); |
| 204 | iPort->device.append(iDevice); |
| 205 | } |
| 206 | |
| 207 | RadioItem::group(iPort->group); |
| 208 | } |
| 209 | |
| 210 | iEmulator->menu.append(iEmulator->power); |
| 211 | if(emulator->information.resettable) |
| 212 | iEmulator->menu.append(iEmulator->reset); |
| 213 | iEmulator->menu.append(*new Separator); |
| 214 | unsigned visiblePorts = 0; |
| 215 | for(auto& iPort : iEmulator->port) { |
| 216 | iEmulator->menu.append(iPort->menu); |
| 217 | if(iPort->device.size() <= 1) iPort->menu.setVisible(false); |
| 218 | else visiblePorts++; |
| 219 | for(auto& iDevice : iPort->device) { |
| 220 | iPort->menu.append(*iDevice); |
| 221 | } |
| 222 | } |
| 223 | iEmulator->menu.append(iEmulator->controllerSeparator); |
| 224 | if(visiblePorts == 0) iEmulator->controllerSeparator.setVisible(false); |
| 225 | iEmulator->menu.append(iEmulator->unload); |
| 226 | |
| 227 | iEmulator->power.onActivate = {&Utility::power, utility}; |
| 228 | iEmulator->reset.onActivate = {&Utility::reset, utility}; |
| 229 | iEmulator->unload.onActivate = {&Utility::unload, utility}; |
| 230 | |
| 231 | emulatorList.append(iEmulator); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | void Presentation::loadShaders() { |
| 236 | //only the OpenGL driver has video shader support |
| 237 | if(config->video.driver == "OpenGL") { |
| 238 | string pathname = program->path("Video Shaders/"); |
| 239 | lstring shaders = directory::folders(pathname, "*.shader"); |
| 240 | for(auto& name : shaders) { |
| 241 | auto shader = new RadioItem; |
| 242 | shader->setText(name.split<1>(".shader/")(0)); |
| 243 | shader->onActivate = [=] { |
| 244 | config->video.shader = {pathname, name}; |
| 245 | utility->updateShader(); |
| 246 | }; |
| 247 | shaderList.append(shader); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | nall::group<RadioItem> group; |
| 252 | group.append(shaderNone); |
| 253 | group.append(shaderBlur); |
| 254 | group.append(shaderEmulation); |
| 255 | for(auto& shader : shaderList) group.append(*shader); |
| 256 | RadioItem::group(group); |
| 257 | } |