all repos — mgba @ 153d1619043788dc3b36102342131f53ee25675d

mGBA Game Boy Advance Emulator

Qt: Add sugar for addGameAction on a CoreController call
Vicki Pfau vi@endrift.com
Sat, 01 Aug 2020 04:01:45 -0700
commit

153d1619043788dc3b36102342131f53ee25675d

parent

9fc8fdb73ba9756a775178ac8128cba2732dea0b

2 files changed, 15 insertions(+), 23 deletions(-)

jump to
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -1182,14 +1182,10 @@

m_actions.addSeparator("quickLoad"); m_actions.addSeparator("quickSave"); - Action* undoLoadState = addGameAction(tr("Undo load state"), "undoLoadState", [this]() { - m_controller->loadBackupState(); - }, "quickLoad", QKeySequence("F11")); + Action* undoLoadState = addGameAction(tr("Undo load state"), "undoLoadState", &CoreController::loadBackupState, "quickLoad", QKeySequence("F11")); m_nonMpActions.append(undoLoadState); - Action* undoSaveState = addGameAction(tr("Undo save state"), "undoSaveState", [this]() { - m_controller->saveBackupState(); - }, "quickSave", QKeySequence("Shift+F11")); + Action* undoSaveState = addGameAction(tr("Undo save state"), "undoSaveState", &CoreController::saveBackupState, "quickSave", QKeySequence("Shift+F11")); m_nonMpActions.append(undoSaveState); m_actions.addSeparator("quickLoad");

@@ -1235,17 +1231,9 @@ m_actions.addAction(tr("E&xit"), "quit", static_cast<QWidget*>(this), &QWidget::close, "file", QKeySequence::Quit);

#endif m_actions.addMenu(tr("&Emulation"), "emu"); - addGameAction(tr("&Reset"), "reset", [this]() { - m_controller->reset(); - }, "emu", QKeySequence("Ctrl+R")); - - addGameAction(tr("Sh&utdown"), "shutdown", [this]() { - m_controller->stop(); - }, "emu"); - - addGameAction(tr("Yank game pak"), "yank", [this]() { - m_controller->yankPak(); - }, "emu"); + addGameAction(tr("&Reset"), "reset", &CoreController::reset, "emu", QKeySequence("Ctrl+R")); + addGameAction(tr("Sh&utdown"), "shutdown", &CoreController::stop, "emu"); + addGameAction(tr("Yank game pak"), "yank", &CoreController::yankPak, "emu"); m_actions.addSeparator("emu");

@@ -1258,9 +1246,7 @@ }

}, "emu", QKeySequence("Ctrl+P")); connect(this, &Window::paused, pause, &Action::setActive); - addGameAction(tr("&Next frame"), "frameAdvance", [this]() { - m_controller->frameAdvance(); - }, "emu", QKeySequence("Ctrl+N")); + addGameAction(tr("&Next frame"), "frameAdvance", &CoreController::frameAdvance, "emu", QKeySequence("Ctrl+N")); m_actions.addSeparator("emu");

@@ -1781,9 +1767,14 @@

template<typename T, typename V> Action* Window::addGameAction(const QString& visibleName, const QString& name, T* obj, V (T::*method)(), const QString& menu, const QKeySequence& shortcut) { return addGameAction(visibleName, name, [this, obj, method]() { - if (m_controller) { - (obj->*method)(); - } + (obj->*method)(); + }, menu, shortcut); +} + +template<typename V> +Action* Window::addGameAction(const QString& visibleName, const QString& name, V (CoreController::*method)(), const QString& menu, const QKeySequence& shortcut) { + return addGameAction(visibleName, name, [this, method]() { + (m_controller.get()->*method)(); }, menu, shortcut); }
M src/platform/qt/Window.hsrc/platform/qt/Window.h

@@ -164,6 +164,7 @@ template <typename T, typename... A> std::function<void()> openControllerTView(A... arg);

Action* addGameAction(const QString& visibleName, const QString& name, Action::Function action, const QString& menu = {}, const QKeySequence& = {}); template<typename T, typename V> Action* addGameAction(const QString& visibleName, const QString& name, T* obj, V (T::*action)(), const QString& menu = {}, const QKeySequence& = {}); + template<typename V> Action* addGameAction(const QString& visibleName, const QString& name, V (CoreController::*action)(), const QString& menu = {}, const QKeySequence& = {}); Action* addGameAction(const QString& visibleName, const QString& name, Action::BooleanFunction action, const QString& menu = {}, const QKeySequence& = {}); void updateTitle(float fps = -1);