mirror of https://github.com/mgba-emu/mgba.git
Add emulation menu with Pause option
This commit is contained in:
parent
5abd1572dc
commit
1eeeb36015
|
@ -42,17 +42,27 @@ GameController::~GameController() {
|
|||
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) {
|
||||
|
|
|
@ -27,9 +27,11 @@ public:
|
|||
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);
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ Window::Window(QWidget* parent) : QMainWindow(parent) {
|
|||
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 @@ void Window::keyReleaseEvent(QKeyEvent* event) {
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -28,12 +28,14 @@ protected:
|
|||
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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue