From bd7eac6c4b3de9bbd4ed30f01d91e3fe150d76c9 Mon Sep 17 00:00:00 2001 From: Fabrice de Gans Date: Tue, 21 Feb 2023 14:21:00 -0800 Subject: [PATCH] Add options shared with sdl to wx g_owned_opts This removed the dependency on ConfigManager from the wx frontend. Next: Move ConfigManager to be only used by the SDL frontend. --- src/common/SoundSDL.cpp | 1 - src/wx/cmdevents.cpp | 44 ++++---- src/wx/config/internal/option-internal.cpp | 32 ++++-- src/wx/config/option-id.h | 2 + src/wx/config/option-proxy.h | 18 ++-- src/wx/dialogs/display-config.cpp | 13 +-- src/wx/gfxviewers.cpp | 24 +++-- src/wx/guiinit.cpp | 16 ++- src/wx/opts.cpp | 4 - src/wx/panel.cpp | 29 +++--- src/wx/sys.cpp | 37 +++---- src/wx/viewsupt.cpp | 11 +- src/wx/widgets/option-validator.cpp | 112 +++++++++++++++++++++ src/wx/widgets/option-validator.h | 55 ++++++++++ src/wx/wxvbam.cpp | 2 +- src/wx/wxvbam.h | 2 +- 16 files changed, 294 insertions(+), 108 deletions(-) diff --git a/src/common/SoundSDL.cpp b/src/common/SoundSDL.cpp index fb95925d..bcfe4bae 100644 --- a/src/common/SoundSDL.cpp +++ b/src/common/SoundSDL.cpp @@ -19,7 +19,6 @@ #include #include #include "SoundSDL.h" -#include "ConfigManager.h" #include "../gba/Globals.h" #include "../gba/Sound.h" diff --git a/src/wx/cmdevents.cpp b/src/wx/cmdevents.cpp index 6e735bf5..bf3678d5 100644 --- a/src/wx/cmdevents.cpp +++ b/src/wx/cmdevents.cpp @@ -91,7 +91,7 @@ void MainFrame::GetMenuOptionInt(const wxString& menuName, int* field, int mask) *field = ((*field) & ~(mask)) | (is_checked ? (value) : 0); } -void MainFrame::SetMenuOption(const wxString& menuName, int value) +void MainFrame::SetMenuOption(const wxString& menuName, bool value) { int id = wxXmlResource::GetXRCID(menuName); @@ -1177,14 +1177,15 @@ EVT_HANDLER_MASK(ScreenCapture, "Screen capture...", CMDEN_GB | CMDEN_GBA) wxString scap_path = GetGamePath(gopts.scrshot_dir); wxString def_name = panel->game_name(); - if (captureFormat == 0) - def_name.append(wxT(".png")); + const int capture_format = OPTION(kPrefCaptureFormat); + if (capture_format == 0) + def_name.append(".png"); else - def_name.append(wxT(".bmp")); + def_name.append(".bmp"); wxFileDialog dlg(this, _("Select output file"), scap_path, def_name, _("PNG images|*.png|BMP images|*.bmp"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT); - dlg.SetFilterIndex(captureFormat); + dlg.SetFilterIndex(capture_format); int ret = ShowModal(&dlg); scap_path = dlg.GetDirectory(); @@ -1512,10 +1513,10 @@ EVT_HANDLER(Pause, "Pause (toggle)") panel->Resume(); // undo next-frame's zeroing of frameskip - int fs = frameSkip; - - if (fs >= 0) - systemFrameSkip = fs; + const int frame_skip = OPTION(kPrefFrameSkip); + if (frame_skip != -1) { + systemFrameSkip = frame_skip; + } } // new @@ -2614,7 +2615,7 @@ EVT_HANDLER(GameBoyAdvanceConfigure, "Game Boy Advance options...") return; if (panel->game_type() == IMAGE_GBA) { - agbPrintEnable(agbPrint); + agbPrintEnable(OPTION(kPrefAgbPrint)); wxString s = wxString((const char*)&rom[0xac], wxConvLibc, 4); wxFileConfig* cfg = wxGetApp().overrides; bool chg; @@ -2726,8 +2727,9 @@ EVT_HANDLER_MASK(DisplayConfigure, "Display options...", CMDEN_NREC_ANY) return; } - if (frameSkip >= 0) { - systemFrameSkip = frameSkip; + const int frame_skip = OPTION(kPrefFrameSkip); + if (frame_skip != -1) { + systemFrameSkip = frame_skip; } update_opts(); @@ -3000,8 +3002,7 @@ EVT_HANDLER(GBSurround, "GB surround sound effect (%)") EVT_HANDLER(AGBPrinter, "Enable AGB printer") { - GetMenuOptionInt("AGBPrinter", &agbPrint, 1); - update_opts(); + GetMenuOptionConfig("AGBPrinter", config::OptionID::kPrefAgbPrint); } EVT_HANDLER_MASK(GBALcdFilter, "Enable LCD filter", CMDEN_GBA) @@ -3037,8 +3038,7 @@ EVT_HANDLER(GBColorOption, "Enable GB color option") EVT_HANDLER(ApplyPatches, "Apply IPS/UPS/IPF patches if found") { - GetMenuOptionInt("ApplyPatches", &autoPatch, 1); - update_opts(); + GetMenuOptionConfig("ApplyPatches", config::OptionID::kPrefAutoPatch); } EVT_HANDLER(KeepOnTop, "Keep window on top") @@ -3064,14 +3064,12 @@ EVT_HANDLER(StatusBar, "Enable status bar") EVT_HANDLER(NoStatusMsg, "Disable on-screen status messages") { - GetMenuOptionInt("NoStatusMsg", &disableStatusMessages, 1); - update_opts(); + GetMenuOptionConfig("NoStatusMsg", config::OptionID::kPrefDisableStatus); } EVT_HANDLER(FrameSkipAuto, "Auto Skip frames.") { - GetMenuOptionInt("FrameSkipAuto", &autoFrameSkip, 1); - update_opts(); + GetMenuOptionConfig("FrameSkipAuto", config::OptionID::kPrefAutoFrameSkip); } EVT_HANDLER(Fullscreen, "Enter fullscreen mode at startup") @@ -3081,8 +3079,7 @@ EVT_HANDLER(Fullscreen, "Enter fullscreen mode at startup") EVT_HANDLER(PauseWhenInactive, "Pause game when main window loses focus") { - GetMenuOptionInt("PauseWhenInactive", &pauseWhenInactive, 1); - update_opts(); + GetMenuOptionConfig("PauseWhenInactive", config::OptionID::kPrefPauseWhenInactive); } EVT_HANDLER(RTC, "Enable RTC (vba-over.ini override is rtcEnabled") @@ -3093,8 +3090,7 @@ EVT_HANDLER(RTC, "Enable RTC (vba-over.ini override is rtcEnabled") EVT_HANDLER(Transparent, "Draw on-screen messages transparently") { - GetMenuOptionInt("Transparent", &showSpeedTransparent, 1); - update_opts(); + GetMenuOptionConfig("Transparent", config::OptionID::kPrefShowSpeedTransparent); } EVT_HANDLER(SkipIntro, "Skip BIOS initialization") diff --git a/src/wx/config/internal/option-internal.cpp b/src/wx/config/internal/option-internal.cpp index bfa78e4f..f465392e 100644 --- a/src/wx/config/internal/option-internal.cpp +++ b/src/wx/config/internal/option-internal.cpp @@ -164,6 +164,18 @@ std::array& Option::All() { /// GB bool colorizer_hack = false; + /// Core + bool agb_print = false; + bool auto_frame_skip = false; + bool auto_patch = true; + uint32_t capture_format = 0; + bool disable_status_messages = false; + uint32_t flash_size = 0; + int32_t frame_skip = 0; + bool pause_when_inactive = false; + uint32_t show_speed = 0; + bool show_speed_transparent = false; + /// General uint32_t ini_version = kIniLatestVersion; @@ -248,18 +260,18 @@ std::array& Option::All() { Option(OptionID::kKeyboard), /// Core - Option(OptionID::kPrefAgbPrint, &agbPrint, 0, 1), - Option(OptionID::kPrefAutoFrameSkip, &autoFrameSkip, 0, 1), - Option(OptionID::kPrefAutoPatch, &autoPatch, 0, 1), + Option(OptionID::kPrefAgbPrint, &g_owned_opts.agb_print), + Option(OptionID::kPrefAutoFrameSkip, &g_owned_opts.auto_frame_skip), + Option(OptionID::kPrefAutoPatch, &g_owned_opts.auto_patch), Option(OptionID::kPrefAutoSaveLoadCheatList, &gopts.autoload_cheats), Option(OptionID::kPrefBorderAutomatic, &gbBorderAutomatic, 0, 1), Option(OptionID::kPrefBorderOn, &gbBorderOn, 0, 1), - Option(OptionID::kPrefCaptureFormat, &captureFormat, 0, 1), + Option(OptionID::kPrefCaptureFormat, &g_owned_opts.capture_format, 0, 1), Option(OptionID::kPrefCheatsEnabled, &coreOptions.cheatsEnabled, 0, 1), - Option(OptionID::kPrefDisableStatus, &disableStatusMessages, 0, 1), + Option(OptionID::kPrefDisableStatus, &g_owned_opts.disable_status_messages), Option(OptionID::kPrefEmulatorType, &gbEmulatorType, 0, 5), - Option(OptionID::kPrefFlashSize, &optFlashSize, 0, 1), - Option(OptionID::kPrefFrameSkip, &frameSkip, -1, 9), + Option(OptionID::kPrefFlashSize, &g_owned_opts.flash_size, 0, 1), + Option(OptionID::kPrefFrameSkip, &g_owned_opts.frame_skip, -1, 9), Option(OptionID::kPrefGBPaletteOption, &gbPaletteOption, 0, 2), Option(OptionID::kPrefGBPrinter, &coreOptions.winGbPrinterEnabled, 0, 1), Option(OptionID::kPrefGDBBreakOnLoad, &gopts.gdb_break_on_load), @@ -268,11 +280,11 @@ std::array& Option::All() { Option(OptionID::kPrefLinkNumPlayers, &gopts.link_num_players, 2, 4), #endif Option(OptionID::kPrefMaxScale, &gopts.max_scale, 0, 100), - Option(OptionID::kPrefPauseWhenInactive, &pauseWhenInactive, 0, 1), + Option(OptionID::kPrefPauseWhenInactive, &g_owned_opts.pause_when_inactive), Option(OptionID::kPrefRTCEnabled, &coreOptions.rtcEnabled, 0, 1), Option(OptionID::kPrefSaveType, &coreOptions.cpuSaveType, 0, 5), - Option(OptionID::kPrefShowSpeed, &showSpeed, 0, 2), - Option(OptionID::kPrefShowSpeedTransparent, &showSpeedTransparent, 0, 1), + Option(OptionID::kPrefShowSpeed, &g_owned_opts.show_speed, 0, 2), + Option(OptionID::kPrefShowSpeedTransparent, &g_owned_opts.show_speed_transparent), Option(OptionID::kPrefSkipBios, &coreOptions.skipBios, 0, 1), Option(OptionID::kPrefSkipSaveGameCheats, &coreOptions.skipSaveGameCheats, 0, 1), Option(OptionID::kPrefSkipSaveGameBattery, &coreOptions.skipSaveGameBattery, 0, 1), diff --git a/src/wx/config/option-id.h b/src/wx/config/option-id.h index e9744248..393a293a 100644 --- a/src/wx/config/option-id.h +++ b/src/wx/config/option-id.h @@ -1,6 +1,8 @@ #ifndef VBAM_WX_CONFIG_OPTION_ID_H_ #define VBAM_WX_CONFIG_OPTION_ID_H_ +#include + namespace config { enum class OptionID { diff --git a/src/wx/config/option-proxy.h b/src/wx/config/option-proxy.h index 56adfd38..3d0b8145 100644 --- a/src/wx/config/option-proxy.h +++ b/src/wx/config/option-proxy.h @@ -70,17 +70,17 @@ static constexpr std::array kOptionsTypes = { /*kKeyboard*/ Option::Type::kNone, /// Core - /*kPrefAgbPrint*/ Option::Type::kInt, - /*kPrefAutoFrameSkip*/ Option::Type::kInt, - /*kPrefAutoPatch*/ Option::Type::kInt, + /*kPrefAgbPrint*/ Option::Type::kBool, + /*kPrefAutoFrameSkip*/ Option::Type::kBool, + /*kPrefAutoPatch*/ Option::Type::kBool, /*kPrefAutoSaveLoadCheatList*/ Option::Type::kBool, /*kPrefBorderAutomatic*/ Option::Type::kInt, /*kPrefBorderOn*/ Option::Type::kInt, - /*kPrefCaptureFormat*/ Option::Type::kInt, + /*kPrefCaptureFormat*/ Option::Type::kUnsigned, /*kPrefCheatsEnabled*/ Option::Type::kInt, - /*kPrefDisableStatus*/ Option::Type::kInt, + /*kPrefDisableStatus*/ Option::Type::kBool, /*kPrefEmulatorType*/ Option::Type::kInt, - /*kPrefFlashSize*/ Option::Type::kInt, + /*kPrefFlashSize*/ Option::Type::kUnsigned, /*kPrefFrameSkip*/ Option::Type::kInt, /*kPrefGBPaletteOption*/ Option::Type::kInt, /*kPrefGBPrinter*/ Option::Type::kInt, @@ -90,11 +90,11 @@ static constexpr std::array kOptionsTypes = { /*kPrefLinkNumPlayers*/ Option::Type::kInt, #endif /*kPrefMaxScale*/ Option::Type::kInt, - /*kPrefPauseWhenInactive*/ Option::Type::kInt, + /*kPrefPauseWhenInactive*/ Option::Type::kBool, /*kPrefRTCEnabled*/ Option::Type::kInt, /*kPrefSaveType*/ Option::Type::kInt, - /*kPrefShowSpeed*/ Option::Type::kInt, - /*kPrefShowSpeedTransparent*/ Option::Type::kInt, + /*kPrefShowSpeed*/ Option::Type::kUnsigned, + /*kPrefShowSpeedTransparent*/ Option::Type::kBool, /*kPrefSkipBios*/ Option::Type::kInt, /*kPrefSkipSaveGameCheats*/ Option::Type::kInt, /*kPrefSkipSaveGameBattery*/ Option::Type::kInt, diff --git a/src/wx/dialogs/display-config.cpp b/src/wx/dialogs/display-config.cpp index 0aef2db6..217c8de1 100644 --- a/src/wx/dialogs/display-config.cpp +++ b/src/wx/dialogs/display-config.cpp @@ -8,8 +8,6 @@ #include #include #include -#include -#include #include #include @@ -261,17 +259,14 @@ DisplayConfig::DisplayConfig(wxWindow* parent) wxXmlResource::Get()->LoadDialog(this, parent, "DisplayConfig"); // Speed - // AutoSkip/FrameSkip are 2 controls for 1 value. Needs post-process - // to ensure checkbox not ignored GetValidatedChild(this, "FrameSkip") - ->SetValidator(wxGenericValidator(&frameSkip)); - if (frameSkip >= 0) { - systemFrameSkip = frameSkip; - } + ->SetValidator( + widgets::OptionSpinCtrlValidator(config::OptionID::kPrefFrameSkip)); // On-Screen Display GetValidatedChild(this, "SpeedIndicator") - ->SetValidator(wxGenericValidator(&showSpeed)); + ->SetValidator( + widgets::OptionChoiceValidator(config::OptionID::kPrefShowSpeed)); // Zoom GetValidatedChild(this, "DefaultScale")->SetValidator(ScaleValidator()); diff --git a/src/wx/gfxviewers.cpp b/src/wx/gfxviewers.cpp index 7f26a1df..cb795fa4 100644 --- a/src/wx/gfxviewers.cpp +++ b/src/wx/gfxviewers.cpp @@ -2,11 +2,13 @@ // these are all the viewer dialogs with graphical panel areas // they can be instantiated multiple times -#include "viewsupt.h" -#include "wxvbam.h" #include #include +#include "config/option-proxy.h" +#include "viewsupt.h" +#include "wxvbam.h" + // FIXME: many of these read e.g. palette data directly without regard to // byte order. Need to determine where things are stored in emulated machine // order and where in native order, and swap the latter on big-endian @@ -1592,14 +1594,15 @@ public: wxString def_name = panel->game_name() + wxT('-') + dname; def_name.resize(def_name.size() - 6); // strlen("Viewer") - if (captureFormat) - def_name += wxT(".bmp"); + const int capture_format = OPTION(kPrefCaptureFormat); + if (capture_format == 0) + def_name.append(".png"); else - def_name += wxT(".png"); + def_name.append(".bmp"); wxFileDialog dlg(GetGrandParent(), _("Select output file"), bmp_save_dir, def_name, _("PNG images|*.png|BMP images|*.bmp"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT); - dlg.SetFilterIndex(captureFormat); + dlg.SetFilterIndex(capture_format); int ret = dlg.ShowModal(); bmp_save_dir = dlg.GetDirectory(); @@ -1734,14 +1737,15 @@ public: wxString def_name = panel->game_name() + wxT('-') + dname; def_name.resize(def_name.size() - 6); // strlen("Viewer") - if (captureFormat) - def_name += wxT(".bmp"); + const int capture_format = OPTION(kPrefCaptureFormat); + if (capture_format == 0) + def_name.append(".png"); else - def_name += wxT(".png"); + def_name.append(".bmp"); wxFileDialog dlg(GetGrandParent(), _("Select output file"), bmp_save_dir, def_name, _("PNG images|*.png|BMP images|*.bmp"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT); - dlg.SetFilterIndex(captureFormat); + dlg.SetFilterIndex(capture_format); int ret = dlg.ShowModal(); bmp_save_dir = dlg.GetDirectory(); diff --git a/src/wx/guiinit.cpp b/src/wx/guiinit.cpp index 798ef7a5..f1cbf6da 100644 --- a/src/wx/guiinit.cpp +++ b/src/wx/guiinit.cpp @@ -30,6 +30,7 @@ #include "config/user-input.h" #include "dialogs/display-config.h" #include "opts.h" +#include "widgets/option-validator.h" #if defined(__WXGTK__) #include "wayland.h" @@ -2981,6 +2982,12 @@ bool MainFrame::BindControls() d = LoadXRCDialog("NetLink"); #endif wxRadioButton* rb; +#define getrbo(name, option_id, value) \ + do { \ + rb = SafeXRCCTRL(d, name); \ + rb->SetValidator( \ + ::widgets::OptionSelectedValidator(option_id, value)); \ + } while (0) #define getrbi(n, o, v) \ do { \ rb = SafeXRCCTRL(d, n); \ @@ -3300,8 +3307,8 @@ bool MainFrame::BindControls() sc->SetValidator(wxUIntValidator(&o)); \ } while (0) { - getrbi("PNG", captureFormat, 0); - getrbi("BMP", captureFormat, 1); + getrbo("PNG", config::OptionID::kPrefCaptureFormat, 0); + getrbo("BMP", config::OptionID::kPrefCaptureFormat, 1); getsc("RewindInterval", gopts.rewind_interval); getsc_uint("Throttle", coreOptions.throttle); throttle_ctrl.thr = sc; @@ -3455,7 +3462,10 @@ bool MainFrame::BindControls() /// System and peripherals ch = GetValidatedChild(d, "SaveType", wxGenericValidator(&coreOptions.cpuSaveType)); BatConfigHandler.type = ch; - ch = GetValidatedChild(d, "FlashSize", wxGenericValidator(&optFlashSize)); + ch = GetValidatedChild( + d, "FlashSize", + widgets::OptionChoiceValidator( + config::OptionID::kPrefFlashSize)); BatConfigHandler.size = ch; d->Connect(XRCID("SaveType"), wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler(BatConfig_t::ChangeType), diff --git a/src/wx/opts.cpp b/src/wx/opts.cpp index 80d648cf..cef97a3e 100644 --- a/src/wx/opts.cpp +++ b/src/wx/opts.cpp @@ -338,10 +338,6 @@ wxAcceleratorEntry_v sys_accels; opts_t::opts_t() { recent = new wxFileHistory(10); - - // These are globals being set here. - frameSkip = -1; - autoPatch = true; } // FIXME: simulate MakeInstanceFilename(vbam.ini) using subkeys (Slave%d/*) diff --git a/src/wx/panel.cpp b/src/wx/panel.cpp index 5c9cb2a0..4fbee176 100644 --- a/src/wx/panel.cpp +++ b/src/wx/panel.cpp @@ -198,7 +198,7 @@ void GameArea::LoadGame(const wxString& name) // out to a temporary file and load it (and can't just use // AssignTempFileName because it needs correct extension) // too much trouble for now, though - bool loadpatch = autoPatch; + bool loadpatch = OPTION(kPrefAutoPatch); wxFileName pfn = loaded_game; int ovSaveType = 0; @@ -331,7 +331,7 @@ void GameArea::LoadGame(const wxString& name) int fsz = cfg->Read(wxT("flashSize"), (long)0); if (fsz != 0x10000 && fsz != 0x20000) - fsz = 0x10000 << optFlashSize; + fsz = 0x10000 << OPTION(kPrefFlashSize); flashSetSize(fsz); ovSaveType = cfg->Read(wxT("coreOptions.saveType"), coreOptions.cpuSaveType); @@ -348,7 +348,7 @@ void GameArea::LoadGame(const wxString& name) cfg->SetPath(wxT("/")); } else { rtcEnable(coreOptions.rtcEnabled); - flashSetSize(0x10000 << optFlashSize); + flashSetSize(0x10000 << OPTION(kPrefFlashSize)); if (coreOptions.cpuSaveType < 0 || coreOptions.cpuSaveType > 5) coreOptions.cpuSaveType = 0; @@ -420,12 +420,13 @@ void GameArea::LoadGame(const wxString& name) gbSerialFunction = gbPrinterSend; // probably only need to do this for GBA carts - agbPrintEnable(agbPrint); - // set frame skip based on ROM type - systemFrameSkip = frameSkip; + agbPrintEnable(OPTION(kPrefAgbPrint)); - if (systemFrameSkip < 0) - systemFrameSkip = 0; + // set frame skip based on ROM type + const int frame_skip = OPTION(kPrefFrameSkip); + if (frame_skip != -1) { + systemFrameSkip = frame_skip; + } // load battery and/or saved state recompute_dirs(); @@ -1892,9 +1893,9 @@ void DrawingPanelBase::DrawArea(uint8_t** data) if (panel->osdstat.size()) drawText(todraw + outstride * (systemColorDepth != 24), outstride, - 10, 20, UTF8(panel->osdstat), showSpeedTransparent); + 10, 20, UTF8(panel->osdstat), OPTION(kPrefShowSpeedTransparent)); - if (!disableStatusMessages && !panel->osdtext.empty()) { + if (!OPTION(kPrefDisableStatus) && !panel->osdtext.empty()) { if (systemGetClock() - panel->osdtime < OSD_TIME) { wxString message = panel->osdtext; int linelen = std::ceil(width * scale - 20) / 8; @@ -1908,7 +1909,7 @@ void DrawingPanelBase::DrawArea(uint8_t** data) ptr[linelen] = 0; drawText(todraw + outstride * (systemColorDepth != 24), outstride, 10, cury, ptr, - showSpeedTransparent); + OPTION(kPrefShowSpeedTransparent)); cury += 10; nlines--; ptr += linelen; @@ -1917,7 +1918,7 @@ void DrawingPanelBase::DrawArea(uint8_t** data) drawText(todraw + outstride * (systemColorDepth != 24), outstride, 10, cury, ptr, - showSpeedTransparent); + OPTION(kPrefShowSpeedTransparent)); free(buf); buf = NULL; @@ -1957,7 +1958,7 @@ void DrawingPanelBase::DrawOSD(wxWindowDC& dc) // directly into the output like DrawText, this is only enabled for // non-3d renderers. GameArea* panel = wxGetApp().frame->GetPanel(); - dc.SetTextForeground(wxColour(255, 0, 0, showSpeedTransparent ? 128 : 255)); + dc.SetTextForeground(wxColour(255, 0, 0, OPTION(kPrefShowSpeedTransparent) ? 128 : 255)); dc.SetTextBackground(wxColour(0, 0, 0, 0)); dc.SetUserScale(1.0, 1.0); @@ -1971,7 +1972,7 @@ void DrawingPanelBase::DrawOSD(wxWindowDC& dc) } } - if (!disableStatusMessages && !panel->osdtext.empty()) { + if (!OPTION(kPrefDisableStatus) && !panel->osdtext.empty()) { wxSize asz = dc.GetSize(); wxString msg = panel->osdtext; int lw, lh; diff --git a/src/wx/sys.cpp b/src/wx/sys.cpp index 6d24da24..1b468d30 100644 --- a/src/wx/sys.cpp +++ b/src/wx/sys.cpp @@ -452,7 +452,7 @@ void systemShowSpeed(int speed) wxString s; s.Printf(_("%d %% (%d, %d fps)"), speed, systemFrameSkip, frames * speed / 100); - switch (showSpeed) { + switch (OPTION(kPrefShowSpeed)) { case SS_NONE: f->GetPanel()->osdstat.clear(); break; @@ -474,9 +474,8 @@ int systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED; void system10Frames() { GameArea* panel = wxGetApp().frame->GetPanel(); - int fs = frameSkip; - if (fs < 0) { + if (OPTION(kPrefFrameSkip) == -1) { // We keep a rolling mean of the last second and use this value to // adjust the systemFrameSkip value dynamically. @@ -550,24 +549,25 @@ void systemScreenCapture(int num) GameArea* panel = wxGetApp().frame->GetPanel(); wxFileName fn = wxFileName(wxGetApp().frame->GetGamePath(gopts.scrshot_dir), wxEmptyString); + const int capture_format = OPTION(kPrefCaptureFormat); do { wxString bfn; bfn.Printf(wxT("%s%02d"), panel->game_name().c_str(), num++); - if (captureFormat == 0) - bfn.append(wxT(".png")); - else // if(gopts.cap_format == 1) - bfn.append(wxT(".bmp")); + if (capture_format == 0) + bfn.append(".png"); + else + bfn.append(".bmp"); fn.SetFullName(bfn); } while (fn.FileExists()); fn.Mkdir(0777, wxPATH_MKDIR_FULL); - if (captureFormat == 0) + if (capture_format == 0) panel->emusys->emuWritePNG(UTF8(fn.GetFullPath())); - else // if(gopts.cap_format == 1) + else panel->emusys->emuWriteBMP(UTF8(fn.GetFullPath())); wxString msg; @@ -930,10 +930,10 @@ void PrintDialog::DoSave(wxCommandEvent&) pats.append(wxALL_FILES); wxString dn = wxGetApp().frame->GetPanel()->game_name(); - if (captureFormat == 0) - dn.append(wxT(".png")); - else // if(gopts.cap_format == 1) - dn.append(wxT(".bmp")); + if (OPTION(kPrefCaptureFormat) == 0) + dn.append(".png"); + else + dn.append(".bmp"); wxFileDialog fdlg(dlg, _("Save printer image to"), prsav_path, dn, pats, wxFD_SAVE | wxFD_OVERWRITE_PROMPT); @@ -1106,16 +1106,17 @@ void systemGbPrint(uint8_t* data, int len, int pages, int feed, int pal, int con if (gopts.print_screen_cap) { wxFileName fn = wxFileName(wxGetApp().frame->GetGamePath(gopts.scrshot_dir), wxEmptyString); int num = 1; + const int capture_format = OPTION(kPrefCaptureFormat); do { wxString bfn; bfn.Printf(wxT("%s-print%02d"), panel->game_name().c_str(), num++); - if (captureFormat == 0) - bfn.append(wxT(".png")); - else // if(gopts.cap_format == 1) - bfn.append(wxT(".bmp")); + if (capture_format == 0) + bfn.append(".png"); + else + bfn.append(".bmp"); fn.SetFullName(bfn); } while (fn.FileExists()); @@ -1128,7 +1129,7 @@ void systemGbPrint(uint8_t* data, int len, int pages, int feed, int pal, int con systemGreenShift = 5; systemBlueShift = 0; wxString of = fn.GetFullPath(); - bool ret = captureFormat == 0 ? utilWritePNGFile(UTF8(of), 160, lines, (uint8_t*)to_print) : utilWriteBMPFile(UTF8(of), 160, lines, (uint8_t*)to_print); + bool ret = capture_format == 0 ? utilWritePNGFile(UTF8(of), 160, lines, (uint8_t*)to_print) : utilWriteBMPFile(UTF8(of), 160, lines, (uint8_t*)to_print); if (ret) { wxString msg; diff --git a/src/wx/viewsupt.cpp b/src/wx/viewsupt.cpp index 0677b9e7..2c1d9fe8 100644 --- a/src/wx/viewsupt.cpp +++ b/src/wx/viewsupt.cpp @@ -1,4 +1,6 @@ #include "viewsupt.h" + +#include "config/option-proxy.h" #include "wxvbam.h" #include "wxutil.h" @@ -1172,14 +1174,15 @@ void GfxViewer::SaveBMP(wxCommandEvent& ev) wxString def_name = panel->game_name() + wxT('-') + dname; def_name.resize(def_name.size() - 6); // strlen("Viewer") - if (captureFormat) - def_name += wxT(".bmp"); + const int capture_format = OPTION(kPrefCaptureFormat); + if (capture_format == 0) + def_name.append(".png"); else - def_name += wxT(".png"); + def_name.append(".bmp"); wxFileDialog dlg(GetGrandParent(), _("Select output file"), bmp_save_dir, def_name, _("PNG images|*.png|BMP images|*.bmp"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT); - dlg.SetFilterIndex(captureFormat); + dlg.SetFilterIndex(capture_format); int ret = dlg.ShowModal(); bmp_save_dir = dlg.GetDirectory(); diff --git a/src/wx/widgets/option-validator.cpp b/src/wx/widgets/option-validator.cpp index c91d26bf..f43a4b92 100644 --- a/src/wx/widgets/option-validator.cpp +++ b/src/wx/widgets/option-validator.cpp @@ -1,5 +1,10 @@ #include "widgets/option-validator.h" +#include +#include +#include +#include + namespace widgets { OptionValidator::OptionValidator(config::OptionID option_id) @@ -30,4 +35,111 @@ void OptionValidator::OnValueChanged() { assert(write_success); } +OptionSelectedValidator::OptionSelectedValidator(config::OptionID option_id, + uint32_t value) + : OptionValidator(option_id), value_(value) { + assert(option()->is_unsigned()); + assert(value_ >= option()->GetUnsignedMin()); + assert(value_ <= option()->GetUnsignedMax()); +} + +wxObject* OptionSelectedValidator::Clone() const { + return new OptionSelectedValidator(option()->id(), value_); +} + +bool OptionSelectedValidator::IsWindowValueValid() { + return true; +} + +bool OptionSelectedValidator::WriteToWindow() { + wxCheckBox* checkbox = wxDynamicCast(GetWindow(), wxCheckBox); + if (checkbox) { + checkbox->SetValue(option()->GetUnsigned() == value_); + return true; + } + + wxRadioButton* radio_button = wxDynamicCast(GetWindow(), wxRadioButton); + if (radio_button) { + radio_button->SetValue(option()->GetUnsigned() == value_); + return true; + } + + assert(false); + return false; +} + +bool OptionSelectedValidator::WriteToOption() { + const wxCheckBox* checkbox = wxDynamicCast(GetWindow(), wxCheckBox); + if (checkbox) { + if (checkbox->GetValue()) { + option()->SetUnsigned(value_); + } + return true; + } + + const wxRadioButton* radio_button = + wxDynamicCast(GetWindow(), wxRadioButton); + if (radio_button) { + if (radio_button->GetValue()) { + option()->SetUnsigned(value_); + } + return true; + } + + assert(false); + return false; +} + +OptionSpinCtrlValidator::OptionSpinCtrlValidator(config::OptionID option_id) + : OptionValidator(option_id) { + assert(option()->is_int()); +} + +wxObject* OptionSpinCtrlValidator::Clone() const { + return new OptionSpinCtrlValidator(option()->id()); +} + +bool OptionSpinCtrlValidator::IsWindowValueValid() { + return true; +} + +bool OptionSpinCtrlValidator::WriteToWindow() { + wxSpinCtrl* spin_ctrl = wxDynamicCast(GetWindow(), wxSpinCtrl); + assert(spin_ctrl); + spin_ctrl->SetValue(option()->GetInt()); + return true; +} + +bool OptionSpinCtrlValidator::WriteToOption() { + const wxSpinCtrl* spin_ctrl = wxDynamicCast(GetWindow(), wxSpinCtrl); + assert(spin_ctrl); + return option()->SetInt(spin_ctrl->GetValue()); +} + +OptionChoiceValidator::OptionChoiceValidator(config::OptionID option_id) + : OptionValidator(option_id) { + assert(option()->is_unsigned()); +} + +wxObject* OptionChoiceValidator::Clone() const { + return new OptionChoiceValidator(option()->id()); +} + +bool OptionChoiceValidator::IsWindowValueValid() { + return true; +} + +bool OptionChoiceValidator::WriteToWindow() { + wxChoice* choice = wxDynamicCast(GetWindow(), wxChoice); + assert(choice); + choice->SetSelection(option()->GetUnsigned()); + return true; +} + +bool OptionChoiceValidator::WriteToOption() { + const wxChoice* choice = wxDynamicCast(GetWindow(), wxChoice); + assert(choice); + return option()->SetUnsigned(choice->GetSelection()); +} + } // namespace widgets diff --git a/src/wx/widgets/option-validator.h b/src/wx/widgets/option-validator.h index b2cd17c7..ed2fab2f 100644 --- a/src/wx/widgets/option-validator.h +++ b/src/wx/widgets/option-validator.h @@ -85,6 +85,61 @@ private: void OnValueChanged() final; }; +// "Generic" validator for a wxChecBox or wxRadioButton widget with a kUnsigned +// Option. This will make sure the kUnsigned Option and the wxRadioButton or +// wxCheckBox are kept in sync. The widget will be checked if the kUnsigned +// Option matches the provided `value` parameter in the constructor. +class OptionSelectedValidator : public OptionValidator { +public: + OptionSelectedValidator(config::OptionID option_id, uint32_t value); + ~OptionSelectedValidator() override = default; + + // Returns a copy of the object. + wxObject* Clone() const override; + +private: + // OptionValidator implementation. + bool IsWindowValueValid() override; + bool WriteToWindow() override; + bool WriteToOption() override; + + const uint32_t value_; +}; + +// Validator for a wxSpinCtrl widget with a kInt Option. This will keep the +// kInt Option and the wxSpinCtrl selection in sync. +class OptionSpinCtrlValidator : public OptionValidator { +public: + explicit OptionSpinCtrlValidator(config::OptionID option_id); + ~OptionSpinCtrlValidator() override = default; + + // Returns a copy of the object. + wxObject* Clone() const override; + +private: + // OptionValidator implementation. + bool IsWindowValueValid() override; + bool WriteToWindow() override; + bool WriteToOption() override; +}; + +// Validator for a wxChoice widget with a kUnsigned Option. This will keep the +// kUnsigned Option and the wxChoice selection in sync. +class OptionChoiceValidator : public OptionValidator { +public: + explicit OptionChoiceValidator(config::OptionID option_id); + ~OptionChoiceValidator() override = default; + + // Returns a copy of the object. + wxObject* Clone() const override; + +private: + // OptionValidator implementation. + bool IsWindowValueValid() override; + bool WriteToWindow() override; + bool WriteToOption() override; +}; + } // namespace widgets #endif // VBAM_WX_WIDGETS_OPTION_VALIDATOR_H_ diff --git a/src/wx/wxvbam.cpp b/src/wx/wxvbam.cpp index 0bb165e7..52e26217 100644 --- a/src/wx/wxvbam.cpp +++ b/src/wx/wxvbam.cpp @@ -817,7 +817,7 @@ void MainFrame::OnActivate(wxActivateEvent& event) if (panel && focused) panel->SetFocus(); - if (pauseWhenInactive) { + if (OPTION(kPrefPauseWhenInactive)) { if (panel && focused && !paused) { panel->Resume(); } diff --git a/src/wx/wxvbam.h b/src/wx/wxvbam.h index 7b752ece..9224bc01 100644 --- a/src/wx/wxvbam.h +++ b/src/wx/wxvbam.h @@ -224,7 +224,7 @@ public: const config::OptionID& option_id); void GetMenuOptionInt(const wxString& menuName, int* field, int mask); void GetMenuOptionBool(const wxString& menuName, bool* field); - void SetMenuOption(const wxString& menuName, int value); + void SetMenuOption(const wxString& menuName, bool value); void SetJoystick();