From 222a9721aadd83788fdc1491106bc65ce776f738 Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Wed, 23 Nov 2016 11:00:10 -0600 Subject: [PATCH] Add a File->Close option --- src/xenia/app/emulator_window.cc | 9 +++++++++ src/xenia/app/emulator_window.h | 1 + src/xenia/emulator.cc | 11 +++++++++++ src/xenia/emulator.h | 6 ++++++ 4 files changed, 27 insertions(+) diff --git a/src/xenia/app/emulator_window.cc b/src/xenia/app/emulator_window.cc index a7b4c55c9..77edbf2b5 100644 --- a/src/xenia/app/emulator_window.cc +++ b/src/xenia/app/emulator_window.cc @@ -167,6 +167,9 @@ bool EmulatorWindow::Initialize() { file_menu->AddChild( MenuItem::Create(MenuItem::Type::kString, L"&Open", L"Ctrl+O", std::bind(&EmulatorWindow::FileOpen, this))); + file_menu->AddChild( + MenuItem::Create(MenuItem::Type::kString, L"Close", + std::bind(&EmulatorWindow::FileClose, this))); file_menu->AddChild(MenuItem::Create(MenuItem::Type::kString, L"E&xit", L"Alt+F4", [this]() { window_->Close(); })); @@ -304,6 +307,12 @@ void EmulatorWindow::FileOpen() { } } +void EmulatorWindow::FileClose() { + if (emulator_->is_title_open()) { + emulator_->TerminateTitle(); + } +} + void EmulatorWindow::CheckHideCursor() { if (!window_->is_fullscreen()) { // Only hide when fullscreen. diff --git a/src/xenia/app/emulator_window.h b/src/xenia/app/emulator_window.h index 3d48279cb..673ad8437 100644 --- a/src/xenia/app/emulator_window.h +++ b/src/xenia/app/emulator_window.h @@ -44,6 +44,7 @@ class EmulatorWindow { void FileDrop(wchar_t* filename); void FileOpen(); + void FileClose(); void CheckHideCursor(); void CpuTimeScalarReset(); void CpuTimeScalarSetHalf(); diff --git a/src/xenia/emulator.cc b/src/xenia/emulator.cc index d5d68e588..54c587c8b 100644 --- a/src/xenia/emulator.cc +++ b/src/xenia/emulator.cc @@ -178,6 +178,17 @@ X_STATUS Emulator::Setup( return result; } +X_STATUS Emulator::TerminateTitle() { + if (!is_title_open()) { + return X_STATUS_UNSUCCESSFUL; + } + + kernel_state_->TerminateTitle(); + title_id_ = 0; + game_title_ = L""; + return X_STATUS_SUCCESS; +} + X_STATUS Emulator::LaunchPath(std::wstring path) { // Launch based on file type. // This is a silly guess based on file extension. diff --git a/src/xenia/emulator.h b/src/xenia/emulator.h index 8cae3eb5e..766e84956 100644 --- a/src/xenia/emulator.h +++ b/src/xenia/emulator.h @@ -56,6 +56,9 @@ class Emulator { // Title of the game in the default language. const std::wstring& game_title() const { return game_title_; } + // Are we currently running a title? + bool is_title_open() const { return title_id_ != 0; } + // Window used for displaying graphical output. ui::Window* display_window() const { return display_window_; } @@ -103,6 +106,9 @@ class Emulator { std::function>(ui::Window*)> input_driver_factory); + // Terminates the currently running title. + X_STATUS TerminateTitle(); + // Launches a game from the given file path. // This will attempt to infer the type of the given file (such as an iso, etc) // using heuristics.