utility.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. auto Program::pause(bool state) -> void {
  2. if(paused == state) return;
  3. paused = state;
  4. presentation.pauseEmulation.setChecked(paused);
  5. if(paused) {
  6. ruby::audio.clear();
  7. presentation.statusRight.setText("Paused");
  8. }
  9. }
  10. auto Program::paletteUpdate() -> void {
  11. if(!emulator) return;
  12. for(auto& screen : emulator->root->find<ares::Node::Screen>()) {
  13. screen->setLuminance(settings.video.luminance);
  14. screen->setSaturation(settings.video.saturation);
  15. screen->setGamma(settings.video.gamma);
  16. }
  17. }
  18. auto Program::runAheadUpdate() -> void {
  19. runAhead = settings.general.runAhead;
  20. if(emulator && emulator->name == "Game Boy Advance") runAhead = false; //crashes immediately
  21. if(emulator && emulator->name == "MSX") runAhead = false; //unstable
  22. if(emulator && emulator->name == "MSX2") runAhead = false; //unstable
  23. }
  24. auto Program::captureScreenshot(const uint32_t* data, uint pitch, uint width, uint height) -> void {
  25. string filename{emulator->locate({Location::notsuffix(emulator->game.location), " ", chrono::local::datetime().transform(":", "-"), ".png"}, ".png", settings.paths.screenshots)};
  26. if(Encode::PNG::RGB8(filename, data, pitch, width, height)) {
  27. showMessage("Captured screenshot");
  28. } else {
  29. showMessage("Failed to capture screenshot");
  30. }
  31. }
  32. auto Program::openFile(BrowserDialog& dialog) -> string {
  33. if(settings.general.nativeFileDialogs) {
  34. BrowserWindow window;
  35. window.setTitle(dialog.title());
  36. window.setPath(dialog.path());
  37. window.setFilters(dialog.filters());
  38. window.setParent(dialog.alignmentWindow());
  39. return window.open();
  40. }
  41. return dialog.openFile();
  42. }
  43. auto Program::selectFolder(BrowserDialog& dialog) -> string {
  44. if(settings.general.nativeFileDialogs) {
  45. BrowserWindow window;
  46. window.setTitle(dialog.title());
  47. window.setPath(dialog.path());
  48. window.setParent(dialog.alignmentWindow());
  49. return window.directory();
  50. }
  51. return dialog.selectFolder();
  52. }