all repos — mgba @ 1eeeb360155fd3783da8584b8ecf11a352ff89cd

mGBA Game Boy Advance Emulator

Add emulation menu with Pause option
Jeffrey Pfau jeffrey@endrift.com
Wed, 29 Jan 2014 23:39:24 -0800
commit

1eeeb360155fd3783da8584b8ecf11a352ff89cd

parent

5abd1572dca6829ab7e02c1d50462fd360c32717

M src/platform/qt/GameController.cppsrc/platform/qt/GameController.cpp

@@ -42,17 +42,27 @@ GBAThreadJoin(&m_threadContext);

delete m_renderer; } -bool GameController::loadGame(const QString& path) { +void GameController::loadGame(const QString& path) { m_rom = new QFile(path); if (!m_rom->open(QIODevice::ReadOnly)) { delete m_rom; m_rom = 0; - return false; } m_threadContext.fd = m_rom->handle(); m_threadContext.fname = path.toLocal8Bit().constData(); GBAThreadStart(&m_threadContext); - return true; + emit gameStarted(); +} + +void GameController::setPaused(bool paused) { + if (paused == GBAThreadIsPaused(&m_threadContext)) { + return; + } + if (paused) { + GBAThreadPause(&m_threadContext); + } else { + GBAThreadUnpause(&m_threadContext); + } } void GameController::keyPressed(int key) {
M src/platform/qt/GameController.hsrc/platform/qt/GameController.h

@@ -27,9 +27,11 @@

signals: void frameAvailable(const QImage&); void audioDeviceAvailable(GBAAudio*); + void gameStarted(); public slots: - bool loadGame(const QString& path); + void loadGame(const QString& path); + void setPaused(bool paused); void keyPressed(int key); void keyReleased(int key);
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -16,6 +16,7 @@ m_display = new Display(this);

setCentralWidget(m_display); connect(m_controller, SIGNAL(frameAvailable(const QImage&)), m_display, SLOT(draw(const QImage&))); connect(m_controller, SIGNAL(audioDeviceAvailable(GBAAudio*)), this, SLOT(setupAudio(GBAAudio*))); + connect(m_controller, SIGNAL(gameStarted()), this, SLOT(gameStarted())); setupMenu(menuBar()); }

@@ -92,6 +93,12 @@ m_controller->keyReleased(key);

event->accept(); } +void Window::gameStarted() { + foreach (QAction* action, m_gameActions) { + action->setDisabled(false); + } +} + void Window::setupAudio(GBAAudio* audio) { AudioDevice::Thread* thread = new AudioDevice::Thread(this); thread->setInput(audio);

@@ -102,4 +109,14 @@ void Window::setupMenu(QMenuBar* menubar) {

menubar->clear(); QMenu* fileMenu = menubar->addMenu(tr("&File")); fileMenu->addAction(tr("Load &ROM"), this, SLOT(selectROM()), QKeySequence::Open); + + QMenu* emulationMenu = menubar->addMenu(tr("&Emulation")); + QAction* pause = new QAction(tr("&Pause"), 0); + pause->setChecked(false); + pause->setCheckable(true); + pause->setShortcut(tr("Ctrl+P")); + pause->setDisabled(true); + connect(pause, SIGNAL(triggered(bool)), m_controller, SLOT(setPaused(bool))); + m_gameActions.append(pause); + emulationMenu->addAction(pause); }
M src/platform/qt/Window.hsrc/platform/qt/Window.h

@@ -28,12 +28,14 @@ virtual void keyPressEvent(QKeyEvent* event);

virtual void keyReleaseEvent(QKeyEvent* event); private slots: + void gameStarted(); void setupAudio(GBAAudio*); private: void setupMenu(QMenuBar*); GameController* m_controller; Display* m_display; + QList<QAction*> m_gameActions; }; }