From d32be9ddbe1fba1062cba246562dfb5f57ec54ff Mon Sep 17 00:00:00 2001 From: Fabrice de Gans Date: Fri, 3 May 2024 19:01:15 -0700 Subject: [PATCH] Move cmdtab and command enable flags to config/ * Moves cmdtab to config/. This removes the dependency on the wxvbam.h header from the config/ directory. * Fixes a number of issues in the shortcuts configuration window: * The "Remove" command was not working properly due to an incorrect refactor. * The window is now fully expandable. --- src/wx/CMakeLists.txt | 6 ++- src/wx/cmdevents.cpp | 6 +-- src/wx/config/cmdtab.cpp | 16 +++++++ src/wx/config/cmdtab.h | 62 +++++++++++++++++++++++++++ src/wx/config/command.cpp | 29 +++++++------ src/wx/copy-events.cmake | 17 +++++--- src/wx/dialogs/accel-config.cpp | 39 +++++++---------- src/wx/guiinit.cpp | 37 +++++++++-------- src/wx/opts.cpp | 25 +++++------ src/wx/panel.cpp | 1 + src/wx/sys.cpp | 1 + src/wx/widgets/client-data.h | 8 ++++ src/wx/wxvbam.cpp | 28 ++++++------- src/wx/wxvbam.h | 46 -------------------- src/wx/xrc/AccelConfig.xrc | 74 ++++++++++++++++++--------------- 15 files changed, 219 insertions(+), 176 deletions(-) create mode 100644 src/wx/config/cmdtab.cpp create mode 100644 src/wx/config/cmdtab.h diff --git a/src/wx/CMakeLists.txt b/src/wx/CMakeLists.txt index a234043c..33b4c421 100644 --- a/src/wx/CMakeLists.txt +++ b/src/wx/CMakeLists.txt @@ -17,6 +17,8 @@ set(VBAM_WX_COMMON config/bindings.h config/command.cpp config/command.h + config/cmdtab.cpp + config/cmdtab.h config/emulated-gamepad.cpp config/emulated-gamepad.h config/internal/bindings-internal.cpp @@ -101,7 +103,7 @@ set(VBAM_WX_COMMON ${VBAM_GENERATED_DIR}/wx/builtin-over.h ${VBAM_GENERATED_DIR}/wx/cmdhandlers.h ${VBAM_GENERATED_DIR}/wx/cmd-evtable.h - ${VBAM_GENERATED_DIR}/wx/cmdtab.cpp + ${VBAM_GENERATED_DIR}/wx/config/internal/cmdtab.cpp ) if(NOT ZIP_PROGRAM) @@ -601,7 +603,7 @@ add_custom_command( # all using portable cmake code add_custom_command( OUTPUT - ${VBAM_GENERATED_DIR}/wx/cmdtab.cpp + ${VBAM_GENERATED_DIR}/wx/config/internal/cmdtab.cpp ${VBAM_GENERATED_DIR}/wx/cmdhandlers.h ${VBAM_GENERATED_DIR}/wx/cmd-evtable.h COMMAND diff --git a/src/wx/cmdevents.cpp b/src/wx/cmdevents.cpp index c0a87178..fff56a2a 100644 --- a/src/wx/cmdevents.cpp +++ b/src/wx/cmdevents.cpp @@ -22,6 +22,7 @@ #include "core/gba/gbaGlobals.h" #include "core/gba/gbaPrint.h" #include "core/gba/gbaSound.h" +#include "wx/config/cmdtab.h" #include "wx/config/option-proxy.h" #include "wx/config/option.h" #include "wx/dialogs/game-maker.h" @@ -29,11 +30,6 @@ #define GetXRCDialog(n) \ wxStaticCast(wxGetApp().frame->FindWindowByName(n), wxDialog) -bool cmditem_lt(const struct cmditem& cmd1, const struct cmditem& cmd2) -{ - return wxStrcmp(cmd1.cmd, cmd2.cmd) < 0; -} - void MainFrame::GetMenuOptionBool(const wxString& menuName, bool* field) { assert(field); diff --git a/src/wx/config/cmdtab.cpp b/src/wx/config/cmdtab.cpp new file mode 100644 index 00000000..5949d695 --- /dev/null +++ b/src/wx/config/cmdtab.cpp @@ -0,0 +1,16 @@ +#include "wx/config/cmdtab.h" + +#include + +// Initializer for struct cmditem +cmditem new_cmditem(const wxString cmd, + const wxString name, + int cmd_id, + int mask_flags, + wxMenuItem* mi) { + return cmditem {cmd, name, cmd_id, mask_flags, mi}; +} + +bool cmditem_lt(const struct cmditem& cmd1, const struct cmditem& cmd2) { + return wxStrcmp(cmd1.cmd, cmd2.cmd) < 0; +} diff --git a/src/wx/config/cmdtab.h b/src/wx/config/cmdtab.h new file mode 100644 index 00000000..a360a3cc --- /dev/null +++ b/src/wx/config/cmdtab.h @@ -0,0 +1,62 @@ +#ifndef VBAM_WX_CONFIG_CMDTAB_H_ +#define VBAM_WX_CONFIG_CMDTAB_H_ + +#include + +#include + +// Forward declaration. +class wxMenuItem; + +// List of all commands with their descriptions +// sorted by cmd field for binary searching +// filled in by copy-events.cmake +struct cmditem { + const wxString cmd; + const wxString name; + int cmd_id; + int mask_flags; // if non-0, one of the flags must be turned on in win + // to enable this command + wxMenuItem* mi; // the menu item to invoke command, if present +}; + +extern std::vector cmdtab; + +// Initializer for struct cmditem +cmditem new_cmditem(const wxString cmd = "", + const wxString name = "", + int cmd_id = 0, + int mask_flags = 0, + wxMenuItem* mi = nullptr); + +// for binary search +bool cmditem_lt(const struct cmditem& cmd1, const struct cmditem& cmd2); + +// here are those conditions +enum { CMDEN_GB = (1 << 0), // GB ROM loaded + CMDEN_GBA = (1 << 1), // GBA ROM loaded + // the rest imply the above, unless: + // _ANY -> does not imply either + // _GBA -> only implies GBA + CMDEN_REWIND = (1 << 2), // rewind states available + CMDEN_SREC = (1 << 3), // sound recording in progress + CMDEN_NSREC = (1 << 4), // no sound recording + CMDEN_VREC = (1 << 5), // video recording + CMDEN_NVREC = (1 << 6), // no video recording + CMDEN_GREC = (1 << 7), // game recording + CMDEN_NGREC = (1 << 8), // no game recording + CMDEN_GPLAY = (1 << 9), // game playback + CMDEN_NGPLAY = (1 << 10), // no game playback + CMDEN_SAVST = (1 << 11), // any save states + CMDEN_GDB = (1 << 12), // gdb connected + CMDEN_NGDB_GBA = (1 << 13), // gdb not connected + CMDEN_NGDB_ANY = (1 << 14), // gdb not connected + CMDEN_NREC_ANY = (1 << 15), // not a/v recording + CMDEN_LINK_ANY = (1 << 16), // link enabled + + CMDEN_NEVER = (1 << 31) // never (for NOOP) +}; +#define ONLOAD_CMDEN (CMDEN_NSREC | CMDEN_NVREC | CMDEN_NGREC | CMDEN_NGPLAY) +#define UNLOAD_CMDEN_KEEP (CMDEN_NGDB_ANY | CMDEN_NREC_ANY | CMDEN_LINK_ANY) + +#endif // VBAM_WX_CONFIG_CMDTAB_H_ diff --git a/src/wx/config/command.cpp b/src/wx/config/command.cpp index 5339bb17..dab3f839 100644 --- a/src/wx/config/command.cpp +++ b/src/wx/config/command.cpp @@ -2,10 +2,11 @@ #include -#include +#include +#include +#include "wx/config/cmdtab.h" #include "wx/strutils.h" -#include "wx/wxvbam.h" namespace config { namespace { @@ -107,17 +108,15 @@ wxString GameCommand::ToUXString() const { } wxString ShortcutCommand::ToConfigString() const { - int cmd = 0; - for (cmd = 0; cmd < ncmds; cmd++) - if (cmdtab[cmd].cmd_id == id_) - break; - if (cmd == ncmds) { - // Command not found. This should never happen. - assert(false); - return wxEmptyString; + for (const cmditem& cmd_item : cmdtab) { + if (cmd_item.cmd_id == id_) { + return wxString::Format("Keyboard/%s", cmd_item.cmd); + } } - return wxString::Format("Keyboard/%s", cmdtab[cmd].cmd); + // Command not found. This should never happen. + assert(false); + return wxEmptyString; } // static @@ -158,14 +157,14 @@ nonstd::optional Command::FromString(const wxString& name) { return nonstd::nullopt; } - const cmditem* cmd = std::lower_bound( - &cmdtab[0], &cmdtab[ncmds], cmditem{parts[1], wxString(), 0, 0, NULL}, cmditem_lt); - if (cmd == &cmdtab[ncmds] || wxStrcmp(parts[1], cmd->cmd)) { + const auto iter = std::lower_bound(cmdtab.begin(), cmdtab.end(), + cmditem{parts[1], wxString(), 0, 0, NULL}, cmditem_lt); + if (iter == cmdtab.end()) { wxLogDebug("Command ID %s not found", parts[1]); return nonstd::nullopt; } - return Command(ShortcutCommand(cmd->cmd_id)); + return Command(ShortcutCommand(iter->cmd_id)); } } diff --git a/src/wx/copy-events.cmake b/src/wx/copy-events.cmake index 6794e7d5..4f930c63 100644 --- a/src/wx/copy-events.cmake +++ b/src/wx/copy-events.cmake @@ -4,7 +4,7 @@ IF(NOT OUTDIR) SET(OUTDIR ".") ENDIF(NOT OUTDIR) -SET(CMDTAB "${OUTDIR}/cmdtab.cpp") +SET(CMDTAB "${OUTDIR}/config/internal/cmdtab.cpp") SET(EVPROTO "${OUTDIR}/cmdhandlers.h") SET(EVTABLE "${OUTDIR}/cmd-evtable.h") @@ -13,20 +13,25 @@ STRING(REGEX MATCHALL "\nEVT_HANDLER([^\")]|\"[^\"]*\")*\\)" MW "${MW}") # cmdtab.cpp is a table of cmd-id-name/cmd-name pairs # sorted for binary searching -FILE(WRITE "${CMDTAB}" "// Generated from cmdevents.cpp; do not edit\n#include \n\n#include \"wx/wxvbam.h\"\n#include \"wx/wxhead.h\"\n\nstruct cmditem cmdtab[] = {\n") +FILE(WRITE "${CMDTAB}" "// Generated from cmdevents.cpp; do not edit\n\n") +FILE(APPEND "${CMDTAB}" "#include \"wx/config/cmdtab.h\"\n\n") +FILE(APPEND "${CMDTAB}" "#include \n\n") +FILE(APPEND "${CMDTAB}" "#include \"wx/config/bindings.h\"\n\n") +FILE(APPEND "${CMDTAB}" "std::vector cmdtab = {\n") SET(EVLINES ) FOREACH(EV ${MW}) # stripping the wxID_ makes it look better, but it's still all-caps STRING(REGEX REPLACE "^[^\"]*\\((wxID_|)([^,]*),[^\"]*(\"[^\"]*\")[^,)]*(,[^)]*|).*" " new_cmditem(\"\\2\", \\3, XRCID(\"\\1\\2\")\\4 )" - EV "${EV}") + EV "${EV}") STRING(REGEX REPLACE "XRCID\\(\"(wxID_[^\"]*)\"\\)" "\\1" EV ${EV}) LIST(APPEND EVLINES "${EV},\n") ENDFOREACH(EV) LIST(SORT EVLINES) STRING(REGEX REPLACE ",\n\$" "\n" EVLINES "${EVLINES}") FILE(APPEND "${CMDTAB}" ${EVLINES}) -FILE(APPEND "${CMDTAB}" "};\nconst int ncmds = sizeof(cmdtab) / sizeof(cmdtab[0]);\n") +FILE(APPEND "${CMDTAB}" "};\n") +FILE(APPEND "${CMDTAB}" "const int ncmds = sizeof(cmdtab) / sizeof(cmdtab[0]);\n") # cmdhandlers.h contains prototypes for all handlers FILE(WRITE "${EVPROTO}" "// Generated from cmdevents.cpp; do not edit\n") @@ -48,9 +53,9 @@ FOREACH(EV ${MW}) STRING(REGEX REPLACE "[^\"]*\\(" "" EV "${EV}") STRING(REGEX REPLACE ",.*" "" EV "${EV}") IF("${EV}" MATCHES "wx.*") - FILE(APPEND "${EVTABLE}" "${EV}") + FILE(APPEND "${EVTABLE}" "${EV}") ELSE("${EV}" MATCHES "wx.*") - FILE(APPEND "${EVTABLE}" "XRCID(\"${EV}\")") + FILE(APPEND "${EVTABLE}" "XRCID(\"${EV}\")") ENDIF("${EV}" MATCHES "wx.*") FILE(APPEND "${EVTABLE}" ", MainFrame::On${EV})\n") ENDFOREACH(EV) diff --git a/src/wx/dialogs/accel-config.cpp b/src/wx/dialogs/accel-config.cpp index a28e7769..22ffa866 100644 --- a/src/wx/dialogs/accel-config.cpp +++ b/src/wx/dialogs/accel-config.cpp @@ -7,12 +7,12 @@ #include #include "wx/config/bindings.h" +#include "wx/config/cmdtab.h" #include "wx/config/command.h" #include "wx/config/user-input.h" #include "wx/dialogs/base-dialog.h" #include "wx/widgets/client-data.h" #include "wx/widgets/user-input-ctrl.h" -#include "wx/wxvbam.h" namespace dialogs { @@ -59,22 +59,23 @@ void AppendItemToTree(std::unordered_map* int command, const wxString& prefix, int level) { - int i = 0; - for (; i < ncmds; i++) { - if (command == cmdtab[i].cmd_id) { + wxString name; + for (const cmditem& cmd_item : cmdtab) { + if (command == cmd_item.cmd_id) { + name = cmd_item.name; break; } } - assert(i < ncmds); + assert(!name.empty()); - const wxTreeItemId tree_item_id = tree->AppendItem( - parent, - /*text=*/cmdtab[i].name, - /*image=*/-1, - /*selImage=*/-1, - /*data=*/ - new CommandTreeItemData(config::ShortcutCommand(command), - AppendString(prefix, level, cmdtab[i].name), cmdtab[i].name)); + const wxTreeItemId tree_item_id = + tree->AppendItem(parent, + /*text=*/name, + /*image=*/-1, + /*selImage=*/-1, + /*data=*/ + new CommandTreeItemData(config::ShortcutCommand(command), + AppendString(prefix, level, name), name)); command_to_item_id->emplace(command, tree_item_id); } @@ -154,16 +155,9 @@ AccelConfig::AccelConfig(wxWindow* parent, tree_->ExpandAll(); tree_->SelectItem(menu_id); - // Set the initial tree size. - wxSize size = tree_->GetBestSize(); - size.SetHeight(std::min(200, size.GetHeight())); - tree_->SetSize(size); - size.SetWidth(-1); // maybe allow it to become bigger - tree_->SetSizeHints(size, size); - int w, h; current_keys_->GetTextExtent("CTRL-ALT-SHIFT-ENTER", &w, &h); - size.Set(w, h); + wxSize size(w, h); current_keys_->SetMinSize(size); // Compute max size for currently_assigned_label_. @@ -178,7 +172,6 @@ AccelConfig::AccelConfig(wxWindow* parent, size.SetHeight(std::max(h, size.GetHeight())); } currently_assigned_label_->SetMinSize(size); - currently_assigned_label_->SetSizeHints(size); // Finally, bind the events. Bind(wxEVT_SHOW, &AccelConfig::OnDialogShown, this, GetId()); @@ -250,7 +243,7 @@ void AccelConfig::OnRemoveBinding(wxCommandEvent&) { return; } - config_shortcuts_.UnassignInput(UserInputClientData::From(current_keys_)); + config_shortcuts_.UnassignInput(UserInputClientData::From(current_keys_, selection)); PopulateCurrentKeys(); } diff --git a/src/wx/guiinit.cpp b/src/wx/guiinit.cpp index 27a6c2e6..2b699d4b 100644 --- a/src/wx/guiinit.cpp +++ b/src/wx/guiinit.cpp @@ -38,6 +38,7 @@ #include "core/gba/gbaCheats.h" #include "core/gba/gbaFlash.h" #include "core/gba/gbaGlobals.h" +#include "wx/config/cmdtab.h" #include "wx/config/option-proxy.h" #include "wx/dialogs/accel-config.h" #include "wx/dialogs/base-dialog.h" @@ -1785,82 +1786,82 @@ bool MainFrame::BindControls() #endif // save all menu items in the command table - for (int i = 0; i < ncmds; i++) { - wxMenuItem* mi = cmdtab[i].mi = XRCITEM_I(cmdtab[i].cmd_id); + for (cmditem& cmd_item : cmdtab) { + wxMenuItem* mi = cmd_item.mi = XRCITEM_I(cmd_item.cmd_id); // remove unsupported commands first #ifdef NO_FFMPEG - if (cmdtab[i].mask_flags & (CMDEN_SREC | CMDEN_NSREC | CMDEN_VREC | CMDEN_NVREC)) { + if (cmd_item.mask_flags & (CMDEN_SREC | CMDEN_NSREC | CMDEN_VREC | CMDEN_NVREC)) { if (mi) mi->GetMenu()->Remove(mi); - cmdtab[i].mi = NULL; + cmd_item.mi = NULL; continue; } #endif #ifndef GBA_LOGGING - if (cmdtab[i].cmd_id == XRCID("Logging")) { + if (cmd_item.cmd_id == XRCID("Logging")) { if (mi) mi->GetMenu()->Remove(mi); - cmdtab[i].mi = NULL; + cmd_item.mi = NULL; continue; } #endif #if defined(__WXMAC__) || defined(__WXGTK__) - if (cmdtab[i].cmd_id == XRCID("AllowKeyboardBackgroundInput") + if (cmd_item.cmd_id == XRCID("AllowKeyboardBackgroundInput") #if defined(__WXGTK__) && IsWayland() #endif ) { if (mi) mi->GetMenu()->Remove(mi); - cmdtab[i].mi = NULL; + cmd_item.mi = NULL; continue; } #endif #ifdef NO_LINK - if (cmdtab[i].cmd_id == XRCID("LanLink") || cmdtab[i].cmd_id == XRCID("LinkType0Nothing") || cmdtab[i].cmd_id == XRCID("LinkType1Cable") || cmdtab[i].cmd_id == XRCID("LinkType2Wireless") || cmdtab[i].cmd_id == XRCID("LinkType3GameCube") || cmdtab[i].cmd_id == XRCID("LinkType4Gameboy") || cmdtab[i].cmd_id == XRCID("LinkAuto") || cmdtab[i].cmd_id == XRCID("SpeedOn") || cmdtab[i].cmd_id == XRCID("LinkProto") || cmdtab[i].cmd_id == XRCID("LinkConfigure")) { + if (cmd_item.cmd_id == XRCID("LanLink") || cmd_item.cmd_id == XRCID("LinkType0Nothing") || cmd_item.cmd_id == XRCID("LinkType1Cable") || cmd_item.cmd_id == XRCID("LinkType2Wireless") || cmd_item.cmd_id == XRCID("LinkType3GameCube") || cmd_item.cmd_id == XRCID("LinkType4Gameboy") || cmd_item.cmd_id == XRCID("LinkAuto") || cmd_item.cmd_id == XRCID("SpeedOn") || cmd_item.cmd_id == XRCID("LinkProto") || cmd_item.cmd_id == XRCID("LinkConfigure")) { if (mi) mi->GetMenu()->Remove(mi); - cmdtab[i].mi = NULL; + cmd_item.mi = NULL; continue; } #else // Always disable Wireless link for now, this has never worked. - if (cmdtab[i].cmd_id == XRCID("LinkType2Wireless")) { + if (cmd_item.cmd_id == XRCID("LinkType2Wireless")) { if (mi) mi->GetMenu()->Remove(mi); - cmdtab[i].mi = NULL; + cmd_item.mi = NULL; continue; } #endif #if !defined(VBAM_ENABLE_DEBUGGER) - if (cmdtab[i].cmd_id == XRCID("DebugGDBBreak") || cmdtab[i].cmd_id == XRCID("DebugGDBDisconnect") || cmdtab[i].cmd_id == XRCID("DebugGDBBreakOnLoad") || cmdtab[i].cmd_id == XRCID("DebugGDBPort")) + if (cmd_item.cmd_id == XRCID("DebugGDBBreak") || cmd_item.cmd_id == XRCID("DebugGDBDisconnect") || cmd_item.cmd_id == XRCID("DebugGDBBreakOnLoad") || cmd_item.cmd_id == XRCID("DebugGDBPort")) { if (mi) { mi->GetMenu()->Enable(mi->GetId(), false); //mi->GetMenu()->Remove(mi); } - cmdtab[i].mi = NULL; + cmd_item.mi = NULL; continue; } #endif // !defined(VBAM_ENABLE_DEBUGGER) #if defined(NO_ONLINEUPDATES) - if (cmdtab[i].cmd_id == XRCID("UpdateEmu")) + if (cmd_item.cmd_id == XRCID("UpdateEmu")) { if (mi) mi->GetMenu()->Remove(mi); - cmdtab[i].mi = NULL; + cmd_item.mi = NULL; continue; } #endif @@ -1877,11 +1878,11 @@ bool MainFrame::BindControls() // store checkable items if (mi->IsCheckable()) { - checkable_mi_t cmi = { cmdtab[i].cmd_id, mi, 0, 0 }; + checkable_mi_t cmi = { cmd_item.cmd_id, mi, 0, 0 }; checkable_mi.push_back(cmi); for (const config::Option& option : config::Option::All()) { - if (cmdtab[i].cmd == option.command()) { + if (cmd_item.cmd == option.command()) { if (option.is_int()) { MenuOptionIntMask( option.command(), option.GetInt(), (1 << 0)); diff --git a/src/wx/opts.cpp b/src/wx/opts.cpp index c5cbbe16..cebd63d1 100644 --- a/src/wx/opts.cpp +++ b/src/wx/opts.cpp @@ -11,6 +11,7 @@ #include #include "wx/config/bindings.h" +#include "wx/config/cmdtab.h" #include "wx/config/command.h" #include "wx/config/option-observer.h" #include "wx/config/option-proxy.h" @@ -221,7 +222,7 @@ void load_opts(bool first_time_launch) { if (s == wxT("Keyboard")) { const cmditem dummy = new_cmditem(e); - if (!std::binary_search(&cmdtab[0], &cmdtab[ncmds], dummy, cmditem_lt)) { + if (!std::binary_search(cmdtab.begin(), cmdtab.end(), dummy, cmditem_lt)) { s.append(wxT('/')); s.append(e); //wxLogWarning(_("Invalid option %s present; removing if possible"), s.c_str()); @@ -329,9 +330,9 @@ void load_opts(bool first_time_launch) { // Keyboard does not get written with defaults wxString kbopt("Keyboard/"); int kboff = kbopt.size(); - for (int i = 0; i < ncmds; i++) { + for (const cmditem& cmd_item : cmdtab) { kbopt.resize(kboff); - kbopt.append(cmdtab[i].cmd); + kbopt.append(cmd_item.cmd); if (cfg->Read(kbopt, &s) && s.size()) { auto inputs = config::UserInput::FromConfigString(s); @@ -340,7 +341,7 @@ void load_opts(bool first_time_launch) { } else { for (const auto& input : inputs) { bindings->AssignInputToCommand(input, - config::ShortcutCommand(cmdtab[i].cmd_id)); + config::ShortcutCommand(cmd_item.cmd_id)); } } } @@ -420,17 +421,17 @@ void update_shortcut_opts() { cfg->DeleteGroup("/Keyboard"); cfg->SetPath("/Keyboard"); for (const auto& iter : wxGetApp().bindings()->GetKeyboardConfiguration()) { - int cmd = 0; - for (cmd = 0; cmd < ncmds; cmd++) - if (cmdtab[cmd].cmd_id == iter.first) + bool found = false; + for (const cmditem& cmd_item : cmdtab) { + if (cmd_item.cmd_id == iter.first) { + found = true; + cfg->Write(cmd_item.cmd, iter.second); break; - if (cmd == ncmds) { - // Command not found. This should never happen. - assert(false); - continue; + } } - cfg->Write(cmdtab[cmd].cmd, iter.second); + // Command not found. This should never happen. + assert(found); } cfg->SetPath("/"); diff --git a/src/wx/panel.cpp b/src/wx/panel.cpp index 85cd0733..0a1290d0 100644 --- a/src/wx/panel.cpp +++ b/src/wx/panel.cpp @@ -41,6 +41,7 @@ #include "core/gba/gbaRtc.h" #include "core/gba/gbaSound.h" #include "wx/background-input.h" +#include "wx/config/cmdtab.h" #include "wx/config/emulated-gamepad.h" #include "wx/config/option-id.h" #include "wx/config/option-proxy.h" diff --git a/src/wx/sys.cpp b/src/wx/sys.cpp index ca1bb156..c1993047 100644 --- a/src/wx/sys.cpp +++ b/src/wx/sys.cpp @@ -11,6 +11,7 @@ #include "core/gba/gbaGlobals.h" #include "core/gba/gbaSound.h" #include "wx/audio/audio.h" +#include "wx/config/cmdtab.h" #include "wx/config/emulated-gamepad.h" #include "wx/config/option-proxy.h" #include "wx/wxvbam.h" diff --git a/src/wx/widgets/client-data.h b/src/wx/widgets/client-data.h index 6edf8537..fe1eceed 100644 --- a/src/wx/widgets/client-data.h +++ b/src/wx/widgets/client-data.h @@ -4,6 +4,7 @@ #include #include +#include #include namespace widgets { @@ -19,6 +20,13 @@ public: return static_cast*>(data)->data(); } + // Returns the data stored in the ClientData object for a container. + static const T& From(wxItemContainer* container, size_t index) { + wxClientData* data = container->GetClientObject(index); + assert(data); + return static_cast*>(data)->data(); + } + explicit ClientData(const T& data) : data_(data) {} ~ClientData() override = default; diff --git a/src/wx/wxvbam.cpp b/src/wx/wxvbam.cpp index 3c875bb4..90e460d4 100644 --- a/src/wx/wxvbam.cpp +++ b/src/wx/wxvbam.cpp @@ -34,6 +34,7 @@ #include "core/gba/gbaSound.h" #include "wx/builtin-over.h" #include "wx/builtin-xrc.h" +#include "wx/config/cmdtab.h" #include "wx/config/emulated-gamepad.h" #include "wx/config/option-proxy.h" #include "wx/config/option.h" @@ -164,14 +165,6 @@ IMPLEMENT_DYNAMIC_CLASS(MainFrame, wxFrame) #include "autoupdater/autoupdater.h" #endif // NO_ONLINEUPDATES -// Initializer for struct cmditem -cmditem new_cmditem(const wxString cmd, const wxString name, int cmd_id, - int mask_flags, wxMenuItem* mi) -{ - struct cmditem tmp = {cmd, name, cmd_id, mask_flags, mi}; - return tmp; -} - // generate config file path static void get_config_path(wxPathList& path, bool exists = true) { @@ -755,8 +748,9 @@ bool wxvbamApp::OnCmdLineParsed(wxCmdLineParser& cl) } wxPrintf(_("The commands available for the Keyboard/* option are:\n\n")); - for (int i = 0; i < ncmds; i++) - wxPrintf(wxT("%s (%s)\n"), cmdtab[i].cmd.c_str(), cmdtab[i].name.c_str()); + for (const cmditem& cmd_item : cmdtab) { + wxPrintf("%s (%s)\n", cmd_item.cmd.c_str(), cmd_item.name.c_str()); + } console_mode = true; return true; @@ -1049,9 +1043,11 @@ wxString MainFrame::GetGamePath(wxString path) void MainFrame::enable_menus() { - for (int i = 0; i < ncmds; i++) - if (cmdtab[i].mask_flags && cmdtab[i].mi) - cmdtab[i].mi->Enable((cmdtab[i].mask_flags & cmd_enable) != 0); + for (const cmditem& cmd_item : cmdtab) { + if (cmd_item.mask_flags && cmd_item.mi) { + cmd_item.mi->Enable((cmd_item.mask_flags & cmd_enable) != 0); + } + } if (cmd_enable & CMDEN_SAVST) for (int i = 0; i < 10; i++) @@ -1179,11 +1175,11 @@ void MainFrame::ResetRecentAccelerators() { } void MainFrame::ResetMenuAccelerators() { - for (int i = 0; i < ncmds; i++) { - if (!cmdtab[i].mi) { + for (const cmditem& cmd_item : cmdtab) { + if (!cmd_item.mi) { continue; } - ResetMenuItemAccelerator(cmdtab[i].mi); + ResetMenuItemAccelerator(cmd_item.mi); } ResetRecentAccelerators(); } diff --git a/src/wx/wxvbam.h b/src/wx/wxvbam.h index ae13587e..5412e22b 100644 --- a/src/wx/wxvbam.h +++ b/src/wx/wxvbam.h @@ -164,33 +164,6 @@ DECLARE_APP(wxvbamApp); } \ void MainFrame::Do##n() -// here are those conditions -enum { CMDEN_GB = (1 << 0), // GB ROM loaded - CMDEN_GBA = (1 << 1), // GBA ROM loaded - // the rest imply the above, unless: - // _ANY -> does not imply either - // _GBA -> only implies GBA - CMDEN_REWIND = (1 << 2), // rewind states available - CMDEN_SREC = (1 << 3), // sound recording in progress - CMDEN_NSREC = (1 << 4), // no sound recording - CMDEN_VREC = (1 << 5), // video recording - CMDEN_NVREC = (1 << 6), // no video recording - CMDEN_GREC = (1 << 7), // game recording - CMDEN_NGREC = (1 << 8), // no game recording - CMDEN_GPLAY = (1 << 9), // game playback - CMDEN_NGPLAY = (1 << 10), // no game playback - CMDEN_SAVST = (1 << 11), // any save states - CMDEN_GDB = (1 << 12), // gdb connected - CMDEN_NGDB_GBA = (1 << 13), // gdb not connected - CMDEN_NGDB_ANY = (1 << 14), // gdb not connected - CMDEN_NREC_ANY = (1 << 15), // not a/v recording - CMDEN_LINK_ANY = (1 << 16), // link enabled - - CMDEN_NEVER = (1 << 31) // never (for NOOP) -}; -#define ONLOAD_CMDEN (CMDEN_NSREC | CMDEN_NVREC | CMDEN_NGREC | CMDEN_NGPLAY) -#define UNLOAD_CMDEN_KEEP (CMDEN_NGDB_ANY | CMDEN_NREC_ANY | CMDEN_LINK_ANY) - struct checkable_mi_t { int cmd; wxMenuItem* mi; @@ -610,25 +583,6 @@ private: // wxString version of OSD message void systemScreenMessage(const wxString& msg); -// List of all commands with their descriptions -// sorted by cmd field for binary searching -// filled in by copy-events.cmake -extern struct cmditem { - const wxString cmd, name; - int cmd_id; - int mask_flags; // if non-0, one of the flags must be turned on in win - // to enable this command - wxMenuItem* mi; // the menu item to invoke command, if present -} cmdtab[]; -extern const int ncmds; - -// Initializer for struct cmditem -cmditem new_cmditem(const wxString cmd = wxT(""), const wxString name = wxT(""), - int cmd_id = 0, int mask_flags = 0, wxMenuItem* mi = NULL); - -// for binary search -extern bool cmditem_lt(const struct cmditem& cmd1, const struct cmditem& cmd2); - #include "wx/rpi.h" #include diff --git a/src/wx/xrc/AccelConfig.xrc b/src/wx/xrc/AccelConfig.xrc index 1eff8465..0788cce5 100644 --- a/src/wx/xrc/AccelConfig.xrc +++ b/src/wx/xrc/AccelConfig.xrc @@ -2,49 +2,58 @@ Key Shortcuts + + wxVERTICAL wxEXPAND + + wxEXPAND + 3 + 2 + 0 + 0 + wxEXPAND + wxVERTICAL + wxEXPAND + wxALL + 5 - wxALL - 5 - - - 300,300 - - wxALL|wxEXPAND - 5 - - wxVERTICAL - - wxEXPAND - - - - - - - - wxALL - 5 - - - wxALL|wxEXPAND 5 + + + - wxVERTICAL + + wxEXPAND + + wxVERTICAL + + wxALL + 5 + + + + + + + wxALL|wxEXPAND + 5 + + + @@ -73,9 +82,11 @@ wxEXPAND - 3 + wxALL + 5 + wxVERTICAL @@ -84,19 +95,16 @@ - wxVERTICAL - wxALL - 5 + wxALL + 5 - wxALL - 5 @@ -110,6 +118,8 @@ + wxALL|wxEXPAND + 5 @@ -118,8 +128,6 @@ - wxALL|wxEXPAND - 5