New pause implementation

This commit is contained in:
Alexandre LittleWhite Laurent 2016-08-16 16:40:36 +02:00
parent e64114f6a6
commit 40d59f085f
4 changed files with 33 additions and 9 deletions

View File

@ -137,7 +137,6 @@ GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread) :
NotifyClientAreaSizeChanged(std::pair<unsigned,unsigned>(child->width(), child->height()));
BackupGeometry();
}
void GRenderWindow::moveContext()
@ -287,11 +286,11 @@ void GRenderWindow::OnMinimalClientAreaChangeRequest(const std::pair<unsigned,un
}
void GRenderWindow::focusInEvent(QFocusEvent*) {
if (emu_thread && UISettings::values.pause_onfocuslost) emit gotFocus();
emit focusChanged(true);
}
void GRenderWindow::focusOutEvent(QFocusEvent*) {
if (emu_thread && UISettings::values.pause_onfocuslost) emit lostFocus();
emit focusChanged(false);
}
void GRenderWindow::OnEmulationStarting(EmuThread* emu_thread) {

View File

@ -136,10 +136,8 @@ public slots:
signals:
/// Emitted when the window is closed
void Closed();
/// Emitted when the window got focus
void gotFocus();
/// Emitted when the window lost focus
void lostFocus();
/// Emitted when the window focus changed
void focusChanged(bool hasFocus);
private:
void OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) override;

View File

@ -186,8 +186,7 @@ GMainWindow::GMainWindow() : config(new Config()), emu_thread(nullptr)
connect(this, SIGNAL(EmulationStarting(EmuThread*)), graphicsTracingWidget, SLOT(OnEmulationStarting(EmuThread*)));
connect(this, SIGNAL(EmulationStopping()), graphicsTracingWidget, SLOT(OnEmulationStopping()));
connect(render_window, SIGNAL(gotFocus()), this, SLOT(OnStartGame()));
connect(render_window, SIGNAL(lostFocus()), this, SLOT(OnPauseGame()));
connect(render_window, SIGNAL(focusChanged(bool)), this, SLOT(OnFocusChanged(bool)));
// Setup hotkeys
RegisterHotkey("Main Window", "Load File", QKeySequence::Open);
@ -472,6 +471,8 @@ void GMainWindow::OnStartGame() {
ui.action_Stop->setEnabled(true);
render_window->setFocus();
emulation_paused = false;
}
void GMainWindow::OnPauseGame() {
@ -480,12 +481,30 @@ void GMainWindow::OnPauseGame() {
ui.action_Start->setEnabled(true);
ui.action_Pause->setEnabled(false);
ui.action_Stop->setEnabled(true);
emulation_paused = true;
}
void GMainWindow::OnStopGame() {
ShutdownGame();
}
void GMainWindow::OnFocusChanged(bool hasFocus) {
// The focus change does not impact actual emulator state if:
// - the option is disabled
// - the emulation is not started
// - the emulation has been paused through menu
if(!UISettings::values.pause_onfocuslost ||
!emu_thread ||
emulation_paused)
return;
if (hasFocus)
emu_thread->SetRunning(true);
else // focus lost
emu_thread->SetRunning(false);
}
void GMainWindow::ToggleWindowMode() {
if (ui.action_Single_Window_Mode->isChecked()) {
// Render in the main window...
@ -521,6 +540,10 @@ void GMainWindow::OnConfigure() {
render_window->ReloadSetKeymaps();
config->Save();
}
// Make sure the emulation is running when all pauses are disabled
if (emu_thread && !UISettings::values.pause_onfocuslost && !emulation_paused)
emu_thread->SetRunning(true);
}
void GMainWindow::OnCreateGraphicsSurfaceViewer() {

View File

@ -98,6 +98,8 @@ private slots:
void OnStartGame();
void OnPauseGame();
void OnStopGame();
/// Called whenever the render window focus is changed
void OnFocusChanged(bool hasFocus);
/// Called whenever a user selects a game in the game list widget.
void OnGameListLoadFile(QString game_path);
void OnMenuLoadFile();
@ -118,6 +120,8 @@ private:
std::unique_ptr<Config> config;
// Whether emulation has been paused (through menus)
bool emulation_paused = false;
// Whether emulation is currently running in Citra.
bool emulation_running = false;
std::unique_ptr<EmuThread> emu_thread;